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
265 for (pos = 0; pos < strlen(buf); ++pos) {
266 if (!strncasecmp(&buf[pos], "http://", 7))
268 if (!strncasecmp(&buf[pos], "ftp://", 6))
275 if ((start > 0) && (buf[start - 1] == '<'))
277 if ((start > 0) && (buf[start - 1] == '['))
279 if ((start > 0) && (buf[start - 1] == '('))
281 if ((start > 0) && (buf[start - 1] == '{'))
284 for (pos = strlen(buf); pos > start; --pos) {
285 if ((buf[pos] == ' ') || (buf[pos] == ench))
289 strncpy(urlbuf, &buf[start], end - start);
290 urlbuf[end - start] = 0;
292 strncpy(outbuf, buf, start);
293 sprintf(&outbuf[start], "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
294 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
295 strcat(outbuf, &buf[end]);
296 if ( strlen(outbuf) < 250 )
302 * \brief Turn a vCard "n" (name) field into something displayable.
303 * \param name the name field to convert
305 void vcard_n_prettyize(char *name)
310 original_name = strdup(name);
311 for (i=0; i<5; ++i) {
312 if (strlen(original_name) > 0) {
313 if (original_name[strlen(original_name)-1] == ' ') {
314 original_name[strlen(original_name)-1] = 0;
316 if (original_name[strlen(original_name)-1] == ';') {
317 original_name[strlen(original_name)-1] = 0;
322 for (i=0; i<strlen(original_name); ++i) {
323 if (original_name[i] == ';') {
327 name[strlen(name)+1] = 0;
328 name[strlen(name)] = original_name[i];
338 * \brief preparse a vcard name
339 * display_vcard() calls this after parsing the textual vCard into
340 * our 'struct vCard' data object.
341 * This gets called instead of display_parsed_vcard() if we are only looking
342 * to extract the person's name instead of displaying the card.
343 * \param v the vcard to retrieve the name from
344 * \param storename where to put the name at
346 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
349 strcpy(storename, "");
351 name = vcard_get_prop(v, "n", 1, 0, 0);
353 strcpy(storename, name);
354 /* vcard_n_prettyize(storename); */
362 * \brief html print a vcard
363 * display_vcard() calls this after parsing the textual vCard into
364 * our 'struct vCard' data object.
366 * Set 'full' to nonzero to display the full card, otherwise it will only
367 * show a summary line.
369 * This code is a bit ugly, so perhaps an explanation is due: we do this
370 * in two passes through the vCard fields. On the first pass, we process
371 * fields we understand, and then render them in a pretty fashion at the
372 * end. Then we make a second pass, outputting all the fields we don't
373 * understand in a simple two-column name/value format.
374 * \param v the vCard to display
375 * \param full display all items of the vcard?
377 void display_parsed_vcard(struct vCard *v, int full) {
383 char *thisname, *thisvalue;
384 char firsttoken[SIZ];
393 strcpy(fullname, "");
401 name = vcard_get_prop(v, "fn", 1, 0, 0);
405 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
406 strcpy(fullname, name);
407 vcard_n_prettyize(fullname);
417 wprintf("<div align=center><table bgcolor=#aaaaaa width=50%%>");
418 for (pass=1; pass<=2; ++pass) {
420 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
422 thisname = strdup(v->prop[i].name);
423 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
425 for (j=0; j<num_tokens(thisname, ';'); ++j) {
426 extract_token(buf, thisname, j, ';', sizeof buf);
427 if (!strcasecmp(buf, "encoding=quoted-printable")) {
429 remove_token(thisname, j, ';');
431 if (!strcasecmp(buf, "encoding=base64")) {
433 remove_token(thisname, j, ';');
438 thisvalue = malloc(strlen(v->prop[i].value) + 50);
439 j = CtdlDecodeQuotedPrintable(
440 thisvalue, v->prop[i].value,
441 strlen(v->prop[i].value) );
445 thisvalue = malloc(strlen(v->prop[i].value) + 50);
447 thisvalue, v->prop[i].value,
448 strlen(v->prop[i].value) );
451 thisvalue = strdup(v->prop[i].value);
454 /** Various fields we may encounter ***/
456 /** N is name, but only if there's no FN already there */
457 if (!strcasecmp(firsttoken, "n")) {
458 if (strlen(fullname) == 0) {
459 strcpy(fullname, thisvalue);
460 vcard_n_prettyize(fullname);
464 /** FN (full name) is a true 'display name' field */
465 else if (!strcasecmp(firsttoken, "fn")) {
466 strcpy(fullname, thisvalue);
470 else if (!strcasecmp(firsttoken, "title")) {
471 strcpy(title, thisvalue);
475 else if (!strcasecmp(firsttoken, "org")) {
476 strcpy(org, thisvalue);
479 else if (!strcasecmp(firsttoken, "email")) {
480 if (strlen(mailto) > 0) strcat(mailto, "<br />");
482 "<a href=\"display_enter"
483 "?force_room=_MAIL_?recp=");
485 urlesc(&mailto[strlen(mailto)], fullname);
486 urlesc(&mailto[strlen(mailto)], " <");
487 urlesc(&mailto[strlen(mailto)], thisvalue);
488 urlesc(&mailto[strlen(mailto)], ">");
490 strcat(mailto, "\">");
491 stresc(&mailto[strlen(mailto)], thisvalue, 1, 1);
492 strcat(mailto, "</A>");
494 else if (!strcasecmp(firsttoken, "tel")) {
495 if (strlen(phone) > 0) strcat(phone, "<br />");
496 strcat(phone, thisvalue);
497 for (j=0; j<num_tokens(thisname, ';'); ++j) {
498 extract_token(buf, thisname, j, ';', sizeof buf);
499 if (!strcasecmp(buf, "tel"))
501 else if (!strcasecmp(buf, "work"))
502 strcat(phone, _(" (work)"));
503 else if (!strcasecmp(buf, "home"))
504 strcat(phone, _(" (home)"));
505 else if (!strcasecmp(buf, "cell"))
506 strcat(phone, _(" (cell)"));
514 else if (!strcasecmp(firsttoken, "adr")) {
517 wprintf(_("Address:"));
518 wprintf("</TD><TD>");
519 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
520 extract_token(buf, thisvalue, j, ';', sizeof buf);
521 if (strlen(buf) > 0) {
523 if (j<3) wprintf("<br />");
527 wprintf("</TD></TR>\n");
530 else if (!strcasecmp(firsttoken, "version")) {
533 else if (!strcasecmp(firsttoken, "rev")) {
536 else if (!strcasecmp(firsttoken, "label")) {
541 /*** Don't show extra fields. They're ugly.
545 wprintf("</TD><TD>");
547 wprintf("</TD></TR>\n");
557 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
558 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
559 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
560 "<FONT SIZE=+1><B>");
562 wprintf("</B></FONT>");
563 if (strlen(title) > 0) {
564 wprintf("<div align=right>");
568 if (strlen(org) > 0) {
569 wprintf("<div align=right>");
573 wprintf("</TD></TR>\n");
575 if (strlen(phone) > 0) {
577 wprintf(_("Telephone:"));
578 wprintf("</td><td>%s</td></tr>\n", phone);
580 if (strlen(mailto) > 0) {
582 wprintf(_("E-mail:"));
583 wprintf("</td><td>%s</td></tr>\n", mailto);
589 wprintf("</table></div>\n");
595 * \brief Display a textual vCard
596 * (Converts to a vCard object and then calls the actual display function)
597 * Set 'full' to nonzero to display the whole card instead of a one-liner.
598 * Or, if "storename" is non-NULL, just store the person's name in that
599 * buffer instead of displaying the card at all.
600 * \param vcard_source the buffer containing the vcard text
601 * \param alpha what???
602 * \param full should we usse all lines?
603 * \param storename where to store???
605 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
611 v = vcard_load(vcard_source);
612 if (v == NULL) return;
614 name = vcard_get_prop(v, "n", 1, 0, 0);
620 if (storename != NULL) {
621 fetchname_parsed_vcard(v, storename);
623 else if ( (alpha == 0)
624 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
625 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
627 display_parsed_vcard(v, full);
641 * \brief I wanna SEE that message!
642 * \param msgnum the citadel number of the message to display
643 * \param printable_view are we doing a print view?
644 * \param section Optional for encapsulated message/rfc822 submessage)
646 void read_message(long msgnum, int printable_view, char *section) {
648 char mime_partnum[256];
649 char mime_filename[256];
650 char mime_content_type[256];
651 char mime_charset[256];
652 char mime_disposition[256];
654 struct attach_link *attach_links = NULL;
655 int num_attach_links = 0;
656 char mime_submessages[256];
663 char reply_all[4096];
669 char vcard_partnum[256];
670 char cal_partnum[256];
671 char *part_source = NULL;
672 char msg4_partnum[32];
674 iconv_t ic = (iconv_t)(-1) ;
675 char *ibuf; /**< Buffer of characters to be converted */
676 char *obuf; /**< Buffer for converted characters */
677 size_t ibuflen; /**< Length of input buffer */
678 size_t obuflen; /**< Length of output buffer */
679 char *osav; /**< Saved pointer to output buffer */
685 strcpy(reply_to, "");
686 strcpy(reply_all, "");
687 strcpy(vcard_partnum, "");
688 strcpy(cal_partnum, "");
689 strcpy(mime_content_type, "text/plain");
690 strcpy(mime_charset, "us-ascii");
691 strcpy(mime_submessages, "");
693 serv_printf("MSG4 %ld|%s", msgnum, section);
694 serv_getln(buf, sizeof buf);
697 wprintf(_("ERROR:"));
698 wprintf("</STRONG> %s<br />\n", &buf[4]);
702 /** begin everythingamundo table */
703 if (!printable_view) {
704 wprintf("<div class=\"fix_scrollbar_bug\">\n");
705 wprintf("<table width=100%% border=1 cellspacing=0 "
706 "cellpadding=0><TR><TD>\n");
709 /** begin message header table */
710 wprintf("<table width=100%% border=0 cellspacing=0 "
711 "cellpadding=1 bgcolor=\"#CCCCCC\"><tr><td>\n");
713 wprintf("<span class=\"message_header\">");
714 strcpy(m_subject, "");
717 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
718 if (!strcmp(buf, "000")) {
720 wprintf(_("unexpected end of message"));
721 wprintf("</i><br /><br />\n");
722 wprintf("</span>\n");
725 if (!strncasecmp(buf, "nhdr=yes", 8))
729 if (!strncasecmp(buf, "type=", 5))
730 format_type = atoi(&buf[5]);
731 if (!strncasecmp(buf, "from=", 5)) {
732 strcpy(from, &buf[5]);
734 wprintf("<a href=\"showuser?who=");
736 utf8ify_rfc822_string(from);
743 if (!strncasecmp(buf, "subj=", 5)) {
744 safestrncpy(m_subject, &buf[5], sizeof m_subject);
746 if (!strncasecmp(buf, "cccc=", 5)) {
747 safestrncpy(m_cc, &buf[5], sizeof m_cc);
748 if (strlen(reply_all) > 0) {
749 strcat(reply_all, ", ");
751 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
752 (sizeof reply_all - strlen(reply_all)) );
754 if ((!strncasecmp(buf, "hnod=", 5))
755 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
756 wprintf("(%s) ", &buf[5]);
758 if ((!strncasecmp(buf, "room=", 5))
759 && (strcasecmp(&buf[5], WC->wc_roomname))
760 && (strlen(&buf[5])>0) ) {
762 wprintf("%s> ", &buf[5]);
764 if (!strncasecmp(buf, "rfca=", 5)) {
765 strcpy(rfca, &buf[5]);
771 if (!strncasecmp(buf, "node=", 5)) {
772 strcpy(node, &buf[5]);
773 if ( ((WC->room_flags & QR_NETWORK)
774 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
775 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
778 wprintf("@%s ", &buf[5]);
781 if (!strncasecmp(buf, "rcpt=", 5)) {
783 if (strlen(reply_all) > 0) {
784 strcat(reply_all, ", ");
786 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
787 (sizeof reply_all - strlen(reply_all)) );
789 utf8ify_rfc822_string(&buf[5]);
794 if (!strncasecmp(buf, "time=", 5)) {
795 fmt_date(now, atol(&buf[5]), 0);
799 if (!strncasecmp(buf, "part=", 5)) {
800 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
801 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
802 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
803 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
804 mime_length = extract_int(&buf[5], 5);
806 if (!strcasecmp(mime_content_type, "message/rfc822")) {
807 if (strlen(mime_submessages) > 0) {
808 strcat(mime_submessages, "|");
810 strcat(mime_submessages, mime_partnum);
812 else if ((!strcasecmp(mime_disposition, "inline"))
813 && (!strncasecmp(mime_content_type, "image/", 6)) ){
815 attach_links = realloc(attach_links,
816 (num_attach_links*sizeof(struct attach_link)));
817 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
818 snprintf(attach_links[num_attach_links-1].html, 1024,
819 "<img src=\"mimepart/%ld/%s/%s\">",
820 msgnum, mime_partnum, mime_filename);
822 else if ( (!strcasecmp(mime_disposition, "attachment"))
823 || (!strcasecmp(mime_disposition, "inline"))
824 || (!strcasecmp(mime_disposition, ""))
827 attach_links = realloc(attach_links,
828 (num_attach_links*sizeof(struct attach_link)));
829 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
830 snprintf(attach_links[num_attach_links-1].html, 1024,
831 "<img src=\"static/diskette_24x.gif\" "
832 "border=0 align=middle>\n"
833 "%s (%s, %d bytes) [ "
834 "<a href=\"mimepart/%ld/%s/%s\""
835 "target=\"wc.%ld.%s\">%s</a>"
837 "<a href=\"mimepart_download/%ld/%s/%s\">%s</a>"
840 mime_content_type, mime_length,
841 msgnum, mime_partnum, mime_filename,
842 msgnum, mime_partnum,
844 msgnum, mime_partnum, mime_filename,
849 /** begin handler prep ***/
850 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
851 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
852 strcpy(vcard_partnum, mime_partnum);
855 if (!strcasecmp(mime_content_type, "text/calendar")) {
856 strcpy(cal_partnum, mime_partnum);
859 /** end handler prep ***/
865 /** Generate a reply-to address */
866 if (strlen(rfca) > 0) {
867 if (strlen(from) > 0) {
868 snprintf(reply_to, sizeof(reply_to), "%s <%s>", from, rfca);
871 strcpy(reply_to, rfca);
875 if ( (strlen(node) > 0)
876 && (strcasecmp(node, serv_info.serv_nodename))
877 && (strcasecmp(node, serv_info.serv_humannode)) ) {
878 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
882 snprintf(reply_to, sizeof(reply_to), "%s", from);
892 utf8ify_rfc822_string(m_cc);
893 utf8ify_rfc822_string(m_subject);
895 if (strlen(m_cc) > 0) {
897 "<span class=\"message_subject\">");
903 if (strlen(m_subject) > 0) {
905 "<span class=\"message_subject\">");
906 wprintf(_("Subject:"));
913 /** start msg buttons */
914 if (!printable_view) {
915 wprintf("<td align=right><span class=\"msgbuttons\">\n");
918 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
919 wprintf("<a href=\"display_enter");
920 if (WC->is_mailbox) {
921 wprintf("?replyquote=%ld", msgnum);
924 urlescputs(reply_to);
925 if (strlen(m_subject) > 0) {
926 wprintf("?subject=");
927 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
928 urlescputs(m_subject);
930 wprintf("\">[%s]</a> ", _("Reply"));
934 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
935 if (!WC->is_mailbox) {
936 wprintf("<a href=\"display_enter");
937 wprintf("?replyquote=%ld", msgnum);
939 urlescputs(reply_to);
940 if (strlen(m_subject) > 0) {
941 wprintf("?subject=");
942 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
943 urlescputs(m_subject);
945 wprintf("\">[%s]</a> ", _("ReplyQuoted"));
950 if (WC->wc_view == VIEW_MAILBOX) {
951 wprintf("<a href=\"display_enter");
952 wprintf("?replyquote=%ld", msgnum);
954 urlescputs(reply_to);
956 urlescputs(reply_all);
957 if (strlen(m_subject) > 0) {
958 wprintf("?subject=");
959 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
960 urlescputs(m_subject);
962 wprintf("\">[%s]</a> ", _("ReplyAll"));
966 if (WC->wc_view == VIEW_MAILBOX) {
967 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
968 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
969 urlescputs(m_subject);
970 wprintf("\">[%s]</a> ", _("Forward"));
973 /** If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
974 if ( (WC->is_room_aide) || (WC->is_mailbox) ) {
976 wprintf("<a href=\"confirm_move_msg?msgid=%ld\">[%s]</a> ",
980 wprintf("<a href=\"delete_msg?msgid=%ld\" "
981 "onClick=\"return confirm('%s');\">"
982 "[%s]</a> ", msgnum, _("Delete this message?"), _("Delete")
987 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'); \" >"
988 "[%s]</a>", msgnum, msgnum, _("Headers"));
992 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'); \" >"
993 "[%s]</a>", msgnum, msgnum, _("Print"));
995 wprintf("</span></td>");
998 wprintf("</tr></table>\n");
1001 wprintf("<table class=\"messages_background\" "
1002 "cellpadding=1 cellspacing=0><tr><td>");
1005 * Learn the content type
1007 strcpy(mime_content_type, "text/plain");
1008 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1009 if (!strcmp(buf, "000")) {
1011 wprintf(_("unexpected end of message"));
1012 wprintf("</i><br /><br />\n");
1015 if (!strncasecmp(buf, "X-Citadel-MSG4-Partnum:", 23)) {
1016 safestrncpy(msg4_partnum, &buf[23], sizeof(msg4_partnum));
1017 striplt(msg4_partnum);
1019 if (!strncasecmp(buf, "Content-type:", 13)) {
1020 safestrncpy(mime_content_type, &buf[13], sizeof(mime_content_type));
1021 striplt(mime_content_type);
1022 for (i=0; i<strlen(mime_content_type); ++i) {
1023 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1024 safestrncpy(mime_charset, &mime_content_type[i+8],
1025 sizeof mime_charset);
1028 for (i=0; i<strlen(mime_content_type); ++i) {
1029 if (mime_content_type[i] == ';') {
1030 mime_content_type[i] = 0;
1033 for (i=0; i<strlen(mime_charset); ++i) {
1034 if (mime_charset[i] == ';') {
1035 mime_charset[i] = 0;
1041 /** Set up a character set conversion if we need to (and if we can) */
1043 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
1044 if ( (strcasecmp(mime_charset, "us-ascii"))
1045 && (strcasecmp(mime_charset, "UTF-8"))
1046 && (strcasecmp(mime_charset, ""))
1048 ic = ctdl_iconv_open("UTF-8", mime_charset);
1049 if (ic == (iconv_t)(-1) ) {
1050 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1051 __FILE__, __LINE__, mime_charset, strerror(errno));
1056 /** Messages in legacy Citadel variformat get handled thusly... */
1057 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1061 /** Boring old 80-column fixed format text gets handled this way... */
1062 else if ( (!strcasecmp(mime_content_type, "text/plain"))
1063 || (!strcasecmp(mime_content_type, "text")) ) {
1064 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1065 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1066 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1069 if (ic != (iconv_t)(-1) ) {
1071 ibuflen = strlen(ibuf);
1073 obuf = (char *) malloc(obuflen);
1075 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1076 osav[SIZ-obuflen] = 0;
1077 safestrncpy(buf, osav, sizeof buf);
1082 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1083 buf[strlen(buf) - 1] = 0;
1085 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1086 wprintf("<blockquote>");
1088 } else if ((bq == 1) &&
1089 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1090 wprintf("</blockquote>");
1096 wprintf("</tt><br />\n");
1098 wprintf("</i><br />");
1101 else /** HTML is fun, but we've got to strip it first */
1102 if (!strcasecmp(mime_content_type, "text/html")) {
1103 output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
1106 /** Unknown weirdness */
1108 wprintf(_("I don't know how to display %s"), mime_content_type);
1109 wprintf("<br />\n", mime_content_type);
1110 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1113 /** If there are attached submessages, display them now... */
1114 if ( (strlen(mime_submessages) > 0) && (!section[0]) ) {
1115 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1116 extract_token(buf, mime_submessages, i, '|', sizeof buf);
1117 /** use printable_view to suppress buttons */
1118 wprintf("<blockquote>");
1119 read_message(msgnum, 1, buf);
1120 wprintf("</blockquote>");
1125 /** Afterwards, offer links to download attachments 'n' such */
1126 if ( (num_attach_links > 0) && (!section[0]) ) {
1127 for (i=0; i<num_attach_links; ++i) {
1128 if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
1129 wprintf("%s", attach_links[i].html);
1134 /** Handler for vCard parts */
1135 if (strlen(vcard_partnum) > 0) {
1136 part_source = load_mimepart(msgnum, vcard_partnum);
1137 if (part_source != NULL) {
1139 /** If it's my vCard I can edit it */
1140 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1141 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1142 || (WC->wc_view == VIEW_ADDRESSBOOK)
1144 wprintf("<a href=\"edit_vcard?"
1145 "msgnum=%ld?partnum=%s\">",
1146 msgnum, vcard_partnum);
1147 wprintf("[%s]</a>", _("edit"));
1150 /** In all cases, display the full card */
1151 display_vcard(part_source, 0, 1, NULL);
1155 /** Handler for calendar parts */
1156 if (strlen(cal_partnum) > 0) {
1157 part_source = load_mimepart(msgnum, cal_partnum);
1158 if (part_source != NULL) {
1159 cal_process_attachment(part_source,
1160 msgnum, cal_partnum);
1170 wprintf("</td></tr></table>\n");
1172 /** end everythingamundo table */
1173 if (!printable_view) {
1174 wprintf("</td></tr></table>\n");
1175 wprintf("</div><br />\n");
1178 if (num_attach_links > 0) {
1183 if (ic != (iconv_t)(-1) ) {
1192 * \brief Unadorned HTML output of an individual message, suitable
1193 * for placing in a hidden iframe, for printing, or whatever
1195 * \param msgnum_as_string Message number, as a string instead of as a long int
1197 void embed_message(char *msgnum_as_string) {
1200 msgnum = atol(msgnum_as_string);
1201 begin_ajax_response();
1202 read_message(msgnum, 0, "");
1203 end_ajax_response();
1208 * \brief Printable view of a message
1210 * \param msgnum_as_string Message number, as a string instead of as a long int
1212 void print_message(char *msgnum_as_string) {
1215 msgnum = atol(msgnum_as_string);
1216 output_headers(0, 0, 0, 0, 0, 0);
1218 wprintf("Content-type: text/html\r\n"
1220 "Connection: close\r\n",
1224 wprintf("\r\n\r\n<html>\n"
1225 "<head><title>Printable view</title></head>\n"
1226 "<body onLoad=\" window.print(); window.close(); \">\n"
1229 read_message(msgnum, 1, "");
1231 wprintf("\n</body></html>\n\n");
1238 * \brief Display a message's headers
1240 * \param msgnum_as_string Message number, as a string instead of as a long int
1242 void display_headers(char *msgnum_as_string) {
1246 msgnum = atol(msgnum_as_string);
1247 output_headers(0, 0, 0, 0, 0, 0);
1249 wprintf("Content-type: text/plain\r\n"
1251 "Connection: close\r\n",
1255 serv_printf("MSG2 %ld|3", msgnum);
1256 serv_getln(buf, sizeof buf);
1257 if (buf[0] == '1') {
1258 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1259 wprintf("%s\n", buf);
1269 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1270 * or 'reply quoted' operations.
1272 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1273 * in this function. Doing so would throw a JavaScript error in the
1274 * 'supplied text' argument to the editor.
1276 * \param msgnum Message number of the message we want to quote
1277 * \param forward_attachments Nonzero if we want attachments to be forwarded
1279 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1281 char mime_partnum[256];
1282 char mime_filename[256];
1283 char mime_content_type[256];
1284 char mime_charset[256];
1285 char mime_disposition[256];
1287 char *attachments = NULL;
1289 int num_attachments = 0;
1290 struct wc_attachment *att, *aptr;
1291 char m_subject[256];
1297 int format_type = 0;
1302 iconv_t ic = (iconv_t)(-1) ;
1303 char *ibuf; /**< Buffer of characters to be converted */
1304 char *obuf; /**< Buffer for converted characters */
1305 size_t ibuflen; /**< Length of input buffer */
1306 size_t obuflen; /**< Length of output buffer */
1307 char *osav; /**< Saved pointer to output buffer */
1313 strcpy(reply_to, "");
1314 strcpy(mime_content_type, "text/plain");
1315 strcpy(mime_charset, "us-ascii");
1317 serv_printf("MSG4 %ld", msgnum);
1318 serv_getln(buf, sizeof buf);
1319 if (buf[0] != '1') {
1320 wprintf(_("ERROR:"));
1321 wprintf("%s<br />", &buf[4]);
1325 strcpy(m_subject, "");
1327 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1328 if (!strcmp(buf, "000")) {
1329 wprintf(_("unexpected end of message"));
1332 if (include_headers) {
1333 if (!strncasecmp(buf, "nhdr=yes", 8))
1337 if (!strncasecmp(buf, "type=", 5))
1338 format_type = atoi(&buf[5]);
1339 if (!strncasecmp(buf, "from=", 5)) {
1340 strcpy(from, &buf[5]);
1341 wprintf(_("from "));
1343 utf8ify_rfc822_string(from);
1347 if (!strncasecmp(buf, "subj=", 5)) {
1348 strcpy(m_subject, &buf[5]);
1350 if ((!strncasecmp(buf, "hnod=", 5))
1351 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1352 wprintf("(%s) ", &buf[5]);
1354 if ((!strncasecmp(buf, "room=", 5))
1355 && (strcasecmp(&buf[5], WC->wc_roomname))
1356 && (strlen(&buf[5])>0) ) {
1358 wprintf("%s> ", &buf[5]);
1360 if (!strncasecmp(buf, "rfca=", 5)) {
1361 strcpy(rfca, &buf[5]);
1367 if (!strncasecmp(buf, "node=", 5)) {
1368 strcpy(node, &buf[5]);
1369 if ( ((WC->room_flags & QR_NETWORK)
1370 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1371 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1372 && (strlen(rfca)==0)
1374 wprintf("@%s ", &buf[5]);
1377 if (!strncasecmp(buf, "rcpt=", 5)) {
1379 wprintf("%s ", &buf[5]);
1381 if (!strncasecmp(buf, "time=", 5)) {
1382 fmt_date(now, atol(&buf[5]), 0);
1383 wprintf("%s ", now);
1388 * Save attachment info for later. We can't start downloading them
1389 * yet because we're in the middle of a server transaction.
1391 if (!strncasecmp(buf, "part=", 5)) {
1392 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1395 sprintf(ptr, "%s%s\n",
1396 ((attachments != NULL) ? attachments : ""),
1401 lprintf(9, "attachments=<%s>\n", attachments);
1407 if (include_headers) {
1411 utf8ify_rfc822_string(m_subject);
1413 if (strlen(m_subject) > 0) {
1414 wprintf(_("Subject:"));
1416 msgescputs(m_subject);
1427 * Learn the content type
1429 strcpy(mime_content_type, "text/plain");
1430 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1431 if (!strcmp(buf, "000")) {
1432 wprintf(_("unexpected end of message"));
1435 if (!strncasecmp(buf, "Content-type: ", 14)) {
1436 safestrncpy(mime_content_type, &buf[14],
1437 sizeof(mime_content_type));
1438 for (i=0; i<strlen(mime_content_type); ++i) {
1439 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1440 safestrncpy(mime_charset, &mime_content_type[i+8],
1441 sizeof mime_charset);
1444 for (i=0; i<strlen(mime_content_type); ++i) {
1445 if (mime_content_type[i] == ';') {
1446 mime_content_type[i] = 0;
1449 for (i=0; i<strlen(mime_charset); ++i) {
1450 if (mime_charset[i] == ';') {
1451 mime_charset[i] = 0;
1457 /** Set up a character set conversion if we need to (and if we can) */
1459 if ( (strcasecmp(mime_charset, "us-ascii"))
1460 && (strcasecmp(mime_charset, "UTF-8"))
1461 && (strcasecmp(mime_charset, ""))
1463 ic = ctdl_iconv_open("UTF-8", mime_charset);
1464 if (ic == (iconv_t)(-1) ) {
1465 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1466 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1471 /** Messages in legacy Citadel variformat get handled thusly... */
1472 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1476 /* Boring old 80-column fixed format text gets handled this way... */
1477 else if (!strcasecmp(mime_content_type, "text/plain")) {
1478 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1479 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1480 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1483 if (ic != (iconv_t)(-1) ) {
1485 ibuflen = strlen(ibuf);
1487 obuf = (char *) malloc(obuflen);
1489 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1490 osav[SIZ-obuflen] = 0;
1491 safestrncpy(buf, osav, sizeof buf);
1496 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1497 buf[strlen(buf) - 1] = 0;
1499 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1500 wprintf("<blockquote>");
1502 } else if ((bq == 1) &&
1503 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1504 wprintf("</blockquote>");
1510 wprintf("</tt><br />");
1512 wprintf("</i><br />");
1515 /** HTML just gets escaped and stuffed back into the editor */
1516 else if (!strcasecmp(mime_content_type, "text/html")) {
1517 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1523 /** Unknown weirdness ... don't know how to handle this content type */
1525 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1529 /** end of body handler */
1532 * If there were attachments, we have to download them and insert them
1533 * into the attachment chain for the forwarded message we are composing.
1535 if ( (forward_attachments) && (num_attachments) ) {
1536 for (i=0; i<num_attachments; ++i) {
1537 extract_token(buf, attachments, i, '\n', sizeof buf);
1538 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1539 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1540 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1541 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1542 mime_length = extract_int(buf, 5);
1545 * tracing ... uncomment if necessary
1548 lprintf(9, "fwd filename: %s\n", mime_filename);
1549 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1550 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1551 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1552 lprintf(9, "fwd length : %d\n", mime_length);
1554 if ( (!strcasecmp(mime_disposition, "inline"))
1555 || (!strcasecmp(mime_disposition, "attachment")) ) {
1557 /* Create an attachment struct from this mime part... */
1558 att = malloc(sizeof(struct wc_attachment));
1559 memset(att, 0, sizeof(struct wc_attachment));
1560 att->length = mime_length;
1561 strcpy(att->content_type, mime_content_type);
1562 strcpy(att->filename, mime_filename);
1564 att->data = load_mimepart(msgnum, mime_partnum);
1566 /* And add it to the list. */
1567 if (WC->first_attachment == NULL) {
1568 WC->first_attachment = att;
1571 aptr = WC->first_attachment;
1572 while (aptr->next != NULL) aptr = aptr->next;
1581 if (ic != (iconv_t)(-1) ) {
1586 if (attachments != NULL) {
1592 * \brief Display one row in the mailbox summary view
1594 * \param num The row number to be displayed
1596 void display_summarized(int num) {
1599 wprintf("<tr id=\"m%ld\" style=\"width:100%%;font-weight:%s;background-color:#ffffff\" "
1600 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1601 WC->summ[num].msgnum,
1602 (WC->summ[num].is_new ? "bold" : "normal"),
1603 WC->summ[num].msgnum
1606 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1607 escputs(WC->summ[num].subj);
1610 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1611 escputs(WC->summ[num].from);
1614 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1615 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1625 * \brief display the adressbook overview
1626 * \param msgnum the citadel message number
1627 * \param alpha what????
1629 void display_addressbook(long msgnum, char alpha) {
1631 char mime_partnum[SIZ];
1632 char mime_filename[SIZ];
1633 char mime_content_type[SIZ];
1634 char mime_disposition[SIZ];
1636 char vcard_partnum[SIZ];
1637 char *vcard_source = NULL;
1638 struct message_summary summ;
1640 memset(&summ, 0, sizeof(summ));
1641 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1643 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1645 serv_getln(buf, sizeof buf);
1646 if (buf[0] != '1') return;
1648 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1649 if (!strncasecmp(buf, "part=", 5)) {
1650 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1651 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1652 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1653 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1654 mime_length = extract_int(&buf[5], 5);
1656 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1657 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1658 strcpy(vcard_partnum, mime_partnum);
1664 if (strlen(vcard_partnum) > 0) {
1665 vcard_source = load_mimepart(msgnum, vcard_partnum);
1666 if (vcard_source != NULL) {
1668 /** Display the summary line */
1669 display_vcard(vcard_source, alpha, 0, NULL);
1671 /** If it's my vCard I can edit it */
1672 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1673 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1674 || (WC->wc_view == VIEW_ADDRESSBOOK)
1676 wprintf("<a href=\"edit_vcard?"
1677 "msgnum=%ld?partnum=%s\">",
1678 msgnum, vcard_partnum);
1679 wprintf("[%s]</a>", _("edit"));
1691 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1692 * \param namebuf name to analyze, reverse if nescessary
1694 void lastfirst_firstlast(char *namebuf) {
1695 char firstname[SIZ];
1699 if (namebuf == NULL) return;
1700 if (strchr(namebuf, ';') != NULL) return;
1702 i = num_tokens(namebuf, ' ');
1705 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1706 remove_token(namebuf, i-1, ' ');
1707 strcpy(firstname, namebuf);
1708 sprintf(namebuf, "%s; %s", lastname, firstname);
1712 * \brief fetch what??? name
1713 * \param msgnum the citadel message number
1714 * \param namebuf where to put the name in???
1716 void fetch_ab_name(long msgnum, char *namebuf) {
1718 char mime_partnum[SIZ];
1719 char mime_filename[SIZ];
1720 char mime_content_type[SIZ];
1721 char mime_disposition[SIZ];
1723 char vcard_partnum[SIZ];
1724 char *vcard_source = NULL;
1726 struct message_summary summ;
1728 if (namebuf == NULL) return;
1729 strcpy(namebuf, "");
1731 memset(&summ, 0, sizeof(summ));
1732 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1734 sprintf(buf, "MSG0 %ld|0", msgnum); /** unfortunately we need the mime info now */
1736 serv_getln(buf, sizeof buf);
1737 if (buf[0] != '1') return;
1739 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1740 if (!strncasecmp(buf, "part=", 5)) {
1741 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1742 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1743 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1744 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1745 mime_length = extract_int(&buf[5], 5);
1747 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1748 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1749 strcpy(vcard_partnum, mime_partnum);
1755 if (strlen(vcard_partnum) > 0) {
1756 vcard_source = load_mimepart(msgnum, vcard_partnum);
1757 if (vcard_source != NULL) {
1759 /* Grab the name off the card */
1760 display_vcard(vcard_source, 0, 0, namebuf);
1766 lastfirst_firstlast(namebuf);
1768 for (i=0; i<strlen(namebuf); ++i) {
1769 if (namebuf[i] != ';') return;
1771 strcpy(namebuf, _("(no name)"));
1777 * \brief Record compare function for sorting address book indices
1778 * \param ab1 adressbook one
1779 * \param ab2 adressbook two
1781 int abcmp(const void *ab1, const void *ab2) {
1783 (((const struct addrbookent *)ab1)->ab_name),
1784 (((const struct addrbookent *)ab2)->ab_name)
1790 * \brief Helper function for do_addrbook_view()
1791 * Converts a name into a three-letter tab label
1792 * \param tabbuf the tabbuffer to add name to
1793 * \param name the name to add to the tabbuffer
1795 void nametab(char *tabbuf, char *name) {
1796 stresc(tabbuf, name, 0, 0);
1797 tabbuf[0] = toupper(tabbuf[0]);
1798 tabbuf[1] = tolower(tabbuf[1]);
1799 tabbuf[2] = tolower(tabbuf[2]);
1805 * \brief Render the address book using info we gathered during the scan
1806 * \param addrbook the addressbook to render
1807 * \param num_ab the number of the addressbook
1809 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1813 static int NAMESPERPAGE = 60;
1817 char tabfirst_label[SIZ];
1819 char tablast_label[SIZ];
1822 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1823 wprintf(_("This address book is empty."));
1824 wprintf("</i></div>\n");
1829 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1832 num_pages = num_ab / NAMESPERPAGE;
1834 page = atoi(bstr("page"));
1837 for (i=0; i<=num_pages; ++i) {
1839 wprintf("<a href=\"readfwd?page=%d\">", i);
1844 tabfirst = i * NAMESPERPAGE;
1845 tablast = tabfirst + NAMESPERPAGE - 1;
1846 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1847 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1848 nametab(tablast_label, addrbook[tablast].ab_name);
1849 wprintf("[%s - %s]",
1850 tabfirst_label, tablast_label
1859 wprintf("<br />\n");
1861 wprintf("<table border=0 cellspacing=0 "
1862 "cellpadding=3 width=100%%>\n"
1865 for (i=0; i<num_ab; ++i) {
1867 if ((i / NAMESPERPAGE) == page) {
1869 if ((displayed % 4) == 0) {
1870 if (displayed > 0) {
1874 wprintf("<tr bgcolor=\"#%s\">",
1875 (bg ? "DDDDDD" : "FFFFFF")
1881 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
1882 addrbook[i].ab_msgnum);
1883 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1884 vcard_n_prettyize(addrbook[i].ab_name);
1885 escputs(addrbook[i].ab_name);
1886 wprintf("</a></td>\n");
1891 wprintf("</tr></table>\n");
1897 * \brief load message pointers from the server
1898 * \param servcmd the citadel command to send to the citserver
1899 * \param with_headers what headers???
1901 int load_msg_ptrs(char *servcmd, int with_headers)
1912 int num_summ_alloc = 0;
1914 if (WC->summ != NULL) {
1919 num_summ_alloc = 100;
1921 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1924 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1926 serv_getln(buf, sizeof buf);
1927 if (buf[0] != '1') {
1930 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1931 if (nummsgs < maxload) {
1932 WC->msgarr[nummsgs] = extract_long(buf, 0);
1933 datestamp = extract_long(buf, 1);
1934 extract_token(fullname, buf, 2, '|', sizeof fullname);
1935 extract_token(nodename, buf, 3, '|', sizeof nodename);
1936 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1937 extract_token(subject, buf, 5, '|', sizeof subject);
1941 if (nummsgs > num_summ_alloc) {
1942 num_summ_alloc *= 2;
1943 WC->summ = realloc(WC->summ,
1944 num_summ_alloc * sizeof(struct message_summary));
1948 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1949 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1950 safestrncpy(WC->summ[nummsgs-1].subj,
1951 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1952 if (strlen(fullname) > 0) {
1953 safestrncpy(WC->summ[nummsgs-1].from,
1954 fullname, sizeof WC->summ[nummsgs-1].from);
1956 if (strlen(subject) > 0) {
1957 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1958 sizeof WC->summ[nummsgs-1].subj);
1961 /** Handle subjects with RFC2047 encoding */
1962 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1964 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1965 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1968 if (strlen(nodename) > 0) {
1969 if ( ((WC->room_flags & QR_NETWORK)
1970 || ((strcasecmp(nodename, serv_info.serv_nodename)
1971 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1973 strcat(WC->summ[nummsgs-1].from, " @ ");
1974 strcat(WC->summ[nummsgs-1].from, nodename);
1978 WC->summ[nummsgs-1].date = datestamp;
1981 /** Handle senders with RFC2047 encoding */
1982 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1984 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1985 strcpy(&WC->summ[nummsgs-1].from[22], "...");
1994 * \brief qsort() compatible function to compare two longs in descending order.
1996 * \param s1 first number to compare
1997 * \param s2 second number to compare
1999 int longcmp_r(const void *s1, const void *s2) {
2006 if (l1 > l2) return(-1);
2007 if (l1 < l2) return(+1);
2013 * \brief qsort() compatible function to compare two message summary structs by ascending subject.
2015 * \param s1 first item to compare
2016 * \param s2 second item to compare
2018 int summcmp_subj(const void *s1, const void *s2) {
2019 struct message_summary *summ1;
2020 struct message_summary *summ2;
2022 summ1 = (struct message_summary *)s1;
2023 summ2 = (struct message_summary *)s2;
2024 return strcasecmp(summ1->subj, summ2->subj);
2028 * \brief qsort() compatible function to compare two message summary structs by descending subject.
2030 * \param s1 first item to compare
2031 * \param s2 second item to compare
2033 int summcmp_rsubj(const void *s1, const void *s2) {
2034 struct message_summary *summ1;
2035 struct message_summary *summ2;
2037 summ1 = (struct message_summary *)s1;
2038 summ2 = (struct message_summary *)s2;
2039 return strcasecmp(summ2->subj, summ1->subj);
2043 * \brief qsort() compatible function to compare two message summary structs by ascending sender.
2045 * \param s1 first item to compare
2046 * \param s2 second item to compare
2048 int summcmp_sender(const void *s1, const void *s2) {
2049 struct message_summary *summ1;
2050 struct message_summary *summ2;
2052 summ1 = (struct message_summary *)s1;
2053 summ2 = (struct message_summary *)s2;
2054 return strcasecmp(summ1->from, summ2->from);
2058 * \brief qsort() compatible function to compare two message summary structs by descending sender.
2060 * \param s1 first item to compare
2061 * \param s2 second item to compare
2063 int summcmp_rsender(const void *s1, const void *s2) {
2064 struct message_summary *summ1;
2065 struct message_summary *summ2;
2067 summ1 = (struct message_summary *)s1;
2068 summ2 = (struct message_summary *)s2;
2069 return strcasecmp(summ2->from, summ1->from);
2073 * \brief qsort() compatible function to compare two message summary structs by ascending date.
2075 * \param s1 first item to compare
2076 * \param s2 second item to compare
2078 int summcmp_date(const void *s1, const void *s2) {
2079 struct message_summary *summ1;
2080 struct message_summary *summ2;
2082 summ1 = (struct message_summary *)s1;
2083 summ2 = (struct message_summary *)s2;
2085 if (summ1->date < summ2->date) return -1;
2086 else if (summ1->date > summ2->date) return +1;
2091 * \brief qsort() compatible function to compare two message summary structs by descending date.
2093 * \param s1 first item to compare
2094 * \param s2 second item to compare
2096 int summcmp_rdate(const void *s1, const void *s2) {
2097 struct message_summary *summ1;
2098 struct message_summary *summ2;
2100 summ1 = (struct message_summary *)s1;
2101 summ2 = (struct message_summary *)s2;
2103 if (summ1->date < summ2->date) return +1;
2104 else if (summ1->date > summ2->date) return -1;
2111 * \brief command loop for reading messages
2113 * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
2115 void readloop(char *oper)
2124 long *displayed_msgs = NULL;
2125 int num_displayed = 0;
2127 int is_addressbook = 0;
2128 int is_singlecard = 0;
2129 int is_calendar = 0;
2134 int lowest_displayed = (-1);
2135 int highest_displayed = 0;
2136 struct addrbookent *addrbook = NULL;
2138 char *sortby = NULL;
2139 char sortpref_name[128];
2140 char sortpref_value[128];
2141 char *subjsort_button;
2142 char *sendsort_button;
2143 char *datesort_button;
2144 int bbs_reverse = 0;
2146 if (WC->wc_view == VIEW_WIKI) {
2147 sprintf(buf, "wiki?room=%s?page=home", WC->wc_roomname);
2152 startmsg = atol(bstr("startmsg"));
2153 maxmsgs = atoi(bstr("maxmsgs"));
2154 is_summary = atoi(bstr("summary"));
2155 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2157 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
2158 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
2160 sortby = bstr("sortby");
2161 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
2162 set_preference(sortpref_name, sortby, 1);
2164 if (strlen(sortby) == 0) sortby = sortpref_value;
2167 if (strlen(sortby) == 0) sortby = "rdate";
2169 /** message board sort */
2170 if (!strcasecmp(sortby, "reverse")) {
2177 output_headers(1, 1, 1, 0, 0, 0);
2180 * When in summary mode, always show ALL messages instead of just
2181 * new or old. Otherwise, show what the user asked for.
2183 if (!strcmp(oper, "readnew")) {
2184 strcpy(cmd, "MSGS NEW");
2186 else if (!strcmp(oper, "readold")) {
2187 strcpy(cmd, "MSGS OLD");
2189 else if (!strcmp(oper, "do_search")) {
2190 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2193 strcpy(cmd, "MSGS ALL");
2196 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
2198 if (!strcmp(oper, "do_search")) {
2199 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2202 strcpy(cmd, "MSGS ALL");
2206 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2208 if (!strcmp(oper, "do_search")) {
2209 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2212 strcpy(cmd, "MSGS ALL");
2217 if (is_summary) { /**< fetch header summary */
2218 snprintf(cmd, sizeof cmd, "MSGS %s|%s||1",
2219 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2220 (!strcmp(oper, "do_search") ? bstr("query") : "")
2227 * Are we doing a summary view? If so, we need to know old messages
2228 * and new messages, so we can do that pretty boldface thing for the
2231 strcpy(old_msgs, "");
2234 serv_getln(buf, sizeof buf);
2235 if (buf[0] == '2') {
2236 strcpy(old_msgs, &buf[4]);
2240 is_singlecard = atoi(bstr("is_singlecard"));
2242 if (WC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2244 strcpy(cmd, "MSGS ALL");
2247 if (WC->wc_default_view == VIEW_TASKS) { /**< tasks */
2249 strcpy(cmd, "MSGS ALL");
2252 if (WC->wc_default_view == VIEW_NOTES) { /**< notes */
2254 strcpy(cmd, "MSGS ALL");
2259 wprintf("<div align=center>%s</div>\n", _("Click on any note to edit it."));
2260 wprintf("<div id=\"new_notes_here\"></div>\n");
2263 nummsgs = load_msg_ptrs(cmd, is_summary);
2266 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2267 wprintf("<div align=\"center\"><br /><em>");
2268 if (!strcmp(oper, "readnew")) {
2269 wprintf(_("No new messages."));
2270 } else if (!strcmp(oper, "readold")) {
2271 wprintf(_("No old messages."));
2273 wprintf(_("No messages here."));
2275 wprintf("</em><br /></div>\n");
2282 for (a = 0; a < nummsgs; ++a) {
2283 /** Are you a new message, or an old message? */
2285 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
2286 WC->summ[a].is_new = 0;
2289 WC->summ[a].is_new = 1;
2295 if (startmsg == 0L) {
2297 startmsg = WC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2300 startmsg = WC->msgarr[0];
2305 if (!strcasecmp(sortby, "subject")) {
2306 qsort(WC->summ, WC->num_summ,
2307 sizeof(struct message_summary), summcmp_subj);
2309 else if (!strcasecmp(sortby, "rsubject")) {
2310 qsort(WC->summ, WC->num_summ,
2311 sizeof(struct message_summary), summcmp_rsubj);
2313 else if (!strcasecmp(sortby, "sender")) {
2314 qsort(WC->summ, WC->num_summ,
2315 sizeof(struct message_summary), summcmp_sender);
2317 else if (!strcasecmp(sortby, "rsender")) {
2318 qsort(WC->summ, WC->num_summ,
2319 sizeof(struct message_summary), summcmp_rsender);
2321 else if (!strcasecmp(sortby, "date")) {
2322 qsort(WC->summ, WC->num_summ,
2323 sizeof(struct message_summary), summcmp_date);
2325 else if (!strcasecmp(sortby, "rdate")) {
2326 qsort(WC->summ, WC->num_summ,
2327 sizeof(struct message_summary), summcmp_rdate);
2331 if (!strcasecmp(sortby, "subject")) {
2332 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2334 else if (!strcasecmp(sortby, "rsubject")) {
2335 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2338 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2341 if (!strcasecmp(sortby, "sender")) {
2342 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2344 else if (!strcasecmp(sortby, "rsender")) {
2345 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2348 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2351 if (!strcasecmp(sortby, "date")) {
2352 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2354 else if (!strcasecmp(sortby, "rdate")) {
2355 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2358 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2362 wprintf("</div>\n"); /** end of 'content' div */
2364 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2365 " document.onkeydown = CtdlMsgListKeyPress; "
2366 " if (document.layers) { "
2367 " document.captureEvents(Event.KEYPRESS); "
2372 /** note that Date and Delete are now in the same column */
2373 wprintf("<div id=\"message_list_hdr\">"
2374 "<div class=\"fix_scrollbar_bug\">"
2375 "<table cellspacing=0 style=\"width:100%%\">"
2378 wprintf("<td width=%d%%><b><i>%s</i></b> %s</td>"
2379 "<td width=%d%%><b><i>%s</i></b> %s</td>"
2380 "<td width=%d%%><b><i>%s</i></b> %s"
2382 "<input type=\"submit\" name=\"delete_button\" style=\"font-size:6pt\" "
2383 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2389 _("Subject"), subjsort_button,
2390 SENDER_COL_WIDTH_PCT,
2391 _("Sender"), sendsort_button,
2392 DATE_PLUS_BUTTONS_WIDTH_PCT,
2393 _("Date"), datesort_button,
2396 wprintf("</table></div></div>\n");
2398 wprintf("<div id=\"message_list\">"
2400 "<div class=\"fix_scrollbar_bug\">\n"
2402 "<table class=\"mailbox_summary\" id=\"summary_headers\" rules=rows "
2403 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2407 for (a = 0; a < nummsgs; ++a) {
2408 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2410 /** Display the message */
2412 display_summarized(a);
2414 else if (is_addressbook) {
2415 fetch_ab_name(WC->msgarr[a], buf);
2417 addrbook = realloc(addrbook,
2418 (sizeof(struct addrbookent) * num_ab) );
2419 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2420 sizeof(addrbook[num_ab-1].ab_name));
2421 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
2423 else if (is_calendar) {
2424 display_calendar(WC->msgarr[a]);
2426 else if (is_tasks) {
2427 display_task(WC->msgarr[a]);
2429 else if (is_notes) {
2430 display_note(WC->msgarr[a]);
2433 if (displayed_msgs == NULL) {
2434 displayed_msgs = malloc(sizeof(long) *
2435 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2437 displayed_msgs[num_displayed] = WC->msgarr[a];
2440 if (lowest_displayed < 0) lowest_displayed = a;
2441 highest_displayed = a;
2448 * Set the "is_bbview" variable if it appears that we are looking at
2449 * a classic bulletin board view.
2451 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2452 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2457 if (displayed_msgs != NULL) {
2459 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2462 /** if we do a split bbview in the future, begin messages div here */
2464 for (a=0; a<num_displayed; ++a) {
2465 read_message(displayed_msgs[a], 0, "");
2468 /** if we do a split bbview in the future, end messages div here */
2470 free(displayed_msgs);
2471 displayed_msgs = NULL;
2476 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2477 wprintf("</div>"); /**< end of 'message_list' div */
2479 /** Here's the grab-it-to-resize-the-message-list widget */
2480 wprintf("<div id=\"resize_msglist\" "
2481 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2482 "<div class=\"fix_scrollbar_bug\">"
2483 "<table width=100%% border=3 cellspacing=0 "
2484 "bgcolor=\"#cccccc\" "
2485 "cellpadding=0><TR><TD> </td></tr></table>"
2489 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2493 * Bump these because although we're thinking in zero base, the user
2494 * is a drooling idiot and is thinking in one base.
2497 ++highest_displayed;
2500 * If we're not currently looking at ALL requested
2501 * messages, then display the selector bar
2504 /** begin bbview scroller */
2505 wprintf("<form name=\"msgomatic\">");
2506 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2508 wprintf("<select name=\"whichones\" size=\"1\" "
2509 "OnChange=\"location.href=msgomatic.whichones.options"
2510 "[selectedIndex].value\">\n");
2513 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2515 lo = b - maxmsgs + 2;
2517 wprintf("<option %s value="
2522 "%d-%d</option> \n",
2523 ((WC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2532 for (b=0; b<nummsgs; b = b + maxmsgs) {
2534 hi = b + maxmsgs + 1;
2535 if (hi > nummsgs) hi = nummsgs;
2536 wprintf("<option %s value="
2541 "%d-%d</option> \n",
2542 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2551 wprintf("<option value=\"%s?startmsg=%ld"
2552 "?maxmsgs=9999999?summary=%d\">"
2556 WC->msgarr[0], is_summary);
2558 wprintf("</select> ");
2559 wprintf(_("of %d messages."), nummsgs);
2561 /** forward/reverse */
2562 wprintf(" <select name=\"direction\" size=\"1\" "
2563 "OnChange=\"location.href=msgomatic.direction.options"
2564 "[selectedIndex].value\">\n"
2567 wprintf("<option %s value=\"%s?sortby=forward\">oldest to newest</option>\n",
2568 (bbs_reverse ? "" : "selected"),
2572 wprintf("<option %s value=\"%s?sortby=reverse\">newest to oldest</option>\n",
2573 (bbs_reverse ? "selected" : ""),
2577 wprintf("</select></form>\n");
2578 /** end bbview scroller */
2583 do_tasks_view(); /** Render the task list */
2587 do_calendar_view(); /** Render the calendar */
2590 if (is_addressbook) {
2591 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2594 /** Note: wDumpContent() will output one additional </div> tag. */
2596 if (addrbook != NULL) free(addrbook);
2598 /** free the summary */
2599 if (WC->summ != NULL) {
2608 * \brief Back end for post_message()
2609 * ... this is where the actual message gets transmitted to the server.
2611 void post_mime_to_server(void) {
2613 int is_multipart = 0;
2615 struct wc_attachment *att;
2617 size_t encoded_length;
2619 /** RFC2045 requires this, and some clients look for it... */
2620 serv_puts("MIME-Version: 1.0");
2621 serv_puts("X-Mailer: " SERVER);
2623 /** If there are attachments, we have to do multipart/mixed */
2624 if (WC->first_attachment != NULL) {
2629 sprintf(boundary, "Citadel--Multipart--%s--%04x--%04x",
2630 serv_info.serv_fqdn,
2635 /** Remember, serv_printf() appends an extra newline */
2636 serv_printf("Content-type: multipart/mixed; "
2637 "boundary=\"%s\"\n", boundary);
2638 serv_printf("This is a multipart message in MIME format.\n");
2639 serv_printf("--%s", boundary);
2642 serv_puts("Content-type: text/html; charset=utf-8");
2643 serv_puts("Content-Transfer-Encoding: quoted-printable");
2645 serv_puts("<html><body>\r\n");
2646 text_to_server_qp(bstr("msgtext")); /** Transmit message in quoted-printable encoding */
2647 serv_puts("</body></html>\r\n");
2651 /** Add in the attachments */
2652 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2654 encoded_length = ((att->length * 150) / 100);
2655 encoded = malloc(encoded_length);
2656 if (encoded == NULL) break;
2657 CtdlEncodeBase64(encoded, att->data, att->length, 1);
2659 serv_printf("--%s", boundary);
2660 serv_printf("Content-type: %s", att->content_type);
2661 serv_printf("Content-disposition: attachment; "
2662 "filename=\"%s\"", att->filename);
2663 serv_puts("Content-transfer-encoding: base64");
2665 serv_write(encoded, strlen(encoded));
2670 serv_printf("--%s--", boundary);
2678 * \brief Post message (or don't post message)
2680 * Note regarding the "dont_post" variable:
2681 * A random value (actually, it's just a timestamp) is inserted as a hidden
2682 * field called "postseq" when the display_enter page is generated. This
2683 * value is checked when posting, using the static variable dont_post. If a
2684 * user attempts to post twice using the same dont_post value, the message is
2685 * discarded. This prevents the accidental double-saving of the same message
2686 * if the user happens to click the browser "back" button.
2688 void post_message(void)
2691 char encoded_subject[1024];
2692 static long dont_post = (-1L);
2693 struct wc_attachment *att, *aptr;
2694 int is_anonymous = 0;
2697 display_name = bstr("display_name");
2698 if (!strcmp(display_name, "__ANONYMOUS__")) {
2703 if (WC->upload_length > 0) {
2705 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WC->upload_length);
2706 /** There's an attachment. Save it to this struct... */
2707 att = malloc(sizeof(struct wc_attachment));
2708 memset(att, 0, sizeof(struct wc_attachment));
2709 att->length = WC->upload_length;
2710 strcpy(att->content_type, WC->upload_content_type);
2711 strcpy(att->filename, WC->upload_filename);
2714 /** And add it to the list. */
2715 if (WC->first_attachment == NULL) {
2716 WC->first_attachment = att;
2719 aptr = WC->first_attachment;
2720 while (aptr->next != NULL) aptr = aptr->next;
2725 * Mozilla sends a simple filename, which is what we want,
2726 * but Satan's Browser sends an entire pathname. Reduce
2727 * the path to just a filename if we need to.
2729 while (num_tokens(att->filename, '/') > 1) {
2730 remove_token(att->filename, 0, '/');
2732 while (num_tokens(att->filename, '\\') > 1) {
2733 remove_token(att->filename, 0, '\\');
2737 * Transfer control of this memory from the upload struct
2738 * to the attachment struct.
2740 att->data = WC->upload;
2741 WC->upload_length = 0;
2747 if (strlen(bstr("cancel_button")) > 0) {
2748 sprintf(WC->ImportantMessage,
2749 _("Cancelled. Message was not posted."));
2750 } else if (strlen(bstr("attach_button")) > 0) {
2753 } else if (atol(bstr("postseq")) == dont_post) {
2754 sprintf(WC->ImportantMessage,
2755 _("Automatically cancelled because you have already "
2756 "saved this message."));
2758 rfc2047encode(encoded_subject, sizeof encoded_subject, bstr("subject"));
2759 sprintf(buf, "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s",
2767 bstr("my_email_addr")
2770 serv_getln(buf, sizeof buf);
2771 if (buf[0] == '4') {
2772 post_mime_to_server();
2773 if ( (strlen(bstr("recp")) > 0)
2774 || (strlen(bstr("cc")) > 0)
2775 || (strlen(bstr("bcc")) > 0)
2777 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2780 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2782 dont_post = atol(bstr("postseq"));
2784 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
2785 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2791 free_attachments(WC);
2794 * We may have been supplied with instructions regarding the location
2795 * to which we must return after posting. If found, go there.
2797 if (strlen(bstr("return_to")) > 0) {
2798 http_redirect(bstr("return_to"));
2801 * If we were editing a page in a wiki room, go to that page now.
2803 else if (strlen(bstr("wikipage")) > 0) {
2804 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
2808 * Otherwise, just go to the "read messages" loop.
2811 readloop("readnew");
2819 * \brief display the message entry screen
2821 void display_enter(void)
2827 struct wc_attachment *att;
2828 int recipient_required = 0;
2829 int recipient_bad = 0;
2831 int is_anonymous = 0;
2832 long existing_page = (-1L);
2836 if (strlen(bstr("force_room")) > 0) {
2837 gotoroom(bstr("force_room"));
2840 display_name = bstr("display_name");
2841 if (!strcmp(display_name, "__ANONYMOUS__")) {
2846 /** First test to see whether this is a room that requires recipients to be entered */
2847 serv_puts("ENT0 0");
2848 serv_getln(buf, sizeof buf);
2849 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
2850 recipient_required = 1;
2852 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2853 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2854 readloop("readnew");
2859 * Are we perhaps in an address book view? If so, then an "enter
2860 * message" command really means "add new entry."
2862 if (WC->wc_default_view == VIEW_ADDRESSBOOK) {
2863 do_edit_vcard(-1, "", "");
2867 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
2869 * Are we perhaps in a calendar room? If so, then an "enter
2870 * message" command really means "add new calendar item."
2872 if (WC->wc_default_view == VIEW_CALENDAR) {
2873 display_edit_event();
2878 * Are we perhaps in a tasks view? If so, then an "enter
2879 * message" command really means "add new task."
2881 if (WC->wc_default_view == VIEW_TASKS) {
2882 display_edit_task();
2888 * Otherwise proceed normally.
2889 * Do a custom room banner with no navbar...
2891 output_headers(1, 1, 2, 0, 0, 0);
2892 wprintf("<div id=\"banner\">\n");
2893 embed_room_banner(NULL, navbar_none);
2894 wprintf("</div>\n");
2895 wprintf("<div id=\"content\">\n"
2896 "<div class=\"fix_scrollbar_bug\">"
2897 "<table class=\"messages_background\"><tr><td>");
2899 /** Now check our actual recipients if there are any */
2900 if (recipient_required) {
2901 sprintf(buf, "ENT0 0|%s|%d|0||%s||%s|%s|%s",
2905 bstr("cc"), bstr("bcc"), bstr("wikipage"));
2907 serv_getln(buf, sizeof buf);
2909 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
2910 if (strlen(bstr("recp")) + strlen(bstr("cc")) + strlen(bstr("bcc")) > 0) {
2914 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2915 wprintf("<em>%s</em><br />\n", &buf[4]);
2920 /** If we got this far, we can display the message entry screen. */
2922 /** begin message entry screen */
2924 "enctype=\"multipart/form-data\" "
2926 "accept-charset=\"UTF-8\" "
2928 "name=\"enterform\""
2930 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2931 if (WC->wc_view == VIEW_WIKI) {
2932 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
2934 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
2938 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2939 fmt_date(buf, now, 0);
2940 wprintf("%s ", buf);
2942 wprintf(_(" <I>from</I> "));
2944 /* Allow the user to select any of his valid screen names */
2946 wprintf("<select name=\"display_name\" size=1>\n");
2949 serv_getln(buf, sizeof buf);
2950 if (buf[0] == '1') {
2951 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2952 wprintf("<option %s value=\"",
2953 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
2958 wprintf("</option>\n");
2962 if (WC->room_flags & QR_ANONOPT) {
2963 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
2964 ((!strcasecmp(bstr("__ANONYMOUS__"), WC->wc_fullname)) ? "selected" : ""),
2969 wprintf("</select>\n");
2971 /* If this is an email (not a post), allow the user to select any of his
2972 * valid email addresses.
2974 if (recipient_required) {
2976 serv_getln(buf, sizeof buf);
2977 if (buf[0] == '1') {
2978 wprintf("<select name=\"my_email_addr\" size=1>\n");
2979 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2980 wprintf("<option value=\"");
2984 wprintf("></option>\n");
2986 wprintf("</select>\n");
2990 wprintf(_(" <I>in</I> "));
2991 escputs(WC->wc_roomname);
2992 wprintf("<br>\n"); /** header bar */
2994 wprintf("<table border=\"0\" width=\"100%%\">\n");
2995 if (recipient_required) {
2997 wprintf("<tr><td>");
2998 wprintf("<font size=-1>");
3002 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
3003 escputs(bstr("recp"));
3004 wprintf("\" size=50 maxlength=1000 />");
3005 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
3006 wprintf("</td><td></td></tr>\n");
3008 wprintf("<tr><td>");
3009 wprintf("<font size=-1>");
3013 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
3014 escputs(bstr("cc"));
3015 wprintf("\" size=50 maxlength=1000 />");
3016 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
3017 wprintf("</td><td></td></tr>\n");
3019 wprintf("<tr><td>");
3020 wprintf("<font size=-1>");
3024 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
3025 escputs(bstr("bcc"));
3026 wprintf("\" size=50 maxlength=1000 />");
3027 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
3028 wprintf("</td><td></td></tr>\n");
3030 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
3031 wprintf("<script type=\"text/javascript\"> \n"
3032 " activate_entmsg_autocompleters(); \n"
3037 wprintf("<tr><td>");
3038 wprintf("<font size=-1>");
3039 wprintf(_("Subject (optional):"));
3042 "<input type=\"text\" name=\"subject\" value=\"");
3043 escputs(bstr("subject"));
3044 wprintf("\" size=50 maxlength=70></td><td>\n");
3046 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3047 if (recipient_required) {
3048 wprintf(_("Send message"));
3050 wprintf(_("Post message"));
3053 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3054 wprintf("</td></tr></table>\n");
3056 wprintf("<center>");
3058 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
3060 /** If we're continuing from a previous edit, put our partially-composed message back... */
3061 msgescputs(bstr("msgtext"));
3063 /* If we're forwarding a message, insert it here... */
3064 if (atol(bstr("fwdquote")) > 0L) {
3065 wprintf("<br><div align=center><i>");
3066 wprintf(_("--- forwarded message ---"));
3067 wprintf("</i></div><br>");
3068 pullquote_message(atol(bstr("fwdquote")), 1, 1);
3071 /** If we're replying quoted, insert the quote here... */
3072 else if (atol(bstr("replyquote")) > 0L) {
3075 pullquote_message(atol(bstr("replyquote")), 0, 1);
3076 wprintf("</blockquote><br>");
3079 /** If we're editing a wiki page, insert the existing page here... */
3080 else if (WC->wc_view == VIEW_WIKI) {
3081 safestrncpy(buf, bstr("wikipage"), sizeof buf);
3082 str_wiki_index(buf);
3083 existing_page = locate_message_by_uid(buf);
3084 if (existing_page >= 0L) {
3085 pullquote_message(existing_page, 1, 0);
3089 /** Insert our signature if appropriate... */
3090 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
3091 get_preference("use_sig", buf, sizeof buf);
3092 if (!strcasecmp(buf, "yes")) {
3093 get_preference("signature", ebuf, sizeof ebuf);
3094 euid_unescapize(buf, ebuf);
3095 wprintf("<br>--<br>");
3096 for (i=0; i<strlen(buf); ++i) {
3097 if (buf[i] == '\n') {
3100 else if (buf[i] == '<') {
3103 else if (buf[i] == '>') {
3106 else if (buf[i] == '&') {
3109 else if (buf[i] == '\"') {
3112 else if (buf[i] == '\'') {
3115 else if (isprint(buf[i])) {
3116 wprintf("%c", buf[i]);
3122 wprintf("</textarea>");
3123 wprintf("</center><br />\n");
3126 * The following script embeds the TinyMCE richedit control, and automatically
3127 * transforms the textarea into a richedit textarea.
3130 "<script language=\"javascript\" type=\"text/javascript\" src=\"tiny_mce/tiny_mce.js\"></script>\n"
3131 "<script language=\"javascript\" type=\"text/javascript\">"
3133 " mode : \"textareas\", width : \"100%%\", browsers : \"msie,gecko\", "
3134 " theme : \"advanced\", plugins : \"iespell\", "
3135 " theme_advanced_buttons1 : \"bold, italic, underline, strikethrough, justifyleft, justifycenter, justifyright, justifyfull, bullist, numlist, cut, copy, paste, link, image, help, forecolor, iespell, code\", "
3136 " theme_advanced_buttons2 : \"\", "
3137 " theme_advanced_buttons3 : \"\", "
3138 " content_css : \"static/webcit-tinymce.css\" "
3144 /** Enumerate any attachments which are already in place... */
3145 wprintf("<img src=\"static/diskette_24x.gif\" border=0 "
3146 "align=middle height=16 width=16> ");
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>");
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"));
3167 /** Seth asked for these to be at the top *and* bottom... */
3168 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3169 if (recipient_required) {
3170 wprintf(_("Send message"));
3172 wprintf(_("Post message"));
3175 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3177 /** Make sure we only insert our signature once */
3178 if (strcmp(bstr("sig_inserted"), "yes")) {
3179 wprintf("<INPUT TYPE=\"hidden\" NAME=\"sig_inserted\" VALUE=\"yes\">\n");
3182 wprintf("</form>\n");
3184 wprintf("</td></tr></table></div>\n");
3185 DONE: wDumpContent(1);
3191 * \brief delete a message
3193 void delete_msg(void)
3198 msgid = atol(bstr("msgid"));
3200 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3201 serv_printf("DELE %ld", msgid);
3203 else { /** Otherwise move it to Trash */
3204 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3207 serv_getln(buf, sizeof buf);
3208 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3210 readloop("readnew");
3215 * \brief move a message to another folder
3222 msgid = atol(bstr("msgid"));
3224 if (strlen(bstr("move_button")) > 0) {
3225 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3227 serv_getln(buf, sizeof buf);
3228 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3230 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3233 readloop("readnew");
3241 * \brief Confirm move of a message
3243 void confirm_move_msg(void)
3249 msgid = atol(bstr("msgid"));
3252 output_headers(1, 1, 2, 0, 0, 0);
3253 wprintf("<div id=\"banner\">\n");
3254 wprintf("<TABLE WIDTH=100%% BORDER=0><TR><TD>");
3255 wprintf("<SPAN CLASS=\"titlebar\">");
3256 wprintf(_("Confirm move of message"));
3257 wprintf("</SPAN>\n");
3258 wprintf("</TD></TR></TABLE>\n");
3259 wprintf("</div>\n<div id=\"content\">\n");
3261 wprintf("<CENTER>");
3263 wprintf(_("Move this message to:"));
3264 wprintf("<br />\n");
3266 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3267 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3269 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3271 serv_getln(buf, sizeof buf);
3272 if (buf[0] == '1') {
3273 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3274 extract_token(targ, buf, 0, '|', sizeof targ);
3275 wprintf("<OPTION>");
3280 wprintf("</SELECT>\n");
3281 wprintf("<br />\n");
3283 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3285 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3286 wprintf("</form></CENTER>\n");
3288 wprintf("</CENTER>\n");