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 StrBuf *default_header_charset;
108 get_preference("default_header_charset", &default_header_charset);
109 if ( (strcasecmp(ChrPtr(default_header_charset), "UTF-8")) &&
110 (strcasecmp(ChrPtr(default_header_charset), "us-ascii")) ) {
111 ic = ctdl_iconv_open("UTF-8", ChrPtr(default_header_charset));
112 if (ic != (iconv_t)(-1) ) {
115 safestrncpy(ibuf, buf, 1024);
116 ibuflen = strlen(ibuf);
118 obuf = (char *) malloc(obuflen);
120 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
121 osav[1024-obuflen] = 0;
130 /* pre evaluate the first pair */
131 nextend = end = NULL;
133 start = strstr(buf, "=?");
135 end = FindNextEnd (start);
137 while ((start != NULL) && (end != NULL))
139 next = strstr(end, "=?");
141 nextend = FindNextEnd(next);
145 /* did we find two partitions */
146 if ((next != NULL) &&
150 while ((ptr < next) &&
156 /* did we find a gab just filled with blanks? */
161 len - (next - start));
163 /* now terminate the gab at the end */
164 delta = (next - end) - 2;
168 /* move next to its new location. */
173 /* our next-pair is our new first pair now. */
178 /* Now we handle foreign character sets properly encoded
181 while (start=strstr(buf, "=?"), end=FindNextEnd((start != NULL)? start : buf),
182 ((start != NULL) && (end != NULL) && (end > start)) )
184 extract_token(charset, start, 1, '?', sizeof charset);
185 extract_token(encoding, start, 2, '?', sizeof encoding);
186 extract_token(istr, start, 3, '?', sizeof istr);
190 if (!strcasecmp(encoding, "B")) { /**< base64 */
191 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
193 else if (!strcasecmp(encoding, "Q")) { /**< quoted-printable */
201 if (istr[pos] == '_') istr[pos] = ' ';
205 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, len);
208 strcpy(ibuf, istr); /**< unknown encoding */
209 ibuflen = strlen(istr);
212 ic = ctdl_iconv_open("UTF-8", charset);
213 if (ic != (iconv_t)(-1) ) {
215 obuf = (char *) malloc(obuflen);
217 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
218 osav[1024-obuflen] = 0;
223 remove_token(end, 0, '?');
224 remove_token(end, 0, '?');
225 remove_token(end, 0, '?');
226 remove_token(end, 0, '?');
227 strcpy(end, &end[1]);
229 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
238 remove_token(end, 0, '?');
239 remove_token(end, 0, '?');
240 remove_token(end, 0, '?');
241 remove_token(end, 0, '?');
242 strcpy(end, &end[1]);
244 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
251 * Since spammers will go to all sorts of absurd lengths to get their
252 * messages through, there are LOTS of corrupt headers out there.
253 * So, prevent a really badly formed RFC2047 header from throwing
254 * this function into an infinite loop.
257 if (passes > 20) return;
262 inline void utf8ify_rfc822_string(char *a){};
270 * \brief RFC2047-encode a header field if necessary.
271 * If no non-ASCII characters are found, the string
272 * will be copied verbatim without encoding.
274 * \param target Target buffer.
275 * \param maxlen Maximum size of target buffer.
276 * \param source Source string to be encoded.
277 * \param SourceLen Length of the source string
278 * \returns encoded length; -1 if non success.
280 int webcit_rfc2047encode(char *target, int maxlen, char *source, long SourceLen)
282 const char headerStr[] = "=?UTF-8?Q?";
283 int need_to_encode = 0;
288 if ((source == NULL) ||
290 (SourceLen > maxlen)) return -1;
292 while ((!IsEmptyStr (&source[i])) &&
293 (need_to_encode == 0) &&
295 if (((unsigned char) source[i] < 32) ||
296 ((unsigned char) source[i] > 126)) {
302 if (!need_to_encode) {
303 memcpy (target, source, SourceLen);
304 target[SourceLen] = '\0';
308 if (sizeof (headerStr + SourceLen + 2) > maxlen)
310 memcpy (target, headerStr, sizeof (headerStr));
311 len = sizeof (headerStr) - 1;
312 for (i=0; (i < SourceLen) && (len + 3< maxlen) ; ++i) {
313 ch = (unsigned char) source[i];
314 if ((ch < 32) || (ch > 126) || (ch == 61)) {
315 sprintf(&target[len], "=%02X", ch);
319 sprintf(&target[len], "%c", ch);
324 if (len + 2 < maxlen) {
325 strcat(&target[len], "?=");
337 * Look for URL's embedded in a buffer and make them linkable. We use a
338 * target window in order to keep the Citadel session in its own window.
340 void url(char *buf, size_t bufsize)
342 int len, UrlLen, Offset, TrailerLen, outpos;
343 char *start, *end, *pos;
350 lprintf(1, "URL: content longer than buffer!");
354 for (pos = buf; (pos < end) && (start == NULL); ++pos) {
355 if (!strncasecmp(pos, "http://", 7))
357 if (!strncasecmp(pos, "ftp://", 6))
364 for (pos = buf+len; pos > start; --pos) {
365 if ( (!isprint(*pos))
384 UrlLen = end - start;
385 if (UrlLen > sizeof(urlbuf)){
386 lprintf(1, "URL: content longer than buffer!");
389 memcpy(urlbuf, start, UrlLen);
390 urlbuf[UrlLen] = '\0';
392 Offset = start - buf;
393 if ((Offset != 0) && (Offset < sizeof(outbuf)))
394 memcpy(outbuf, buf, Offset);
395 outpos = snprintf(&outbuf[Offset], sizeof(outbuf) - Offset,
396 "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
397 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
398 if (outpos >= sizeof(outbuf) - Offset) {
399 lprintf(1, "URL: content longer than buffer!");
403 TrailerLen = len - (end - start);
405 memcpy(outbuf + Offset + outpos, end, TrailerLen);
406 if (Offset + outpos + TrailerLen > bufsize) {
407 lprintf(1, "URL: content longer than buffer!");
410 memcpy (buf, outbuf, Offset + outpos + TrailerLen);
411 *(buf + Offset + outpos + TrailerLen) = '\0';
416 * \brief Turn a vCard "n" (name) field into something displayable.
417 * \param name the name field to convert
419 void vcard_n_prettyize(char *name)
424 original_name = strdup(name);
425 len = strlen(original_name);
426 for (i=0; i<5; ++i) {
428 if (original_name[len-1] == ' ') {
429 original_name[--len] = 0;
431 if (original_name[len-1] == ';') {
432 original_name[--len] = 0;
438 for (i=0; i<len; ++i) {
439 if (original_name[i] == ';') {
444 name[j++] = original_name[i];
455 * \brief preparse a vcard name
456 * display_vcard() calls this after parsing the textual vCard into
457 * our 'struct vCard' data object.
458 * This gets called instead of display_parsed_vcard() if we are only looking
459 * to extract the person's name instead of displaying the card.
460 * \param v the vcard to retrieve the name from
461 * \param storename where to put the name at
463 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
466 strcpy(storename, "");
468 name = vcard_get_prop(v, "n", 1, 0, 0);
470 strcpy(storename, name);
471 /* vcard_n_prettyize(storename); */
479 * \brief html print a vcard
480 * display_vcard() calls this after parsing the textual vCard into
481 * our 'struct vCard' data object.
483 * Set 'full' to nonzero to display the full card, otherwise it will only
484 * show a summary line.
486 * This code is a bit ugly, so perhaps an explanation is due: we do this
487 * in two passes through the vCard fields. On the first pass, we process
488 * fields we understand, and then render them in a pretty fashion at the
489 * end. Then we make a second pass, outputting all the fields we don't
490 * understand in a simple two-column name/value format.
491 * \param v the vCard to display
492 * \param full display all items of the vcard?
493 * \param msgnum Citadel message pointer
495 void display_parsed_vcard(struct vCard *v, int full, long msgnum) {
501 char *thisname, *thisvalue;
502 char firsttoken[SIZ];
511 strcpy(fullname, "");
519 name = vcard_get_prop(v, "fn", 1, 0, 0);
523 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
524 strcpy(fullname, name);
525 vcard_n_prettyize(fullname);
535 wprintf("<div align=center>"
536 "<table bgcolor=#aaaaaa width=50%%>");
537 for (pass=1; pass<=2; ++pass) {
539 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
541 thisname = strdup(v->prop[i].name);
542 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
544 for (j=0; j<num_tokens(thisname, ';'); ++j) {
545 extract_token(buf, thisname, j, ';', sizeof buf);
546 if (!strcasecmp(buf, "encoding=quoted-printable")) {
548 remove_token(thisname, j, ';');
550 if (!strcasecmp(buf, "encoding=base64")) {
552 remove_token(thisname, j, ';');
556 len = strlen(v->prop[i].value);
557 /* if we have some untagged QP, detect it here. */
558 if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
559 utf8ify_rfc822_string(v->prop[i].value);
562 // %ff can become 6 bytes in utf8
563 thisvalue = malloc(len * 2 + 3);
564 j = CtdlDecodeQuotedPrintable(
565 thisvalue, v->prop[i].value,
570 // ff will become one byte..
571 thisvalue = malloc(len + 50);
573 thisvalue, v->prop[i].value,
574 strlen(v->prop[i].value) );
577 thisvalue = strdup(v->prop[i].value);
580 /** Various fields we may encounter ***/
582 /** N is name, but only if there's no FN already there */
583 if (!strcasecmp(firsttoken, "n")) {
584 if (IsEmptyStr(fullname)) {
585 strcpy(fullname, thisvalue);
586 vcard_n_prettyize(fullname);
590 /** FN (full name) is a true 'display name' field */
591 else if (!strcasecmp(firsttoken, "fn")) {
592 strcpy(fullname, thisvalue);
596 else if (!strcasecmp(firsttoken, "title")) {
597 strcpy(title, thisvalue);
601 else if (!strcasecmp(firsttoken, "org")) {
602 strcpy(org, thisvalue);
605 else if (!strcasecmp(firsttoken, "email")) {
607 if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
609 "<a href=\"display_enter"
610 "?force_room=_MAIL_?recp=");
612 len = strlen(mailto);
613 urlesc(&mailto[len], SIZ - len, "\"");
614 len = strlen(mailto);
615 urlesc(&mailto[len], SIZ - len, fullname);
616 len = strlen(mailto);
617 urlesc(&mailto[len], SIZ - len, "\" <");
618 len = strlen(mailto);
619 urlesc(&mailto[len], SIZ - len, thisvalue);
620 len = strlen(mailto);
621 urlesc(&mailto[len], SIZ - len, ">");
623 strcat(mailto, "\">");
624 len = strlen(mailto);
625 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
626 strcat(mailto, "</A>");
628 else if (!strcasecmp(firsttoken, "tel")) {
629 if (!IsEmptyStr(phone)) strcat(phone, "<br />");
630 strcat(phone, thisvalue);
631 for (j=0; j<num_tokens(thisname, ';'); ++j) {
632 extract_token(buf, thisname, j, ';', sizeof buf);
633 if (!strcasecmp(buf, "tel"))
635 else if (!strcasecmp(buf, "work"))
636 strcat(phone, _(" (work)"));
637 else if (!strcasecmp(buf, "home"))
638 strcat(phone, _(" (home)"));
639 else if (!strcasecmp(buf, "cell"))
640 strcat(phone, _(" (cell)"));
648 else if (!strcasecmp(firsttoken, "adr")) {
651 wprintf(_("Address:"));
652 wprintf("</TD><TD>");
653 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
654 extract_token(buf, thisvalue, j, ';', sizeof buf);
655 if (!IsEmptyStr(buf)) {
657 if (j<3) wprintf("<br />");
661 wprintf("</TD></TR>\n");
664 else if (!strcasecmp(firsttoken, "photo") && full && pass == 2) {
665 // Only output on second pass
667 wprintf(_("Photo:"));
668 wprintf("</td><td>");
669 wprintf("<img src=\"/vcardphoto/%ld/\" alt=\"Contact photo\"/>",msgnum);
670 wprintf("</td></tr>\n");
672 else if (!strcasecmp(firsttoken, "version")) {
675 else if (!strcasecmp(firsttoken, "rev")) {
678 else if (!strcasecmp(firsttoken, "label")) {
683 /*** Don't show extra fields. They're ugly.
687 wprintf("</TD><TD>");
689 wprintf("</TD></TR>\n");
699 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
700 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
701 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
702 "<FONT SIZE=+1><B>");
704 wprintf("</B></FONT>");
705 if (!IsEmptyStr(title)) {
706 wprintf("<div align=right>");
710 if (!IsEmptyStr(org)) {
711 wprintf("<div align=right>");
715 wprintf("</TD></TR>\n");
717 if (!IsEmptyStr(phone)) {
719 wprintf(_("Telephone:"));
720 wprintf("</td><td>%s</td></tr>\n", phone);
722 if (!IsEmptyStr(mailto)) {
724 wprintf(_("E-mail:"));
725 wprintf("</td><td>%s</td></tr>\n", mailto);
731 wprintf("</table></div>\n");
737 * \brief Display a textual vCard
738 * (Converts to a vCard object and then calls the actual display function)
739 * Set 'full' to nonzero to display the whole card instead of a one-liner.
740 * Or, if "storename" is non-NULL, just store the person's name in that
741 * buffer instead of displaying the card at all.
742 * \param vcard_source the buffer containing the vcard text
743 * \param alpha what???
744 * \param full should we usse all lines?
745 * \param storename where to store???
746 * \param msgnum Citadel message pointer
748 void display_vcard(char *vcard_source, char alpha, int full, char *storename,
755 v = vcard_load(vcard_source);
756 if (v == NULL) return;
758 name = vcard_get_prop(v, "n", 1, 0, 0);
760 utf8ify_rfc822_string(name);
765 if (storename != NULL) {
766 fetchname_parsed_vcard(v, storename);
768 else if ( (alpha == 0)
769 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
770 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
772 display_parsed_vcard(v, full,msgnum);
786 * I wanna SEE that message!
788 * msgnum Message number to display
789 * printable_view Nonzero to display a printable view
790 * section Optional for encapsulated message/rfc822 submessage
792 void read_message(long msgnum, int printable_view, char *section) {
794 char mime_partnum[256] = "";
795 char mime_name[256] = "";
796 char mime_filename[256] = "";
797 char escaped_mime_filename[256] = "";
798 char mime_content_type[256] = "";
799 const char *mime_content_type_ptr;
800 char mime_charset[256] = "";
801 char mime_disposition[256] = "";
803 struct attach_link *attach_links = NULL;
804 int num_attach_links = 0;
805 char mime_submessages[256] = "";
806 char m_subject[1024] = "";
807 char m_cc[1024] = "";
811 char reply_to[512] = "";
812 char reply_all[4096] = "";
813 char reply_references[1024] = "";
814 char reply_inreplyto[256] = "";
820 char vcard_partnum[256] = "";
821 char cal_partnum[256] = "";
822 char *part_source = NULL;
823 char msg4_partnum[32] = "";
825 iconv_t ic = (iconv_t)(-1) ;
826 char *ibuf; /**< Buffer of characters to be converted */
827 char *obuf; /**< Buffer for converted characters */
828 size_t ibuflen; /**< Length of input buffer */
829 size_t obuflen; /**< Length of output buffer */
830 char *osav; /**< Saved pointer to output buffer */
833 strcpy(mime_content_type, "text/plain");
834 strcpy(mime_charset, "us-ascii");
835 strcpy(mime_submessages, "");
837 serv_printf("MSG4 %ld|%s", msgnum, section);
838 serv_getln(buf, sizeof buf);
841 wprintf(_("ERROR:"));
842 wprintf("</strong> %s<br />\n", &buf[4]);
846 /** begin everythingamundo table */
847 if (!printable_view) {
848 wprintf("<div class=\"fix_scrollbar_bug message\" ");
849 wprintf("onMouseOver=document.getElementById(\"msg%ld\").style.visibility=\"visible\" ", msgnum);
850 wprintf("onMouseOut=document.getElementById(\"msg%ld\").style.visibility=\"hidden\" >", msgnum);
853 /** begin message header table */
854 wprintf("<div class=\"message_header\">");
856 strcpy(m_subject, "");
859 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
860 if (!strcmp(buf, "000")) {
862 wprintf(_("unexpected end of message"));
863 wprintf(" (1)</i><br /><br />\n");
867 if (!strncasecmp(buf, "nhdr=yes", 8))
871 if (!strncasecmp(buf, "type=", 5))
872 format_type = atoi(&buf[5]);
873 if (!strncasecmp(buf, "from=", 5)) {
874 strcpy(from, &buf[5]);
876 wprintf("<a href=\"showuser?who=");
877 utf8ify_rfc822_string(from);
883 if (!strncasecmp(buf, "subj=", 5)) {
884 safestrncpy(m_subject, &buf[5], sizeof m_subject);
886 if (!strncasecmp(buf, "msgn=", 5)) {
887 safestrncpy(reply_inreplyto, &buf[5], sizeof reply_inreplyto);
889 if (!strncasecmp(buf, "wefw=", 5)) {
890 safestrncpy(reply_references, &buf[5], sizeof reply_references);
892 if (!strncasecmp(buf, "cccc=", 5)) {
894 safestrncpy(m_cc, &buf[5], sizeof m_cc);
895 if (!IsEmptyStr(reply_all)) {
896 strcat(reply_all, ", ");
898 len = strlen(reply_all);
899 safestrncpy(&reply_all[len], &buf[5],
900 (sizeof reply_all - len) );
902 if ((!strncasecmp(buf, "hnod=", 5))
903 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
904 wprintf("(%s) ", &buf[5]);
906 if ((!strncasecmp(buf, "room=", 5))
907 && (strcasecmp(&buf[5], WC->wc_roomname))
908 && (!IsEmptyStr(&buf[5])) ) {
910 wprintf("%s> ", &buf[5]);
912 if (!strncasecmp(buf, "rfca=", 5)) {
913 strcpy(rfca, &buf[5]);
919 if (!strncasecmp(buf, "node=", 5)) {
920 strcpy(node, &buf[5]);
921 if ( ((WC->room_flags & QR_NETWORK)
922 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
923 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
924 && (IsEmptyStr(rfca))
926 wprintf("@%s ", &buf[5]);
929 if (!strncasecmp(buf, "rcpt=", 5)) {
932 if (!IsEmptyStr(reply_all)) {
933 strcat(reply_all, ", ");
935 len = strlen(reply_all);
936 safestrncpy(&reply_all[len], &buf[5],
937 (sizeof reply_all - len) );
938 utf8ify_rfc822_string(&buf[5]);
942 if (!strncasecmp(buf, "time=", 5)) {
943 webcit_fmt_date(now, atol(&buf[5]), 0);
949 if (!strncasecmp(buf, "part=", 5)) {
950 extract_token(mime_name, &buf[5], 0, '|', sizeof mime_filename);
951 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
952 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
953 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
954 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
955 mime_length = extract_int(&buf[5], 5);
958 striplt(mime_filename);
959 if ( (IsEmptyStr(mime_filename)) && (!IsEmptyStr(mime_name)) ) {
960 strcpy(mime_filename, mime_name);
963 if (!strcasecmp(mime_content_type, "message/rfc822")) {
964 if (!IsEmptyStr(mime_submessages)) {
965 strcat(mime_submessages, "|");
967 strcat(mime_submessages, mime_partnum);
969 else if ((!strcasecmp(mime_disposition, "inline"))
970 && (!strncasecmp(mime_content_type, "image/", 6)) ){
972 attach_links = realloc(attach_links,
973 (num_attach_links*sizeof(struct attach_link)));
974 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
975 snprintf(attach_links[num_attach_links-1].html, 1024,
976 "<img src=\"mimepart/%ld/%s/%s\">",
977 msgnum, mime_partnum, mime_filename);
979 else if ( ( (!strcasecmp(mime_disposition, "attachment"))
980 || (!strcasecmp(mime_disposition, "inline"))
981 || (!strcasecmp(mime_disposition, ""))
982 ) && (!IsEmptyStr(mime_content_type))
985 attach_links = realloc(attach_links,
986 (num_attach_links*sizeof(struct attach_link)));
987 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
988 utf8ify_rfc822_string(mime_filename);
990 mime_content_type_ptr = mime_content_type;
991 if (strcasecmp(mime_content_type, "application/octet-stream") == 0) {
992 mime_content_type_ptr = GuessMimeByFilename(mime_filename,
993 strlen(mime_filename));
995 urlesc(escaped_mime_filename, 265, mime_filename);
996 snprintf(attach_links[num_attach_links-1].html, 1024,
997 "<img src=\"display_mime_icon?type=%s\" "
998 "border=0 align=middle>\n"
999 "%s (%s, %d bytes) [ "
1000 "<a href=\"mimepart/%ld/%s/%s\""
1001 "target=\"wc.%ld.%s\">%s</a>"
1003 "<a href=\"mimepart_download/%ld/%s/%s\">%s</a>"
1005 mime_content_type_ptr,
1007 mime_content_type, mime_length,
1008 msgnum, mime_partnum, escaped_mime_filename,
1009 msgnum, mime_partnum,
1011 msgnum, mime_partnum, escaped_mime_filename,
1016 /** begin handler prep ***/
1017 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1018 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1019 strcpy(vcard_partnum, mime_partnum);
1022 if ( (!strcasecmp(mime_content_type, "text/calendar"))
1023 || (!strcasecmp(mime_content_type, "application/ics")) ) {
1024 strcpy(cal_partnum, mime_partnum);
1027 /** end handler prep ***/
1033 /* Trim down excessively long lists of thread references. We eliminate the
1034 * second one in the list so that the thread root remains intact.
1036 int rrtok = num_tokens(reply_references, '|');
1037 int rrlen = strlen(reply_references);
1038 if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
1039 remove_token(reply_references, 1, '|');
1042 /* Generate a reply-to address */
1043 if (!IsEmptyStr(rfca)) {
1044 if (!IsEmptyStr(from)) {
1045 snprintf(reply_to, sizeof(reply_to), "%s <%s>", from, rfca);
1048 strcpy(reply_to, rfca);
1052 if ((!IsEmptyStr(node))
1053 && (strcasecmp(node, serv_info.serv_nodename))
1054 && (strcasecmp(node, serv_info.serv_humannode)) ) {
1055 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
1059 snprintf(reply_to, sizeof(reply_to), "%s", from);
1067 utf8ify_rfc822_string(m_cc);
1068 utf8ify_rfc822_string(m_subject);
1070 /** start msg buttons */
1072 if (!printable_view) {
1073 wprintf("<p id=\"msg%ld\" class=\"msgbuttons\" >\n",msgnum);
1076 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
1077 wprintf("<a href=\"display_enter");
1078 if (WC->is_mailbox) {
1079 wprintf("?replyquote=%ld", msgnum);
1082 urlescputs(reply_to);
1083 if (!IsEmptyStr(m_subject)) {
1084 wprintf("?subject=");
1085 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%%20");
1086 urlescputs(m_subject);
1088 wprintf("?references=");
1089 if (!IsEmptyStr(reply_references)) {
1090 urlescputs(reply_references);
1093 urlescputs(reply_inreplyto);
1094 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Reply"));
1098 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
1099 if (!WC->is_mailbox) {
1100 wprintf("<a href=\"display_enter");
1101 wprintf("?replyquote=%ld", msgnum);
1103 urlescputs(reply_to);
1104 if (!IsEmptyStr(m_subject)) {
1105 wprintf("?subject=");
1106 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%%20");
1107 urlescputs(m_subject);
1109 wprintf("?references=");
1110 if (!IsEmptyStr(reply_references)) {
1111 urlescputs(reply_references);
1114 urlescputs(reply_inreplyto);
1115 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyQuoted"));
1120 if (WC->wc_view == VIEW_MAILBOX) {
1121 wprintf("<a href=\"display_enter");
1122 wprintf("?replyquote=%ld", msgnum);
1124 urlescputs(reply_to);
1126 urlescputs(reply_all);
1127 if (!IsEmptyStr(m_subject)) {
1128 wprintf("?subject=");
1129 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%%20");
1130 urlescputs(m_subject);
1132 wprintf("?references=");
1133 if (!IsEmptyStr(reply_references)) {
1134 urlescputs(reply_references);
1137 urlescputs(reply_inreplyto);
1138 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyAll"));
1142 if (WC->wc_view == VIEW_MAILBOX) {
1143 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
1144 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%%20");
1145 urlescputs(m_subject);
1146 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Forward"));
1149 /* If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
1150 if ( (WC->is_room_aide) || (WC->is_mailbox) || (WC->room_flags2 & QR2_COLLABDEL) ) {
1152 wprintf("<a href=\"confirm_move_msg?msgid=%ld\"><span>[</span>%s<span>]</span></a> ",
1156 wprintf("<a href=\"delete_msg?msgid=%ld\" "
1157 "onClick=\"return confirm('%s');\">"
1158 "<span>[</span>%s<span>]</span> "
1159 "</a> ", msgnum, _("Delete this message?"), _("Delete")
1164 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'); \" >"
1165 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Headers"));
1169 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'); \" >"
1170 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Print"));
1176 if (!IsEmptyStr(m_cc)) {
1183 if (!IsEmptyStr(m_subject)) {
1184 wprintf("<p class=\"message_subject\">");
1185 wprintf(_("Subject:"));
1194 wprintf("<div class=\"message_content\">");
1197 * Learn the content type
1199 strcpy(mime_content_type, "text/plain");
1200 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1201 if (!strcmp(buf, "000")) {
1202 /* This is not necessarily an error condition. See bug #226. */
1205 if (!strncasecmp(buf, "X-Citadel-MSG4-Partnum:", 23)) {
1206 safestrncpy(msg4_partnum, &buf[23], sizeof(msg4_partnum));
1207 striplt(msg4_partnum);
1209 if (!strncasecmp(buf, "Content-type:", 13)) {
1211 safestrncpy(mime_content_type, &buf[13], sizeof(mime_content_type));
1212 striplt(mime_content_type);
1213 len = strlen(mime_content_type);
1214 for (i=0; i<len; ++i) {
1215 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1216 safestrncpy(mime_charset, &mime_content_type[i+8],
1217 sizeof mime_charset);
1220 for (i=0; i<len; ++i) {
1221 if (mime_content_type[i] == ';') {
1222 mime_content_type[i] = 0;
1226 len = strlen(mime_charset);
1227 for (i=0; i<len; ++i) {
1228 if (mime_charset[i] == ';') {
1229 mime_charset[i] = 0;
1236 /* Set up a character set conversion if we need to (and if we can) */
1238 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
1239 if ( (strcasecmp(mime_charset, "us-ascii"))
1240 && (strcasecmp(mime_charset, "UTF-8"))
1241 && (strcasecmp(mime_charset, ""))
1243 ic = ctdl_iconv_open("UTF-8", mime_charset);
1244 if (ic == (iconv_t)(-1) ) {
1245 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1246 __FILE__, __LINE__, mime_charset, strerror(errno));
1251 /* Messages in legacy Citadel variformat get handled thusly... */
1252 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1256 /* Boring old 80-column fixed format text gets handled this way... */
1257 else if ( (!strcasecmp(mime_content_type, "text/plain"))
1258 || (!strcasecmp(mime_content_type, "text")) ) {
1260 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1263 if ((len > 0) && buf[len-1] == '\n') buf[--len] = 0;
1264 if ((len > 0) && buf[len-1] == '\r') buf[--len] = 0;
1267 if (ic != (iconv_t)(-1) ) {
1269 ibuflen = strlen(ibuf);
1271 obuf = (char *) malloc(obuflen);
1273 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1274 osav[SIZ-obuflen] = 0;
1275 safestrncpy(buf, osav, sizeof buf);
1281 while ((!IsEmptyStr(buf)) && (isspace(buf[len-1])))
1284 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1285 wprintf("<blockquote>");
1287 } else if ((bq == 1) &&
1288 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1289 wprintf("</blockquote>");
1293 url(buf, sizeof(buf));
1295 wprintf("</tt><br />\n");
1297 wprintf("</i><br />");
1300 /* HTML is fun, but we've got to strip it first */
1301 else if (!strcasecmp(mime_content_type, "text/html")) {
1302 output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
1305 /* Unknown weirdness */
1307 wprintf(_("I don't know how to display %s"), mime_content_type);
1308 wprintf("<br />\n");
1309 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1312 ENDBODY: /* If there are attached submessages, display them now... */
1314 if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
1315 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1316 extract_token(buf, mime_submessages, i, '|', sizeof buf);
1317 /** use printable_view to suppress buttons */
1318 wprintf("<blockquote>");
1319 read_message(msgnum, 1, buf);
1320 wprintf("</blockquote>");
1325 /* Afterwards, offer links to download attachments 'n' such */
1326 if ( (num_attach_links > 0) && (!section[0]) ) {
1327 for (i=0; i<num_attach_links; ++i) {
1328 if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
1329 wprintf("%s", attach_links[i].html);
1334 /* Handler for vCard parts */
1335 if (!IsEmptyStr(vcard_partnum)) {
1336 part_source = load_mimepart(msgnum, vcard_partnum);
1337 if (part_source != NULL) {
1339 /** If it's my vCard I can edit it */
1340 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1341 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1342 || (WC->wc_view == VIEW_ADDRESSBOOK)
1344 wprintf("<a href=\"edit_vcard?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, msgnum, cal_partnum);
1367 wprintf("</div>\n");
1369 /* end everythingamundo table */
1370 if (!printable_view) {
1371 wprintf("</div>\n");
1374 if (num_attach_links > 0) {
1379 if (ic != (iconv_t)(-1) ) {
1388 * Unadorned HTML output of an individual message, suitable
1389 * for placing in a hidden iframe, for printing, or whatever
1391 * msgnum_as_string == Message number, as a string instead of as a long int
1393 void embed_message(char *msgnum_as_string) {
1396 msgnum = atol(msgnum_as_string);
1397 begin_ajax_response();
1398 read_message(msgnum, 0, "");
1399 end_ajax_response();
1404 * Printable view of a message
1406 * msgnum_as_string == Message number, as a string instead of as a long int
1408 void print_message(char *msgnum_as_string) {
1411 msgnum = atol(msgnum_as_string);
1412 output_headers(0, 0, 0, 0, 0, 0);
1414 wprintf("Content-type: text/html\r\n"
1416 "Connection: close\r\n",
1420 wprintf("\r\n\r\n<html>\n<head><title>");
1421 escputs(WC->wc_fullname);
1422 wprintf("</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) {
1801 wprintf("<tr id=\"m%ld\" style=\"font-weight:%s;\" "
1802 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1803 WC->summ[num].msgnum,
1804 (WC->summ[num].is_new ? "bold" : "normal"),
1805 WC->summ[num].msgnum
1808 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1810 escputs(WC->summ[num].subj);//////////////////////////////////TODO: QP DECODE
1813 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1814 escputs(WC->summ[num].from);
1817 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1818 webcit_fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1825 * \brief Output a message row for the mobile view
1826 * \param The row number
1828 void display_mobile_summary(int num) {
1830 wprintf("\n<div><div id=\"m%ld\" style=\"font-weight:%s;\" "
1831 "onClick=\"CtdlLoadMsgMouseDown(event,%ld)\">",
1832 WC->summ[num].msgnum,
1833 (WC->summ[num].is_new ? "bold" : "normal"),
1834 WC->summ[num].msgnum
1836 wprintf("<span>%s</span>",WC->summ[num].from);
1837 wprintf("<span style=\"float: right;\">");
1838 webcit_fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1840 wprintf("</span><br/><span class=\"subject\">");
1841 wprintf(WC->summ[num].subj);
1842 wprintf("</span></div><div id=\"m_%ld\" class=\"msgview\" onMouseDown=\"\"></div></div>",WC->summ[num].msgnum);
1846 * \brief display the adressbook overview
1847 * \param msgnum the citadel message number
1848 * \param alpha what????
1850 void display_addressbook(long msgnum, char alpha) {
1852 char mime_partnum[SIZ];
1853 char mime_filename[SIZ];
1854 char mime_content_type[SIZ];
1855 char mime_disposition[SIZ];
1857 char vcard_partnum[SIZ];
1858 char *vcard_source = NULL;
1859 struct message_summary summ;
1861 memset(&summ, 0, sizeof(summ));
1862 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1864 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1866 serv_getln(buf, sizeof buf);
1867 if (buf[0] != '1') return;
1869 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1870 if (!strncasecmp(buf, "part=", 5)) {
1871 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1872 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1873 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1874 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1875 mime_length = extract_int(&buf[5], 5);
1877 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1878 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1879 strcpy(vcard_partnum, mime_partnum);
1885 if (!IsEmptyStr(vcard_partnum)) {
1886 vcard_source = load_mimepart(msgnum, vcard_partnum);
1887 if (vcard_source != NULL) {
1889 /** Display the summary line */
1890 display_vcard(vcard_source, alpha, 0, NULL,msgnum);
1892 /** If it's my vCard I can edit it */
1893 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1894 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1895 || (WC->wc_view == VIEW_ADDRESSBOOK)
1897 wprintf("<a href=\"edit_vcard?"
1898 "msgnum=%ld?partnum=%s\">",
1899 msgnum, vcard_partnum);
1900 wprintf("[%s]</a>", _("edit"));
1912 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1913 * \param namebuf name to analyze, reverse if nescessary
1915 void lastfirst_firstlast(char *namebuf) {
1916 char firstname[SIZ];
1920 if (namebuf == NULL) return;
1921 if (strchr(namebuf, ';') != NULL) return;
1923 i = num_tokens(namebuf, ' ');
1926 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1927 remove_token(namebuf, i-1, ' ');
1928 strcpy(firstname, namebuf);
1929 sprintf(namebuf, "%s; %s", lastname, firstname);
1933 * \brief fetch what??? name
1934 * \param msgnum the citadel message number
1935 * \param namebuf where to put the name in???
1937 void fetch_ab_name(long msgnum, char *namebuf) {
1939 char mime_partnum[SIZ];
1940 char mime_filename[SIZ];
1941 char mime_content_type[SIZ];
1942 char mime_disposition[SIZ];
1944 char vcard_partnum[SIZ];
1945 char *vcard_source = NULL;
1947 struct message_summary summ;
1949 if (namebuf == NULL) return;
1950 strcpy(namebuf, "");
1952 memset(&summ, 0, sizeof(summ));
1953 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1955 sprintf(buf, "MSG0 %ld|0", msgnum); /** unfortunately we need the mime info now */
1957 serv_getln(buf, sizeof buf);
1958 if (buf[0] != '1') return;
1960 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1961 if (!strncasecmp(buf, "part=", 5)) {
1962 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1963 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1964 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1965 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1966 mime_length = extract_int(&buf[5], 5);
1968 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1969 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1970 strcpy(vcard_partnum, mime_partnum);
1976 if (!IsEmptyStr(vcard_partnum)) {
1977 vcard_source = load_mimepart(msgnum, vcard_partnum);
1978 if (vcard_source != NULL) {
1980 /* Grab the name off the card */
1981 display_vcard(vcard_source, 0, 0, namebuf,msgnum);
1987 lastfirst_firstlast(namebuf);
1989 len = strlen(namebuf);
1990 for (i=0; i<len; ++i) {
1991 if (namebuf[i] != ';') return;
1993 strcpy(namebuf, _("(no name)"));
1999 * \brief Record compare function for sorting address book indices
2000 * \param ab1 adressbook one
2001 * \param ab2 adressbook two
2003 int abcmp(const void *ab1, const void *ab2) {
2005 (((const struct addrbookent *)ab1)->ab_name),
2006 (((const struct addrbookent *)ab2)->ab_name)
2012 * \brief Helper function for do_addrbook_view()
2013 * Converts a name into a three-letter tab label
2014 * \param tabbuf the tabbuffer to add name to
2015 * \param name the name to add to the tabbuffer
2017 void nametab(char *tabbuf, long len, char *name) {
2018 stresc(tabbuf, len, name, 0, 0);
2019 tabbuf[0] = toupper(tabbuf[0]);
2020 tabbuf[1] = tolower(tabbuf[1]);
2021 tabbuf[2] = tolower(tabbuf[2]);
2027 * \brief Render the address book using info we gathered during the scan
2028 * \param addrbook the addressbook to render
2029 * \param num_ab the number of the addressbook
2031 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
2035 static int NAMESPERPAGE = 60;
2038 char tabfirst_label[64];
2040 char tablast_label[64];
2041 char this_tablabel[64];
2046 wprintf("<br /><br /><br /><div align=\"center\"><i>");
2047 wprintf(_("This address book is empty."));
2048 wprintf("</i></div>\n");
2053 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
2056 num_pages = (num_ab / NAMESPERPAGE) + 1;
2058 tablabels = malloc(num_pages * sizeof (char *));
2059 if (tablabels == NULL) {
2060 wprintf("<br /><br /><br /><div align=\"center\"><i>");
2061 wprintf(_("An internal error has occurred."));
2062 wprintf("</i></div>\n");
2066 for (i=0; i<num_pages; ++i) {
2067 tabfirst = i * NAMESPERPAGE;
2068 tablast = tabfirst + NAMESPERPAGE - 1;
2069 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
2070 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
2071 nametab(tablast_label, 64, addrbook[tablast].ab_name);
2072 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
2073 tablabels[i] = strdup(this_tablabel);
2076 tabbed_dialog(num_pages, tablabels);
2079 for (i=0; i<num_ab; ++i) {
2081 if ((i / NAMESPERPAGE) != page) { /* New tab */
2082 page = (i / NAMESPERPAGE);
2084 wprintf("</tr></table>\n");
2085 end_tab(page-1, num_pages);
2087 begin_tab(page, num_pages);
2088 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
2092 if ((displayed % 4) == 0) {
2093 if (displayed > 0) {
2097 wprintf("<tr bgcolor=\"#%s\">",
2098 (bg ? "DDDDDD" : "FFFFFF")
2104 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
2105 addrbook[i].ab_msgnum);
2106 wprintf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
2107 vcard_n_prettyize(addrbook[i].ab_name);
2108 escputs(addrbook[i].ab_name);
2109 wprintf("</a></td>\n");
2113 wprintf("</tr></table>\n");
2114 end_tab((num_pages-1), num_pages);
2116 for (i=0; i<num_pages; ++i) {
2125 * \brief load message pointers from the server
2126 * \param servcmd the citadel command to send to the citserver
2127 * \param with_headers what headers???
2129 int load_msg_ptrs(char *servcmd, int with_headers)
2142 int num_summ_alloc = 0;
2144 if (WC->summ != NULL) {
2149 num_summ_alloc = 100;
2151 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
2154 maxload = sizeof(WC->msgarr) / sizeof(long) ;
2156 serv_getln(buf, sizeof buf);
2157 if (buf[0] != '1') {
2160 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2161 if (nummsgs < maxload) {
2162 WC->msgarr[nummsgs] = extract_long(buf, 0);
2163 datestamp = extract_long(buf, 1);
2164 extract_token(fullname, buf, 2, '|', sizeof fullname);
2165 extract_token(nodename, buf, 3, '|', sizeof nodename);
2166 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
2167 extract_token(subject, buf, 5, '|', sizeof subject);
2171 if (nummsgs > num_summ_alloc) {
2172 num_summ_alloc *= 2;
2173 WC->summ = realloc(WC->summ,
2174 num_summ_alloc * sizeof(struct message_summary));
2178 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
2179 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
2180 safestrncpy(WC->summ[nummsgs-1].subj,
2181 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
2182 if (!IsEmptyStr(subject)) {
2183 /** Handle subjects with RFC2047 encoding */
2184 utf8ify_rfc822_string(subject);
2185 safestrncpy(WC->summ[nummsgs-1].subj, subject,
2186 sizeof WC->summ[nummsgs-1].subj);
2188 sbjlen = Ctdl_Utf8StrLen(WC->summ[nummsgs-1].subj);
2190 ptr = Ctdl_Utf8StrCut(WC->summ[nummsgs-1].subj, 72);
2195 if (!IsEmptyStr(fullname)) {
2196 /** Handle senders with RFC2047 encoding */
2197 utf8ify_rfc822_string(fullname);
2198 safestrncpy(WC->summ[nummsgs-1].from,
2199 fullname, sizeof WC->summ[nummsgs-1].from);
2201 if ((!IsEmptyStr(nodename)) &&
2202 ( ((WC->room_flags & QR_NETWORK)
2203 || ((strcasecmp(nodename, serv_info.serv_nodename)
2204 && (strcasecmp(nodename, serv_info.serv_fqdn)))))))
2206 strcat(WC->summ[nummsgs-1].from, " @ ");
2207 strcat(WC->summ[nummsgs-1].from, nodename);
2210 sbjlen = Ctdl_Utf8StrLen(WC->summ[nummsgs-1].from);
2212 ptr = Ctdl_Utf8StrCut(WC->summ[nummsgs-1].from, 23);
2216 WC->summ[nummsgs-1].date = datestamp;
2224 * \brief qsort() compatible function to compare two longs in descending order.
2226 * \param s1 first number to compare
2227 * \param s2 second number to compare
2229 int longcmp_r(const void *s1, const void *s2) {
2236 if (l1 > l2) return(-1);
2237 if (l1 < l2) return(+1);
2243 * \brief qsort() compatible function to compare two message summary structs by ascending subject.
2245 * \param s1 first item to compare
2246 * \param s2 second item to compare
2248 int summcmp_subj(const void *s1, const void *s2) {
2249 struct message_summary *summ1;
2250 struct message_summary *summ2;
2252 summ1 = (struct message_summary *)s1;
2253 summ2 = (struct message_summary *)s2;
2254 return strcasecmp(summ1->subj, summ2->subj);
2258 * \brief qsort() compatible function to compare two message summary structs by descending subject.
2260 * \param s1 first item to compare
2261 * \param s2 second item to compare
2263 int summcmp_rsubj(const void *s1, const void *s2) {
2264 struct message_summary *summ1;
2265 struct message_summary *summ2;
2267 summ1 = (struct message_summary *)s1;
2268 summ2 = (struct message_summary *)s2;
2269 return strcasecmp(summ2->subj, summ1->subj);
2273 * \brief qsort() compatible function to compare two message summary structs by ascending sender.
2275 * \param s1 first item to compare
2276 * \param s2 second item to compare
2278 int summcmp_sender(const void *s1, const void *s2) {
2279 struct message_summary *summ1;
2280 struct message_summary *summ2;
2282 summ1 = (struct message_summary *)s1;
2283 summ2 = (struct message_summary *)s2;
2284 return strcasecmp(summ1->from, summ2->from);
2288 * \brief qsort() compatible function to compare two message summary structs by descending sender.
2290 * \param s1 first item to compare
2291 * \param s2 second item to compare
2293 int summcmp_rsender(const void *s1, const void *s2) {
2294 struct message_summary *summ1;
2295 struct message_summary *summ2;
2297 summ1 = (struct message_summary *)s1;
2298 summ2 = (struct message_summary *)s2;
2299 return strcasecmp(summ2->from, summ1->from);
2303 * \brief qsort() compatible function to compare two message summary structs by ascending date.
2305 * \param s1 first item to compare
2306 * \param s2 second item to compare
2308 int summcmp_date(const void *s1, const void *s2) {
2309 struct message_summary *summ1;
2310 struct message_summary *summ2;
2312 summ1 = (struct message_summary *)s1;
2313 summ2 = (struct message_summary *)s2;
2315 if (summ1->date < summ2->date) return -1;
2316 else if (summ1->date > summ2->date) return +1;
2321 * \brief qsort() compatible function to compare two message summary structs by descending date.
2323 * \param s1 first item to compare
2324 * \param s2 second item to compare
2326 int summcmp_rdate(const void *s1, const void *s2) {
2327 struct message_summary *summ1;
2328 struct message_summary *summ2;
2330 summ1 = (struct message_summary *)s1;
2331 summ2 = (struct message_summary *)s2;
2333 if (summ1->date < summ2->date) return +1;
2334 else if (summ1->date > summ2->date) return -1;
2341 * \brief command loop for reading messages
2343 * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
2345 void readloop(char *oper)
2354 long *displayed_msgs = NULL;
2355 int num_displayed = 0;
2357 int is_addressbook = 0;
2358 int is_singlecard = 0;
2359 int is_calendar = 0;
2364 int lowest_displayed = (-1);
2365 int highest_displayed = 0;
2366 struct addrbookent *addrbook = NULL;
2368 StrBuf *sortby = NULL;
2369 StrBuf *sortpref_name;
2370 StrBuf *sortpref_value;
2371 char *subjsort_button;
2372 char *sendsort_button;
2373 char *datesort_button;
2374 int bbs_reverse = 0;
2375 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
2377 if (WCC->wc_view == VIEW_WIKI) {
2378 sprintf(buf, "wiki?room=%s?page=home", WCC->wc_roomname);
2383 startmsg = lbstr("startmsg");
2384 maxmsgs = ibstr("maxmsgs");
2385 is_summary = (ibstr("is_summary") && !WCC->is_mobile);
2386 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2388 sortpref_name = NewStrBuf ();
2389 StrBufPrintf(sortpref_name, "sort %s", WCC->wc_roomname);
2390 get_pref(sortpref_name, &sortpref_value);
2392 sortby = NewStrBufPlain(bstr("sortby"), -1);
2393 if ( (!IsEmptyStr(ChrPtr(sortby))) &&
2394 (strcasecmp(ChrPtr(sortby), ChrPtr(sortpref_value))) ) {
2395 set_pref(sortpref_name, sortby, 1);
2397 FreeStrBuf(&sortpref_name);
2398 if (IsEmptyStr(ChrPtr(sortby))) StrBufAppendBuf(sortby, sortpref_value, 0);
2401 if (IsEmptyStr(ChrPtr(sortby))) StrBufPrintf(sortby, "rdate");
2403 /** message board sort */
2404 if (!strcasecmp(ChrPtr(sortby), "reverse")) {
2411 output_headers(1, 1, 1, 0, 0, 0);
2414 * When in summary mode, always show ALL messages instead of just
2415 * new or old. Otherwise, show what the user asked for.
2417 if (!strcmp(oper, "readnew")) {
2418 strcpy(cmd, "MSGS NEW");
2420 else if (!strcmp(oper, "readold")) {
2421 strcpy(cmd, "MSGS OLD");
2423 else if (!strcmp(oper, "do_search")) {
2424 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2427 strcpy(cmd, "MSGS ALL");
2430 if ((WCC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1) && !WCC->is_mobile) {
2432 if (!strcmp(oper, "do_search")) {
2433 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2436 strcpy(cmd, "MSGS ALL");
2440 if ((WCC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2442 if (!strcmp(oper, "do_search")) {
2443 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2446 strcpy(cmd, "MSGS ALL");
2451 if (is_summary || WCC->is_mobile) { /**< fetch header summary */
2452 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
2453 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2454 (!strcmp(oper, "do_search") ? bstr("query") : "")
2459 if (WCC->is_mobile) {
2465 * Are we doing a summary view? If so, we need to know old messages
2466 * and new messages, so we can do that pretty boldface thing for the
2469 strcpy(old_msgs, "");
2470 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){
2472 serv_getln(buf, sizeof buf);
2473 if (buf[0] == '2') {
2474 strcpy(old_msgs, &buf[4]);
2478 is_singlecard = ibstr("is_singlecard");
2480 if (WCC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2482 strcpy(cmd, "MSGS ALL|||1");
2485 if (WCC->wc_default_view == VIEW_TASKS) { /**< tasks */
2487 strcpy(cmd, "MSGS ALL");
2490 if (WCC->wc_default_view == VIEW_NOTES) { /**< notes */
2492 strcpy(cmd, "MSGS ALL");
2497 wprintf("<div id=\"new_notes_here\"></div>\n");
2500 nummsgs = load_msg_ptrs(cmd, (is_summary || WCC->is_mobile));
2503 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2504 wprintf("<div align=\"center\"><br /><em>");
2505 if (!strcmp(oper, "readnew")) {
2506 wprintf(_("No new messages."));
2507 } else if (!strcmp(oper, "readold")) {
2508 wprintf(_("No old messages."));
2510 wprintf(_("No messages here."));
2512 wprintf("</em><br /></div>\n");
2518 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){
2519 for (a = 0; a < nummsgs; ++a) {
2520 /** Are you a new message, or an old message? */
2522 if (is_msg_in_mset(old_msgs, WCC->msgarr[a])) {
2523 WCC->summ[a].is_new = 0;
2526 WCC->summ[a].is_new = 1;
2532 if (startmsg == 0L) {
2534 startmsg = WCC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2537 startmsg = WCC->msgarr[0];
2541 if (is_summary || WCC->is_mobile) {
2542 if (!strcasecmp(ChrPtr(sortby), "subject")) {
2543 qsort(WCC->summ, WCC->num_summ,
2544 sizeof(struct message_summary), summcmp_subj);
2546 else if (!strcasecmp(ChrPtr(sortby), "rsubject")) {
2547 qsort(WCC->summ, WCC->num_summ,
2548 sizeof(struct message_summary), summcmp_rsubj);
2550 else if (!strcasecmp(ChrPtr(sortby), "sender")) {
2551 qsort(WCC->summ, WCC->num_summ,
2552 sizeof(struct message_summary), summcmp_sender);
2554 else if (!strcasecmp(ChrPtr(sortby), "rsender")) {
2555 qsort(WCC->summ, WCC->num_summ,
2556 sizeof(struct message_summary), summcmp_rsender);
2558 else if (!strcasecmp(ChrPtr(sortby), "date")) {
2559 qsort(WCC->summ, WCC->num_summ,
2560 sizeof(struct message_summary), summcmp_date);
2562 else if (!strcasecmp(ChrPtr(sortby), "rdate")) {
2563 qsort(WCC->summ, WCC->num_summ,
2564 sizeof(struct message_summary), summcmp_rdate);
2568 if (!strcasecmp(ChrPtr(sortby), "subject")) {
2569 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2571 else if (!strcasecmp(ChrPtr(sortby), "rsubject")) {
2572 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2575 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2578 if (!strcasecmp(ChrPtr(sortby), "sender")) {
2579 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2581 else if (!strcasecmp(ChrPtr(sortby), "rsender")) {
2582 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2585 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2588 if (!strcasecmp(ChrPtr(sortby), "date")) {
2589 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2591 else if (!strcasecmp(ChrPtr(sortby), "rdate")) {
2592 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2595 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2600 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2601 " document.onkeydown = CtdlMsgListKeyPress; "
2602 " if (document.layers) { "
2603 " document.captureEvents(Event.KEYPRESS); "
2608 /** note that Date and Delete are now in the same column */
2609 wprintf("<div id=\"message_list_hdr\">"
2610 "<div class=\"fix_scrollbar_bug\">"
2611 "<table cellspacing=0 style=\"width:100%%\">"
2614 wprintf("<th width=%d%%>%s %s</th>"
2615 "<th width=%d%%>%s %s</th>"
2616 "<th width=%d%%>%s %s"
2618 "<input type=\"submit\" name=\"delete_button\" id=\"delbutton\" "
2619 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2625 _("Subject"), subjsort_button,
2626 SENDER_COL_WIDTH_PCT,
2627 _("Sender"), sendsort_button,
2628 DATE_PLUS_BUTTONS_WIDTH_PCT,
2629 _("Date"), datesort_button,
2632 wprintf("</table></div></div>\n");
2633 wprintf("<div id=\"message_list\">"
2635 "<div class=\"fix_scrollbar_bug\">\n"
2636 "<table class=\"mailbox_summary\" id=\"summary_headers\" "
2637 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2639 } else if (WCC->is_mobile) {
2640 wprintf("<div id=\"message_list\">");
2645 * Set the "is_bbview" variable if it appears that we are looking at
2646 * a classic bulletin board view.
2648 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2649 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2654 * If we're not currently looking at ALL requested
2655 * messages, then display the selector bar
2658 /** begin bbview scroller */
2659 wprintf("<form name=\"msgomatictop\" class=\"selector_top\" > \n <p>");
2660 wprintf(_("Reading #"));//// TODO this isn't used, should it? : , lowest_displayed, highest_displayed);
2662 wprintf("<select name=\"whichones\" size=\"1\" "
2663 "OnChange=\"location.href=msgomatictop.whichones.options"
2664 "[selectedIndex].value\">\n");
2667 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2669 lo = b - maxmsgs + 2;
2671 wprintf("<option %s value="
2676 "%d-%d</option> \n",
2677 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2686 for (b=0; b<nummsgs; b = b + maxmsgs) {
2688 hi = b + maxmsgs + 1;
2689 if (hi > nummsgs) hi = nummsgs;
2690 wprintf("<option %s value="
2695 "%d-%d</option> \n",
2696 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2705 wprintf("<option value=\"%s?startmsg=%ld"
2706 "?maxmsgs=9999999?is_summary=%d\">",
2708 WCC->msgarr[0], is_summary);
2710 wprintf("</option>");
2711 wprintf("</select> ");
2712 wprintf(_("of %d messages."), nummsgs);
2714 /** forward/reverse */
2715 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2716 "OnChange=\"location.href='%s?sortby=forward'\"",
2717 (bbs_reverse ? "" : "checked"),
2721 wprintf(_("oldest to newest"));
2722 wprintf(" ");
2724 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2725 "OnChange=\"location.href='%s?sortby=reverse'\"",
2726 (bbs_reverse ? "checked" : ""),
2730 wprintf(_("newest to oldest"));
2733 wprintf("</p></form>\n");
2734 /** end bbview scroller */
2736 for (a = 0; a < nummsgs; ++a) {
2737 if ((WCC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2739 /** Display the message */
2741 display_summarized(a);
2743 else if (is_addressbook) {
2744 fetch_ab_name(WCC->msgarr[a], buf);
2746 addrbook = realloc(addrbook,
2747 (sizeof(struct addrbookent) * num_ab) );
2748 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2749 sizeof(addrbook[num_ab-1].ab_name));
2750 addrbook[num_ab-1].ab_msgnum = WCC->msgarr[a];
2752 else if (is_calendar) {
2753 display_calendar(WCC->msgarr[a], WCC->summ[a].is_new);
2755 else if (is_tasks) {
2756 display_task(WCC->msgarr[a], WCC->summ[a].is_new);
2758 else if (is_notes) {
2759 display_note(WCC->msgarr[a], WCC->summ[a].is_new);
2760 } else if (WCC->is_mobile) {
2761 display_mobile_summary(a);
2764 if (displayed_msgs == NULL) {
2765 displayed_msgs = malloc(sizeof(long) *
2766 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2768 displayed_msgs[num_displayed] = WCC->msgarr[a];
2771 if (lowest_displayed < 0) lowest_displayed = a;
2772 highest_displayed = a;
2779 if (displayed_msgs != NULL) {
2781 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2784 /** if we do a split bbview in the future, begin messages div here */
2786 for (a=0; a<num_displayed; ++a) {
2787 read_message(displayed_msgs[a], 0, "");
2790 /** if we do a split bbview in the future, end messages div here */
2792 free(displayed_msgs);
2793 displayed_msgs = NULL;
2798 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2799 wprintf("</div>"); /**< end of 'message_list' div */
2801 /** Here's the grab-it-to-resize-the-message-list widget */
2802 wprintf("<div id=\"resize_msglist\" "
2803 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2804 "<div class=\"fix_scrollbar_bug\"> <hr>"
2808 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2809 } else if (WCC->is_mobile) {
2814 * Bump these because although we're thinking in zero base, the user
2815 * is a drooling idiot and is thinking in one base.
2818 ++highest_displayed;
2821 * If we're not currently looking at ALL requested
2822 * messages, then display the selector bar
2825 /** begin bbview scroller */
2826 wprintf("<form name=\"msgomatic\" class=\"selector_bottom\" > \n <p>");
2827 wprintf(_("Reading #")); /// TODO: this isn't used: , lowest_displayed, highest_displayed);
2829 wprintf("<select name=\"whichones\" size=\"1\" "
2830 "OnChange=\"location.href=msgomatic.whichones.options"
2831 "[selectedIndex].value\">\n");
2834 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2836 lo = b - maxmsgs + 2;
2838 wprintf("<option %s value="
2843 "%d-%d</option> \n",
2844 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2853 for (b=0; b<nummsgs; b = b + maxmsgs) {
2855 hi = b + maxmsgs + 1;
2856 if (hi > nummsgs) hi = nummsgs;
2857 wprintf("<option %s value="
2862 "%d-%d</option> \n",
2863 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2872 wprintf("<option value=\"%s?startmsg=%ld"
2873 "?maxmsgs=9999999?is_summary=%d\">",
2875 WCC->msgarr[0], is_summary);
2877 wprintf("</option>");
2878 wprintf("</select> ");
2879 wprintf(_("of %d messages."), nummsgs);
2881 /** forward/reverse */
2882 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2883 "OnChange=\"location.href='%s?sortby=forward'\"",
2884 (bbs_reverse ? "" : "checked"),
2888 wprintf(_("oldest to newest"));
2889 wprintf(" ");
2890 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2891 "OnChange=\"location.href='%s?sortby=reverse'\"",
2892 (bbs_reverse ? "checked" : ""),
2896 wprintf(_("newest to oldest"));
2899 wprintf("</p></form>\n");
2900 /** end bbview scroller */
2905 do_tasks_view(); /** Render the task list */
2909 do_calendar_view(); /** Render the calendar */
2912 if (is_addressbook) {
2913 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2916 /** Note: wDumpContent() will output one additional </div> tag. */
2917 wprintf("</div>\n"); /** end of 'content' div */
2920 /** free the summary */
2921 if (WCC->summ != NULL) {
2926 if (addrbook != NULL) free(addrbook);
2931 * Back end for post_message()
2932 * ... this is where the actual message gets transmitted to the server.
2934 void post_mime_to_server(void) {
2935 char top_boundary[SIZ];
2936 char alt_boundary[SIZ];
2937 int is_multipart = 0;
2939 struct wc_attachment *att;
2941 size_t encoded_length;
2942 size_t encoded_strlen;
2943 char *txtmail = NULL;
2945 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
2946 serv_info.serv_fqdn,
2950 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
2951 serv_info.serv_fqdn,
2956 /* RFC2045 requires this, and some clients look for it... */
2957 serv_puts("MIME-Version: 1.0");
2958 serv_puts("X-Mailer: " PACKAGE_STRING);
2960 /* If there are attachments, we have to do multipart/mixed */
2961 if (WC->first_attachment != NULL) {
2966 /* Remember, serv_printf() appends an extra newline */
2967 serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
2968 serv_printf("This is a multipart message in MIME format.\n");
2969 serv_printf("--%s", top_boundary);
2972 /* Remember, serv_printf() appends an extra newline */
2973 serv_printf("Content-type: multipart/alternative; "
2974 "boundary=\"%s\"\n", alt_boundary);
2975 serv_printf("This is a multipart message in MIME format.\n");
2976 serv_printf("--%s", alt_boundary);
2978 serv_puts("Content-type: text/plain; charset=utf-8");
2979 serv_puts("Content-Transfer-Encoding: quoted-printable");
2981 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
2982 text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */
2985 serv_printf("--%s", alt_boundary);
2987 serv_puts("Content-type: text/html; charset=utf-8");
2988 serv_puts("Content-Transfer-Encoding: quoted-printable");
2990 serv_puts("<html><body>\r\n");
2991 text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */
2992 serv_puts("</body></html>\r\n");
2994 serv_printf("--%s--", alt_boundary);
2998 /* Add in the attachments */
2999 for (att = WC->first_attachment; att!=NULL; att=att->next) {
3001 encoded_length = ((att->length * 150) / 100);
3002 encoded = malloc(encoded_length);
3003 if (encoded == NULL) break;
3004 encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1);
3006 serv_printf("--%s", top_boundary);
3007 serv_printf("Content-type: %s", att->content_type);
3008 serv_printf("Content-disposition: attachment; filename=\"%s\"", att->filename);
3009 serv_puts("Content-transfer-encoding: base64");
3011 serv_write(encoded, encoded_strlen);
3016 serv_printf("--%s--", top_boundary);
3024 * Post message (or don't post message)
3026 * Note regarding the "dont_post" variable:
3027 * A random value (actually, it's just a timestamp) is inserted as a hidden
3028 * field called "postseq" when the display_enter page is generated. This
3029 * value is checked when posting, using the static variable dont_post. If a
3030 * user attempts to post twice using the same dont_post value, the message is
3031 * discarded. This prevents the accidental double-saving of the same message
3032 * if the user happens to click the browser "back" button.
3034 void post_message(void)
3039 char *encoded_subject = NULL;
3040 static long dont_post = (-1L);
3041 struct wc_attachment *att, *aptr;
3042 int is_anonymous = 0;
3043 const char *display_name;
3045 struct wcsession *WCC = WC;
3048 if (havebstr("force_room")) {
3049 gotoroom(bstr("force_room"));
3052 if (GetHash(WC->urlstrings, HKEY("display_name"), &U)) {
3053 u = (urlcontent*) U;
3054 display_name = u->url_data;
3055 dpLen = u->url_data_size;
3060 if (!strcmp(display_name, "__ANONYMOUS__")) {
3065 if (WCC->upload_length > 0) {
3067 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WCC->upload_length);
3068 /** There's an attachment. Save it to this struct... */
3069 att = malloc(sizeof(struct wc_attachment));
3070 memset(att, 0, sizeof(struct wc_attachment));
3071 att->length = WCC->upload_length;
3072 strcpy(att->content_type, WCC->upload_content_type);
3073 strcpy(att->filename, WCC->upload_filename);
3076 /** And add it to the list. */
3077 if (WCC->first_attachment == NULL) {
3078 WCC->first_attachment = att;
3081 aptr = WCC->first_attachment;
3082 while (aptr->next != NULL) aptr = aptr->next;
3087 * Mozilla sends a simple filename, which is what we want,
3088 * but Satan's Browser sends an entire pathname. Reduce
3089 * the path to just a filename if we need to.
3091 while (num_tokens(att->filename, '/') > 1) {
3092 remove_token(att->filename, 0, '/');
3094 while (num_tokens(att->filename, '\\') > 1) {
3095 remove_token(att->filename, 0, '\\');
3099 * Transfer control of this memory from the upload struct
3100 * to the attachment struct.
3102 att->data = WCC->upload;
3103 WCC->upload_length = 0;
3109 if (havebstr("cancel_button")) {
3110 sprintf(WCC->ImportantMessage,
3111 _("Cancelled. Message was not posted."));
3112 } else if (havebstr("attach_button")) {
3115 } else if (lbstr("postseq") == dont_post) {
3116 sprintf(WCC->ImportantMessage,
3117 _("Automatically cancelled because you have already "
3118 "saved this message."));
3120 const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s";
3121 const char *Recp = "";
3122 const char *Cc = "";
3123 const char *Bcc = "";
3124 const char *Wikipage = "";
3125 const char *my_email_addr = "";
3126 char *CmdBuf = NULL;;
3129 char references[SIZ] = "";
3130 size_t references_len = 0;
3132 safestrncpy(references, bstr("references"), sizeof references);
3133 lprintf(9, "Converting: %s\n", references);
3134 for (ptr=references; *ptr != 0; ++ptr) {
3135 if (*ptr == '|') *ptr = '!';
3138 lprintf(9, "Converted: %s\n", references);
3140 if (havebstr("subject")) {
3144 * make enough room for the encoded string;
3145 * plus the QP header
3147 Subj = xbstr("subject", &SLen);
3148 len = SLen * 3 + 32;
3149 encoded_subject = malloc (len);
3150 len = webcit_rfc2047encode(encoded_subject, len, Subj, SLen);
3152 free (encoded_subject);
3156 len += sizeof (CMD) + dpLen;
3157 Recp = xbstr("recp", &nLen);
3159 Cc = xbstr("cc", &nLen);
3161 Bcc = xbstr("bcc", &nLen);
3163 Wikipage = xbstr("wikipage", &nLen);
3165 my_email_addr = xbstr("my_email_addr", &nLen);
3167 len += references_len;
3169 CmdBuf = (char*) malloc (len + 11);
3171 snprintf(CmdBuf, len + 1, CMD,
3174 (encoded_subject ? encoded_subject : ""),
3181 lprintf(9, "%s\n", CmdBuf);
3183 serv_getln(buf, sizeof buf);
3185 if (encoded_subject) free(encoded_subject);
3186 if (buf[0] == '4') {
3187 post_mime_to_server();
3188 if ( (havebstr("recp"))
3189 || (havebstr("cc" ))
3190 || (havebstr("bcc" ))
3192 sprintf(WCC->ImportantMessage, _("Message has been sent.\n"));
3195 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
3197 dont_post = lbstr("postseq");
3199 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
3200 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3206 free_attachments(WCC);
3209 * We may have been supplied with instructions regarding the location
3210 * to which we must return after posting. If found, go there.
3212 if (havebstr("return_to")) {
3213 http_redirect(bstr("return_to"));
3216 * If we were editing a page in a wiki room, go to that page now.
3218 else if (havebstr("wikipage")) {
3219 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
3223 * Otherwise, just go to the "read messages" loop.
3226 readloop("readnew");
3234 * \brief display the message entry screen
3236 void display_enter(void)
3242 struct wc_attachment *att;
3243 int recipient_required = 0;
3244 int subject_required = 0;
3245 int recipient_bad = 0;
3247 int is_anonymous = 0;
3248 long existing_page = (-1L);
3253 if (havebstr("force_room")) {
3254 gotoroom(bstr("force_room"));
3257 display_name = xbstr("display_name", &dplen);
3258 if (!strcmp(display_name, "__ANONYMOUS__")) {
3264 /** First test to see whether this is a room that requires recipients to be entered */
3265 serv_puts("ENT0 0");
3266 serv_getln(buf, sizeof buf);
3268 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
3269 recipient_required = 1;
3271 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3272 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3273 readloop("readnew");
3277 /* Is the server strongly recommending that the user enter a message subject? */
3278 if ((buf[3] != '\0') && (buf[4] != '\0')) {
3279 subject_required = extract_int(&buf[4], 1);
3283 * Are we perhaps in an address book view? If so, then an "enter
3284 * message" command really means "add new entry."
3286 if (WC->wc_default_view == VIEW_ADDRESSBOOK) {
3287 do_edit_vcard(-1, "", "", WC->wc_roomname);
3292 * Are we perhaps in a calendar room? If so, then an "enter
3293 * message" command really means "add new calendar item."
3295 if (WC->wc_default_view == VIEW_CALENDAR) {
3296 display_edit_event();
3301 * Are we perhaps in a tasks view? If so, then an "enter
3302 * message" command really means "add new task."
3304 if (WC->wc_default_view == VIEW_TASKS) {
3305 display_edit_task();
3310 * Otherwise proceed normally.
3311 * Do a custom room banner with no navbar...
3313 output_headers(1, 1, 2, 0, 0, 0);
3314 wprintf("<div id=\"banner\">\n");
3315 embed_room_banner(NULL, navbar_none);
3316 wprintf("</div>\n");
3317 wprintf("<div id=\"content\">\n"
3318 "<div class=\"fix_scrollbar_bug message \">");
3320 /* Now check our actual recipients if there are any */
3321 if (recipient_required) {
3322 const char *Recp = "";
3323 const char *Cc = "";
3324 const char *Bcc = "";
3325 const char *Wikipage = "";
3326 char *CmdBuf = NULL;;
3329 const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
3331 len = sizeof(CMD) + dplen;
3332 Recp = xbstr("recp", &nLen);
3334 Cc = xbstr("cc", &nLen);
3336 Bcc = xbstr("bcc", &nLen);
3338 Wikipage = xbstr("wikipage", &nLen);
3342 CmdBuf = (char*) malloc (len + 1);
3344 snprintf(CmdBuf, len, CMD,
3349 serv_getln(buf, sizeof buf);
3351 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
3352 if (havebstr("recp") &&
3358 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3359 wprintf("<em>%s</em><br />\n", &buf[4]);
3364 /** If we got this far, we can display the message entry screen. */
3366 /* begin message entry screen */
3368 "enctype=\"multipart/form-data\" "
3370 "accept-charset=\"UTF-8\" "
3372 "name=\"enterform\""
3374 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
3375 if (WC->wc_view == VIEW_WIKI) {
3376 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
3378 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
3379 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
3380 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
3381 escputs(WC->wc_roomname);
3383 wprintf("<input type=\"hidden\" name=\"references\" value=\"");
3384 escputs(bstr("references"));
3387 /** submit or cancel buttons */
3388 wprintf("<p class=\"send_edit_msg\">");
3389 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3390 if (recipient_required) {
3391 wprintf(_("Send message"));
3393 wprintf(_("Post message"));
3396 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3401 wprintf("<img src=\"static/newmess3_24x.gif\" class=\"imgedit\">");
3402 wprintf(" "); /** header bar */
3403 webcit_fmt_date(buf, now, 0);
3405 wprintf("\n"); /** header bar */
3407 wprintf("<table width=\"100%%\" class=\"edit_msg_table\">");
3409 wprintf("<th><label for=\"from_id\" > ");
3410 wprintf(_(" <I>from</I> "));
3411 wprintf("</label></th>");
3413 wprintf("<td colspan=\"2\">");
3415 /* Allow the user to select any of his valid screen names */
3417 wprintf("<select name=\"display_name\" size=1 id=\"from_id\">\n");
3420 serv_getln(buf, sizeof buf);
3421 if (buf[0] == '1') {
3422 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3423 wprintf("<option %s value=\"",
3424 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
3429 wprintf("</option>\n");
3433 if (WC->room_flags & QR_ANONOPT) {
3434 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
3435 ((!strcasecmp(bstr("__ANONYMOUS__"), WC->wc_fullname)) ? "selected" : ""),
3440 wprintf("</select>\n");
3442 /* If this is an email (not a post), allow the user to select any of his
3443 * valid email addresses.
3445 if (recipient_required) {
3447 serv_getln(buf, sizeof buf);
3448 if (buf[0] == '1') {
3449 wprintf("<select name=\"my_email_addr\" size=1>\n");
3450 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3451 wprintf("<option value=\"");
3455 wprintf("></option>\n");
3457 wprintf("</select>\n");
3461 wprintf(_(" <I>in</I> "));
3462 escputs(WC->wc_roomname);
3464 wprintf("</td></tr>");
3466 if (recipient_required) {
3470 wprintf("<tr><th><label for=\"recp_id\"> ");
3472 wprintf("</label></th>"
3473 "<td><input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
3474 ccraw = xbstr("recp", &len);
3475 copy = (char*) malloc(len * 2 + 1);
3476 memcpy(copy, ccraw, len + 1);
3477 utf8ify_rfc822_string(copy);
3480 wprintf("\" size=45 maxlength=1000 />");
3481 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
3482 wprintf("</td><td rowspan=\"3\" align=\"left\" valign=\"top\">");
3484 /** Pop open an address book -- begin **/
3486 "<a href=\"javascript:PopOpenAddressBook('recp_id|%s|cc_id|%s|bcc_id|%s');\" "
3488 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
3490 _("To:"), _("CC:"), _("BCC:"),
3491 _("Contacts"), _("Contacts")
3493 /** Pop open an address book -- end **/
3495 wprintf("</td></tr>");
3497 wprintf("<tr><th><label for=\"cc_id\"> ");
3499 wprintf("</label></th>"
3500 "<td><input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
3501 ccraw = xbstr("cc", &len);
3502 copy = (char*) malloc(len * 2 + 1);
3503 memcpy(copy, ccraw, len + 1);
3504 utf8ify_rfc822_string(copy);
3507 wprintf("\" size=45 maxlength=1000 />");
3508 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
3509 wprintf("</td></tr>");
3511 wprintf("<tr><th><label for=\"bcc_id\"> ");
3513 wprintf("</label></th>"
3514 "<td><input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
3515 ccraw = xbstr("bcc", &len);
3516 copy = (char*) malloc(len * 2 + 1);
3517 memcpy(copy, ccraw, len + 1);
3518 utf8ify_rfc822_string(copy);
3521 wprintf("\" size=45 maxlength=1000 />");
3522 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
3523 wprintf("</td></tr>");
3525 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
3526 wprintf("<script type=\"text/javascript\"> \n"
3527 " activate_entmsg_autocompleters(); \n"
3533 wprintf("<tr><th><label for=\"subject_id\" > ");
3534 if (recipient_required || subject_required) {
3535 wprintf(_("Subject:"));
3538 wprintf(_("Subject (optional):"));
3540 wprintf("</label></th>"
3541 "<td colspan=\"2\">"
3542 "<input type=\"text\" name=\"subject\" id=\"subject_id\" value=\"");
3543 escputs(bstr("subject"));
3544 wprintf("\" size=45 maxlength=70>\n");
3545 wprintf("</td></tr>");
3547 wprintf("<tr><td colspan=\"3\">\n");
3549 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
3551 /** If we're continuing from a previous edit, put our partially-composed message back... */
3552 msgescputs(bstr("msgtext"));
3554 /* If we're forwarding a message, insert it here... */
3555 if (lbstr("fwdquote") > 0L) {
3556 wprintf("<br><div align=center><i>");
3557 wprintf(_("--- forwarded message ---"));
3558 wprintf("</i></div><br>");
3559 pullquote_message(lbstr("fwdquote"), 1, 1);
3562 /** If we're replying quoted, insert the quote here... */
3563 else if (lbstr("replyquote") > 0L) {
3566 pullquote_message(lbstr("replyquote"), 0, 1);
3567 wprintf("</blockquote><br>");
3570 /** If we're editing a wiki page, insert the existing page here... */
3571 else if (WC->wc_view == VIEW_WIKI) {
3572 safestrncpy(buf, bstr("wikipage"), sizeof buf);
3573 str_wiki_index(buf);
3574 existing_page = locate_message_by_uid(buf);
3575 if (existing_page >= 0L) {
3576 pullquote_message(existing_page, 1, 0);
3580 /** Insert our signature if appropriate... */
3581 if ( (WC->is_mailbox) && yesbstr("sig_inserted") ) {
3583 get_pref_yesno("use_sig", &UseSig, 0);
3586 get_preference("signature", &ebuf);
3587 euid_unescapize(buf, ChrPtr(ebuf));/////TODO
3588 wprintf("<br>--<br>");
3590 for (i=0; i<len; ++i) {
3591 if (buf[i] == '\n') {
3594 else if (buf[i] == '<') {
3597 else if (buf[i] == '>') {
3600 else if (buf[i] == '&') {
3603 else if (buf[i] == '\"') {
3606 else if (buf[i] == '\'') {
3609 else if (isprint(buf[i])) {
3610 wprintf("%c", buf[i]);
3616 wprintf("</textarea>\n");
3618 /** Make sure we only insert our signature once */
3619 /** We don't care if it was there or not before, it needs to be there now. */
3620 wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
3623 * The following template embeds the TinyMCE richedit control, and automatically
3624 * transforms the textarea into a richedit textarea.
3626 do_template("richedit");
3628 /** Enumerate any attachments which are already in place... */
3629 wprintf("<div class=\"attachment buttons\"><img src=\"static/diskette_24x.gif\" class=\"imgedit\" > ");
3630 wprintf(_("Attachments:"));
3632 wprintf("<select name=\"which_attachment\" size=1>");
3633 for (att = WC->first_attachment; att != NULL; att = att->next) {
3634 wprintf("<option value=\"");
3635 urlescputs(att->filename);
3637 escputs(att->filename);
3638 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3639 wprintf("</option>\n");
3641 wprintf("</select>");
3643 /** Now offer the ability to attach additional files... */
3644 wprintf(" ");
3645 wprintf(_("Attach file:"));
3646 wprintf(" <input name=\"attachfile\" class=\"attachfile\" "
3647 "size=16 type=\"file\">\n "
3648 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3649 wprintf("</div>"); /* End of "attachment buttons" div */
3652 wprintf("</td></tr></table>");
3654 wprintf("</form>\n");
3655 wprintf("</div>\n"); /* end of "fix_scrollbar_bug" div */
3657 /* NOTE: address_book_popup() will close the "content" div. Don't close it here. */
3658 DONE: address_book_popup();
3664 * \brief delete a message
3666 void delete_msg(void)
3671 msgid = lbstr("msgid");
3673 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3674 serv_printf("DELE %ld", msgid);
3676 else { /** Otherwise move it to Trash */
3677 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3680 serv_getln(buf, sizeof buf);
3681 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3683 readloop("readnew");
3688 * \brief move a message to another folder
3695 msgid = lbstr("msgid");
3697 if (havebstr("move_button")) {
3698 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3700 serv_getln(buf, sizeof buf);
3701 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3703 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3706 readloop("readnew");
3714 * Confirm move of a message
3716 void confirm_move_msg(void)
3722 msgid = lbstr("msgid");
3725 output_headers(1, 1, 2, 0, 0, 0);
3726 wprintf("<div id=\"banner\">\n");
3728 wprintf(_("Confirm move of message"));
3730 wprintf("</div>\n");
3732 wprintf("<div id=\"content\" class=\"service\">\n");
3734 wprintf("<CENTER>");
3736 wprintf(_("Move this message to:"));
3737 wprintf("<br />\n");
3739 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3740 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
3741 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3743 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3745 serv_getln(buf, sizeof buf);
3746 if (buf[0] == '1') {
3747 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3748 extract_token(targ, buf, 0, '|', sizeof targ);
3749 wprintf("<OPTION>");
3754 wprintf("</SELECT>\n");
3755 wprintf("<br />\n");
3757 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3759 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3760 wprintf("</form></CENTER>\n");
3762 wprintf("</CENTER>\n");