4 * Functions which deal with the fetching and displaying of messages.
12 #define SUBJ_COL_WIDTH_PCT 50 /**< Mailbox view column width */
13 #define SENDER_COL_WIDTH_PCT 30 /**< Mailbox view column width */
14 #define DATE_PLUS_BUTTONS_WIDTH_PCT 20 /**< Mailbox view column width */
17 * Address book entry (keep it short and sweet, it's just a quickie lookup
18 * which we can use to get to the real meat and bones later)
21 char ab_name[64]; /**< name string */
22 long ab_msgnum; /**< message number of address book entry */
30 * Wrapper around iconv_open()
31 * Our version adds aliases for non-standard Microsoft charsets
32 * such as 'MS950', aliasing them to names like 'CP950'
34 * tocode Target encoding
35 * fromcode Source encoding
37 iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode)
39 iconv_t ic = (iconv_t)(-1) ;
40 ic = iconv_open(tocode, fromcode);
41 if (ic == (iconv_t)(-1) ) {
42 char alias_fromcode[64];
43 if ( (strlen(fromcode) == 5) && (!strncasecmp(fromcode, "MS", 2)) ) {
44 safestrncpy(alias_fromcode, fromcode, sizeof alias_fromcode);
45 alias_fromcode[0] = 'C';
46 alias_fromcode[1] = 'P';
47 ic = iconv_open(tocode, alias_fromcode);
55 inline char *FindNextEnd (char *bptr)
58 /* Find the next ?Q? */
59 end = strchr(bptr + 2, '?');
60 if (end == NULL) return NULL;
61 if (((*(end + 1) == 'B') || (*(end + 1) == 'Q')) &&
62 (*(end + 2) == '?')) {
63 /* skip on to the end of the cluster, the next ?= */
64 end = strstr(end + 3, "?=");
67 /* sort of half valid encoding, try to find an end. */
68 end = strstr(bptr, "?=");
73 * Handle subjects with RFC2047 encoding such as:
74 * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=
76 void utf8ify_rfc822_string(char *buf) {
77 char *start, *end, *next, *nextend, *ptr;
82 iconv_t ic = (iconv_t)(-1) ;
83 char *ibuf; /**< Buffer of characters to be converted */
84 char *obuf; /**< Buffer for converted characters */
85 size_t ibuflen; /**< Length of input buffer */
86 size_t obuflen; /**< Length of output buffer */
87 char *isav; /**< Saved pointer to input buffer */
88 char *osav; /**< Saved pointer to output buffer */
91 int illegal_non_rfc2047_encoding = 0;
93 /* Sometimes, badly formed messages contain strings which were simply
94 * written out directly in some foreign character set instead of
95 * using RFC2047 encoding. This is illegal but we will attempt to
96 * handle it anyway by converting from a user-specified default
97 * charset to UTF-8 if we see any nonprintable characters.
100 for (i=0; i<len; ++i) {
101 if ((buf[i] < 32) || (buf[i] > 126)) {
102 illegal_non_rfc2047_encoding = 1;
103 i = len; ///< take a shortcut, it won't be more than one.
106 if (illegal_non_rfc2047_encoding) {
107 char default_header_charset[128];
108 get_preference("default_header_charset", default_header_charset, sizeof default_header_charset);
109 if ( (strcasecmp(default_header_charset, "UTF-8")) && (strcasecmp(default_header_charset, "us-ascii")) ) {
110 ic = ctdl_iconv_open("UTF-8", default_header_charset);
111 if (ic != (iconv_t)(-1) ) {
114 safestrncpy(ibuf, buf, 1024);
115 ibuflen = strlen(ibuf);
117 obuf = (char *) malloc(obuflen);
119 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
120 osav[1024-obuflen] = 0;
129 /* pre evaluate the first pair */
130 nextend = end = NULL;
132 start = strstr(buf, "=?");
134 end = FindNextEnd (start);
136 while ((start != NULL) && (end != NULL))
138 next = strstr(end, "=?");
140 nextend = FindNextEnd(next);
144 /* did we find two partitions */
145 if ((next != NULL) &&
149 while ((ptr < next) &&
155 /* did we find a gab just filled with blanks? */
160 len - (next - start));
162 /* now terminate the gab at the end */
163 delta = (next - end) - 2;
167 /* move next to its new location. */
172 /* our next-pair is our new first pair now. */
177 /* Now we handle foreign character sets properly encoded
180 while (start=strstr(buf, "=?"), end=FindNextEnd((start != NULL)? start : buf),
181 ((start != NULL) && (end != NULL) && (end > start)) )
183 extract_token(charset, start, 1, '?', sizeof charset);
184 extract_token(encoding, start, 2, '?', sizeof encoding);
185 extract_token(istr, start, 3, '?', sizeof istr);
189 if (!strcasecmp(encoding, "B")) { /**< base64 */
190 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
192 else if (!strcasecmp(encoding, "Q")) { /**< quoted-printable */
200 if (istr[pos] == '_') istr[pos] = ' ';
204 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, len);
207 strcpy(ibuf, istr); /**< unknown encoding */
208 ibuflen = strlen(istr);
211 ic = ctdl_iconv_open("UTF-8", charset);
212 if (ic != (iconv_t)(-1) ) {
214 obuf = (char *) malloc(obuflen);
216 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
217 osav[1024-obuflen] = 0;
222 remove_token(end, 0, '?');
223 remove_token(end, 0, '?');
224 remove_token(end, 0, '?');
225 remove_token(end, 0, '?');
226 strcpy(end, &end[1]);
228 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
237 remove_token(end, 0, '?');
238 remove_token(end, 0, '?');
239 remove_token(end, 0, '?');
240 remove_token(end, 0, '?');
241 strcpy(end, &end[1]);
243 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
250 * Since spammers will go to all sorts of absurd lengths to get their
251 * messages through, there are LOTS of corrupt headers out there.
252 * So, prevent a really badly formed RFC2047 header from throwing
253 * this function into an infinite loop.
256 if (passes > 20) return;
261 inline void utf8ify_rfc822_string(char *a){};
269 * \brief RFC2047-encode a header field if necessary.
270 * If no non-ASCII characters are found, the string
271 * will be copied verbatim without encoding.
273 * \param target Target buffer.
274 * \param maxlen Maximum size of target buffer.
275 * \param source Source string to be encoded.
276 * \param SourceLen Length of the source string
277 * \returns encoded length; -1 if non success.
279 int webcit_rfc2047encode(char *target, int maxlen, char *source, long SourceLen)
281 const char headerStr[] = "=?UTF-8?Q?";
282 int need_to_encode = 0;
287 if ((source == NULL) ||
289 (SourceLen > maxlen)) return -1;
291 while ((!IsEmptyStr (&source[i])) &&
292 (need_to_encode == 0) &&
294 if (((unsigned char) source[i] < 32) ||
295 ((unsigned char) source[i] > 126)) {
301 if (!need_to_encode) {
302 memcpy (target, source, SourceLen);
303 target[SourceLen] = '\0';
307 if (sizeof (headerStr + SourceLen + 2) > maxlen)
309 memcpy (target, headerStr, sizeof (headerStr));
310 len = sizeof (headerStr) - 1;
311 for (i=0; (i < SourceLen) && (len + 3< maxlen) ; ++i) {
312 ch = (unsigned char) source[i];
313 if ((ch < 32) || (ch > 126) || (ch == 61)) {
314 sprintf(&target[len], "=%02X", ch);
318 sprintf(&target[len], "%c", ch);
323 if (len + 2 < maxlen) {
324 strcat(&target[len], "?=");
336 * Look for URL's embedded in a buffer and make them linkable. We use a
337 * target window in order to keep the Citadel session in its own window.
339 void url(char *buf, size_t bufsize)
341 int len, UrlLen, Offset, TrailerLen, outpos;
342 char *start, *end, *pos;
349 lprintf(1, "URL: content longer than buffer!");
353 for (pos = buf; (pos < end) && (start == NULL); ++pos) {
354 if (!strncasecmp(pos, "http://", 7))
356 if (!strncasecmp(pos, "ftp://", 6))
363 for (pos = buf+len; pos > start; --pos) {
364 if ( (!isprint(*pos))
383 UrlLen = end - start;
384 if (UrlLen > sizeof(urlbuf)){
385 lprintf(1, "URL: content longer than buffer!");
388 memcpy(urlbuf, start, UrlLen);
389 urlbuf[UrlLen] = '\0';
391 Offset = start - buf;
392 if ((Offset != 0) && (Offset < sizeof(outbuf)))
393 memcpy(outbuf, buf, Offset);
394 outpos = snprintf(&outbuf[Offset], sizeof(outbuf) - Offset,
395 "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
396 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
397 if (outpos >= sizeof(outbuf) - Offset) {
398 lprintf(1, "URL: content longer than buffer!");
402 TrailerLen = len - (end - start);
404 memcpy(outbuf + Offset + outpos, end, TrailerLen);
405 if (Offset + outpos + TrailerLen > bufsize) {
406 lprintf(1, "URL: content longer than buffer!");
409 memcpy (buf, outbuf, Offset + outpos + TrailerLen);
410 *(buf + Offset + outpos + TrailerLen) = '\0';
415 * \brief Turn a vCard "n" (name) field into something displayable.
416 * \param name the name field to convert
418 void vcard_n_prettyize(char *name)
423 original_name = strdup(name);
424 len = strlen(original_name);
425 for (i=0; i<5; ++i) {
427 if (original_name[len-1] == ' ') {
428 original_name[--len] = 0;
430 if (original_name[len-1] == ';') {
431 original_name[--len] = 0;
437 for (i=0; i<len; ++i) {
438 if (original_name[i] == ';') {
443 name[j++] = original_name[i];
454 * \brief preparse a vcard name
455 * display_vcard() calls this after parsing the textual vCard into
456 * our 'struct vCard' data object.
457 * This gets called instead of display_parsed_vcard() if we are only looking
458 * to extract the person's name instead of displaying the card.
459 * \param v the vcard to retrieve the name from
460 * \param storename where to put the name at
462 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
465 strcpy(storename, "");
467 name = vcard_get_prop(v, "n", 1, 0, 0);
469 strcpy(storename, name);
470 /* vcard_n_prettyize(storename); */
478 * \brief html print a vcard
479 * display_vcard() calls this after parsing the textual vCard into
480 * our 'struct vCard' data object.
482 * Set 'full' to nonzero to display the full card, otherwise it will only
483 * show a summary line.
485 * This code is a bit ugly, so perhaps an explanation is due: we do this
486 * in two passes through the vCard fields. On the first pass, we process
487 * fields we understand, and then render them in a pretty fashion at the
488 * end. Then we make a second pass, outputting all the fields we don't
489 * understand in a simple two-column name/value format.
490 * \param v the vCard to display
491 * \param full display all items of the vcard?
492 * \param msgnum Citadel message pointer
494 void display_parsed_vcard(struct vCard *v, int full, long msgnum) {
500 char *thisname, *thisvalue;
501 char firsttoken[SIZ];
510 strcpy(fullname, "");
518 name = vcard_get_prop(v, "fn", 1, 0, 0);
522 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
523 strcpy(fullname, name);
524 vcard_n_prettyize(fullname);
534 wprintf("<div align=center>"
535 "<table bgcolor=#aaaaaa width=50%%>");
536 for (pass=1; pass<=2; ++pass) {
538 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
540 thisname = strdup(v->prop[i].name);
541 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
543 for (j=0; j<num_tokens(thisname, ';'); ++j) {
544 extract_token(buf, thisname, j, ';', sizeof buf);
545 if (!strcasecmp(buf, "encoding=quoted-printable")) {
547 remove_token(thisname, j, ';');
549 if (!strcasecmp(buf, "encoding=base64")) {
551 remove_token(thisname, j, ';');
555 len = strlen(v->prop[i].value);
556 /* if we have some untagged QP, detect it here. */
557 if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
558 utf8ify_rfc822_string(v->prop[i].value);
561 // %ff can become 6 bytes in utf8
562 thisvalue = malloc(len * 2 + 3);
563 j = CtdlDecodeQuotedPrintable(
564 thisvalue, v->prop[i].value,
569 // ff will become one byte..
570 thisvalue = malloc(len + 50);
572 thisvalue, v->prop[i].value,
573 strlen(v->prop[i].value) );
576 thisvalue = strdup(v->prop[i].value);
579 /** Various fields we may encounter ***/
581 /** N is name, but only if there's no FN already there */
582 if (!strcasecmp(firsttoken, "n")) {
583 if (IsEmptyStr(fullname)) {
584 strcpy(fullname, thisvalue);
585 vcard_n_prettyize(fullname);
589 /** FN (full name) is a true 'display name' field */
590 else if (!strcasecmp(firsttoken, "fn")) {
591 strcpy(fullname, thisvalue);
595 else if (!strcasecmp(firsttoken, "title")) {
596 strcpy(title, thisvalue);
600 else if (!strcasecmp(firsttoken, "org")) {
601 strcpy(org, thisvalue);
604 else if (!strcasecmp(firsttoken, "email")) {
606 if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
608 "<a href=\"display_enter"
609 "?force_room=_MAIL_?recp=");
611 len = strlen(mailto);
612 urlesc(&mailto[len], SIZ - len, "\"");
613 len = strlen(mailto);
614 urlesc(&mailto[len], SIZ - len, fullname);
615 len = strlen(mailto);
616 urlesc(&mailto[len], SIZ - len, "\" <");
617 len = strlen(mailto);
618 urlesc(&mailto[len], SIZ - len, thisvalue);
619 len = strlen(mailto);
620 urlesc(&mailto[len], SIZ - len, ">");
622 strcat(mailto, "\">");
623 len = strlen(mailto);
624 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
625 strcat(mailto, "</A>");
627 else if (!strcasecmp(firsttoken, "tel")) {
628 if (!IsEmptyStr(phone)) strcat(phone, "<br />");
629 strcat(phone, thisvalue);
630 for (j=0; j<num_tokens(thisname, ';'); ++j) {
631 extract_token(buf, thisname, j, ';', sizeof buf);
632 if (!strcasecmp(buf, "tel"))
634 else if (!strcasecmp(buf, "work"))
635 strcat(phone, _(" (work)"));
636 else if (!strcasecmp(buf, "home"))
637 strcat(phone, _(" (home)"));
638 else if (!strcasecmp(buf, "cell"))
639 strcat(phone, _(" (cell)"));
647 else if (!strcasecmp(firsttoken, "adr")) {
650 wprintf(_("Address:"));
651 wprintf("</TD><TD>");
652 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
653 extract_token(buf, thisvalue, j, ';', sizeof buf);
654 if (!IsEmptyStr(buf)) {
656 if (j<3) wprintf("<br />");
660 wprintf("</TD></TR>\n");
663 else if (!strcasecmp(firsttoken, "photo") && full && pass == 2) {
664 // Only output on second pass
666 wprintf(_("Photo:"));
667 wprintf("</td><td>");
668 wprintf("<img src=\"/vcardphoto/%d/\" alt=\"Contact photo\"/>",msgnum);
669 wprintf("</td></tr>\n");
671 else if (!strcasecmp(firsttoken, "version")) {
674 else if (!strcasecmp(firsttoken, "rev")) {
677 else if (!strcasecmp(firsttoken, "label")) {
682 /*** Don't show extra fields. They're ugly.
686 wprintf("</TD><TD>");
688 wprintf("</TD></TR>\n");
698 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
699 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
700 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
701 "<FONT SIZE=+1><B>");
703 wprintf("</B></FONT>");
704 if (!IsEmptyStr(title)) {
705 wprintf("<div align=right>");
709 if (!IsEmptyStr(org)) {
710 wprintf("<div align=right>");
714 wprintf("</TD></TR>\n");
716 if (!IsEmptyStr(phone)) {
718 wprintf(_("Telephone:"));
719 wprintf("</td><td>%s</td></tr>\n", phone);
721 if (!IsEmptyStr(mailto)) {
723 wprintf(_("E-mail:"));
724 wprintf("</td><td>%s</td></tr>\n", mailto);
730 wprintf("</table></div>\n");
736 * \brief Display a textual vCard
737 * (Converts to a vCard object and then calls the actual display function)
738 * Set 'full' to nonzero to display the whole card instead of a one-liner.
739 * Or, if "storename" is non-NULL, just store the person's name in that
740 * buffer instead of displaying the card at all.
741 * \param vcard_source the buffer containing the vcard text
742 * \param alpha what???
743 * \param full should we usse all lines?
744 * \param storename where to store???
745 * \param msgnum Citadel message pointer
747 void display_vcard(char *vcard_source, char alpha, int full, char *storename,
754 v = vcard_load(vcard_source);
755 if (v == NULL) return;
757 name = vcard_get_prop(v, "n", 1, 0, 0);
759 utf8ify_rfc822_string(name);
764 if (storename != NULL) {
765 fetchname_parsed_vcard(v, storename);
767 else if ( (alpha == 0)
768 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
769 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
771 display_parsed_vcard(v, full,msgnum);
785 * I wanna SEE that message!
787 * msgnum Message number to display
788 * printable_view Nonzero to display a printable view
789 * section Optional for encapsulated message/rfc822 submessage
791 void read_message(long msgnum, int printable_view, char *section) {
793 char mime_partnum[256] = "";
794 char mime_name[256] = "";
795 char mime_filename[256] = "";
796 char escaped_mime_filename[256] = "";
797 char mime_content_type[256] = "";
798 const char *mime_content_type_ptr;
799 char mime_charset[256] = "";
800 char mime_disposition[256] = "";
802 struct attach_link *attach_links = NULL;
803 int num_attach_links = 0;
804 char mime_submessages[256] = "";
805 char m_subject[1024] = "";
806 char m_cc[1024] = "";
810 char reply_to[512] = "";
811 char reply_all[4096] = "";
812 char reply_references[1024] = "";
813 char reply_inreplyto[256] = "";
819 char vcard_partnum[256] = "";
820 char cal_partnum[256] = "";
821 char *part_source = NULL;
822 char msg4_partnum[32] = "";
824 iconv_t ic = (iconv_t)(-1) ;
825 char *ibuf; /**< Buffer of characters to be converted */
826 char *obuf; /**< Buffer for converted characters */
827 size_t ibuflen; /**< Length of input buffer */
828 size_t obuflen; /**< Length of output buffer */
829 char *osav; /**< Saved pointer to output buffer */
832 strcpy(mime_content_type, "text/plain");
833 strcpy(mime_charset, "us-ascii");
834 strcpy(mime_submessages, "");
836 serv_printf("MSG4 %ld|%s", msgnum, section);
837 serv_getln(buf, sizeof buf);
840 wprintf(_("ERROR:"));
841 wprintf("</strong> %s<br />\n", &buf[4]);
845 /** begin everythingamundo table */
846 if (!printable_view) {
847 wprintf("<div class=\"fix_scrollbar_bug message\" ");
848 wprintf("onMouseOver=document.getElementById(\"msg%ld\").style.visibility=\"visible\" ", msgnum);
849 wprintf("onMouseOut=document.getElementById(\"msg%ld\").style.visibility=\"hidden\" >", msgnum);
852 /** begin message header table */
853 wprintf("<div class=\"message_header\">");
855 strcpy(m_subject, "");
858 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
859 if (!strcmp(buf, "000")) {
861 wprintf(_("unexpected end of message"));
862 wprintf(" (1)</i><br /><br />\n");
866 if (!strncasecmp(buf, "nhdr=yes", 8))
870 if (!strncasecmp(buf, "type=", 5))
871 format_type = atoi(&buf[5]);
872 if (!strncasecmp(buf, "from=", 5)) {
873 strcpy(from, &buf[5]);
875 wprintf("<a href=\"showuser?who=");
876 utf8ify_rfc822_string(from);
882 if (!strncasecmp(buf, "subj=", 5)) {
883 safestrncpy(m_subject, &buf[5], sizeof m_subject);
885 if (!strncasecmp(buf, "msgn=", 5)) {
886 safestrncpy(reply_inreplyto, &buf[5], sizeof reply_inreplyto);
888 if (!strncasecmp(buf, "wefw=", 5)) {
889 safestrncpy(reply_references, &buf[5], sizeof reply_references);
891 if (!strncasecmp(buf, "cccc=", 5)) {
893 safestrncpy(m_cc, &buf[5], sizeof m_cc);
894 if (!IsEmptyStr(reply_all)) {
895 strcat(reply_all, ", ");
897 len = strlen(reply_all);
898 safestrncpy(&reply_all[len], &buf[5],
899 (sizeof reply_all - len) );
901 if ((!strncasecmp(buf, "hnod=", 5))
902 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
903 wprintf("(%s) ", &buf[5]);
905 if ((!strncasecmp(buf, "room=", 5))
906 && (strcasecmp(&buf[5], WC->wc_roomname))
907 && (!IsEmptyStr(&buf[5])) ) {
909 wprintf("%s> ", &buf[5]);
911 if (!strncasecmp(buf, "rfca=", 5)) {
912 strcpy(rfca, &buf[5]);
918 if (!strncasecmp(buf, "node=", 5)) {
919 strcpy(node, &buf[5]);
920 if ( ((WC->room_flags & QR_NETWORK)
921 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
922 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
923 && (IsEmptyStr(rfca))
925 wprintf("@%s ", &buf[5]);
928 if (!strncasecmp(buf, "rcpt=", 5)) {
931 if (!IsEmptyStr(reply_all)) {
932 strcat(reply_all, ", ");
934 len = strlen(reply_all);
935 safestrncpy(&reply_all[len], &buf[5],
936 (sizeof reply_all - len) );
937 utf8ify_rfc822_string(&buf[5]);
941 if (!strncasecmp(buf, "time=", 5)) {
942 webcit_fmt_date(now, atol(&buf[5]), 0);
948 if (!strncasecmp(buf, "part=", 5)) {
949 extract_token(mime_name, &buf[5], 0, '|', sizeof mime_filename);
950 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
951 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
952 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
953 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
954 mime_length = extract_int(&buf[5], 5);
957 striplt(mime_filename);
958 if ( (IsEmptyStr(mime_filename)) && (!IsEmptyStr(mime_name)) ) {
959 strcpy(mime_filename, mime_name);
962 if (!strcasecmp(mime_content_type, "message/rfc822")) {
963 if (!IsEmptyStr(mime_submessages)) {
964 strcat(mime_submessages, "|");
966 strcat(mime_submessages, mime_partnum);
968 else if ((!strcasecmp(mime_disposition, "inline"))
969 && (!strncasecmp(mime_content_type, "image/", 6)) ){
971 attach_links = realloc(attach_links,
972 (num_attach_links*sizeof(struct attach_link)));
973 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
974 snprintf(attach_links[num_attach_links-1].html, 1024,
975 "<img src=\"mimepart/%ld/%s/%s\">",
976 msgnum, mime_partnum, mime_filename);
978 else if ( ( (!strcasecmp(mime_disposition, "attachment"))
979 || (!strcasecmp(mime_disposition, "inline"))
980 || (!strcasecmp(mime_disposition, ""))
981 ) && (!IsEmptyStr(mime_content_type))
984 attach_links = realloc(attach_links,
985 (num_attach_links*sizeof(struct attach_link)));
986 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
987 utf8ify_rfc822_string(mime_filename);
989 mime_content_type_ptr = mime_content_type;
990 if (strcasecmp(mime_content_type, "application/octet-stream") == 0) {
991 mime_content_type_ptr = GuessMimeByFilename(mime_filename,
992 strlen(mime_filename));
994 urlesc(escaped_mime_filename, 265, mime_filename);
995 snprintf(attach_links[num_attach_links-1].html, 1024,
996 "<img src=\"display_mime_icon?type=%s\" "
997 "border=0 align=middle>\n"
998 "%s (%s, %d bytes) [ "
999 "<a href=\"mimepart/%ld/%s/%s\""
1000 "target=\"wc.%ld.%s\">%s</a>"
1002 "<a href=\"mimepart_download/%ld/%s/%s\">%s</a>"
1004 mime_content_type_ptr,
1006 mime_content_type, mime_length,
1007 msgnum, mime_partnum, escaped_mime_filename,
1008 msgnum, mime_partnum,
1010 msgnum, mime_partnum, escaped_mime_filename,
1015 /** begin handler prep ***/
1016 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1017 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1018 strcpy(vcard_partnum, mime_partnum);
1021 if ( (!strcasecmp(mime_content_type, "text/calendar"))
1022 || (!strcasecmp(mime_content_type, "application/ics")) ) {
1023 strcpy(cal_partnum, mime_partnum);
1026 /** end handler prep ***/
1032 /* Trim down excessively long lists of thread references. We eliminate the
1033 * second one in the list so that the thread root remains intact.
1035 int rrtok = num_tokens(reply_references, '|');
1036 int rrlen = strlen(reply_references);
1037 if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
1038 remove_token(reply_references, 1, '|');
1041 /* Generate a reply-to address */
1042 if (!IsEmptyStr(rfca)) {
1043 if (!IsEmptyStr(from)) {
1044 snprintf(reply_to, sizeof(reply_to), "%s <%s>", from, rfca);
1047 strcpy(reply_to, rfca);
1051 if ((!IsEmptyStr(node))
1052 && (strcasecmp(node, serv_info.serv_nodename))
1053 && (strcasecmp(node, serv_info.serv_humannode)) ) {
1054 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
1058 snprintf(reply_to, sizeof(reply_to), "%s", from);
1066 utf8ify_rfc822_string(m_cc);
1067 utf8ify_rfc822_string(m_subject);
1069 /** start msg buttons */
1071 if (!printable_view) {
1072 wprintf("<p id=\"msg%ld\" class=\"msgbuttons\" >\n",msgnum);
1075 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
1076 wprintf("<a href=\"display_enter");
1077 if (WC->is_mailbox) {
1078 wprintf("?replyquote=%ld", msgnum);
1081 urlescputs(reply_to);
1082 if (!IsEmptyStr(m_subject)) {
1083 wprintf("?subject=");
1084 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
1085 urlescputs(m_subject);
1087 wprintf("?references=");
1088 if (!IsEmptyStr(reply_references)) {
1089 urlescputs(reply_references);
1092 urlescputs(reply_inreplyto);
1093 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Reply"));
1097 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
1098 if (!WC->is_mailbox) {
1099 wprintf("<a href=\"display_enter");
1100 wprintf("?replyquote=%ld", msgnum);
1102 urlescputs(reply_to);
1103 if (!IsEmptyStr(m_subject)) {
1104 wprintf("?subject=");
1105 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
1106 urlescputs(m_subject);
1108 wprintf("?references=");
1109 if (!IsEmptyStr(reply_references)) {
1110 urlescputs(reply_references);
1113 urlescputs(reply_inreplyto);
1114 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyQuoted"));
1119 if (WC->wc_view == VIEW_MAILBOX) {
1120 wprintf("<a href=\"display_enter");
1121 wprintf("?replyquote=%ld", msgnum);
1123 urlescputs(reply_to);
1125 urlescputs(reply_all);
1126 if (!IsEmptyStr(m_subject)) {
1127 wprintf("?subject=");
1128 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
1129 urlescputs(m_subject);
1131 wprintf("?references=");
1132 if (!IsEmptyStr(reply_references)) {
1133 urlescputs(reply_references);
1136 urlescputs(reply_inreplyto);
1137 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyAll"));
1141 if (WC->wc_view == VIEW_MAILBOX) {
1142 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
1143 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
1144 urlescputs(m_subject);
1145 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Forward"));
1148 /* If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
1149 if ( (WC->is_room_aide) || (WC->is_mailbox) || (WC->room_flags2 & QR2_COLLABDEL) ) {
1151 wprintf("<a href=\"confirm_move_msg?msgid=%ld\"><span>[</span>%s<span>]</span></a> ",
1155 wprintf("<a href=\"delete_msg?msgid=%ld\" "
1156 "onClick=\"return confirm('%s');\">"
1157 "<span>[</span>%s<span>]</span> "
1158 "</a> ", msgnum, _("Delete this message?"), _("Delete")
1163 wprintf("<a href=\"#\" onClick=\"window.open('msgheaders/%ld', 'headers%ld', 'toolbar=no,location=no,directories=no,copyhistory=no,status=yes,scrollbars=yes,resizable=yes,width=600,height=400'); \" >"
1164 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Headers"));
1168 wprintf("<a href=\"#\" onClick=\"window.open('printmsg/%ld', 'print%ld', 'toolbar=no,location=no,directories=no,copyhistory=no,status=yes,scrollbars=yes,resizable=yes,width=600,height=400'); \" >"
1169 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Print"));
1175 if (!IsEmptyStr(m_cc)) {
1182 if (!IsEmptyStr(m_subject)) {
1183 wprintf("<p class=\"message_subject\">");
1184 wprintf(_("Subject:"));
1193 wprintf("<div class=\"message_content\">");
1196 * Learn the content type
1198 strcpy(mime_content_type, "text/plain");
1199 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1200 if (!strcmp(buf, "000")) {
1201 /* This is not necessarily an error condition. See bug #226. */
1204 if (!strncasecmp(buf, "X-Citadel-MSG4-Partnum:", 23)) {
1205 safestrncpy(msg4_partnum, &buf[23], sizeof(msg4_partnum));
1206 striplt(msg4_partnum);
1208 if (!strncasecmp(buf, "Content-type:", 13)) {
1210 safestrncpy(mime_content_type, &buf[13], sizeof(mime_content_type));
1211 striplt(mime_content_type);
1212 len = strlen(mime_content_type);
1213 for (i=0; i<len; ++i) {
1214 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1215 safestrncpy(mime_charset, &mime_content_type[i+8],
1216 sizeof mime_charset);
1219 for (i=0; i<len; ++i) {
1220 if (mime_content_type[i] == ';') {
1221 mime_content_type[i] = 0;
1225 len = strlen(mime_charset);
1226 for (i=0; i<len; ++i) {
1227 if (mime_charset[i] == ';') {
1228 mime_charset[i] = 0;
1235 /* Set up a character set conversion if we need to (and if we can) */
1237 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
1238 if ( (strcasecmp(mime_charset, "us-ascii"))
1239 && (strcasecmp(mime_charset, "UTF-8"))
1240 && (strcasecmp(mime_charset, ""))
1242 ic = ctdl_iconv_open("UTF-8", mime_charset);
1243 if (ic == (iconv_t)(-1) ) {
1244 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1245 __FILE__, __LINE__, mime_charset, strerror(errno));
1250 /* Messages in legacy Citadel variformat get handled thusly... */
1251 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1255 /* Boring old 80-column fixed format text gets handled this way... */
1256 else if ( (!strcasecmp(mime_content_type, "text/plain"))
1257 || (!strcasecmp(mime_content_type, "text")) ) {
1259 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1262 if ((len > 0) && buf[len-1] == '\n') buf[--len] = 0;
1263 if ((len > 0) && buf[len-1] == '\r') buf[--len] = 0;
1266 if (ic != (iconv_t)(-1) ) {
1268 ibuflen = strlen(ibuf);
1270 obuf = (char *) malloc(obuflen);
1272 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1273 osav[SIZ-obuflen] = 0;
1274 safestrncpy(buf, osav, sizeof buf);
1280 while ((!IsEmptyStr(buf)) && (isspace(buf[len-1])))
1283 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1284 wprintf("<blockquote>");
1286 } else if ((bq == 1) &&
1287 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1288 wprintf("</blockquote>");
1292 url(buf, sizeof(buf));
1294 wprintf("</tt><br />\n");
1296 wprintf("</i><br />");
1299 else /** HTML is fun, but we've got to strip it first */
1300 if (!strcasecmp(mime_content_type, "text/html")) {
1301 output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
1304 /** Unknown weirdness */
1306 wprintf(_("I don't know how to display %s"), mime_content_type);
1307 wprintf("<br />\n", mime_content_type);
1308 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1311 ENDBODY: /* If there are attached submessages, display them now... */
1313 if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
1314 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1315 extract_token(buf, mime_submessages, i, '|', sizeof buf);
1316 /** use printable_view to suppress buttons */
1317 wprintf("<blockquote>");
1318 read_message(msgnum, 1, buf);
1319 wprintf("</blockquote>");
1324 /** Afterwards, offer links to download attachments 'n' such */
1325 if ( (num_attach_links > 0) && (!section[0]) ) {
1326 for (i=0; i<num_attach_links; ++i) {
1327 if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
1328 wprintf("%s", attach_links[i].html);
1333 /** Handler for vCard parts */
1334 if (!IsEmptyStr(vcard_partnum)) {
1335 part_source = load_mimepart(msgnum, vcard_partnum);
1336 if (part_source != NULL) {
1338 /** If it's my vCard I can edit it */
1339 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1340 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1341 || (WC->wc_view == VIEW_ADDRESSBOOK)
1343 wprintf("<a href=\"edit_vcard?"
1344 "msgnum=%ld?partnum=%s\">",
1345 msgnum, vcard_partnum);
1346 wprintf("[%s]</a>", _("edit"));
1349 /** In all cases, display the full card */
1350 display_vcard(part_source, 0, 1, NULL,msgnum);
1354 /** Handler for calendar parts */
1355 if (!IsEmptyStr(cal_partnum)) {
1356 part_source = load_mimepart(msgnum, cal_partnum);
1357 if (part_source != NULL) {
1358 cal_process_attachment(part_source,
1359 msgnum, cal_partnum);
1368 wprintf("</div>\n");
1370 /** end everythingamundo table */
1371 if (!printable_view) {
1372 wprintf("</div>\n");
1375 if (num_attach_links > 0) {
1380 if (ic != (iconv_t)(-1) ) {
1389 * \brief Unadorned HTML output of an individual message, suitable
1390 * for placing in a hidden iframe, for printing, or whatever
1392 * \param msgnum_as_string Message number, as a string instead of as a long int
1394 void embed_message(char *msgnum_as_string) {
1397 msgnum = atol(msgnum_as_string);
1398 begin_ajax_response();
1399 read_message(msgnum, 0, "");
1400 end_ajax_response();
1405 * \brief Printable view of a message
1407 * \param msgnum_as_string Message number, as a string instead of as a long int
1409 void print_message(char *msgnum_as_string) {
1412 msgnum = atol(msgnum_as_string);
1413 output_headers(0, 0, 0, 0, 0, 0);
1415 wprintf("Content-type: text/html\r\n"
1417 "Connection: close\r\n",
1421 wprintf("\r\n\r\n<html>\n"
1422 "<head><title>Printable view</title></head>\n"
1423 "<body onLoad=\" window.print(); window.close(); \">\n"
1426 read_message(msgnum, 1, "");
1428 wprintf("\n</body></html>\n\n");
1435 * \brief Display a message's headers
1437 * \param msgnum_as_string Message number, as a string instead of as a long int
1439 void display_headers(char *msgnum_as_string) {
1443 msgnum = atol(msgnum_as_string);
1444 output_headers(0, 0, 0, 0, 0, 0);
1446 wprintf("Content-type: text/plain\r\n"
1448 "Connection: close\r\n",
1452 serv_printf("MSG2 %ld|3", msgnum);
1453 serv_getln(buf, sizeof buf);
1454 if (buf[0] == '1') {
1455 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1456 wprintf("%s\n", buf);
1466 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1467 * or 'reply quoted' operations.
1469 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1470 * in this function. Doing so would throw a JavaScript error in the
1471 * 'supplied text' argument to the editor.
1473 * \param msgnum Message number of the message we want to quote
1474 * \param forward_attachments Nonzero if we want attachments to be forwarded
1476 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1478 char mime_partnum[256];
1479 char mime_filename[256];
1480 char mime_content_type[256];
1481 char mime_charset[256];
1482 char mime_disposition[256];
1484 char *attachments = NULL;
1486 int num_attachments = 0;
1487 struct wc_attachment *att, *aptr;
1488 char m_subject[1024];
1495 int format_type = 0;
1500 iconv_t ic = (iconv_t)(-1) ;
1501 char *ibuf; /**< Buffer of characters to be converted */
1502 char *obuf; /**< Buffer for converted characters */
1503 size_t ibuflen; /**< Length of input buffer */
1504 size_t obuflen; /**< Length of output buffer */
1505 char *osav; /**< Saved pointer to output buffer */
1511 strcpy(reply_to, "");
1512 strcpy(mime_content_type, "text/plain");
1513 strcpy(mime_charset, "us-ascii");
1515 serv_printf("MSG4 %ld", msgnum);
1516 serv_getln(buf, sizeof buf);
1517 if (buf[0] != '1') {
1518 wprintf(_("ERROR:"));
1519 wprintf("%s<br />", &buf[4]);
1523 strcpy(m_subject, "");
1525 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1526 if (!strcmp(buf, "000")) {
1527 wprintf("%s (3)", _("unexpected end of message"));
1530 if (include_headers) {
1531 if (!strncasecmp(buf, "nhdr=yes", 8))
1535 if (!strncasecmp(buf, "type=", 5))
1536 format_type = atoi(&buf[5]);
1537 if (!strncasecmp(buf, "from=", 5)) {
1538 strcpy(from, &buf[5]);
1539 wprintf(_("from "));
1540 utf8ify_rfc822_string(from);
1543 if (!strncasecmp(buf, "subj=", 5)) {
1544 strcpy(m_subject, &buf[5]);
1546 if ((!strncasecmp(buf, "hnod=", 5))
1547 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1548 wprintf("(%s) ", &buf[5]);
1550 if ((!strncasecmp(buf, "room=", 5))
1551 && (strcasecmp(&buf[5], WC->wc_roomname))
1552 && (!IsEmptyStr(&buf[5])) ) {
1554 wprintf("%s> ", &buf[5]);
1556 if (!strncasecmp(buf, "rfca=", 5)) {
1557 strcpy(rfca, &buf[5]);
1562 if (!strncasecmp(buf, "node=", 5)) {
1563 strcpy(node, &buf[5]);
1564 if ( ((WC->room_flags & QR_NETWORK)
1565 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1566 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1567 && (IsEmptyStr(rfca))
1569 wprintf("@%s ", &buf[5]);
1572 if (!strncasecmp(buf, "rcpt=", 5)) {
1574 strcpy(to, &buf[5]);
1575 utf8ify_rfc822_string(to);
1578 if (!strncasecmp(buf, "time=", 5)) {
1579 webcit_fmt_date(now, atol(&buf[5]), 0);
1580 wprintf("%s ", now);
1585 * Save attachment info for later. We can't start downloading them
1586 * yet because we're in the middle of a server transaction.
1588 if (!strncasecmp(buf, "part=", 5)) {
1589 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1592 sprintf(ptr, "%s%s\n",
1593 ((attachments != NULL) ? attachments : ""),
1598 lprintf(9, "attachments=<%s>\n", attachments);
1604 if (include_headers) {
1607 utf8ify_rfc822_string(m_subject);
1608 if (!IsEmptyStr(m_subject)) {
1609 wprintf(_("Subject:"));
1611 msgescputs(m_subject);
1622 * Learn the content type
1624 strcpy(mime_content_type, "text/plain");
1625 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1626 if (!strcmp(buf, "000")) {
1627 wprintf("%s (4)", _("unexpected end of message"));
1630 if (!strncasecmp(buf, "Content-type: ", 14)) {
1632 safestrncpy(mime_content_type, &buf[14],
1633 sizeof(mime_content_type));
1634 for (i=0; i<strlen(mime_content_type); ++i) {
1635 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1636 safestrncpy(mime_charset, &mime_content_type[i+8],
1637 sizeof mime_charset);
1640 len = strlen(mime_content_type);
1641 for (i=0; i<len; ++i) {
1642 if (mime_content_type[i] == ';') {
1643 mime_content_type[i] = 0;
1647 len = strlen(mime_charset);
1648 for (i=0; i<len; ++i) {
1649 if (mime_charset[i] == ';') {
1650 mime_charset[i] = 0;
1657 /** Set up a character set conversion if we need to (and if we can) */
1659 if ( (strcasecmp(mime_charset, "us-ascii"))
1660 && (strcasecmp(mime_charset, "UTF-8"))
1661 && (strcasecmp(mime_charset, ""))
1663 ic = ctdl_iconv_open("UTF-8", mime_charset);
1664 if (ic == (iconv_t)(-1) ) {
1665 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1666 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1671 /** Messages in legacy Citadel variformat get handled thusly... */
1672 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1676 /* Boring old 80-column fixed format text gets handled this way... */
1677 else if (!strcasecmp(mime_content_type, "text/plain")) {
1678 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1681 if (buf[len-1] == '\n') buf[--len] = 0;
1682 if (buf[len-1] == '\r') buf[--len] = 0;
1685 if (ic != (iconv_t)(-1) ) {
1689 obuf = (char *) malloc(obuflen);
1691 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1692 osav[SIZ-obuflen] = 0;
1693 safestrncpy(buf, osav, sizeof buf);
1699 while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
1702 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1703 wprintf("<blockquote>");
1705 } else if ((bq == 1) &&
1706 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1707 wprintf("</blockquote>");
1711 url(buf, sizeof(buf));
1713 wprintf("</tt><br />");
1715 wprintf("</i><br />");
1718 /** HTML just gets escaped and stuffed back into the editor */
1719 else if (!strcasecmp(mime_content_type, "text/html")) {
1720 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1724 }//// TODO: charset? utf8?
1726 /** Unknown weirdness ... don't know how to handle this content type */
1728 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1732 /** end of body handler */
1735 * If there were attachments, we have to download them and insert them
1736 * into the attachment chain for the forwarded message we are composing.
1738 if ( (forward_attachments) && (num_attachments) ) {
1739 for (i=0; i<num_attachments; ++i) {
1740 extract_token(buf, attachments, i, '\n', sizeof buf);
1741 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1742 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1743 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1744 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1745 mime_length = extract_int(buf, 5);
1748 * tracing ... uncomment if necessary
1751 lprintf(9, "fwd filename: %s\n", mime_filename);
1752 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1753 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1754 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1755 lprintf(9, "fwd length : %d\n", mime_length);
1757 if ( (!strcasecmp(mime_disposition, "inline"))
1758 || (!strcasecmp(mime_disposition, "attachment")) ) {
1760 /* Create an attachment struct from this mime part... */
1761 att = malloc(sizeof(struct wc_attachment));
1762 memset(att, 0, sizeof(struct wc_attachment));
1763 att->length = mime_length;
1764 strcpy(att->content_type, mime_content_type);
1765 strcpy(att->filename, mime_filename);
1767 att->data = load_mimepart(msgnum, mime_partnum);
1769 /* And add it to the list. */
1770 if (WC->first_attachment == NULL) {
1771 WC->first_attachment = att;
1774 aptr = WC->first_attachment;
1775 while (aptr->next != NULL) aptr = aptr->next;
1784 if (ic != (iconv_t)(-1) ) {
1789 if (attachments != NULL) {
1795 * \brief Display one row in the mailbox summary view
1797 * \param num The row number to be displayed
1799 void display_summarized(int num) {
1802 wprintf("<tr id=\"m%ld\" style=\"font-weight:%s;\" "
1803 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1804 WC->summ[num].msgnum,
1805 (WC->summ[num].is_new ? "bold" : "normal"),
1806 WC->summ[num].msgnum
1809 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1811 escputs(WC->summ[num].subj);//////////////////////////////////TODO: QP DECODE
1814 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1815 escputs(WC->summ[num].from);
1818 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1819 webcit_fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1829 * \brief display the adressbook overview
1830 * \param msgnum the citadel message number
1831 * \param alpha what????
1833 void display_addressbook(long msgnum, char alpha) {
1835 char mime_partnum[SIZ];
1836 char mime_filename[SIZ];
1837 char mime_content_type[SIZ];
1838 char mime_disposition[SIZ];
1840 char vcard_partnum[SIZ];
1841 char *vcard_source = NULL;
1842 struct message_summary summ;
1844 memset(&summ, 0, sizeof(summ));
1845 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1847 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1849 serv_getln(buf, sizeof buf);
1850 if (buf[0] != '1') return;
1852 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1853 if (!strncasecmp(buf, "part=", 5)) {
1854 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1855 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1856 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1857 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1858 mime_length = extract_int(&buf[5], 5);
1860 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1861 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1862 strcpy(vcard_partnum, mime_partnum);
1868 if (!IsEmptyStr(vcard_partnum)) {
1869 vcard_source = load_mimepart(msgnum, vcard_partnum);
1870 if (vcard_source != NULL) {
1872 /** Display the summary line */
1873 display_vcard(vcard_source, alpha, 0, NULL,msgnum);
1875 /** If it's my vCard I can edit it */
1876 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1877 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1878 || (WC->wc_view == VIEW_ADDRESSBOOK)
1880 wprintf("<a href=\"edit_vcard?"
1881 "msgnum=%ld?partnum=%s\">",
1882 msgnum, vcard_partnum);
1883 wprintf("[%s]</a>", _("edit"));
1895 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1896 * \param namebuf name to analyze, reverse if nescessary
1898 void lastfirst_firstlast(char *namebuf) {
1899 char firstname[SIZ];
1903 if (namebuf == NULL) return;
1904 if (strchr(namebuf, ';') != NULL) return;
1906 i = num_tokens(namebuf, ' ');
1909 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1910 remove_token(namebuf, i-1, ' ');
1911 strcpy(firstname, namebuf);
1912 sprintf(namebuf, "%s; %s", lastname, firstname);
1916 * \brief fetch what??? name
1917 * \param msgnum the citadel message number
1918 * \param namebuf where to put the name in???
1920 void fetch_ab_name(long msgnum, char *namebuf) {
1922 char mime_partnum[SIZ];
1923 char mime_filename[SIZ];
1924 char mime_content_type[SIZ];
1925 char mime_disposition[SIZ];
1927 char vcard_partnum[SIZ];
1928 char *vcard_source = NULL;
1930 struct message_summary summ;
1932 if (namebuf == NULL) return;
1933 strcpy(namebuf, "");
1935 memset(&summ, 0, sizeof(summ));
1936 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1938 sprintf(buf, "MSG0 %ld|0", msgnum); /** unfortunately we need the mime info now */
1940 serv_getln(buf, sizeof buf);
1941 if (buf[0] != '1') return;
1943 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1944 if (!strncasecmp(buf, "part=", 5)) {
1945 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1946 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1947 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1948 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1949 mime_length = extract_int(&buf[5], 5);
1951 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1952 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1953 strcpy(vcard_partnum, mime_partnum);
1959 if (!IsEmptyStr(vcard_partnum)) {
1960 vcard_source = load_mimepart(msgnum, vcard_partnum);
1961 if (vcard_source != NULL) {
1963 /* Grab the name off the card */
1964 display_vcard(vcard_source, 0, 0, namebuf,msgnum);
1970 lastfirst_firstlast(namebuf);
1972 len = strlen(namebuf);
1973 for (i=0; i<len; ++i) {
1974 if (namebuf[i] != ';') return;
1976 strcpy(namebuf, _("(no name)"));
1982 * \brief Record compare function for sorting address book indices
1983 * \param ab1 adressbook one
1984 * \param ab2 adressbook two
1986 int abcmp(const void *ab1, const void *ab2) {
1988 (((const struct addrbookent *)ab1)->ab_name),
1989 (((const struct addrbookent *)ab2)->ab_name)
1995 * \brief Helper function for do_addrbook_view()
1996 * Converts a name into a three-letter tab label
1997 * \param tabbuf the tabbuffer to add name to
1998 * \param name the name to add to the tabbuffer
2000 void nametab(char *tabbuf, long len, char *name) {
2001 stresc(tabbuf, len, name, 0, 0);
2002 tabbuf[0] = toupper(tabbuf[0]);
2003 tabbuf[1] = tolower(tabbuf[1]);
2004 tabbuf[2] = tolower(tabbuf[2]);
2010 * \brief Render the address book using info we gathered during the scan
2011 * \param addrbook the addressbook to render
2012 * \param num_ab the number of the addressbook
2014 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
2018 static int NAMESPERPAGE = 60;
2021 char tabfirst_label[64];
2023 char tablast_label[64];
2024 char this_tablabel[64];
2029 wprintf("<br /><br /><br /><div align=\"center\"><i>");
2030 wprintf(_("This address book is empty."));
2031 wprintf("</i></div>\n");
2036 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
2039 num_pages = (num_ab / NAMESPERPAGE) + 1;
2041 tablabels = malloc(num_pages * sizeof (char *));
2042 if (tablabels == NULL) {
2043 wprintf("<br /><br /><br /><div align=\"center\"><i>");
2044 wprintf(_("An internal error has occurred."));
2045 wprintf("</i></div>\n");
2049 for (i=0; i<num_pages; ++i) {
2050 tabfirst = i * NAMESPERPAGE;
2051 tablast = tabfirst + NAMESPERPAGE - 1;
2052 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
2053 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
2054 nametab(tablast_label, 64, addrbook[tablast].ab_name);
2055 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
2056 tablabels[i] = strdup(this_tablabel);
2059 tabbed_dialog(num_pages, tablabels);
2062 for (i=0; i<num_ab; ++i) {
2064 if ((i / NAMESPERPAGE) != page) { /* New tab */
2065 page = (i / NAMESPERPAGE);
2067 wprintf("</tr></table>\n");
2068 end_tab(page-1, num_pages);
2070 begin_tab(page, num_pages);
2071 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
2075 if ((displayed % 4) == 0) {
2076 if (displayed > 0) {
2080 wprintf("<tr bgcolor=\"#%s\">",
2081 (bg ? "DDDDDD" : "FFFFFF")
2087 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
2088 addrbook[i].ab_msgnum);
2089 wprintf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
2090 vcard_n_prettyize(addrbook[i].ab_name);
2091 escputs(addrbook[i].ab_name);
2092 wprintf("</a></td>\n");
2096 wprintf("</tr></table>\n");
2097 end_tab((num_pages-1), num_pages);
2099 for (i=0; i<num_pages; ++i) {
2108 * \brief load message pointers from the server
2109 * \param servcmd the citadel command to send to the citserver
2110 * \param with_headers what headers???
2112 int load_msg_ptrs(char *servcmd, int with_headers)
2124 int num_summ_alloc = 0;
2126 if (WC->summ != NULL) {
2131 num_summ_alloc = 100;
2133 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
2136 maxload = sizeof(WC->msgarr) / sizeof(long) ;
2138 serv_getln(buf, sizeof buf);
2139 if (buf[0] != '1') {
2142 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2143 if (nummsgs < maxload) {
2144 WC->msgarr[nummsgs] = extract_long(buf, 0);
2145 datestamp = extract_long(buf, 1);
2146 extract_token(fullname, buf, 2, '|', sizeof fullname);
2147 extract_token(nodename, buf, 3, '|', sizeof nodename);
2148 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
2149 extract_token(subject, buf, 5, '|', sizeof subject);
2153 if (nummsgs > num_summ_alloc) {
2154 num_summ_alloc *= 2;
2155 WC->summ = realloc(WC->summ,
2156 num_summ_alloc * sizeof(struct message_summary));
2160 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
2161 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
2162 safestrncpy(WC->summ[nummsgs-1].subj,
2163 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
2164 if (!IsEmptyStr(fullname)) {
2165 /** Handle senders with RFC2047 encoding */
2166 utf8ify_rfc822_string(fullname);
2167 safestrncpy(WC->summ[nummsgs-1].from,
2168 fullname, sizeof WC->summ[nummsgs-1].from);
2170 if (!IsEmptyStr(subject)) {
2171 /** Handle subjects with RFC2047 encoding */
2172 utf8ify_rfc822_string(subject);
2173 safestrncpy(WC->summ[nummsgs-1].subj, subject,
2174 sizeof WC->summ[nummsgs-1].subj);
2176 sbjlen = Ctdl_Utf8StrLen(WC->summ[nummsgs-1].subj);
2179 ptr = Ctdl_Utf8StrCut(WC->summ[nummsgs-1].subj, 72);
2184 if (!IsEmptyStr(nodename)) {
2185 if ( ((WC->room_flags & QR_NETWORK)
2186 || ((strcasecmp(nodename, serv_info.serv_nodename)
2187 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
2189 strcat(WC->summ[nummsgs-1].from, " @ ");
2190 strcat(WC->summ[nummsgs-1].from, nodename);
2194 WC->summ[nummsgs-1].date = datestamp;
2196 /** Handle senders with RFC2047 encoding */
2197 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
2198 if (strlen(WC->summ[nummsgs-1].from) > 25) {
2199 strcpy(&WC->summ[nummsgs-1].from[22], "...");
2208 * \brief qsort() compatible function to compare two longs in descending order.
2210 * \param s1 first number to compare
2211 * \param s2 second number to compare
2213 int longcmp_r(const void *s1, const void *s2) {
2220 if (l1 > l2) return(-1);
2221 if (l1 < l2) return(+1);
2227 * \brief qsort() compatible function to compare two message summary structs by ascending subject.
2229 * \param s1 first item to compare
2230 * \param s2 second item to compare
2232 int summcmp_subj(const void *s1, const void *s2) {
2233 struct message_summary *summ1;
2234 struct message_summary *summ2;
2236 summ1 = (struct message_summary *)s1;
2237 summ2 = (struct message_summary *)s2;
2238 return strcasecmp(summ1->subj, summ2->subj);
2242 * \brief qsort() compatible function to compare two message summary structs by descending subject.
2244 * \param s1 first item to compare
2245 * \param s2 second item to compare
2247 int summcmp_rsubj(const void *s1, const void *s2) {
2248 struct message_summary *summ1;
2249 struct message_summary *summ2;
2251 summ1 = (struct message_summary *)s1;
2252 summ2 = (struct message_summary *)s2;
2253 return strcasecmp(summ2->subj, summ1->subj);
2257 * \brief qsort() compatible function to compare two message summary structs by ascending sender.
2259 * \param s1 first item to compare
2260 * \param s2 second item to compare
2262 int summcmp_sender(const void *s1, const void *s2) {
2263 struct message_summary *summ1;
2264 struct message_summary *summ2;
2266 summ1 = (struct message_summary *)s1;
2267 summ2 = (struct message_summary *)s2;
2268 return strcasecmp(summ1->from, summ2->from);
2272 * \brief qsort() compatible function to compare two message summary structs by descending sender.
2274 * \param s1 first item to compare
2275 * \param s2 second item to compare
2277 int summcmp_rsender(const void *s1, const void *s2) {
2278 struct message_summary *summ1;
2279 struct message_summary *summ2;
2281 summ1 = (struct message_summary *)s1;
2282 summ2 = (struct message_summary *)s2;
2283 return strcasecmp(summ2->from, summ1->from);
2287 * \brief qsort() compatible function to compare two message summary structs by ascending date.
2289 * \param s1 first item to compare
2290 * \param s2 second item to compare
2292 int summcmp_date(const void *s1, const void *s2) {
2293 struct message_summary *summ1;
2294 struct message_summary *summ2;
2296 summ1 = (struct message_summary *)s1;
2297 summ2 = (struct message_summary *)s2;
2299 if (summ1->date < summ2->date) return -1;
2300 else if (summ1->date > summ2->date) return +1;
2305 * \brief qsort() compatible function to compare two message summary structs by descending date.
2307 * \param s1 first item to compare
2308 * \param s2 second item to compare
2310 int summcmp_rdate(const void *s1, const void *s2) {
2311 struct message_summary *summ1;
2312 struct message_summary *summ2;
2314 summ1 = (struct message_summary *)s1;
2315 summ2 = (struct message_summary *)s2;
2317 if (summ1->date < summ2->date) return +1;
2318 else if (summ1->date > summ2->date) return -1;
2325 * \brief command loop for reading messages
2327 * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
2329 void readloop(char *oper)
2338 long *displayed_msgs = NULL;
2339 int num_displayed = 0;
2341 int is_addressbook = 0;
2342 int is_singlecard = 0;
2343 int is_calendar = 0;
2348 int lowest_displayed = (-1);
2349 int highest_displayed = 0;
2350 struct addrbookent *addrbook = NULL;
2352 char *sortby = NULL;
2353 char sortpref_name[128];
2354 char sortpref_value[128];
2355 char *subjsort_button;
2356 char *sendsort_button;
2357 char *datesort_button;
2358 int bbs_reverse = 0;
2359 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
2361 if (WCC->wc_view == VIEW_WIKI) {
2362 sprintf(buf, "wiki?room=%s?page=home", WCC->wc_roomname);
2367 startmsg = lbstr("startmsg");
2368 maxmsgs = ibstr("maxmsgs");
2369 is_summary = ibstr("is_summary");
2370 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2372 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WCC->wc_roomname);
2373 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
2375 sortby = bstr("sortby");
2376 if ( (!IsEmptyStr(sortby)) && (strcasecmp(sortby, sortpref_value)) ) {
2377 set_preference(sortpref_name, sortby, 1);
2379 if (IsEmptyStr(sortby)) sortby = sortpref_value;
2382 if (IsEmptyStr(sortby)) sortby = "rdate";
2384 /** message board sort */
2385 if (!strcasecmp(sortby, "reverse")) {
2392 output_headers(1, 1, 1, 0, 0, 0);
2395 * When in summary mode, always show ALL messages instead of just
2396 * new or old. Otherwise, show what the user asked for.
2398 if (!strcmp(oper, "readnew")) {
2399 strcpy(cmd, "MSGS NEW");
2401 else if (!strcmp(oper, "readold")) {
2402 strcpy(cmd, "MSGS OLD");
2404 else if (!strcmp(oper, "do_search")) {
2405 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2408 strcpy(cmd, "MSGS ALL");
2411 if ((WCC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
2413 if (!strcmp(oper, "do_search")) {
2414 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2417 strcpy(cmd, "MSGS ALL");
2421 if ((WCC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2423 if (!strcmp(oper, "do_search")) {
2424 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2427 strcpy(cmd, "MSGS ALL");
2432 if (is_summary) { /**< fetch header summary */
2433 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
2434 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2435 (!strcmp(oper, "do_search") ? bstr("query") : "")
2442 * Are we doing a summary view? If so, we need to know old messages
2443 * and new messages, so we can do that pretty boldface thing for the
2446 strcpy(old_msgs, "");
2447 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR)){
2449 serv_getln(buf, sizeof buf);
2450 if (buf[0] == '2') {
2451 strcpy(old_msgs, &buf[4]);
2455 is_singlecard = ibstr("is_singlecard");
2457 if (WCC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2459 strcpy(cmd, "MSGS ALL|||1");
2462 if (WCC->wc_default_view == VIEW_TASKS) { /**< tasks */
2464 strcpy(cmd, "MSGS ALL");
2467 if (WCC->wc_default_view == VIEW_NOTES) { /**< notes */
2469 strcpy(cmd, "MSGS ALL");
2474 wprintf("<div align=center>%s</div>\n", _("Click on any note to edit it."));
2475 wprintf("<div id=\"new_notes_here\"></div>\n");
2478 nummsgs = load_msg_ptrs(cmd, is_summary);
2481 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2482 wprintf("<div align=\"center\"><br /><em>");
2483 if (!strcmp(oper, "readnew")) {
2484 wprintf(_("No new messages."));
2485 } else if (!strcmp(oper, "readold")) {
2486 wprintf(_("No old messages."));
2488 wprintf(_("No messages here."));
2490 wprintf("</em><br /></div>\n");
2496 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR)){
2497 for (a = 0; a < nummsgs; ++a) {
2498 /** Are you a new message, or an old message? */
2500 if (is_msg_in_mset(old_msgs, WCC->msgarr[a])) {
2501 WCC->summ[a].is_new = 0;
2504 WCC->summ[a].is_new = 1;
2510 if (startmsg == 0L) {
2512 startmsg = WCC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2515 startmsg = WCC->msgarr[0];
2520 if (!strcasecmp(sortby, "subject")) {
2521 qsort(WCC->summ, WCC->num_summ,
2522 sizeof(struct message_summary), summcmp_subj);
2524 else if (!strcasecmp(sortby, "rsubject")) {
2525 qsort(WCC->summ, WCC->num_summ,
2526 sizeof(struct message_summary), summcmp_rsubj);
2528 else if (!strcasecmp(sortby, "sender")) {
2529 qsort(WCC->summ, WCC->num_summ,
2530 sizeof(struct message_summary), summcmp_sender);
2532 else if (!strcasecmp(sortby, "rsender")) {
2533 qsort(WCC->summ, WCC->num_summ,
2534 sizeof(struct message_summary), summcmp_rsender);
2536 else if (!strcasecmp(sortby, "date")) {
2537 qsort(WCC->summ, WCC->num_summ,
2538 sizeof(struct message_summary), summcmp_date);
2540 else if (!strcasecmp(sortby, "rdate")) {
2541 qsort(WCC->summ, WCC->num_summ,
2542 sizeof(struct message_summary), summcmp_rdate);
2546 if (!strcasecmp(sortby, "subject")) {
2547 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2549 else if (!strcasecmp(sortby, "rsubject")) {
2550 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2553 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2556 if (!strcasecmp(sortby, "sender")) {
2557 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2559 else if (!strcasecmp(sortby, "rsender")) {
2560 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2563 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2566 if (!strcasecmp(sortby, "date")) {
2567 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2569 else if (!strcasecmp(sortby, "rdate")) {
2570 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2573 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2578 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2579 " document.onkeydown = CtdlMsgListKeyPress; "
2580 " if (document.layers) { "
2581 " document.captureEvents(Event.KEYPRESS); "
2586 /** note that Date and Delete are now in the same column */
2587 wprintf("<div id=\"message_list_hdr\">"
2588 "<div class=\"fix_scrollbar_bug\">"
2589 "<table cellspacing=0 style=\"width:100%%\">"
2592 wprintf("<th width=%d%%>%s %s</th>"
2593 "<th width=%d%%>%s %s</th>"
2594 "<th width=%d%%>%s %s"
2596 "<input type=\"submit\" name=\"delete_button\" id=\"delbutton\" "
2597 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2603 _("Subject"), subjsort_button,
2604 SENDER_COL_WIDTH_PCT,
2605 _("Sender"), sendsort_button,
2606 DATE_PLUS_BUTTONS_WIDTH_PCT,
2607 _("Date"), datesort_button,
2610 wprintf("</table></div></div>\n");
2612 wprintf("<div id=\"message_list\">"
2614 "<div class=\"fix_scrollbar_bug\">\n"
2616 "<table class=\"mailbox_summary\" id=\"summary_headers\" "
2617 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2623 * Set the "is_bbview" variable if it appears that we are looking at
2624 * a classic bulletin board view.
2626 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2627 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2632 * If we're not currently looking at ALL requested
2633 * messages, then display the selector bar
2636 /** begin bbview scroller */
2637 wprintf("<form name=\"msgomatictop\" class=\"selector_top\" > \n <p>");
2638 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2640 wprintf("<select name=\"whichones\" size=\"1\" "
2641 "OnChange=\"location.href=msgomatictop.whichones.options"
2642 "[selectedIndex].value\">\n");
2645 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2647 lo = b - maxmsgs + 2;
2649 wprintf("<option %s value="
2654 "%d-%d</option> \n",
2655 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2664 for (b=0; b<nummsgs; b = b + maxmsgs) {
2666 hi = b + maxmsgs + 1;
2667 if (hi > nummsgs) hi = nummsgs;
2668 wprintf("<option %s value="
2673 "%d-%d</option> \n",
2674 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2683 wprintf("<option value=\"%s?startmsg=%ld"
2684 "?maxmsgs=9999999?is_summary=%d\">",
2686 WCC->msgarr[0], is_summary);
2688 wprintf("</option>");
2689 wprintf("</select> ");
2690 wprintf(_("of %d messages."), nummsgs);
2692 /** forward/reverse */
2693 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2694 "OnChange=\"location.href='%s?sortby=forward'\"",
2695 (bbs_reverse ? "" : "checked"),
2699 wprintf(_("oldest to newest"));
2700 wprintf(" ");
2702 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2703 "OnChange=\"location.href='%s?sortby=reverse'\"",
2704 (bbs_reverse ? "checked" : ""),
2708 wprintf(_("newest to oldest"));
2711 wprintf("</p></form>\n");
2712 /** end bbview scroller */
2717 wprintf ("<script src=\"/static/dragdrop.js\" type=\"text/javascript\"></script>\n");
2722 for (a = 0; a < nummsgs; ++a) {
2723 if ((WCC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2725 /** Display the message */
2727 display_summarized(a);
2729 else if (is_addressbook) {
2730 fetch_ab_name(WCC->msgarr[a], buf);
2732 addrbook = realloc(addrbook,
2733 (sizeof(struct addrbookent) * num_ab) );
2734 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2735 sizeof(addrbook[num_ab-1].ab_name));
2736 addrbook[num_ab-1].ab_msgnum = WCC->msgarr[a];
2738 else if (is_calendar) {
2739 display_calendar(WCC->msgarr[a], WCC->summ[a].is_new);
2741 else if (is_tasks) {
2742 display_task(WCC->msgarr[a], WCC->summ[a].is_new);
2744 else if (is_notes) {
2745 display_note(WCC->msgarr[a], WCC->summ[a].is_new);
2748 if (displayed_msgs == NULL) {
2749 displayed_msgs = malloc(sizeof(long) *
2750 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2752 displayed_msgs[num_displayed] = WCC->msgarr[a];
2755 if (lowest_displayed < 0) lowest_displayed = a;
2756 highest_displayed = a;
2763 if (displayed_msgs != NULL) {
2765 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2768 /** if we do a split bbview in the future, begin messages div here */
2770 for (a=0; a<num_displayed; ++a) {
2771 read_message(displayed_msgs[a], 0, "");
2774 /** if we do a split bbview in the future, end messages div here */
2776 free(displayed_msgs);
2777 displayed_msgs = NULL;
2782 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2783 wprintf("</div>"); /**< end of 'message_list' div */
2785 /** Here's the grab-it-to-resize-the-message-list widget */
2786 wprintf("<div id=\"resize_msglist\" "
2787 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2788 "<div class=\"fix_scrollbar_bug\"> <hr>"
2792 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2796 * Bump these because although we're thinking in zero base, the user
2797 * is a drooling idiot and is thinking in one base.
2800 ++highest_displayed;
2803 * If we're not currently looking at ALL requested
2804 * messages, then display the selector bar
2807 /** begin bbview scroller */
2808 wprintf("<form name=\"msgomatic\" class=\"selector_bottom\" > \n <p>");
2809 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2811 wprintf("<select name=\"whichones\" size=\"1\" "
2812 "OnChange=\"location.href=msgomatic.whichones.options"
2813 "[selectedIndex].value\">\n");
2816 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2818 lo = b - maxmsgs + 2;
2820 wprintf("<option %s value="
2825 "%d-%d</option> \n",
2826 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2835 for (b=0; b<nummsgs; b = b + maxmsgs) {
2837 hi = b + maxmsgs + 1;
2838 if (hi > nummsgs) hi = nummsgs;
2839 wprintf("<option %s value="
2844 "%d-%d</option> \n",
2845 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2854 wprintf("<option value=\"%s?startmsg=%ld"
2855 "?maxmsgs=9999999?is_summary=%d\">",
2857 WCC->msgarr[0], is_summary);
2859 wprintf("</option>");
2860 wprintf("</select> ");
2861 wprintf(_("of %d messages."), nummsgs);
2863 /** forward/reverse */
2864 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2865 "OnChange=\"location.href='%s?sortby=forward'\"",
2866 (bbs_reverse ? "" : "checked"),
2870 wprintf(_("oldest to newest"));
2871 wprintf(" ");
2872 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2873 "OnChange=\"location.href='%s?sortby=reverse'\"",
2874 (bbs_reverse ? "checked" : ""),
2878 wprintf(_("newest to oldest"));
2881 wprintf("</p></form>\n");
2882 /** end bbview scroller */
2887 // wprintf ("</div>\n");
2888 wprintf ("<div id=\"wastebin\" align=middle>Drop notes here to remove them.</div>\n");
2889 wprintf ("<script type=\"text/javascript\">\n");
2890 // wprintf ("//<![CDATA[\n");
2891 wprintf ("Droppables.add(\"wastebin\",\n");
2893 wprintf ("\t\taccept:'notes',\n");
2894 wprintf ("\t\tonDrop:function(element)\n");
2895 wprintf ("\t\t{\n");
2896 wprintf ("\t\t\tElement.hide(element);\n");
2897 wprintf ("\t\t\tnew Ajax.Updater('notes', 'delnote',\n");
2898 wprintf ("\t\t\t{\n");
2899 wprintf ("\t\t\t\tasynchronous:true,\n");
2900 wprintf ("\t\t\t\tevalScripts:true,\n");
2901 wprintf ("\t\t\t\tonComplete:function(request)\n");
2902 wprintf ("\t\t\t\t{\n");
2903 wprintf ("\t\t\t\t\tElement.hide('indicator')\n");
2904 wprintf ("\t\t\t\t},\n");
2905 wprintf ("\t\t\t\tonLoading:function(request)\n");
2906 wprintf ("\t\t\t\t{\n");
2907 wprintf ("\t\t\t\t\tElement.show('indicator')\n");
2908 wprintf ("\t\t\t\t},\n");
2909 wprintf ("\t\t\t\tparameters:'id=' + encodeURIComponent(element.id)\n");
2910 wprintf ("\t\t\t})\n");
2911 wprintf ("\t\t}\n");
2913 // wprintf ("//]]>\n");
2914 wprintf ("</script>\n");
2921 do_tasks_view(); /** Render the task list */
2925 do_calendar_view(); /** Render the calendar */
2928 if (is_addressbook) {
2929 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2932 /** Note: wDumpContent() will output one additional </div> tag. */
2933 wprintf("</div>\n"); /** end of 'content' div */
2936 /** free the summary */
2937 if (WCC->summ != NULL) {
2942 if (addrbook != NULL) free(addrbook);
2947 * Back end for post_message()
2948 * ... this is where the actual message gets transmitted to the server.
2950 void post_mime_to_server(void) {
2951 char top_boundary[SIZ];
2952 char alt_boundary[SIZ];
2953 int is_multipart = 0;
2955 struct wc_attachment *att;
2957 size_t encoded_length;
2958 size_t encoded_strlen;
2959 char *txtmail = NULL;
2961 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
2962 serv_info.serv_fqdn,
2966 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
2967 serv_info.serv_fqdn,
2972 /* RFC2045 requires this, and some clients look for it... */
2973 serv_puts("MIME-Version: 1.0");
2974 serv_puts("X-Mailer: " PACKAGE_STRING);
2976 /* If there are attachments, we have to do multipart/mixed */
2977 if (WC->first_attachment != NULL) {
2982 /* Remember, serv_printf() appends an extra newline */
2983 serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
2984 serv_printf("This is a multipart message in MIME format.\n");
2985 serv_printf("--%s", top_boundary);
2988 /* Remember, serv_printf() appends an extra newline */
2989 serv_printf("Content-type: multipart/alternative; "
2990 "boundary=\"%s\"\n", alt_boundary);
2991 serv_printf("This is a multipart message in MIME format.\n");
2992 serv_printf("--%s", alt_boundary);
2994 serv_puts("Content-type: text/plain; charset=utf-8");
2995 serv_puts("Content-Transfer-Encoding: quoted-printable");
2997 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
2998 text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */
3001 serv_printf("--%s", alt_boundary);
3003 serv_puts("Content-type: text/html; charset=utf-8");
3004 serv_puts("Content-Transfer-Encoding: quoted-printable");
3006 serv_puts("<html><body>\r\n");
3007 text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */
3008 serv_puts("</body></html>\r\n");
3010 serv_printf("--%s--", alt_boundary);
3014 /* Add in the attachments */
3015 for (att = WC->first_attachment; att!=NULL; att=att->next) {
3017 encoded_length = ((att->length * 150) / 100);
3018 encoded = malloc(encoded_length);
3019 if (encoded == NULL) break;
3020 encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1);
3022 serv_printf("--%s", top_boundary);
3023 serv_printf("Content-type: %s", att->content_type);
3024 serv_printf("Content-disposition: attachment; filename=\"%s\"", att->filename);
3025 serv_puts("Content-transfer-encoding: base64");
3027 serv_write(encoded, encoded_strlen);
3032 serv_printf("--%s--", top_boundary);
3040 * Post message (or don't post message)
3042 * Note regarding the "dont_post" variable:
3043 * A random value (actually, it's just a timestamp) is inserted as a hidden
3044 * field called "postseq" when the display_enter page is generated. This
3045 * value is checked when posting, using the static variable dont_post. If a
3046 * user attempts to post twice using the same dont_post value, the message is
3047 * discarded. This prevents the accidental double-saving of the same message
3048 * if the user happens to click the browser "back" button.
3050 void post_message(void)
3055 char *encoded_subject = NULL;
3056 static long dont_post = (-1L);
3057 struct wc_attachment *att, *aptr;
3058 int is_anonymous = 0;
3059 const char *display_name;
3061 struct wcsession *WCC = WC;
3064 if (havebstr("force_room")) {
3065 gotoroom(bstr("force_room"));
3068 if (GetHash(WC->urlstrings, HKEY("display_name"), &U)) {
3069 u = (urlcontent*) U;
3070 display_name = u->url_data;
3071 dpLen = u->url_data_size;
3076 if (!strcmp(display_name, "__ANONYMOUS__")) {
3081 if (WCC->upload_length > 0) {
3083 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WCC->upload_length);
3084 /** There's an attachment. Save it to this struct... */
3085 att = malloc(sizeof(struct wc_attachment));
3086 memset(att, 0, sizeof(struct wc_attachment));
3087 att->length = WCC->upload_length;
3088 strcpy(att->content_type, WCC->upload_content_type);
3089 strcpy(att->filename, WCC->upload_filename);
3092 /** And add it to the list. */
3093 if (WCC->first_attachment == NULL) {
3094 WCC->first_attachment = att;
3097 aptr = WCC->first_attachment;
3098 while (aptr->next != NULL) aptr = aptr->next;
3103 * Mozilla sends a simple filename, which is what we want,
3104 * but Satan's Browser sends an entire pathname. Reduce
3105 * the path to just a filename if we need to.
3107 while (num_tokens(att->filename, '/') > 1) {
3108 remove_token(att->filename, 0, '/');
3110 while (num_tokens(att->filename, '\\') > 1) {
3111 remove_token(att->filename, 0, '\\');
3115 * Transfer control of this memory from the upload struct
3116 * to the attachment struct.
3118 att->data = WCC->upload;
3119 WCC->upload_length = 0;
3125 if (havebstr("cancel_button")) {
3126 sprintf(WCC->ImportantMessage,
3127 _("Cancelled. Message was not posted."));
3128 } else if (havebstr("attach_button")) {
3131 } else if (lbstr("postseq") == dont_post) {
3132 sprintf(WCC->ImportantMessage,
3133 _("Automatically cancelled because you have already "
3134 "saved this message."));
3136 const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s";
3137 const char *Recp = "";
3138 const char *Cc = "";
3139 const char *Bcc = "";
3140 const char *Wikipage = "";
3141 const char *my_email_addr = "";
3142 char *CmdBuf = NULL;;
3145 char references[SIZ] = "";
3146 size_t references_len = 0;
3148 safestrncpy(references, bstr("references"), sizeof references);
3149 lprintf(9, "Converting: %s\n", references);
3150 for (ptr=references; *ptr != 0; ++ptr) {
3151 if (*ptr == '|') *ptr = '!';
3154 lprintf(9, "Converted: %s\n", references);
3156 if (havebstr("subject")) {
3160 * make enough room for the encoded string;
3161 * plus the QP header
3163 Subj = xbstr("subject", &SLen);
3164 len = SLen * 3 + 32;
3165 encoded_subject = malloc (len);
3166 len = webcit_rfc2047encode(encoded_subject, len, Subj, SLen);
3168 free (encoded_subject);
3172 len += sizeof (CMD) + dpLen;
3173 Recp = xbstr("recp", &nLen);
3175 Cc = xbstr("cc", &nLen);
3177 Bcc = xbstr("bcc", &nLen);
3179 Wikipage = xbstr("wikipage", &nLen);
3181 my_email_addr = xbstr("my_email_addr", &nLen);
3183 len += references_len;
3185 CmdBuf = (char*) malloc (len + 11);
3187 snprintf(CmdBuf, len + 1, CMD,
3190 (encoded_subject ? encoded_subject : ""),
3197 lprintf(9, "%s\n", CmdBuf);
3199 serv_getln(buf, sizeof buf);
3201 if (encoded_subject) free(encoded_subject);
3202 if (buf[0] == '4') {
3203 post_mime_to_server();
3204 if ( (havebstr("recp"))
3205 || (havebstr("cc" ))
3206 || (havebstr("bcc" ))
3208 sprintf(WCC->ImportantMessage, _("Message has been sent.\n"));
3211 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
3213 dont_post = lbstr("postseq");
3215 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
3216 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3222 free_attachments(WCC);
3225 * We may have been supplied with instructions regarding the location
3226 * to which we must return after posting. If found, go there.
3228 if (havebstr("return_to")) {
3229 http_redirect(bstr("return_to"));
3232 * If we were editing a page in a wiki room, go to that page now.
3234 else if (havebstr("wikipage")) {
3235 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
3239 * Otherwise, just go to the "read messages" loop.
3242 readloop("readnew");
3250 * \brief display the message entry screen
3252 void display_enter(void)
3258 struct wc_attachment *att;
3259 int recipient_required = 0;
3260 int subject_required = 0;
3261 int recipient_bad = 0;
3263 int is_anonymous = 0;
3264 long existing_page = (-1L);
3269 if (havebstr("force_room")) {
3270 gotoroom(bstr("force_room"));
3273 display_name = xbstr("display_name", &dplen);
3274 if (!strcmp(display_name, "__ANONYMOUS__")) {
3280 /** First test to see whether this is a room that requires recipients to be entered */
3281 serv_puts("ENT0 0");
3282 serv_getln(buf, sizeof buf);
3284 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
3285 recipient_required = 1;
3287 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3288 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3289 readloop("readnew");
3293 /* Is the server strongly recommending that the user enter a message subject? */
3294 if ((buf[3] != '\0') && (buf[4] != '\0')) {
3295 subject_required = extract_int(&buf[4], 1);
3299 * Are we perhaps in an address book view? If so, then an "enter
3300 * message" command really means "add new entry."
3302 if (WC->wc_default_view == VIEW_ADDRESSBOOK) {
3303 do_edit_vcard(-1, "", "", WC->wc_roomname);
3308 * Are we perhaps in a calendar room? If so, then an "enter
3309 * message" command really means "add new calendar item."
3311 if (WC->wc_default_view == VIEW_CALENDAR) {
3312 display_edit_event();
3317 * Are we perhaps in a tasks view? If so, then an "enter
3318 * message" command really means "add new task."
3320 if (WC->wc_default_view == VIEW_TASKS) {
3321 display_edit_task();
3326 * Otherwise proceed normally.
3327 * Do a custom room banner with no navbar...
3329 output_headers(1, 1, 2, 0, 0, 0);
3330 wprintf("<div id=\"banner\">\n");
3331 embed_room_banner(NULL, navbar_none);
3332 wprintf("</div>\n");
3333 wprintf("<div id=\"content\">\n"
3334 "<div class=\"fix_scrollbar_bug message \">");
3336 /* Now check our actual recipients if there are any */
3337 if (recipient_required) {
3338 const char *Recp = "";
3339 const char *Cc = "";
3340 const char *Bcc = "";
3341 const char *Wikipage = "";
3342 char *CmdBuf = NULL;;
3345 const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
3347 len = sizeof(CMD) + dplen;
3348 Recp = xbstr("recp", &nLen);
3350 Cc = xbstr("cc", &nLen);
3352 Bcc = xbstr("bcc", &nLen);
3354 Wikipage = xbstr("wikipage", &nLen);
3358 CmdBuf = (char*) malloc (len + 1);
3360 snprintf(CmdBuf, len, CMD,
3365 serv_getln(buf, sizeof buf);
3367 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
3368 if (havebstr("recp") &&
3374 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3375 wprintf("<em>%s</em><br />\n", &buf[4]);
3380 /** If we got this far, we can display the message entry screen. */
3382 /* begin message entry screen */
3384 "enctype=\"multipart/form-data\" "
3386 "accept-charset=\"UTF-8\" "
3388 "name=\"enterform\""
3390 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
3391 if (WC->wc_view == VIEW_WIKI) {
3392 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
3394 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
3395 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
3396 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
3397 escputs(WC->wc_roomname);
3399 wprintf("<input type=\"hidden\" name=\"references\" value=\"");
3400 escputs(bstr("references"));
3403 /** submit or cancel buttons */
3404 wprintf("<p class=\"send_edit_msg\">");
3405 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3406 if (recipient_required) {
3407 wprintf(_("Send message"));
3409 wprintf(_("Post message"));
3412 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3417 wprintf("<img src=\"static/newmess3_24x.gif\" class=\"imgedit\">");
3418 wprintf(" "); /** header bar */
3419 webcit_fmt_date(buf, now, 0);
3421 wprintf("\n"); /** header bar */
3423 wprintf("<table width=\"100%%\" class=\"edit_msg_table\">");
3425 wprintf("<th><label for=\"from_id\" > ");
3426 wprintf(_(" <I>from</I> "));
3427 wprintf("</label></th>");
3429 wprintf("<td colspan=\"2\">");
3431 /* Allow the user to select any of his valid screen names */
3433 wprintf("<select name=\"display_name\" size=1 id=\"from_id\">\n");
3436 serv_getln(buf, sizeof buf);
3437 if (buf[0] == '1') {
3438 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3439 wprintf("<option %s value=\"",
3440 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
3445 wprintf("</option>\n");
3449 if (WC->room_flags & QR_ANONOPT) {
3450 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
3451 ((!strcasecmp(bstr("__ANONYMOUS__"), WC->wc_fullname)) ? "selected" : ""),
3456 wprintf("</select>\n");
3458 /* If this is an email (not a post), allow the user to select any of his
3459 * valid email addresses.
3461 if (recipient_required) {
3463 serv_getln(buf, sizeof buf);
3464 if (buf[0] == '1') {
3465 wprintf("<select name=\"my_email_addr\" size=1>\n");
3466 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3467 wprintf("<option value=\"");
3471 wprintf("></option>\n");
3473 wprintf("</select>\n");
3477 wprintf(_(" <I>in</I> "));
3478 escputs(WC->wc_roomname);
3480 wprintf("</td></tr>");
3482 if (recipient_required) {
3486 wprintf("<tr><th><label for=\"recp_id\"> ");
3488 wprintf("</label></th>"
3489 "<td><input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
3490 ccraw = xbstr("recp", &len);
3491 copy = (char*) malloc(len * 2 + 1);
3492 memcpy(copy, ccraw, len + 1);
3493 utf8ify_rfc822_string(copy);
3496 wprintf("\" size=45 maxlength=1000 />");
3497 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
3498 wprintf("</td><td rowspan=\"3\" align=\"left\" valign=\"top\">");
3500 /** Pop open an address book -- begin **/
3502 "<a href=\"javascript:PopOpenAddressBook('recp_id|%s|cc_id|%s|bcc_id|%s');\" "
3504 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
3506 _("To:"), _("CC:"), _("BCC:"),
3507 _("Contacts"), _("Contacts")
3509 /** Pop open an address book -- end **/
3511 wprintf("</td></tr>");
3513 wprintf("<tr><th><label for=\"cc_id\"> ");
3515 wprintf("</label></th>"
3516 "<td><input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
3517 ccraw = xbstr("cc", &len);
3518 copy = (char*) malloc(len * 2 + 1);
3519 memcpy(copy, ccraw, len + 1);
3520 utf8ify_rfc822_string(copy);
3523 wprintf("\" size=45 maxlength=1000 />");
3524 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
3525 wprintf("</td></tr>");
3527 wprintf("<tr><th><label for=\"bcc_id\"> ");
3529 wprintf("</label></th>"
3530 "<td><input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
3531 ccraw = xbstr("bcc", &len);
3532 copy = (char*) malloc(len * 2 + 1);
3533 memcpy(copy, ccraw, len + 1);
3534 utf8ify_rfc822_string(copy);
3537 wprintf("\" size=45 maxlength=1000 />");
3538 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
3539 wprintf("</td></tr>");
3541 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
3542 wprintf("<script type=\"text/javascript\"> \n"
3543 " activate_entmsg_autocompleters(); \n"
3549 wprintf("<tr><th><label for=\"subject_id\" > ");
3550 if (recipient_required || subject_required) {
3551 wprintf(_("Subject:"));
3554 wprintf(_("Subject (optional):"));
3556 wprintf("</label></th>"
3557 "<td colspan=\"2\">"
3558 "<input type=\"text\" name=\"subject\" id=\"subject_id\" value=\"");
3559 escputs(bstr("subject"));
3560 wprintf("\" size=45 maxlength=70>\n");
3561 wprintf("</td></tr>");
3563 wprintf("<tr><td colspan=\"3\">\n");
3565 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
3567 /** If we're continuing from a previous edit, put our partially-composed message back... */
3568 msgescputs(bstr("msgtext"));
3570 /* If we're forwarding a message, insert it here... */
3571 if (lbstr("fwdquote") > 0L) {
3572 wprintf("<br><div align=center><i>");
3573 wprintf(_("--- forwarded message ---"));
3574 wprintf("</i></div><br>");
3575 pullquote_message(lbstr("fwdquote"), 1, 1);
3578 /** If we're replying quoted, insert the quote here... */
3579 else if (lbstr("replyquote") > 0L) {
3582 pullquote_message(lbstr("replyquote"), 0, 1);
3583 wprintf("</blockquote><br>");
3586 /** If we're editing a wiki page, insert the existing page here... */
3587 else if (WC->wc_view == VIEW_WIKI) {
3588 safestrncpy(buf, bstr("wikipage"), sizeof buf);
3589 str_wiki_index(buf);
3590 existing_page = locate_message_by_uid(buf);
3591 if (existing_page >= 0L) {
3592 pullquote_message(existing_page, 1, 0);
3596 /** Insert our signature if appropriate... */
3597 if ( (WC->is_mailbox) && yesbstr("sig_inserted") ) {
3598 get_preference("use_sig", buf, sizeof buf);
3599 if (!strcasecmp(buf, "yes")) {
3601 get_preference("signature", ebuf, sizeof ebuf);
3602 euid_unescapize(buf, ebuf);
3603 wprintf("<br>--<br>");
3605 for (i=0; i<len; ++i) {
3606 if (buf[i] == '\n') {
3609 else if (buf[i] == '<') {
3612 else if (buf[i] == '>') {
3615 else if (buf[i] == '&') {
3618 else if (buf[i] == '\"') {
3621 else if (buf[i] == '\'') {
3624 else if (isprint(buf[i])) {
3625 wprintf("%c", buf[i]);
3631 wprintf("</textarea>\n");
3633 /** Make sure we only insert our signature once */
3634 /** We don't care if it was there or not before, it needs to be there now. */
3635 wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
3638 * The following template embeds the TinyMCE richedit control, and automatically
3639 * transforms the textarea into a richedit textarea.
3641 do_template("richedit");
3643 /** Enumerate any attachments which are already in place... */
3644 wprintf("<div class=\"attachment buttons\"><img src=\"static/diskette_24x.gif\" class=\"imgedit\" > ");
3645 wprintf(_("Attachments:"));
3647 wprintf("<select name=\"which_attachment\" size=1>");
3648 for (att = WC->first_attachment; att != NULL; att = att->next) {
3649 wprintf("<option value=\"");
3650 urlescputs(att->filename);
3652 escputs(att->filename);
3653 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3654 wprintf("</option>\n");
3656 wprintf("</select>");
3658 /** Now offer the ability to attach additional files... */
3659 wprintf(" ");
3660 wprintf(_("Attach file:"));
3661 wprintf(" <input name=\"attachfile\" class=\"attachfile\" "
3662 "size=16 type=\"file\">\n "
3663 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3664 wprintf("</div>"); /* End of "attachment buttons" div */
3667 wprintf("</td></tr></table>");
3669 wprintf("</form>\n");
3670 wprintf("</div>\n"); /* end of "fix_scrollbar_bug" div */
3672 /* NOTE: address_book_popup() will close the "content" div. Don't close it here. */
3673 DONE: address_book_popup();
3679 * \brief delete a message
3681 void delete_msg(void)
3686 msgid = lbstr("msgid");
3688 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3689 serv_printf("DELE %ld", msgid);
3691 else { /** Otherwise move it to Trash */
3692 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3695 serv_getln(buf, sizeof buf);
3696 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3698 readloop("readnew");
3703 * \brief move a message to another folder
3710 msgid = lbstr("msgid");
3712 if (havebstr("move_button")) {
3713 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3715 serv_getln(buf, sizeof buf);
3716 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3718 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3721 readloop("readnew");
3729 * \brief Confirm move of a message
3731 void confirm_move_msg(void)
3737 msgid = lbstr("msgid");
3740 output_headers(1, 1, 2, 0, 0, 0);
3741 wprintf("<div id=\"banner\">\n");
3743 wprintf(_("Confirm move of message"));
3745 wprintf("</div>\n");
3747 wprintf("<div id=\"content\" class=\"service\">\n");
3749 wprintf("<CENTER>");
3751 wprintf(_("Move this message to:"));
3752 wprintf("<br />\n");
3754 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3755 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
3756 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3758 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3760 serv_getln(buf, sizeof buf);
3761 if (buf[0] == '1') {
3762 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3763 extract_token(targ, buf, 0, '|', sizeof targ);
3764 wprintf("<OPTION>");
3769 wprintf("</SELECT>\n");
3770 wprintf("<br />\n");
3772 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3774 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3775 wprintf("</form></CENTER>\n");
3777 wprintf("</CENTER>\n");