4 * Functions which deal with the fetching and displaying of messages.
10 #include "webserver.h"
14 /* Address book entry (keep it short and sweet, it's just a quickie lookup
15 * which we can use to get to the real meat and bones later)
25 /* Handle subjects with RFC2047 encoding, such as:
26 * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=
28 void utf8ify_rfc822_string(char *buf) {
34 iconv_t ic = (iconv_t)(-1) ;
35 char *ibuf; /* Buffer of characters to be converted */
36 char *obuf; /* Buffer for converted characters */
37 size_t ibuflen; /* Length of input buffer */
38 size_t obuflen; /* Length of output buffer */
39 char *isav; /* Saved pointer to input buffer */
40 char *osav; /* Saved pointer to output buffer */
43 while (start=strstr(buf, "=?"), end=strstr(buf, "?="),
44 ((start != NULL) && (end != NULL) && (end > start)) )
46 extract_token(charset, start, 1, '?', sizeof charset);
47 extract_token(encoding, start, 2, '?', sizeof encoding);
48 extract_token(istr, start, 3, '?', sizeof istr);
56 if (!strcasecmp(encoding, "B")) { /* base64 */
57 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
59 else if (!strcasecmp(encoding, "Q")) { /* quoted-printable */
60 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, strlen(istr));
63 strcpy(ibuf, istr); /* huh? */
64 ibuflen = strlen(istr);
67 ic = iconv_open("UTF-8", charset);
68 if (ic != (iconv_t)(-1) ) {
71 obuf = (char *) malloc(obuflen);
73 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
74 osav[1024-obuflen] = 0;
79 remove_token(end, 0, '?');
80 remove_token(end, 0, '?');
81 remove_token(end, 0, '?');
82 remove_token(end, 0, '?');
85 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
94 remove_token(end, 0, '?');
95 remove_token(end, 0, '?');
96 remove_token(end, 0, '?');
97 remove_token(end, 0, '?');
100 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
106 /* Since spammers will go to all sorts of absurd lengths to get their
107 * messages through, there are LOTS of corrupt headers out there.
108 * So, prevent a really badly formed RFC2047 header from throwing
109 * this function into an infinite loop.
112 if (passes > 20) return;
120 * Look for URL's embedded in a buffer and make them linkable. We use a
121 * target window in order to keep the BBS session in its own window.
137 for (pos = 0; pos < strlen(buf); ++pos) {
138 if (!strncasecmp(&buf[pos], "http://", 7))
140 if (!strncasecmp(&buf[pos], "ftp://", 6))
147 if ((start > 0) && (buf[start - 1] == '<'))
149 if ((start > 0) && (buf[start - 1] == '['))
151 if ((start > 0) && (buf[start - 1] == '('))
153 if ((start > 0) && (buf[start - 1] == '{'))
156 for (pos = strlen(buf); pos > start; --pos) {
157 if ((buf[pos] == ' ') || (buf[pos] == ench))
161 strncpy(urlbuf, &buf[start], end - start);
162 urlbuf[end - start] = 0;
164 strncpy(outbuf, buf, start);
165 sprintf(&outbuf[start], "%cA HREF=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
166 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
167 strcat(outbuf, &buf[end]);
168 if ( strlen(outbuf) < 250 )
174 * Turn a vCard "n" (name) field into something displayable.
176 void vcard_n_prettyize(char *name)
181 original_name = strdup(name);
182 for (i=0; i<5; ++i) {
183 if (strlen(original_name) > 0) {
184 if (original_name[strlen(original_name)-1] == ' ') {
185 original_name[strlen(original_name)-1] = 0;
187 if (original_name[strlen(original_name)-1] == ';') {
188 original_name[strlen(original_name)-1] = 0;
193 for (i=0; i<strlen(original_name); ++i) {
194 if (original_name[i] == ';') {
198 name[strlen(name)+1] = 0;
199 name[strlen(name)] = original_name[i];
208 /* display_vcard() calls this after parsing the textual vCard into
209 * our 'struct vCard' data object.
210 * This gets called instead of display_parsed_vcard() if we are only looking
211 * to extract the person's name instead of displaying the card.
213 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
216 strcpy(storename, "");
218 name = vcard_get_prop(v, "n", 1, 0, 0);
220 strcpy(storename, name);
221 /* vcard_n_prettyize(storename); */
228 /* display_vcard() calls this after parsing the textual vCard into
229 * our 'struct vCard' data object.
231 * Set 'full' to nonzero to display the full card, otherwise it will only
232 * show a summary line.
234 * This code is a bit ugly, so perhaps an explanation is due: we do this
235 * in two passes through the vCard fields. On the first pass, we process
236 * fields we understand, and then render them in a pretty fashion at the
237 * end. Then we make a second pass, outputting all the fields we don't
238 * understand in a simple two-column name/value format.
240 void display_parsed_vcard(struct vCard *v, int full) {
246 char *thisname, *thisvalue;
247 char firsttoken[SIZ];
250 char displayname[SIZ];
256 strcpy(displayname, "");
264 name = vcard_get_prop(v, "fn", 1, 0, 0);
268 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
269 strcpy(displayname, name);
270 vcard_n_prettyize(displayname);
271 escputs(displayname);
280 wprintf("<div align=center><table bgcolor=#aaaaaa width=50%%>");
281 for (pass=1; pass<=2; ++pass) {
283 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
285 thisname = strdup(v->prop[i].name);
286 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
288 for (j=0; j<num_tokens(thisname, ';'); ++j) {
289 extract_token(buf, thisname, j, ';', sizeof buf);
290 if (!strcasecmp(buf, "encoding=quoted-printable")) {
292 remove_token(thisname, j, ';');
294 if (!strcasecmp(buf, "encoding=base64")) {
296 remove_token(thisname, j, ';');
301 thisvalue = malloc(strlen(v->prop[i].value) + 50);
302 j = CtdlDecodeQuotedPrintable(
303 thisvalue, v->prop[i].value,
304 strlen(v->prop[i].value) );
308 thisvalue = malloc(strlen(v->prop[i].value) + 50);
310 thisvalue, v->prop[i].value,
311 strlen(v->prop[i].value) );
314 thisvalue = strdup(v->prop[i].value);
317 /*** Various fields we may encounter ***/
319 /* N is name, but only if there's no FN already there */
320 if (!strcasecmp(firsttoken, "n")) {
321 if (strlen(displayname) == 0) {
322 strcpy(displayname, thisvalue);
323 vcard_n_prettyize(displayname);
327 /* FN (full name) is a true 'display name' field */
328 else if (!strcasecmp(firsttoken, "fn")) {
329 strcpy(displayname, thisvalue);
333 else if (!strcasecmp(firsttoken, "title")) {
334 strcpy(title, thisvalue);
338 else if (!strcasecmp(firsttoken, "org")) {
339 strcpy(org, thisvalue);
342 else if (!strcasecmp(firsttoken, "email")) {
343 if (strlen(mailto) > 0) strcat(mailto, "<br />");
345 "<A HREF=\"/display_enter"
346 "?force_room=_MAIL_?recp=");
348 urlesc(&mailto[strlen(mailto)], displayname);
349 urlesc(&mailto[strlen(mailto)], " <");
350 urlesc(&mailto[strlen(mailto)], thisvalue);
351 urlesc(&mailto[strlen(mailto)], ">");
353 strcat(mailto, "\">");
354 stresc(&mailto[strlen(mailto)], thisvalue, 1, 1);
355 strcat(mailto, "</A>");
357 else if (!strcasecmp(firsttoken, "tel")) {
358 if (strlen(phone) > 0) strcat(phone, "<br />");
359 strcat(phone, thisvalue);
360 for (j=0; j<num_tokens(thisname, ';'); ++j) {
361 extract_token(buf, thisname, j, ';', sizeof buf);
362 if (!strcasecmp(buf, "tel"))
364 else if (!strcasecmp(buf, "work"))
365 strcat(phone, _(" (work)"));
366 else if (!strcasecmp(buf, "home"))
367 strcat(phone, _(" (home)"));
368 else if (!strcasecmp(buf, "cell"))
369 strcat(phone, _(" (cell)"));
377 else if (!strcasecmp(firsttoken, "adr")) {
380 wprintf(_("Address:"));
381 wprintf("</TD><TD>");
382 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
383 extract_token(buf, thisvalue, j, ';', sizeof buf);
384 if (strlen(buf) > 0) {
386 if (j<3) wprintf("<br />");
390 wprintf("</TD></TR>\n");
393 else if (!strcasecmp(firsttoken, "version")) {
396 else if (!strcasecmp(firsttoken, "rev")) {
399 else if (!strcasecmp(firsttoken, "label")) {
404 /*** Don't show extra fields. They're ugly.
408 wprintf("</TD><TD>");
410 wprintf("</TD></TR>\n");
420 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
421 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
422 "<IMG ALIGN=CENTER SRC=\"/static/viewcontacts_48x.gif\">"
423 "<FONT SIZE=+1><B>");
424 escputs(displayname);
425 wprintf("</B></FONT>");
426 if (strlen(title) > 0) {
427 wprintf("<div align=right>");
431 if (strlen(org) > 0) {
432 wprintf("<div align=right>");
436 wprintf("</TD></TR>\n");
438 if (strlen(phone) > 0) {
440 wprintf(_("Telephone:"));
441 wprintf("</td><td>%s</td></tr>\n", phone);
443 if (strlen(mailto) > 0) {
445 wprintf(_("E-mail:"));
446 wprintf("</td><td>%s</td></tr>\n", mailto);
452 wprintf("</table></div>\n");
458 * Display a textual vCard
459 * (Converts to a vCard object and then calls the actual display function)
460 * Set 'full' to nonzero to display the whole card instead of a one-liner.
461 * Or, if "storename" is non-NULL, just store the person's name in that
462 * buffer instead of displaying the card at all.
464 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
470 v = vcard_load(vcard_source);
471 if (v == NULL) return;
473 name = vcard_get_prop(v, "n", 1, 0, 0);
479 if (storename != NULL) {
480 fetchname_parsed_vcard(v, storename);
482 else if ( (alpha == 0)
483 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
484 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
486 display_parsed_vcard(v, full);
494 * I wanna SEE that message! (Optional 'section' for encapsulated message/rfc822 submessage)
496 void read_message(long msgnum, int printable_view, char *section) {
498 char mime_partnum[256];
499 char mime_filename[256];
500 char mime_content_type[256];
501 char mime_charset[256];
502 char mime_disposition[256];
505 char mime_submessages[256];
512 char reply_all[4096];
518 char vcard_partnum[256];
519 char cal_partnum[256];
520 char *part_source = NULL;
522 iconv_t ic = (iconv_t)(-1) ;
523 char *ibuf; /* Buffer of characters to be converted */
524 char *obuf; /* Buffer for converted characters */
525 size_t ibuflen; /* Length of input buffer */
526 size_t obuflen; /* Length of output buffer */
527 char *osav; /* Saved pointer to output buffer */
533 strcpy(reply_to, "");
534 strcpy(reply_all, "");
535 strcpy(vcard_partnum, "");
536 strcpy(cal_partnum, "");
537 strcpy(mime_http, "");
538 strcpy(mime_content_type, "text/plain");
539 strcpy(mime_charset, "us-ascii");
540 strcpy(mime_submessages, "");
542 serv_printf("MSG4 %ld|%s", msgnum, section);
543 serv_getln(buf, sizeof buf);
546 wprintf(_("ERROR:"));
547 wprintf("</STRONG> %s<br />\n", &buf[4]);
551 /* begin everythingamundo table */
552 if (!printable_view) {
553 wprintf("<div id=\"fix_scrollbar_bug\">\n");
554 wprintf("<table width=100%% border=1 cellspacing=0 "
555 "cellpadding=0><TR><TD>\n");
558 /* begin message header table */
559 wprintf("<TABLE WIDTH=100%% BORDER=0 CELLSPACING=0 "
560 "CELLPADDING=1 BGCOLOR=\"#CCCCCC\"><TR><TD>\n");
562 wprintf("<SPAN CLASS=\"message_header\">");
563 strcpy(m_subject, "");
566 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
567 if (!strcmp(buf, "000")) {
569 wprintf(_("unexpected end of message"));
570 wprintf("</I><br /><br />\n");
571 wprintf("</SPAN>\n");
574 if (!strncasecmp(buf, "nhdr=yes", 8))
578 if (!strncasecmp(buf, "type=", 5))
579 format_type = atoi(&buf[5]);
580 if (!strncasecmp(buf, "from=", 5)) {
581 strcpy(from, &buf[5]);
583 wprintf("<A HREF=\"/showuser?who=");
585 utf8ify_rfc822_string(from);
592 if (!strncasecmp(buf, "subj=", 5)) {
593 safestrncpy(m_subject, &buf[5], sizeof m_subject);
595 if (!strncasecmp(buf, "cccc=", 5)) {
596 safestrncpy(m_cc, &buf[5], sizeof m_cc);
597 if (strlen(reply_all) > 0) {
598 strcat(reply_all, ", ");
600 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
601 (sizeof reply_all - strlen(reply_all)) );
602 lprintf(9, "REPLY_ALL: %s\n", reply_all); // FIXME
604 if ((!strncasecmp(buf, "hnod=", 5))
605 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
606 wprintf("(%s) ", &buf[5]);
608 if ((!strncasecmp(buf, "room=", 5))
609 && (strcasecmp(&buf[5], WC->wc_roomname))
610 && (strlen(&buf[5])>0) ) {
612 wprintf("%s> ", &buf[5]);
614 if (!strncasecmp(buf, "rfca=", 5)) {
615 strcpy(rfca, &buf[5]);
621 if (!strncasecmp(buf, "node=", 5)) {
622 strcpy(node, &buf[5]);
623 if ( ((WC->room_flags & QR_NETWORK)
624 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
625 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
628 wprintf("@%s ", &buf[5]);
631 if (!strncasecmp(buf, "rcpt=", 5)) {
635 if (strlen(reply_all) > 0) {
636 strcat(reply_all, ", ");
638 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
639 (sizeof reply_all - strlen(reply_all)) );
641 if (!strncasecmp(buf, "time=", 5)) {
642 fmt_date(now, atol(&buf[5]), 0);
646 if (!strncasecmp(buf, "part=", 5)) {
647 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
648 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
649 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
650 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
651 mime_length = extract_int(&buf[5], 5);
653 if (!strcasecmp(mime_content_type, "message/rfc822")) {
654 if (strlen(mime_submessages) > 0) {
655 strcat(mime_submessages, "|");
657 strcat(mime_submessages, mime_partnum);
659 else if ((!strcasecmp(mime_disposition, "inline"))
660 && (!strncasecmp(mime_content_type, "image/", 6)) ){
661 snprintf(&mime_http[strlen(mime_http)],
662 (sizeof(mime_http) - strlen(mime_http) - 1),
663 "<IMG SRC=\"/mimepart/%ld/%s/%s\">",
664 msgnum, mime_partnum, mime_filename);
666 else if ( (!strcasecmp(mime_disposition, "attachment"))
667 || (!strcasecmp(mime_disposition, "inline")) ) {
668 snprintf(&mime_http[strlen(mime_http)],
669 (sizeof(mime_http) - strlen(mime_http) - 1),
670 "<A HREF=\"/mimepart/%ld/%s/%s\" "
671 "TARGET=\"wc.%ld.%s\">"
672 "<IMG SRC=\"/static/diskette_24x.gif\" "
673 "BORDER=0 ALIGN=MIDDLE>\n"
674 "%s (%s, %d bytes)</A><br />\n",
675 msgnum, mime_partnum, mime_filename,
676 msgnum, mime_partnum,
678 mime_content_type, mime_length
682 /*** begin handler prep ***/
683 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
684 strcpy(vcard_partnum, mime_partnum);
687 if (!strcasecmp(mime_content_type, "text/calendar")) {
688 strcpy(cal_partnum, mime_partnum);
691 /*** end handler prep ***/
697 /* Generate a reply-to address */
698 if (strlen(rfca) > 0) {
699 strcpy(reply_to, rfca);
702 if ( (strlen(node) > 0)
703 && (strcasecmp(node, serv_info.serv_nodename))
704 && (strcasecmp(node, serv_info.serv_humannode)) ) {
705 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
709 snprintf(reply_to, sizeof(reply_to), "%s", from);
719 utf8ify_rfc822_string(m_cc);
720 utf8ify_rfc822_string(m_subject);
722 if (strlen(m_cc) > 0) {
724 "<SPAN CLASS=\"message_subject\">");
730 if (strlen(m_subject) > 0) {
732 "<SPAN CLASS=\"message_subject\">");
733 wprintf(_("Subject:"));
740 /* start msg buttons */
741 if (!printable_view) {
742 wprintf("<td align=right>\n");
745 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
746 wprintf("<a href=\"/display_enter");
747 if (WC->is_mailbox) {
748 wprintf("?replyquote=%ld", msgnum);
751 urlescputs(reply_to);
752 wprintf("?subject=");
753 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
754 urlescputs(m_subject);
755 wprintf("\">[%s]</a> ", _("Reply"));
759 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
760 if (!WC->is_mailbox) {
761 wprintf("<a href=\"/display_enter");
762 wprintf("?replyquote=%ld", msgnum);
764 urlescputs(reply_to);
765 wprintf("?subject=");
766 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
767 urlescputs(m_subject);
768 wprintf("\">[%s]</a> ", _("ReplyQuoted"));
773 if (WC->wc_view == VIEW_MAILBOX) {
774 wprintf("<a href=\"/display_enter");
775 wprintf("?replyquote=%ld", msgnum);
777 urlescputs(reply_to);
779 urlescputs(reply_all);
780 if (strlen(m_subject) > 0) {
781 wprintf("?subject=");
782 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
783 urlescputs(m_subject);
785 wprintf("\">[%s]</a> ", _("ReplyAll"));
789 if (WC->wc_view == VIEW_MAILBOX) {
790 wprintf("<a href=\"/display_enter?fwdquote=%ld?subject=", msgnum);
791 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
792 urlescputs(m_subject);
793 wprintf("\">[%s]</a> ", _("Forward"));
796 /* If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
797 if ( (WC->is_room_aide) || (WC->is_mailbox) ) {
799 wprintf("<a href=\"/confirm_move_msg?msgid=%ld\">[%s]</a> ",
803 wprintf("<a href=\"/delete_msg?msgid=%ld\" "
804 "onClick=\"return confirm('%s');\">"
805 "[%s]</a> ", msgnum, _("Delete this message?"), _("Delete")
809 wprintf("<a href=\"#\" onClick=\"window.open('/printmsg?msgnum=%ld', 'print%ld', 'toolbar=no,location=no,directories=no,copyhistory=no,status=yes,scrollbars=yes,resizable=yes,width=600,height=400'); \" >"
810 "[%s]</a>", msgnum, msgnum, _("Print"));
815 wprintf("</TR></TABLE>\n");
818 wprintf("<TABLE BORDER=0 WIDTH=100%% BGCOLOR=#FFFFFF "
819 "CELLPADDING=1 CELLSPACING=0><TR><TD>");
822 * Learn the content type
824 strcpy(mime_content_type, "text/plain");
825 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
826 if (!strcmp(buf, "000")) {
828 wprintf(_("unexpected end of message"));
829 wprintf("</I><br /><br />\n");
832 if (!strncasecmp(buf, "Content-type: ", 14)) {
833 safestrncpy(mime_content_type, &buf[14],
834 sizeof(mime_content_type));
835 for (i=0; i<strlen(mime_content_type); ++i) {
836 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
837 safestrncpy(mime_charset, &mime_content_type[i+8],
838 sizeof mime_charset);
841 for (i=0; i<strlen(mime_content_type); ++i) {
842 if (mime_content_type[i] == ';') {
843 mime_content_type[i] = 0;
849 /* Set up a character set conversion if we need to (and if we can) */
851 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
852 if ( (strcasecmp(mime_charset, "us-ascii"))
853 && (strcasecmp(mime_charset, "UTF-8"))
854 && (strcasecmp(mime_charset, ""))
856 ic = iconv_open("UTF-8", mime_charset);
857 if (ic == (iconv_t)(-1) ) {
858 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n", __FILE__, __LINE__, mime_charset, strerror(errno));
863 /* Messages in legacy Citadel variformat get handled thusly... */
864 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
868 /* Boring old 80-column fixed format text gets handled this way... */
869 else if ( (!strcasecmp(mime_content_type, "text/plain"))
870 || (!strcasecmp(mime_content_type, "text")) ) {
871 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
872 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
873 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
876 if (ic != (iconv_t)(-1) ) {
878 ibuflen = strlen(ibuf);
880 obuf = (char *) malloc(obuflen);
882 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
883 osav[SIZ-obuflen] = 0;
884 safestrncpy(buf, osav, sizeof buf);
889 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
890 buf[strlen(buf) - 1] = 0;
892 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
893 wprintf("<BLOCKQUOTE>");
895 } else if ((bq == 1) &&
896 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
897 wprintf("</BLOCKQUOTE>");
903 wprintf("</TT><br />\n");
905 wprintf("</I><br />");
908 else /* HTML is fun, but we've got to strip it first */
909 if (!strcasecmp(mime_content_type, "text/html")) {
910 output_html(mime_charset);
913 /* Unknown weirdness */
915 wprintf(_("I don't know how to display %s"), mime_content_type);
916 wprintf("<br />\n", mime_content_type);
917 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
920 /* If there are attached submessages, display them now... */
921 if ( (strlen(mime_submessages) > 0) && (!section[0]) ) {
922 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
923 extract_token(buf, mime_submessages, i, '|', sizeof buf);
924 /* use printable_view to suppress buttons */
925 wprintf("<blockquote>");
926 read_message(msgnum, 1, buf);
927 wprintf("</blockquote>");
932 /* Afterwards, offer links to download attachments 'n' such */
933 if ( (strlen(mime_http) > 0) && (!section[0]) ) {
934 wprintf("%s", mime_http);
937 /* Handler for vCard parts */
938 if (strlen(vcard_partnum) > 0) {
939 part_source = load_mimepart(msgnum, vcard_partnum);
940 if (part_source != NULL) {
942 /* If it's my vCard I can edit it */
943 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
944 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
945 || (WC->wc_view == VIEW_ADDRESSBOOK)
947 wprintf("<A HREF=\"/edit_vcard?"
948 "msgnum=%ld?partnum=%s\">",
949 msgnum, vcard_partnum);
950 wprintf("[%s]</A>", _("edit"));
953 /* In all cases, display the full card */
954 display_vcard(part_source, 0, 1, NULL);
958 /* Handler for calendar parts */
959 if (strlen(cal_partnum) > 0) {
960 part_source = load_mimepart(msgnum, cal_partnum);
961 if (part_source != NULL) {
962 cal_process_attachment(part_source,
963 msgnum, cal_partnum);
973 wprintf("</TD></TR></TABLE>\n");
975 /* end everythingamundo table */
976 if (!printable_view) {
977 wprintf("</TD></TR></TABLE>\n");
978 wprintf("</div><br />\n");
982 if (ic != (iconv_t)(-1) ) {
991 * Unadorned HTML output of an individual message, suitable
992 * for placing in a hidden iframe, for printing, or whatever
994 void embed_message(void) {
997 msgnum = atol(bstr("msgnum"));
998 begin_ajax_response();
999 read_message(msgnum, 0, "");
1000 end_ajax_response();
1005 * Printable view of a message
1007 void print_message(void) {
1010 msgnum = atol(bstr("msgnum"));
1011 output_headers(0, 0, 0, 0, 0, 0);
1013 wprintf("Content-type: text/html\r\n"
1015 "Connection: close\r\n",
1019 wprintf("\r\n\r\n<html>\n"
1020 "<head><title>Printable view</title></head>\n"
1021 "<body onLoad=\" window.print(); window.close(); \">\n"
1024 read_message(msgnum, 1, "");
1026 wprintf("\n</body></html>\n\n");
1033 * Read message in simple, JavaScript-embeddable form for 'forward'
1034 * or 'reply quoted' operations.
1036 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1037 * in this function. Doing so would throw a JavaScript error in the
1038 * 'supplied text' argument to the editor.
1040 void pullquote_message(long msgnum, int forward_attachments) {
1042 char mime_partnum[256];
1043 char mime_filename[256];
1044 char mime_content_type[256];
1045 char mime_charset[256];
1046 char mime_disposition[256];
1048 char mime_http[SIZ];
1049 char *attachments = NULL;
1050 int num_attachments = 0;
1051 struct wc_attachment *att, *aptr;
1052 char m_subject[256];
1058 int format_type = 0;
1063 iconv_t ic = (iconv_t)(-1) ;
1064 char *ibuf; /* Buffer of characters to be converted */
1065 char *obuf; /* Buffer for converted characters */
1066 size_t ibuflen; /* Length of input buffer */
1067 size_t obuflen; /* Length of output buffer */
1068 char *osav; /* Saved pointer to output buffer */
1074 strcpy(reply_to, "");
1075 strcpy(mime_http, "");
1076 strcpy(mime_content_type, "text/plain");
1077 strcpy(mime_charset, "us-ascii");
1079 serv_printf("MSG4 %ld", msgnum);
1080 serv_getln(buf, sizeof buf);
1081 if (buf[0] != '1') {
1082 wprintf(_("ERROR:"));
1083 wprintf("%s<br />", &buf[4]);
1087 strcpy(m_subject, "");
1089 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1090 if (!strcmp(buf, "000")) {
1091 wprintf(_("unexpected end of message"));
1094 if (!strncasecmp(buf, "nhdr=yes", 8))
1098 if (!strncasecmp(buf, "type=", 5))
1099 format_type = atoi(&buf[5]);
1100 if (!strncasecmp(buf, "from=", 5)) {
1101 strcpy(from, &buf[5]);
1102 wprintf(_("from "));
1104 utf8ify_rfc822_string(from);
1108 if (!strncasecmp(buf, "subj=", 5)) {
1109 strcpy(m_subject, &buf[5]);
1111 if ((!strncasecmp(buf, "hnod=", 5))
1112 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1113 wprintf("(%s) ", &buf[5]);
1115 if ((!strncasecmp(buf, "room=", 5))
1116 && (strcasecmp(&buf[5], WC->wc_roomname))
1117 && (strlen(&buf[5])>0) ) {
1119 wprintf("%s> ", &buf[5]);
1121 if (!strncasecmp(buf, "rfca=", 5)) {
1122 strcpy(rfca, &buf[5]);
1128 if (!strncasecmp(buf, "node=", 5)) {
1129 strcpy(node, &buf[5]);
1130 if ( ((WC->room_flags & QR_NETWORK)
1131 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1132 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1133 && (strlen(rfca)==0)
1135 wprintf("@%s ", &buf[5]);
1138 if (!strncasecmp(buf, "rcpt=", 5)) {
1140 wprintf("%s ", &buf[5]);
1142 if (!strncasecmp(buf, "time=", 5)) {
1143 fmt_date(now, atol(&buf[5]), 0);
1144 wprintf("%s ", now);
1148 * Save attachment info for later. We can't start downloading them
1149 * yet because we're in the middle of a server transaction.
1151 if (!strncasecmp(buf, "part=", 5)) {
1153 attachments = realloc(attachments, (num_attachments * 1024));
1154 strcat(attachments, &buf[5]);
1155 strcat(attachments, "\n");
1163 utf8ify_rfc822_string(m_subject);
1165 if (strlen(m_subject) > 0) {
1166 wprintf(_("Subject:"));
1168 msgescputs(m_subject);
1178 * Learn the content type
1180 strcpy(mime_content_type, "text/plain");
1181 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1182 if (!strcmp(buf, "000")) {
1183 wprintf(_("unexpected end of message"));
1186 if (!strncasecmp(buf, "Content-type: ", 14)) {
1187 safestrncpy(mime_content_type, &buf[14],
1188 sizeof(mime_content_type));
1189 for (i=0; i<strlen(mime_content_type); ++i) {
1190 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1191 safestrncpy(mime_charset, &mime_content_type[i+8],
1192 sizeof mime_charset);
1195 for (i=0; i<strlen(mime_content_type); ++i) {
1196 if (mime_content_type[i] == ';') {
1197 mime_content_type[i] = 0;
1203 /* Set up a character set conversion if we need to (and if we can) */
1205 if ( (strcasecmp(mime_charset, "us-ascii"))
1206 && (strcasecmp(mime_charset, "UTF-8"))
1207 && (strcasecmp(mime_charset, ""))
1209 ic = iconv_open("UTF-8", mime_charset);
1210 if (ic == (iconv_t)(-1) ) {
1211 lprintf(5, "%s:%d iconv_open() failed: %s\n", __FILE__, __LINE__, strerror(errno));
1216 /* Messages in legacy Citadel variformat get handled thusly... */
1217 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1221 /* Boring old 80-column fixed format text gets handled this way... */
1222 else if (!strcasecmp(mime_content_type, "text/plain")) {
1223 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1224 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1225 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1228 if (ic != (iconv_t)(-1) ) {
1230 ibuflen = strlen(ibuf);
1232 obuf = (char *) malloc(obuflen);
1234 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1235 osav[SIZ-obuflen] = 0;
1236 safestrncpy(buf, osav, sizeof buf);
1241 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1242 buf[strlen(buf) - 1] = 0;
1244 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
1245 wprintf("<BLOCKQUOTE>");
1247 } else if ((bq == 1) &&
1248 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
1249 wprintf("</BLOCKQUOTE>");
1255 wprintf("</TT><br />");
1257 wprintf("</I><br />");
1260 /* HTML just gets escaped and stuffed back into the editor */
1261 else if (!strcasecmp(mime_content_type, "text/html")) {
1262 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1267 /* Unknown weirdness ... don't know how to handle this content type */
1269 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1273 /* end of body handler */
1276 * If there were attachments, we have to download them and insert them
1277 * into the attachment chain for the forwarded message we are composing.
1279 if ( (forward_attachments) && (num_attachments) ) {
1280 for (i=0; i<num_attachments; ++i) {
1281 extract_token(buf, attachments, i, '\n', sizeof buf);
1282 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1283 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1284 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1285 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1286 mime_length = extract_int(buf, 5);
1289 * tracing ... uncomment if necessary
1291 lprintf(9, "fwd filename: %s\n", mime_filename);
1292 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1293 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1294 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1295 lprintf(9, "fwd length : %d\n", mime_length);
1298 if ( (!strcasecmp(mime_disposition, "inline"))
1299 || (!strcasecmp(mime_disposition, "attachment")) ) {
1301 /* Create an attachment struct from this mime part... */
1302 att = malloc(sizeof(struct wc_attachment));
1303 memset(att, 0, sizeof(struct wc_attachment));
1304 att->length = mime_length;
1305 strcpy(att->content_type, mime_content_type);
1306 strcpy(att->filename, mime_filename);
1308 att->data = load_mimepart(msgnum, mime_partnum);
1310 /* And add it to the list. */
1311 if (WC->first_attachment == NULL) {
1312 WC->first_attachment = att;
1315 aptr = WC->first_attachment;
1316 while (aptr->next != NULL) aptr = aptr->next;
1326 if (ic != (iconv_t)(-1) ) {
1337 void display_summarized(int num) {
1340 wprintf("<tr bgcolor=\"#%s\" ",
1341 ((num % 2) ? "DDDDDD" : "FFFFFF")
1344 wprintf("onClick=\" new Ajax.Updater('preview_pane', '/msg', { method: 'get', parameters: 'msgnum=%ld' } ); \" ", WC->summ[num].msgnum);
1348 if (WC->summ[num].is_new) wprintf("<B>");
1349 escputs(WC->summ[num].subj);
1350 if (WC->summ[num].is_new) wprintf("</B>");
1351 wprintf("</TD><TD>");
1352 if (WC->summ[num].is_new) wprintf("<B>");
1353 escputs(WC->summ[num].from);
1354 if (WC->summ[num].is_new) wprintf("</B>");
1355 wprintf(" </TD><TD>");
1356 if (WC->summ[num].is_new) wprintf("<B>");
1357 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1359 if (WC->summ[num].is_new) wprintf("</B>");
1362 "<INPUT TYPE=\"checkbox\" NAME=\"msg_%ld\" VALUE=\"yes\">"
1364 WC->summ[num].msgnum
1374 void display_addressbook(long msgnum, char alpha) {
1376 char mime_partnum[SIZ];
1377 char mime_filename[SIZ];
1378 char mime_content_type[SIZ];
1379 char mime_disposition[SIZ];
1381 char vcard_partnum[SIZ];
1382 char *vcard_source = NULL;
1383 struct message_summary summ;
1385 memset(&summ, 0, sizeof(summ));
1386 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1388 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1390 serv_getln(buf, sizeof buf);
1391 if (buf[0] != '1') return;
1393 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1394 if (!strncasecmp(buf, "part=", 5)) {
1395 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1396 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1397 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1398 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1399 mime_length = extract_int(&buf[5], 5);
1401 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1402 strcpy(vcard_partnum, mime_partnum);
1408 if (strlen(vcard_partnum) > 0) {
1409 vcard_source = load_mimepart(msgnum, vcard_partnum);
1410 if (vcard_source != NULL) {
1412 /* Display the summary line */
1413 display_vcard(vcard_source, alpha, 0, NULL);
1415 /* If it's my vCard I can edit it */
1416 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1417 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1418 || (WC->wc_view == VIEW_ADDRESSBOOK)
1420 wprintf("<A HREF=\"/edit_vcard?"
1421 "msgnum=%ld?partnum=%s\">",
1422 msgnum, vcard_partnum);
1423 wprintf("[%s]</A>", _("edit"));
1434 /* If it's an old "Firstname Lastname" style record, try to
1437 void lastfirst_firstlast(char *namebuf) {
1438 char firstname[SIZ];
1442 if (namebuf == NULL) return;
1443 if (strchr(namebuf, ';') != NULL) return;
1445 i = num_tokens(namebuf, ' ');
1448 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1449 remove_token(namebuf, i-1, ' ');
1450 strcpy(firstname, namebuf);
1451 sprintf(namebuf, "%s; %s", lastname, firstname);
1455 void fetch_ab_name(long msgnum, char *namebuf) {
1457 char mime_partnum[SIZ];
1458 char mime_filename[SIZ];
1459 char mime_content_type[SIZ];
1460 char mime_disposition[SIZ];
1462 char vcard_partnum[SIZ];
1463 char *vcard_source = NULL;
1465 struct message_summary summ;
1467 if (namebuf == NULL) return;
1468 strcpy(namebuf, "");
1470 memset(&summ, 0, sizeof(summ));
1471 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1473 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1475 serv_getln(buf, sizeof buf);
1476 if (buf[0] != '1') return;
1478 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1479 if (!strncasecmp(buf, "part=", 5)) {
1480 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1481 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1482 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1483 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1484 mime_length = extract_int(&buf[5], 5);
1486 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1487 strcpy(vcard_partnum, mime_partnum);
1493 if (strlen(vcard_partnum) > 0) {
1494 vcard_source = load_mimepart(msgnum, vcard_partnum);
1495 if (vcard_source != NULL) {
1497 /* Grab the name off the card */
1498 display_vcard(vcard_source, 0, 0, namebuf);
1504 lastfirst_firstlast(namebuf);
1506 for (i=0; i<strlen(namebuf); ++i) {
1507 if (namebuf[i] != ';') return;
1509 strcpy(namebuf, _("(no name)"));
1515 * Record compare function for sorting address book indices
1517 int abcmp(const void *ab1, const void *ab2) {
1519 (((const struct addrbookent *)ab1)->ab_name),
1520 (((const struct addrbookent *)ab2)->ab_name)
1526 * Helper function for do_addrbook_view()
1527 * Converts a name into a three-letter tab label
1529 void nametab(char *tabbuf, char *name) {
1530 stresc(tabbuf, name, 0, 0);
1531 tabbuf[0] = toupper(tabbuf[0]);
1532 tabbuf[1] = tolower(tabbuf[1]);
1533 tabbuf[2] = tolower(tabbuf[2]);
1539 * Render the address book using info we gathered during the scan
1541 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1545 static int NAMESPERPAGE = 60;
1549 char tabfirst_label[SIZ];
1551 char tablast_label[SIZ];
1554 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1555 wprintf(_("This address book is empty."));
1556 wprintf("</i></div>\n");
1561 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1564 num_pages = num_ab / NAMESPERPAGE;
1566 page = atoi(bstr("page"));
1569 for (i=0; i<=num_pages; ++i) {
1571 wprintf("<A HREF=\"/readfwd?page=%d\">", i);
1576 tabfirst = i * NAMESPERPAGE;
1577 tablast = tabfirst + NAMESPERPAGE - 1;
1578 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1579 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1580 nametab(tablast_label, addrbook[tablast].ab_name);
1581 wprintf("[%s - %s]",
1582 tabfirst_label, tablast_label
1591 wprintf("<br />\n");
1593 wprintf("<TABLE border=0 cellspacing=0 "
1594 "cellpadding=3 width=100%%>\n"
1597 for (i=0; i<num_ab; ++i) {
1599 if ((i / NAMESPERPAGE) == page) {
1601 if ((displayed % 4) == 0) {
1602 if (displayed > 0) {
1606 wprintf("<TR BGCOLOR=\"#%s\">",
1607 (bg ? "DDDDDD" : "FFFFFF")
1613 wprintf("<A HREF=\"/readfwd?startmsg=%ld&is_singlecard=1",
1614 addrbook[i].ab_msgnum);
1615 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1616 vcard_n_prettyize(addrbook[i].ab_name);
1617 escputs(addrbook[i].ab_name);
1618 wprintf("</A></TD>\n");
1623 wprintf("</TR></TABLE>\n");
1629 * load message pointers from the server
1631 int load_msg_ptrs(char *servcmd, int with_headers)
1635 char displayname[128];
1642 int num_summ_alloc = 0;
1645 if (WC->num_summ != 0) {
1650 num_summ_alloc = 100;
1652 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1655 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1657 serv_getln(buf, sizeof buf);
1658 if (buf[0] != '1') {
1659 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1662 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1663 if (nummsgs < maxload) {
1664 WC->msgarr[nummsgs] = extract_long(buf, 0);
1665 datestamp = extract_long(buf, 1);
1666 extract_token(displayname, buf, 2, '|', sizeof displayname);
1667 extract_token(nodename, buf, 3, '|', sizeof nodename);
1668 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1669 extract_token(subject, buf, 5, '|', sizeof subject);
1673 if (nummsgs > num_summ_alloc) {
1674 num_summ_alloc *= 2;
1675 WC->summ = realloc(WC->summ, num_summ_alloc * sizeof(struct message_summary));
1679 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1680 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1681 safestrncpy(WC->summ[nummsgs-1].subj, _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1682 if (strlen(displayname) > 0) {
1683 safestrncpy(WC->summ[nummsgs-1].from, displayname, sizeof WC->summ[nummsgs-1].from);
1685 if (strlen(subject) > 0) {
1686 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1687 sizeof WC->summ[nummsgs-1].subj);
1690 /* Handle subjects with RFC2047 encoding */
1691 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1693 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1694 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1697 if (strlen(nodename) > 0) {
1698 if ( ((WC->room_flags & QR_NETWORK)
1699 || ((strcasecmp(nodename, serv_info.serv_nodename)
1700 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1702 strcat(WC->summ[nummsgs-1].from, " @ ");
1703 strcat(WC->summ[nummsgs-1].from, nodename);
1707 WC->summ[nummsgs-1].date = datestamp;
1710 /* Handle senders with RFC2047 encoding */
1711 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1713 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1714 strcpy(&WC->summ[nummsgs-1].from[22], "...");
1723 int summcmp_subj(const void *s1, const void *s2) {
1724 struct message_summary *summ1;
1725 struct message_summary *summ2;
1727 summ1 = (struct message_summary *)s1;
1728 summ2 = (struct message_summary *)s2;
1729 return strcasecmp(summ1->subj, summ2->subj);
1732 int summcmp_rsubj(const void *s1, const void *s2) {
1733 struct message_summary *summ1;
1734 struct message_summary *summ2;
1736 summ1 = (struct message_summary *)s1;
1737 summ2 = (struct message_summary *)s2;
1738 return strcasecmp(summ2->subj, summ1->subj);
1741 int summcmp_sender(const void *s1, const void *s2) {
1742 struct message_summary *summ1;
1743 struct message_summary *summ2;
1745 summ1 = (struct message_summary *)s1;
1746 summ2 = (struct message_summary *)s2;
1747 return strcasecmp(summ1->from, summ2->from);
1750 int summcmp_rsender(const void *s1, const void *s2) {
1751 struct message_summary *summ1;
1752 struct message_summary *summ2;
1754 summ1 = (struct message_summary *)s1;
1755 summ2 = (struct message_summary *)s2;
1756 return strcasecmp(summ2->from, summ1->from);
1759 int summcmp_date(const void *s1, const void *s2) {
1760 struct message_summary *summ1;
1761 struct message_summary *summ2;
1763 summ1 = (struct message_summary *)s1;
1764 summ2 = (struct message_summary *)s2;
1766 if (summ1->date < summ2->date) return -1;
1767 else if (summ1->date > summ2->date) return +1;
1771 int summcmp_rdate(const void *s1, const void *s2) {
1772 struct message_summary *summ1;
1773 struct message_summary *summ2;
1775 summ1 = (struct message_summary *)s1;
1776 summ2 = (struct message_summary *)s2;
1778 if (summ1->date < summ2->date) return +1;
1779 else if (summ1->date > summ2->date) return -1;
1784 * command loop for reading messages
1786 void readloop(char *oper)
1795 int num_displayed = 0;
1797 int is_addressbook = 0;
1798 int is_singlecard = 0;
1799 int is_calendar = 0;
1802 int remaining_messages;
1804 int lowest_displayed = (-1);
1805 int highest_displayed = 0;
1806 long pn_previous = 0L;
1807 long pn_current = 0L;
1809 struct addrbookent *addrbook = NULL;
1811 char *sortby = NULL;
1812 char sortpref_name[128];
1813 char sortpref_value[128];
1814 char *subjsort_button;
1815 char *sendsort_button;
1816 char *datesort_button;
1818 startmsg = atol(bstr("startmsg"));
1819 maxmsgs = atoi(bstr("maxmsgs"));
1820 is_summary = atoi(bstr("summary"));
1821 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1823 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
1824 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
1826 sortby = bstr("sortby");
1827 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
1828 set_preference(sortpref_name, sortby, 1);
1830 if (strlen(sortby) == 0) sortby = sortpref_value;
1831 if (strlen(sortby) == 0) sortby = "rdate";
1833 output_headers(1, 1, 1, 0, 0, 0);
1835 /* When in summary mode, always show ALL messages instead of just
1836 * new or old. Otherwise, show what the user asked for.
1838 if (!strcmp(oper, "readnew")) {
1839 strcpy(cmd, "MSGS NEW");
1841 else if (!strcmp(oper, "readold")) {
1842 strcpy(cmd, "MSGS OLD");
1845 strcpy(cmd, "MSGS ALL");
1848 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
1850 strcpy(cmd, "MSGS ALL");
1853 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
1855 strcpy(cmd, "MSGS ALL");
1860 strcpy(cmd, "MSGS ALL|||1"); /* fetch header summary */
1865 /* Are we doing a summary view? If so, we need to know old messages
1866 * and new messages, so we can do that pretty boldface thing for the
1869 strcpy(old_msgs, "");
1872 serv_getln(buf, sizeof buf);
1873 if (buf[0] == '2') {
1874 strcpy(old_msgs, &buf[4]);
1878 is_singlecard = atoi(bstr("is_singlecard"));
1880 if (WC->wc_view == VIEW_CALENDAR) { /* calendar */
1882 strcpy(cmd, "MSGS ALL");
1885 if (WC->wc_view == VIEW_TASKS) { /* tasks */
1887 strcpy(cmd, "MSGS ALL");
1890 if (WC->wc_view == VIEW_NOTES) { /* notes */
1892 strcpy(cmd, "MSGS ALL");
1896 nummsgs = load_msg_ptrs(cmd, is_summary);
1899 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
1901 if (!strcmp(oper, "readnew")) {
1902 wprintf(_("No new messages."));
1903 } else if (!strcmp(oper, "readold")) {
1904 wprintf(_("No old messages."));
1906 wprintf(_("No messages here."));
1915 for (a = 0; a < nummsgs; ++a) {
1916 /* Are you a new message, or an old message? */
1918 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
1919 WC->summ[a].is_new = 0;
1922 WC->summ[a].is_new = 1;
1928 if (startmsg == 0L) startmsg = WC->msgarr[0];
1929 remaining_messages = 0;
1931 for (a = 0; a < nummsgs; ++a) {
1932 if (WC->msgarr[a] >= startmsg) {
1933 ++remaining_messages;
1938 if (!strcasecmp(sortby, "subject")) {
1939 qsort(WC->summ, WC->num_summ,
1940 sizeof(struct message_summary), summcmp_subj);
1942 else if (!strcasecmp(sortby, "rsubject")) {
1943 qsort(WC->summ, WC->num_summ,
1944 sizeof(struct message_summary), summcmp_rsubj);
1946 else if (!strcasecmp(sortby, "sender")) {
1947 qsort(WC->summ, WC->num_summ,
1948 sizeof(struct message_summary), summcmp_sender);
1950 else if (!strcasecmp(sortby, "rsender")) {
1951 qsort(WC->summ, WC->num_summ,
1952 sizeof(struct message_summary), summcmp_rsender);
1954 else if (!strcasecmp(sortby, "date")) {
1955 qsort(WC->summ, WC->num_summ,
1956 sizeof(struct message_summary), summcmp_date);
1958 else if (!strcasecmp(sortby, "rdate")) {
1959 qsort(WC->summ, WC->num_summ,
1960 sizeof(struct message_summary), summcmp_rdate);
1964 if (!strcasecmp(sortby, "subject")) {
1965 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1967 else if (!strcasecmp(sortby, "rsubject")) {
1968 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1971 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1974 if (!strcasecmp(sortby, "sender")) {
1975 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1977 else if (!strcasecmp(sortby, "rsender")) {
1978 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1981 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1984 if (!strcasecmp(sortby, "date")) {
1985 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1987 else if (!strcasecmp(sortby, "rdate")) {
1988 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1991 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1995 wprintf("</div>"); /* end of 'content' div */
1997 wprintf("<div id=\"message_list\">"
1999 "<div id=\"fix_scrollbar_bug\">\n"
2001 "<form name=\"msgomatic\" "
2002 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n"
2004 "<span class=\"mailbox_summary\">"
2005 "<table border=0 cellspacing=0 "
2006 "cellpadding=0 width=100%%>\n"
2008 "<TD align=center><b><i>%s</i></b> %s</TD>"
2009 "<TD align=center><b><i>%s</i></b> %s</TD>"
2010 "<TD align=center><b><i>%s</i></b> %s</TD>"
2011 "<TD><INPUT TYPE=\"submit\" NAME=\"delete_button\" "
2012 "STYLE=\"font-family: Bitstream Vera Sans,Arial,Helvetica,sans-serif;"
2013 " font-size: 6pt;\" "
2014 "VALUE=\"%s\"></TD>"
2017 _("Subject"), subjsort_button,
2018 _("Sender"), sendsort_button,
2019 _("Date"), datesort_button,
2024 for (a = 0; a < nummsgs; ++a) {
2025 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2027 /* Learn which msgs "Prev" & "Next" buttons go to */
2028 pn_current = WC->msgarr[a];
2029 if (a > 0) pn_previous = WC->msgarr[a-1];
2030 if (a < (nummsgs-1)) pn_next = WC->msgarr[a+1];
2032 /* Display the message */
2034 display_summarized(a);
2036 else if (is_addressbook) {
2037 fetch_ab_name(WC->msgarr[a], buf);
2039 addrbook = realloc(addrbook,
2040 (sizeof(struct addrbookent) * num_ab) );
2041 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2042 sizeof(addrbook[num_ab-1].ab_name));
2043 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
2045 else if (is_calendar) {
2046 display_calendar(WC->msgarr[a]);
2048 else if (is_tasks) {
2049 display_task(WC->msgarr[a]);
2051 else if (is_notes) {
2052 display_note(WC->msgarr[a]);
2055 read_message(WC->msgarr[a], 0, "");
2058 if (lowest_displayed < 0) lowest_displayed = a;
2059 highest_displayed = a;
2062 --remaining_messages;
2067 wprintf("</table></span></form>"
2068 "</div>\n"); /* end of 'fix_scrollbar_bug' div */
2069 wprintf("</div>"); /* end of 'message_list' div */
2071 wprintf("<div id=\"ml_slider\"></div>"); /* slider */
2073 wprintf("<div id=\"preview_pane\">"); /* The preview pane will initially be empty */
2075 /* Now register each message (whose element ID is "m9999",
2076 * where "9999" is the message number) as draggable.
2077 wprintf("<script type=\"text/javascript\">\n");
2078 for (a = 0; a < nummsgs; ++a) {
2079 wprintf("new Draggable('m%ld',{revert:true});\n",
2080 WC->summ[a].msgnum);
2082 wprintf("</script>\n");
2086 /* Bump these because although we're thinking in zero base, the user
2087 * is a drooling idiot and is thinking in one base.
2090 ++highest_displayed;
2092 /* If we're only looking at one message, do a prev/next thing */
2093 if (num_displayed == 1) {
2094 if ((!is_tasks) && (!is_calendar) && (!is_addressbook) && (!is_notes) && (!is_singlecard)) {
2096 wprintf("<div id=\"fix_scrollbar_bug\">"
2097 "<table border=0 width=100%% bgcolor=\"#dddddd\"><tr><td>");
2098 wprintf(_("Reading #%d of %d messages."), lowest_displayed, nummsgs);
2099 wprintf("</TD><TD ALIGN=RIGHT><FONT SIZE=+1>");
2101 if (pn_previous > 0L) {
2102 wprintf("<A HREF=\"/%s"
2113 wprintf("<A HREF=\"/%s"
2123 wprintf("<A HREF=\"/%s?startmsg=%ld"
2124 "?maxmsgs=%d?summary=1\">"
2133 wprintf("</td></tr></table></div>\n");
2138 * If we're not currently looking at ALL requested
2139 * messages, then display the selector bar
2141 if (num_displayed > 1) {
2142 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2143 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2145 wprintf("<form name=\"msgomatic\" "
2146 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n");
2148 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2150 wprintf("<select name=\"whichones\" size=\"1\" "
2151 "OnChange=\"location.href=msgomatic.whichones.options"
2152 "[selectedIndex].value\">\n");
2154 for (b=0; b<nummsgs; b = b + maxmsgs) {
2157 if (hi > nummsgs) hi = nummsgs;
2158 wprintf("<option %s value="
2163 "%d-%d</option> \n",
2164 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2171 wprintf("<option value=\"/%s?startmsg=%ld"
2172 "?maxmsgs=9999999?summary=%d\">"
2176 WC->msgarr[0], is_summary);
2178 wprintf("</select> ");
2179 wprintf(_("of %d messages."), nummsgs);
2180 wprintf("</form>\n");
2186 do_tasks_view(); /* Render the task list */
2190 do_calendar_view(); /* Render the calendar */
2193 if (is_addressbook) {
2194 do_addrbook_view(addrbook, num_ab); /* Render the address book */
2197 /* Put the data transfer hidden iframe in a hidden div, to make it *really* hidden */
2199 "<div display=\"hidden\">\n"
2200 "<iframe name=\"msgloader1\" id=\"msgloader1\" width=\"1\"></iframe>\n"
2203 /* Note: wDumpContent() will output one additional </div> tag. */
2205 if (addrbook != NULL) free(addrbook);
2207 /* free the summary */
2208 if (WC->num_summ != 0) {
2213 /* If we got here via a mailbox view and are reading a single
2214 * message, mark it as "seen." We do this after rendering the web page
2215 * so it doesn't keep the user waiting.
2217 if ( (maxmsgs == 1) && (WC->wc_view == VIEW_MAILBOX) ) {
2218 serv_printf("SEEN %ld|1", startmsg);
2219 serv_getln(buf, sizeof buf);
2225 * Back end for post_message() ... this is where the actual message
2226 * gets transmitted to the server.
2228 void post_mime_to_server(void) {
2230 int is_multipart = 0;
2232 struct wc_attachment *att;
2234 size_t encoded_length;
2236 /* RFC2045 requires this, and some clients look for it... */
2237 serv_puts("MIME-Version: 1.0");
2239 /* If there are attachments, we have to do multipart/mixed */
2240 if (WC->first_attachment != NULL) {
2245 sprintf(boundary, "---Citadel-Multipart-%s-%04x%04x---",
2246 serv_info.serv_fqdn,
2251 /* Remember, serv_printf() appends an extra newline */
2252 serv_printf("Content-type: multipart/mixed; "
2253 "boundary=\"%s\"\n", boundary);
2254 serv_printf("This is a multipart message in MIME format.\n");
2255 serv_printf("--%s", boundary);
2258 serv_puts("Content-type: text/html; charset=utf-8");
2260 serv_puts("<HTML><BODY>\n");
2261 text_to_server(bstr("msgtext"), 0);
2262 serv_puts("</BODY></HTML>\n");
2267 /* Add in the attachments */
2268 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2270 encoded_length = ((att->length * 150) / 100);
2271 encoded = malloc(encoded_length);
2272 if (encoded == NULL) break;
2273 CtdlEncodeBase64(encoded, att->data, att->length);
2275 serv_printf("--%s", boundary);
2276 serv_printf("Content-type: %s", att->content_type);
2277 serv_printf("Content-disposition: attachment; "
2278 "filename=\"%s\"", att->filename);
2279 serv_puts("Content-transfer-encoding: base64");
2281 serv_write(encoded, strlen(encoded));
2286 serv_printf("--%s--", boundary);
2294 * Post message (or don't post message)
2296 * Note regarding the "dont_post" variable:
2297 * A random value (actually, it's just a timestamp) is inserted as a hidden
2298 * field called "postseq" when the display_enter page is generated. This
2299 * value is checked when posting, using the static variable dont_post. If a
2300 * user attempts to post twice using the same dont_post value, the message is
2301 * discarded. This prevents the accidental double-saving of the same message
2302 * if the user happens to click the browser "back" button.
2304 void post_message(void)
2307 static long dont_post = (-1L);
2308 struct wc_attachment *att, *aptr;
2310 if (WC->upload_length > 0) {
2312 /* There's an attachment. Save it to this struct... */
2313 att = malloc(sizeof(struct wc_attachment));
2314 memset(att, 0, sizeof(struct wc_attachment));
2315 att->length = WC->upload_length;
2316 strcpy(att->content_type, WC->upload_content_type);
2317 strcpy(att->filename, WC->upload_filename);
2320 /* And add it to the list. */
2321 if (WC->first_attachment == NULL) {
2322 WC->first_attachment = att;
2325 aptr = WC->first_attachment;
2326 while (aptr->next != NULL) aptr = aptr->next;
2330 /* Mozilla sends a simple filename, which is what we want,
2331 * but Satan's Browser sends an entire pathname. Reduce
2332 * the path to just a filename if we need to.
2334 while (num_tokens(att->filename, '/') > 1) {
2335 remove_token(att->filename, 0, '/');
2337 while (num_tokens(att->filename, '\\') > 1) {
2338 remove_token(att->filename, 0, '\\');
2341 /* Transfer control of this memory from the upload struct
2342 * to the attachment struct.
2344 att->data = WC->upload;
2345 WC->upload_length = 0;
2351 if (strlen(bstr("cancel_button")) > 0) {
2352 sprintf(WC->ImportantMessage,
2353 _("Cancelled. Message was not posted."));
2354 } else if (strlen(bstr("attach_button")) > 0) {
2357 } else if (atol(bstr("postseq")) == dont_post) {
2358 sprintf(WC->ImportantMessage,
2359 _("Automatically cancelled because you have already "
2360 "saved this message."));
2362 sprintf(buf, "ENT0 1|%s|0|4|%s|||%s|%s",
2369 serv_getln(buf, sizeof buf);
2370 if (buf[0] == '4') {
2371 post_mime_to_server();
2372 if ( (strlen(bstr("recp")) > 0)
2373 || (strlen(bstr("cc")) > 0)
2374 || (strlen(bstr("bcc")) > 0)
2376 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2379 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2381 dont_post = atol(bstr("postseq"));
2383 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2389 free_attachments(WC);
2390 readloop("readnew");
2397 * display the message entry screen
2399 void display_enter(void)
2404 struct wc_attachment *att;
2405 int recipient_required = 0;
2406 int recipient_bad = 0;
2409 if (strlen(bstr("force_room")) > 0) {
2410 gotoroom(bstr("force_room"));
2413 /* Are we perhaps in an address book view? If so, then an "enter
2414 * message" command really means "add new entry."
2416 if (WC->wc_view == VIEW_ADDRESSBOOK) {
2417 do_edit_vcard(-1, "", "");
2421 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
2422 /* Are we perhaps in a calendar view? If so, then an "enter
2423 * message" command really means "add new calendar item."
2425 if (WC->wc_view == VIEW_CALENDAR) {
2426 display_edit_event();
2430 /* Are we perhaps in a tasks view? If so, then an "enter
2431 * message" command really means "add new task."
2433 if (WC->wc_view == VIEW_TASKS) {
2434 display_edit_task();
2440 * Otherwise proceed normally.
2441 * Do a custom room banner with no navbar...
2443 output_headers(1, 1, 2, 0, 0, 0);
2444 wprintf("<div id=\"banner\">\n");
2445 embed_room_banner(NULL, navbar_none);
2446 wprintf("</div>\n");
2447 wprintf("<div id=\"content\">\n"
2448 "<div id=\"fix_scrollbar_bug\">"
2449 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
2451 /* First test to see whether this is a room that requires recipients to be entered */
2452 serv_puts("ENT0 0");
2453 serv_getln(buf, sizeof buf);
2454 if (!strncmp(buf, "570", 3)) { /* 570 means that we need a recipient here */
2455 recipient_required = 1;
2457 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
2458 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2462 /* Now check our actual recipients if there are any */
2463 if (recipient_required) {
2464 sprintf(buf, "ENT0 0|%s|0|0||||%s|%s", bstr("recp"), bstr("cc"), bstr("bcc"));
2466 serv_getln(buf, sizeof buf);
2468 if (!strncmp(buf, "570", 3)) { /* 570 means we have an invalid recipient listed */
2469 if (strlen(bstr("recp")) + strlen(bstr("cc")) + strlen(bstr("bcc")) > 0) {
2473 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
2474 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2479 /* If we got this far, we can display the message entry screen. */
2482 fmt_date(buf, now, 0);
2483 strcat(&buf[strlen(buf)], _(" <I>from</I> "));
2484 stresc(&buf[strlen(buf)], WC->wc_username, 1, 1);
2486 /* Don't need this anymore, it's in the input box below
2487 if (strlen(bstr("recp")) > 0) {
2488 strcat(&buf[strlen(buf)], _(" <I>to</I> "));
2489 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
2493 strcat(&buf[strlen(buf)], _(" <I>in</I> "));
2494 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
2496 /* begin message entry screen */
2497 wprintf("<form enctype=\"multipart/form-data\" "
2498 "method=\"POST\" action=\"/post\" "
2499 "name=\"enterform\""
2501 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2503 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2504 wprintf("%s<br>\n", buf); /* header bar */
2506 wprintf("<table border=\"0\" width=\"100%%\">\n");
2507 if (recipient_required) {
2509 wprintf("<tr><td>");
2510 wprintf("<font size=-1>");
2514 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
2515 escputs(bstr("recp"));
2516 wprintf("\" size=50 maxlength=1000 />");
2517 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
2518 wprintf("</td><td></td></tr>\n");
2520 wprintf("<tr><td>");
2521 wprintf("<font size=-1>");
2525 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
2526 escputs(bstr("cc"));
2527 wprintf("\" size=50 maxlength=1000 />");
2528 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
2529 wprintf("</td><td></td></tr>\n");
2531 wprintf("<tr><td>");
2532 wprintf("<font size=-1>");
2536 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
2537 escputs(bstr("bcc"));
2538 wprintf("\" size=50 maxlength=1000 />");
2539 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
2540 wprintf("</td><td></td></tr>\n");
2542 /* Initialize the autocomplete ajax helpers (found in wclib.js) */
2543 wprintf("<script type=\"text/javascript\"> \n"
2544 " activate_entmsg_autocompleters(); \n"
2549 wprintf("<tr><td>");
2550 wprintf("<font size=-1>");
2551 wprintf(_("Subject (optional):"));
2554 "<input type=\"text\" name=\"subject\" value=\"");
2555 escputs(bstr("subject"));
2556 wprintf("\" size=50 maxlength=70></td><td>\n");
2558 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2559 if (recipient_required) {
2560 wprintf(_("Send message"));
2562 wprintf(_("Post message"));
2565 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2566 wprintf("</td></tr></table>\n");
2568 wprintf("<center>");
2570 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
2572 /* If we're continuing from a previous edit, put our partially-composed message back... */
2573 msgescputs(bstr("msgtext"));
2575 /* If we're forwarding a message, insert it here... */
2576 if (atol(bstr("fwdquote")) > 0L) {
2577 wprintf("<br><div align=center><i>");
2578 wprintf(_("--- forwarded message ---"));
2579 wprintf("</i></div><br>");
2580 pullquote_message(atol(bstr("fwdquote")), 1);
2583 /* If we're replying quoted, insert the quote here... */
2584 else if (atol(bstr("replyquote")) > 0L) {
2587 pullquote_message(atol(bstr("replyquote")), 0);
2588 wprintf("</blockquote>");
2591 /* Insert our signature if appropriate... */
2592 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
2593 get_preference("use_sig", buf, sizeof buf);
2594 if (!strcasecmp(buf, "yes")) {
2595 get_preference("signature", ebuf, sizeof ebuf);
2596 euid_unescapize(buf, ebuf);
2597 wprintf("<br>--<br>");
2598 for (i=0; i<strlen(buf); ++i) {
2599 if (buf[i] == '\n') {
2602 else if (buf[i] == '<') {
2605 else if (buf[i] == '>') {
2608 else if (buf[i] == '&') {
2611 else if (buf[i] == '\"') {
2614 else if (buf[i] == '\'') {
2617 else if (isprint(buf[i])) {
2618 wprintf("%c", buf[i]);
2624 wprintf("</textarea>");
2625 wprintf("</center><br />\n");
2628 * The following script embeds the TinyMCE richedit control, and automatically
2629 * transforms the textarea into a richedit textarea.
2632 "<script language=\"javascript\" type=\"text/javascript\" src=\"tiny_mce/tiny_mce.js\"></script>\n"
2633 "<script language=\"javascript\" type=\"text/javascript\">"
2635 " mode : \"textareas\", width : \"100%%\", browsers : \"msie,gecko\" "
2640 /* Enumerate any attachments which are already in place... */
2641 wprintf("<img src=\"/static/diskette_24x.gif\" border=0 "
2642 "align=middle height=16 width=16> Attachments: ");
2643 wprintf("<select name=\"which_attachment\" size=1>");
2644 for (att = WC->first_attachment; att != NULL; att = att->next) {
2645 wprintf("<option value=\"");
2646 urlescputs(att->filename);
2648 escputs(att->filename);
2649 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
2650 wprintf("</option>\n");
2652 wprintf("</select>");
2654 /* Now offer the ability to attach additional files... */
2655 wprintf(" "
2656 "Attach file: <input NAME=\"attachfile\" "
2657 "SIZE=16 TYPE=\"file\">\n "
2658 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
2660 /* Seth asked for these to be at the top *and* bottom... */
2661 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2662 if (recipient_required) {
2663 wprintf(_("Send message"));
2665 wprintf(_("Post message"));
2668 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2670 /* Make sure we only insert our signature once */
2671 if (strcmp(bstr("sig_inserted"), "yes")) {
2672 wprintf("<INPUT TYPE=\"hidden\" NAME=\"sig_inserted\" VALUE=\"yes\">\n");
2675 wprintf("</form>\n");
2677 wprintf("</td></tr></table></div>\n");
2678 DONE: wDumpContent(1);
2688 void delete_msg(void)
2693 msgid = atol(bstr("msgid"));
2695 output_headers(1, 1, 1, 0, 0, 0);
2697 sprintf(buf, "DELE %ld", msgid);
2699 serv_getln(buf, sizeof buf);
2700 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2709 * Confirm move of a message
2711 void confirm_move_msg(void)
2717 msgid = atol(bstr("msgid"));
2720 output_headers(1, 1, 2, 0, 0, 0);
2721 wprintf("<div id=\"banner\">\n");
2722 wprintf("<TABLE WIDTH=100%% BORDER=0><TR><TD>");
2723 wprintf("<SPAN CLASS=\"titlebar\">");
2724 wprintf(_("Confirm move of message"));
2725 wprintf("</SPAN>\n");
2726 wprintf("</TD></TR></TABLE>\n");
2727 wprintf("</div>\n<div id=\"content\">\n");
2729 wprintf("<CENTER>");
2731 wprintf(_("Move this message to:"));
2732 wprintf("<br />\n");
2734 wprintf("<form METHOD=\"POST\" ACTION=\"/move_msg\">\n");
2735 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
2737 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
2739 serv_getln(buf, sizeof buf);
2740 if (buf[0] == '1') {
2741 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2742 extract_token(targ, buf, 0, '|', sizeof targ);
2743 wprintf("<OPTION>");
2748 wprintf("</SELECT>\n");
2749 wprintf("<br />\n");
2751 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
2753 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
2754 wprintf("</form></CENTER>\n");
2756 wprintf("</CENTER>\n");
2767 msgid = atol(bstr("msgid"));
2769 if (strlen(bstr("move_button")) > 0) {
2770 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
2772 serv_getln(buf, sizeof buf);
2773 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2775 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
2778 readloop("readnew");
2783 * This gets called when a user selects multiple messages in a summary
2784 * list and then clicks to perform a transformation of some sort on them
2785 * (such as deleting them).
2787 void do_stuff_to_msgs(void) {
2791 struct stuff_t *next;
2795 struct stuff_t *stuff = NULL;
2796 struct stuff_t *ptr;
2797 int delete_button_pressed = 0;
2800 serv_puts("MSGS ALL");
2801 serv_getln(buf, sizeof buf);
2803 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2804 ptr = malloc(sizeof(struct stuff_t));
2805 ptr->msgnum = atol(buf);
2810 if (strlen(bstr("delete_button")) > 0) {
2811 delete_button_pressed = 1;
2814 while (stuff != NULL) {
2816 sprintf(buf, "msg_%ld", stuff->msgnum);
2817 if (!strcasecmp(bstr(buf), "yes")) {
2819 if (delete_button_pressed) {
2820 serv_printf("DELE %ld", stuff->msgnum);
2821 serv_getln(buf, sizeof buf);
2831 readloop("readfwd");