4 * Functions which deal with the fetching and displaying of messages.
10 #include "webserver.h"
13 #define SUBJ_COL_WIDTH_PCT 50
14 #define SENDER_COL_WIDTH_PCT 30
15 #define DATE_PLUS_BUTTONS_WIDTH_PCT 20
17 /* Address book entry (keep it short and sweet, it's just a quickie lookup
18 * which we can use to get to the real meat and bones later)
28 /* Handle subjects with RFC2047 encoding, such as:
29 * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=
31 void utf8ify_rfc822_string(char *buf) {
37 iconv_t ic = (iconv_t)(-1) ;
38 char *ibuf; /* Buffer of characters to be converted */
39 char *obuf; /* Buffer for converted characters */
40 size_t ibuflen; /* Length of input buffer */
41 size_t obuflen; /* Length of output buffer */
42 char *isav; /* Saved pointer to input buffer */
43 char *osav; /* Saved pointer to output buffer */
46 while (start=strstr(buf, "=?"), end=strstr(buf, "?="),
47 ((start != NULL) && (end != NULL) && (end > start)) )
49 extract_token(charset, start, 1, '?', sizeof charset);
50 extract_token(encoding, start, 2, '?', sizeof encoding);
51 extract_token(istr, start, 3, '?', sizeof istr);
59 if (!strcasecmp(encoding, "B")) { /* base64 */
60 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
62 else if (!strcasecmp(encoding, "Q")) { /* quoted-printable */
63 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, strlen(istr));
66 strcpy(ibuf, istr); /* huh? */
67 ibuflen = strlen(istr);
70 ic = iconv_open("UTF-8", charset);
71 if (ic != (iconv_t)(-1) ) {
74 obuf = (char *) malloc(obuflen);
76 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
77 osav[1024-obuflen] = 0;
82 remove_token(end, 0, '?');
83 remove_token(end, 0, '?');
84 remove_token(end, 0, '?');
85 remove_token(end, 0, '?');
88 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
97 remove_token(end, 0, '?');
98 remove_token(end, 0, '?');
99 remove_token(end, 0, '?');
100 remove_token(end, 0, '?');
101 strcpy(end, &end[1]);
103 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
109 /* Since spammers will go to all sorts of absurd lengths to get their
110 * messages through, there are LOTS of corrupt headers out there.
111 * So, prevent a really badly formed RFC2047 header from throwing
112 * this function into an infinite loop.
115 if (passes > 20) return;
123 * Look for URL's embedded in a buffer and make them linkable. We use a
124 * target window in order to keep the BBS session in its own window.
140 for (pos = 0; pos < strlen(buf); ++pos) {
141 if (!strncasecmp(&buf[pos], "http://", 7))
143 if (!strncasecmp(&buf[pos], "ftp://", 6))
150 if ((start > 0) && (buf[start - 1] == '<'))
152 if ((start > 0) && (buf[start - 1] == '['))
154 if ((start > 0) && (buf[start - 1] == '('))
156 if ((start > 0) && (buf[start - 1] == '{'))
159 for (pos = strlen(buf); pos > start; --pos) {
160 if ((buf[pos] == ' ') || (buf[pos] == ench))
164 strncpy(urlbuf, &buf[start], end - start);
165 urlbuf[end - start] = 0;
167 strncpy(outbuf, buf, start);
168 sprintf(&outbuf[start], "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
169 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
170 strcat(outbuf, &buf[end]);
171 if ( strlen(outbuf) < 250 )
177 * Turn a vCard "n" (name) field into something displayable.
179 void vcard_n_prettyize(char *name)
184 original_name = strdup(name);
185 for (i=0; i<5; ++i) {
186 if (strlen(original_name) > 0) {
187 if (original_name[strlen(original_name)-1] == ' ') {
188 original_name[strlen(original_name)-1] = 0;
190 if (original_name[strlen(original_name)-1] == ';') {
191 original_name[strlen(original_name)-1] = 0;
196 for (i=0; i<strlen(original_name); ++i) {
197 if (original_name[i] == ';') {
201 name[strlen(name)+1] = 0;
202 name[strlen(name)] = original_name[i];
211 /* display_vcard() calls this after parsing the textual vCard into
212 * our 'struct vCard' data object.
213 * This gets called instead of display_parsed_vcard() if we are only looking
214 * to extract the person's name instead of displaying the card.
216 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
219 strcpy(storename, "");
221 name = vcard_get_prop(v, "n", 1, 0, 0);
223 strcpy(storename, name);
224 /* vcard_n_prettyize(storename); */
231 /* display_vcard() calls this after parsing the textual vCard into
232 * our 'struct vCard' data object.
234 * Set 'full' to nonzero to display the full card, otherwise it will only
235 * show a summary line.
237 * This code is a bit ugly, so perhaps an explanation is due: we do this
238 * in two passes through the vCard fields. On the first pass, we process
239 * fields we understand, and then render them in a pretty fashion at the
240 * end. Then we make a second pass, outputting all the fields we don't
241 * understand in a simple two-column name/value format.
243 void display_parsed_vcard(struct vCard *v, int full) {
249 char *thisname, *thisvalue;
250 char firsttoken[SIZ];
253 char displayname[SIZ];
259 strcpy(displayname, "");
267 name = vcard_get_prop(v, "fn", 1, 0, 0);
271 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
272 strcpy(displayname, name);
273 vcard_n_prettyize(displayname);
274 escputs(displayname);
283 wprintf("<div align=center><table bgcolor=#aaaaaa width=50%%>");
284 for (pass=1; pass<=2; ++pass) {
286 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
288 thisname = strdup(v->prop[i].name);
289 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
291 for (j=0; j<num_tokens(thisname, ';'); ++j) {
292 extract_token(buf, thisname, j, ';', sizeof buf);
293 if (!strcasecmp(buf, "encoding=quoted-printable")) {
295 remove_token(thisname, j, ';');
297 if (!strcasecmp(buf, "encoding=base64")) {
299 remove_token(thisname, j, ';');
304 thisvalue = malloc(strlen(v->prop[i].value) + 50);
305 j = CtdlDecodeQuotedPrintable(
306 thisvalue, v->prop[i].value,
307 strlen(v->prop[i].value) );
311 thisvalue = malloc(strlen(v->prop[i].value) + 50);
313 thisvalue, v->prop[i].value,
314 strlen(v->prop[i].value) );
317 thisvalue = strdup(v->prop[i].value);
320 /*** Various fields we may encounter ***/
322 /* N is name, but only if there's no FN already there */
323 if (!strcasecmp(firsttoken, "n")) {
324 if (strlen(displayname) == 0) {
325 strcpy(displayname, thisvalue);
326 vcard_n_prettyize(displayname);
330 /* FN (full name) is a true 'display name' field */
331 else if (!strcasecmp(firsttoken, "fn")) {
332 strcpy(displayname, thisvalue);
336 else if (!strcasecmp(firsttoken, "title")) {
337 strcpy(title, thisvalue);
341 else if (!strcasecmp(firsttoken, "org")) {
342 strcpy(org, thisvalue);
345 else if (!strcasecmp(firsttoken, "email")) {
346 if (strlen(mailto) > 0) strcat(mailto, "<br />");
348 "<a href=\"display_enter"
349 "?force_room=_MAIL_?recp=");
351 urlesc(&mailto[strlen(mailto)], displayname);
352 urlesc(&mailto[strlen(mailto)], " <");
353 urlesc(&mailto[strlen(mailto)], thisvalue);
354 urlesc(&mailto[strlen(mailto)], ">");
356 strcat(mailto, "\">");
357 stresc(&mailto[strlen(mailto)], thisvalue, 1, 1);
358 strcat(mailto, "</A>");
360 else if (!strcasecmp(firsttoken, "tel")) {
361 if (strlen(phone) > 0) strcat(phone, "<br />");
362 strcat(phone, thisvalue);
363 for (j=0; j<num_tokens(thisname, ';'); ++j) {
364 extract_token(buf, thisname, j, ';', sizeof buf);
365 if (!strcasecmp(buf, "tel"))
367 else if (!strcasecmp(buf, "work"))
368 strcat(phone, _(" (work)"));
369 else if (!strcasecmp(buf, "home"))
370 strcat(phone, _(" (home)"));
371 else if (!strcasecmp(buf, "cell"))
372 strcat(phone, _(" (cell)"));
380 else if (!strcasecmp(firsttoken, "adr")) {
383 wprintf(_("Address:"));
384 wprintf("</TD><TD>");
385 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
386 extract_token(buf, thisvalue, j, ';', sizeof buf);
387 if (strlen(buf) > 0) {
389 if (j<3) wprintf("<br />");
393 wprintf("</TD></TR>\n");
396 else if (!strcasecmp(firsttoken, "version")) {
399 else if (!strcasecmp(firsttoken, "rev")) {
402 else if (!strcasecmp(firsttoken, "label")) {
407 /*** Don't show extra fields. They're ugly.
411 wprintf("</TD><TD>");
413 wprintf("</TD></TR>\n");
423 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
424 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
425 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
426 "<FONT SIZE=+1><B>");
427 escputs(displayname);
428 wprintf("</B></FONT>");
429 if (strlen(title) > 0) {
430 wprintf("<div align=right>");
434 if (strlen(org) > 0) {
435 wprintf("<div align=right>");
439 wprintf("</TD></TR>\n");
441 if (strlen(phone) > 0) {
443 wprintf(_("Telephone:"));
444 wprintf("</td><td>%s</td></tr>\n", phone);
446 if (strlen(mailto) > 0) {
448 wprintf(_("E-mail:"));
449 wprintf("</td><td>%s</td></tr>\n", mailto);
455 wprintf("</table></div>\n");
461 * Display a textual vCard
462 * (Converts to a vCard object and then calls the actual display function)
463 * Set 'full' to nonzero to display the whole card instead of a one-liner.
464 * Or, if "storename" is non-NULL, just store the person's name in that
465 * buffer instead of displaying the card at all.
467 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
473 v = vcard_load(vcard_source);
474 if (v == NULL) return;
476 name = vcard_get_prop(v, "n", 1, 0, 0);
482 if (storename != NULL) {
483 fetchname_parsed_vcard(v, storename);
485 else if ( (alpha == 0)
486 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
487 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
489 display_parsed_vcard(v, full);
497 * I wanna SEE that message! (Optional 'section' for encapsulated message/rfc822 submessage)
499 void read_message(long msgnum, int printable_view, char *section) {
501 char mime_partnum[256];
502 char mime_filename[256];
503 char mime_content_type[256];
504 char mime_charset[256];
505 char mime_disposition[256];
508 char mime_submessages[256];
515 char reply_all[4096];
521 char vcard_partnum[256];
522 char cal_partnum[256];
523 char *part_source = NULL;
525 iconv_t ic = (iconv_t)(-1) ;
526 char *ibuf; /* Buffer of characters to be converted */
527 char *obuf; /* Buffer for converted characters */
528 size_t ibuflen; /* Length of input buffer */
529 size_t obuflen; /* Length of output buffer */
530 char *osav; /* Saved pointer to output buffer */
536 strcpy(reply_to, "");
537 strcpy(reply_all, "");
538 strcpy(vcard_partnum, "");
539 strcpy(cal_partnum, "");
540 strcpy(mime_http, "");
541 strcpy(mime_content_type, "text/plain");
542 strcpy(mime_charset, "us-ascii");
543 strcpy(mime_submessages, "");
545 serv_printf("MSG4 %ld|%s", msgnum, section);
546 serv_getln(buf, sizeof buf);
549 wprintf(_("ERROR:"));
550 wprintf("</STRONG> %s<br />\n", &buf[4]);
554 /* begin everythingamundo table */
555 if (!printable_view) {
556 wprintf("<div id=\"fix_scrollbar_bug\">\n");
557 wprintf("<table width=100%% border=1 cellspacing=0 "
558 "cellpadding=0><TR><TD>\n");
561 /* begin message header table */
562 wprintf("<TABLE WIDTH=100%% BORDER=0 CELLSPACING=0 "
563 "CELLPADDING=1 BGCOLOR=\"#CCCCCC\"><TR><TD>\n");
565 wprintf("<SPAN CLASS=\"message_header\">");
566 strcpy(m_subject, "");
569 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
570 if (!strcmp(buf, "000")) {
572 wprintf(_("unexpected end of message"));
573 wprintf("</I><br /><br />\n");
574 wprintf("</SPAN>\n");
577 if (!strncasecmp(buf, "nhdr=yes", 8))
581 if (!strncasecmp(buf, "type=", 5))
582 format_type = atoi(&buf[5]);
583 if (!strncasecmp(buf, "from=", 5)) {
584 strcpy(from, &buf[5]);
586 wprintf("<a href=\"showuser?who=");
588 utf8ify_rfc822_string(from);
595 if (!strncasecmp(buf, "subj=", 5)) {
596 safestrncpy(m_subject, &buf[5], sizeof m_subject);
598 if (!strncasecmp(buf, "cccc=", 5)) {
599 safestrncpy(m_cc, &buf[5], sizeof m_cc);
600 if (strlen(reply_all) > 0) {
601 strcat(reply_all, ", ");
603 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
604 (sizeof reply_all - strlen(reply_all)) );
606 if ((!strncasecmp(buf, "hnod=", 5))
607 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
608 wprintf("(%s) ", &buf[5]);
610 if ((!strncasecmp(buf, "room=", 5))
611 && (strcasecmp(&buf[5], WC->wc_roomname))
612 && (strlen(&buf[5])>0) ) {
614 wprintf("%s> ", &buf[5]);
616 if (!strncasecmp(buf, "rfca=", 5)) {
617 strcpy(rfca, &buf[5]);
623 if (!strncasecmp(buf, "node=", 5)) {
624 strcpy(node, &buf[5]);
625 if ( ((WC->room_flags & QR_NETWORK)
626 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
627 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
630 wprintf("@%s ", &buf[5]);
633 if (!strncasecmp(buf, "rcpt=", 5)) {
637 if (strlen(reply_all) > 0) {
638 strcat(reply_all, ", ");
640 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
641 (sizeof reply_all - strlen(reply_all)) );
643 if (!strncasecmp(buf, "time=", 5)) {
644 fmt_date(now, atol(&buf[5]), 0);
648 if (!strncasecmp(buf, "part=", 5)) {
649 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
650 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
651 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
652 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
653 mime_length = extract_int(&buf[5], 5);
655 if (!strcasecmp(mime_content_type, "message/rfc822")) {
656 if (strlen(mime_submessages) > 0) {
657 strcat(mime_submessages, "|");
659 strcat(mime_submessages, mime_partnum);
661 else if ((!strcasecmp(mime_disposition, "inline"))
662 && (!strncasecmp(mime_content_type, "image/", 6)) ){
663 snprintf(&mime_http[strlen(mime_http)],
664 (sizeof(mime_http) - strlen(mime_http) - 1),
665 "<img src=\"mimepart/%ld/%s/%s\">",
666 msgnum, mime_partnum, mime_filename);
668 else if ( (!strcasecmp(mime_disposition, "attachment"))
669 || (!strcasecmp(mime_disposition, "inline")) ) {
670 snprintf(&mime_http[strlen(mime_http)],
671 (sizeof(mime_http) - strlen(mime_http) - 1),
672 "<a href=\"mimepart/%ld/%s/%s\" "
673 "TARGET=\"wc.%ld.%s\">"
674 "<img src=\"static/diskette_24x.gif\" "
675 "BORDER=0 ALIGN=MIDDLE>\n"
676 "%s (%s, %d bytes)</A><br />\n",
677 msgnum, mime_partnum, mime_filename,
678 msgnum, mime_partnum,
680 mime_content_type, mime_length
684 /*** begin handler prep ***/
685 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
686 strcpy(vcard_partnum, mime_partnum);
689 if (!strcasecmp(mime_content_type, "text/calendar")) {
690 strcpy(cal_partnum, mime_partnum);
693 /*** end handler prep ***/
699 /* Generate a reply-to address */
700 if (strlen(rfca) > 0) {
701 strcpy(reply_to, rfca);
704 if ( (strlen(node) > 0)
705 && (strcasecmp(node, serv_info.serv_nodename))
706 && (strcasecmp(node, serv_info.serv_humannode)) ) {
707 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
711 snprintf(reply_to, sizeof(reply_to), "%s", from);
721 utf8ify_rfc822_string(m_cc);
722 utf8ify_rfc822_string(m_subject);
724 if (strlen(m_cc) > 0) {
726 "<SPAN CLASS=\"message_subject\">");
732 if (strlen(m_subject) > 0) {
734 "<SPAN CLASS=\"message_subject\">");
735 wprintf(_("Subject:"));
742 /* start msg buttons */
743 if (!printable_view) {
744 wprintf("<td align=right>\n");
747 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
748 wprintf("<a href=\"display_enter");
749 if (WC->is_mailbox) {
750 wprintf("?replyquote=%ld", msgnum);
753 urlescputs(reply_to);
754 wprintf("?subject=");
755 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
756 urlescputs(m_subject);
757 wprintf("\">[%s]</a> ", _("Reply"));
761 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
762 if (!WC->is_mailbox) {
763 wprintf("<a href=\"display_enter");
764 wprintf("?replyquote=%ld", msgnum);
766 urlescputs(reply_to);
767 wprintf("?subject=");
768 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
769 urlescputs(m_subject);
770 wprintf("\">[%s]</a> ", _("ReplyQuoted"));
775 if (WC->wc_view == VIEW_MAILBOX) {
776 wprintf("<a href=\"display_enter");
777 wprintf("?replyquote=%ld", msgnum);
779 urlescputs(reply_to);
781 urlescputs(reply_all);
782 if (strlen(m_subject) > 0) {
783 wprintf("?subject=");
784 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
785 urlescputs(m_subject);
787 wprintf("\">[%s]</a> ", _("ReplyAll"));
791 if (WC->wc_view == VIEW_MAILBOX) {
792 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
793 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
794 urlescputs(m_subject);
795 wprintf("\">[%s]</a> ", _("Forward"));
798 /* If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
799 if ( (WC->is_room_aide) || (WC->is_mailbox) ) {
801 wprintf("<a href=\"confirm_move_msg?msgid=%ld\">[%s]</a> ",
805 wprintf("<a href=\"delete_msg?msgid=%ld\" "
806 "onClick=\"return confirm('%s');\">"
807 "[%s]</a> ", msgnum, _("Delete this message?"), _("Delete")
811 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'); \" >"
812 "[%s]</a>", msgnum, msgnum, _("Print"));
817 wprintf("</TR></TABLE>\n");
820 wprintf("<TABLE BORDER=0 WIDTH=100%% BGCOLOR=#FFFFFF "
821 "CELLPADDING=1 CELLSPACING=0><TR><TD>");
824 * Learn the content type
826 strcpy(mime_content_type, "text/plain");
827 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
828 if (!strcmp(buf, "000")) {
830 wprintf(_("unexpected end of message"));
831 wprintf("</I><br /><br />\n");
834 if (!strncasecmp(buf, "Content-type: ", 14)) {
835 safestrncpy(mime_content_type, &buf[14],
836 sizeof(mime_content_type));
837 for (i=0; i<strlen(mime_content_type); ++i) {
838 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
839 safestrncpy(mime_charset, &mime_content_type[i+8],
840 sizeof mime_charset);
843 for (i=0; i<strlen(mime_content_type); ++i) {
844 if (mime_content_type[i] == ';') {
845 mime_content_type[i] = 0;
851 /* Set up a character set conversion if we need to (and if we can) */
853 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
854 if ( (strcasecmp(mime_charset, "us-ascii"))
855 && (strcasecmp(mime_charset, "UTF-8"))
856 && (strcasecmp(mime_charset, ""))
858 ic = iconv_open("UTF-8", mime_charset);
859 if (ic == (iconv_t)(-1) ) {
860 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
861 __FILE__, __LINE__, mime_charset, strerror(errno));
866 /* Messages in legacy Citadel variformat get handled thusly... */
867 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
871 /* Boring old 80-column fixed format text gets handled this way... */
872 else if ( (!strcasecmp(mime_content_type, "text/plain"))
873 || (!strcasecmp(mime_content_type, "text")) ) {
874 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
875 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
876 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
879 if (ic != (iconv_t)(-1) ) {
881 ibuflen = strlen(ibuf);
883 obuf = (char *) malloc(obuflen);
885 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
886 osav[SIZ-obuflen] = 0;
887 safestrncpy(buf, osav, sizeof buf);
892 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
893 buf[strlen(buf) - 1] = 0;
895 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
896 wprintf("<BLOCKQUOTE>");
898 } else if ((bq == 1) &&
899 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
900 wprintf("</BLOCKQUOTE>");
906 wprintf("</TT><br />\n");
908 wprintf("</I><br />");
911 else /* HTML is fun, but we've got to strip it first */
912 if (!strcasecmp(mime_content_type, "text/html")) {
913 output_html(mime_charset);
916 /* Unknown weirdness */
918 wprintf(_("I don't know how to display %s"), mime_content_type);
919 wprintf("<br />\n", mime_content_type);
920 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
923 /* If there are attached submessages, display them now... */
924 if ( (strlen(mime_submessages) > 0) && (!section[0]) ) {
925 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
926 extract_token(buf, mime_submessages, i, '|', sizeof buf);
927 /* use printable_view to suppress buttons */
928 wprintf("<blockquote>");
929 read_message(msgnum, 1, buf);
930 wprintf("</blockquote>");
935 /* Afterwards, offer links to download attachments 'n' such */
936 if ( (strlen(mime_http) > 0) && (!section[0]) ) {
937 wprintf("%s", mime_http);
940 /* Handler for vCard parts */
941 if (strlen(vcard_partnum) > 0) {
942 part_source = load_mimepart(msgnum, vcard_partnum);
943 if (part_source != NULL) {
945 /* If it's my vCard I can edit it */
946 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
947 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
948 || (WC->wc_view == VIEW_ADDRESSBOOK)
950 wprintf("<a href=\"edit_vcard?"
951 "msgnum=%ld?partnum=%s\">",
952 msgnum, vcard_partnum);
953 wprintf("[%s]</A>", _("edit"));
956 /* In all cases, display the full card */
957 display_vcard(part_source, 0, 1, NULL);
961 /* Handler for calendar parts */
962 if (strlen(cal_partnum) > 0) {
963 part_source = load_mimepart(msgnum, cal_partnum);
964 if (part_source != NULL) {
965 cal_process_attachment(part_source,
966 msgnum, cal_partnum);
976 wprintf("</TD></TR></TABLE>\n");
978 /* end everythingamundo table */
979 if (!printable_view) {
980 wprintf("</TD></TR></TABLE>\n");
981 wprintf("</div><br />\n");
985 if (ic != (iconv_t)(-1) ) {
994 * Unadorned HTML output of an individual message, suitable
995 * for placing in a hidden iframe, for printing, or whatever
997 void embed_message(char *msgnum_as_string) {
1000 msgnum = atol(msgnum_as_string);
1001 begin_ajax_response();
1002 read_message(msgnum, 0, "");
1003 end_ajax_response();
1008 * Printable view of a message
1010 void print_message(char *msgnum_as_string) {
1013 msgnum = atol(msgnum_as_string);
1014 output_headers(0, 0, 0, 0, 0, 0);
1016 wprintf("Content-type: text/html\r\n"
1018 "Connection: close\r\n",
1022 wprintf("\r\n\r\n<html>\n"
1023 "<head><title>Printable view</title></head>\n"
1024 "<body onLoad=\" window.print(); window.close(); \">\n"
1027 read_message(msgnum, 1, "");
1029 wprintf("\n</body></html>\n\n");
1036 * Read message in simple, JavaScript-embeddable form for 'forward'
1037 * or 'reply quoted' operations.
1039 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1040 * in this function. Doing so would throw a JavaScript error in the
1041 * 'supplied text' argument to the editor.
1043 void pullquote_message(long msgnum, int forward_attachments) {
1045 char mime_partnum[256];
1046 char mime_filename[256];
1047 char mime_content_type[256];
1048 char mime_charset[256];
1049 char mime_disposition[256];
1051 char mime_http[SIZ];
1052 char *attachments = NULL;
1053 int num_attachments = 0;
1054 struct wc_attachment *att, *aptr;
1055 char m_subject[256];
1061 int format_type = 0;
1066 iconv_t ic = (iconv_t)(-1) ;
1067 char *ibuf; /* Buffer of characters to be converted */
1068 char *obuf; /* Buffer for converted characters */
1069 size_t ibuflen; /* Length of input buffer */
1070 size_t obuflen; /* Length of output buffer */
1071 char *osav; /* Saved pointer to output buffer */
1077 strcpy(reply_to, "");
1078 strcpy(mime_http, "");
1079 strcpy(mime_content_type, "text/plain");
1080 strcpy(mime_charset, "us-ascii");
1082 serv_printf("MSG4 %ld", msgnum);
1083 serv_getln(buf, sizeof buf);
1084 if (buf[0] != '1') {
1085 wprintf(_("ERROR:"));
1086 wprintf("%s<br />", &buf[4]);
1090 strcpy(m_subject, "");
1092 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1093 if (!strcmp(buf, "000")) {
1094 wprintf(_("unexpected end of message"));
1097 if (!strncasecmp(buf, "nhdr=yes", 8))
1101 if (!strncasecmp(buf, "type=", 5))
1102 format_type = atoi(&buf[5]);
1103 if (!strncasecmp(buf, "from=", 5)) {
1104 strcpy(from, &buf[5]);
1105 wprintf(_("from "));
1107 utf8ify_rfc822_string(from);
1111 if (!strncasecmp(buf, "subj=", 5)) {
1112 strcpy(m_subject, &buf[5]);
1114 if ((!strncasecmp(buf, "hnod=", 5))
1115 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1116 wprintf("(%s) ", &buf[5]);
1118 if ((!strncasecmp(buf, "room=", 5))
1119 && (strcasecmp(&buf[5], WC->wc_roomname))
1120 && (strlen(&buf[5])>0) ) {
1122 wprintf("%s> ", &buf[5]);
1124 if (!strncasecmp(buf, "rfca=", 5)) {
1125 strcpy(rfca, &buf[5]);
1131 if (!strncasecmp(buf, "node=", 5)) {
1132 strcpy(node, &buf[5]);
1133 if ( ((WC->room_flags & QR_NETWORK)
1134 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1135 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1136 && (strlen(rfca)==0)
1138 wprintf("@%s ", &buf[5]);
1141 if (!strncasecmp(buf, "rcpt=", 5)) {
1143 wprintf("%s ", &buf[5]);
1145 if (!strncasecmp(buf, "time=", 5)) {
1146 fmt_date(now, atol(&buf[5]), 0);
1147 wprintf("%s ", now);
1151 * Save attachment info for later. We can't start downloading them
1152 * yet because we're in the middle of a server transaction.
1154 if (!strncasecmp(buf, "part=", 5)) {
1156 attachments = realloc(attachments, (num_attachments * 1024));
1157 strcat(attachments, &buf[5]);
1158 strcat(attachments, "\n");
1166 utf8ify_rfc822_string(m_subject);
1168 if (strlen(m_subject) > 0) {
1169 wprintf(_("Subject:"));
1171 msgescputs(m_subject);
1181 * Learn the content type
1183 strcpy(mime_content_type, "text/plain");
1184 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1185 if (!strcmp(buf, "000")) {
1186 wprintf(_("unexpected end of message"));
1189 if (!strncasecmp(buf, "Content-type: ", 14)) {
1190 safestrncpy(mime_content_type, &buf[14],
1191 sizeof(mime_content_type));
1192 for (i=0; i<strlen(mime_content_type); ++i) {
1193 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1194 safestrncpy(mime_charset, &mime_content_type[i+8],
1195 sizeof mime_charset);
1198 for (i=0; i<strlen(mime_content_type); ++i) {
1199 if (mime_content_type[i] == ';') {
1200 mime_content_type[i] = 0;
1206 /* Set up a character set conversion if we need to (and if we can) */
1208 if ( (strcasecmp(mime_charset, "us-ascii"))
1209 && (strcasecmp(mime_charset, "UTF-8"))
1210 && (strcasecmp(mime_charset, ""))
1212 ic = iconv_open("UTF-8", mime_charset);
1213 if (ic == (iconv_t)(-1) ) {
1214 lprintf(5, "%s:%d iconv_open() failed: %s\n",
1215 __FILE__, __LINE__, strerror(errno));
1220 /* Messages in legacy Citadel variformat get handled thusly... */
1221 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1225 /* Boring old 80-column fixed format text gets handled this way... */
1226 else if (!strcasecmp(mime_content_type, "text/plain")) {
1227 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1228 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1229 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1232 if (ic != (iconv_t)(-1) ) {
1234 ibuflen = strlen(ibuf);
1236 obuf = (char *) malloc(obuflen);
1238 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1239 osav[SIZ-obuflen] = 0;
1240 safestrncpy(buf, osav, sizeof buf);
1245 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1246 buf[strlen(buf) - 1] = 0;
1248 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
1249 wprintf("<BLOCKQUOTE>");
1251 } else if ((bq == 1) &&
1252 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
1253 wprintf("</BLOCKQUOTE>");
1259 wprintf("</TT><br />");
1261 wprintf("</I><br />");
1264 /* HTML just gets escaped and stuffed back into the editor */
1265 else if (!strcasecmp(mime_content_type, "text/html")) {
1266 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1271 /* Unknown weirdness ... don't know how to handle this content type */
1273 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1277 /* end of body handler */
1280 * If there were attachments, we have to download them and insert them
1281 * into the attachment chain for the forwarded message we are composing.
1283 if ( (forward_attachments) && (num_attachments) ) {
1284 for (i=0; i<num_attachments; ++i) {
1285 extract_token(buf, attachments, i, '\n', sizeof buf);
1286 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1287 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1288 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1289 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1290 mime_length = extract_int(buf, 5);
1293 * tracing ... uncomment if necessary
1295 lprintf(9, "fwd filename: %s\n", mime_filename);
1296 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1297 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1298 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1299 lprintf(9, "fwd length : %d\n", mime_length);
1302 if ( (!strcasecmp(mime_disposition, "inline"))
1303 || (!strcasecmp(mime_disposition, "attachment")) ) {
1305 /* Create an attachment struct from this mime part... */
1306 att = malloc(sizeof(struct wc_attachment));
1307 memset(att, 0, sizeof(struct wc_attachment));
1308 att->length = mime_length;
1309 strcpy(att->content_type, mime_content_type);
1310 strcpy(att->filename, mime_filename);
1312 att->data = load_mimepart(msgnum, mime_partnum);
1314 /* And add it to the list. */
1315 if (WC->first_attachment == NULL) {
1316 WC->first_attachment = att;
1319 aptr = WC->first_attachment;
1320 while (aptr->next != NULL) aptr = aptr->next;
1330 if (ic != (iconv_t)(-1) ) {
1337 void display_summarized(int num) {
1340 wprintf("<tr id=\"m%ld\" style=\"width:100%%;font-weight:%s;background-color:#fff\" "
1341 "onClick=\"CtdlSingleClickMsg(event,%ld)\">",
1342 WC->summ[num].msgnum,
1343 (WC->summ[num].is_new ? "bold" : "normal"),
1344 WC->summ[num].msgnum
1347 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1348 escputs(WC->summ[num].subj);
1351 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1352 escputs(WC->summ[num].from);
1355 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1356 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1367 void display_addressbook(long msgnum, char alpha) {
1369 char mime_partnum[SIZ];
1370 char mime_filename[SIZ];
1371 char mime_content_type[SIZ];
1372 char mime_disposition[SIZ];
1374 char vcard_partnum[SIZ];
1375 char *vcard_source = NULL;
1376 struct message_summary summ;
1378 memset(&summ, 0, sizeof(summ));
1379 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1381 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1383 serv_getln(buf, sizeof buf);
1384 if (buf[0] != '1') return;
1386 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1387 if (!strncasecmp(buf, "part=", 5)) {
1388 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1389 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1390 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1391 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1392 mime_length = extract_int(&buf[5], 5);
1394 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1395 strcpy(vcard_partnum, mime_partnum);
1401 if (strlen(vcard_partnum) > 0) {
1402 vcard_source = load_mimepart(msgnum, vcard_partnum);
1403 if (vcard_source != NULL) {
1405 /* Display the summary line */
1406 display_vcard(vcard_source, alpha, 0, NULL);
1408 /* If it's my vCard I can edit it */
1409 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1410 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1411 || (WC->wc_view == VIEW_ADDRESSBOOK)
1413 wprintf("<a href=\"edit_vcard?"
1414 "msgnum=%ld?partnum=%s\">",
1415 msgnum, vcard_partnum);
1416 wprintf("[%s]</A>", _("edit"));
1427 /* If it's an old "Firstname Lastname" style record, try to
1430 void lastfirst_firstlast(char *namebuf) {
1431 char firstname[SIZ];
1435 if (namebuf == NULL) return;
1436 if (strchr(namebuf, ';') != NULL) return;
1438 i = num_tokens(namebuf, ' ');
1441 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1442 remove_token(namebuf, i-1, ' ');
1443 strcpy(firstname, namebuf);
1444 sprintf(namebuf, "%s; %s", lastname, firstname);
1448 void fetch_ab_name(long msgnum, char *namebuf) {
1450 char mime_partnum[SIZ];
1451 char mime_filename[SIZ];
1452 char mime_content_type[SIZ];
1453 char mime_disposition[SIZ];
1455 char vcard_partnum[SIZ];
1456 char *vcard_source = NULL;
1458 struct message_summary summ;
1460 if (namebuf == NULL) return;
1461 strcpy(namebuf, "");
1463 memset(&summ, 0, sizeof(summ));
1464 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1466 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1468 serv_getln(buf, sizeof buf);
1469 if (buf[0] != '1') return;
1471 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1472 if (!strncasecmp(buf, "part=", 5)) {
1473 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1474 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1475 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1476 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1477 mime_length = extract_int(&buf[5], 5);
1479 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1480 strcpy(vcard_partnum, mime_partnum);
1486 if (strlen(vcard_partnum) > 0) {
1487 vcard_source = load_mimepart(msgnum, vcard_partnum);
1488 if (vcard_source != NULL) {
1490 /* Grab the name off the card */
1491 display_vcard(vcard_source, 0, 0, namebuf);
1497 lastfirst_firstlast(namebuf);
1499 for (i=0; i<strlen(namebuf); ++i) {
1500 if (namebuf[i] != ';') return;
1502 strcpy(namebuf, _("(no name)"));
1508 * Record compare function for sorting address book indices
1510 int abcmp(const void *ab1, const void *ab2) {
1512 (((const struct addrbookent *)ab1)->ab_name),
1513 (((const struct addrbookent *)ab2)->ab_name)
1519 * Helper function for do_addrbook_view()
1520 * Converts a name into a three-letter tab label
1522 void nametab(char *tabbuf, char *name) {
1523 stresc(tabbuf, name, 0, 0);
1524 tabbuf[0] = toupper(tabbuf[0]);
1525 tabbuf[1] = tolower(tabbuf[1]);
1526 tabbuf[2] = tolower(tabbuf[2]);
1532 * Render the address book using info we gathered during the scan
1534 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1538 static int NAMESPERPAGE = 60;
1542 char tabfirst_label[SIZ];
1544 char tablast_label[SIZ];
1547 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1548 wprintf(_("This address book is empty."));
1549 wprintf("</i></div>\n");
1554 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1557 num_pages = num_ab / NAMESPERPAGE;
1559 page = atoi(bstr("page"));
1562 for (i=0; i<=num_pages; ++i) {
1564 wprintf("<a href=\"readfwd?page=%d\">", i);
1569 tabfirst = i * NAMESPERPAGE;
1570 tablast = tabfirst + NAMESPERPAGE - 1;
1571 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1572 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1573 nametab(tablast_label, addrbook[tablast].ab_name);
1574 wprintf("[%s - %s]",
1575 tabfirst_label, tablast_label
1584 wprintf("<br />\n");
1586 wprintf("<TABLE border=0 cellspacing=0 "
1587 "cellpadding=3 width=100%%>\n"
1590 for (i=0; i<num_ab; ++i) {
1592 if ((i / NAMESPERPAGE) == page) {
1594 if ((displayed % 4) == 0) {
1595 if (displayed > 0) {
1599 wprintf("<TR BGCOLOR=\"#%s\">",
1600 (bg ? "DDDDDD" : "FFFFFF")
1606 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
1607 addrbook[i].ab_msgnum);
1608 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1609 vcard_n_prettyize(addrbook[i].ab_name);
1610 escputs(addrbook[i].ab_name);
1611 wprintf("</A></TD>\n");
1616 wprintf("</TR></TABLE>\n");
1622 * load message pointers from the server
1624 int load_msg_ptrs(char *servcmd, int with_headers)
1628 char displayname[128];
1635 int num_summ_alloc = 0;
1638 if (WC->num_summ != 0) {
1643 num_summ_alloc = 100;
1645 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1648 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1650 serv_getln(buf, sizeof buf);
1651 if (buf[0] != '1') {
1652 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1655 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1656 if (nummsgs < maxload) {
1657 WC->msgarr[nummsgs] = extract_long(buf, 0);
1658 datestamp = extract_long(buf, 1);
1659 extract_token(displayname, buf, 2, '|', sizeof displayname);
1660 extract_token(nodename, buf, 3, '|', sizeof nodename);
1661 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1662 extract_token(subject, buf, 5, '|', sizeof subject);
1666 if (nummsgs > num_summ_alloc) {
1667 num_summ_alloc *= 2;
1668 WC->summ = realloc(WC->summ, num_summ_alloc * sizeof(struct message_summary));
1672 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1673 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1674 safestrncpy(WC->summ[nummsgs-1].subj, _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1675 if (strlen(displayname) > 0) {
1676 safestrncpy(WC->summ[nummsgs-1].from, displayname, sizeof WC->summ[nummsgs-1].from);
1678 if (strlen(subject) > 0) {
1679 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1680 sizeof WC->summ[nummsgs-1].subj);
1683 /* Handle subjects with RFC2047 encoding */
1684 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1686 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1687 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1690 if (strlen(nodename) > 0) {
1691 if ( ((WC->room_flags & QR_NETWORK)
1692 || ((strcasecmp(nodename, serv_info.serv_nodename)
1693 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1695 strcat(WC->summ[nummsgs-1].from, " @ ");
1696 strcat(WC->summ[nummsgs-1].from, nodename);
1700 WC->summ[nummsgs-1].date = datestamp;
1703 /* Handle senders with RFC2047 encoding */
1704 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1706 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1707 strcpy(&WC->summ[nummsgs-1].from[22], "...");
1715 int longcmp_r(const void *s1, const void *s2) {
1722 if (l1 > l2) return(-1);
1723 if (l1 < l2) return(+1);
1728 int summcmp_subj(const void *s1, const void *s2) {
1729 struct message_summary *summ1;
1730 struct message_summary *summ2;
1732 summ1 = (struct message_summary *)s1;
1733 summ2 = (struct message_summary *)s2;
1734 return strcasecmp(summ1->subj, summ2->subj);
1737 int summcmp_rsubj(const void *s1, const void *s2) {
1738 struct message_summary *summ1;
1739 struct message_summary *summ2;
1741 summ1 = (struct message_summary *)s1;
1742 summ2 = (struct message_summary *)s2;
1743 return strcasecmp(summ2->subj, summ1->subj);
1746 int summcmp_sender(const void *s1, const void *s2) {
1747 struct message_summary *summ1;
1748 struct message_summary *summ2;
1750 summ1 = (struct message_summary *)s1;
1751 summ2 = (struct message_summary *)s2;
1752 return strcasecmp(summ1->from, summ2->from);
1755 int summcmp_rsender(const void *s1, const void *s2) {
1756 struct message_summary *summ1;
1757 struct message_summary *summ2;
1759 summ1 = (struct message_summary *)s1;
1760 summ2 = (struct message_summary *)s2;
1761 return strcasecmp(summ2->from, summ1->from);
1764 int summcmp_date(const void *s1, const void *s2) {
1765 struct message_summary *summ1;
1766 struct message_summary *summ2;
1768 summ1 = (struct message_summary *)s1;
1769 summ2 = (struct message_summary *)s2;
1771 if (summ1->date < summ2->date) return -1;
1772 else if (summ1->date > summ2->date) return +1;
1776 int summcmp_rdate(const void *s1, const void *s2) {
1777 struct message_summary *summ1;
1778 struct message_summary *summ2;
1780 summ1 = (struct message_summary *)s1;
1781 summ2 = (struct message_summary *)s2;
1783 if (summ1->date < summ2->date) return +1;
1784 else if (summ1->date > summ2->date) return -1;
1789 * command loop for reading messages
1791 void readloop(char *oper)
1800 long *displayed_msgs = NULL;
1801 int num_displayed = 0;
1803 int is_addressbook = 0;
1804 int is_singlecard = 0;
1805 int is_calendar = 0;
1809 int lowest_displayed = (-1);
1810 int highest_displayed = 0;
1811 struct addrbookent *addrbook = NULL;
1813 char *sortby = NULL;
1814 char sortpref_name[128];
1815 char sortpref_value[128];
1816 char *subjsort_button;
1817 char *sendsort_button;
1818 char *datesort_button;
1819 int bbs_reverse = 0; /* FIXME we need to set/reset this option now. It works. */
1821 startmsg = atol(bstr("startmsg"));
1822 maxmsgs = atoi(bstr("maxmsgs"));
1823 is_summary = atoi(bstr("summary"));
1824 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1826 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
1827 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
1829 sortby = bstr("sortby");
1830 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
1831 set_preference(sortpref_name, sortby, 1);
1833 if (strlen(sortby) == 0) sortby = sortpref_value;
1836 if (strlen(sortby) == 0) sortby = "rdate";
1838 /* message board sort */
1839 if (!strcasecmp(sortby, "reverse")) {
1846 output_headers(1, 1, 1, 0, 0, 0);
1848 /* When in summary mode, always show ALL messages instead of just
1849 * new or old. Otherwise, show what the user asked for.
1851 if (!strcmp(oper, "readnew")) {
1852 strcpy(cmd, "MSGS NEW");
1854 else if (!strcmp(oper, "readold")) {
1855 strcpy(cmd, "MSGS OLD");
1858 strcpy(cmd, "MSGS ALL");
1861 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
1863 strcpy(cmd, "MSGS ALL");
1866 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
1868 strcpy(cmd, "MSGS ALL");
1873 strcpy(cmd, "MSGS ALL|||1"); /* fetch header summary */
1878 /* Are we doing a summary view? If so, we need to know old messages
1879 * and new messages, so we can do that pretty boldface thing for the
1882 strcpy(old_msgs, "");
1885 serv_getln(buf, sizeof buf);
1886 if (buf[0] == '2') {
1887 strcpy(old_msgs, &buf[4]);
1891 is_singlecard = atoi(bstr("is_singlecard"));
1893 if (WC->wc_view == VIEW_CALENDAR) { /* calendar */
1895 strcpy(cmd, "MSGS ALL");
1898 if (WC->wc_view == VIEW_TASKS) { /* tasks */
1900 strcpy(cmd, "MSGS ALL");
1903 if (WC->wc_view == VIEW_NOTES) { /* notes */
1905 strcpy(cmd, "MSGS ALL");
1909 nummsgs = load_msg_ptrs(cmd, is_summary);
1912 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
1914 if (!strcmp(oper, "readnew")) {
1915 wprintf(_("No new messages."));
1916 } else if (!strcmp(oper, "readold")) {
1917 wprintf(_("No old messages."));
1919 wprintf(_("No messages here."));
1928 for (a = 0; a < nummsgs; ++a) {
1929 /* Are you a new message, or an old message? */
1931 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
1932 WC->summ[a].is_new = 0;
1935 WC->summ[a].is_new = 1;
1941 if (startmsg == 0L) {
1943 startmsg = WC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
1946 startmsg = WC->msgarr[0];
1951 if (!strcasecmp(sortby, "subject")) {
1952 qsort(WC->summ, WC->num_summ,
1953 sizeof(struct message_summary), summcmp_subj);
1955 else if (!strcasecmp(sortby, "rsubject")) {
1956 qsort(WC->summ, WC->num_summ,
1957 sizeof(struct message_summary), summcmp_rsubj);
1959 else if (!strcasecmp(sortby, "sender")) {
1960 qsort(WC->summ, WC->num_summ,
1961 sizeof(struct message_summary), summcmp_sender);
1963 else if (!strcasecmp(sortby, "rsender")) {
1964 qsort(WC->summ, WC->num_summ,
1965 sizeof(struct message_summary), summcmp_rsender);
1967 else if (!strcasecmp(sortby, "date")) {
1968 qsort(WC->summ, WC->num_summ,
1969 sizeof(struct message_summary), summcmp_date);
1971 else if (!strcasecmp(sortby, "rdate")) {
1972 qsort(WC->summ, WC->num_summ,
1973 sizeof(struct message_summary), summcmp_rdate);
1977 if (!strcasecmp(sortby, "subject")) {
1978 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
1980 else if (!strcasecmp(sortby, "rsubject")) {
1981 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
1984 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
1987 if (!strcasecmp(sortby, "sender")) {
1988 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
1990 else if (!strcasecmp(sortby, "rsender")) {
1991 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
1994 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
1997 if (!strcasecmp(sortby, "date")) {
1998 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2000 else if (!strcasecmp(sortby, "rdate")) {
2001 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2004 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2008 wprintf("</div>\n"); /* end of 'content' div */
2010 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2011 " document.onkeydown = CtdlMsgListKeyPress; "
2012 " if (document.layers) { "
2013 " document.captureEvents(Event.KEYPRESS); "
2018 /* note that Date and Delete are now in the same column */
2019 wprintf("<div id=\"message_list_hdr\">"
2020 "<div id=\"fix_scrollbar_bug\">"
2021 "<table cellspacing=0 style=\"width:100%%\">"
2024 wprintf("<td width=%d%%><b><i>%s</i></b> %s</td>"
2025 "<td width=%d%%><b><i>%s</i></b> %s</td>"
2026 "<td width=%d%%><b><i>%s</i></b> %s"
2028 "<input type=\"submit\" name=\"delete_button\" style=\"font-size:6pt\" "
2029 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2035 _("Subject"), subjsort_button,
2036 SENDER_COL_WIDTH_PCT,
2037 _("Sender"), sendsort_button,
2038 DATE_PLUS_BUTTONS_WIDTH_PCT,
2039 _("Date"), datesort_button,
2042 wprintf("</table></div></div>\n");
2044 wprintf("<div id=\"message_list\">"
2046 "<div id=\"fix_scrollbar_bug\">\n"
2048 "<span class=\"mailbox_summary\">"
2049 "<table id=\"summary_headers\" rules=rows cellspacing=0 style=\"width:100%%\">"
2053 for (a = 0; a < nummsgs; ++a) {
2054 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2056 /* Display the message */
2058 display_summarized(a);
2060 else if (is_addressbook) {
2061 fetch_ab_name(WC->msgarr[a], buf);
2063 addrbook = realloc(addrbook,
2064 (sizeof(struct addrbookent) * num_ab) );
2065 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2066 sizeof(addrbook[num_ab-1].ab_name));
2067 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
2069 else if (is_calendar) {
2070 display_calendar(WC->msgarr[a]);
2072 else if (is_tasks) {
2073 display_task(WC->msgarr[a]);
2075 else if (is_notes) {
2076 display_note(WC->msgarr[a]);
2079 if (displayed_msgs == NULL) {
2080 displayed_msgs = malloc(sizeof(long) *
2081 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2083 displayed_msgs[num_displayed] = WC->msgarr[a];
2086 if (lowest_displayed < 0) lowest_displayed = a;
2087 highest_displayed = a;
2093 if (displayed_msgs != NULL) {
2095 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2098 for (a=0; a<num_displayed; ++a) {
2099 read_message(displayed_msgs[a], 0, "");
2101 free(displayed_msgs);
2102 displayed_msgs = NULL;
2106 wprintf("</table></span>"
2107 "</div>\n"); /* end of 'fix_scrollbar_bug' div */
2108 wprintf("</div>"); /* end of 'message_list' div */
2110 wprintf("<div id=\"preview_pane\">"); /* The preview pane will initially be empty */
2113 /* Bump these because although we're thinking in zero base, the user
2114 * is a drooling idiot and is thinking in one base.
2117 ++highest_displayed;
2120 * If we're not currently looking at ALL requested
2121 * messages, then display the selector bar
2123 if (num_displayed > 1) {
2124 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2125 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2127 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2129 wprintf("<select name=\"whichones\" size=\"1\" "
2130 "OnChange=\"location.href=msgomatic.whichones.options"
2131 "[selectedIndex].value\">\n");
2134 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2136 lo = b - maxmsgs + 2;
2138 wprintf("<option %s value="
2143 "%d-%d</option> \n",
2144 ((WC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2153 for (b=0; b<nummsgs; b = b + maxmsgs) {
2155 hi = b + maxmsgs + 1;
2156 if (hi > nummsgs) hi = nummsgs;
2157 wprintf("<option %s value="
2162 "%d-%d</option> \n",
2163 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2172 wprintf("<option value=\"%s?startmsg=%ld"
2173 "?maxmsgs=9999999?summary=%d\">"
2177 WC->msgarr[0], is_summary);
2179 wprintf("</select> ");
2180 wprintf(_("of %d messages."), nummsgs);
2182 /* forward/reverse */
2183 wprintf(" <select name=\"direction\" size=\"1\" "
2184 "OnChange=\"location.href=msgomatic.direction.options"
2185 "[selectedIndex].value\">\n"
2188 wprintf("<option %s value=\"%s&sortby=forward\">oldest to newest</option>\n",
2189 (bbs_reverse ? "" : "selected"),
2193 wprintf("<option %s value=\"%s&sortby=reverse\">newest to oldest</option>\n",
2194 (bbs_reverse ? "selected" : ""),
2198 wprintf("</select>");
2204 do_tasks_view(); /* Render the task list */
2208 do_calendar_view(); /* Render the calendar */
2211 if (is_addressbook) {
2212 do_addrbook_view(addrbook, num_ab); /* Render the address book */
2215 /* Put the data transfer hidden iframe in a hidden div, to make it *really* hidden */
2217 "<div display=\"hidden\">\n"
2218 "<iframe name=\"msgloader1\" id=\"msgloader1\" width=\"1\"></iframe>\n"
2221 /* Note: wDumpContent() will output one additional </div> tag. */
2223 if (addrbook != NULL) free(addrbook);
2225 /* free the summary */
2226 if (WC->num_summ != 0) {
2234 * Back end for post_message() ... this is where the actual message
2235 * gets transmitted to the server.
2237 void post_mime_to_server(void) {
2239 int is_multipart = 0;
2241 struct wc_attachment *att;
2243 size_t encoded_length;
2245 /* RFC2045 requires this, and some clients look for it... */
2246 serv_puts("MIME-Version: 1.0");
2248 /* If there are attachments, we have to do multipart/mixed */
2249 if (WC->first_attachment != NULL) {
2254 sprintf(boundary, "---Citadel-Multipart-%s-%04x%04x---",
2255 serv_info.serv_fqdn,
2260 /* Remember, serv_printf() appends an extra newline */
2261 serv_printf("Content-type: multipart/mixed; "
2262 "boundary=\"%s\"\n", boundary);
2263 serv_printf("This is a multipart message in MIME format.\n");
2264 serv_printf("--%s", boundary);
2267 serv_puts("Content-type: text/html; charset=utf-8");
2269 serv_puts("<HTML><BODY>\n");
2270 text_to_server(bstr("msgtext"), 0);
2271 serv_puts("</BODY></HTML>\n");
2276 /* Add in the attachments */
2277 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2279 encoded_length = ((att->length * 150) / 100);
2280 encoded = malloc(encoded_length);
2281 if (encoded == NULL) break;
2282 CtdlEncodeBase64(encoded, att->data, att->length);
2284 serv_printf("--%s", boundary);
2285 serv_printf("Content-type: %s", att->content_type);
2286 serv_printf("Content-disposition: attachment; "
2287 "filename=\"%s\"", att->filename);
2288 serv_puts("Content-transfer-encoding: base64");
2290 serv_write(encoded, strlen(encoded));
2295 serv_printf("--%s--", boundary);
2303 * Post message (or don't post message)
2305 * Note regarding the "dont_post" variable:
2306 * A random value (actually, it's just a timestamp) is inserted as a hidden
2307 * field called "postseq" when the display_enter page is generated. This
2308 * value is checked when posting, using the static variable dont_post. If a
2309 * user attempts to post twice using the same dont_post value, the message is
2310 * discarded. This prevents the accidental double-saving of the same message
2311 * if the user happens to click the browser "back" button.
2313 void post_message(void)
2316 static long dont_post = (-1L);
2317 struct wc_attachment *att, *aptr;
2319 if (WC->upload_length > 0) {
2321 /* There's an attachment. Save it to this struct... */
2322 att = malloc(sizeof(struct wc_attachment));
2323 memset(att, 0, sizeof(struct wc_attachment));
2324 att->length = WC->upload_length;
2325 strcpy(att->content_type, WC->upload_content_type);
2326 strcpy(att->filename, WC->upload_filename);
2329 /* And add it to the list. */
2330 if (WC->first_attachment == NULL) {
2331 WC->first_attachment = att;
2334 aptr = WC->first_attachment;
2335 while (aptr->next != NULL) aptr = aptr->next;
2339 /* Mozilla sends a simple filename, which is what we want,
2340 * but Satan's Browser sends an entire pathname. Reduce
2341 * the path to just a filename if we need to.
2343 while (num_tokens(att->filename, '/') > 1) {
2344 remove_token(att->filename, 0, '/');
2346 while (num_tokens(att->filename, '\\') > 1) {
2347 remove_token(att->filename, 0, '\\');
2350 /* Transfer control of this memory from the upload struct
2351 * to the attachment struct.
2353 att->data = WC->upload;
2354 WC->upload_length = 0;
2360 if (strlen(bstr("cancel_button")) > 0) {
2361 sprintf(WC->ImportantMessage,
2362 _("Cancelled. Message was not posted."));
2363 } else if (strlen(bstr("attach_button")) > 0) {
2366 } else if (atol(bstr("postseq")) == dont_post) {
2367 sprintf(WC->ImportantMessage,
2368 _("Automatically cancelled because you have already "
2369 "saved this message."));
2371 sprintf(buf, "ENT0 1|%s|0|4|%s|||%s|%s",
2378 serv_getln(buf, sizeof buf);
2379 if (buf[0] == '4') {
2380 post_mime_to_server();
2381 if ( (strlen(bstr("recp")) > 0)
2382 || (strlen(bstr("cc")) > 0)
2383 || (strlen(bstr("bcc")) > 0)
2385 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2388 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2390 dont_post = atol(bstr("postseq"));
2392 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2398 free_attachments(WC);
2399 readloop("readnew");
2406 * display the message entry screen
2408 void display_enter(void)
2413 struct wc_attachment *att;
2414 int recipient_required = 0;
2415 int recipient_bad = 0;
2418 if (strlen(bstr("force_room")) > 0) {
2419 gotoroom(bstr("force_room"));
2422 /* Are we perhaps in an address book view? If so, then an "enter
2423 * message" command really means "add new entry."
2425 if (WC->wc_view == VIEW_ADDRESSBOOK) {
2426 do_edit_vcard(-1, "", "");
2430 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
2431 /* Are we perhaps in a calendar view? If so, then an "enter
2432 * message" command really means "add new calendar item."
2434 if (WC->wc_view == VIEW_CALENDAR) {
2435 display_edit_event();
2439 /* Are we perhaps in a tasks view? If so, then an "enter
2440 * message" command really means "add new task."
2442 if (WC->wc_view == VIEW_TASKS) {
2443 display_edit_task();
2449 * Otherwise proceed normally.
2450 * Do a custom room banner with no navbar...
2452 output_headers(1, 1, 2, 0, 0, 0);
2453 wprintf("<div id=\"banner\">\n");
2454 embed_room_banner(NULL, navbar_none);
2455 wprintf("</div>\n");
2456 wprintf("<div id=\"content\">\n"
2457 "<div id=\"fix_scrollbar_bug\">"
2458 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
2460 /* First test to see whether this is a room that requires recipients to be entered */
2461 serv_puts("ENT0 0");
2462 serv_getln(buf, sizeof buf);
2463 if (!strncmp(buf, "570", 3)) { /* 570 means that we need a recipient here */
2464 recipient_required = 1;
2466 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
2467 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2471 /* Now check our actual recipients if there are any */
2472 if (recipient_required) {
2473 sprintf(buf, "ENT0 0|%s|0|0||||%s|%s", bstr("recp"), bstr("cc"), bstr("bcc"));
2475 serv_getln(buf, sizeof buf);
2477 if (!strncmp(buf, "570", 3)) { /* 570 means we have an invalid recipient listed */
2478 if (strlen(bstr("recp")) + strlen(bstr("cc")) + strlen(bstr("bcc")) > 0) {
2482 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
2483 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2488 /* If we got this far, we can display the message entry screen. */
2491 fmt_date(buf, now, 0);
2492 strcat(&buf[strlen(buf)], _(" <I>from</I> "));
2493 stresc(&buf[strlen(buf)], WC->wc_username, 1, 1);
2495 /* Don't need this anymore, it's in the input box below
2496 if (strlen(bstr("recp")) > 0) {
2497 strcat(&buf[strlen(buf)], _(" <I>to</I> "));
2498 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
2502 strcat(&buf[strlen(buf)], _(" <I>in</I> "));
2503 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
2505 /* begin message entry screen */
2506 wprintf("<form enctype=\"multipart/form-data\" "
2507 "method=\"POST\" action=\"post\" "
2508 "name=\"enterform\""
2510 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2512 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2513 wprintf("%s<br>\n", buf); /* header bar */
2515 wprintf("<table border=\"0\" width=\"100%%\">\n");
2516 if (recipient_required) {
2518 wprintf("<tr><td>");
2519 wprintf("<font size=-1>");
2523 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
2524 escputs(bstr("recp"));
2525 wprintf("\" size=50 maxlength=1000 />");
2526 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
2527 wprintf("</td><td></td></tr>\n");
2529 wprintf("<tr><td>");
2530 wprintf("<font size=-1>");
2534 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
2535 escputs(bstr("cc"));
2536 wprintf("\" size=50 maxlength=1000 />");
2537 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
2538 wprintf("</td><td></td></tr>\n");
2540 wprintf("<tr><td>");
2541 wprintf("<font size=-1>");
2545 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
2546 escputs(bstr("bcc"));
2547 wprintf("\" size=50 maxlength=1000 />");
2548 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
2549 wprintf("</td><td></td></tr>\n");
2551 /* Initialize the autocomplete ajax helpers (found in wclib.js) */
2552 wprintf("<script type=\"text/javascript\"> \n"
2553 " activate_entmsg_autocompleters(); \n"
2558 wprintf("<tr><td>");
2559 wprintf("<font size=-1>");
2560 wprintf(_("Subject (optional):"));
2563 "<input type=\"text\" name=\"subject\" value=\"");
2564 escputs(bstr("subject"));
2565 wprintf("\" size=50 maxlength=70></td><td>\n");
2567 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2568 if (recipient_required) {
2569 wprintf(_("Send message"));
2571 wprintf(_("Post message"));
2574 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2575 wprintf("</td></tr></table>\n");
2577 wprintf("<center>");
2579 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
2581 /* If we're continuing from a previous edit, put our partially-composed message back... */
2582 msgescputs(bstr("msgtext"));
2584 /* If we're forwarding a message, insert it here... */
2585 if (atol(bstr("fwdquote")) > 0L) {
2586 wprintf("<br><div align=center><i>");
2587 wprintf(_("--- forwarded message ---"));
2588 wprintf("</i></div><br>");
2589 pullquote_message(atol(bstr("fwdquote")), 1);
2592 /* If we're replying quoted, insert the quote here... */
2593 else if (atol(bstr("replyquote")) > 0L) {
2596 pullquote_message(atol(bstr("replyquote")), 0);
2597 wprintf("</blockquote>");
2600 /* Insert our signature if appropriate... */
2601 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
2602 get_preference("use_sig", buf, sizeof buf);
2603 if (!strcasecmp(buf, "yes")) {
2604 get_preference("signature", ebuf, sizeof ebuf);
2605 euid_unescapize(buf, ebuf);
2606 wprintf("<br>--<br>");
2607 for (i=0; i<strlen(buf); ++i) {
2608 if (buf[i] == '\n') {
2611 else if (buf[i] == '<') {
2614 else if (buf[i] == '>') {
2617 else if (buf[i] == '&') {
2620 else if (buf[i] == '\"') {
2623 else if (buf[i] == '\'') {
2626 else if (isprint(buf[i])) {
2627 wprintf("%c", buf[i]);
2633 wprintf("</textarea>");
2634 wprintf("</center><br />\n");
2637 * The following script embeds the TinyMCE richedit control, and automatically
2638 * transforms the textarea into a richedit textarea.
2641 "<script language=\"javascript\" type=\"text/javascript\" src=\"tiny_mce/tiny_mce.js\"></script>\n"
2642 "<script language=\"javascript\" type=\"text/javascript\">"
2644 " mode : \"textareas\", width : \"100%%\", browsers : \"msie,gecko\" "
2649 /* Enumerate any attachments which are already in place... */
2650 wprintf("<img src=\"static/diskette_24x.gif\" border=0 "
2651 "align=middle height=16 width=16> Attachments: ");
2652 wprintf("<select name=\"which_attachment\" size=1>");
2653 for (att = WC->first_attachment; att != NULL; att = att->next) {
2654 wprintf("<option value=\"");
2655 urlescputs(att->filename);
2657 escputs(att->filename);
2658 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
2659 wprintf("</option>\n");
2661 wprintf("</select>");
2663 /* Now offer the ability to attach additional files... */
2664 wprintf(" "
2665 "Attach file: <input NAME=\"attachfile\" "
2666 "SIZE=16 TYPE=\"file\">\n "
2667 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
2669 /* Seth asked for these to be at the top *and* bottom... */
2670 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2671 if (recipient_required) {
2672 wprintf(_("Send message"));
2674 wprintf(_("Post message"));
2677 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2679 /* Make sure we only insert our signature once */
2680 if (strcmp(bstr("sig_inserted"), "yes")) {
2681 wprintf("<INPUT TYPE=\"hidden\" NAME=\"sig_inserted\" VALUE=\"yes\">\n");
2684 wprintf("</form>\n");
2686 wprintf("</td></tr></table></div>\n");
2687 DONE: wDumpContent(1);
2697 void delete_msg(void)
2702 msgid = atol(bstr("msgid"));
2704 output_headers(1, 1, 1, 0, 0, 0);
2706 serv_printf("MOVE %ld|_TRASH_|0", msgid);
2707 serv_getln(buf, sizeof buf);
2708 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2717 * Confirm move of a message
2719 void confirm_move_msg(void)
2725 msgid = atol(bstr("msgid"));
2728 output_headers(1, 1, 2, 0, 0, 0);
2729 wprintf("<div id=\"banner\">\n");
2730 wprintf("<TABLE WIDTH=100%% BORDER=0><TR><TD>");
2731 wprintf("<SPAN CLASS=\"titlebar\">");
2732 wprintf(_("Confirm move of message"));
2733 wprintf("</SPAN>\n");
2734 wprintf("</TD></TR></TABLE>\n");
2735 wprintf("</div>\n<div id=\"content\">\n");
2737 wprintf("<CENTER>");
2739 wprintf(_("Move this message to:"));
2740 wprintf("<br />\n");
2742 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
2743 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
2745 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
2747 serv_getln(buf, sizeof buf);
2748 if (buf[0] == '1') {
2749 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2750 extract_token(targ, buf, 0, '|', sizeof targ);
2751 wprintf("<OPTION>");
2756 wprintf("</SELECT>\n");
2757 wprintf("<br />\n");
2759 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
2761 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
2762 wprintf("</form></CENTER>\n");
2764 wprintf("</CENTER>\n");
2775 msgid = atol(bstr("msgid"));
2777 if (strlen(bstr("move_button")) > 0) {
2778 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
2780 serv_getln(buf, sizeof buf);
2781 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2783 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
2786 readloop("readnew");