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.
86 for (i=0; i<strlen(buf); ++i) {
87 if ((buf[i] < 32) || (buf[i] > 126)) {
88 illegal_non_rfc2047_encoding = 1;
91 if (illegal_non_rfc2047_encoding) {
92 char default_header_charset[128];
93 get_preference("default_header_charset", default_header_charset, sizeof default_header_charset);
94 if ( (strcasecmp(default_header_charset, "UTF-8")) && (strcasecmp(default_header_charset, "us-ascii")) ) {
95 ic = ctdl_iconv_open("UTF-8", default_header_charset);
96 if (ic != (iconv_t)(-1) ) {
99 safestrncpy(ibuf, buf, 1024);
100 ibuflen = strlen(ibuf);
102 obuf = (char *) malloc(obuflen);
104 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
105 osav[1024-obuflen] = 0;
114 /** Now we handle foreign character sets properly encoded
117 while (start=strstr(buf, "=?"), end=strstr(buf, "?="),
118 ((start != NULL) && (end != NULL) && (end > start)) )
120 extract_token(charset, start, 1, '?', sizeof charset);
121 extract_token(encoding, start, 2, '?', sizeof encoding);
122 extract_token(istr, start, 3, '?', sizeof istr);
126 if (!strcasecmp(encoding, "B")) { /**< base64 */
127 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
129 else if (!strcasecmp(encoding, "Q")) { /**< quoted-printable */
137 if (istr[pos] == '_') istr[pos] = ' ';
141 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, len);
144 strcpy(ibuf, istr); /**< unknown encoding */
145 ibuflen = strlen(istr);
148 ic = ctdl_iconv_open("UTF-8", charset);
149 if (ic != (iconv_t)(-1) ) {
151 obuf = (char *) malloc(obuflen);
153 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
154 osav[1024-obuflen] = 0;
159 remove_token(end, 0, '?');
160 remove_token(end, 0, '?');
161 remove_token(end, 0, '?');
162 remove_token(end, 0, '?');
163 strcpy(end, &end[1]);
165 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
174 remove_token(end, 0, '?');
175 remove_token(end, 0, '?');
176 remove_token(end, 0, '?');
177 remove_token(end, 0, '?');
178 strcpy(end, &end[1]);
180 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
187 * Since spammers will go to all sorts of absurd lengths to get their
188 * messages through, there are LOTS of corrupt headers out there.
189 * So, prevent a really badly formed RFC2047 header from throwing
190 * this function into an infinite loop.
193 if (passes > 20) return;
203 * \brief RFC2047-encode a header field if necessary.
204 * If no non-ASCII characters are found, the string
205 * will be copied verbatim without encoding.
207 * \param target Target buffer.
208 * \param maxlen Maximum size of target buffer.
209 * \param source Source string to be encoded.
211 void rfc2047encode(char *target, int maxlen, char *source)
213 int need_to_encode = 0;
217 if (target == NULL) return;
219 for (i=0; i<strlen(source); ++i) {
220 if ((source[i] < 32) || (source[i] > 126)) {
225 if (!need_to_encode) {
226 safestrncpy(target, source, maxlen);
230 strcpy(target, "=?UTF-8?Q?");
231 for (i=0; i<strlen(source); ++i) {
232 ch = (unsigned char) source[i];
233 if ((ch < 32) || (ch > 126) || (ch == 61)) {
234 sprintf(&target[strlen(target)], "=%02X", ch);
237 sprintf(&target[strlen(target)], "%c", ch);
241 strcat(target, "?=");
248 * \brief Look for URL's embedded in a buffer and make them linkable. We use a
249 * target window in order to keep the BBS session in its own window.
250 * \param buf the message buffer
262 for (pos = 0; pos < strlen(buf); ++pos) {
263 if (!strncasecmp(&buf[pos], "http://", 7))
265 if (!strncasecmp(&buf[pos], "ftp://", 6))
272 for (pos = strlen(buf); pos > start; --pos) {
273 if ( (!isprint(buf[pos]))
274 || (isspace(buf[pos]))
278 || (buf[pos] == '\\')
292 strncpy(urlbuf, &buf[start], end - start);
293 urlbuf[end - start] = 0;
295 strncpy(outbuf, buf, start);
296 sprintf(&outbuf[start], "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
297 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
298 strcat(outbuf, &buf[end]);
299 if ( strlen(outbuf) < 250 )
305 * \brief Turn a vCard "n" (name) field into something displayable.
306 * \param name the name field to convert
308 void vcard_n_prettyize(char *name)
313 original_name = strdup(name);
314 for (i=0; i<5; ++i) {
315 if (strlen(original_name) > 0) {
316 if (original_name[strlen(original_name)-1] == ' ') {
317 original_name[strlen(original_name)-1] = 0;
319 if (original_name[strlen(original_name)-1] == ';') {
320 original_name[strlen(original_name)-1] = 0;
325 for (i=0; i<strlen(original_name); ++i) {
326 if (original_name[i] == ';') {
330 name[strlen(name)+1] = 0;
331 name[strlen(name)] = original_name[i];
341 * \brief preparse a vcard name
342 * display_vcard() calls this after parsing the textual vCard into
343 * our 'struct vCard' data object.
344 * This gets called instead of display_parsed_vcard() if we are only looking
345 * to extract the person's name instead of displaying the card.
346 * \param v the vcard to retrieve the name from
347 * \param storename where to put the name at
349 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
352 strcpy(storename, "");
354 name = vcard_get_prop(v, "n", 1, 0, 0);
356 strcpy(storename, name);
357 /* vcard_n_prettyize(storename); */
365 * \brief html print a vcard
366 * display_vcard() calls this after parsing the textual vCard into
367 * our 'struct vCard' data object.
369 * Set 'full' to nonzero to display the full card, otherwise it will only
370 * show a summary line.
372 * This code is a bit ugly, so perhaps an explanation is due: we do this
373 * in two passes through the vCard fields. On the first pass, we process
374 * fields we understand, and then render them in a pretty fashion at the
375 * end. Then we make a second pass, outputting all the fields we don't
376 * understand in a simple two-column name/value format.
377 * \param v the vCard to display
378 * \param full display all items of the vcard?
380 void display_parsed_vcard(struct vCard *v, int full) {
386 char *thisname, *thisvalue;
387 char firsttoken[SIZ];
396 strcpy(fullname, "");
404 name = vcard_get_prop(v, "fn", 1, 0, 0);
408 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
409 strcpy(fullname, name);
410 vcard_n_prettyize(fullname);
420 wprintf("<div align=center><table bgcolor=#aaaaaa width=50%%>");
421 for (pass=1; pass<=2; ++pass) {
423 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
425 thisname = strdup(v->prop[i].name);
426 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
428 for (j=0; j<num_tokens(thisname, ';'); ++j) {
429 extract_token(buf, thisname, j, ';', sizeof buf);
430 if (!strcasecmp(buf, "encoding=quoted-printable")) {
432 remove_token(thisname, j, ';');
434 if (!strcasecmp(buf, "encoding=base64")) {
436 remove_token(thisname, j, ';');
441 thisvalue = malloc(strlen(v->prop[i].value) + 50);
442 j = CtdlDecodeQuotedPrintable(
443 thisvalue, v->prop[i].value,
444 strlen(v->prop[i].value) );
448 thisvalue = malloc(strlen(v->prop[i].value) + 50);
450 thisvalue, v->prop[i].value,
451 strlen(v->prop[i].value) );
454 thisvalue = strdup(v->prop[i].value);
457 /** Various fields we may encounter ***/
459 /** N is name, but only if there's no FN already there */
460 if (!strcasecmp(firsttoken, "n")) {
461 if (strlen(fullname) == 0) {
462 strcpy(fullname, thisvalue);
463 vcard_n_prettyize(fullname);
467 /** FN (full name) is a true 'display name' field */
468 else if (!strcasecmp(firsttoken, "fn")) {
469 strcpy(fullname, thisvalue);
473 else if (!strcasecmp(firsttoken, "title")) {
474 strcpy(title, thisvalue);
478 else if (!strcasecmp(firsttoken, "org")) {
479 strcpy(org, thisvalue);
482 else if (!strcasecmp(firsttoken, "email")) {
483 if (strlen(mailto) > 0) strcat(mailto, "<br />");
485 "<a href=\"display_enter"
486 "?force_room=_MAIL_?recp=");
488 urlesc(&mailto[strlen(mailto)], fullname);
489 urlesc(&mailto[strlen(mailto)], " <");
490 urlesc(&mailto[strlen(mailto)], thisvalue);
491 urlesc(&mailto[strlen(mailto)], ">");
493 strcat(mailto, "\">");
494 stresc(&mailto[strlen(mailto)], thisvalue, 1, 1);
495 strcat(mailto, "</A>");
497 else if (!strcasecmp(firsttoken, "tel")) {
498 if (strlen(phone) > 0) strcat(phone, "<br />");
499 strcat(phone, thisvalue);
500 for (j=0; j<num_tokens(thisname, ';'); ++j) {
501 extract_token(buf, thisname, j, ';', sizeof buf);
502 if (!strcasecmp(buf, "tel"))
504 else if (!strcasecmp(buf, "work"))
505 strcat(phone, _(" (work)"));
506 else if (!strcasecmp(buf, "home"))
507 strcat(phone, _(" (home)"));
508 else if (!strcasecmp(buf, "cell"))
509 strcat(phone, _(" (cell)"));
517 else if (!strcasecmp(firsttoken, "adr")) {
520 wprintf(_("Address:"));
521 wprintf("</TD><TD>");
522 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
523 extract_token(buf, thisvalue, j, ';', sizeof buf);
524 if (strlen(buf) > 0) {
526 if (j<3) wprintf("<br />");
530 wprintf("</TD></TR>\n");
533 else if (!strcasecmp(firsttoken, "version")) {
536 else if (!strcasecmp(firsttoken, "rev")) {
539 else if (!strcasecmp(firsttoken, "label")) {
544 /*** Don't show extra fields. They're ugly.
548 wprintf("</TD><TD>");
550 wprintf("</TD></TR>\n");
560 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
561 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
562 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
563 "<FONT SIZE=+1><B>");
565 wprintf("</B></FONT>");
566 if (strlen(title) > 0) {
567 wprintf("<div align=right>");
571 if (strlen(org) > 0) {
572 wprintf("<div align=right>");
576 wprintf("</TD></TR>\n");
578 if (strlen(phone) > 0) {
580 wprintf(_("Telephone:"));
581 wprintf("</td><td>%s</td></tr>\n", phone);
583 if (strlen(mailto) > 0) {
585 wprintf(_("E-mail:"));
586 wprintf("</td><td>%s</td></tr>\n", mailto);
592 wprintf("</table></div>\n");
598 * \brief Display a textual vCard
599 * (Converts to a vCard object and then calls the actual display function)
600 * Set 'full' to nonzero to display the whole card instead of a one-liner.
601 * Or, if "storename" is non-NULL, just store the person's name in that
602 * buffer instead of displaying the card at all.
603 * \param vcard_source the buffer containing the vcard text
604 * \param alpha what???
605 * \param full should we usse all lines?
606 * \param storename where to store???
608 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
614 v = vcard_load(vcard_source);
615 if (v == NULL) return;
617 name = vcard_get_prop(v, "n", 1, 0, 0);
623 if (storename != NULL) {
624 fetchname_parsed_vcard(v, storename);
626 else if ( (alpha == 0)
627 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
628 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
630 display_parsed_vcard(v, full);
644 * \brief I wanna SEE that message!
645 * \param msgnum the citadel number of the message to display
646 * \param printable_view are we doing a print view?
647 * \param section Optional for encapsulated message/rfc822 submessage)
649 void read_message(long msgnum, int printable_view, char *section) {
651 char mime_partnum[256];
653 char mime_filename[256];
654 char mime_content_type[256];
655 char mime_charset[256];
656 char mime_disposition[256];
658 struct attach_link *attach_links = NULL;
659 int num_attach_links = 0;
660 char mime_submessages[256];
667 char reply_all[4096];
673 char vcard_partnum[256];
674 char cal_partnum[256];
675 char *part_source = NULL;
676 char msg4_partnum[32];
678 iconv_t ic = (iconv_t)(-1) ;
679 char *ibuf; /**< Buffer of characters to be converted */
680 char *obuf; /**< Buffer for converted characters */
681 size_t ibuflen; /**< Length of input buffer */
682 size_t obuflen; /**< Length of output buffer */
683 char *osav; /**< Saved pointer to output buffer */
689 strcpy(reply_to, "");
690 strcpy(reply_all, "");
691 strcpy(vcard_partnum, "");
692 strcpy(cal_partnum, "");
693 strcpy(mime_content_type, "text/plain");
694 strcpy(mime_charset, "us-ascii");
695 strcpy(mime_submessages, "");
697 serv_printf("MSG4 %ld|%s", msgnum, section);
698 serv_getln(buf, sizeof buf);
701 wprintf(_("ERROR:"));
702 wprintf("</strong> %s<br />\n", &buf[4]);
706 /** begin everythingamundo table */
707 if (!printable_view) {
708 wprintf("<div class=\"fix_scrollbar_bug message\" ");
709 wprintf("onMouseOver=document.getElementById(\"msg%ld\").style.visibility=\"visible\" ", msgnum);
710 wprintf("onMouseOut=document.getElementById(\"msg%ld\").style.visibility=\"hidden\" >", msgnum);
713 /** start msg buttons */
714 if (!printable_view) {
715 wprintf("<div id=\"msg%ld\" class=\"msgbuttons\" >\n",msgnum);
718 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
719 wprintf("<a href=\"display_enter");
720 if (WC->is_mailbox) {
721 wprintf("?replyquote=%ld", msgnum);
724 urlescputs(reply_to);
725 if (strlen(m_subject) > 0) {
726 wprintf("?subject=");
727 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
728 urlescputs(m_subject);
730 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Reply"));
734 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
735 if (!WC->is_mailbox) {
736 wprintf("<a href=\"display_enter");
737 wprintf("?replyquote=%ld", msgnum);
739 urlescputs(reply_to);
740 if (strlen(m_subject) > 0) {
741 wprintf("?subject=");
742 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
743 urlescputs(m_subject);
745 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyQuoted"));
750 if (WC->wc_view == VIEW_MAILBOX) {
751 wprintf("<a href=\"display_enter");
752 wprintf("?replyquote=%ld", msgnum);
754 urlescputs(reply_to);
756 urlescputs(reply_all);
757 if (strlen(m_subject) > 0) {
758 wprintf("?subject=");
759 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
760 urlescputs(m_subject);
762 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyAll"));
766 if (WC->wc_view == VIEW_MAILBOX) {
767 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
768 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
769 urlescputs(m_subject);
770 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Forward"));
773 /** If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
774 if ( (WC->is_room_aide) || (WC->is_mailbox) || (WC->room_flags2 & QR2_COLLABDEL) ) {
776 wprintf("<a href=\"confirm_move_msg?msgid=%ld\"><span>[</span>%s<span>]</span></a> ",
780 wprintf("<a href=\"delete_msg?msgid=%ld\" "
781 "onClick=\"return confirm('%s');\">"
782 "<span>[</span>%s<span>]</span> "
783 "</a> ", msgnum, _("Delete this message?"), _("Delete")
788 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'); \" >"
789 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Headers"));
793 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'); \" >"
794 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Print"));
801 /** begin message header table */
802 wprintf("<div class=\"message_header\">");
803 strcpy(m_subject, "");
806 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
807 if (!strcmp(buf, "000")) {
809 wprintf(_("unexpected end of message"));
810 wprintf(" (1)</i><br /><br />\n");
814 if (!strncasecmp(buf, "nhdr=yes", 8))
818 if (!strncasecmp(buf, "type=", 5))
819 format_type = atoi(&buf[5]);
820 if (!strncasecmp(buf, "from=", 5)) {
821 strcpy(from, &buf[5]);
823 wprintf("<a href=\"showuser?who=");
825 utf8ify_rfc822_string(from);
832 if (!strncasecmp(buf, "subj=", 5)) {
833 safestrncpy(m_subject, &buf[5], sizeof m_subject);
835 if (!strncasecmp(buf, "cccc=", 5)) {
836 safestrncpy(m_cc, &buf[5], sizeof m_cc);
837 if (strlen(reply_all) > 0) {
838 strcat(reply_all, ", ");
840 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
841 (sizeof reply_all - strlen(reply_all)) );
843 if ((!strncasecmp(buf, "hnod=", 5))
844 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
845 wprintf("(%s) ", &buf[5]);
847 if ((!strncasecmp(buf, "room=", 5))
848 && (strcasecmp(&buf[5], WC->wc_roomname))
849 && (strlen(&buf[5])>0) ) {
851 wprintf("%s> ", &buf[5]);
853 if (!strncasecmp(buf, "rfca=", 5)) {
854 strcpy(rfca, &buf[5]);
860 if (!strncasecmp(buf, "node=", 5)) {
861 strcpy(node, &buf[5]);
862 if ( ((WC->room_flags & QR_NETWORK)
863 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
864 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
867 wprintf("@%s ", &buf[5]);
870 if (!strncasecmp(buf, "rcpt=", 5)) {
872 if (strlen(reply_all) > 0) {
873 strcat(reply_all, ", ");
875 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
876 (sizeof reply_all - strlen(reply_all)) );
878 utf8ify_rfc822_string(&buf[5]);
883 if (!strncasecmp(buf, "time=", 5)) {
884 fmt_date(now, atol(&buf[5]), 0);
888 if (!strncasecmp(buf, "part=", 5)) {
889 extract_token(mime_name, &buf[5], 0, '|', sizeof mime_filename);
890 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
891 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
892 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
893 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
894 mime_length = extract_int(&buf[5], 5);
897 striplt(mime_filename);
898 if ( (strlen(mime_filename) == 0) && (strlen(mime_name) > 0) ) {
899 strcpy(mime_filename, mime_name);
902 if (!strcasecmp(mime_content_type, "message/rfc822")) {
903 if (strlen(mime_submessages) > 0) {
904 strcat(mime_submessages, "|");
906 strcat(mime_submessages, mime_partnum);
908 else if ((!strcasecmp(mime_disposition, "inline"))
909 && (!strncasecmp(mime_content_type, "image/", 6)) ){
911 attach_links = realloc(attach_links,
912 (num_attach_links*sizeof(struct attach_link)));
913 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
914 snprintf(attach_links[num_attach_links-1].html, 1024,
915 "<img src=\"mimepart/%ld/%s/%s\">",
916 msgnum, mime_partnum, mime_filename);
918 else if ( ( (!strcasecmp(mime_disposition, "attachment"))
919 || (!strcasecmp(mime_disposition, "inline"))
920 || (!strcasecmp(mime_disposition, ""))
921 ) && (strlen(mime_content_type) > 0)
924 attach_links = realloc(attach_links,
925 (num_attach_links*sizeof(struct attach_link)));
926 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
927 snprintf(attach_links[num_attach_links-1].html, 1024,
928 "<img src=\"static/diskette_24x.gif\" "
929 "border=0 align=middle>\n"
930 "%s (%s, %d bytes) [ "
931 "<a href=\"mimepart/%ld/%s/%s\""
932 "target=\"wc.%ld.%s\">%s</a>"
934 "<a href=\"mimepart_download/%ld/%s/%s\">%s</a>"
937 mime_content_type, mime_length,
938 msgnum, mime_partnum, mime_filename,
939 msgnum, mime_partnum,
941 msgnum, mime_partnum, mime_filename,
946 /** begin handler prep ***/
947 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
948 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
949 strcpy(vcard_partnum, mime_partnum);
952 if (!strcasecmp(mime_content_type, "text/calendar")) {
953 strcpy(cal_partnum, mime_partnum);
956 /** end handler prep ***/
962 /** Generate a reply-to address */
963 if (strlen(rfca) > 0) {
964 if (strlen(from) > 0) {
965 snprintf(reply_to, sizeof(reply_to), "%s <%s>", from, rfca);
968 strcpy(reply_to, rfca);
972 if ( (strlen(node) > 0)
973 && (strcasecmp(node, serv_info.serv_nodename))
974 && (strcasecmp(node, serv_info.serv_humannode)) ) {
975 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
979 snprintf(reply_to, sizeof(reply_to), "%s", from);
990 utf8ify_rfc822_string(m_cc);
991 utf8ify_rfc822_string(m_subject);
993 if (strlen(m_cc) > 0) {
994 wprintf("<div class=\"message_subject\">");
1000 if (strlen(m_subject) > 0) {
1001 wprintf("<div class=\"message_subject\">");
1002 wprintf(_("Subject:"));
1010 wprintf("<div class=\"message_content\" ");
1013 * Learn the content type
1015 strcpy(mime_content_type, "text/plain");
1016 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1017 if (!strcmp(buf, "000")) {
1019 wprintf(_("unexpected end of message"));
1020 wprintf(" (2)</i><br /><br />\n");
1023 if (!strncasecmp(buf, "X-Citadel-MSG4-Partnum:", 23)) {
1024 safestrncpy(msg4_partnum, &buf[23], sizeof(msg4_partnum));
1025 striplt(msg4_partnum);
1027 if (!strncasecmp(buf, "Content-type:", 13)) {
1028 safestrncpy(mime_content_type, &buf[13], sizeof(mime_content_type));
1029 striplt(mime_content_type);
1030 for (i=0; i<strlen(mime_content_type); ++i) {
1031 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1032 safestrncpy(mime_charset, &mime_content_type[i+8],
1033 sizeof mime_charset);
1036 for (i=0; i<strlen(mime_content_type); ++i) {
1037 if (mime_content_type[i] == ';') {
1038 mime_content_type[i] = 0;
1041 for (i=0; i<strlen(mime_charset); ++i) {
1042 if (mime_charset[i] == ';') {
1043 mime_charset[i] = 0;
1049 /** Set up a character set conversion if we need to (and if we can) */
1051 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
1052 if ( (strcasecmp(mime_charset, "us-ascii"))
1053 && (strcasecmp(mime_charset, "UTF-8"))
1054 && (strcasecmp(mime_charset, ""))
1056 ic = ctdl_iconv_open("UTF-8", mime_charset);
1057 if (ic == (iconv_t)(-1) ) {
1058 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1059 __FILE__, __LINE__, mime_charset, strerror(errno));
1064 /** Messages in legacy Citadel variformat get handled thusly... */
1065 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1069 /** Boring old 80-column fixed format text gets handled this way... */
1070 else if ( (!strcasecmp(mime_content_type, "text/plain"))
1071 || (!strcasecmp(mime_content_type, "text")) ) {
1072 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1073 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1074 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1077 if (ic != (iconv_t)(-1) ) {
1079 ibuflen = strlen(ibuf);
1081 obuf = (char *) malloc(obuflen);
1083 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1084 osav[SIZ-obuflen] = 0;
1085 safestrncpy(buf, osav, sizeof buf);
1090 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1091 buf[strlen(buf) - 1] = 0;
1093 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1094 wprintf("<blockquote>");
1096 } else if ((bq == 1) &&
1097 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1098 wprintf("</blockquote>");
1104 wprintf("</tt><br />\n");
1106 wprintf("</i><br />");
1109 else /** HTML is fun, but we've got to strip it first */
1110 if (!strcasecmp(mime_content_type, "text/html")) {
1111 output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
1114 /** Unknown weirdness */
1116 wprintf(_("I don't know how to display %s"), mime_content_type);
1117 wprintf("<br />\n", mime_content_type);
1118 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1121 /** If there are attached submessages, display them now... */
1122 if ( (strlen(mime_submessages) > 0) && (!section[0]) ) {
1123 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1124 extract_token(buf, mime_submessages, i, '|', sizeof buf);
1125 /** use printable_view to suppress buttons */
1126 wprintf("<blockquote>");
1127 read_message(msgnum, 1, buf);
1128 wprintf("</blockquote>");
1133 /** Afterwards, offer links to download attachments 'n' such */
1134 if ( (num_attach_links > 0) && (!section[0]) ) {
1135 for (i=0; i<num_attach_links; ++i) {
1136 if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
1137 wprintf("%s", attach_links[i].html);
1142 /** Handler for vCard parts */
1143 if (strlen(vcard_partnum) > 0) {
1144 part_source = load_mimepart(msgnum, vcard_partnum);
1145 if (part_source != NULL) {
1147 /** If it's my vCard I can edit it */
1148 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1149 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1150 || (WC->wc_view == VIEW_ADDRESSBOOK)
1152 wprintf("<a href=\"edit_vcard?"
1153 "msgnum=%ld?partnum=%s\">",
1154 msgnum, vcard_partnum);
1155 wprintf("[%s]</a>", _("edit"));
1158 /** In all cases, display the full card */
1159 display_vcard(part_source, 0, 1, NULL);
1163 /** Handler for calendar parts */
1164 if (strlen(cal_partnum) > 0) {
1165 part_source = load_mimepart(msgnum, cal_partnum);
1166 if (part_source != NULL) {
1167 cal_process_attachment(part_source,
1168 msgnum, cal_partnum);
1178 wprintf("</div>\n");
1180 /** end everythingamundo table */
1181 if (!printable_view) {
1182 wprintf("</div>\n");
1185 if (num_attach_links > 0) {
1190 if (ic != (iconv_t)(-1) ) {
1199 * \brief Unadorned HTML output of an individual message, suitable
1200 * for placing in a hidden iframe, for printing, or whatever
1202 * \param msgnum_as_string Message number, as a string instead of as a long int
1204 void embed_message(char *msgnum_as_string) {
1207 msgnum = atol(msgnum_as_string);
1208 begin_ajax_response();
1209 read_message(msgnum, 0, "");
1210 end_ajax_response();
1215 * \brief Printable view of a message
1217 * \param msgnum_as_string Message number, as a string instead of as a long int
1219 void print_message(char *msgnum_as_string) {
1222 msgnum = atol(msgnum_as_string);
1223 output_headers(0, 0, 0, 0, 0, 0);
1225 wprintf("Content-type: text/html\r\n"
1227 "Connection: close\r\n",
1231 wprintf("\r\n\r\n<html>\n"
1232 "<head><title>Printable view</title></head>\n"
1233 "<body onLoad=\" window.print(); window.close(); \">\n"
1236 read_message(msgnum, 1, "");
1238 wprintf("\n</body></html>\n\n");
1245 * \brief Display a message's headers
1247 * \param msgnum_as_string Message number, as a string instead of as a long int
1249 void display_headers(char *msgnum_as_string) {
1253 msgnum = atol(msgnum_as_string);
1254 output_headers(0, 0, 0, 0, 0, 0);
1256 wprintf("Content-type: text/plain\r\n"
1258 "Connection: close\r\n",
1262 serv_printf("MSG2 %ld|3", msgnum);
1263 serv_getln(buf, sizeof buf);
1264 if (buf[0] == '1') {
1265 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1266 wprintf("%s\n", buf);
1276 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1277 * or 'reply quoted' operations.
1279 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1280 * in this function. Doing so would throw a JavaScript error in the
1281 * 'supplied text' argument to the editor.
1283 * \param msgnum Message number of the message we want to quote
1284 * \param forward_attachments Nonzero if we want attachments to be forwarded
1286 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1288 char mime_partnum[256];
1289 char mime_filename[256];
1290 char mime_content_type[256];
1291 char mime_charset[256];
1292 char mime_disposition[256];
1294 char *attachments = NULL;
1296 int num_attachments = 0;
1297 struct wc_attachment *att, *aptr;
1298 char m_subject[256];
1304 int format_type = 0;
1309 iconv_t ic = (iconv_t)(-1) ;
1310 char *ibuf; /**< Buffer of characters to be converted */
1311 char *obuf; /**< Buffer for converted characters */
1312 size_t ibuflen; /**< Length of input buffer */
1313 size_t obuflen; /**< Length of output buffer */
1314 char *osav; /**< Saved pointer to output buffer */
1320 strcpy(reply_to, "");
1321 strcpy(mime_content_type, "text/plain");
1322 strcpy(mime_charset, "us-ascii");
1324 serv_printf("MSG4 %ld", msgnum);
1325 serv_getln(buf, sizeof buf);
1326 if (buf[0] != '1') {
1327 wprintf(_("ERROR:"));
1328 wprintf("%s<br />", &buf[4]);
1332 strcpy(m_subject, "");
1334 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1335 if (!strcmp(buf, "000")) {
1336 wprintf("%s (3)", _("unexpected end of message"));
1339 if (include_headers) {
1340 if (!strncasecmp(buf, "nhdr=yes", 8))
1344 if (!strncasecmp(buf, "type=", 5))
1345 format_type = atoi(&buf[5]);
1346 if (!strncasecmp(buf, "from=", 5)) {
1347 strcpy(from, &buf[5]);
1348 wprintf(_("from "));
1350 utf8ify_rfc822_string(from);
1354 if (!strncasecmp(buf, "subj=", 5)) {
1355 strcpy(m_subject, &buf[5]);
1357 if ((!strncasecmp(buf, "hnod=", 5))
1358 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1359 wprintf("(%s) ", &buf[5]);
1361 if ((!strncasecmp(buf, "room=", 5))
1362 && (strcasecmp(&buf[5], WC->wc_roomname))
1363 && (strlen(&buf[5])>0) ) {
1365 wprintf("%s> ", &buf[5]);
1367 if (!strncasecmp(buf, "rfca=", 5)) {
1368 strcpy(rfca, &buf[5]);
1374 if (!strncasecmp(buf, "node=", 5)) {
1375 strcpy(node, &buf[5]);
1376 if ( ((WC->room_flags & QR_NETWORK)
1377 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1378 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1379 && (strlen(rfca)==0)
1381 wprintf("@%s ", &buf[5]);
1384 if (!strncasecmp(buf, "rcpt=", 5)) {
1386 wprintf("%s ", &buf[5]);
1388 if (!strncasecmp(buf, "time=", 5)) {
1389 fmt_date(now, atol(&buf[5]), 0);
1390 wprintf("%s ", now);
1395 * Save attachment info for later. We can't start downloading them
1396 * yet because we're in the middle of a server transaction.
1398 if (!strncasecmp(buf, "part=", 5)) {
1399 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1402 sprintf(ptr, "%s%s\n",
1403 ((attachments != NULL) ? attachments : ""),
1408 lprintf(9, "attachments=<%s>\n", attachments);
1414 if (include_headers) {
1418 utf8ify_rfc822_string(m_subject);
1420 if (strlen(m_subject) > 0) {
1421 wprintf(_("Subject:"));
1423 msgescputs(m_subject);
1434 * Learn the content type
1436 strcpy(mime_content_type, "text/plain");
1437 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1438 if (!strcmp(buf, "000")) {
1439 wprintf("%s (4)", _("unexpected end of message"));
1442 if (!strncasecmp(buf, "Content-type: ", 14)) {
1443 safestrncpy(mime_content_type, &buf[14],
1444 sizeof(mime_content_type));
1445 for (i=0; i<strlen(mime_content_type); ++i) {
1446 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1447 safestrncpy(mime_charset, &mime_content_type[i+8],
1448 sizeof mime_charset);
1451 for (i=0; i<strlen(mime_content_type); ++i) {
1452 if (mime_content_type[i] == ';') {
1453 mime_content_type[i] = 0;
1456 for (i=0; i<strlen(mime_charset); ++i) {
1457 if (mime_charset[i] == ';') {
1458 mime_charset[i] = 0;
1464 /** Set up a character set conversion if we need to (and if we can) */
1466 if ( (strcasecmp(mime_charset, "us-ascii"))
1467 && (strcasecmp(mime_charset, "UTF-8"))
1468 && (strcasecmp(mime_charset, ""))
1470 ic = ctdl_iconv_open("UTF-8", mime_charset);
1471 if (ic == (iconv_t)(-1) ) {
1472 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1473 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1478 /** Messages in legacy Citadel variformat get handled thusly... */
1479 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1483 /* Boring old 80-column fixed format text gets handled this way... */
1484 else if (!strcasecmp(mime_content_type, "text/plain")) {
1485 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1486 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1487 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1490 if (ic != (iconv_t)(-1) ) {
1492 ibuflen = strlen(ibuf);
1494 obuf = (char *) malloc(obuflen);
1496 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1497 osav[SIZ-obuflen] = 0;
1498 safestrncpy(buf, osav, sizeof buf);
1503 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1504 buf[strlen(buf) - 1] = 0;
1506 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1507 wprintf("<blockquote>");
1509 } else if ((bq == 1) &&
1510 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1511 wprintf("</blockquote>");
1517 wprintf("</tt><br />");
1519 wprintf("</i><br />");
1522 /** HTML just gets escaped and stuffed back into the editor */
1523 else if (!strcasecmp(mime_content_type, "text/html")) {
1524 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1530 /** Unknown weirdness ... don't know how to handle this content type */
1532 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1536 /** end of body handler */
1539 * If there were attachments, we have to download them and insert them
1540 * into the attachment chain for the forwarded message we are composing.
1542 if ( (forward_attachments) && (num_attachments) ) {
1543 for (i=0; i<num_attachments; ++i) {
1544 extract_token(buf, attachments, i, '\n', sizeof buf);
1545 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1546 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1547 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1548 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1549 mime_length = extract_int(buf, 5);
1552 * tracing ... uncomment if necessary
1555 lprintf(9, "fwd filename: %s\n", mime_filename);
1556 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1557 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1558 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1559 lprintf(9, "fwd length : %d\n", mime_length);
1561 if ( (!strcasecmp(mime_disposition, "inline"))
1562 || (!strcasecmp(mime_disposition, "attachment")) ) {
1564 /* Create an attachment struct from this mime part... */
1565 att = malloc(sizeof(struct wc_attachment));
1566 memset(att, 0, sizeof(struct wc_attachment));
1567 att->length = mime_length;
1568 strcpy(att->content_type, mime_content_type);
1569 strcpy(att->filename, mime_filename);
1571 att->data = load_mimepart(msgnum, mime_partnum);
1573 /* And add it to the list. */
1574 if (WC->first_attachment == NULL) {
1575 WC->first_attachment = att;
1578 aptr = WC->first_attachment;
1579 while (aptr->next != NULL) aptr = aptr->next;
1588 if (ic != (iconv_t)(-1) ) {
1593 if (attachments != NULL) {
1599 * \brief Display one row in the mailbox summary view
1601 * \param num The row number to be displayed
1603 void display_summarized(int num) {
1606 wprintf("<tr id=\"m%ld\" style=\"font-weight:%s;\" "
1607 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1608 WC->summ[num].msgnum,
1609 (WC->summ[num].is_new ? "bold" : "normal"),
1610 WC->summ[num].msgnum
1613 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1614 escputs(WC->summ[num].subj);
1617 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1618 escputs(WC->summ[num].from);
1621 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1622 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1632 * \brief display the adressbook overview
1633 * \param msgnum the citadel message number
1634 * \param alpha what????
1636 void display_addressbook(long msgnum, char alpha) {
1638 char mime_partnum[SIZ];
1639 char mime_filename[SIZ];
1640 char mime_content_type[SIZ];
1641 char mime_disposition[SIZ];
1643 char vcard_partnum[SIZ];
1644 char *vcard_source = NULL;
1645 struct message_summary summ;
1647 memset(&summ, 0, sizeof(summ));
1648 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1650 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1652 serv_getln(buf, sizeof buf);
1653 if (buf[0] != '1') return;
1655 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1656 if (!strncasecmp(buf, "part=", 5)) {
1657 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1658 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1659 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1660 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1661 mime_length = extract_int(&buf[5], 5);
1663 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1664 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1665 strcpy(vcard_partnum, mime_partnum);
1671 if (strlen(vcard_partnum) > 0) {
1672 vcard_source = load_mimepart(msgnum, vcard_partnum);
1673 if (vcard_source != NULL) {
1675 /** Display the summary line */
1676 display_vcard(vcard_source, alpha, 0, NULL);
1678 /** If it's my vCard I can edit it */
1679 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1680 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1681 || (WC->wc_view == VIEW_ADDRESSBOOK)
1683 wprintf("<a href=\"edit_vcard?"
1684 "msgnum=%ld?partnum=%s\">",
1685 msgnum, vcard_partnum);
1686 wprintf("[%s]</a>", _("edit"));
1698 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1699 * \param namebuf name to analyze, reverse if nescessary
1701 void lastfirst_firstlast(char *namebuf) {
1702 char firstname[SIZ];
1706 if (namebuf == NULL) return;
1707 if (strchr(namebuf, ';') != NULL) return;
1709 i = num_tokens(namebuf, ' ');
1712 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1713 remove_token(namebuf, i-1, ' ');
1714 strcpy(firstname, namebuf);
1715 sprintf(namebuf, "%s; %s", lastname, firstname);
1719 * \brief fetch what??? name
1720 * \param msgnum the citadel message number
1721 * \param namebuf where to put the name in???
1723 void fetch_ab_name(long msgnum, char *namebuf) {
1725 char mime_partnum[SIZ];
1726 char mime_filename[SIZ];
1727 char mime_content_type[SIZ];
1728 char mime_disposition[SIZ];
1730 char vcard_partnum[SIZ];
1731 char *vcard_source = NULL;
1733 struct message_summary summ;
1735 if (namebuf == NULL) return;
1736 strcpy(namebuf, "");
1738 memset(&summ, 0, sizeof(summ));
1739 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1741 sprintf(buf, "MSG0 %ld|0", msgnum); /** unfortunately we need the mime info now */
1743 serv_getln(buf, sizeof buf);
1744 if (buf[0] != '1') return;
1746 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1747 if (!strncasecmp(buf, "part=", 5)) {
1748 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1749 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1750 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1751 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1752 mime_length = extract_int(&buf[5], 5);
1754 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1755 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1756 strcpy(vcard_partnum, mime_partnum);
1762 if (strlen(vcard_partnum) > 0) {
1763 vcard_source = load_mimepart(msgnum, vcard_partnum);
1764 if (vcard_source != NULL) {
1766 /* Grab the name off the card */
1767 display_vcard(vcard_source, 0, 0, namebuf);
1773 lastfirst_firstlast(namebuf);
1775 for (i=0; i<strlen(namebuf); ++i) {
1776 if (namebuf[i] != ';') return;
1778 strcpy(namebuf, _("(no name)"));
1784 * \brief Record compare function for sorting address book indices
1785 * \param ab1 adressbook one
1786 * \param ab2 adressbook two
1788 int abcmp(const void *ab1, const void *ab2) {
1790 (((const struct addrbookent *)ab1)->ab_name),
1791 (((const struct addrbookent *)ab2)->ab_name)
1797 * \brief Helper function for do_addrbook_view()
1798 * Converts a name into a three-letter tab label
1799 * \param tabbuf the tabbuffer to add name to
1800 * \param name the name to add to the tabbuffer
1802 void nametab(char *tabbuf, char *name) {
1803 stresc(tabbuf, name, 0, 0);
1804 tabbuf[0] = toupper(tabbuf[0]);
1805 tabbuf[1] = tolower(tabbuf[1]);
1806 tabbuf[2] = tolower(tabbuf[2]);
1812 * \brief Render the address book using info we gathered during the scan
1813 * \param addrbook the addressbook to render
1814 * \param num_ab the number of the addressbook
1816 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1820 static int NAMESPERPAGE = 60;
1824 char tabfirst_label[SIZ];
1826 char tablast_label[SIZ];
1829 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1830 wprintf(_("This address book is empty."));
1831 wprintf("</i></div>\n");
1836 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1839 num_pages = num_ab / NAMESPERPAGE;
1841 page = atoi(bstr("page"));
1844 for (i=0; i<=num_pages; ++i) {
1846 wprintf("<a href=\"readfwd?page=%d\">", i);
1851 tabfirst = i * NAMESPERPAGE;
1852 tablast = tabfirst + NAMESPERPAGE - 1;
1853 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1854 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1855 nametab(tablast_label, addrbook[tablast].ab_name);
1856 wprintf("[%s - %s]",
1857 tabfirst_label, tablast_label
1866 wprintf("<br />\n");
1868 wprintf("<table border=0 cellspacing=0 "
1869 "cellpadding=3 width=100%%>\n"
1872 for (i=0; i<num_ab; ++i) {
1874 if ((i / NAMESPERPAGE) == page) {
1876 if ((displayed % 4) == 0) {
1877 if (displayed > 0) {
1881 wprintf("<tr bgcolor=\"#%s\">",
1882 (bg ? "DDDDDD" : "FFFFFF")
1888 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
1889 addrbook[i].ab_msgnum);
1890 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1891 vcard_n_prettyize(addrbook[i].ab_name);
1892 escputs(addrbook[i].ab_name);
1893 wprintf("</a></td>\n");
1898 wprintf("</tr></table>\n");
1904 * \brief load message pointers from the server
1905 * \param servcmd the citadel command to send to the citserver
1906 * \param with_headers what headers???
1908 int load_msg_ptrs(char *servcmd, int with_headers)
1919 int num_summ_alloc = 0;
1921 if (WC->summ != NULL) {
1926 num_summ_alloc = 100;
1928 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1931 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1933 serv_getln(buf, sizeof buf);
1934 if (buf[0] != '1') {
1937 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1938 if (nummsgs < maxload) {
1939 WC->msgarr[nummsgs] = extract_long(buf, 0);
1940 datestamp = extract_long(buf, 1);
1941 extract_token(fullname, buf, 2, '|', sizeof fullname);
1942 extract_token(nodename, buf, 3, '|', sizeof nodename);
1943 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1944 extract_token(subject, buf, 5, '|', sizeof subject);
1948 if (nummsgs > num_summ_alloc) {
1949 num_summ_alloc *= 2;
1950 WC->summ = realloc(WC->summ,
1951 num_summ_alloc * sizeof(struct message_summary));
1955 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1956 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1957 safestrncpy(WC->summ[nummsgs-1].subj,
1958 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1959 if (strlen(fullname) > 0) {
1960 safestrncpy(WC->summ[nummsgs-1].from,
1961 fullname, sizeof WC->summ[nummsgs-1].from);
1963 if (strlen(subject) > 0) {
1964 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1965 sizeof WC->summ[nummsgs-1].subj);
1968 /** Handle subjects with RFC2047 encoding */
1969 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1971 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1972 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1975 if (strlen(nodename) > 0) {
1976 if ( ((WC->room_flags & QR_NETWORK)
1977 || ((strcasecmp(nodename, serv_info.serv_nodename)
1978 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1980 strcat(WC->summ[nummsgs-1].from, " @ ");
1981 strcat(WC->summ[nummsgs-1].from, nodename);
1985 WC->summ[nummsgs-1].date = datestamp;
1988 /** Handle senders with RFC2047 encoding */
1989 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1991 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1992 strcpy(&WC->summ[nummsgs-1].from[22], "...");
2001 * \brief qsort() compatible function to compare two longs in descending order.
2003 * \param s1 first number to compare
2004 * \param s2 second number to compare
2006 int longcmp_r(const void *s1, const void *s2) {
2013 if (l1 > l2) return(-1);
2014 if (l1 < l2) return(+1);
2020 * \brief qsort() compatible function to compare two message summary structs by ascending subject.
2022 * \param s1 first item to compare
2023 * \param s2 second item to compare
2025 int summcmp_subj(const void *s1, const void *s2) {
2026 struct message_summary *summ1;
2027 struct message_summary *summ2;
2029 summ1 = (struct message_summary *)s1;
2030 summ2 = (struct message_summary *)s2;
2031 return strcasecmp(summ1->subj, summ2->subj);
2035 * \brief qsort() compatible function to compare two message summary structs by descending subject.
2037 * \param s1 first item to compare
2038 * \param s2 second item to compare
2040 int summcmp_rsubj(const void *s1, const void *s2) {
2041 struct message_summary *summ1;
2042 struct message_summary *summ2;
2044 summ1 = (struct message_summary *)s1;
2045 summ2 = (struct message_summary *)s2;
2046 return strcasecmp(summ2->subj, summ1->subj);
2050 * \brief qsort() compatible function to compare two message summary structs by ascending sender.
2052 * \param s1 first item to compare
2053 * \param s2 second item to compare
2055 int summcmp_sender(const void *s1, const void *s2) {
2056 struct message_summary *summ1;
2057 struct message_summary *summ2;
2059 summ1 = (struct message_summary *)s1;
2060 summ2 = (struct message_summary *)s2;
2061 return strcasecmp(summ1->from, summ2->from);
2065 * \brief qsort() compatible function to compare two message summary structs by descending sender.
2067 * \param s1 first item to compare
2068 * \param s2 second item to compare
2070 int summcmp_rsender(const void *s1, const void *s2) {
2071 struct message_summary *summ1;
2072 struct message_summary *summ2;
2074 summ1 = (struct message_summary *)s1;
2075 summ2 = (struct message_summary *)s2;
2076 return strcasecmp(summ2->from, summ1->from);
2080 * \brief qsort() compatible function to compare two message summary structs by ascending date.
2082 * \param s1 first item to compare
2083 * \param s2 second item to compare
2085 int summcmp_date(const void *s1, const void *s2) {
2086 struct message_summary *summ1;
2087 struct message_summary *summ2;
2089 summ1 = (struct message_summary *)s1;
2090 summ2 = (struct message_summary *)s2;
2092 if (summ1->date < summ2->date) return -1;
2093 else if (summ1->date > summ2->date) return +1;
2098 * \brief qsort() compatible function to compare two message summary structs by descending date.
2100 * \param s1 first item to compare
2101 * \param s2 second item to compare
2103 int summcmp_rdate(const void *s1, const void *s2) {
2104 struct message_summary *summ1;
2105 struct message_summary *summ2;
2107 summ1 = (struct message_summary *)s1;
2108 summ2 = (struct message_summary *)s2;
2110 if (summ1->date < summ2->date) return +1;
2111 else if (summ1->date > summ2->date) return -1;
2118 * \brief command loop for reading messages
2120 * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
2122 void readloop(char *oper)
2131 long *displayed_msgs = NULL;
2132 int num_displayed = 0;
2134 int is_addressbook = 0;
2135 int is_singlecard = 0;
2136 int is_calendar = 0;
2141 int lowest_displayed = (-1);
2142 int highest_displayed = 0;
2143 struct addrbookent *addrbook = NULL;
2145 char *sortby = NULL;
2146 char sortpref_name[128];
2147 char sortpref_value[128];
2148 char *subjsort_button;
2149 char *sendsort_button;
2150 char *datesort_button;
2151 int bbs_reverse = 0;
2153 if (WC->wc_view == VIEW_WIKI) {
2154 sprintf(buf, "wiki?room=%s?page=home", WC->wc_roomname);
2159 startmsg = atol(bstr("startmsg"));
2160 maxmsgs = atoi(bstr("maxmsgs"));
2161 is_summary = atoi(bstr("summary"));
2162 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2164 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
2165 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
2167 sortby = bstr("sortby");
2168 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
2169 set_preference(sortpref_name, sortby, 1);
2171 if (strlen(sortby) == 0) sortby = sortpref_value;
2174 if (strlen(sortby) == 0) sortby = "rdate";
2176 /** message board sort */
2177 if (!strcasecmp(sortby, "reverse")) {
2184 output_headers(1, 1, 1, 0, 0, 0);
2187 * When in summary mode, always show ALL messages instead of just
2188 * new or old. Otherwise, show what the user asked for.
2190 if (!strcmp(oper, "readnew")) {
2191 strcpy(cmd, "MSGS NEW");
2193 else if (!strcmp(oper, "readold")) {
2194 strcpy(cmd, "MSGS OLD");
2196 else if (!strcmp(oper, "do_search")) {
2197 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2200 strcpy(cmd, "MSGS ALL");
2203 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
2205 if (!strcmp(oper, "do_search")) {
2206 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2209 strcpy(cmd, "MSGS ALL");
2213 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2215 if (!strcmp(oper, "do_search")) {
2216 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2219 strcpy(cmd, "MSGS ALL");
2224 if (is_summary) { /**< fetch header summary */
2225 snprintf(cmd, sizeof cmd, "MSGS %s|%s||1",
2226 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2227 (!strcmp(oper, "do_search") ? bstr("query") : "")
2234 * Are we doing a summary view? If so, we need to know old messages
2235 * and new messages, so we can do that pretty boldface thing for the
2238 strcpy(old_msgs, "");
2241 serv_getln(buf, sizeof buf);
2242 if (buf[0] == '2') {
2243 strcpy(old_msgs, &buf[4]);
2247 is_singlecard = atoi(bstr("is_singlecard"));
2249 if (WC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2251 strcpy(cmd, "MSGS ALL");
2254 if (WC->wc_default_view == VIEW_TASKS) { /**< tasks */
2256 strcpy(cmd, "MSGS ALL");
2259 if (WC->wc_default_view == VIEW_NOTES) { /**< notes */
2261 strcpy(cmd, "MSGS ALL");
2266 wprintf("<div align=center>%s</div>\n", _("Click on any note to edit it."));
2267 wprintf("<div id=\"new_notes_here\"></div>\n");
2270 nummsgs = load_msg_ptrs(cmd, is_summary);
2273 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2274 wprintf("<div align=\"center\"><br /><em>");
2275 if (!strcmp(oper, "readnew")) {
2276 wprintf(_("No new messages."));
2277 } else if (!strcmp(oper, "readold")) {
2278 wprintf(_("No old messages."));
2280 wprintf(_("No messages here."));
2282 wprintf("</em><br /></div>\n");
2289 for (a = 0; a < nummsgs; ++a) {
2290 /** Are you a new message, or an old message? */
2292 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
2293 WC->summ[a].is_new = 0;
2296 WC->summ[a].is_new = 1;
2302 if (startmsg == 0L) {
2304 startmsg = WC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2307 startmsg = WC->msgarr[0];
2312 if (!strcasecmp(sortby, "subject")) {
2313 qsort(WC->summ, WC->num_summ,
2314 sizeof(struct message_summary), summcmp_subj);
2316 else if (!strcasecmp(sortby, "rsubject")) {
2317 qsort(WC->summ, WC->num_summ,
2318 sizeof(struct message_summary), summcmp_rsubj);
2320 else if (!strcasecmp(sortby, "sender")) {
2321 qsort(WC->summ, WC->num_summ,
2322 sizeof(struct message_summary), summcmp_sender);
2324 else if (!strcasecmp(sortby, "rsender")) {
2325 qsort(WC->summ, WC->num_summ,
2326 sizeof(struct message_summary), summcmp_rsender);
2328 else if (!strcasecmp(sortby, "date")) {
2329 qsort(WC->summ, WC->num_summ,
2330 sizeof(struct message_summary), summcmp_date);
2332 else if (!strcasecmp(sortby, "rdate")) {
2333 qsort(WC->summ, WC->num_summ,
2334 sizeof(struct message_summary), summcmp_rdate);
2338 if (!strcasecmp(sortby, "subject")) {
2339 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2341 else if (!strcasecmp(sortby, "rsubject")) {
2342 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2345 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2348 if (!strcasecmp(sortby, "sender")) {
2349 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2351 else if (!strcasecmp(sortby, "rsender")) {
2352 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2355 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2358 if (!strcasecmp(sortby, "date")) {
2359 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2361 else if (!strcasecmp(sortby, "rdate")) {
2362 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2365 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2369 wprintf("</div>\n"); /** end of 'content' div */
2371 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2372 " document.onkeydown = CtdlMsgListKeyPress; "
2373 " if (document.layers) { "
2374 " document.captureEvents(Event.KEYPRESS); "
2379 /** note that Date and Delete are now in the same column */
2380 wprintf("<div id=\"message_list_hdr\">"
2381 "<div class=\"fix_scrollbar_bug\">"
2382 "<table cellspacing=0 style=\"width:100%%\">"
2385 wprintf("<th width=%d%%>%s %s</th>"
2386 "<th width=%d%%>%s %s</th>"
2387 "<th width=%d%%>%s %s"
2389 "<input type=\"submit\" name=\"delete_button\" id=\"delbutton\" "
2390 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2396 _("Subject"), subjsort_button,
2397 SENDER_COL_WIDTH_PCT,
2398 _("Sender"), sendsort_button,
2399 DATE_PLUS_BUTTONS_WIDTH_PCT,
2400 _("Date"), datesort_button,
2403 wprintf("</table></div></div>\n");
2405 wprintf("<div id=\"message_list\">"
2407 "<div class=\"fix_scrollbar_bug\">\n"
2409 "<table class=\"mailbox_summary\" id=\"summary_headers\" "
2410 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2414 for (a = 0; a < nummsgs; ++a) {
2415 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2417 /** Display the message */
2419 display_summarized(a);
2421 else if (is_addressbook) {
2422 fetch_ab_name(WC->msgarr[a], buf);
2424 addrbook = realloc(addrbook,
2425 (sizeof(struct addrbookent) * num_ab) );
2426 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2427 sizeof(addrbook[num_ab-1].ab_name));
2428 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
2430 else if (is_calendar) {
2431 display_calendar(WC->msgarr[a]);
2433 else if (is_tasks) {
2434 display_task(WC->msgarr[a]);
2436 else if (is_notes) {
2437 display_note(WC->msgarr[a]);
2440 if (displayed_msgs == NULL) {
2441 displayed_msgs = malloc(sizeof(long) *
2442 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2444 displayed_msgs[num_displayed] = WC->msgarr[a];
2447 if (lowest_displayed < 0) lowest_displayed = a;
2448 highest_displayed = a;
2455 * Set the "is_bbview" variable if it appears that we are looking at
2456 * a classic bulletin board view.
2458 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2459 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2464 if (displayed_msgs != NULL) {
2466 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2469 /** if we do a split bbview in the future, begin messages div here */
2471 for (a=0; a<num_displayed; ++a) {
2472 read_message(displayed_msgs[a], 0, "");
2475 /** if we do a split bbview in the future, end messages div here */
2477 free(displayed_msgs);
2478 displayed_msgs = NULL;
2483 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2484 wprintf("</div>"); /**< end of 'message_list' div */
2486 /** Here's the grab-it-to-resize-the-message-list widget */
2487 wprintf("<div id=\"resize_msglist\" "
2488 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2489 "<div class=\"fix_scrollbar_bug\"> <hr>"
2493 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2497 * Bump these because although we're thinking in zero base, the user
2498 * is a drooling idiot and is thinking in one base.
2501 ++highest_displayed;
2504 * If we're not currently looking at ALL requested
2505 * messages, then display the selector bar
2508 /** begin bbview scroller */
2509 wprintf("<form name=\"msgomatic\">");
2510 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2512 wprintf("<select name=\"whichones\" size=\"1\" "
2513 "OnChange=\"location.href=msgomatic.whichones.options"
2514 "[selectedIndex].value\">\n");
2517 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2519 lo = b - maxmsgs + 2;
2521 wprintf("<option %s value="
2526 "%d-%d</option> \n",
2527 ((WC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2536 for (b=0; b<nummsgs; b = b + maxmsgs) {
2538 hi = b + maxmsgs + 1;
2539 if (hi > nummsgs) hi = nummsgs;
2540 wprintf("<option %s value="
2545 "%d-%d</option> \n",
2546 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2555 wprintf("<option value=\"%s?startmsg=%ld"
2556 "?maxmsgs=9999999?summary=%d\">"
2560 WC->msgarr[0], is_summary);
2562 wprintf("</select> ");
2563 wprintf(_("of %d messages."), nummsgs);
2565 /** forward/reverse */
2566 wprintf(" <select name=\"direction\" size=\"1\" "
2567 "OnChange=\"location.href=msgomatic.direction.options"
2568 "[selectedIndex].value\">\n"
2571 wprintf("<option %s value=\"%s?sortby=forward\">oldest to newest</option>\n",
2572 (bbs_reverse ? "" : "selected"),
2576 wprintf("<option %s value=\"%s?sortby=reverse\">newest to oldest</option>\n",
2577 (bbs_reverse ? "selected" : ""),
2581 wprintf("</select></form>\n");
2582 /** end bbview scroller */
2587 do_tasks_view(); /** Render the task list */
2591 do_calendar_view(); /** Render the calendar */
2594 if (is_addressbook) {
2595 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2598 /** Note: wDumpContent() will output one additional </div> tag. */
2600 if (addrbook != NULL) free(addrbook);
2602 /** free the summary */
2603 if (WC->summ != NULL) {
2612 * \brief Back end for post_message()
2613 * ... this is where the actual message gets transmitted to the server.
2615 void post_mime_to_server(void) {
2617 int is_multipart = 0;
2619 struct wc_attachment *att;
2621 size_t encoded_length;
2623 /** RFC2045 requires this, and some clients look for it... */
2624 serv_puts("MIME-Version: 1.0");
2625 serv_puts("X-Mailer: " SERVER);
2627 /** If there are attachments, we have to do multipart/mixed */
2628 if (WC->first_attachment != NULL) {
2633 sprintf(boundary, "Citadel--Multipart--%s--%04x--%04x",
2634 serv_info.serv_fqdn,
2639 /** Remember, serv_printf() appends an extra newline */
2640 serv_printf("Content-type: multipart/mixed; "
2641 "boundary=\"%s\"\n", boundary);
2642 serv_printf("This is a multipart message in MIME format.\n");
2643 serv_printf("--%s", boundary);
2646 serv_puts("Content-type: text/html; charset=utf-8");
2647 serv_puts("Content-Transfer-Encoding: quoted-printable");
2649 serv_puts("<html><body>\r\n");
2650 text_to_server_qp(bstr("msgtext")); /** Transmit message in quoted-printable encoding */
2651 serv_puts("</body></html>\r\n");
2655 /** Add in the attachments */
2656 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2658 encoded_length = ((att->length * 150) / 100);
2659 encoded = malloc(encoded_length);
2660 if (encoded == NULL) break;
2661 CtdlEncodeBase64(encoded, att->data, att->length, 1);
2663 serv_printf("--%s", boundary);
2664 serv_printf("Content-type: %s", att->content_type);
2665 serv_printf("Content-disposition: attachment; "
2666 "filename=\"%s\"", att->filename);
2667 serv_puts("Content-transfer-encoding: base64");
2669 serv_write(encoded, strlen(encoded));
2674 serv_printf("--%s--", boundary);
2682 * \brief Post message (or don't post message)
2684 * Note regarding the "dont_post" variable:
2685 * A random value (actually, it's just a timestamp) is inserted as a hidden
2686 * field called "postseq" when the display_enter page is generated. This
2687 * value is checked when posting, using the static variable dont_post. If a
2688 * user attempts to post twice using the same dont_post value, the message is
2689 * discarded. This prevents the accidental double-saving of the same message
2690 * if the user happens to click the browser "back" button.
2692 void post_message(void)
2695 char encoded_subject[1024];
2696 static long dont_post = (-1L);
2697 struct wc_attachment *att, *aptr;
2698 int is_anonymous = 0;
2701 display_name = bstr("display_name");
2702 if (!strcmp(display_name, "__ANONYMOUS__")) {
2707 if (WC->upload_length > 0) {
2709 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WC->upload_length);
2710 /** There's an attachment. Save it to this struct... */
2711 att = malloc(sizeof(struct wc_attachment));
2712 memset(att, 0, sizeof(struct wc_attachment));
2713 att->length = WC->upload_length;
2714 strcpy(att->content_type, WC->upload_content_type);
2715 strcpy(att->filename, WC->upload_filename);
2718 /** And add it to the list. */
2719 if (WC->first_attachment == NULL) {
2720 WC->first_attachment = att;
2723 aptr = WC->first_attachment;
2724 while (aptr->next != NULL) aptr = aptr->next;
2729 * Mozilla sends a simple filename, which is what we want,
2730 * but Satan's Browser sends an entire pathname. Reduce
2731 * the path to just a filename if we need to.
2733 while (num_tokens(att->filename, '/') > 1) {
2734 remove_token(att->filename, 0, '/');
2736 while (num_tokens(att->filename, '\\') > 1) {
2737 remove_token(att->filename, 0, '\\');
2741 * Transfer control of this memory from the upload struct
2742 * to the attachment struct.
2744 att->data = WC->upload;
2745 WC->upload_length = 0;
2751 if (strlen(bstr("cancel_button")) > 0) {
2752 sprintf(WC->ImportantMessage,
2753 _("Cancelled. Message was not posted."));
2754 } else if (strlen(bstr("attach_button")) > 0) {
2757 } else if (atol(bstr("postseq")) == dont_post) {
2758 sprintf(WC->ImportantMessage,
2759 _("Automatically cancelled because you have already "
2760 "saved this message."));
2762 rfc2047encode(encoded_subject, sizeof encoded_subject, bstr("subject"));
2763 sprintf(buf, "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s",
2771 bstr("my_email_addr")
2774 serv_getln(buf, sizeof buf);
2775 if (buf[0] == '4') {
2776 post_mime_to_server();
2777 if ( (strlen(bstr("recp")) > 0)
2778 || (strlen(bstr("cc")) > 0)
2779 || (strlen(bstr("bcc")) > 0)
2781 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2784 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2786 dont_post = atol(bstr("postseq"));
2788 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
2789 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2795 free_attachments(WC);
2798 * We may have been supplied with instructions regarding the location
2799 * to which we must return after posting. If found, go there.
2801 if (strlen(bstr("return_to")) > 0) {
2802 http_redirect(bstr("return_to"));
2805 * If we were editing a page in a wiki room, go to that page now.
2807 else if (strlen(bstr("wikipage")) > 0) {
2808 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
2812 * Otherwise, just go to the "read messages" loop.
2815 readloop("readnew");
2823 * \brief display the message entry screen
2825 void display_enter(void)
2831 struct wc_attachment *att;
2832 int recipient_required = 0;
2833 int recipient_bad = 0;
2835 int is_anonymous = 0;
2836 long existing_page = (-1L);
2840 if (strlen(bstr("force_room")) > 0) {
2841 gotoroom(bstr("force_room"));
2844 display_name = bstr("display_name");
2845 if (!strcmp(display_name, "__ANONYMOUS__")) {
2850 /** First test to see whether this is a room that requires recipients to be entered */
2851 serv_puts("ENT0 0");
2852 serv_getln(buf, sizeof buf);
2853 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
2854 recipient_required = 1;
2856 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2857 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2858 readloop("readnew");
2863 * Are we perhaps in an address book view? If so, then an "enter
2864 * message" command really means "add new entry."
2866 if (WC->wc_default_view == VIEW_ADDRESSBOOK) {
2867 do_edit_vcard(-1, "", "");
2871 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
2873 * Are we perhaps in a calendar room? If so, then an "enter
2874 * message" command really means "add new calendar item."
2876 if (WC->wc_default_view == VIEW_CALENDAR) {
2877 display_edit_event();
2882 * Are we perhaps in a tasks view? If so, then an "enter
2883 * message" command really means "add new task."
2885 if (WC->wc_default_view == VIEW_TASKS) {
2886 display_edit_task();
2892 * Otherwise proceed normally.
2893 * Do a custom room banner with no navbar...
2895 output_headers(1, 1, 2, 0, 0, 0);
2896 wprintf("<div id=\"banner\">\n");
2897 embed_room_banner(NULL, navbar_none);
2898 wprintf("</div>\n");
2899 wprintf("<div id=\"content\">\n"
2900 "<div class=\"fix_scrollbar_bug message \">");
2902 /** Now check our actual recipients if there are any */
2903 if (recipient_required) {
2904 sprintf(buf, "ENT0 0|%s|%d|0||%s||%s|%s|%s",
2908 bstr("cc"), bstr("bcc"), bstr("wikipage"));
2910 serv_getln(buf, sizeof buf);
2912 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
2913 if (strlen(bstr("recp")) + strlen(bstr("cc")) + strlen(bstr("bcc")) > 0) {
2917 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2918 wprintf("<em>%s</em><br />\n", &buf[4]);
2923 /** If we got this far, we can display the message entry screen. */
2925 /** begin message entry screen */
2927 "enctype=\"multipart/form-data\" "
2929 "accept-charset=\"UTF-8\" "
2931 "name=\"enterform\""
2933 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2934 if (WC->wc_view == VIEW_WIKI) {
2935 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
2937 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
2941 wprintf("<img src=\"static/newmess3_24x.gif\" class=\"imgedit\">");
2942 wprintf(" "); /** header bar */
2943 fmt_date(buf, now, 0);
2945 wprintf("\n"); /** header bar */
2948 wprintf("<label for=\"from_id\" > ");
2949 wprintf(_(" <I>from</I> "));
2950 wprintf("</label>");
2952 /* Allow the user to select any of his valid screen names */
2954 wprintf("<select name=\"display_name\" size=1 id=\"from_id\">\n");
2957 serv_getln(buf, sizeof buf);
2958 if (buf[0] == '1') {
2959 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2960 wprintf("<option %s value=\"",
2961 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
2966 wprintf("</option>\n");
2970 if (WC->room_flags & QR_ANONOPT) {
2971 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
2972 ((!strcasecmp(bstr("__ANONYMOUS__"), WC->wc_fullname)) ? "selected" : ""),
2977 wprintf("</select>\n");
2979 /* If this is an email (not a post), allow the user to select any of his
2980 * valid email addresses.
2982 if (recipient_required) {
2984 serv_getln(buf, sizeof buf);
2985 if (buf[0] == '1') {
2986 wprintf("<select name=\"my_email_addr\" size=1>\n");
2987 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2988 wprintf("<option value=\"");
2992 wprintf("></option>\n");
2994 wprintf("</select>\n");
2998 wprintf(_(" <I>in</I> "));
2999 escputs(WC->wc_roomname);
3002 if (recipient_required) {
3004 wprintf("<div style=\"float: left;\"><label for=\"recp_id\"> ");
3007 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
3008 escputs(bstr("recp"));
3009 wprintf("\" size=45 maxlength=1000 />");
3010 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
3013 wprintf("<br/><label for=\"cc_id\"> ");
3016 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
3017 escputs(bstr("cc"));
3018 wprintf("\" size=45 maxlength=1000 />");
3019 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
3020 wprintf("<br/><label for=\"bcc_id\"> ");
3023 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
3024 escputs(bstr("bcc"));
3025 wprintf("\" size=45 maxlength=1000 />");
3026 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
3028 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
3029 wprintf("<script type=\"text/javascript\"> \n"
3030 " activate_entmsg_autocompleters(); \n"
3035 /** Pop open an address book -- begin **/
3037 "<a href=\"javascript:PopOpenAddressBook('recp_id|%s|cc_id|%s|bcc_id|%s');\" "
3039 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
3041 _("To:"), _("CC:"), _("BCC:"),
3042 _("Contacts"), _("Contacts")
3044 /** Pop open an address book -- end **/
3047 wprintf("<div style=\"clear: both;\"><label for=\"subject_id\" > ");
3048 if (recipient_required) {
3049 wprintf(_("Subject:"));
3052 wprintf(_("Subject (optional):"));
3055 "<input type=\"text\" name=\"subject\" value=\" \" id=\"subject_id\" ");
3056 escputs(bstr("subject"));
3057 wprintf("\" size=45 maxlength=70>\n");
3059 wprintf("</div>\n");
3061 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
3063 /** If we're continuing from a previous edit, put our partially-composed message back... */
3064 msgescputs(bstr("msgtext"));
3066 /* If we're forwarding a message, insert it here... */
3067 if (atol(bstr("fwdquote")) > 0L) {
3068 wprintf("<br><div align=center><i>");
3069 wprintf(_("--- forwarded message ---"));
3070 wprintf("</i></div><br>");
3071 pullquote_message(atol(bstr("fwdquote")), 1, 1);
3074 /** If we're replying quoted, insert the quote here... */
3075 else if (atol(bstr("replyquote")) > 0L) {
3078 pullquote_message(atol(bstr("replyquote")), 0, 1);
3079 wprintf("</blockquote><br>");
3082 /** If we're editing a wiki page, insert the existing page here... */
3083 else if (WC->wc_view == VIEW_WIKI) {
3084 safestrncpy(buf, bstr("wikipage"), sizeof buf);
3085 str_wiki_index(buf);
3086 existing_page = locate_message_by_uid(buf);
3087 if (existing_page >= 0L) {
3088 pullquote_message(existing_page, 1, 0);
3092 /** Insert our signature if appropriate... */
3093 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
3094 get_preference("use_sig", buf, sizeof buf);
3095 if (!strcasecmp(buf, "yes")) {
3096 get_preference("signature", ebuf, sizeof ebuf);
3097 euid_unescapize(buf, ebuf);
3098 wprintf("<br>--<br>");
3099 for (i=0; i<strlen(buf); ++i) {
3100 if (buf[i] == '\n') {
3103 else if (buf[i] == '<') {
3106 else if (buf[i] == '>') {
3109 else if (buf[i] == '&') {
3112 else if (buf[i] == '\"') {
3115 else if (buf[i] == '\'') {
3118 else if (isprint(buf[i])) {
3119 wprintf("%c", buf[i]);
3125 wprintf("</textarea>");
3128 * The following script embeds the TinyMCE richedit control, and automatically
3129 * transforms the textarea into a richedit textarea.
3132 "<script language=\"javascript\" type=\"text/javascript\" src=\"tiny_mce/tiny_mce.js\"></script>\n"
3133 "<script language=\"javascript\" type=\"text/javascript\">"
3135 " mode : \"textareas\", width : \"100%%\", browsers : \"msie,gecko\", "
3136 " theme : \"advanced\", plugins : \"iespell\", "
3137 " theme_advanced_buttons1 : \"bold, italic, underline, strikethrough, justifyleft, justifycenter, justifyright, justifyfull, bullist, numlist, cut, copy, paste, link, image, help, forecolor, iespell, code\", "
3138 " theme_advanced_buttons2 : \"\", "
3139 " theme_advanced_buttons3 : \"\", "
3140 " content_css : \"static/webcit-tinymce.css\" "
3145 /** Enumerate any attachments which are already in place... */
3146 wprintf("<div style=\"float: left; \"><img src=\"static/diskette_24x.gif\" border=0 ");
3147 wprintf(_("Attachments:"));
3149 wprintf("<select name=\"which_attachment\" size=1>");
3150 for (att = WC->first_attachment; att != NULL; att = att->next) {
3151 wprintf("<option value=\"");
3152 urlescputs(att->filename);
3154 escputs(att->filename);
3155 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3156 wprintf("</option>\n");
3158 wprintf("</select><br />");
3160 /** Now offer the ability to attach additional files... */
3161 wprintf(" ");
3162 wprintf(_("Attach file:"));
3163 wprintf(" <input name=\"attachfile\" "
3164 "size=16 type=\"file\">\n "
3165 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3168 /** Seth asked for these to be at the top *and* bottom... (removed) */
3169 wprintf("<div class=\"send_edit_msg\">");
3170 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3171 if (recipient_required) {
3172 wprintf(_("Send message"));
3174 wprintf(_("Post message"));
3177 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3181 /** Make sure we only insert our signature once */
3182 if (strcmp(bstr("sig_inserted"), "yes")) {
3183 wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
3186 wprintf("</form>\n");
3187 wprintf("</div></div>\n");
3189 DONE: address_book_popup();
3195 * \brief delete a message
3197 void delete_msg(void)
3202 msgid = atol(bstr("msgid"));
3204 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3205 serv_printf("DELE %ld", msgid);
3207 else { /** Otherwise move it to Trash */
3208 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3211 serv_getln(buf, sizeof buf);
3212 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3214 readloop("readnew");
3219 * \brief move a message to another folder
3226 msgid = atol(bstr("msgid"));
3228 if (strlen(bstr("move_button")) > 0) {
3229 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3231 serv_getln(buf, sizeof buf);
3232 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3234 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3237 readloop("readnew");
3245 * \brief Confirm move of a message
3247 void confirm_move_msg(void)
3253 msgid = atol(bstr("msgid"));
3256 output_headers(1, 1, 2, 0, 0, 0);
3257 wprintf("<div id=\"banner\">\n");
3258 wprintf("<TABLE WIDTH=100%% BORDER=0><TR><TD>");
3259 wprintf("<SPAN CLASS=\"titlebar\">");
3260 wprintf(_("Confirm move of message"));
3261 wprintf("</SPAN>\n");
3262 wprintf("</TD></TR></TABLE>\n");
3263 wprintf("</div>\n<div id=\"content\">\n");
3265 wprintf("<CENTER>");
3267 wprintf(_("Move this message to:"));
3268 wprintf("<br />\n");
3270 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3271 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3273 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3275 serv_getln(buf, sizeof buf);
3276 if (buf[0] == '1') {
3277 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3278 extract_token(targ, buf, 0, '|', sizeof targ);
3279 wprintf("<OPTION>");
3284 wprintf("</SELECT>\n");
3285 wprintf("<br />\n");
3287 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3289 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3290 wprintf("</form></CENTER>\n");
3292 wprintf("</CENTER>\n");