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];
652 char mime_filename[256];
653 char mime_content_type[256];
654 char mime_charset[256];
655 char mime_disposition[256];
657 struct attach_link *attach_links = NULL;
658 int num_attach_links = 0;
659 char mime_submessages[256];
666 char reply_all[4096];
672 char vcard_partnum[256];
673 char cal_partnum[256];
674 char *part_source = NULL;
675 char msg4_partnum[32];
677 iconv_t ic = (iconv_t)(-1) ;
678 char *ibuf; /**< Buffer of characters to be converted */
679 char *obuf; /**< Buffer for converted characters */
680 size_t ibuflen; /**< Length of input buffer */
681 size_t obuflen; /**< Length of output buffer */
682 char *osav; /**< Saved pointer to output buffer */
688 strcpy(reply_to, "");
689 strcpy(reply_all, "");
690 strcpy(vcard_partnum, "");
691 strcpy(cal_partnum, "");
692 strcpy(mime_content_type, "text/plain");
693 strcpy(mime_charset, "us-ascii");
694 strcpy(mime_submessages, "");
696 serv_printf("MSG4 %ld|%s", msgnum, section);
697 serv_getln(buf, sizeof buf);
700 wprintf(_("ERROR:"));
701 wprintf("</STRONG> %s<br />\n", &buf[4]);
705 /** begin everythingamundo table */
706 if (!printable_view) {
707 wprintf("<div class=\"fix_scrollbar_bug\">\n");
708 wprintf("<table width=100%% border=1 cellspacing=0 "
709 "cellpadding=0><TR><TD>\n");
712 /** begin message header table */
713 wprintf("<table width=100%% border=0 cellspacing=0 "
714 "cellpadding=1 bgcolor=\"#CCCCCC\"><tr><td>\n");
716 wprintf("<span class=\"message_header\">");
717 strcpy(m_subject, "");
720 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
721 if (!strcmp(buf, "000")) {
723 wprintf(_("unexpected end of message"));
724 wprintf("</i><br /><br />\n");
725 wprintf("</span>\n");
728 if (!strncasecmp(buf, "nhdr=yes", 8))
732 if (!strncasecmp(buf, "type=", 5))
733 format_type = atoi(&buf[5]);
734 if (!strncasecmp(buf, "from=", 5)) {
735 strcpy(from, &buf[5]);
737 wprintf("<a href=\"showuser?who=");
739 utf8ify_rfc822_string(from);
746 if (!strncasecmp(buf, "subj=", 5)) {
747 safestrncpy(m_subject, &buf[5], sizeof m_subject);
749 if (!strncasecmp(buf, "cccc=", 5)) {
750 safestrncpy(m_cc, &buf[5], sizeof m_cc);
751 if (strlen(reply_all) > 0) {
752 strcat(reply_all, ", ");
754 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
755 (sizeof reply_all - strlen(reply_all)) );
757 if ((!strncasecmp(buf, "hnod=", 5))
758 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
759 wprintf("(%s) ", &buf[5]);
761 if ((!strncasecmp(buf, "room=", 5))
762 && (strcasecmp(&buf[5], WC->wc_roomname))
763 && (strlen(&buf[5])>0) ) {
765 wprintf("%s> ", &buf[5]);
767 if (!strncasecmp(buf, "rfca=", 5)) {
768 strcpy(rfca, &buf[5]);
774 if (!strncasecmp(buf, "node=", 5)) {
775 strcpy(node, &buf[5]);
776 if ( ((WC->room_flags & QR_NETWORK)
777 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
778 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
781 wprintf("@%s ", &buf[5]);
784 if (!strncasecmp(buf, "rcpt=", 5)) {
786 if (strlen(reply_all) > 0) {
787 strcat(reply_all, ", ");
789 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
790 (sizeof reply_all - strlen(reply_all)) );
792 utf8ify_rfc822_string(&buf[5]);
797 if (!strncasecmp(buf, "time=", 5)) {
798 fmt_date(now, atol(&buf[5]), 0);
802 if (!strncasecmp(buf, "part=", 5)) {
803 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
804 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
805 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
806 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
807 mime_length = extract_int(&buf[5], 5);
809 if (!strcasecmp(mime_content_type, "message/rfc822")) {
810 if (strlen(mime_submessages) > 0) {
811 strcat(mime_submessages, "|");
813 strcat(mime_submessages, mime_partnum);
815 else if ((!strcasecmp(mime_disposition, "inline"))
816 && (!strncasecmp(mime_content_type, "image/", 6)) ){
818 attach_links = realloc(attach_links,
819 (num_attach_links*sizeof(struct attach_link)));
820 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
821 snprintf(attach_links[num_attach_links-1].html, 1024,
822 "<img src=\"mimepart/%ld/%s/%s\">",
823 msgnum, mime_partnum, mime_filename);
825 else if ( ( (!strcasecmp(mime_disposition, "attachment"))
826 || (!strcasecmp(mime_disposition, "inline"))
827 || (!strcasecmp(mime_disposition, ""))
828 ) && (strlen(mime_content_type) > 0)
831 attach_links = realloc(attach_links,
832 (num_attach_links*sizeof(struct attach_link)));
833 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
834 snprintf(attach_links[num_attach_links-1].html, 1024,
835 "<img src=\"static/diskette_24x.gif\" "
836 "border=0 align=middle>\n"
837 "%s (%s, %d bytes) [ "
838 "<a href=\"mimepart/%ld/%s/%s\""
839 "target=\"wc.%ld.%s\">%s</a>"
841 "<a href=\"mimepart_download/%ld/%s/%s\">%s</a>"
844 mime_content_type, mime_length,
845 msgnum, mime_partnum, mime_filename,
846 msgnum, mime_partnum,
848 msgnum, mime_partnum, mime_filename,
853 /** begin handler prep ***/
854 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
855 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
856 strcpy(vcard_partnum, mime_partnum);
859 if (!strcasecmp(mime_content_type, "text/calendar")) {
860 strcpy(cal_partnum, mime_partnum);
863 /** end handler prep ***/
869 /** Generate a reply-to address */
870 if (strlen(rfca) > 0) {
871 if (strlen(from) > 0) {
872 snprintf(reply_to, sizeof(reply_to), "%s <%s>", from, rfca);
875 strcpy(reply_to, rfca);
879 if ( (strlen(node) > 0)
880 && (strcasecmp(node, serv_info.serv_nodename))
881 && (strcasecmp(node, serv_info.serv_humannode)) ) {
882 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
886 snprintf(reply_to, sizeof(reply_to), "%s", from);
896 utf8ify_rfc822_string(m_cc);
897 utf8ify_rfc822_string(m_subject);
899 if (strlen(m_cc) > 0) {
901 "<span class=\"message_subject\">");
907 if (strlen(m_subject) > 0) {
909 "<span class=\"message_subject\">");
910 wprintf(_("Subject:"));
917 /** start msg buttons */
918 if (!printable_view) {
919 wprintf("<td align=right><span class=\"msgbuttons\">\n");
922 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
923 wprintf("<a href=\"display_enter");
924 if (WC->is_mailbox) {
925 wprintf("?replyquote=%ld", msgnum);
928 urlescputs(reply_to);
929 if (strlen(m_subject) > 0) {
930 wprintf("?subject=");
931 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
932 urlescputs(m_subject);
934 wprintf("\">[%s]</a> ", _("Reply"));
938 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
939 if (!WC->is_mailbox) {
940 wprintf("<a href=\"display_enter");
941 wprintf("?replyquote=%ld", msgnum);
943 urlescputs(reply_to);
944 if (strlen(m_subject) > 0) {
945 wprintf("?subject=");
946 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
947 urlescputs(m_subject);
949 wprintf("\">[%s]</a> ", _("ReplyQuoted"));
954 if (WC->wc_view == VIEW_MAILBOX) {
955 wprintf("<a href=\"display_enter");
956 wprintf("?replyquote=%ld", msgnum);
958 urlescputs(reply_to);
960 urlescputs(reply_all);
961 if (strlen(m_subject) > 0) {
962 wprintf("?subject=");
963 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
964 urlescputs(m_subject);
966 wprintf("\">[%s]</a> ", _("ReplyAll"));
970 if (WC->wc_view == VIEW_MAILBOX) {
971 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
972 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
973 urlescputs(m_subject);
974 wprintf("\">[%s]</a> ", _("Forward"));
977 /** If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
978 if ( (WC->is_room_aide) || (WC->is_mailbox) || (WC->room_flags2 & QR2_COLLABDEL) ) {
980 wprintf("<a href=\"confirm_move_msg?msgid=%ld\">[%s]</a> ",
984 wprintf("<a href=\"delete_msg?msgid=%ld\" "
985 "onClick=\"return confirm('%s');\">"
986 "[%s]</a> ", msgnum, _("Delete this message?"), _("Delete")
991 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'); \" >"
992 "[%s]</a>", msgnum, msgnum, _("Headers"));
996 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'); \" >"
997 "[%s]</a>", msgnum, msgnum, _("Print"));
999 wprintf("</span></td>");
1002 wprintf("</tr></table>\n");
1005 wprintf("<table class=\"messages_background\" "
1006 "cellpadding=1 cellspacing=0><tr><td>");
1009 * Learn the content type
1011 strcpy(mime_content_type, "text/plain");
1012 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1013 if (!strcmp(buf, "000")) {
1015 wprintf(_("unexpected end of message"));
1016 wprintf("</i><br /><br />\n");
1019 if (!strncasecmp(buf, "X-Citadel-MSG4-Partnum:", 23)) {
1020 safestrncpy(msg4_partnum, &buf[23], sizeof(msg4_partnum));
1021 striplt(msg4_partnum);
1023 if (!strncasecmp(buf, "Content-type:", 13)) {
1024 safestrncpy(mime_content_type, &buf[13], sizeof(mime_content_type));
1025 striplt(mime_content_type);
1026 for (i=0; i<strlen(mime_content_type); ++i) {
1027 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1028 safestrncpy(mime_charset, &mime_content_type[i+8],
1029 sizeof mime_charset);
1032 for (i=0; i<strlen(mime_content_type); ++i) {
1033 if (mime_content_type[i] == ';') {
1034 mime_content_type[i] = 0;
1037 for (i=0; i<strlen(mime_charset); ++i) {
1038 if (mime_charset[i] == ';') {
1039 mime_charset[i] = 0;
1045 /** Set up a character set conversion if we need to (and if we can) */
1047 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
1048 if ( (strcasecmp(mime_charset, "us-ascii"))
1049 && (strcasecmp(mime_charset, "UTF-8"))
1050 && (strcasecmp(mime_charset, ""))
1052 ic = ctdl_iconv_open("UTF-8", mime_charset);
1053 if (ic == (iconv_t)(-1) ) {
1054 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1055 __FILE__, __LINE__, mime_charset, strerror(errno));
1060 /** Messages in legacy Citadel variformat get handled thusly... */
1061 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1065 /** Boring old 80-column fixed format text gets handled this way... */
1066 else if ( (!strcasecmp(mime_content_type, "text/plain"))
1067 || (!strcasecmp(mime_content_type, "text")) ) {
1068 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1069 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1070 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1073 if (ic != (iconv_t)(-1) ) {
1075 ibuflen = strlen(ibuf);
1077 obuf = (char *) malloc(obuflen);
1079 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1080 osav[SIZ-obuflen] = 0;
1081 safestrncpy(buf, osav, sizeof buf);
1086 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1087 buf[strlen(buf) - 1] = 0;
1089 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1090 wprintf("<blockquote>");
1092 } else if ((bq == 1) &&
1093 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1094 wprintf("</blockquote>");
1100 wprintf("</tt><br />\n");
1102 wprintf("</i><br />");
1105 else /** HTML is fun, but we've got to strip it first */
1106 if (!strcasecmp(mime_content_type, "text/html")) {
1107 output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
1110 /** Unknown weirdness */
1112 wprintf(_("I don't know how to display %s"), mime_content_type);
1113 wprintf("<br />\n", mime_content_type);
1114 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1117 /** If there are attached submessages, display them now... */
1118 if ( (strlen(mime_submessages) > 0) && (!section[0]) ) {
1119 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1120 extract_token(buf, mime_submessages, i, '|', sizeof buf);
1121 /** use printable_view to suppress buttons */
1122 wprintf("<blockquote>");
1123 read_message(msgnum, 1, buf);
1124 wprintf("</blockquote>");
1129 /** Afterwards, offer links to download attachments 'n' such */
1130 if ( (num_attach_links > 0) && (!section[0]) ) {
1131 for (i=0; i<num_attach_links; ++i) {
1132 if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
1133 wprintf("%s", attach_links[i].html);
1138 /** Handler for vCard parts */
1139 if (strlen(vcard_partnum) > 0) {
1140 part_source = load_mimepart(msgnum, vcard_partnum);
1141 if (part_source != NULL) {
1143 /** If it's my vCard I can edit it */
1144 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1145 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1146 || (WC->wc_view == VIEW_ADDRESSBOOK)
1148 wprintf("<a href=\"edit_vcard?"
1149 "msgnum=%ld?partnum=%s\">",
1150 msgnum, vcard_partnum);
1151 wprintf("[%s]</a>", _("edit"));
1154 /** In all cases, display the full card */
1155 display_vcard(part_source, 0, 1, NULL);
1159 /** Handler for calendar parts */
1160 if (strlen(cal_partnum) > 0) {
1161 part_source = load_mimepart(msgnum, cal_partnum);
1162 if (part_source != NULL) {
1163 cal_process_attachment(part_source,
1164 msgnum, cal_partnum);
1174 wprintf("</td></tr></table>\n");
1176 /** end everythingamundo table */
1177 if (!printable_view) {
1178 wprintf("</td></tr></table>\n");
1179 wprintf("</div><br />\n");
1182 if (num_attach_links > 0) {
1187 if (ic != (iconv_t)(-1) ) {
1196 * \brief Unadorned HTML output of an individual message, suitable
1197 * for placing in a hidden iframe, for printing, or whatever
1199 * \param msgnum_as_string Message number, as a string instead of as a long int
1201 void embed_message(char *msgnum_as_string) {
1204 msgnum = atol(msgnum_as_string);
1205 begin_ajax_response();
1206 read_message(msgnum, 0, "");
1207 end_ajax_response();
1212 * \brief Printable view of a message
1214 * \param msgnum_as_string Message number, as a string instead of as a long int
1216 void print_message(char *msgnum_as_string) {
1219 msgnum = atol(msgnum_as_string);
1220 output_headers(0, 0, 0, 0, 0, 0);
1222 wprintf("Content-type: text/html\r\n"
1224 "Connection: close\r\n",
1228 wprintf("\r\n\r\n<html>\n"
1229 "<head><title>Printable view</title></head>\n"
1230 "<body onLoad=\" window.print(); window.close(); \">\n"
1233 read_message(msgnum, 1, "");
1235 wprintf("\n</body></html>\n\n");
1242 * \brief Display a message's headers
1244 * \param msgnum_as_string Message number, as a string instead of as a long int
1246 void display_headers(char *msgnum_as_string) {
1250 msgnum = atol(msgnum_as_string);
1251 output_headers(0, 0, 0, 0, 0, 0);
1253 wprintf("Content-type: text/plain\r\n"
1255 "Connection: close\r\n",
1259 serv_printf("MSG2 %ld|3", msgnum);
1260 serv_getln(buf, sizeof buf);
1261 if (buf[0] == '1') {
1262 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1263 wprintf("%s\n", buf);
1273 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1274 * or 'reply quoted' operations.
1276 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1277 * in this function. Doing so would throw a JavaScript error in the
1278 * 'supplied text' argument to the editor.
1280 * \param msgnum Message number of the message we want to quote
1281 * \param forward_attachments Nonzero if we want attachments to be forwarded
1283 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1285 char mime_partnum[256];
1286 char mime_filename[256];
1287 char mime_content_type[256];
1288 char mime_charset[256];
1289 char mime_disposition[256];
1291 char *attachments = NULL;
1293 int num_attachments = 0;
1294 struct wc_attachment *att, *aptr;
1295 char m_subject[256];
1301 int format_type = 0;
1306 iconv_t ic = (iconv_t)(-1) ;
1307 char *ibuf; /**< Buffer of characters to be converted */
1308 char *obuf; /**< Buffer for converted characters */
1309 size_t ibuflen; /**< Length of input buffer */
1310 size_t obuflen; /**< Length of output buffer */
1311 char *osav; /**< Saved pointer to output buffer */
1317 strcpy(reply_to, "");
1318 strcpy(mime_content_type, "text/plain");
1319 strcpy(mime_charset, "us-ascii");
1321 serv_printf("MSG4 %ld", msgnum);
1322 serv_getln(buf, sizeof buf);
1323 if (buf[0] != '1') {
1324 wprintf(_("ERROR:"));
1325 wprintf("%s<br />", &buf[4]);
1329 strcpy(m_subject, "");
1331 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1332 if (!strcmp(buf, "000")) {
1333 wprintf(_("unexpected end of message"));
1336 if (include_headers) {
1337 if (!strncasecmp(buf, "nhdr=yes", 8))
1341 if (!strncasecmp(buf, "type=", 5))
1342 format_type = atoi(&buf[5]);
1343 if (!strncasecmp(buf, "from=", 5)) {
1344 strcpy(from, &buf[5]);
1345 wprintf(_("from "));
1347 utf8ify_rfc822_string(from);
1351 if (!strncasecmp(buf, "subj=", 5)) {
1352 strcpy(m_subject, &buf[5]);
1354 if ((!strncasecmp(buf, "hnod=", 5))
1355 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1356 wprintf("(%s) ", &buf[5]);
1358 if ((!strncasecmp(buf, "room=", 5))
1359 && (strcasecmp(&buf[5], WC->wc_roomname))
1360 && (strlen(&buf[5])>0) ) {
1362 wprintf("%s> ", &buf[5]);
1364 if (!strncasecmp(buf, "rfca=", 5)) {
1365 strcpy(rfca, &buf[5]);
1371 if (!strncasecmp(buf, "node=", 5)) {
1372 strcpy(node, &buf[5]);
1373 if ( ((WC->room_flags & QR_NETWORK)
1374 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1375 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1376 && (strlen(rfca)==0)
1378 wprintf("@%s ", &buf[5]);
1381 if (!strncasecmp(buf, "rcpt=", 5)) {
1383 wprintf("%s ", &buf[5]);
1385 if (!strncasecmp(buf, "time=", 5)) {
1386 fmt_date(now, atol(&buf[5]), 0);
1387 wprintf("%s ", now);
1392 * Save attachment info for later. We can't start downloading them
1393 * yet because we're in the middle of a server transaction.
1395 if (!strncasecmp(buf, "part=", 5)) {
1396 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1399 sprintf(ptr, "%s%s\n",
1400 ((attachments != NULL) ? attachments : ""),
1405 lprintf(9, "attachments=<%s>\n", attachments);
1411 if (include_headers) {
1415 utf8ify_rfc822_string(m_subject);
1417 if (strlen(m_subject) > 0) {
1418 wprintf(_("Subject:"));
1420 msgescputs(m_subject);
1431 * Learn the content type
1433 strcpy(mime_content_type, "text/plain");
1434 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1435 if (!strcmp(buf, "000")) {
1436 wprintf(_("unexpected end of message"));
1439 if (!strncasecmp(buf, "Content-type: ", 14)) {
1440 safestrncpy(mime_content_type, &buf[14],
1441 sizeof(mime_content_type));
1442 for (i=0; i<strlen(mime_content_type); ++i) {
1443 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1444 safestrncpy(mime_charset, &mime_content_type[i+8],
1445 sizeof mime_charset);
1448 for (i=0; i<strlen(mime_content_type); ++i) {
1449 if (mime_content_type[i] == ';') {
1450 mime_content_type[i] = 0;
1453 for (i=0; i<strlen(mime_charset); ++i) {
1454 if (mime_charset[i] == ';') {
1455 mime_charset[i] = 0;
1461 /** Set up a character set conversion if we need to (and if we can) */
1463 if ( (strcasecmp(mime_charset, "us-ascii"))
1464 && (strcasecmp(mime_charset, "UTF-8"))
1465 && (strcasecmp(mime_charset, ""))
1467 ic = ctdl_iconv_open("UTF-8", mime_charset);
1468 if (ic == (iconv_t)(-1) ) {
1469 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1470 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1475 /** Messages in legacy Citadel variformat get handled thusly... */
1476 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1480 /* Boring old 80-column fixed format text gets handled this way... */
1481 else if (!strcasecmp(mime_content_type, "text/plain")) {
1482 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1483 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1484 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1487 if (ic != (iconv_t)(-1) ) {
1489 ibuflen = strlen(ibuf);
1491 obuf = (char *) malloc(obuflen);
1493 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1494 osav[SIZ-obuflen] = 0;
1495 safestrncpy(buf, osav, sizeof buf);
1500 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1501 buf[strlen(buf) - 1] = 0;
1503 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1504 wprintf("<blockquote>");
1506 } else if ((bq == 1) &&
1507 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1508 wprintf("</blockquote>");
1514 wprintf("</tt><br />");
1516 wprintf("</i><br />");
1519 /** HTML just gets escaped and stuffed back into the editor */
1520 else if (!strcasecmp(mime_content_type, "text/html")) {
1521 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1527 /** Unknown weirdness ... don't know how to handle this content type */
1529 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1533 /** end of body handler */
1536 * If there were attachments, we have to download them and insert them
1537 * into the attachment chain for the forwarded message we are composing.
1539 if ( (forward_attachments) && (num_attachments) ) {
1540 for (i=0; i<num_attachments; ++i) {
1541 extract_token(buf, attachments, i, '\n', sizeof buf);
1542 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1543 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1544 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1545 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1546 mime_length = extract_int(buf, 5);
1549 * tracing ... uncomment if necessary
1552 lprintf(9, "fwd filename: %s\n", mime_filename);
1553 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1554 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1555 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1556 lprintf(9, "fwd length : %d\n", mime_length);
1558 if ( (!strcasecmp(mime_disposition, "inline"))
1559 || (!strcasecmp(mime_disposition, "attachment")) ) {
1561 /* Create an attachment struct from this mime part... */
1562 att = malloc(sizeof(struct wc_attachment));
1563 memset(att, 0, sizeof(struct wc_attachment));
1564 att->length = mime_length;
1565 strcpy(att->content_type, mime_content_type);
1566 strcpy(att->filename, mime_filename);
1568 att->data = load_mimepart(msgnum, mime_partnum);
1570 /* And add it to the list. */
1571 if (WC->first_attachment == NULL) {
1572 WC->first_attachment = att;
1575 aptr = WC->first_attachment;
1576 while (aptr->next != NULL) aptr = aptr->next;
1585 if (ic != (iconv_t)(-1) ) {
1590 if (attachments != NULL) {
1596 * \brief Display one row in the mailbox summary view
1598 * \param num The row number to be displayed
1600 void display_summarized(int num) {
1603 wprintf("<tr id=\"m%ld\" style=\"width:100%%;font-weight:%s;background-color:#ffffff\" "
1604 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1605 WC->summ[num].msgnum,
1606 (WC->summ[num].is_new ? "bold" : "normal"),
1607 WC->summ[num].msgnum
1610 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1611 escputs(WC->summ[num].subj);
1614 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1615 escputs(WC->summ[num].from);
1618 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1619 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1629 * \brief display the adressbook overview
1630 * \param msgnum the citadel message number
1631 * \param alpha what????
1633 void display_addressbook(long msgnum, char alpha) {
1635 char mime_partnum[SIZ];
1636 char mime_filename[SIZ];
1637 char mime_content_type[SIZ];
1638 char mime_disposition[SIZ];
1640 char vcard_partnum[SIZ];
1641 char *vcard_source = NULL;
1642 struct message_summary summ;
1644 memset(&summ, 0, sizeof(summ));
1645 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1647 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1649 serv_getln(buf, sizeof buf);
1650 if (buf[0] != '1') return;
1652 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1653 if (!strncasecmp(buf, "part=", 5)) {
1654 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1655 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1656 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1657 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1658 mime_length = extract_int(&buf[5], 5);
1660 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1661 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1662 strcpy(vcard_partnum, mime_partnum);
1668 if (strlen(vcard_partnum) > 0) {
1669 vcard_source = load_mimepart(msgnum, vcard_partnum);
1670 if (vcard_source != NULL) {
1672 /** Display the summary line */
1673 display_vcard(vcard_source, alpha, 0, NULL);
1675 /** If it's my vCard I can edit it */
1676 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1677 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1678 || (WC->wc_view == VIEW_ADDRESSBOOK)
1680 wprintf("<a href=\"edit_vcard?"
1681 "msgnum=%ld?partnum=%s\">",
1682 msgnum, vcard_partnum);
1683 wprintf("[%s]</a>", _("edit"));
1695 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1696 * \param namebuf name to analyze, reverse if nescessary
1698 void lastfirst_firstlast(char *namebuf) {
1699 char firstname[SIZ];
1703 if (namebuf == NULL) return;
1704 if (strchr(namebuf, ';') != NULL) return;
1706 i = num_tokens(namebuf, ' ');
1709 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1710 remove_token(namebuf, i-1, ' ');
1711 strcpy(firstname, namebuf);
1712 sprintf(namebuf, "%s; %s", lastname, firstname);
1716 * \brief fetch what??? name
1717 * \param msgnum the citadel message number
1718 * \param namebuf where to put the name in???
1720 void fetch_ab_name(long msgnum, char *namebuf) {
1722 char mime_partnum[SIZ];
1723 char mime_filename[SIZ];
1724 char mime_content_type[SIZ];
1725 char mime_disposition[SIZ];
1727 char vcard_partnum[SIZ];
1728 char *vcard_source = NULL;
1730 struct message_summary summ;
1732 if (namebuf == NULL) return;
1733 strcpy(namebuf, "");
1735 memset(&summ, 0, sizeof(summ));
1736 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1738 sprintf(buf, "MSG0 %ld|0", msgnum); /** unfortunately we need the mime info now */
1740 serv_getln(buf, sizeof buf);
1741 if (buf[0] != '1') return;
1743 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1744 if (!strncasecmp(buf, "part=", 5)) {
1745 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1746 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1747 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1748 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1749 mime_length = extract_int(&buf[5], 5);
1751 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1752 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1753 strcpy(vcard_partnum, mime_partnum);
1759 if (strlen(vcard_partnum) > 0) {
1760 vcard_source = load_mimepart(msgnum, vcard_partnum);
1761 if (vcard_source != NULL) {
1763 /* Grab the name off the card */
1764 display_vcard(vcard_source, 0, 0, namebuf);
1770 lastfirst_firstlast(namebuf);
1772 for (i=0; i<strlen(namebuf); ++i) {
1773 if (namebuf[i] != ';') return;
1775 strcpy(namebuf, _("(no name)"));
1781 * \brief Record compare function for sorting address book indices
1782 * \param ab1 adressbook one
1783 * \param ab2 adressbook two
1785 int abcmp(const void *ab1, const void *ab2) {
1787 (((const struct addrbookent *)ab1)->ab_name),
1788 (((const struct addrbookent *)ab2)->ab_name)
1794 * \brief Helper function for do_addrbook_view()
1795 * Converts a name into a three-letter tab label
1796 * \param tabbuf the tabbuffer to add name to
1797 * \param name the name to add to the tabbuffer
1799 void nametab(char *tabbuf, char *name) {
1800 stresc(tabbuf, name, 0, 0);
1801 tabbuf[0] = toupper(tabbuf[0]);
1802 tabbuf[1] = tolower(tabbuf[1]);
1803 tabbuf[2] = tolower(tabbuf[2]);
1809 * \brief Render the address book using info we gathered during the scan
1810 * \param addrbook the addressbook to render
1811 * \param num_ab the number of the addressbook
1813 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1817 static int NAMESPERPAGE = 60;
1821 char tabfirst_label[SIZ];
1823 char tablast_label[SIZ];
1826 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1827 wprintf(_("This address book is empty."));
1828 wprintf("</i></div>\n");
1833 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1836 num_pages = num_ab / NAMESPERPAGE;
1838 page = atoi(bstr("page"));
1841 for (i=0; i<=num_pages; ++i) {
1843 wprintf("<a href=\"readfwd?page=%d\">", i);
1848 tabfirst = i * NAMESPERPAGE;
1849 tablast = tabfirst + NAMESPERPAGE - 1;
1850 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1851 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1852 nametab(tablast_label, addrbook[tablast].ab_name);
1853 wprintf("[%s - %s]",
1854 tabfirst_label, tablast_label
1863 wprintf("<br />\n");
1865 wprintf("<table border=0 cellspacing=0 "
1866 "cellpadding=3 width=100%%>\n"
1869 for (i=0; i<num_ab; ++i) {
1871 if ((i / NAMESPERPAGE) == page) {
1873 if ((displayed % 4) == 0) {
1874 if (displayed > 0) {
1878 wprintf("<tr bgcolor=\"#%s\">",
1879 (bg ? "DDDDDD" : "FFFFFF")
1885 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
1886 addrbook[i].ab_msgnum);
1887 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1888 vcard_n_prettyize(addrbook[i].ab_name);
1889 escputs(addrbook[i].ab_name);
1890 wprintf("</a></td>\n");
1895 wprintf("</tr></table>\n");
1901 * \brief load message pointers from the server
1902 * \param servcmd the citadel command to send to the citserver
1903 * \param with_headers what headers???
1905 int load_msg_ptrs(char *servcmd, int with_headers)
1916 int num_summ_alloc = 0;
1918 if (WC->summ != NULL) {
1923 num_summ_alloc = 100;
1925 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1928 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1930 serv_getln(buf, sizeof buf);
1931 if (buf[0] != '1') {
1934 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1935 if (nummsgs < maxload) {
1936 WC->msgarr[nummsgs] = extract_long(buf, 0);
1937 datestamp = extract_long(buf, 1);
1938 extract_token(fullname, buf, 2, '|', sizeof fullname);
1939 extract_token(nodename, buf, 3, '|', sizeof nodename);
1940 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1941 extract_token(subject, buf, 5, '|', sizeof subject);
1945 if (nummsgs > num_summ_alloc) {
1946 num_summ_alloc *= 2;
1947 WC->summ = realloc(WC->summ,
1948 num_summ_alloc * sizeof(struct message_summary));
1952 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1953 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1954 safestrncpy(WC->summ[nummsgs-1].subj,
1955 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1956 if (strlen(fullname) > 0) {
1957 safestrncpy(WC->summ[nummsgs-1].from,
1958 fullname, sizeof WC->summ[nummsgs-1].from);
1960 if (strlen(subject) > 0) {
1961 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1962 sizeof WC->summ[nummsgs-1].subj);
1965 /** Handle subjects with RFC2047 encoding */
1966 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1968 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1969 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1972 if (strlen(nodename) > 0) {
1973 if ( ((WC->room_flags & QR_NETWORK)
1974 || ((strcasecmp(nodename, serv_info.serv_nodename)
1975 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1977 strcat(WC->summ[nummsgs-1].from, " @ ");
1978 strcat(WC->summ[nummsgs-1].from, nodename);
1982 WC->summ[nummsgs-1].date = datestamp;
1985 /** Handle senders with RFC2047 encoding */
1986 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1988 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1989 strcpy(&WC->summ[nummsgs-1].from[22], "...");
1998 * \brief qsort() compatible function to compare two longs in descending order.
2000 * \param s1 first number to compare
2001 * \param s2 second number to compare
2003 int longcmp_r(const void *s1, const void *s2) {
2010 if (l1 > l2) return(-1);
2011 if (l1 < l2) return(+1);
2017 * \brief qsort() compatible function to compare two message summary structs by ascending subject.
2019 * \param s1 first item to compare
2020 * \param s2 second item to compare
2022 int summcmp_subj(const void *s1, const void *s2) {
2023 struct message_summary *summ1;
2024 struct message_summary *summ2;
2026 summ1 = (struct message_summary *)s1;
2027 summ2 = (struct message_summary *)s2;
2028 return strcasecmp(summ1->subj, summ2->subj);
2032 * \brief qsort() compatible function to compare two message summary structs by descending subject.
2034 * \param s1 first item to compare
2035 * \param s2 second item to compare
2037 int summcmp_rsubj(const void *s1, const void *s2) {
2038 struct message_summary *summ1;
2039 struct message_summary *summ2;
2041 summ1 = (struct message_summary *)s1;
2042 summ2 = (struct message_summary *)s2;
2043 return strcasecmp(summ2->subj, summ1->subj);
2047 * \brief qsort() compatible function to compare two message summary structs by ascending sender.
2049 * \param s1 first item to compare
2050 * \param s2 second item to compare
2052 int summcmp_sender(const void *s1, const void *s2) {
2053 struct message_summary *summ1;
2054 struct message_summary *summ2;
2056 summ1 = (struct message_summary *)s1;
2057 summ2 = (struct message_summary *)s2;
2058 return strcasecmp(summ1->from, summ2->from);
2062 * \brief qsort() compatible function to compare two message summary structs by descending sender.
2064 * \param s1 first item to compare
2065 * \param s2 second item to compare
2067 int summcmp_rsender(const void *s1, const void *s2) {
2068 struct message_summary *summ1;
2069 struct message_summary *summ2;
2071 summ1 = (struct message_summary *)s1;
2072 summ2 = (struct message_summary *)s2;
2073 return strcasecmp(summ2->from, summ1->from);
2077 * \brief qsort() compatible function to compare two message summary structs by ascending date.
2079 * \param s1 first item to compare
2080 * \param s2 second item to compare
2082 int summcmp_date(const void *s1, const void *s2) {
2083 struct message_summary *summ1;
2084 struct message_summary *summ2;
2086 summ1 = (struct message_summary *)s1;
2087 summ2 = (struct message_summary *)s2;
2089 if (summ1->date < summ2->date) return -1;
2090 else if (summ1->date > summ2->date) return +1;
2095 * \brief qsort() compatible function to compare two message summary structs by descending date.
2097 * \param s1 first item to compare
2098 * \param s2 second item to compare
2100 int summcmp_rdate(const void *s1, const void *s2) {
2101 struct message_summary *summ1;
2102 struct message_summary *summ2;
2104 summ1 = (struct message_summary *)s1;
2105 summ2 = (struct message_summary *)s2;
2107 if (summ1->date < summ2->date) return +1;
2108 else if (summ1->date > summ2->date) return -1;
2115 * \brief command loop for reading messages
2117 * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
2119 void readloop(char *oper)
2128 long *displayed_msgs = NULL;
2129 int num_displayed = 0;
2131 int is_addressbook = 0;
2132 int is_singlecard = 0;
2133 int is_calendar = 0;
2138 int lowest_displayed = (-1);
2139 int highest_displayed = 0;
2140 struct addrbookent *addrbook = NULL;
2142 char *sortby = NULL;
2143 char sortpref_name[128];
2144 char sortpref_value[128];
2145 char *subjsort_button;
2146 char *sendsort_button;
2147 char *datesort_button;
2148 int bbs_reverse = 0;
2150 if (WC->wc_view == VIEW_WIKI) {
2151 sprintf(buf, "wiki?room=%s?page=home", WC->wc_roomname);
2156 startmsg = atol(bstr("startmsg"));
2157 maxmsgs = atoi(bstr("maxmsgs"));
2158 is_summary = atoi(bstr("summary"));
2159 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2161 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
2162 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
2164 sortby = bstr("sortby");
2165 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
2166 set_preference(sortpref_name, sortby, 1);
2168 if (strlen(sortby) == 0) sortby = sortpref_value;
2171 if (strlen(sortby) == 0) sortby = "rdate";
2173 /** message board sort */
2174 if (!strcasecmp(sortby, "reverse")) {
2181 output_headers(1, 1, 1, 0, 0, 0);
2184 * When in summary mode, always show ALL messages instead of just
2185 * new or old. Otherwise, show what the user asked for.
2187 if (!strcmp(oper, "readnew")) {
2188 strcpy(cmd, "MSGS NEW");
2190 else if (!strcmp(oper, "readold")) {
2191 strcpy(cmd, "MSGS OLD");
2193 else if (!strcmp(oper, "do_search")) {
2194 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2197 strcpy(cmd, "MSGS ALL");
2200 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
2202 if (!strcmp(oper, "do_search")) {
2203 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2206 strcpy(cmd, "MSGS ALL");
2210 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2212 if (!strcmp(oper, "do_search")) {
2213 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2216 strcpy(cmd, "MSGS ALL");
2221 if (is_summary) { /**< fetch header summary */
2222 snprintf(cmd, sizeof cmd, "MSGS %s|%s||1",
2223 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2224 (!strcmp(oper, "do_search") ? bstr("query") : "")
2231 * Are we doing a summary view? If so, we need to know old messages
2232 * and new messages, so we can do that pretty boldface thing for the
2235 strcpy(old_msgs, "");
2238 serv_getln(buf, sizeof buf);
2239 if (buf[0] == '2') {
2240 strcpy(old_msgs, &buf[4]);
2244 is_singlecard = atoi(bstr("is_singlecard"));
2246 if (WC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2248 strcpy(cmd, "MSGS ALL");
2251 if (WC->wc_default_view == VIEW_TASKS) { /**< tasks */
2253 strcpy(cmd, "MSGS ALL");
2256 if (WC->wc_default_view == VIEW_NOTES) { /**< notes */
2258 strcpy(cmd, "MSGS ALL");
2263 wprintf("<div align=center>%s</div>\n", _("Click on any note to edit it."));
2264 wprintf("<div id=\"new_notes_here\"></div>\n");
2267 nummsgs = load_msg_ptrs(cmd, is_summary);
2270 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2271 wprintf("<div align=\"center\"><br /><em>");
2272 if (!strcmp(oper, "readnew")) {
2273 wprintf(_("No new messages."));
2274 } else if (!strcmp(oper, "readold")) {
2275 wprintf(_("No old messages."));
2277 wprintf(_("No messages here."));
2279 wprintf("</em><br /></div>\n");
2286 for (a = 0; a < nummsgs; ++a) {
2287 /** Are you a new message, or an old message? */
2289 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
2290 WC->summ[a].is_new = 0;
2293 WC->summ[a].is_new = 1;
2299 if (startmsg == 0L) {
2301 startmsg = WC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2304 startmsg = WC->msgarr[0];
2309 if (!strcasecmp(sortby, "subject")) {
2310 qsort(WC->summ, WC->num_summ,
2311 sizeof(struct message_summary), summcmp_subj);
2313 else if (!strcasecmp(sortby, "rsubject")) {
2314 qsort(WC->summ, WC->num_summ,
2315 sizeof(struct message_summary), summcmp_rsubj);
2317 else if (!strcasecmp(sortby, "sender")) {
2318 qsort(WC->summ, WC->num_summ,
2319 sizeof(struct message_summary), summcmp_sender);
2321 else if (!strcasecmp(sortby, "rsender")) {
2322 qsort(WC->summ, WC->num_summ,
2323 sizeof(struct message_summary), summcmp_rsender);
2325 else if (!strcasecmp(sortby, "date")) {
2326 qsort(WC->summ, WC->num_summ,
2327 sizeof(struct message_summary), summcmp_date);
2329 else if (!strcasecmp(sortby, "rdate")) {
2330 qsort(WC->summ, WC->num_summ,
2331 sizeof(struct message_summary), summcmp_rdate);
2335 if (!strcasecmp(sortby, "subject")) {
2336 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2338 else if (!strcasecmp(sortby, "rsubject")) {
2339 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2342 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2345 if (!strcasecmp(sortby, "sender")) {
2346 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2348 else if (!strcasecmp(sortby, "rsender")) {
2349 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2352 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2355 if (!strcasecmp(sortby, "date")) {
2356 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2358 else if (!strcasecmp(sortby, "rdate")) {
2359 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2362 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2366 wprintf("</div>\n"); /** end of 'content' div */
2368 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2369 " document.onkeydown = CtdlMsgListKeyPress; "
2370 " if (document.layers) { "
2371 " document.captureEvents(Event.KEYPRESS); "
2376 /** note that Date and Delete are now in the same column */
2377 wprintf("<div id=\"message_list_hdr\">"
2378 "<div class=\"fix_scrollbar_bug\">"
2379 "<table cellspacing=0 style=\"width:100%%\">"
2382 wprintf("<td width=%d%%><b><i>%s</i></b> %s</td>"
2383 "<td width=%d%%><b><i>%s</i></b> %s</td>"
2384 "<td width=%d%%><b><i>%s</i></b> %s"
2386 "<input type=\"submit\" name=\"delete_button\" style=\"font-size:6pt\" "
2387 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2393 _("Subject"), subjsort_button,
2394 SENDER_COL_WIDTH_PCT,
2395 _("Sender"), sendsort_button,
2396 DATE_PLUS_BUTTONS_WIDTH_PCT,
2397 _("Date"), datesort_button,
2400 wprintf("</table></div></div>\n");
2402 wprintf("<div id=\"message_list\">"
2404 "<div class=\"fix_scrollbar_bug\">\n"
2406 "<table class=\"mailbox_summary\" id=\"summary_headers\" rules=rows "
2407 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2411 for (a = 0; a < nummsgs; ++a) {
2412 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2414 /** Display the message */
2416 display_summarized(a);
2418 else if (is_addressbook) {
2419 fetch_ab_name(WC->msgarr[a], buf);
2421 addrbook = realloc(addrbook,
2422 (sizeof(struct addrbookent) * num_ab) );
2423 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2424 sizeof(addrbook[num_ab-1].ab_name));
2425 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
2427 else if (is_calendar) {
2428 display_calendar(WC->msgarr[a]);
2430 else if (is_tasks) {
2431 display_task(WC->msgarr[a]);
2433 else if (is_notes) {
2434 display_note(WC->msgarr[a]);
2437 if (displayed_msgs == NULL) {
2438 displayed_msgs = malloc(sizeof(long) *
2439 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2441 displayed_msgs[num_displayed] = WC->msgarr[a];
2444 if (lowest_displayed < 0) lowest_displayed = a;
2445 highest_displayed = a;
2452 * Set the "is_bbview" variable if it appears that we are looking at
2453 * a classic bulletin board view.
2455 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2456 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2461 if (displayed_msgs != NULL) {
2463 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2466 /** if we do a split bbview in the future, begin messages div here */
2468 for (a=0; a<num_displayed; ++a) {
2469 read_message(displayed_msgs[a], 0, "");
2472 /** if we do a split bbview in the future, end messages div here */
2474 free(displayed_msgs);
2475 displayed_msgs = NULL;
2480 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2481 wprintf("</div>"); /**< end of 'message_list' div */
2483 /** Here's the grab-it-to-resize-the-message-list widget */
2484 wprintf("<div id=\"resize_msglist\" "
2485 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2486 "<div class=\"fix_scrollbar_bug\">"
2487 "<table width=100%% border=3 cellspacing=0 "
2488 "bgcolor=\"#cccccc\" "
2489 "cellpadding=0><TR><TD> </td></tr></table>"
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\">"
2901 "<table class=\"messages_background\"><tr><td>");
2903 /** Now check our actual recipients if there are any */
2904 if (recipient_required) {
2905 sprintf(buf, "ENT0 0|%s|%d|0||%s||%s|%s|%s",
2909 bstr("cc"), bstr("bcc"), bstr("wikipage"));
2911 serv_getln(buf, sizeof buf);
2913 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
2914 if (strlen(bstr("recp")) + strlen(bstr("cc")) + strlen(bstr("bcc")) > 0) {
2918 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2919 wprintf("<em>%s</em><br />\n", &buf[4]);
2924 /** If we got this far, we can display the message entry screen. */
2926 /** begin message entry screen */
2928 "enctype=\"multipart/form-data\" "
2930 "accept-charset=\"UTF-8\" "
2932 "name=\"enterform\""
2934 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2935 if (WC->wc_view == VIEW_WIKI) {
2936 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
2938 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
2942 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2943 fmt_date(buf, now, 0);
2944 wprintf("%s ", buf);
2946 wprintf(_(" <I>from</I> "));
2948 /* Allow the user to select any of his valid screen names */
2950 wprintf("<select name=\"display_name\" size=1>\n");
2953 serv_getln(buf, sizeof buf);
2954 if (buf[0] == '1') {
2955 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2956 wprintf("<option %s value=\"",
2957 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
2962 wprintf("</option>\n");
2966 if (WC->room_flags & QR_ANONOPT) {
2967 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
2968 ((!strcasecmp(bstr("__ANONYMOUS__"), WC->wc_fullname)) ? "selected" : ""),
2973 wprintf("</select>\n");
2975 /* If this is an email (not a post), allow the user to select any of his
2976 * valid email addresses.
2978 if (recipient_required) {
2980 serv_getln(buf, sizeof buf);
2981 if (buf[0] == '1') {
2982 wprintf("<select name=\"my_email_addr\" size=1>\n");
2983 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2984 wprintf("<option value=\"");
2988 wprintf("></option>\n");
2990 wprintf("</select>\n");
2994 wprintf(_(" <I>in</I> "));
2995 escputs(WC->wc_roomname);
2996 wprintf("<br>\n"); /** header bar */
2998 wprintf("<table border=\"0\" width=\"100%%\">\n");
2999 if (recipient_required) {
3001 wprintf("<tr><td>");
3002 wprintf("<font size=-1>");
3006 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
3007 escputs(bstr("recp"));
3008 wprintf("\" size=50 maxlength=1000 />");
3009 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
3010 wprintf("</td><td></td></tr>\n");
3012 wprintf("<tr><td>");
3013 wprintf("<font size=-1>");
3017 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
3018 escputs(bstr("cc"));
3019 wprintf("\" size=50 maxlength=1000 />");
3020 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
3021 wprintf("</td><td></td></tr>\n");
3023 wprintf("<tr><td>");
3024 wprintf("<font size=-1>");
3028 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
3029 escputs(bstr("bcc"));
3030 wprintf("\" size=50 maxlength=1000 />");
3031 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
3032 wprintf("</td><td></td></tr>\n");
3034 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
3035 wprintf("<script type=\"text/javascript\"> \n"
3036 " activate_entmsg_autocompleters(); \n"
3041 wprintf("<tr><td>");
3042 wprintf("<font size=-1>");
3043 wprintf(_("Subject (optional):"));
3046 "<input type=\"text\" name=\"subject\" value=\"");
3047 escputs(bstr("subject"));
3048 wprintf("\" size=50 maxlength=70></td><td>\n");
3050 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3051 if (recipient_required) {
3052 wprintf(_("Send message"));
3054 wprintf(_("Post message"));
3057 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3058 wprintf("</td></tr></table>\n");
3060 wprintf("<center>");
3062 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
3064 /** If we're continuing from a previous edit, put our partially-composed message back... */
3065 msgescputs(bstr("msgtext"));
3067 /* If we're forwarding a message, insert it here... */
3068 if (atol(bstr("fwdquote")) > 0L) {
3069 wprintf("<br><div align=center><i>");
3070 wprintf(_("--- forwarded message ---"));
3071 wprintf("</i></div><br>");
3072 pullquote_message(atol(bstr("fwdquote")), 1, 1);
3075 /** If we're replying quoted, insert the quote here... */
3076 else if (atol(bstr("replyquote")) > 0L) {
3079 pullquote_message(atol(bstr("replyquote")), 0, 1);
3080 wprintf("</blockquote><br>");
3083 /** If we're editing a wiki page, insert the existing page here... */
3084 else if (WC->wc_view == VIEW_WIKI) {
3085 safestrncpy(buf, bstr("wikipage"), sizeof buf);
3086 str_wiki_index(buf);
3087 existing_page = locate_message_by_uid(buf);
3088 if (existing_page >= 0L) {
3089 pullquote_message(existing_page, 1, 0);
3093 /** Insert our signature if appropriate... */
3094 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
3095 get_preference("use_sig", buf, sizeof buf);
3096 if (!strcasecmp(buf, "yes")) {
3097 get_preference("signature", ebuf, sizeof ebuf);
3098 euid_unescapize(buf, ebuf);
3099 wprintf("<br>--<br>");
3100 for (i=0; i<strlen(buf); ++i) {
3101 if (buf[i] == '\n') {
3104 else if (buf[i] == '<') {
3107 else if (buf[i] == '>') {
3110 else if (buf[i] == '&') {
3113 else if (buf[i] == '\"') {
3116 else if (buf[i] == '\'') {
3119 else if (isprint(buf[i])) {
3120 wprintf("%c", buf[i]);
3126 wprintf("</textarea>");
3127 wprintf("</center><br />\n");
3130 * The following script embeds the TinyMCE richedit control, and automatically
3131 * transforms the textarea into a richedit textarea.
3134 "<script language=\"javascript\" type=\"text/javascript\" src=\"tiny_mce/tiny_mce.js\"></script>\n"
3135 "<script language=\"javascript\" type=\"text/javascript\">"
3137 " mode : \"textareas\", width : \"100%%\", browsers : \"msie,gecko\", "
3138 " theme : \"advanced\", plugins : \"iespell\", "
3139 " theme_advanced_buttons1 : \"bold, italic, underline, strikethrough, justifyleft, justifycenter, justifyright, justifyfull, bullist, numlist, cut, copy, paste, link, image, help, forecolor, iespell, code\", "
3140 " theme_advanced_buttons2 : \"\", "
3141 " theme_advanced_buttons3 : \"\", "
3142 " content_css : \"static/webcit-tinymce.css\" "
3148 /** Enumerate any attachments which are already in place... */
3149 wprintf("<img src=\"static/diskette_24x.gif\" border=0 "
3150 "align=middle height=16 width=16> ");
3151 wprintf(_("Attachments:"));
3153 wprintf("<select name=\"which_attachment\" size=1>");
3154 for (att = WC->first_attachment; att != NULL; att = att->next) {
3155 wprintf("<option value=\"");
3156 urlescputs(att->filename);
3158 escputs(att->filename);
3159 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3160 wprintf("</option>\n");
3162 wprintf("</select>");
3164 /** Now offer the ability to attach additional files... */
3165 wprintf(" ");
3166 wprintf(_("Attach file:"));
3167 wprintf(" <input NAME=\"attachfile\" "
3168 "SIZE=16 TYPE=\"file\">\n "
3169 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3171 /** Seth asked for these to be at the top *and* bottom... */
3172 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3173 if (recipient_required) {
3174 wprintf(_("Send message"));
3176 wprintf(_("Post message"));
3179 "<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");
3188 wprintf("</td></tr></table></div>\n");
3189 DONE: wDumpContent(1);
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");