5 * \defgroup MsgDisp Functions which deal with the fetching and displaying of messages.
6 * \ingroup WebcitDisplayItems
12 #include "webserver.h"
15 #define SUBJ_COL_WIDTH_PCT 50 /**< Mailbox view column width */
16 #define SENDER_COL_WIDTH_PCT 30 /**< Mailbox view column width */
17 #define DATE_PLUS_BUTTONS_WIDTH_PCT 20 /**< Mailbox view column width */
20 * Address book entry (keep it short and sweet, it's just a quickie lookup
21 * which we can use to get to the real meat and bones later)
24 char ab_name[64]; /**< name string */
25 long ab_msgnum; /**< message number of address book entry */
33 * \brief Wrapper around iconv_open()
34 * Our version adds aliases for non-standard Microsoft charsets
35 * such as 'MS950', aliasing them to names like 'CP950'
37 * \param tocode Target encoding
38 * \param fromcode Source encoding
40 iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode)
42 iconv_t ic = (iconv_t)(-1) ;
43 ic = iconv_open(tocode, fromcode);
44 if (ic == (iconv_t)(-1) ) {
45 char alias_fromcode[64];
46 if ( (strlen(fromcode) == 5) && (!strncasecmp(fromcode, "MS", 2)) ) {
47 safestrncpy(alias_fromcode, fromcode, sizeof alias_fromcode);
48 alias_fromcode[0] = 'C';
49 alias_fromcode[1] = 'P';
50 ic = iconv_open(tocode, alias_fromcode);
58 * \brief Handle subjects with RFC2047 encoding
60 * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=
61 * \param buf the stringbuffer to process
63 void utf8ify_rfc822_string(char *buf) {
69 iconv_t ic = (iconv_t)(-1) ;
70 char *ibuf; /**< Buffer of characters to be converted */
71 char *obuf; /**< Buffer for converted characters */
72 size_t ibuflen; /**< Length of input buffer */
73 size_t obuflen; /**< Length of output buffer */
74 char *isav; /**< Saved pointer to input buffer */
75 char *osav; /**< Saved pointer to output buffer */
78 int illegal_non_rfc2047_encoding = 0;
80 /** Sometimes, badly formed messages contain strings which were simply
81 * written out directly in some foreign character set instead of
82 * using RFC2047 encoding. This is illegal but we will attempt to
83 * handle it anyway by converting from a user-specified default
84 * charset to UTF-8 if we see any nonprintable characters.
87 for (i=0; i<len; ++i) {
88 if ((buf[i] < 32) || (buf[i] > 126)) {
89 illegal_non_rfc2047_encoding = 1;
90 i = len; ///< take a shortcut, it won't be more than one.
93 if (illegal_non_rfc2047_encoding) {
94 char default_header_charset[128];
95 get_preference("default_header_charset", default_header_charset, sizeof default_header_charset);
96 if ( (strcasecmp(default_header_charset, "UTF-8")) && (strcasecmp(default_header_charset, "us-ascii")) ) {
97 ic = ctdl_iconv_open("UTF-8", default_header_charset);
98 if (ic != (iconv_t)(-1) ) {
101 safestrncpy(ibuf, buf, 1024);
102 ibuflen = strlen(ibuf);
104 obuf = (char *) malloc(obuflen);
106 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
107 osav[1024-obuflen] = 0;
116 /** Now we handle foreign character sets properly encoded
119 while (start=strstr(buf, "=?"), end=strstr(buf, "?="),
120 ((start != NULL) && (end != NULL) && (end > start)) )
122 extract_token(charset, start, 1, '?', sizeof charset);
123 extract_token(encoding, start, 2, '?', sizeof encoding);
124 extract_token(istr, start, 3, '?', sizeof istr);
128 if (!strcasecmp(encoding, "B")) { /**< base64 */
129 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
131 else if (!strcasecmp(encoding, "Q")) { /**< quoted-printable */
139 if (istr[pos] == '_') istr[pos] = ' ';
143 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, len);
146 strcpy(ibuf, istr); /**< unknown encoding */
147 ibuflen = strlen(istr);
150 ic = ctdl_iconv_open("UTF-8", charset);
151 if (ic != (iconv_t)(-1) ) {
153 obuf = (char *) malloc(obuflen);
155 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
156 osav[1024-obuflen] = 0;
161 remove_token(end, 0, '?');
162 remove_token(end, 0, '?');
163 remove_token(end, 0, '?');
164 remove_token(end, 0, '?');
165 strcpy(end, &end[1]);
167 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
176 remove_token(end, 0, '?');
177 remove_token(end, 0, '?');
178 remove_token(end, 0, '?');
179 remove_token(end, 0, '?');
180 strcpy(end, &end[1]);
182 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
189 * Since spammers will go to all sorts of absurd lengths to get their
190 * messages through, there are LOTS of corrupt headers out there.
191 * So, prevent a really badly formed RFC2047 header from throwing
192 * this function into an infinite loop.
195 if (passes > 20) return;
205 * \brief RFC2047-encode a header field if necessary.
206 * If no non-ASCII characters are found, the string
207 * will be copied verbatim without encoding.
209 * \param target Target buffer.
210 * \param maxlen Maximum size of target buffer.
211 * \param source Source string to be encoded.
213 void rfc2047encode(char *target, int maxlen, char *source)
215 int need_to_encode = 0;
219 if (target == NULL) return;
220 len = strlen(source);
221 for (i=0; i<len; ++i) {
222 if ((source[i] < 32) || (source[i] > 126)) {
224 i = len; ///< shortcut. won't become more than 1
228 if (!need_to_encode) {
229 safestrncpy(target, source, maxlen);
233 strcpy(target, "=?UTF-8?Q?");
234 for (i=0; i<len; ++i) {
235 ch = (unsigned char) source[i];
236 if ((ch < 32) || (ch > 126) || (ch == 61)) {
237 sprintf(&target[strlen(target)], "=%02X", ch);
240 sprintf(&target[strlen(target)], "%c", ch);
244 strcat(target, "?=");
251 * \brief Look for URL's embedded in a buffer and make them linkable. We use a
252 * target window in order to keep the BBS session in its own window.
253 * \param buf the message buffer
262 len = end = strlen(buf);
264 for (pos = 0; pos < len; ++pos) {
265 if (!strncasecmp(&buf[pos], "http://", 7))
267 if (!strncasecmp(&buf[pos], "ftp://", 6))
274 for (pos = len; pos > start; --pos) {
275 if ( (!isprint(buf[pos]))
276 || (isspace(buf[pos]))
280 || (buf[pos] == '\\')
294 strncpy(urlbuf, &buf[start], end - start);
295 urlbuf[end - start] = 0;
297 strncpy(outbuf, buf, start);
298 sprintf(&outbuf[start], "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
299 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
300 strcat(outbuf, &buf[end]);
301 if ( strlen(outbuf) < 250 )
307 * \brief Turn a vCard "n" (name) field into something displayable.
308 * \param name the name field to convert
310 void vcard_n_prettyize(char *name)
315 original_name = strdup(name);
316 len = strlen(original_name);
317 for (i=0; i<5; ++i) {
319 if (original_name[len-1] == ' ') {
320 original_name[--len] = 0;
322 if (original_name[len-1] == ';') {
323 original_name[--len] = 0;
329 for (i=0; i<len; ++i) {
330 if (original_name[i] == ';') {
335 name[j++] = original_name[i];
346 * \brief preparse a vcard name
347 * display_vcard() calls this after parsing the textual vCard into
348 * our 'struct vCard' data object.
349 * This gets called instead of display_parsed_vcard() if we are only looking
350 * to extract the person's name instead of displaying the card.
351 * \param v the vcard to retrieve the name from
352 * \param storename where to put the name at
354 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
357 strcpy(storename, "");
359 name = vcard_get_prop(v, "n", 1, 0, 0);
361 strcpy(storename, name);
362 /* vcard_n_prettyize(storename); */
370 * \brief html print a vcard
371 * display_vcard() calls this after parsing the textual vCard into
372 * our 'struct vCard' data object.
374 * Set 'full' to nonzero to display the full card, otherwise it will only
375 * show a summary line.
377 * This code is a bit ugly, so perhaps an explanation is due: we do this
378 * in two passes through the vCard fields. On the first pass, we process
379 * fields we understand, and then render them in a pretty fashion at the
380 * end. Then we make a second pass, outputting all the fields we don't
381 * understand in a simple two-column name/value format.
382 * \param v the vCard to display
383 * \param full display all items of the vcard?
385 void display_parsed_vcard(struct vCard *v, int full) {
391 char *thisname, *thisvalue;
392 char firsttoken[SIZ];
401 strcpy(fullname, "");
409 name = vcard_get_prop(v, "fn", 1, 0, 0);
413 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
414 strcpy(fullname, name);
415 vcard_n_prettyize(fullname);
425 wprintf("<div align=center>"
426 "<table bgcolor=#aaaaaa width=50%%>");
427 for (pass=1; pass<=2; ++pass) {
429 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
431 thisname = strdup(v->prop[i].name);
432 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
434 for (j=0; j<num_tokens(thisname, ';'); ++j) {
435 extract_token(buf, thisname, j, ';', sizeof buf);
436 if (!strcasecmp(buf, "encoding=quoted-printable")) {
438 remove_token(thisname, j, ';');
440 if (!strcasecmp(buf, "encoding=base64")) {
442 remove_token(thisname, j, ';');
446 len = strlen(v->prop[i].value);
449 // %ff can become 6 bytes in utf8
450 thisvalue = malloc(len * 2 + 3);
451 j = CtdlDecodeQuotedPrintable(
452 thisvalue, v->prop[i].value,
457 // ff will become one byte..
458 thisvalue = malloc(len + 50);
460 thisvalue, v->prop[i].value,
461 strlen(v->prop[i].value) );
464 thisvalue = strdup(v->prop[i].value);
467 /** Various fields we may encounter ***/
469 /** N is name, but only if there's no FN already there */
470 if (!strcasecmp(firsttoken, "n")) {
471 if (IsEmptyStr(fullname)) {
472 strcpy(fullname, thisvalue);
473 vcard_n_prettyize(fullname);
477 /** FN (full name) is a true 'display name' field */
478 else if (!strcasecmp(firsttoken, "fn")) {
479 strcpy(fullname, thisvalue);
483 else if (!strcasecmp(firsttoken, "title")) {
484 strcpy(title, thisvalue);
488 else if (!strcasecmp(firsttoken, "org")) {
489 strcpy(org, thisvalue);
492 else if (!strcasecmp(firsttoken, "email")) {
493 if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
495 "<a href=\"display_enter"
496 "?force_room=_MAIL_?recp=");
498 urlesc(&mailto[strlen(mailto)], fullname);
499 urlesc(&mailto[strlen(mailto)], " <");
500 urlesc(&mailto[strlen(mailto)], thisvalue);
501 urlesc(&mailto[strlen(mailto)], ">");
503 strcat(mailto, "\">");
504 stresc(&mailto[strlen(mailto)], thisvalue, 1, 1);
505 strcat(mailto, "</A>");
507 else if (!strcasecmp(firsttoken, "tel")) {
508 if (!IsEmptyStr(phone)) strcat(phone, "<br />");
509 strcat(phone, thisvalue);
510 for (j=0; j<num_tokens(thisname, ';'); ++j) {
511 extract_token(buf, thisname, j, ';', sizeof buf);
512 if (!strcasecmp(buf, "tel"))
514 else if (!strcasecmp(buf, "work"))
515 strcat(phone, _(" (work)"));
516 else if (!strcasecmp(buf, "home"))
517 strcat(phone, _(" (home)"));
518 else if (!strcasecmp(buf, "cell"))
519 strcat(phone, _(" (cell)"));
527 else if (!strcasecmp(firsttoken, "adr")) {
530 wprintf(_("Address:"));
531 wprintf("</TD><TD>");
532 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
533 extract_token(buf, thisvalue, j, ';', sizeof buf);
534 if (!IsEmptyStr(buf)) {
536 if (j<3) wprintf("<br />");
540 wprintf("</TD></TR>\n");
543 else if (!strcasecmp(firsttoken, "version")) {
546 else if (!strcasecmp(firsttoken, "rev")) {
549 else if (!strcasecmp(firsttoken, "label")) {
554 /*** Don't show extra fields. They're ugly.
558 wprintf("</TD><TD>");
560 wprintf("</TD></TR>\n");
570 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
571 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
572 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
573 "<FONT SIZE=+1><B>");
575 wprintf("</B></FONT>");
576 if (!IsEmptyStr(title)) {
577 wprintf("<div align=right>");
581 if (!IsEmptyStr(org)) {
582 wprintf("<div align=right>");
586 wprintf("</TD></TR>\n");
588 if (!IsEmptyStr(phone)) {
590 wprintf(_("Telephone:"));
591 wprintf("</td><td>%s</td></tr>\n", phone);
593 if (!IsEmptyStr(mailto)) {
595 wprintf(_("E-mail:"));
596 wprintf("</td><td>%s</td></tr>\n", mailto);
602 wprintf("</table></div>\n");
608 * \brief Display a textual vCard
609 * (Converts to a vCard object and then calls the actual display function)
610 * Set 'full' to nonzero to display the whole card instead of a one-liner.
611 * Or, if "storename" is non-NULL, just store the person's name in that
612 * buffer instead of displaying the card at all.
613 * \param vcard_source the buffer containing the vcard text
614 * \param alpha what???
615 * \param full should we usse all lines?
616 * \param storename where to store???
618 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
624 v = vcard_load(vcard_source);
625 if (v == NULL) return;
627 name = vcard_get_prop(v, "n", 1, 0, 0);
633 if (storename != NULL) {
634 fetchname_parsed_vcard(v, storename);
636 else if ( (alpha == 0)
637 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
638 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
640 display_parsed_vcard(v, full);
654 * \brief I wanna SEE that message!
655 * \param msgnum the citadel number of the message to display
656 * \param printable_view are we doing a print view?
657 * \param section Optional for encapsulated message/rfc822 submessage)
659 void read_message(long msgnum, int printable_view, char *section) {
661 char mime_partnum[256];
663 char mime_filename[256];
664 char mime_content_type[256];
665 char mime_charset[256];
666 char mime_disposition[256];
668 struct attach_link *attach_links = NULL;
669 int num_attach_links = 0;
670 char mime_submessages[256];
677 char reply_all[4096];
683 char vcard_partnum[256];
684 char cal_partnum[256];
685 char *part_source = NULL;
686 char msg4_partnum[32];
688 iconv_t ic = (iconv_t)(-1) ;
689 char *ibuf; /**< Buffer of characters to be converted */
690 char *obuf; /**< Buffer for converted characters */
691 size_t ibuflen; /**< Length of input buffer */
692 size_t obuflen; /**< Length of output buffer */
693 char *osav; /**< Saved pointer to output buffer */
699 strcpy(reply_to, "");
700 strcpy(reply_all, "");
701 strcpy(vcard_partnum, "");
702 strcpy(cal_partnum, "");
703 strcpy(mime_content_type, "text/plain");
704 strcpy(mime_charset, "us-ascii");
705 strcpy(mime_submessages, "");
707 serv_printf("MSG4 %ld|%s", msgnum, section);
708 serv_getln(buf, sizeof buf);
711 wprintf(_("ERROR:"));
712 wprintf("</strong> %s<br />\n", &buf[4]);
716 /** begin everythingamundo table */
717 if (!printable_view) {
718 wprintf("<div class=\"fix_scrollbar_bug message\" ");
719 wprintf("onMouseOver=document.getElementById(\"msg%ld\").style.visibility=\"visible\" ", msgnum);
720 wprintf("onMouseOut=document.getElementById(\"msg%ld\").style.visibility=\"hidden\" >", msgnum);
723 /** start msg buttons */
725 if (!printable_view) {
726 wprintf("<p id=\"msg%ld\" class=\"msgbuttons\" >\n",msgnum);
729 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
730 wprintf("<a href=\"display_enter");
731 if (WC->is_mailbox) {
732 wprintf("?replyquote=%ld", msgnum);
735 urlescputs(reply_to);
736 if (!IsEmptyStr(m_subject)) {
737 wprintf("?subject=");
738 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
739 urlescputs(m_subject);
741 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Reply"));
745 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
746 if (!WC->is_mailbox) {
747 wprintf("<a href=\"display_enter");
748 wprintf("?replyquote=%ld", msgnum);
750 urlescputs(reply_to);
751 if (!IsEmptyStr(m_subject)) {
752 wprintf("?subject=");
753 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
754 urlescputs(m_subject);
756 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyQuoted"));
761 if (WC->wc_view == VIEW_MAILBOX) {
762 wprintf("<a href=\"display_enter");
763 wprintf("?replyquote=%ld", msgnum);
765 urlescputs(reply_to);
767 urlescputs(reply_all);
768 if (!IsEmptyStr(m_subject)) {
769 wprintf("?subject=");
770 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
771 urlescputs(m_subject);
773 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyAll"));
777 if (WC->wc_view == VIEW_MAILBOX) {
778 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
779 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
780 urlescputs(m_subject);
781 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Forward"));
784 /** If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
785 if ( (WC->is_room_aide) || (WC->is_mailbox) || (WC->room_flags2 & QR2_COLLABDEL) ) {
787 wprintf("<a href=\"confirm_move_msg?msgid=%ld\"><span>[</span>%s<span>]</span></a> ",
791 wprintf("<a href=\"delete_msg?msgid=%ld\" "
792 "onClick=\"return confirm('%s');\">"
793 "<span>[</span>%s<span>]</span> "
794 "</a> ", msgnum, _("Delete this message?"), _("Delete")
799 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'); \" >"
800 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Headers"));
804 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'); \" >"
805 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Print"));
811 /** begin message header table */
812 wprintf("<div class=\"message_header\">");
816 strcpy(m_subject, "");
819 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
820 if (!strcmp(buf, "000")) {
822 wprintf(_("unexpected end of message"));
823 wprintf(" (1)</i><br /><br />\n");
827 if (!strncasecmp(buf, "nhdr=yes", 8))
831 if (!strncasecmp(buf, "type=", 5))
832 format_type = atoi(&buf[5]);
833 if (!strncasecmp(buf, "from=", 5)) {
834 strcpy(from, &buf[5]);
837 wprintf("<a href=\"showuser?who=");
839 utf8ify_rfc822_string(from);
846 if (!strncasecmp(buf, "subj=", 5)) {
847 safestrncpy(m_subject, &buf[5], sizeof m_subject);
849 if (!strncasecmp(buf, "cccc=", 5)) {
851 safestrncpy(m_cc, &buf[5], sizeof m_cc);
852 if (!IsEmptyStr(reply_all)) {
853 strcat(reply_all, ", ");
855 len = strlen(reply_all);
856 safestrncpy(&reply_all[len], &buf[5],
857 (sizeof reply_all - len) );
859 if ((!strncasecmp(buf, "hnod=", 5))
860 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
861 wprintf("(%s) ", &buf[5]);
863 if ((!strncasecmp(buf, "room=", 5))
864 && (strcasecmp(&buf[5], WC->wc_roomname))
865 && (!IsEmptyStr(&buf[5])) ) {
867 wprintf("%s> ", &buf[5]);
869 if (!strncasecmp(buf, "rfca=", 5)) {
870 strcpy(rfca, &buf[5]);
876 if (!strncasecmp(buf, "node=", 5)) {
877 strcpy(node, &buf[5]);
878 if ( ((WC->room_flags & QR_NETWORK)
879 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
880 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
881 && (IsEmptyStr(rfca))
883 wprintf("@%s ", &buf[5]);
886 if (!strncasecmp(buf, "rcpt=", 5)) {
889 if (!IsEmptyStr(reply_all)) {
890 strcat(reply_all, ", ");
892 len = strlen(reply_all);
893 safestrncpy(&reply_all[len], &buf[5],
894 (sizeof reply_all - len) );
896 utf8ify_rfc822_string(&buf[5]);
901 if (!strncasecmp(buf, "time=", 5)) {
902 fmt_date(now, atol(&buf[5]), 0);
906 if (!strncasecmp(buf, "part=", 5)) {
907 extract_token(mime_name, &buf[5], 0, '|', sizeof mime_filename);
908 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
909 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
910 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
911 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
912 mime_length = extract_int(&buf[5], 5);
915 striplt(mime_filename);
916 if ( (IsEmptyStr(mime_filename)) && (!IsEmptyStr(mime_name)) ) {
917 strcpy(mime_filename, mime_name);
920 if (!strcasecmp(mime_content_type, "message/rfc822")) {
921 if (!IsEmptyStr(mime_submessages)) {
922 strcat(mime_submessages, "|");
924 strcat(mime_submessages, mime_partnum);
926 else if ((!strcasecmp(mime_disposition, "inline"))
927 && (!strncasecmp(mime_content_type, "image/", 6)) ){
929 attach_links = realloc(attach_links,
930 (num_attach_links*sizeof(struct attach_link)));
931 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
932 snprintf(attach_links[num_attach_links-1].html, 1024,
933 "<img src=\"mimepart/%ld/%s/%s\">",
934 msgnum, mime_partnum, mime_filename);
936 else if ( ( (!strcasecmp(mime_disposition, "attachment"))
937 || (!strcasecmp(mime_disposition, "inline"))
938 || (!strcasecmp(mime_disposition, ""))
939 ) && (!IsEmptyStr(mime_content_type))
942 attach_links = realloc(attach_links,
943 (num_attach_links*sizeof(struct attach_link)));
944 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
945 snprintf(attach_links[num_attach_links-1].html, 1024,
946 "<img src=\"static/diskette_24x.gif\" "
947 "border=0 align=middle>\n"
948 "%s (%s, %d bytes) [ "
949 "<a href=\"mimepart/%ld/%s/%s\""
950 "target=\"wc.%ld.%s\">%s</a>"
952 "<a href=\"mimepart_download/%ld/%s/%s\">%s</a>"
955 mime_content_type, mime_length,
956 msgnum, mime_partnum, mime_filename,
957 msgnum, mime_partnum,
959 msgnum, mime_partnum, mime_filename,
964 /** begin handler prep ***/
965 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
966 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
967 strcpy(vcard_partnum, mime_partnum);
970 if (!strcasecmp(mime_content_type, "text/calendar")) {
971 strcpy(cal_partnum, mime_partnum);
974 /** end handler prep ***/
980 /** Generate a reply-to address */
981 if (!IsEmptyStr(rfca)) {
982 if (!IsEmptyStr(from)) {
983 snprintf(reply_to, sizeof(reply_to), "%s <%s>", from, rfca);
986 strcpy(reply_to, rfca);
990 if ((!IsEmptyStr(node))
991 && (strcasecmp(node, serv_info.serv_nodename))
992 && (strcasecmp(node, serv_info.serv_humannode)) ) {
993 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
997 snprintf(reply_to, sizeof(reply_to), "%s", from);
1008 utf8ify_rfc822_string(m_cc);
1009 utf8ify_rfc822_string(m_subject);
1011 if (!IsEmptyStr(m_cc)) {
1012 wprintf("<div class=\"message_subject\">");
1018 if (!IsEmptyStr(m_subject)) {
1019 wprintf("<div class=\"message_subject\">");
1020 wprintf(_("Subject:"));
1027 wprintf("<div class=\"message_content\">");
1030 * Learn the content type
1032 strcpy(mime_content_type, "text/plain");
1033 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1034 if (!strcmp(buf, "000")) {
1036 wprintf(_("unexpected end of message"));
1037 wprintf(" (2)</i><br /><br />\n");
1040 if (!strncasecmp(buf, "X-Citadel-MSG4-Partnum:", 23)) {
1041 safestrncpy(msg4_partnum, &buf[23], sizeof(msg4_partnum));
1042 striplt(msg4_partnum);
1044 if (!strncasecmp(buf, "Content-type:", 13)) {
1046 safestrncpy(mime_content_type, &buf[13], sizeof(mime_content_type));
1047 striplt(mime_content_type);
1048 len = strlen(mime_content_type);
1049 for (i=0; i<len; ++i) {
1050 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1051 safestrncpy(mime_charset, &mime_content_type[i+8],
1052 sizeof mime_charset);
1055 for (i=0; i<len; ++i) {
1056 if (mime_content_type[i] == ';') {
1057 mime_content_type[i] = 0;
1061 len = strlen(mime_charset);
1062 for (i=0; i<len; ++i) {
1063 if (mime_charset[i] == ';') {
1064 mime_charset[i] = 0;
1071 /** Set up a character set conversion if we need to (and if we can) */
1073 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
1074 if ( (strcasecmp(mime_charset, "us-ascii"))
1075 && (strcasecmp(mime_charset, "UTF-8"))
1076 && (strcasecmp(mime_charset, ""))
1078 ic = ctdl_iconv_open("UTF-8", mime_charset);
1079 if (ic == (iconv_t)(-1) ) {
1080 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1081 __FILE__, __LINE__, mime_charset, strerror(errno));
1086 /** Messages in legacy Citadel variformat get handled thusly... */
1087 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1091 /** Boring old 80-column fixed format text gets handled this way... */
1092 else if ( (!strcasecmp(mime_content_type, "text/plain"))
1093 || (!strcasecmp(mime_content_type, "text")) ) {
1094 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1097 if (buf[len-1] == '\n') buf[--len] = 0;
1098 if (buf[len-1] == '\r') buf[--len] = 0;
1101 if (ic != (iconv_t)(-1) ) {
1103 ibuflen = strlen(ibuf);
1105 obuf = (char *) malloc(obuflen);
1107 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1108 osav[SIZ-obuflen] = 0;
1109 safestrncpy(buf, osav, sizeof buf);
1115 while ((!IsEmptyStr(buf)) && (isspace(buf[len-1])))
1118 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1119 wprintf("<blockquote>");
1121 } else if ((bq == 1) &&
1122 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1123 wprintf("</blockquote>");
1129 wprintf("</tt><br />\n");
1131 wprintf("</i><br />");
1134 else /** HTML is fun, but we've got to strip it first */
1135 if (!strcasecmp(mime_content_type, "text/html")) {
1136 output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
1139 /** Unknown weirdness */
1141 wprintf(_("I don't know how to display %s"), mime_content_type);
1142 wprintf("<br />\n", mime_content_type);
1143 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1146 /** If there are attached submessages, display them now... */
1147 if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
1148 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1149 extract_token(buf, mime_submessages, i, '|', sizeof buf);
1150 /** use printable_view to suppress buttons */
1151 wprintf("<blockquote>");
1152 read_message(msgnum, 1, buf);
1153 wprintf("</blockquote>");
1158 /** Afterwards, offer links to download attachments 'n' such */
1159 if ( (num_attach_links > 0) && (!section[0]) ) {
1160 for (i=0; i<num_attach_links; ++i) {
1161 if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
1162 wprintf("%s", attach_links[i].html);
1167 /** Handler for vCard parts */
1168 if (!IsEmptyStr(vcard_partnum)) {
1169 part_source = load_mimepart(msgnum, vcard_partnum);
1170 if (part_source != NULL) {
1172 /** If it's my vCard I can edit it */
1173 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1174 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1175 || (WC->wc_view == VIEW_ADDRESSBOOK)
1177 wprintf("<a href=\"edit_vcard?"
1178 "msgnum=%ld?partnum=%s\">",
1179 msgnum, vcard_partnum);
1180 wprintf("[%s]</a>", _("edit"));
1183 /** In all cases, display the full card */
1184 display_vcard(part_source, 0, 1, NULL);
1188 /** Handler for calendar parts */
1189 if (!IsEmptyStr(cal_partnum)) {
1190 part_source = load_mimepart(msgnum, cal_partnum);
1191 if (part_source != NULL) {
1192 cal_process_attachment(part_source,
1193 msgnum, cal_partnum);
1203 wprintf("</div>\n");
1205 /** end everythingamundo table */
1206 if (!printable_view) {
1207 wprintf("</div>\n");
1210 if (num_attach_links > 0) {
1215 if (ic != (iconv_t)(-1) ) {
1224 * \brief Unadorned HTML output of an individual message, suitable
1225 * for placing in a hidden iframe, for printing, or whatever
1227 * \param msgnum_as_string Message number, as a string instead of as a long int
1229 void embed_message(char *msgnum_as_string) {
1232 msgnum = atol(msgnum_as_string);
1233 begin_ajax_response();
1234 read_message(msgnum, 0, "");
1235 end_ajax_response();
1240 * \brief Printable view of a message
1242 * \param msgnum_as_string Message number, as a string instead of as a long int
1244 void print_message(char *msgnum_as_string) {
1247 msgnum = atol(msgnum_as_string);
1248 output_headers(0, 0, 0, 0, 0, 0);
1250 wprintf("Content-type: text/html\r\n"
1252 "Connection: close\r\n",
1256 wprintf("\r\n\r\n<html>\n"
1257 "<head><title>Printable view</title></head>\n"
1258 "<body onLoad=\" window.print(); window.close(); \">\n"
1261 read_message(msgnum, 1, "");
1263 wprintf("\n</body></html>\n\n");
1270 * \brief Display a message's headers
1272 * \param msgnum_as_string Message number, as a string instead of as a long int
1274 void display_headers(char *msgnum_as_string) {
1278 msgnum = atol(msgnum_as_string);
1279 output_headers(0, 0, 0, 0, 0, 0);
1281 wprintf("Content-type: text/plain\r\n"
1283 "Connection: close\r\n",
1287 serv_printf("MSG2 %ld|3", msgnum);
1288 serv_getln(buf, sizeof buf);
1289 if (buf[0] == '1') {
1290 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1291 wprintf("%s\n", buf);
1301 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1302 * or 'reply quoted' operations.
1304 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1305 * in this function. Doing so would throw a JavaScript error in the
1306 * 'supplied text' argument to the editor.
1308 * \param msgnum Message number of the message we want to quote
1309 * \param forward_attachments Nonzero if we want attachments to be forwarded
1311 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1313 char mime_partnum[256];
1314 char mime_filename[256];
1315 char mime_content_type[256];
1316 char mime_charset[256];
1317 char mime_disposition[256];
1319 char *attachments = NULL;
1321 int num_attachments = 0;
1322 struct wc_attachment *att, *aptr;
1323 char m_subject[256];
1329 int format_type = 0;
1334 iconv_t ic = (iconv_t)(-1) ;
1335 char *ibuf; /**< Buffer of characters to be converted */
1336 char *obuf; /**< Buffer for converted characters */
1337 size_t ibuflen; /**< Length of input buffer */
1338 size_t obuflen; /**< Length of output buffer */
1339 char *osav; /**< Saved pointer to output buffer */
1345 strcpy(reply_to, "");
1346 strcpy(mime_content_type, "text/plain");
1347 strcpy(mime_charset, "us-ascii");
1349 serv_printf("MSG4 %ld", msgnum);
1350 serv_getln(buf, sizeof buf);
1351 if (buf[0] != '1') {
1352 wprintf(_("ERROR:"));
1353 wprintf("%s<br />", &buf[4]);
1357 strcpy(m_subject, "");
1359 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1360 if (!strcmp(buf, "000")) {
1361 wprintf("%s (3)", _("unexpected end of message"));
1364 if (include_headers) {
1365 if (!strncasecmp(buf, "nhdr=yes", 8))
1369 if (!strncasecmp(buf, "type=", 5))
1370 format_type = atoi(&buf[5]);
1371 if (!strncasecmp(buf, "from=", 5)) {
1372 strcpy(from, &buf[5]);
1373 wprintf(_("from "));
1375 utf8ify_rfc822_string(from);
1379 if (!strncasecmp(buf, "subj=", 5)) {
1380 strcpy(m_subject, &buf[5]);
1382 if ((!strncasecmp(buf, "hnod=", 5))
1383 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1384 wprintf("(%s) ", &buf[5]);
1386 if ((!strncasecmp(buf, "room=", 5))
1387 && (strcasecmp(&buf[5], WC->wc_roomname))
1388 && (!IsEmptyStr(&buf[5])) ) {
1390 wprintf("%s> ", &buf[5]);
1392 if (!strncasecmp(buf, "rfca=", 5)) {
1393 strcpy(rfca, &buf[5]);
1399 if (!strncasecmp(buf, "node=", 5)) {
1400 strcpy(node, &buf[5]);
1401 if ( ((WC->room_flags & QR_NETWORK)
1402 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1403 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1404 && (IsEmptyStr(rfca))
1406 wprintf("@%s ", &buf[5]);
1409 if (!strncasecmp(buf, "rcpt=", 5)) {
1411 wprintf("%s ", &buf[5]);
1413 if (!strncasecmp(buf, "time=", 5)) {
1414 fmt_date(now, atol(&buf[5]), 0);
1415 wprintf("%s ", now);
1420 * Save attachment info for later. We can't start downloading them
1421 * yet because we're in the middle of a server transaction.
1423 if (!strncasecmp(buf, "part=", 5)) {
1424 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1427 sprintf(ptr, "%s%s\n",
1428 ((attachments != NULL) ? attachments : ""),
1433 lprintf(9, "attachments=<%s>\n", attachments);
1439 if (include_headers) {
1443 utf8ify_rfc822_string(m_subject);
1445 if (!IsEmptyStr(m_subject)) {
1446 wprintf(_("Subject:"));
1448 msgescputs(m_subject);
1459 * Learn the content type
1461 strcpy(mime_content_type, "text/plain");
1462 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1463 if (!strcmp(buf, "000")) {
1464 wprintf("%s (4)", _("unexpected end of message"));
1467 if (!strncasecmp(buf, "Content-type: ", 14)) {
1469 safestrncpy(mime_content_type, &buf[14],
1470 sizeof(mime_content_type));
1471 for (i=0; i<strlen(mime_content_type); ++i) {
1472 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1473 safestrncpy(mime_charset, &mime_content_type[i+8],
1474 sizeof mime_charset);
1477 len = strlen(mime_content_type);
1478 for (i=0; i<len; ++i) {
1479 if (mime_content_type[i] == ';') {
1480 mime_content_type[i] = 0;
1484 len = strlen(mime_charset);
1485 for (i=0; i<len; ++i) {
1486 if (mime_charset[i] == ';') {
1487 mime_charset[i] = 0;
1494 /** Set up a character set conversion if we need to (and if we can) */
1496 if ( (strcasecmp(mime_charset, "us-ascii"))
1497 && (strcasecmp(mime_charset, "UTF-8"))
1498 && (strcasecmp(mime_charset, ""))
1500 ic = ctdl_iconv_open("UTF-8", mime_charset);
1501 if (ic == (iconv_t)(-1) ) {
1502 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1503 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1508 /** Messages in legacy Citadel variformat get handled thusly... */
1509 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1513 /* Boring old 80-column fixed format text gets handled this way... */
1514 else if (!strcasecmp(mime_content_type, "text/plain")) {
1515 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1518 if (buf[len-1] == '\n') buf[--len] = 0;
1519 if (buf[len-1] == '\r') buf[--len] = 0;
1522 if (ic != (iconv_t)(-1) ) {
1526 obuf = (char *) malloc(obuflen);
1528 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1529 osav[SIZ-obuflen] = 0;
1530 safestrncpy(buf, osav, sizeof buf);
1536 while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
1539 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1540 wprintf("<blockquote>");
1542 } else if ((bq == 1) &&
1543 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1544 wprintf("</blockquote>");
1550 wprintf("</tt><br />");
1552 wprintf("</i><br />");
1555 /** HTML just gets escaped and stuffed back into the editor */
1556 else if (!strcasecmp(mime_content_type, "text/html")) {
1557 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1563 /** Unknown weirdness ... don't know how to handle this content type */
1565 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1569 /** end of body handler */
1572 * If there were attachments, we have to download them and insert them
1573 * into the attachment chain for the forwarded message we are composing.
1575 if ( (forward_attachments) && (num_attachments) ) {
1576 for (i=0; i<num_attachments; ++i) {
1577 extract_token(buf, attachments, i, '\n', sizeof buf);
1578 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1579 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1580 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1581 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1582 mime_length = extract_int(buf, 5);
1585 * tracing ... uncomment if necessary
1588 lprintf(9, "fwd filename: %s\n", mime_filename);
1589 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1590 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1591 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1592 lprintf(9, "fwd length : %d\n", mime_length);
1594 if ( (!strcasecmp(mime_disposition, "inline"))
1595 || (!strcasecmp(mime_disposition, "attachment")) ) {
1597 /* Create an attachment struct from this mime part... */
1598 att = malloc(sizeof(struct wc_attachment));
1599 memset(att, 0, sizeof(struct wc_attachment));
1600 att->length = mime_length;
1601 strcpy(att->content_type, mime_content_type);
1602 strcpy(att->filename, mime_filename);
1604 att->data = load_mimepart(msgnum, mime_partnum);
1606 /* And add it to the list. */
1607 if (WC->first_attachment == NULL) {
1608 WC->first_attachment = att;
1611 aptr = WC->first_attachment;
1612 while (aptr->next != NULL) aptr = aptr->next;
1621 if (ic != (iconv_t)(-1) ) {
1626 if (attachments != NULL) {
1632 * \brief Display one row in the mailbox summary view
1634 * \param num The row number to be displayed
1636 void display_summarized(int num) {
1639 wprintf("<tr id=\"m%ld\" style=\"font-weight:%s;\" "
1640 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1641 WC->summ[num].msgnum,
1642 (WC->summ[num].is_new ? "bold" : "normal"),
1643 WC->summ[num].msgnum
1646 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1647 escputs(WC->summ[num].subj);
1650 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1651 escputs(WC->summ[num].from);
1654 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1655 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1665 * \brief display the adressbook overview
1666 * \param msgnum the citadel message number
1667 * \param alpha what????
1669 void display_addressbook(long msgnum, char alpha) {
1671 char mime_partnum[SIZ];
1672 char mime_filename[SIZ];
1673 char mime_content_type[SIZ];
1674 char mime_disposition[SIZ];
1676 char vcard_partnum[SIZ];
1677 char *vcard_source = NULL;
1678 struct message_summary summ;
1680 memset(&summ, 0, sizeof(summ));
1681 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1683 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1685 serv_getln(buf, sizeof buf);
1686 if (buf[0] != '1') return;
1688 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1689 if (!strncasecmp(buf, "part=", 5)) {
1690 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1691 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1692 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1693 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1694 mime_length = extract_int(&buf[5], 5);
1696 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1697 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1698 strcpy(vcard_partnum, mime_partnum);
1704 if (!IsEmptyStr(vcard_partnum)) {
1705 vcard_source = load_mimepart(msgnum, vcard_partnum);
1706 if (vcard_source != NULL) {
1708 /** Display the summary line */
1709 display_vcard(vcard_source, alpha, 0, NULL);
1711 /** If it's my vCard I can edit it */
1712 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1713 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1714 || (WC->wc_view == VIEW_ADDRESSBOOK)
1716 wprintf("<a href=\"edit_vcard?"
1717 "msgnum=%ld?partnum=%s\">",
1718 msgnum, vcard_partnum);
1719 wprintf("[%s]</a>", _("edit"));
1731 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1732 * \param namebuf name to analyze, reverse if nescessary
1734 void lastfirst_firstlast(char *namebuf) {
1735 char firstname[SIZ];
1739 if (namebuf == NULL) return;
1740 if (strchr(namebuf, ';') != NULL) return;
1742 i = num_tokens(namebuf, ' ');
1745 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1746 remove_token(namebuf, i-1, ' ');
1747 strcpy(firstname, namebuf);
1748 sprintf(namebuf, "%s; %s", lastname, firstname);
1752 * \brief fetch what??? name
1753 * \param msgnum the citadel message number
1754 * \param namebuf where to put the name in???
1756 void fetch_ab_name(long msgnum, char *namebuf) {
1758 char mime_partnum[SIZ];
1759 char mime_filename[SIZ];
1760 char mime_content_type[SIZ];
1761 char mime_disposition[SIZ];
1763 char vcard_partnum[SIZ];
1764 char *vcard_source = NULL;
1766 struct message_summary summ;
1768 if (namebuf == NULL) return;
1769 strcpy(namebuf, "");
1771 memset(&summ, 0, sizeof(summ));
1772 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1774 sprintf(buf, "MSG0 %ld|0", msgnum); /** unfortunately we need the mime info now */
1776 serv_getln(buf, sizeof buf);
1777 if (buf[0] != '1') return;
1779 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1780 if (!strncasecmp(buf, "part=", 5)) {
1781 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1782 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1783 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1784 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1785 mime_length = extract_int(&buf[5], 5);
1787 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1788 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1789 strcpy(vcard_partnum, mime_partnum);
1795 if (!IsEmptyStr(vcard_partnum)) {
1796 vcard_source = load_mimepart(msgnum, vcard_partnum);
1797 if (vcard_source != NULL) {
1799 /* Grab the name off the card */
1800 display_vcard(vcard_source, 0, 0, namebuf);
1806 lastfirst_firstlast(namebuf);
1808 len = strlen(namebuf);
1809 for (i=0; i<len; ++i) {
1810 if (namebuf[i] != ';') return;
1812 strcpy(namebuf, _("(no name)"));
1818 * \brief Record compare function for sorting address book indices
1819 * \param ab1 adressbook one
1820 * \param ab2 adressbook two
1822 int abcmp(const void *ab1, const void *ab2) {
1824 (((const struct addrbookent *)ab1)->ab_name),
1825 (((const struct addrbookent *)ab2)->ab_name)
1831 * \brief Helper function for do_addrbook_view()
1832 * Converts a name into a three-letter tab label
1833 * \param tabbuf the tabbuffer to add name to
1834 * \param name the name to add to the tabbuffer
1836 void nametab(char *tabbuf, char *name) {
1837 stresc(tabbuf, name, 0, 0);
1838 tabbuf[0] = toupper(tabbuf[0]);
1839 tabbuf[1] = tolower(tabbuf[1]);
1840 tabbuf[2] = tolower(tabbuf[2]);
1846 * \brief Render the address book using info we gathered during the scan
1847 * \param addrbook the addressbook to render
1848 * \param num_ab the number of the addressbook
1850 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1854 static int NAMESPERPAGE = 60;
1857 char tabfirst_label[64];
1859 char tablast_label[64];
1860 char this_tablabel[64];
1865 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1866 wprintf(_("This address book is empty."));
1867 wprintf("</i></div>\n");
1872 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1875 num_pages = (num_ab / NAMESPERPAGE) + 1;
1877 tablabels = malloc(num_pages * sizeof (char *));
1878 if (tablabels == NULL) {
1879 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1880 wprintf(_("An internal error has occurred."));
1881 wprintf("</i></div>\n");
1885 for (i=0; i<num_pages; ++i) {
1886 tabfirst = i * NAMESPERPAGE;
1887 tablast = tabfirst + NAMESPERPAGE - 1;
1888 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1889 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1890 nametab(tablast_label, addrbook[tablast].ab_name);
1891 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
1892 tablabels[i] = strdup(this_tablabel);
1895 tabbed_dialog(num_pages, tablabels);
1898 for (i=0; i<num_ab; ++i) {
1900 if ((i / NAMESPERPAGE) != page) { /* New tab */
1901 page = (i / NAMESPERPAGE);
1903 wprintf("</tr></table>\n");
1904 end_tab(page-1, num_pages);
1906 begin_tab(page, num_pages);
1907 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
1911 if ((displayed % 4) == 0) {
1912 if (displayed > 0) {
1916 wprintf("<tr bgcolor=\"#%s\">",
1917 (bg ? "DDDDDD" : "FFFFFF")
1923 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
1924 addrbook[i].ab_msgnum);
1925 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1926 vcard_n_prettyize(addrbook[i].ab_name);
1927 escputs(addrbook[i].ab_name);
1928 wprintf("</a></td>\n");
1932 wprintf("</tr></table>\n");
1933 end_tab((num_pages-1), num_pages);
1935 for (i=0; i<num_pages; ++i) {
1944 * \brief load message pointers from the server
1945 * \param servcmd the citadel command to send to the citserver
1946 * \param with_headers what headers???
1948 int load_msg_ptrs(char *servcmd, int with_headers)
1959 int num_summ_alloc = 0;
1961 if (WC->summ != NULL) {
1966 num_summ_alloc = 100;
1968 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1971 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1973 serv_getln(buf, sizeof buf);
1974 if (buf[0] != '1') {
1977 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1978 if (nummsgs < maxload) {
1979 WC->msgarr[nummsgs] = extract_long(buf, 0);
1980 datestamp = extract_long(buf, 1);
1981 extract_token(fullname, buf, 2, '|', sizeof fullname);
1982 extract_token(nodename, buf, 3, '|', sizeof nodename);
1983 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1984 extract_token(subject, buf, 5, '|', sizeof subject);
1988 if (nummsgs > num_summ_alloc) {
1989 num_summ_alloc *= 2;
1990 WC->summ = realloc(WC->summ,
1991 num_summ_alloc * sizeof(struct message_summary));
1995 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1996 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1997 safestrncpy(WC->summ[nummsgs-1].subj,
1998 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1999 if (!IsEmptyStr(fullname)) {
2000 safestrncpy(WC->summ[nummsgs-1].from,
2001 fullname, sizeof WC->summ[nummsgs-1].from);
2003 if (!IsEmptyStr(subject)) {
2004 safestrncpy(WC->summ[nummsgs-1].subj, subject,
2005 sizeof WC->summ[nummsgs-1].subj);
2008 /** Handle subjects with RFC2047 encoding */
2009 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
2011 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
2012 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
2015 if (!IsEmptyStr(nodename)) {
2016 if ( ((WC->room_flags & QR_NETWORK)
2017 || ((strcasecmp(nodename, serv_info.serv_nodename)
2018 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
2020 strcat(WC->summ[nummsgs-1].from, " @ ");
2021 strcat(WC->summ[nummsgs-1].from, nodename);
2025 WC->summ[nummsgs-1].date = datestamp;
2028 /** Handle senders with RFC2047 encoding */
2029 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
2031 if (strlen(WC->summ[nummsgs-1].from) > 25) {
2032 strcpy(&WC->summ[nummsgs-1].from[22], "...");
2041 * \brief qsort() compatible function to compare two longs in descending order.
2043 * \param s1 first number to compare
2044 * \param s2 second number to compare
2046 int longcmp_r(const void *s1, const void *s2) {
2053 if (l1 > l2) return(-1);
2054 if (l1 < l2) return(+1);
2060 * \brief qsort() compatible function to compare two message summary structs by ascending subject.
2062 * \param s1 first item to compare
2063 * \param s2 second item to compare
2065 int summcmp_subj(const void *s1, const void *s2) {
2066 struct message_summary *summ1;
2067 struct message_summary *summ2;
2069 summ1 = (struct message_summary *)s1;
2070 summ2 = (struct message_summary *)s2;
2071 return strcasecmp(summ1->subj, summ2->subj);
2075 * \brief qsort() compatible function to compare two message summary structs by descending subject.
2077 * \param s1 first item to compare
2078 * \param s2 second item to compare
2080 int summcmp_rsubj(const void *s1, const void *s2) {
2081 struct message_summary *summ1;
2082 struct message_summary *summ2;
2084 summ1 = (struct message_summary *)s1;
2085 summ2 = (struct message_summary *)s2;
2086 return strcasecmp(summ2->subj, summ1->subj);
2090 * \brief qsort() compatible function to compare two message summary structs by ascending sender.
2092 * \param s1 first item to compare
2093 * \param s2 second item to compare
2095 int summcmp_sender(const void *s1, const void *s2) {
2096 struct message_summary *summ1;
2097 struct message_summary *summ2;
2099 summ1 = (struct message_summary *)s1;
2100 summ2 = (struct message_summary *)s2;
2101 return strcasecmp(summ1->from, summ2->from);
2105 * \brief qsort() compatible function to compare two message summary structs by descending sender.
2107 * \param s1 first item to compare
2108 * \param s2 second item to compare
2110 int summcmp_rsender(const void *s1, const void *s2) {
2111 struct message_summary *summ1;
2112 struct message_summary *summ2;
2114 summ1 = (struct message_summary *)s1;
2115 summ2 = (struct message_summary *)s2;
2116 return strcasecmp(summ2->from, summ1->from);
2120 * \brief qsort() compatible function to compare two message summary structs by ascending date.
2122 * \param s1 first item to compare
2123 * \param s2 second item to compare
2125 int summcmp_date(const void *s1, const void *s2) {
2126 struct message_summary *summ1;
2127 struct message_summary *summ2;
2129 summ1 = (struct message_summary *)s1;
2130 summ2 = (struct message_summary *)s2;
2132 if (summ1->date < summ2->date) return -1;
2133 else if (summ1->date > summ2->date) return +1;
2138 * \brief qsort() compatible function to compare two message summary structs by descending date.
2140 * \param s1 first item to compare
2141 * \param s2 second item to compare
2143 int summcmp_rdate(const void *s1, const void *s2) {
2144 struct message_summary *summ1;
2145 struct message_summary *summ2;
2147 summ1 = (struct message_summary *)s1;
2148 summ2 = (struct message_summary *)s2;
2150 if (summ1->date < summ2->date) return +1;
2151 else if (summ1->date > summ2->date) return -1;
2158 * \brief command loop for reading messages
2160 * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
2162 void readloop(char *oper)
2171 long *displayed_msgs = NULL;
2172 int num_displayed = 0;
2174 int is_addressbook = 0;
2175 int is_singlecard = 0;
2176 int is_calendar = 0;
2181 int lowest_displayed = (-1);
2182 int highest_displayed = 0;
2183 struct addrbookent *addrbook = NULL;
2185 char *sortby = NULL;
2186 char sortpref_name[128];
2187 char sortpref_value[128];
2188 char *subjsort_button;
2189 char *sendsort_button;
2190 char *datesort_button;
2191 int bbs_reverse = 0;
2193 if (WC->wc_view == VIEW_WIKI) {
2194 sprintf(buf, "wiki?room=%s?page=home", WC->wc_roomname);
2199 startmsg = atol(bstr("startmsg"));
2200 maxmsgs = atoi(bstr("maxmsgs"));
2201 is_summary = atoi(bstr("summary"));
2202 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2204 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
2205 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
2207 sortby = bstr("sortby");
2208 if ( (!IsEmptyStr(sortby)) && (strcasecmp(sortby, sortpref_value)) ) {
2209 set_preference(sortpref_name, sortby, 1);
2211 if (IsEmptyStr(sortby)) sortby = sortpref_value;
2214 if (IsEmptyStr(sortby)) sortby = "rdate";
2216 /** message board sort */
2217 if (!strcasecmp(sortby, "reverse")) {
2224 output_headers(1, 1, 1, 0, 0, 0);
2227 * When in summary mode, always show ALL messages instead of just
2228 * new or old. Otherwise, show what the user asked for.
2230 if (!strcmp(oper, "readnew")) {
2231 strcpy(cmd, "MSGS NEW");
2233 else if (!strcmp(oper, "readold")) {
2234 strcpy(cmd, "MSGS OLD");
2236 else if (!strcmp(oper, "do_search")) {
2237 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2240 strcpy(cmd, "MSGS ALL");
2243 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
2245 if (!strcmp(oper, "do_search")) {
2246 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2249 strcpy(cmd, "MSGS ALL");
2253 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2255 if (!strcmp(oper, "do_search")) {
2256 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2259 strcpy(cmd, "MSGS ALL");
2264 if (is_summary) { /**< fetch header summary */
2265 snprintf(cmd, sizeof cmd, "MSGS %s|%s||1",
2266 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2267 (!strcmp(oper, "do_search") ? bstr("query") : "")
2274 * Are we doing a summary view? If so, we need to know old messages
2275 * and new messages, so we can do that pretty boldface thing for the
2278 strcpy(old_msgs, "");
2281 serv_getln(buf, sizeof buf);
2282 if (buf[0] == '2') {
2283 strcpy(old_msgs, &buf[4]);
2287 is_singlecard = atoi(bstr("is_singlecard"));
2289 if (WC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2291 strcpy(cmd, "MSGS ALL");
2294 if (WC->wc_default_view == VIEW_TASKS) { /**< tasks */
2296 strcpy(cmd, "MSGS ALL");
2299 if (WC->wc_default_view == VIEW_NOTES) { /**< notes */
2301 strcpy(cmd, "MSGS ALL");
2306 wprintf("<div align=center>%s</div>\n", _("Click on any note to edit it."));
2307 wprintf("<div id=\"new_notes_here\"></div>\n");
2310 nummsgs = load_msg_ptrs(cmd, is_summary);
2313 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2314 wprintf("<div align=\"center\"><br /><em>");
2315 if (!strcmp(oper, "readnew")) {
2316 wprintf(_("No new messages."));
2317 } else if (!strcmp(oper, "readold")) {
2318 wprintf(_("No old messages."));
2320 wprintf(_("No messages here."));
2322 wprintf("</em><br /></div>\n");
2329 for (a = 0; a < nummsgs; ++a) {
2330 /** Are you a new message, or an old message? */
2332 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
2333 WC->summ[a].is_new = 0;
2336 WC->summ[a].is_new = 1;
2342 if (startmsg == 0L) {
2344 startmsg = WC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2347 startmsg = WC->msgarr[0];
2352 if (!strcasecmp(sortby, "subject")) {
2353 qsort(WC->summ, WC->num_summ,
2354 sizeof(struct message_summary), summcmp_subj);
2356 else if (!strcasecmp(sortby, "rsubject")) {
2357 qsort(WC->summ, WC->num_summ,
2358 sizeof(struct message_summary), summcmp_rsubj);
2360 else if (!strcasecmp(sortby, "sender")) {
2361 qsort(WC->summ, WC->num_summ,
2362 sizeof(struct message_summary), summcmp_sender);
2364 else if (!strcasecmp(sortby, "rsender")) {
2365 qsort(WC->summ, WC->num_summ,
2366 sizeof(struct message_summary), summcmp_rsender);
2368 else if (!strcasecmp(sortby, "date")) {
2369 qsort(WC->summ, WC->num_summ,
2370 sizeof(struct message_summary), summcmp_date);
2372 else if (!strcasecmp(sortby, "rdate")) {
2373 qsort(WC->summ, WC->num_summ,
2374 sizeof(struct message_summary), summcmp_rdate);
2378 if (!strcasecmp(sortby, "subject")) {
2379 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2381 else if (!strcasecmp(sortby, "rsubject")) {
2382 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2385 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2388 if (!strcasecmp(sortby, "sender")) {
2389 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2391 else if (!strcasecmp(sortby, "rsender")) {
2392 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2395 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2398 if (!strcasecmp(sortby, "date")) {
2399 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2401 else if (!strcasecmp(sortby, "rdate")) {
2402 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2405 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2410 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2411 " document.onkeydown = CtdlMsgListKeyPress; "
2412 " if (document.layers) { "
2413 " document.captureEvents(Event.KEYPRESS); "
2418 /** note that Date and Delete are now in the same column */
2419 wprintf("<div id=\"message_list_hdr\">"
2420 "<div class=\"fix_scrollbar_bug\">"
2421 "<table cellspacing=0 style=\"width:100%%\">"
2424 wprintf("<th width=%d%%>%s %s</th>"
2425 "<th width=%d%%>%s %s</th>"
2426 "<th width=%d%%>%s %s"
2428 "<input type=\"submit\" name=\"delete_button\" id=\"delbutton\" "
2429 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2435 _("Subject"), subjsort_button,
2436 SENDER_COL_WIDTH_PCT,
2437 _("Sender"), sendsort_button,
2438 DATE_PLUS_BUTTONS_WIDTH_PCT,
2439 _("Date"), datesort_button,
2442 wprintf("</table></div></div>\n");
2444 wprintf("<div id=\"message_list\">"
2446 "<div class=\"fix_scrollbar_bug\">\n"
2448 "<table class=\"mailbox_summary\" id=\"summary_headers\" "
2449 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2453 for (a = 0; a < nummsgs; ++a) {
2454 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2456 /** Display the message */
2458 display_summarized(a);
2460 else if (is_addressbook) {
2461 fetch_ab_name(WC->msgarr[a], buf);
2463 addrbook = realloc(addrbook,
2464 (sizeof(struct addrbookent) * num_ab) );
2465 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2466 sizeof(addrbook[num_ab-1].ab_name));
2467 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
2469 else if (is_calendar) {
2470 display_calendar(WC->msgarr[a]);
2472 else if (is_tasks) {
2473 display_task(WC->msgarr[a]);
2475 else if (is_notes) {
2476 display_note(WC->msgarr[a]);
2479 if (displayed_msgs == NULL) {
2480 displayed_msgs = malloc(sizeof(long) *
2481 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2483 displayed_msgs[num_displayed] = WC->msgarr[a];
2486 if (lowest_displayed < 0) lowest_displayed = a;
2487 highest_displayed = a;
2494 * Set the "is_bbview" variable if it appears that we are looking at
2495 * a classic bulletin board view.
2497 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2498 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2503 if (displayed_msgs != NULL) {
2505 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2508 /** if we do a split bbview in the future, begin messages div here */
2510 for (a=0; a<num_displayed; ++a) {
2511 read_message(displayed_msgs[a], 0, "");
2514 /** if we do a split bbview in the future, end messages div here */
2516 free(displayed_msgs);
2517 displayed_msgs = NULL;
2522 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2523 wprintf("</div>"); /**< end of 'message_list' div */
2525 /** Here's the grab-it-to-resize-the-message-list widget */
2526 wprintf("<div id=\"resize_msglist\" "
2527 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2528 "<div class=\"fix_scrollbar_bug\"> <hr>"
2532 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2536 * Bump these because although we're thinking in zero base, the user
2537 * is a drooling idiot and is thinking in one base.
2540 ++highest_displayed;
2543 * If we're not currently looking at ALL requested
2544 * messages, then display the selector bar
2547 /** begin bbview scroller */
2548 wprintf("<form name=\"msgomatic\">");
2549 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2551 wprintf("<select name=\"whichones\" size=\"1\" "
2552 "OnChange=\"location.href=msgomatic.whichones.options"
2553 "[selectedIndex].value\">\n");
2556 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2558 lo = b - maxmsgs + 2;
2560 wprintf("<option %s value="
2565 "%d-%d</option> \n",
2566 ((WC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2575 for (b=0; b<nummsgs; b = b + maxmsgs) {
2577 hi = b + maxmsgs + 1;
2578 if (hi > nummsgs) hi = nummsgs;
2579 wprintf("<option %s value="
2584 "%d-%d</option> \n",
2585 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2594 wprintf("<option value=\"%s?startmsg=%ld"
2595 "?maxmsgs=9999999?summary=%d\">"
2599 WC->msgarr[0], is_summary);
2601 wprintf("</select> ");
2602 wprintf(_("of %d messages."), nummsgs);
2604 /** forward/reverse */
2605 wprintf(" <select name=\"direction\" size=\"1\" "
2606 "OnChange=\"location.href=msgomatic.direction.options"
2607 "[selectedIndex].value\">\n"
2610 wprintf("<option %s value=\"%s?sortby=forward\">oldest to newest</option>\n",
2611 (bbs_reverse ? "" : "selected"),
2615 wprintf("<option %s value=\"%s?sortby=reverse\">newest to oldest</option>\n",
2616 (bbs_reverse ? "selected" : ""),
2620 wprintf("</select></form>\n");
2621 /** end bbview scroller */
2626 do_tasks_view(); /** Render the task list */
2630 do_calendar_view(); /** Render the calendar */
2633 if (is_addressbook) {
2634 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2637 /** Note: wDumpContent() will output one additional </div> tag. */
2638 wprintf("</div>\n"); /** end of 'content' div */
2641 /** free the summary */
2642 if (WC->summ != NULL) {
2647 if (addrbook != NULL) free(addrbook);
2652 * \brief Back end for post_message()
2653 * ... this is where the actual message gets transmitted to the server.
2655 void post_mime_to_server(void) {
2657 int is_multipart = 0;
2659 struct wc_attachment *att;
2661 size_t encoded_length;
2663 /** RFC2045 requires this, and some clients look for it... */
2664 serv_puts("MIME-Version: 1.0");
2665 serv_puts("X-Mailer: " SERVER);
2667 /** If there are attachments, we have to do multipart/mixed */
2668 if (WC->first_attachment != NULL) {
2673 sprintf(boundary, "Citadel--Multipart--%s--%04x--%04x",
2674 serv_info.serv_fqdn,
2679 /** Remember, serv_printf() appends an extra newline */
2680 serv_printf("Content-type: multipart/mixed; "
2681 "boundary=\"%s\"\n", boundary);
2682 serv_printf("This is a multipart message in MIME format.\n");
2683 serv_printf("--%s", boundary);
2686 serv_puts("Content-type: text/html; charset=utf-8");
2687 serv_puts("Content-Transfer-Encoding: quoted-printable");
2689 serv_puts("<html><body>\r\n");
2690 text_to_server_qp(bstr("msgtext")); /** Transmit message in quoted-printable encoding */
2691 serv_puts("</body></html>\r\n");
2695 /** Add in the attachments */
2696 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2698 encoded_length = ((att->length * 150) / 100);
2699 encoded = malloc(encoded_length);
2700 if (encoded == NULL) break;
2701 CtdlEncodeBase64(encoded, att->data, att->length, 1);
2703 serv_printf("--%s", boundary);
2704 serv_printf("Content-type: %s", att->content_type);
2705 serv_printf("Content-disposition: attachment; "
2706 "filename=\"%s\"", att->filename);
2707 serv_puts("Content-transfer-encoding: base64");
2709 serv_write(encoded, strlen(encoded));
2714 serv_printf("--%s--", boundary);
2722 * \brief Post message (or don't post message)
2724 * Note regarding the "dont_post" variable:
2725 * A random value (actually, it's just a timestamp) is inserted as a hidden
2726 * field called "postseq" when the display_enter page is generated. This
2727 * value is checked when posting, using the static variable dont_post. If a
2728 * user attempts to post twice using the same dont_post value, the message is
2729 * discarded. This prevents the accidental double-saving of the same message
2730 * if the user happens to click the browser "back" button.
2732 void post_message(void)
2735 char encoded_subject[1024];
2736 static long dont_post = (-1L);
2737 struct wc_attachment *att, *aptr;
2738 int is_anonymous = 0;
2741 display_name = bstr("display_name");
2742 if (!strcmp(display_name, "__ANONYMOUS__")) {
2747 if (WC->upload_length > 0) {
2749 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WC->upload_length);
2750 /** There's an attachment. Save it to this struct... */
2751 att = malloc(sizeof(struct wc_attachment));
2752 memset(att, 0, sizeof(struct wc_attachment));
2753 att->length = WC->upload_length;
2754 strcpy(att->content_type, WC->upload_content_type);
2755 strcpy(att->filename, WC->upload_filename);
2758 /** And add it to the list. */
2759 if (WC->first_attachment == NULL) {
2760 WC->first_attachment = att;
2763 aptr = WC->first_attachment;
2764 while (aptr->next != NULL) aptr = aptr->next;
2769 * Mozilla sends a simple filename, which is what we want,
2770 * but Satan's Browser sends an entire pathname. Reduce
2771 * the path to just a filename if we need to.
2773 while (num_tokens(att->filename, '/') > 1) {
2774 remove_token(att->filename, 0, '/');
2776 while (num_tokens(att->filename, '\\') > 1) {
2777 remove_token(att->filename, 0, '\\');
2781 * Transfer control of this memory from the upload struct
2782 * to the attachment struct.
2784 att->data = WC->upload;
2785 WC->upload_length = 0;
2791 if (!IsEmptyStr(bstr("cancel_button"))) {
2792 sprintf(WC->ImportantMessage,
2793 _("Cancelled. Message was not posted."));
2794 } else if (!IsEmptyStr(bstr("attach_button"))) {
2797 } else if (atol(bstr("postseq")) == dont_post) {
2798 sprintf(WC->ImportantMessage,
2799 _("Automatically cancelled because you have already "
2800 "saved this message."));
2802 rfc2047encode(encoded_subject, sizeof encoded_subject, bstr("subject"));
2803 sprintf(buf, "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s",
2811 bstr("my_email_addr")
2814 serv_getln(buf, sizeof buf);
2815 if (buf[0] == '4') {
2816 post_mime_to_server();
2817 if ( (!IsEmptyStr(bstr("recp")))
2818 || (!IsEmptyStr(bstr("cc" )))
2819 || (!IsEmptyStr(bstr("bcc" )))
2821 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2824 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2826 dont_post = atol(bstr("postseq"));
2828 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
2829 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2835 free_attachments(WC);
2838 * We may have been supplied with instructions regarding the location
2839 * to which we must return after posting. If found, go there.
2841 if (!IsEmptyStr(bstr("return_to"))) {
2842 http_redirect(bstr("return_to"));
2845 * If we were editing a page in a wiki room, go to that page now.
2847 else if (!IsEmptyStr(bstr("wikipage"))) {
2848 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
2852 * Otherwise, just go to the "read messages" loop.
2855 readloop("readnew");
2863 * \brief display the message entry screen
2865 void display_enter(void)
2871 struct wc_attachment *att;
2872 int recipient_required = 0;
2873 int subject_required = 0;
2874 int recipient_bad = 0;
2876 int is_anonymous = 0;
2877 long existing_page = (-1L);
2881 if (!IsEmptyStr(bstr("force_room"))) {
2882 gotoroom(bstr("force_room"));
2885 display_name = bstr("display_name");
2886 if (!strcmp(display_name, "__ANONYMOUS__")) {
2891 /** First test to see whether this is a room that requires recipients to be entered */
2892 serv_puts("ENT0 0");
2893 serv_getln(buf, sizeof buf);
2895 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
2896 recipient_required = 1;
2898 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2899 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2900 readloop("readnew");
2904 /* Is the server strongly recommending that the user enter a message subject? */
2905 if ((buf[3] != '\0') && (buf[4] != '\0')) {
2906 subject_required = extract_int(&buf[4], 1);
2910 * Are we perhaps in an address book view? If so, then an "enter
2911 * message" command really means "add new entry."
2913 if (WC->wc_default_view == VIEW_ADDRESSBOOK) {
2914 do_edit_vcard(-1, "", "");
2918 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
2920 * Are we perhaps in a calendar room? If so, then an "enter
2921 * message" command really means "add new calendar item."
2923 if (WC->wc_default_view == VIEW_CALENDAR) {
2924 display_edit_event();
2929 * Are we perhaps in a tasks view? If so, then an "enter
2930 * message" command really means "add new task."
2932 if (WC->wc_default_view == VIEW_TASKS) {
2933 display_edit_task();
2939 * Otherwise proceed normally.
2940 * Do a custom room banner with no navbar...
2942 output_headers(1, 1, 2, 0, 0, 0);
2943 wprintf("<div id=\"banner\">\n");
2944 embed_room_banner(NULL, navbar_none);
2945 wprintf("</div>\n");
2946 wprintf("<div id=\"content\">\n"
2947 "<div class=\"fix_scrollbar_bug message \">");
2949 /** Now check our actual recipients if there are any */
2950 if (recipient_required) {
2951 sprintf(buf, "ENT0 0|%s|%d|0||%s||%s|%s|%s",
2955 bstr("cc"), bstr("bcc"), bstr("wikipage"));
2957 serv_getln(buf, sizeof buf);
2959 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
2960 if (!IsEmptyStr(bstr("recp")) &&
2961 !IsEmptyStr(bstr("cc" )) &&
2962 !IsEmptyStr(bstr("bcc" ))) {
2966 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2967 wprintf("<em>%s</em><br />\n", &buf[4]);
2972 /** If we got this far, we can display the message entry screen. */
2974 /** begin message entry screen */
2976 "enctype=\"multipart/form-data\" "
2978 "accept-charset=\"UTF-8\" "
2980 "name=\"enterform\""
2982 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2983 if (WC->wc_view == VIEW_WIKI) {
2984 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
2986 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
2987 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
2989 /** submit or cancel buttons */
2990 wprintf("<p class=\"send_edit_msg\">");
2991 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2992 if (recipient_required) {
2993 wprintf(_("Send message"));
2995 wprintf(_("Post message"));
2998 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3003 wprintf("<img src=\"static/newmess3_24x.gif\" class=\"imgedit\">");
3004 wprintf(" "); /** header bar */
3005 fmt_date(buf, now, 0);
3007 wprintf("\n"); /** header bar */
3010 wprintf("<label for=\"from_id\" > ");
3011 wprintf(_(" <I>from</I> "));
3012 wprintf("</label>");
3014 /* Allow the user to select any of his valid screen names */
3016 wprintf("<select name=\"display_name\" size=1 id=\"from_id\">\n");
3019 serv_getln(buf, sizeof buf);
3020 if (buf[0] == '1') {
3021 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3022 wprintf("<option %s value=\"",
3023 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
3028 wprintf("</option>\n");
3032 if (WC->room_flags & QR_ANONOPT) {
3033 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
3034 ((!strcasecmp(bstr("__ANONYMOUS__"), WC->wc_fullname)) ? "selected" : ""),
3039 wprintf("</select>\n");
3041 /* If this is an email (not a post), allow the user to select any of his
3042 * valid email addresses.
3044 if (recipient_required) {
3046 serv_getln(buf, sizeof buf);
3047 if (buf[0] == '1') {
3048 wprintf("<select name=\"my_email_addr\" size=1>\n");
3049 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3050 wprintf("<option value=\"");
3054 wprintf("></option>\n");
3056 wprintf("</select>\n");
3060 wprintf(_(" <I>in</I> "));
3061 escputs(WC->wc_roomname);
3064 if (recipient_required) {
3066 wprintf("<div style=\"float: left;\"><label for=\"recp_id\"> ");
3069 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
3070 escputs(bstr("recp"));
3071 wprintf("\" size=45 maxlength=1000 />");
3072 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
3075 wprintf("<br/><label for=\"cc_id\"> ");
3078 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
3079 escputs(bstr("cc"));
3080 wprintf("\" size=45 maxlength=1000 />");
3081 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
3082 wprintf("<br/><label for=\"bcc_id\"> ");
3085 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
3086 escputs(bstr("bcc"));
3087 wprintf("\" size=45 maxlength=1000 />");
3088 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
3090 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
3091 wprintf("<script type=\"text/javascript\"> \n"
3092 " activate_entmsg_autocompleters(); \n"
3097 /** Pop open an address book -- begin **/
3099 "<a href=\"javascript:PopOpenAddressBook('recp_id|%s|cc_id|%s|bcc_id|%s');\" "
3101 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
3103 _("To:"), _("CC:"), _("BCC:"),
3104 _("Contacts"), _("Contacts")
3106 /** Pop open an address book -- end **/
3109 wprintf("<div style=\"clear: both;\"><label for=\"subject_id\" > ");
3110 if (recipient_required || subject_required) {
3111 wprintf(_("Subject:"));
3114 wprintf(_("Subject (optional):"));
3117 "<input type=\"text\" name=\"subject\" id=\"subject_id\" value=\" ");
3118 escputs(bstr("subject"));
3119 wprintf("\" size=45 maxlength=70>\n");
3121 wprintf("</div>\n");
3123 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
3125 /** If we're continuing from a previous edit, put our partially-composed message back... */
3126 msgescputs(bstr("msgtext"));
3128 /* If we're forwarding a message, insert it here... */
3129 if (atol(bstr("fwdquote")) > 0L) {
3130 wprintf("<br><div align=center><i>");
3131 wprintf(_("--- forwarded message ---"));
3132 wprintf("</i></div><br>");
3133 pullquote_message(atol(bstr("fwdquote")), 1, 1);
3136 /** If we're replying quoted, insert the quote here... */
3137 else if (atol(bstr("replyquote")) > 0L) {
3140 pullquote_message(atol(bstr("replyquote")), 0, 1);
3141 wprintf("</blockquote><br>");
3144 /** If we're editing a wiki page, insert the existing page here... */
3145 else if (WC->wc_view == VIEW_WIKI) {
3146 safestrncpy(buf, bstr("wikipage"), sizeof buf);
3147 str_wiki_index(buf);
3148 existing_page = locate_message_by_uid(buf);
3149 if (existing_page >= 0L) {
3150 pullquote_message(existing_page, 1, 0);
3154 /** Insert our signature if appropriate... */
3155 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
3156 get_preference("use_sig", buf, sizeof buf);
3157 if (!strcasecmp(buf, "yes")) {
3159 get_preference("signature", ebuf, sizeof ebuf);
3160 euid_unescapize(buf, ebuf);
3161 wprintf("<br>--<br>");
3163 for (i=0; i<len; ++i) {
3164 if (buf[i] == '\n') {
3167 else if (buf[i] == '<') {
3170 else if (buf[i] == '>') {
3173 else if (buf[i] == '&') {
3176 else if (buf[i] == '\"') {
3179 else if (buf[i] == '\'') {
3182 else if (isprint(buf[i])) {
3183 wprintf("%c", buf[i]);
3189 wprintf("</textarea>");
3192 * The following template embeds the TinyMCE richedit control, and automatically
3193 * transforms the textarea into a richedit textarea.
3195 do_template("richedit");
3197 /** Enumerate any attachments which are already in place... */
3198 wprintf("<div><img src=\"static/diskette_24x.gif\" class=\"imgedit\" ");
3199 wprintf(_("Attachments:"));
3201 wprintf("<select name=\"which_attachment\" size=1>");
3202 for (att = WC->first_attachment; att != NULL; att = att->next) {
3203 wprintf("<option value=\"");
3204 urlescputs(att->filename);
3206 escputs(att->filename);
3207 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3208 wprintf("</option>\n");
3210 wprintf("</select>");
3212 /** Now offer the ability to attach additional files... */
3213 wprintf(" ");
3214 wprintf(_("Attach file:"));
3215 wprintf(" <input name=\"attachfile\" "
3216 "size=16 type=\"file\">\n "
3217 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3221 /** Make sure we only insert our signature once */
3222 if (strcmp(bstr("sig_inserted"), "yes")) {
3223 wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
3226 wprintf("</form>\n");
3227 wprintf("</div></div>\n");
3229 DONE: address_book_popup();
3235 * \brief delete a message
3237 void delete_msg(void)
3242 msgid = atol(bstr("msgid"));
3244 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3245 serv_printf("DELE %ld", msgid);
3247 else { /** Otherwise move it to Trash */
3248 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3251 serv_getln(buf, sizeof buf);
3252 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3254 readloop("readnew");
3259 * \brief move a message to another folder
3266 msgid = atol(bstr("msgid"));
3268 if (!IsEmptyStr(bstr("move_button"))) {
3269 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3271 serv_getln(buf, sizeof buf);
3272 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3274 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3277 readloop("readnew");
3285 * \brief Confirm move of a message
3287 void confirm_move_msg(void)
3293 msgid = atol(bstr("msgid"));
3296 output_headers(1, 1, 2, 0, 0, 0);
3297 wprintf("<div id=\"banner\">\n");
3298 wprintf("<TABLE WIDTH=100%% BORDER=0><TR><TD>");
3299 wprintf("<SPAN CLASS=\"titlebar\">");
3300 wprintf(_("Confirm move of message"));
3301 wprintf("</SPAN>\n");
3302 wprintf("</TD></TR></TABLE>\n");
3303 wprintf("</div>\n<div id=\"content\">\n");
3305 wprintf("<CENTER>");
3307 wprintf(_("Move this message to:"));
3308 wprintf("<br />\n");
3310 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3311 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
3312 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3314 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3316 serv_getln(buf, sizeof buf);
3317 if (buf[0] == '1') {
3318 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3319 extract_token(targ, buf, 0, '|', sizeof targ);
3320 wprintf("<OPTION>");
3325 wprintf("</SELECT>\n");
3326 wprintf("<br />\n");
3328 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3330 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3331 wprintf("</form></CENTER>\n");
3333 wprintf("</CENTER>\n");