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 */
130 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, strlen(istr));
133 strcpy(ibuf, istr); /**< unknown encoding */
134 ibuflen = strlen(istr);
137 ic = ctdl_iconv_open("UTF-8", charset);
138 if (ic != (iconv_t)(-1) ) {
140 obuf = (char *) malloc(obuflen);
142 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
143 osav[1024-obuflen] = 0;
148 remove_token(end, 0, '?');
149 remove_token(end, 0, '?');
150 remove_token(end, 0, '?');
151 remove_token(end, 0, '?');
152 strcpy(end, &end[1]);
154 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
163 remove_token(end, 0, '?');
164 remove_token(end, 0, '?');
165 remove_token(end, 0, '?');
166 remove_token(end, 0, '?');
167 strcpy(end, &end[1]);
169 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
176 * Since spammers will go to all sorts of absurd lengths to get their
177 * messages through, there are LOTS of corrupt headers out there.
178 * So, prevent a really badly formed RFC2047 header from throwing
179 * this function into an infinite loop.
182 if (passes > 20) return;
192 * \brief RFC2047-encode a header field if necessary.
193 * If no non-ASCII characters are found, the string
194 * will be copied verbatim without encoding.
196 * \param target Target buffer.
197 * \param maxlen Maximum size of target buffer.
198 * \param source Source string to be encoded.
200 void rfc2047encode(char *target, int maxlen, char *source)
202 int need_to_encode = 0;
206 if (target == NULL) return;
208 for (i=0; i<strlen(source); ++i) {
209 if ((source[i] < 32) || (source[i] > 126)) {
214 if (!need_to_encode) {
215 safestrncpy(target, source, maxlen);
219 strcpy(target, "=?UTF-8?Q?");
220 for (i=0; i<strlen(source); ++i) {
221 ch = (unsigned char) source[i];
222 if ((ch < 32) || (ch > 126) || (ch == 61)) {
223 sprintf(&target[strlen(target)], "=%02X", ch);
226 sprintf(&target[strlen(target)], "%c", ch);
230 strcat(target, "?=");
237 * \brief Look for URL's embedded in a buffer and make them linkable. We use a
238 * target window in order to keep the BBS session in its own window.
239 * \param buf the message buffer
254 for (pos = 0; pos < strlen(buf); ++pos) {
255 if (!strncasecmp(&buf[pos], "http://", 7))
257 if (!strncasecmp(&buf[pos], "ftp://", 6))
264 if ((start > 0) && (buf[start - 1] == '<'))
266 if ((start > 0) && (buf[start - 1] == '['))
268 if ((start > 0) && (buf[start - 1] == '('))
270 if ((start > 0) && (buf[start - 1] == '{'))
273 for (pos = strlen(buf); pos > start; --pos) {
274 if ((buf[pos] == ' ') || (buf[pos] == ench))
278 strncpy(urlbuf, &buf[start], end - start);
279 urlbuf[end - start] = 0;
281 strncpy(outbuf, buf, start);
282 sprintf(&outbuf[start], "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
283 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
284 strcat(outbuf, &buf[end]);
285 if ( strlen(outbuf) < 250 )
291 * \brief Turn a vCard "n" (name) field into something displayable.
292 * \param name the name field to convert
294 void vcard_n_prettyize(char *name)
299 original_name = strdup(name);
300 for (i=0; i<5; ++i) {
301 if (strlen(original_name) > 0) {
302 if (original_name[strlen(original_name)-1] == ' ') {
303 original_name[strlen(original_name)-1] = 0;
305 if (original_name[strlen(original_name)-1] == ';') {
306 original_name[strlen(original_name)-1] = 0;
311 for (i=0; i<strlen(original_name); ++i) {
312 if (original_name[i] == ';') {
316 name[strlen(name)+1] = 0;
317 name[strlen(name)] = original_name[i];
327 * \brief preparse a vcard name
328 * display_vcard() calls this after parsing the textual vCard into
329 * our 'struct vCard' data object.
330 * This gets called instead of display_parsed_vcard() if we are only looking
331 * to extract the person's name instead of displaying the card.
332 * \param v the vcard to retrieve the name from
333 * \param storename where to put the name at
335 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
338 strcpy(storename, "");
340 name = vcard_get_prop(v, "n", 1, 0, 0);
342 strcpy(storename, name);
343 /* vcard_n_prettyize(storename); */
351 * \brief html print a vcard
352 * display_vcard() calls this after parsing the textual vCard into
353 * our 'struct vCard' data object.
355 * Set 'full' to nonzero to display the full card, otherwise it will only
356 * show a summary line.
358 * This code is a bit ugly, so perhaps an explanation is due: we do this
359 * in two passes through the vCard fields. On the first pass, we process
360 * fields we understand, and then render them in a pretty fashion at the
361 * end. Then we make a second pass, outputting all the fields we don't
362 * understand in a simple two-column name/value format.
363 * \param v the vCard to display
364 * \param full display all items of the vcard?
366 void display_parsed_vcard(struct vCard *v, int full) {
372 char *thisname, *thisvalue;
373 char firsttoken[SIZ];
382 strcpy(fullname, "");
390 name = vcard_get_prop(v, "fn", 1, 0, 0);
394 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
395 strcpy(fullname, name);
396 vcard_n_prettyize(fullname);
406 wprintf("<div align=center><table bgcolor=#aaaaaa width=50%%>");
407 for (pass=1; pass<=2; ++pass) {
409 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
411 thisname = strdup(v->prop[i].name);
412 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
414 for (j=0; j<num_tokens(thisname, ';'); ++j) {
415 extract_token(buf, thisname, j, ';', sizeof buf);
416 if (!strcasecmp(buf, "encoding=quoted-printable")) {
418 remove_token(thisname, j, ';');
420 if (!strcasecmp(buf, "encoding=base64")) {
422 remove_token(thisname, j, ';');
427 thisvalue = malloc(strlen(v->prop[i].value) + 50);
428 j = CtdlDecodeQuotedPrintable(
429 thisvalue, v->prop[i].value,
430 strlen(v->prop[i].value) );
434 thisvalue = malloc(strlen(v->prop[i].value) + 50);
436 thisvalue, v->prop[i].value,
437 strlen(v->prop[i].value) );
440 thisvalue = strdup(v->prop[i].value);
443 /** Various fields we may encounter ***/
445 /** N is name, but only if there's no FN already there */
446 if (!strcasecmp(firsttoken, "n")) {
447 if (strlen(fullname) == 0) {
448 strcpy(fullname, thisvalue);
449 vcard_n_prettyize(fullname);
453 /** FN (full name) is a true 'display name' field */
454 else if (!strcasecmp(firsttoken, "fn")) {
455 strcpy(fullname, thisvalue);
459 else if (!strcasecmp(firsttoken, "title")) {
460 strcpy(title, thisvalue);
464 else if (!strcasecmp(firsttoken, "org")) {
465 strcpy(org, thisvalue);
468 else if (!strcasecmp(firsttoken, "email")) {
469 if (strlen(mailto) > 0) strcat(mailto, "<br />");
471 "<a href=\"display_enter"
472 "?force_room=_MAIL_?recp=");
474 urlesc(&mailto[strlen(mailto)], fullname);
475 urlesc(&mailto[strlen(mailto)], " <");
476 urlesc(&mailto[strlen(mailto)], thisvalue);
477 urlesc(&mailto[strlen(mailto)], ">");
479 strcat(mailto, "\">");
480 stresc(&mailto[strlen(mailto)], thisvalue, 1, 1);
481 strcat(mailto, "</A>");
483 else if (!strcasecmp(firsttoken, "tel")) {
484 if (strlen(phone) > 0) strcat(phone, "<br />");
485 strcat(phone, thisvalue);
486 for (j=0; j<num_tokens(thisname, ';'); ++j) {
487 extract_token(buf, thisname, j, ';', sizeof buf);
488 if (!strcasecmp(buf, "tel"))
490 else if (!strcasecmp(buf, "work"))
491 strcat(phone, _(" (work)"));
492 else if (!strcasecmp(buf, "home"))
493 strcat(phone, _(" (home)"));
494 else if (!strcasecmp(buf, "cell"))
495 strcat(phone, _(" (cell)"));
503 else if (!strcasecmp(firsttoken, "adr")) {
506 wprintf(_("Address:"));
507 wprintf("</TD><TD>");
508 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
509 extract_token(buf, thisvalue, j, ';', sizeof buf);
510 if (strlen(buf) > 0) {
512 if (j<3) wprintf("<br />");
516 wprintf("</TD></TR>\n");
519 else if (!strcasecmp(firsttoken, "version")) {
522 else if (!strcasecmp(firsttoken, "rev")) {
525 else if (!strcasecmp(firsttoken, "label")) {
530 /*** Don't show extra fields. They're ugly.
534 wprintf("</TD><TD>");
536 wprintf("</TD></TR>\n");
546 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
547 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
548 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
549 "<FONT SIZE=+1><B>");
551 wprintf("</B></FONT>");
552 if (strlen(title) > 0) {
553 wprintf("<div align=right>");
557 if (strlen(org) > 0) {
558 wprintf("<div align=right>");
562 wprintf("</TD></TR>\n");
564 if (strlen(phone) > 0) {
566 wprintf(_("Telephone:"));
567 wprintf("</td><td>%s</td></tr>\n", phone);
569 if (strlen(mailto) > 0) {
571 wprintf(_("E-mail:"));
572 wprintf("</td><td>%s</td></tr>\n", mailto);
578 wprintf("</table></div>\n");
584 * \brief Display a textual vCard
585 * (Converts to a vCard object and then calls the actual display function)
586 * Set 'full' to nonzero to display the whole card instead of a one-liner.
587 * Or, if "storename" is non-NULL, just store the person's name in that
588 * buffer instead of displaying the card at all.
589 * \param vcard_source the buffer containing the vcard text
590 * \param alpha what???
591 * \param full should we usse all lines?
592 * \param storename where to store???
594 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
600 v = vcard_load(vcard_source);
601 if (v == NULL) return;
603 name = vcard_get_prop(v, "n", 1, 0, 0);
609 if (storename != NULL) {
610 fetchname_parsed_vcard(v, storename);
612 else if ( (alpha == 0)
613 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
614 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
616 display_parsed_vcard(v, full);
624 * \brief I wanna SEE that message!
625 * \param msgnum the citadel number of the message to display
626 * \param printable_view are we doing a print view?
627 * \param section Optional for encapsulated message/rfc822 submessage)
629 void read_message(long msgnum, int printable_view, char *section) {
631 char mime_partnum[256];
632 char mime_filename[256];
633 char mime_content_type[256];
634 char mime_charset[256];
635 char mime_disposition[256];
638 char mime_submessages[256];
645 char reply_all[4096];
651 char vcard_partnum[256];
652 char cal_partnum[256];
653 char *part_source = NULL;
655 iconv_t ic = (iconv_t)(-1) ;
656 char *ibuf; /**< Buffer of characters to be converted */
657 char *obuf; /**< Buffer for converted characters */
658 size_t ibuflen; /**< Length of input buffer */
659 size_t obuflen; /**< Length of output buffer */
660 char *osav; /**< Saved pointer to output buffer */
666 strcpy(reply_to, "");
667 strcpy(reply_all, "");
668 strcpy(vcard_partnum, "");
669 strcpy(cal_partnum, "");
670 strcpy(mime_http, "");
671 strcpy(mime_content_type, "text/plain");
672 strcpy(mime_charset, "us-ascii");
673 strcpy(mime_submessages, "");
675 serv_printf("MSG4 %ld|%s", msgnum, section);
676 serv_getln(buf, sizeof buf);
679 wprintf(_("ERROR:"));
680 wprintf("</STRONG> %s<br />\n", &buf[4]);
684 /** begin everythingamundo table */
685 if (!printable_view) {
686 wprintf("<div class=\"fix_scrollbar_bug\">\n");
687 wprintf("<table width=100%% border=1 cellspacing=0 "
688 "cellpadding=0><TR><TD>\n");
691 /** begin message header table */
692 wprintf("<table width=100%% border=0 cellspacing=0 "
693 "cellpadding=1 bgcolor=\"#CCCCCC\"><tr><td>\n");
695 wprintf("<span class=\"message_header\">");
696 strcpy(m_subject, "");
699 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
700 if (!strcmp(buf, "000")) {
702 wprintf(_("unexpected end of message"));
703 wprintf("</i><br /><br />\n");
704 wprintf("</span>\n");
707 if (!strncasecmp(buf, "nhdr=yes", 8))
711 if (!strncasecmp(buf, "type=", 5))
712 format_type = atoi(&buf[5]);
713 if (!strncasecmp(buf, "from=", 5)) {
714 strcpy(from, &buf[5]);
716 wprintf("<a href=\"showuser?who=");
718 utf8ify_rfc822_string(from);
725 if (!strncasecmp(buf, "subj=", 5)) {
726 safestrncpy(m_subject, &buf[5], sizeof m_subject);
728 if (!strncasecmp(buf, "cccc=", 5)) {
729 safestrncpy(m_cc, &buf[5], sizeof m_cc);
730 if (strlen(reply_all) > 0) {
731 strcat(reply_all, ", ");
733 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
734 (sizeof reply_all - strlen(reply_all)) );
736 if ((!strncasecmp(buf, "hnod=", 5))
737 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
738 wprintf("(%s) ", &buf[5]);
740 if ((!strncasecmp(buf, "room=", 5))
741 && (strcasecmp(&buf[5], WC->wc_roomname))
742 && (strlen(&buf[5])>0) ) {
744 wprintf("%s> ", &buf[5]);
746 if (!strncasecmp(buf, "rfca=", 5)) {
747 strcpy(rfca, &buf[5]);
753 if (!strncasecmp(buf, "node=", 5)) {
754 strcpy(node, &buf[5]);
755 if ( ((WC->room_flags & QR_NETWORK)
756 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
757 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
760 wprintf("@%s ", &buf[5]);
763 if (!strncasecmp(buf, "rcpt=", 5)) {
765 if (strlen(reply_all) > 0) {
766 strcat(reply_all, ", ");
768 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
769 (sizeof reply_all - strlen(reply_all)) );
771 utf8ify_rfc822_string(&buf[5]);
776 if (!strncasecmp(buf, "time=", 5)) {
777 fmt_date(now, atol(&buf[5]), 0);
781 if (!strncasecmp(buf, "part=", 5)) {
782 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
783 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
784 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
785 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
786 mime_length = extract_int(&buf[5], 5);
788 if (!strcasecmp(mime_content_type, "message/rfc822")) {
789 if (strlen(mime_submessages) > 0) {
790 strcat(mime_submessages, "|");
792 strcat(mime_submessages, mime_partnum);
794 else if ((!strcasecmp(mime_disposition, "inline"))
795 && (!strncasecmp(mime_content_type, "image/", 6)) ){
796 snprintf(&mime_http[strlen(mime_http)],
797 (sizeof(mime_http) - strlen(mime_http) - 1),
798 "<img src=\"mimepart/%ld/%s/%s\">",
799 msgnum, mime_partnum, mime_filename);
801 else if ( (!strcasecmp(mime_disposition, "attachment"))
802 || (!strcasecmp(mime_disposition, "inline")) ) {
803 snprintf(&mime_http[strlen(mime_http)],
804 (sizeof(mime_http) - strlen(mime_http) - 1),
805 "<img src=\"static/diskette_24x.gif\" "
806 "border=0 align=middle>\n"
807 "%s (%s, %d bytes) [ "
808 "<a href=\"mimepart/%ld/%s/%s\""
809 "target=\"wc.%ld.%s\">%s</a>"
811 "<a href=\"mimepart_download/%ld/%s/%s\">%s</a>"
814 mime_content_type, mime_length,
815 msgnum, mime_partnum, mime_filename,
816 msgnum, mime_partnum,
818 msgnum, mime_partnum, mime_filename,
823 /** begin handler prep ***/
824 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
825 strcpy(vcard_partnum, mime_partnum);
828 if (!strcasecmp(mime_content_type, "text/calendar")) {
829 strcpy(cal_partnum, mime_partnum);
832 /** end handler prep ***/
838 /** Generate a reply-to address */
839 if (strlen(rfca) > 0) {
840 strcpy(reply_to, rfca);
843 if ( (strlen(node) > 0)
844 && (strcasecmp(node, serv_info.serv_nodename))
845 && (strcasecmp(node, serv_info.serv_humannode)) ) {
846 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
850 snprintf(reply_to, sizeof(reply_to), "%s", from);
860 utf8ify_rfc822_string(m_cc);
861 utf8ify_rfc822_string(m_subject);
863 if (strlen(m_cc) > 0) {
865 "<span class=\"message_subject\">");
871 if (strlen(m_subject) > 0) {
873 "<span class=\"message_subject\">");
874 wprintf(_("Subject:"));
881 /** start msg buttons */
882 if (!printable_view) {
883 wprintf("<td align=right><span class=\"msgbuttons\">\n");
886 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
887 wprintf("<a href=\"display_enter");
888 if (WC->is_mailbox) {
889 wprintf("?replyquote=%ld", msgnum);
892 urlescputs(reply_to);
893 if (strlen(m_subject) > 0) {
894 wprintf("?subject=");
895 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
896 urlescputs(m_subject);
898 wprintf("\">[%s]</a> ", _("Reply"));
902 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
903 if (!WC->is_mailbox) {
904 wprintf("<a href=\"display_enter");
905 wprintf("?replyquote=%ld", msgnum);
907 urlescputs(reply_to);
908 if (strlen(m_subject) > 0) {
909 wprintf("?subject=");
910 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
911 urlescputs(m_subject);
913 wprintf("\">[%s]</a> ", _("ReplyQuoted"));
918 if (WC->wc_view == VIEW_MAILBOX) {
919 wprintf("<a href=\"display_enter");
920 wprintf("?replyquote=%ld", msgnum);
922 urlescputs(reply_to);
924 urlescputs(reply_all);
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> ", _("ReplyAll"));
934 if (WC->wc_view == VIEW_MAILBOX) {
935 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
936 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
937 urlescputs(m_subject);
938 wprintf("\">[%s]</a> ", _("Forward"));
941 /** If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
942 if ( (WC->is_room_aide) || (WC->is_mailbox) ) {
944 wprintf("<a href=\"confirm_move_msg?msgid=%ld\">[%s]</a> ",
948 wprintf("<a href=\"delete_msg?msgid=%ld\" "
949 "onClick=\"return confirm('%s');\">"
950 "[%s]</a> ", msgnum, _("Delete this message?"), _("Delete")
955 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'); \" >"
956 "[%s]</a>", msgnum, msgnum, _("Headers"));
960 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'); \" >"
961 "[%s]</a>", msgnum, msgnum, _("Print"));
963 wprintf("</span></td>");
966 wprintf("</tr></table>\n");
969 wprintf("<table border=0 width=100%% bgcolor=\"#FFFFFF\" "
970 "cellpadding=1 cellspacing=0><tr><td>");
973 * Learn the content type
975 strcpy(mime_content_type, "text/plain");
976 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
977 if (!strcmp(buf, "000")) {
979 wprintf(_("unexpected end of message"));
980 wprintf("</i><br /><br />\n");
983 if (!strncasecmp(buf, "Content-type: ", 14)) {
984 safestrncpy(mime_content_type, &buf[14],
985 sizeof(mime_content_type));
986 for (i=0; i<strlen(mime_content_type); ++i) {
987 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
988 safestrncpy(mime_charset, &mime_content_type[i+8],
989 sizeof mime_charset);
992 for (i=0; i<strlen(mime_content_type); ++i) {
993 if (mime_content_type[i] == ';') {
994 mime_content_type[i] = 0;
997 for (i=0; i<strlen(mime_charset); ++i) {
998 if (mime_charset[i] == ';') {
1005 /** Set up a character set conversion if we need to (and if we can) */
1007 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
1008 if ( (strcasecmp(mime_charset, "us-ascii"))
1009 && (strcasecmp(mime_charset, "UTF-8"))
1010 && (strcasecmp(mime_charset, ""))
1012 ic = ctdl_iconv_open("UTF-8", mime_charset);
1013 if (ic == (iconv_t)(-1) ) {
1014 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1015 __FILE__, __LINE__, mime_charset, strerror(errno));
1020 /** Messages in legacy Citadel variformat get handled thusly... */
1021 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1025 /** Boring old 80-column fixed format text gets handled this way... */
1026 else if ( (!strcasecmp(mime_content_type, "text/plain"))
1027 || (!strcasecmp(mime_content_type, "text")) ) {
1028 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1029 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1030 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1033 if (ic != (iconv_t)(-1) ) {
1035 ibuflen = strlen(ibuf);
1037 obuf = (char *) malloc(obuflen);
1039 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1040 osav[SIZ-obuflen] = 0;
1041 safestrncpy(buf, osav, sizeof buf);
1046 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1047 buf[strlen(buf) - 1] = 0;
1049 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1050 wprintf("<blockquote>");
1052 } else if ((bq == 1) &&
1053 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1054 wprintf("</blockquote>");
1060 wprintf("</tt><br />\n");
1062 wprintf("</i><br />");
1065 else /** HTML is fun, but we've got to strip it first */
1066 if (!strcasecmp(mime_content_type, "text/html")) {
1067 output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
1070 /** Unknown weirdness */
1072 wprintf(_("I don't know how to display %s"), mime_content_type);
1073 wprintf("<br />\n", mime_content_type);
1074 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1077 /** If there are attached submessages, display them now... */
1078 if ( (strlen(mime_submessages) > 0) && (!section[0]) ) {
1079 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1080 extract_token(buf, mime_submessages, i, '|', sizeof buf);
1081 /** use printable_view to suppress buttons */
1082 wprintf("<blockquote>");
1083 read_message(msgnum, 1, buf);
1084 wprintf("</blockquote>");
1089 /** Afterwards, offer links to download attachments 'n' such */
1090 if ( (strlen(mime_http) > 0) && (!section[0]) ) {
1091 wprintf("%s", mime_http);
1094 /** Handler for vCard parts */
1095 if (strlen(vcard_partnum) > 0) {
1096 part_source = load_mimepart(msgnum, vcard_partnum);
1097 if (part_source != NULL) {
1099 /** If it's my vCard I can edit it */
1100 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1101 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1102 || (WC->wc_view == VIEW_ADDRESSBOOK)
1104 wprintf("<a href=\"edit_vcard?"
1105 "msgnum=%ld?partnum=%s\">",
1106 msgnum, vcard_partnum);
1107 wprintf("[%s]</a>", _("edit"));
1110 /** In all cases, display the full card */
1111 display_vcard(part_source, 0, 1, NULL);
1115 /** Handler for calendar parts */
1116 if (strlen(cal_partnum) > 0) {
1117 part_source = load_mimepart(msgnum, cal_partnum);
1118 if (part_source != NULL) {
1119 cal_process_attachment(part_source,
1120 msgnum, cal_partnum);
1130 wprintf("</td></tr></table>\n");
1132 /** end everythingamundo table */
1133 if (!printable_view) {
1134 wprintf("</td></tr></table>\n");
1135 wprintf("</div><br />\n");
1139 if (ic != (iconv_t)(-1) ) {
1148 * \brief Unadorned HTML output of an individual message, suitable
1149 * for placing in a hidden iframe, for printing, or whatever
1151 * \param msgnum_as_string Message number, as a string instead of as a long int
1153 void embed_message(char *msgnum_as_string) {
1156 msgnum = atol(msgnum_as_string);
1157 begin_ajax_response();
1158 read_message(msgnum, 0, "");
1159 end_ajax_response();
1164 * \brief Printable view of a message
1166 * \param msgnum_as_string Message number, as a string instead of as a long int
1168 void print_message(char *msgnum_as_string) {
1171 msgnum = atol(msgnum_as_string);
1172 output_headers(0, 0, 0, 0, 0, 0);
1174 wprintf("Content-type: text/html\r\n"
1176 "Connection: close\r\n",
1180 wprintf("\r\n\r\n<html>\n"
1181 "<head><title>Printable view</title></head>\n"
1182 "<body onLoad=\" window.print(); window.close(); \">\n"
1185 read_message(msgnum, 1, "");
1187 wprintf("\n</body></html>\n\n");
1194 * \brief Display a message's headers
1196 * \param msgnum_as_string Message number, as a string instead of as a long int
1198 void display_headers(char *msgnum_as_string) {
1202 msgnum = atol(msgnum_as_string);
1203 output_headers(0, 0, 0, 0, 0, 0);
1205 wprintf("Content-type: text/plain\r\n"
1207 "Connection: close\r\n",
1211 serv_printf("MSG2 %ld|3", msgnum);
1212 serv_getln(buf, sizeof buf);
1213 if (buf[0] == '1') {
1214 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1215 wprintf("%s\n", buf);
1225 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1226 * or 'reply quoted' operations.
1228 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1229 * in this function. Doing so would throw a JavaScript error in the
1230 * 'supplied text' argument to the editor.
1232 * \param msgnum Message number of the message we want to quote
1233 * \param forward_attachments Nonzero if we want attachments to be forwarded
1235 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1237 char mime_partnum[256];
1238 char mime_filename[256];
1239 char mime_content_type[256];
1240 char mime_charset[256];
1241 char mime_disposition[256];
1243 char *attachments = NULL;
1245 int num_attachments = 0;
1246 struct wc_attachment *att, *aptr;
1247 char m_subject[256];
1253 int format_type = 0;
1258 iconv_t ic = (iconv_t)(-1) ;
1259 char *ibuf; /**< Buffer of characters to be converted */
1260 char *obuf; /**< Buffer for converted characters */
1261 size_t ibuflen; /**< Length of input buffer */
1262 size_t obuflen; /**< Length of output buffer */
1263 char *osav; /**< Saved pointer to output buffer */
1269 strcpy(reply_to, "");
1270 strcpy(mime_content_type, "text/plain");
1271 strcpy(mime_charset, "us-ascii");
1273 serv_printf("MSG4 %ld", msgnum);
1274 serv_getln(buf, sizeof buf);
1275 if (buf[0] != '1') {
1276 wprintf(_("ERROR:"));
1277 wprintf("%s<br />", &buf[4]);
1281 strcpy(m_subject, "");
1283 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1284 if (!strcmp(buf, "000")) {
1285 wprintf(_("unexpected end of message"));
1288 if (include_headers) {
1289 if (!strncasecmp(buf, "nhdr=yes", 8))
1293 if (!strncasecmp(buf, "type=", 5))
1294 format_type = atoi(&buf[5]);
1295 if (!strncasecmp(buf, "from=", 5)) {
1296 strcpy(from, &buf[5]);
1297 wprintf(_("from "));
1299 utf8ify_rfc822_string(from);
1303 if (!strncasecmp(buf, "subj=", 5)) {
1304 strcpy(m_subject, &buf[5]);
1306 if ((!strncasecmp(buf, "hnod=", 5))
1307 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1308 wprintf("(%s) ", &buf[5]);
1310 if ((!strncasecmp(buf, "room=", 5))
1311 && (strcasecmp(&buf[5], WC->wc_roomname))
1312 && (strlen(&buf[5])>0) ) {
1314 wprintf("%s> ", &buf[5]);
1316 if (!strncasecmp(buf, "rfca=", 5)) {
1317 strcpy(rfca, &buf[5]);
1323 if (!strncasecmp(buf, "node=", 5)) {
1324 strcpy(node, &buf[5]);
1325 if ( ((WC->room_flags & QR_NETWORK)
1326 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1327 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1328 && (strlen(rfca)==0)
1330 wprintf("@%s ", &buf[5]);
1333 if (!strncasecmp(buf, "rcpt=", 5)) {
1335 wprintf("%s ", &buf[5]);
1337 if (!strncasecmp(buf, "time=", 5)) {
1338 fmt_date(now, atol(&buf[5]), 0);
1339 wprintf("%s ", now);
1344 * Save attachment info for later. We can't start downloading them
1345 * yet because we're in the middle of a server transaction.
1347 if (!strncasecmp(buf, "part=", 5)) {
1348 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1351 sprintf(ptr, "%s%s\n",
1352 ((attachments != NULL) ? attachments : ""),
1357 lprintf(9, "attachments=<%s>\n", attachments);
1363 if (include_headers) {
1367 utf8ify_rfc822_string(m_subject);
1369 if (strlen(m_subject) > 0) {
1370 wprintf(_("Subject:"));
1372 msgescputs(m_subject);
1383 * Learn the content type
1385 strcpy(mime_content_type, "text/plain");
1386 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1387 if (!strcmp(buf, "000")) {
1388 wprintf(_("unexpected end of message"));
1391 if (!strncasecmp(buf, "Content-type: ", 14)) {
1392 safestrncpy(mime_content_type, &buf[14],
1393 sizeof(mime_content_type));
1394 for (i=0; i<strlen(mime_content_type); ++i) {
1395 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1396 safestrncpy(mime_charset, &mime_content_type[i+8],
1397 sizeof mime_charset);
1400 for (i=0; i<strlen(mime_content_type); ++i) {
1401 if (mime_content_type[i] == ';') {
1402 mime_content_type[i] = 0;
1405 for (i=0; i<strlen(mime_charset); ++i) {
1406 if (mime_charset[i] == ';') {
1407 mime_charset[i] = 0;
1413 /** Set up a character set conversion if we need to (and if we can) */
1415 if ( (strcasecmp(mime_charset, "us-ascii"))
1416 && (strcasecmp(mime_charset, "UTF-8"))
1417 && (strcasecmp(mime_charset, ""))
1419 ic = ctdl_iconv_open("UTF-8", mime_charset);
1420 if (ic == (iconv_t)(-1) ) {
1421 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1422 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1427 /** Messages in legacy Citadel variformat get handled thusly... */
1428 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1432 /* Boring old 80-column fixed format text gets handled this way... */
1433 else if (!strcasecmp(mime_content_type, "text/plain")) {
1434 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1435 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1436 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1439 if (ic != (iconv_t)(-1) ) {
1441 ibuflen = strlen(ibuf);
1443 obuf = (char *) malloc(obuflen);
1445 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1446 osav[SIZ-obuflen] = 0;
1447 safestrncpy(buf, osav, sizeof buf);
1452 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1453 buf[strlen(buf) - 1] = 0;
1455 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1456 wprintf("<blockquote>");
1458 } else if ((bq == 1) &&
1459 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1460 wprintf("</blockquote>");
1466 wprintf("</tt><br />");
1468 wprintf("</i><br />");
1471 /** HTML just gets escaped and stuffed back into the editor */
1472 else if (!strcasecmp(mime_content_type, "text/html")) {
1473 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1479 /** Unknown weirdness ... don't know how to handle this content type */
1481 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1485 /** end of body handler */
1488 * If there were attachments, we have to download them and insert them
1489 * into the attachment chain for the forwarded message we are composing.
1491 if ( (forward_attachments) && (num_attachments) ) {
1492 for (i=0; i<num_attachments; ++i) {
1493 extract_token(buf, attachments, i, '\n', sizeof buf);
1494 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1495 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1496 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1497 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1498 mime_length = extract_int(buf, 5);
1501 * tracing ... uncomment if necessary
1504 lprintf(9, "fwd filename: %s\n", mime_filename);
1505 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1506 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1507 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1508 lprintf(9, "fwd length : %d\n", mime_length);
1510 if ( (!strcasecmp(mime_disposition, "inline"))
1511 || (!strcasecmp(mime_disposition, "attachment")) ) {
1513 /* Create an attachment struct from this mime part... */
1514 att = malloc(sizeof(struct wc_attachment));
1515 memset(att, 0, sizeof(struct wc_attachment));
1516 att->length = mime_length;
1517 strcpy(att->content_type, mime_content_type);
1518 strcpy(att->filename, mime_filename);
1520 att->data = load_mimepart(msgnum, mime_partnum);
1522 /* And add it to the list. */
1523 if (WC->first_attachment == NULL) {
1524 WC->first_attachment = att;
1527 aptr = WC->first_attachment;
1528 while (aptr->next != NULL) aptr = aptr->next;
1537 if (ic != (iconv_t)(-1) ) {
1542 if (attachments != NULL) {
1548 * \brief Display one row in the mailbox summary view
1550 * \param num The row number to be displayed
1552 void display_summarized(int num) {
1555 wprintf("<tr id=\"m%ld\" style=\"width:100%%;font-weight:%s;background-color:#ffffff\" "
1556 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1557 WC->summ[num].msgnum,
1558 (WC->summ[num].is_new ? "bold" : "normal"),
1559 WC->summ[num].msgnum
1562 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1563 escputs(WC->summ[num].subj);
1566 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1567 escputs(WC->summ[num].from);
1570 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1571 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1581 * \brief display the adressbook overview
1582 * \param msgnum the citadel message number
1583 * \param alpha what????
1585 void display_addressbook(long msgnum, char alpha) {
1587 char mime_partnum[SIZ];
1588 char mime_filename[SIZ];
1589 char mime_content_type[SIZ];
1590 char mime_disposition[SIZ];
1592 char vcard_partnum[SIZ];
1593 char *vcard_source = NULL;
1594 struct message_summary summ;
1596 memset(&summ, 0, sizeof(summ));
1597 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1599 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1601 serv_getln(buf, sizeof buf);
1602 if (buf[0] != '1') return;
1604 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1605 if (!strncasecmp(buf, "part=", 5)) {
1606 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1607 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1608 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1609 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1610 mime_length = extract_int(&buf[5], 5);
1612 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1613 strcpy(vcard_partnum, mime_partnum);
1619 if (strlen(vcard_partnum) > 0) {
1620 vcard_source = load_mimepart(msgnum, vcard_partnum);
1621 if (vcard_source != NULL) {
1623 /** Display the summary line */
1624 display_vcard(vcard_source, alpha, 0, NULL);
1626 /** If it's my vCard I can edit it */
1627 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1628 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1629 || (WC->wc_view == VIEW_ADDRESSBOOK)
1631 wprintf("<a href=\"edit_vcard?"
1632 "msgnum=%ld?partnum=%s\">",
1633 msgnum, vcard_partnum);
1634 wprintf("[%s]</a>", _("edit"));
1646 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1647 * \param namebuf name to analyze, reverse if nescessary
1649 void lastfirst_firstlast(char *namebuf) {
1650 char firstname[SIZ];
1654 if (namebuf == NULL) return;
1655 if (strchr(namebuf, ';') != NULL) return;
1657 i = num_tokens(namebuf, ' ');
1660 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1661 remove_token(namebuf, i-1, ' ');
1662 strcpy(firstname, namebuf);
1663 sprintf(namebuf, "%s; %s", lastname, firstname);
1667 * \brief fetch what??? name
1668 * \param msgnum the citadel message number
1669 * \param namebuf where to put the name in???
1671 void fetch_ab_name(long msgnum, char *namebuf) {
1673 char mime_partnum[SIZ];
1674 char mime_filename[SIZ];
1675 char mime_content_type[SIZ];
1676 char mime_disposition[SIZ];
1678 char vcard_partnum[SIZ];
1679 char *vcard_source = NULL;
1681 struct message_summary summ;
1683 if (namebuf == NULL) return;
1684 strcpy(namebuf, "");
1686 memset(&summ, 0, sizeof(summ));
1687 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1689 sprintf(buf, "MSG0 %ld|1", msgnum); /** ask for headers only */
1691 serv_getln(buf, sizeof buf);
1692 if (buf[0] != '1') return;
1694 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1695 if (!strncasecmp(buf, "part=", 5)) {
1696 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1697 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1698 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1699 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1700 mime_length = extract_int(&buf[5], 5);
1702 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1703 strcpy(vcard_partnum, mime_partnum);
1709 if (strlen(vcard_partnum) > 0) {
1710 vcard_source = load_mimepart(msgnum, vcard_partnum);
1711 if (vcard_source != NULL) {
1713 /* Grab the name off the card */
1714 display_vcard(vcard_source, 0, 0, namebuf);
1720 lastfirst_firstlast(namebuf);
1722 for (i=0; i<strlen(namebuf); ++i) {
1723 if (namebuf[i] != ';') return;
1725 strcpy(namebuf, _("(no name)"));
1731 * \brief Record compare function for sorting address book indices
1732 * \param ab1 adressbook one
1733 * \param ab2 adressbook two
1735 int abcmp(const void *ab1, const void *ab2) {
1737 (((const struct addrbookent *)ab1)->ab_name),
1738 (((const struct addrbookent *)ab2)->ab_name)
1744 * \brief Helper function for do_addrbook_view()
1745 * Converts a name into a three-letter tab label
1746 * \param tabbuf the tabbuffer to add name to
1747 * \param name the name to add to the tabbuffer
1749 void nametab(char *tabbuf, char *name) {
1750 stresc(tabbuf, name, 0, 0);
1751 tabbuf[0] = toupper(tabbuf[0]);
1752 tabbuf[1] = tolower(tabbuf[1]);
1753 tabbuf[2] = tolower(tabbuf[2]);
1759 * \brief Render the address book using info we gathered during the scan
1760 * \param addrbook the addressbook to render
1761 * \param num_ab the number of the addressbook
1763 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1767 static int NAMESPERPAGE = 60;
1771 char tabfirst_label[SIZ];
1773 char tablast_label[SIZ];
1776 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1777 wprintf(_("This address book is empty."));
1778 wprintf("</i></div>\n");
1783 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1786 num_pages = num_ab / NAMESPERPAGE;
1788 page = atoi(bstr("page"));
1791 for (i=0; i<=num_pages; ++i) {
1793 wprintf("<a href=\"readfwd?page=%d\">", i);
1798 tabfirst = i * NAMESPERPAGE;
1799 tablast = tabfirst + NAMESPERPAGE - 1;
1800 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1801 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1802 nametab(tablast_label, addrbook[tablast].ab_name);
1803 wprintf("[%s - %s]",
1804 tabfirst_label, tablast_label
1813 wprintf("<br />\n");
1815 wprintf("<table border=0 cellspacing=0 "
1816 "cellpadding=3 width=100%%>\n"
1819 for (i=0; i<num_ab; ++i) {
1821 if ((i / NAMESPERPAGE) == page) {
1823 if ((displayed % 4) == 0) {
1824 if (displayed > 0) {
1828 wprintf("<tr bgcolor=\"#%s\">",
1829 (bg ? "DDDDDD" : "FFFFFF")
1835 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
1836 addrbook[i].ab_msgnum);
1837 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1838 vcard_n_prettyize(addrbook[i].ab_name);
1839 escputs(addrbook[i].ab_name);
1840 wprintf("</a></td>\n");
1845 wprintf("</tr></table>\n");
1851 * \brief load message pointers from the server
1852 * \param servcmd the citadel command to send to the citserver
1853 * \param with_headers what headers???
1855 int load_msg_ptrs(char *servcmd, int with_headers)
1866 int num_summ_alloc = 0;
1868 if (WC->summ != NULL) {
1873 num_summ_alloc = 100;
1875 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1878 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1880 serv_getln(buf, sizeof buf);
1881 if (buf[0] != '1') {
1884 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1885 if (nummsgs < maxload) {
1886 WC->msgarr[nummsgs] = extract_long(buf, 0);
1887 datestamp = extract_long(buf, 1);
1888 extract_token(fullname, buf, 2, '|', sizeof fullname);
1889 extract_token(nodename, buf, 3, '|', sizeof nodename);
1890 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1891 extract_token(subject, buf, 5, '|', sizeof subject);
1895 if (nummsgs > num_summ_alloc) {
1896 num_summ_alloc *= 2;
1897 WC->summ = realloc(WC->summ,
1898 num_summ_alloc * sizeof(struct message_summary));
1902 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1903 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1904 safestrncpy(WC->summ[nummsgs-1].subj,
1905 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1906 if (strlen(fullname) > 0) {
1907 safestrncpy(WC->summ[nummsgs-1].from,
1908 fullname, sizeof WC->summ[nummsgs-1].from);
1910 if (strlen(subject) > 0) {
1911 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1912 sizeof WC->summ[nummsgs-1].subj);
1915 /** Handle subjects with RFC2047 encoding */
1916 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1918 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1919 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1922 if (strlen(nodename) > 0) {
1923 if ( ((WC->room_flags & QR_NETWORK)
1924 || ((strcasecmp(nodename, serv_info.serv_nodename)
1925 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1927 strcat(WC->summ[nummsgs-1].from, " @ ");
1928 strcat(WC->summ[nummsgs-1].from, nodename);
1932 WC->summ[nummsgs-1].date = datestamp;
1935 /** Handle senders with RFC2047 encoding */
1936 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1938 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1939 strcpy(&WC->summ[nummsgs-1].from[22], "...");
1948 * \brief qsort() compatible function to compare two longs in descending order.
1950 * \param s1 first number to compare
1951 * \param s2 second number to compare
1953 int longcmp_r(const void *s1, const void *s2) {
1960 if (l1 > l2) return(-1);
1961 if (l1 < l2) return(+1);
1967 * \brief qsort() compatible function to compare two message summary structs by ascending subject.
1969 * \param s1 first item to compare
1970 * \param s2 second item to compare
1972 int summcmp_subj(const void *s1, const void *s2) {
1973 struct message_summary *summ1;
1974 struct message_summary *summ2;
1976 summ1 = (struct message_summary *)s1;
1977 summ2 = (struct message_summary *)s2;
1978 return strcasecmp(summ1->subj, summ2->subj);
1982 * \brief qsort() compatible function to compare two message summary structs by descending subject.
1984 * \param s1 first item to compare
1985 * \param s2 second item to compare
1987 int summcmp_rsubj(const void *s1, const void *s2) {
1988 struct message_summary *summ1;
1989 struct message_summary *summ2;
1991 summ1 = (struct message_summary *)s1;
1992 summ2 = (struct message_summary *)s2;
1993 return strcasecmp(summ2->subj, summ1->subj);
1997 * \brief qsort() compatible function to compare two message summary structs by ascending sender.
1999 * \param s1 first item to compare
2000 * \param s2 second item to compare
2002 int summcmp_sender(const void *s1, const void *s2) {
2003 struct message_summary *summ1;
2004 struct message_summary *summ2;
2006 summ1 = (struct message_summary *)s1;
2007 summ2 = (struct message_summary *)s2;
2008 return strcasecmp(summ1->from, summ2->from);
2012 * \brief qsort() compatible function to compare two message summary structs by descending sender.
2014 * \param s1 first item to compare
2015 * \param s2 second item to compare
2017 int summcmp_rsender(const void *s1, const void *s2) {
2018 struct message_summary *summ1;
2019 struct message_summary *summ2;
2021 summ1 = (struct message_summary *)s1;
2022 summ2 = (struct message_summary *)s2;
2023 return strcasecmp(summ2->from, summ1->from);
2027 * \brief qsort() compatible function to compare two message summary structs by ascending date.
2029 * \param s1 first item to compare
2030 * \param s2 second item to compare
2032 int summcmp_date(const void *s1, const void *s2) {
2033 struct message_summary *summ1;
2034 struct message_summary *summ2;
2036 summ1 = (struct message_summary *)s1;
2037 summ2 = (struct message_summary *)s2;
2039 if (summ1->date < summ2->date) return -1;
2040 else if (summ1->date > summ2->date) return +1;
2045 * \brief qsort() compatible function to compare two message summary structs by descending date.
2047 * \param s1 first item to compare
2048 * \param s2 second item to compare
2050 int summcmp_rdate(const void *s1, const void *s2) {
2051 struct message_summary *summ1;
2052 struct message_summary *summ2;
2054 summ1 = (struct message_summary *)s1;
2055 summ2 = (struct message_summary *)s2;
2057 if (summ1->date < summ2->date) return +1;
2058 else if (summ1->date > summ2->date) return -1;
2065 * \brief command loop for reading messages
2067 * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
2069 void readloop(char *oper)
2078 long *displayed_msgs = NULL;
2079 int num_displayed = 0;
2081 int is_addressbook = 0;
2082 int is_singlecard = 0;
2083 int is_calendar = 0;
2088 int lowest_displayed = (-1);
2089 int highest_displayed = 0;
2090 struct addrbookent *addrbook = NULL;
2092 char *sortby = NULL;
2093 char sortpref_name[128];
2094 char sortpref_value[128];
2095 char *subjsort_button;
2096 char *sendsort_button;
2097 char *datesort_button;
2098 int bbs_reverse = 0;
2100 if (WC->wc_view == VIEW_WIKI) {
2101 sprintf(buf, "wiki?room=%s?page=home", WC->wc_roomname);
2106 startmsg = atol(bstr("startmsg"));
2107 maxmsgs = atoi(bstr("maxmsgs"));
2108 is_summary = atoi(bstr("summary"));
2109 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2111 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
2112 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
2114 sortby = bstr("sortby");
2115 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
2116 set_preference(sortpref_name, sortby, 1);
2118 if (strlen(sortby) == 0) sortby = sortpref_value;
2121 if (strlen(sortby) == 0) sortby = "rdate";
2123 /** message board sort */
2124 if (!strcasecmp(sortby, "reverse")) {
2131 output_headers(1, 1, 1, 0, 0, 0);
2134 * When in summary mode, always show ALL messages instead of just
2135 * new or old. Otherwise, show what the user asked for.
2137 if (!strcmp(oper, "readnew")) {
2138 strcpy(cmd, "MSGS NEW");
2140 else if (!strcmp(oper, "readold")) {
2141 strcpy(cmd, "MSGS OLD");
2143 else if (!strcmp(oper, "do_search")) {
2144 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2147 strcpy(cmd, "MSGS ALL");
2150 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
2152 if (!strcmp(oper, "do_search")) {
2153 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2156 strcpy(cmd, "MSGS ALL");
2160 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2162 if (!strcmp(oper, "do_search")) {
2163 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2166 strcpy(cmd, "MSGS ALL");
2171 if (is_summary) { /**< fetch header summary */
2172 snprintf(cmd, sizeof cmd, "MSGS %s|%s||1",
2173 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2174 (!strcmp(oper, "do_search") ? bstr("query") : "")
2181 * Are we doing a summary view? If so, we need to know old messages
2182 * and new messages, so we can do that pretty boldface thing for the
2185 strcpy(old_msgs, "");
2188 serv_getln(buf, sizeof buf);
2189 if (buf[0] == '2') {
2190 strcpy(old_msgs, &buf[4]);
2194 is_singlecard = atoi(bstr("is_singlecard"));
2196 if (WC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2198 strcpy(cmd, "MSGS ALL");
2201 if (WC->wc_default_view == VIEW_TASKS) { /**< tasks */
2203 strcpy(cmd, "MSGS ALL");
2206 if (WC->wc_default_view == VIEW_NOTES) { /**< notes */
2208 strcpy(cmd, "MSGS ALL");
2213 wprintf("<div align=center>%s</div>\n", _("Click on any note to edit it."));
2214 wprintf("<div id=\"new_notes_here\"></div>\n");
2217 nummsgs = load_msg_ptrs(cmd, is_summary);
2220 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2221 wprintf("<div align=\"center\"><br /><em>");
2222 if (!strcmp(oper, "readnew")) {
2223 wprintf(_("No new messages."));
2224 } else if (!strcmp(oper, "readold")) {
2225 wprintf(_("No old messages."));
2227 wprintf(_("No messages here."));
2229 wprintf("</em><br /></div>\n");
2236 for (a = 0; a < nummsgs; ++a) {
2237 /** Are you a new message, or an old message? */
2239 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
2240 WC->summ[a].is_new = 0;
2243 WC->summ[a].is_new = 1;
2249 if (startmsg == 0L) {
2251 startmsg = WC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2254 startmsg = WC->msgarr[0];
2259 if (!strcasecmp(sortby, "subject")) {
2260 qsort(WC->summ, WC->num_summ,
2261 sizeof(struct message_summary), summcmp_subj);
2263 else if (!strcasecmp(sortby, "rsubject")) {
2264 qsort(WC->summ, WC->num_summ,
2265 sizeof(struct message_summary), summcmp_rsubj);
2267 else if (!strcasecmp(sortby, "sender")) {
2268 qsort(WC->summ, WC->num_summ,
2269 sizeof(struct message_summary), summcmp_sender);
2271 else if (!strcasecmp(sortby, "rsender")) {
2272 qsort(WC->summ, WC->num_summ,
2273 sizeof(struct message_summary), summcmp_rsender);
2275 else if (!strcasecmp(sortby, "date")) {
2276 qsort(WC->summ, WC->num_summ,
2277 sizeof(struct message_summary), summcmp_date);
2279 else if (!strcasecmp(sortby, "rdate")) {
2280 qsort(WC->summ, WC->num_summ,
2281 sizeof(struct message_summary), summcmp_rdate);
2285 if (!strcasecmp(sortby, "subject")) {
2286 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2288 else if (!strcasecmp(sortby, "rsubject")) {
2289 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2292 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2295 if (!strcasecmp(sortby, "sender")) {
2296 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2298 else if (!strcasecmp(sortby, "rsender")) {
2299 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2302 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2305 if (!strcasecmp(sortby, "date")) {
2306 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2308 else if (!strcasecmp(sortby, "rdate")) {
2309 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2312 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2316 wprintf("</div>\n"); /** end of 'content' div */
2318 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2319 " document.onkeydown = CtdlMsgListKeyPress; "
2320 " if (document.layers) { "
2321 " document.captureEvents(Event.KEYPRESS); "
2326 /** note that Date and Delete are now in the same column */
2327 wprintf("<div id=\"message_list_hdr\">"
2328 "<div class=\"fix_scrollbar_bug\">"
2329 "<table cellspacing=0 style=\"width:100%%\">"
2332 wprintf("<td width=%d%%><b><i>%s</i></b> %s</td>"
2333 "<td width=%d%%><b><i>%s</i></b> %s</td>"
2334 "<td width=%d%%><b><i>%s</i></b> %s"
2336 "<input type=\"submit\" name=\"delete_button\" style=\"font-size:6pt\" "
2337 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2343 _("Subject"), subjsort_button,
2344 SENDER_COL_WIDTH_PCT,
2345 _("Sender"), sendsort_button,
2346 DATE_PLUS_BUTTONS_WIDTH_PCT,
2347 _("Date"), datesort_button,
2350 wprintf("</table></div></div>\n");
2352 wprintf("<div id=\"message_list\">"
2354 "<div class=\"fix_scrollbar_bug\">\n"
2356 "<table class=\"mailbox_summary\" id=\"summary_headers\" rules=rows "
2357 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2361 for (a = 0; a < nummsgs; ++a) {
2362 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2364 /** Display the message */
2366 display_summarized(a);
2368 else if (is_addressbook) {
2369 fetch_ab_name(WC->msgarr[a], buf);
2371 addrbook = realloc(addrbook,
2372 (sizeof(struct addrbookent) * num_ab) );
2373 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2374 sizeof(addrbook[num_ab-1].ab_name));
2375 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
2377 else if (is_calendar) {
2378 display_calendar(WC->msgarr[a]);
2380 else if (is_tasks) {
2381 display_task(WC->msgarr[a]);
2383 else if (is_notes) {
2384 display_note(WC->msgarr[a]);
2387 if (displayed_msgs == NULL) {
2388 displayed_msgs = malloc(sizeof(long) *
2389 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2391 displayed_msgs[num_displayed] = WC->msgarr[a];
2394 if (lowest_displayed < 0) lowest_displayed = a;
2395 highest_displayed = a;
2402 * Set the "is_bbview" variable if it appears that we are looking at
2403 * a classic bulletin board view.
2405 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2406 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2411 if (displayed_msgs != NULL) {
2413 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2416 /** if we do a split bbview in the future, begin messages div here */
2418 for (a=0; a<num_displayed; ++a) {
2419 read_message(displayed_msgs[a], 0, "");
2422 /** if we do a split bbview in the future, end messages div here */
2424 free(displayed_msgs);
2425 displayed_msgs = NULL;
2430 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2431 wprintf("</div>"); /**< end of 'message_list' div */
2433 /** Here's the grab-it-to-resize-the-message-list widget */
2434 wprintf("<div id=\"resize_msglist\" "
2435 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2436 "<div class=\"fix_scrollbar_bug\">"
2437 "<table width=100%% border=3 cellspacing=0 "
2438 "bgcolor=\"#cccccc\" "
2439 "cellpadding=0><TR><TD> </td></tr></table>"
2443 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2447 * Bump these because although we're thinking in zero base, the user
2448 * is a drooling idiot and is thinking in one base.
2451 ++highest_displayed;
2454 * If we're not currently looking at ALL requested
2455 * messages, then display the selector bar
2458 /** begin bbview scroller */
2459 wprintf("<form name=\"msgomatic\">");
2460 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2462 wprintf("<select name=\"whichones\" size=\"1\" "
2463 "OnChange=\"location.href=msgomatic.whichones.options"
2464 "[selectedIndex].value\">\n");
2467 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2469 lo = b - maxmsgs + 2;
2471 wprintf("<option %s value="
2476 "%d-%d</option> \n",
2477 ((WC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2486 for (b=0; b<nummsgs; b = b + maxmsgs) {
2488 hi = b + maxmsgs + 1;
2489 if (hi > nummsgs) hi = nummsgs;
2490 wprintf("<option %s value="
2495 "%d-%d</option> \n",
2496 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2505 wprintf("<option value=\"%s?startmsg=%ld"
2506 "?maxmsgs=9999999?summary=%d\">"
2510 WC->msgarr[0], is_summary);
2512 wprintf("</select> ");
2513 wprintf(_("of %d messages."), nummsgs);
2515 /** forward/reverse */
2516 wprintf(" <select name=\"direction\" size=\"1\" "
2517 "OnChange=\"location.href=msgomatic.direction.options"
2518 "[selectedIndex].value\">\n"
2521 wprintf("<option %s value=\"%s?sortby=forward\">oldest to newest</option>\n",
2522 (bbs_reverse ? "" : "selected"),
2526 wprintf("<option %s value=\"%s?sortby=reverse\">newest to oldest</option>\n",
2527 (bbs_reverse ? "selected" : ""),
2531 wprintf("</select></form>\n");
2532 /** end bbview scroller */
2537 do_tasks_view(); /** Render the task list */
2541 do_calendar_view(); /** Render the calendar */
2544 if (is_addressbook) {
2545 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2548 /** Note: wDumpContent() will output one additional </div> tag. */
2550 if (addrbook != NULL) free(addrbook);
2552 /** free the summary */
2553 if (WC->summ != NULL) {
2562 * \brief Back end for post_message()
2563 * ... this is where the actual message gets transmitted to the server.
2565 void post_mime_to_server(void) {
2567 int is_multipart = 0;
2569 struct wc_attachment *att;
2571 size_t encoded_length;
2573 /** RFC2045 requires this, and some clients look for it... */
2574 serv_puts("MIME-Version: 1.0");
2575 serv_puts("X-Mailer: " SERVER);
2577 /** If there are attachments, we have to do multipart/mixed */
2578 if (WC->first_attachment != NULL) {
2583 sprintf(boundary, "=_Citadel_Multipart_%s_%04x%04x",
2584 serv_info.serv_fqdn,
2589 /** Remember, serv_printf() appends an extra newline */
2590 serv_printf("Content-type: multipart/mixed; "
2591 "boundary=\"%s\"\n", boundary);
2592 serv_printf("This is a multipart message in MIME format.\n");
2593 serv_printf("--%s", boundary);
2596 serv_puts("Content-type: text/html; charset=utf-8");
2597 serv_puts("Content-Transfer-Encoding: quoted-printable");
2599 serv_puts("<html><body>\r\n");
2600 text_to_server_qp(bstr("msgtext")); /** Transmit message in quoted-printable encoding */
2601 serv_puts("</body></html>\r\n");
2605 /** Add in the attachments */
2606 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2608 encoded_length = ((att->length * 150) / 100);
2609 encoded = malloc(encoded_length);
2610 if (encoded == NULL) break;
2611 CtdlEncodeBase64(encoded, att->data, att->length, 1);
2613 serv_printf("--%s", boundary);
2614 serv_printf("Content-type: %s", att->content_type);
2615 serv_printf("Content-disposition: attachment; "
2616 "filename=\"%s\"", att->filename);
2617 serv_puts("Content-transfer-encoding: base64");
2619 serv_write(encoded, strlen(encoded));
2624 serv_printf("--%s--", boundary);
2632 * \brief Post message (or don't post message)
2634 * Note regarding the "dont_post" variable:
2635 * A random value (actually, it's just a timestamp) is inserted as a hidden
2636 * field called "postseq" when the display_enter page is generated. This
2637 * value is checked when posting, using the static variable dont_post. If a
2638 * user attempts to post twice using the same dont_post value, the message is
2639 * discarded. This prevents the accidental double-saving of the same message
2640 * if the user happens to click the browser "back" button.
2642 void post_message(void)
2645 char encoded_subject[1024];
2646 static long dont_post = (-1L);
2647 struct wc_attachment *att, *aptr;
2648 int is_anonymous = 0;
2650 if (!strcasecmp(bstr("is_anonymous"), "yes")) {
2654 if (WC->upload_length > 0) {
2656 /** There's an attachment. Save it to this struct... */
2657 att = malloc(sizeof(struct wc_attachment));
2658 memset(att, 0, sizeof(struct wc_attachment));
2659 att->length = WC->upload_length;
2660 strcpy(att->content_type, WC->upload_content_type);
2661 strcpy(att->filename, WC->upload_filename);
2664 /** And add it to the list. */
2665 if (WC->first_attachment == NULL) {
2666 WC->first_attachment = att;
2669 aptr = WC->first_attachment;
2670 while (aptr->next != NULL) aptr = aptr->next;
2675 * Mozilla sends a simple filename, which is what we want,
2676 * but Satan's Browser sends an entire pathname. Reduce
2677 * the path to just a filename if we need to.
2679 while (num_tokens(att->filename, '/') > 1) {
2680 remove_token(att->filename, 0, '/');
2682 while (num_tokens(att->filename, '\\') > 1) {
2683 remove_token(att->filename, 0, '\\');
2687 * Transfer control of this memory from the upload struct
2688 * to the attachment struct.
2690 att->data = WC->upload;
2691 WC->upload_length = 0;
2697 if (strlen(bstr("cancel_button")) > 0) {
2698 sprintf(WC->ImportantMessage,
2699 _("Cancelled. Message was not posted."));
2700 } else if (strlen(bstr("attach_button")) > 0) {
2703 } else if (atol(bstr("postseq")) == dont_post) {
2704 sprintf(WC->ImportantMessage,
2705 _("Automatically cancelled because you have already "
2706 "saved this message."));
2708 rfc2047encode(encoded_subject, sizeof encoded_subject, bstr("subject"));
2709 sprintf(buf, "ENT0 1|%s|%d|4|%s|||%s|%s|%s",
2718 serv_getln(buf, sizeof buf);
2719 if (buf[0] == '4') {
2720 post_mime_to_server();
2721 if ( (strlen(bstr("recp")) > 0)
2722 || (strlen(bstr("cc")) > 0)
2723 || (strlen(bstr("bcc")) > 0)
2725 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2728 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2730 dont_post = atol(bstr("postseq"));
2732 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2738 free_attachments(WC);
2741 * We may have been supplied with instructions regarding the location
2742 * to which we must return after posting. If found, go there.
2744 if (strlen(bstr("return_to")) > 0) {
2745 http_redirect(bstr("return_to"));
2748 * If we were editing a page in a wiki room, go to that page now.
2750 else if (strlen(bstr("wikipage")) > 0) {
2751 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
2755 * Otherwise, just go to the "read messages" loop.
2758 readloop("readnew");
2766 * \brief display the message entry screen
2768 void display_enter(void)
2773 struct wc_attachment *att;
2774 int recipient_required = 0;
2775 int recipient_bad = 0;
2777 int is_anonymous = 0;
2778 long existing_page = (-1L);
2780 if (strlen(bstr("force_room")) > 0) {
2781 gotoroom(bstr("force_room"));
2784 if (!strcasecmp(bstr("is_anonymous"), "yes")) {
2788 /** First test to see whether this is a room that requires recipients to be entered */
2789 serv_puts("ENT0 0");
2790 serv_getln(buf, sizeof buf);
2791 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
2792 recipient_required = 1;
2794 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2795 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2796 readloop("readnew");
2801 * Are we perhaps in an address book view? If so, then an "enter
2802 * message" command really means "add new entry."
2804 if (WC->wc_default_view == VIEW_ADDRESSBOOK) {
2805 do_edit_vcard(-1, "", "");
2809 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
2811 * Are we perhaps in a calendar room? If so, then an "enter
2812 * message" command really means "add new calendar item."
2814 if (WC->wc_default_view == VIEW_CALENDAR) {
2815 display_edit_event();
2820 * Are we perhaps in a tasks view? If so, then an "enter
2821 * message" command really means "add new task."
2823 if (WC->wc_default_view == VIEW_TASKS) {
2824 display_edit_task();
2830 * Otherwise proceed normally.
2831 * Do a custom room banner with no navbar...
2833 output_headers(1, 1, 2, 0, 0, 0);
2834 wprintf("<div id=\"banner\">\n");
2835 embed_room_banner(NULL, navbar_none);
2836 wprintf("</div>\n");
2837 wprintf("<div id=\"content\">\n"
2838 "<div class=\"fix_scrollbar_bug\">"
2839 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
2841 /** Now check our actual recipients if there are any */
2842 if (recipient_required) {
2843 sprintf(buf, "ENT0 0|%s|%d|0||||%s|%s|%s", bstr("recp"), is_anonymous,
2844 bstr("cc"), bstr("bcc"), bstr("wikipage"));
2846 serv_getln(buf, sizeof buf);
2848 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
2849 if (strlen(bstr("recp")) + strlen(bstr("cc")) + strlen(bstr("bcc")) > 0) {
2853 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2854 wprintf("<em>%s</em><br />\n", &buf[4]);
2859 /** If we got this far, we can display the message entry screen. */
2862 fmt_date(buf, now, 0);
2863 strcat(&buf[strlen(buf)], _(" <I>from</I> "));
2864 stresc(&buf[strlen(buf)], WC->wc_fullname, 1, 1);
2866 /* Don't need this anymore, it's in the input box below
2867 if (strlen(bstr("recp")) > 0) {
2868 strcat(&buf[strlen(buf)], _(" <I>to</I> "));
2869 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
2873 strcat(&buf[strlen(buf)], _(" <I>in</I> "));
2874 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
2876 /** begin message entry screen */
2878 "enctype=\"multipart/form-data\" "
2880 "accept-charset=\"UTF-8\" "
2882 "name=\"enterform\""
2884 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2885 if (WC->wc_view == VIEW_WIKI) {
2886 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
2888 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
2890 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2891 wprintf("%s\n", buf); /** header bar */
2892 if (WC->room_flags & QR_ANONOPT) {
2894 "<input type=\"checkbox\" name=\"is_anonymous\" value=\"yes\" %s>",
2895 (is_anonymous ? "checked" : "")
2897 wprintf("Anonymous");
2899 wprintf("<br>\n"); /** header bar */
2901 wprintf("<table border=\"0\" width=\"100%%\">\n");
2902 if (recipient_required) {
2904 wprintf("<tr><td>");
2905 wprintf("<font size=-1>");
2909 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
2910 escputs(bstr("recp"));
2911 wprintf("\" size=50 maxlength=1000 />");
2912 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
2913 wprintf("</td><td></td></tr>\n");
2915 wprintf("<tr><td>");
2916 wprintf("<font size=-1>");
2920 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
2921 escputs(bstr("cc"));
2922 wprintf("\" size=50 maxlength=1000 />");
2923 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
2924 wprintf("</td><td></td></tr>\n");
2926 wprintf("<tr><td>");
2927 wprintf("<font size=-1>");
2931 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
2932 escputs(bstr("bcc"));
2933 wprintf("\" size=50 maxlength=1000 />");
2934 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
2935 wprintf("</td><td></td></tr>\n");
2937 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
2938 wprintf("<script type=\"text/javascript\"> \n"
2939 " activate_entmsg_autocompleters(); \n"
2944 wprintf("<tr><td>");
2945 wprintf("<font size=-1>");
2946 wprintf(_("Subject (optional):"));
2949 "<input type=\"text\" name=\"subject\" value=\"");
2950 escputs(bstr("subject"));
2951 wprintf("\" size=50 maxlength=70></td><td>\n");
2953 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2954 if (recipient_required) {
2955 wprintf(_("Send message"));
2957 wprintf(_("Post message"));
2960 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2961 wprintf("</td></tr></table>\n");
2963 wprintf("<center>");
2965 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
2967 /** If we're continuing from a previous edit, put our partially-composed message back... */
2968 msgescputs(bstr("msgtext"));
2970 /* If we're forwarding a message, insert it here... */
2971 if (atol(bstr("fwdquote")) > 0L) {
2972 wprintf("<br><div align=center><i>");
2973 wprintf(_("--- forwarded message ---"));
2974 wprintf("</i></div><br>");
2975 pullquote_message(atol(bstr("fwdquote")), 1, 1);
2978 /** If we're replying quoted, insert the quote here... */
2979 else if (atol(bstr("replyquote")) > 0L) {
2982 pullquote_message(atol(bstr("replyquote")), 0, 1);
2983 wprintf("</blockquote><br>");
2986 /** If we're editing a wiki page, insert the existing page here... */
2987 else if (WC->wc_view == VIEW_WIKI) {
2988 safestrncpy(buf, bstr("wikipage"), sizeof buf);
2989 str_wiki_index(buf);
2990 existing_page = locate_message_by_uid(buf);
2991 if (existing_page >= 0L) {
2992 pullquote_message(existing_page, 1, 0);
2996 /** Insert our signature if appropriate... */
2997 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
2998 get_preference("use_sig", buf, sizeof buf);
2999 if (!strcasecmp(buf, "yes")) {
3000 get_preference("signature", ebuf, sizeof ebuf);
3001 euid_unescapize(buf, ebuf);
3002 wprintf("<br>--<br>");
3003 for (i=0; i<strlen(buf); ++i) {
3004 if (buf[i] == '\n') {
3007 else if (buf[i] == '<') {
3010 else if (buf[i] == '>') {
3013 else if (buf[i] == '&') {
3016 else if (buf[i] == '\"') {
3019 else if (buf[i] == '\'') {
3022 else if (isprint(buf[i])) {
3023 wprintf("%c", buf[i]);
3029 wprintf("</textarea>");
3030 wprintf("</center><br />\n");
3033 * The following script embeds the TinyMCE richedit control, and automatically
3034 * transforms the textarea into a richedit textarea.
3037 "<script language=\"javascript\" type=\"text/javascript\" src=\"tiny_mce/tiny_mce.js\"></script>\n"
3038 "<script language=\"javascript\" type=\"text/javascript\">"
3040 " mode : \"textareas\", width : \"100%%\", browsers : \"msie,gecko\", "
3041 " theme : \"advanced\", plugins : \"iespell\", "
3042 " theme_advanced_buttons1 : \"bold, italic, underline, strikethrough, justifyleft, justifycenter, justifyright, justifyfull, bullist, numlist, cut, copy, paste, link, image, help, forecolor, iespell, code\", "
3043 " theme_advanced_buttons2 : \"\", "
3044 " theme_advanced_buttons3 : \"\", "
3045 " content_css : \"static/webcit-tinymce.css\" "
3051 /** Enumerate any attachments which are already in place... */
3052 wprintf("<img src=\"static/diskette_24x.gif\" border=0 "
3053 "align=middle height=16 width=16> ");
3054 wprintf(_("Attachments:"));
3056 wprintf("<select name=\"which_attachment\" size=1>");
3057 for (att = WC->first_attachment; att != NULL; att = att->next) {
3058 wprintf("<option value=\"");
3059 urlescputs(att->filename);
3061 escputs(att->filename);
3062 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3063 wprintf("</option>\n");
3065 wprintf("</select>");
3067 /** Now offer the ability to attach additional files... */
3068 wprintf(" ");
3069 wprintf(_("Attach file:"));
3070 wprintf(" <input NAME=\"attachfile\" "
3071 "SIZE=16 TYPE=\"file\">\n "
3072 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3074 /** Seth asked for these to be at the top *and* bottom... */
3075 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3076 if (recipient_required) {
3077 wprintf(_("Send message"));
3079 wprintf(_("Post message"));
3082 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3084 /** Make sure we only insert our signature once */
3085 if (strcmp(bstr("sig_inserted"), "yes")) {
3086 wprintf("<INPUT TYPE=\"hidden\" NAME=\"sig_inserted\" VALUE=\"yes\">\n");
3089 wprintf("</form>\n");
3091 wprintf("</td></tr></table></div>\n");
3092 DONE: wDumpContent(1);
3098 * \brief delete a message
3100 void delete_msg(void)
3105 msgid = atol(bstr("msgid"));
3107 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3108 serv_printf("DELE %ld", msgid);
3110 else { /** Otherwise move it to Trash */
3111 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3114 serv_getln(buf, sizeof buf);
3115 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3117 readloop("readnew");
3122 * \brief move a message to another folder
3129 msgid = atol(bstr("msgid"));
3131 if (strlen(bstr("move_button")) > 0) {
3132 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3134 serv_getln(buf, sizeof buf);
3135 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3137 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3140 readloop("readnew");
3148 * \brief Confirm move of a message
3150 void confirm_move_msg(void)
3156 msgid = atol(bstr("msgid"));
3159 output_headers(1, 1, 2, 0, 0, 0);
3160 wprintf("<div id=\"banner\">\n");
3161 wprintf("<TABLE WIDTH=100%% BORDER=0><TR><TD>");
3162 wprintf("<SPAN CLASS=\"titlebar\">");
3163 wprintf(_("Confirm move of message"));
3164 wprintf("</SPAN>\n");
3165 wprintf("</TD></TR></TABLE>\n");
3166 wprintf("</div>\n<div id=\"content\">\n");
3168 wprintf("<CENTER>");
3170 wprintf(_("Move this message to:"));
3171 wprintf("<br />\n");
3173 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3174 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3176 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3178 serv_getln(buf, sizeof buf);
3179 if (buf[0] == '1') {
3180 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3181 extract_token(targ, buf, 0, '|', sizeof targ);
3182 wprintf("<OPTION>");
3187 wprintf("</SELECT>\n");
3188 wprintf("<br />\n");
3190 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3192 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3193 wprintf("</form></CENTER>\n");
3195 wprintf("</CENTER>\n");