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 "Part %s: %s (%s, %d bytes)</A><br />\n",
675 msgnum, mime_partnum, mime_filename,
676 msgnum, mime_partnum,
677 mime_partnum, mime_filename,
678 mime_content_type, mime_length);
681 /*** begin handler prep ***/
682 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
683 strcpy(vcard_partnum, mime_partnum);
686 if (!strcasecmp(mime_content_type, "text/calendar")) {
687 strcpy(cal_partnum, mime_partnum);
690 /*** end handler prep ***/
696 /* Generate a reply-to address */
697 if (strlen(rfca) > 0) {
698 strcpy(reply_to, rfca);
701 if ( (strlen(node) > 0)
702 && (strcasecmp(node, serv_info.serv_nodename))
703 && (strcasecmp(node, serv_info.serv_humannode)) ) {
704 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
708 snprintf(reply_to, sizeof(reply_to), "%s", from);
718 utf8ify_rfc822_string(m_cc);
719 utf8ify_rfc822_string(m_subject);
721 if (strlen(m_cc) > 0) {
723 "<SPAN CLASS=\"message_subject\">");
729 if (strlen(m_subject) > 0) {
731 "<SPAN CLASS=\"message_subject\">");
732 wprintf(_("Subject:"));
739 /* start msg buttons */
740 if (!printable_view) {
741 wprintf("<td align=right>\n");
744 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
745 wprintf("<a href=\"/display_enter");
746 if (WC->is_mailbox) {
747 wprintf("?replyquote=%ld", msgnum);
750 urlescputs(reply_to);
751 wprintf("?subject=");
752 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
753 urlescputs(m_subject);
754 wprintf("\">[%s]</a> ", _("Reply"));
758 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
759 if (!WC->is_mailbox) {
760 wprintf("<a href=\"/display_enter");
761 wprintf("?replyquote=%ld", msgnum);
763 urlescputs(reply_to);
764 wprintf("?subject=");
765 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
766 urlescputs(m_subject);
767 wprintf("\">[%s]</a> ", _("ReplyQuoted"));
772 if (WC->wc_view == VIEW_MAILBOX) {
773 wprintf("<a href=\"/display_enter");
774 wprintf("?replyquote=%ld", msgnum);
776 urlescputs(reply_to);
778 urlescputs(reply_all);
779 if (strlen(m_subject) > 0) {
780 wprintf("?subject=");
781 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
782 urlescputs(m_subject);
784 wprintf("\">[%s]</a> ", _("ReplyAll"));
788 if (WC->wc_view == VIEW_MAILBOX) {
789 wprintf("<a href=\"/display_enter?fwdquote=%ld?subject=", msgnum);
790 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
791 urlescputs(m_subject);
792 wprintf("\">[%s]</a> ", _("Forward"));
795 /* If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
796 if ( (WC->is_room_aide) || (WC->is_mailbox) ) {
798 wprintf("<a href=\"/confirm_move_msg?msgid=%ld\">[%s]</a> ",
802 wprintf("<a href=\"/delete_msg?msgid=%ld\" "
803 "onClick=\"return confirm('%s');\">"
804 "[%s]</a> ", msgnum, _("Delete this message?"), _("Delete")
808 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'); \" >"
809 "[%s]</a>", msgnum, msgnum, _("Print"));
814 wprintf("</TR></TABLE>\n");
817 wprintf("<TABLE BORDER=0 WIDTH=100%% BGCOLOR=#FFFFFF "
818 "CELLPADDING=1 CELLSPACING=0><TR><TD>");
821 * Learn the content type
823 strcpy(mime_content_type, "text/plain");
824 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
825 if (!strcmp(buf, "000")) {
827 wprintf(_("unexpected end of message"));
828 wprintf("</I><br /><br />\n");
831 if (!strncasecmp(buf, "Content-type: ", 14)) {
832 safestrncpy(mime_content_type, &buf[14],
833 sizeof(mime_content_type));
834 for (i=0; i<strlen(mime_content_type); ++i) {
835 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
836 safestrncpy(mime_charset, &mime_content_type[i+8],
837 sizeof mime_charset);
840 for (i=0; i<strlen(mime_content_type); ++i) {
841 if (mime_content_type[i] == ';') {
842 mime_content_type[i] = 0;
848 /* Set up a character set conversion if we need to (and if we can) */
850 if ( (strcasecmp(mime_charset, "us-ascii"))
851 && (strcasecmp(mime_charset, "UTF-8")) ) {
852 ic = iconv_open("UTF-8", mime_charset);
853 if (ic == (iconv_t)(-1) ) {
854 lprintf(5, "iconv_open() failed: %s\n", strerror(errno));
859 /* Messages in legacy Citadel variformat get handled thusly... */
860 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
864 /* Boring old 80-column fixed format text gets handled this way... */
865 else if ( (!strcasecmp(mime_content_type, "text/plain"))
866 || (!strcasecmp(mime_content_type, "text")) ) {
867 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
868 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
869 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
872 if (ic != (iconv_t)(-1) ) {
874 ibuflen = strlen(ibuf);
876 obuf = (char *) malloc(obuflen);
878 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
879 osav[SIZ-obuflen] = 0;
880 safestrncpy(buf, osav, sizeof buf);
885 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
886 buf[strlen(buf) - 1] = 0;
888 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
889 wprintf("<BLOCKQUOTE>");
891 } else if ((bq == 1) &&
892 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
893 wprintf("</BLOCKQUOTE>");
899 wprintf("</TT><br />\n");
901 wprintf("</I><br />");
904 else /* HTML is fun, but we've got to strip it first */
905 if (!strcasecmp(mime_content_type, "text/html")) {
906 output_html(mime_charset);
909 /* Unknown weirdness */
911 wprintf(_("I don't know how to display %s"), mime_content_type);
912 wprintf("<br />\n", mime_content_type);
913 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
916 /* If there are attached submessages, display them now... */
917 if (strlen(mime_submessages) > 0) {
918 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
919 extract_token(buf, mime_submessages, i, '|', sizeof buf);
920 /* use printable_view to suppress buttons */
921 wprintf("<blockquote>");
922 read_message(msgnum, 1, buf);
923 wprintf("</blockquote>");
929 /* Afterwards, offer links to download attachments 'n' such */
930 if (strlen(mime_http) > 0) {
931 wprintf("%s", mime_http);
934 /* Handler for vCard parts */
935 if (strlen(vcard_partnum) > 0) {
936 part_source = load_mimepart(msgnum, vcard_partnum);
937 if (part_source != NULL) {
939 /* If it's my vCard I can edit it */
940 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
941 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
942 || (WC->wc_view == VIEW_ADDRESSBOOK)
944 wprintf("<A HREF=\"/edit_vcard?"
945 "msgnum=%ld?partnum=%s\">",
946 msgnum, vcard_partnum);
947 wprintf("[%s]</A>", _("edit"));
950 /* In all cases, display the full card */
951 display_vcard(part_source, 0, 1, NULL);
955 /* Handler for calendar parts */
956 if (strlen(cal_partnum) > 0) {
957 part_source = load_mimepart(msgnum, cal_partnum);
958 if (part_source != NULL) {
959 cal_process_attachment(part_source,
960 msgnum, cal_partnum);
970 wprintf("</TD></TR></TABLE>\n");
972 /* end everythingamundo table */
973 if (!printable_view) {
974 wprintf("</TD></TR></TABLE>\n");
975 wprintf("</div><br />\n");
979 if (ic != (iconv_t)(-1) ) {
988 * Unadorned HTML output of an individual message, suitable
989 * for placing in a hidden iframe, for printing, or whatever
991 void embed_message(void) {
994 msgnum = atol(bstr("msgnum"));
995 begin_ajax_response();
996 read_message(msgnum, 0, "");
1002 * Printable view of a message
1004 void print_message(void) {
1007 msgnum = atol(bstr("msgnum"));
1008 output_headers(0, 0, 0, 0, 0, 0);
1010 wprintf("Content-type: text/html\r\n"
1012 "Connection: close\r\n",
1016 wprintf("\r\n\r\n<html>\n"
1017 "<head><title>Printable view</title></head>\n"
1018 "<body onLoad=\" window.print(); window.close(); \">\n"
1021 read_message(msgnum, 1, "");
1023 wprintf("\n</body></html>\n\n");
1030 * Read message in simple, JavaScript-embeddable form for 'forward'
1031 * or 'reply quoted' operations.
1033 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1034 * in this function. Doing so would throw a JavaScript error in the
1035 * 'supplied text' argument to the editor.
1037 void pullquote_message(long msgnum, int forward_attachments) {
1039 char mime_partnum[256];
1040 char mime_filename[256];
1041 char mime_content_type[256];
1042 char mime_charset[256];
1043 char mime_disposition[256];
1045 char mime_http[SIZ];
1046 char *attachments = NULL;
1047 int num_attachments = 0;
1048 struct wc_attachment *att, *aptr;
1049 char m_subject[256];
1055 int format_type = 0;
1060 iconv_t ic = (iconv_t)(-1) ;
1061 char *ibuf; /* Buffer of characters to be converted */
1062 char *obuf; /* Buffer for converted characters */
1063 size_t ibuflen; /* Length of input buffer */
1064 size_t obuflen; /* Length of output buffer */
1065 char *osav; /* Saved pointer to output buffer */
1071 strcpy(reply_to, "");
1072 strcpy(mime_http, "");
1073 strcpy(mime_content_type, "text/plain");
1074 strcpy(mime_charset, "us-ascii");
1076 serv_printf("MSG4 %ld", msgnum);
1077 serv_getln(buf, sizeof buf);
1078 if (buf[0] != '1') {
1079 wprintf(_("ERROR:"));
1080 wprintf("%s<br />", &buf[4]);
1084 strcpy(m_subject, "");
1086 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1087 if (!strcmp(buf, "000")) {
1088 wprintf(_("unexpected end of message"));
1091 if (!strncasecmp(buf, "nhdr=yes", 8))
1095 if (!strncasecmp(buf, "type=", 5))
1096 format_type = atoi(&buf[5]);
1097 if (!strncasecmp(buf, "from=", 5)) {
1098 strcpy(from, &buf[5]);
1099 wprintf(_("from "));
1101 utf8ify_rfc822_string(from);
1105 if (!strncasecmp(buf, "subj=", 5)) {
1106 strcpy(m_subject, &buf[5]);
1108 if ((!strncasecmp(buf, "hnod=", 5))
1109 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1110 wprintf("(%s) ", &buf[5]);
1112 if ((!strncasecmp(buf, "room=", 5))
1113 && (strcasecmp(&buf[5], WC->wc_roomname))
1114 && (strlen(&buf[5])>0) ) {
1116 wprintf("%s> ", &buf[5]);
1118 if (!strncasecmp(buf, "rfca=", 5)) {
1119 strcpy(rfca, &buf[5]);
1125 if (!strncasecmp(buf, "node=", 5)) {
1126 strcpy(node, &buf[5]);
1127 if ( ((WC->room_flags & QR_NETWORK)
1128 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1129 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1130 && (strlen(rfca)==0)
1132 wprintf("@%s ", &buf[5]);
1135 if (!strncasecmp(buf, "rcpt=", 5)) {
1137 wprintf("%s ", &buf[5]);
1139 if (!strncasecmp(buf, "time=", 5)) {
1140 fmt_date(now, atol(&buf[5]), 0);
1141 wprintf("%s ", now);
1145 * Save attachment info for later. We can't start downloading them
1146 * yet because we're in the middle of a server transaction.
1148 if (!strncasecmp(buf, "part=", 5)) {
1150 attachments = realloc(attachments, (num_attachments * 1024));
1151 strcat(attachments, &buf[5]);
1152 strcat(attachments, "\n");
1160 utf8ify_rfc822_string(m_subject);
1162 if (strlen(m_subject) > 0) {
1163 wprintf(_("Subject:"));
1165 msgescputs(m_subject);
1175 * Learn the content type
1177 strcpy(mime_content_type, "text/plain");
1178 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1179 if (!strcmp(buf, "000")) {
1180 wprintf(_("unexpected end of message"));
1183 if (!strncasecmp(buf, "Content-type: ", 14)) {
1184 safestrncpy(mime_content_type, &buf[14],
1185 sizeof(mime_content_type));
1186 for (i=0; i<strlen(mime_content_type); ++i) {
1187 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1188 safestrncpy(mime_charset, &mime_content_type[i+8],
1189 sizeof mime_charset);
1192 for (i=0; i<strlen(mime_content_type); ++i) {
1193 if (mime_content_type[i] == ';') {
1194 mime_content_type[i] = 0;
1200 /* Set up a character set conversion if we need to (and if we can) */
1202 if ( (strcasecmp(mime_charset, "us-ascii"))
1203 && (strcasecmp(mime_charset, "UTF-8")) ) {
1204 ic = iconv_open("UTF-8", mime_charset);
1205 if (ic == (iconv_t)(-1) ) {
1206 lprintf(5, "iconv_open() failed: %s\n", strerror(errno));
1211 /* Messages in legacy Citadel variformat get handled thusly... */
1212 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1216 /* Boring old 80-column fixed format text gets handled this way... */
1217 else if (!strcasecmp(mime_content_type, "text/plain")) {
1218 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1219 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1220 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1223 if (ic != (iconv_t)(-1) ) {
1225 ibuflen = strlen(ibuf);
1227 obuf = (char *) malloc(obuflen);
1229 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1230 osav[SIZ-obuflen] = 0;
1231 safestrncpy(buf, osav, sizeof buf);
1236 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1237 buf[strlen(buf) - 1] = 0;
1239 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
1240 wprintf("<BLOCKQUOTE>");
1242 } else if ((bq == 1) &&
1243 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
1244 wprintf("</BLOCKQUOTE>");
1250 wprintf("</TT><br />");
1252 wprintf("</I><br />");
1255 /* HTML just gets escaped and stuffed back into the editor */
1256 else if (!strcasecmp(mime_content_type, "text/html")) {
1257 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1262 /* Unknown weirdness ... don't know how to handle this content type */
1264 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1268 /* end of body handler */
1271 * If there were attachments, we have to download them and insert them
1272 * into the attachment chain for the forwarded message we are composing.
1274 if ( (forward_attachments) && (num_attachments) ) {
1275 for (i=0; i<num_attachments; ++i) {
1276 extract_token(buf, attachments, i, '\n', sizeof buf);
1277 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1278 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1279 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1280 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1281 mime_length = extract_int(buf, 5);
1284 * tracing ... uncomment if necessary
1286 lprintf(9, "fwd filename: %s\n", mime_filename);
1287 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1288 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1289 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1290 lprintf(9, "fwd length : %d\n", mime_length);
1293 if ( (!strcasecmp(mime_disposition, "inline"))
1294 || (!strcasecmp(mime_disposition, "attachment")) ) {
1296 /* Create an attachment struct from this mime part... */
1297 att = malloc(sizeof(struct wc_attachment));
1298 memset(att, 0, sizeof(struct wc_attachment));
1299 att->length = mime_length;
1300 strcpy(att->content_type, mime_content_type);
1301 strcpy(att->filename, mime_filename);
1303 att->data = load_mimepart(msgnum, mime_partnum);
1305 /* And add it to the list. */
1306 if (WC->first_attachment == NULL) {
1307 WC->first_attachment = att;
1310 aptr = WC->first_attachment;
1311 while (aptr->next != NULL) aptr = aptr->next;
1321 if (ic != (iconv_t)(-1) ) {
1332 void display_summarized(int num) {
1335 wprintf("<tr bgcolor=\"#%s\" ",
1336 ((num % 2) ? "DDDDDD" : "FFFFFF")
1339 wprintf("onClick=\" new Ajax.Updater('preview_pane', '/msg', { method: 'get', parameters: 'msgnum=%ld' } ); \" ", WC->summ[num].msgnum);
1343 if (WC->summ[num].is_new) wprintf("<B>");
1344 escputs(WC->summ[num].subj);
1345 if (WC->summ[num].is_new) wprintf("</B>");
1346 wprintf("</TD><TD>");
1347 if (WC->summ[num].is_new) wprintf("<B>");
1348 escputs(WC->summ[num].from);
1349 if (WC->summ[num].is_new) wprintf("</B>");
1350 wprintf(" </TD><TD>");
1351 if (WC->summ[num].is_new) wprintf("<B>");
1352 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1354 if (WC->summ[num].is_new) wprintf("</B>");
1357 "<INPUT TYPE=\"checkbox\" NAME=\"msg_%ld\" VALUE=\"yes\">"
1359 WC->summ[num].msgnum
1369 void display_addressbook(long msgnum, char alpha) {
1371 char mime_partnum[SIZ];
1372 char mime_filename[SIZ];
1373 char mime_content_type[SIZ];
1374 char mime_disposition[SIZ];
1376 char vcard_partnum[SIZ];
1377 char *vcard_source = NULL;
1378 struct message_summary summ;
1380 memset(&summ, 0, sizeof(summ));
1381 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1383 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1385 serv_getln(buf, sizeof buf);
1386 if (buf[0] != '1') return;
1388 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1389 if (!strncasecmp(buf, "part=", 5)) {
1390 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1391 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1392 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1393 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1394 mime_length = extract_int(&buf[5], 5);
1396 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1397 strcpy(vcard_partnum, mime_partnum);
1403 if (strlen(vcard_partnum) > 0) {
1404 vcard_source = load_mimepart(msgnum, vcard_partnum);
1405 if (vcard_source != NULL) {
1407 /* Display the summary line */
1408 display_vcard(vcard_source, alpha, 0, NULL);
1410 /* If it's my vCard I can edit it */
1411 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1412 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1413 || (WC->wc_view == VIEW_ADDRESSBOOK)
1415 wprintf("<A HREF=\"/edit_vcard?"
1416 "msgnum=%ld?partnum=%s\">",
1417 msgnum, vcard_partnum);
1418 wprintf("[%s]</A>", _("edit"));
1429 /* If it's an old "Firstname Lastname" style record, try to
1432 void lastfirst_firstlast(char *namebuf) {
1433 char firstname[SIZ];
1437 if (namebuf == NULL) return;
1438 if (strchr(namebuf, ';') != NULL) return;
1440 i = num_tokens(namebuf, ' ');
1443 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1444 remove_token(namebuf, i-1, ' ');
1445 strcpy(firstname, namebuf);
1446 sprintf(namebuf, "%s; %s", lastname, firstname);
1450 void fetch_ab_name(long msgnum, char *namebuf) {
1452 char mime_partnum[SIZ];
1453 char mime_filename[SIZ];
1454 char mime_content_type[SIZ];
1455 char mime_disposition[SIZ];
1457 char vcard_partnum[SIZ];
1458 char *vcard_source = NULL;
1460 struct message_summary summ;
1462 if (namebuf == NULL) return;
1463 strcpy(namebuf, "");
1465 memset(&summ, 0, sizeof(summ));
1466 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1468 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1470 serv_getln(buf, sizeof buf);
1471 if (buf[0] != '1') return;
1473 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1474 if (!strncasecmp(buf, "part=", 5)) {
1475 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1476 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1477 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1478 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1479 mime_length = extract_int(&buf[5], 5);
1481 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1482 strcpy(vcard_partnum, mime_partnum);
1488 if (strlen(vcard_partnum) > 0) {
1489 vcard_source = load_mimepart(msgnum, vcard_partnum);
1490 if (vcard_source != NULL) {
1492 /* Grab the name off the card */
1493 display_vcard(vcard_source, 0, 0, namebuf);
1499 lastfirst_firstlast(namebuf);
1501 for (i=0; i<strlen(namebuf); ++i) {
1502 if (namebuf[i] != ';') return;
1504 strcpy(namebuf, _("(no name)"));
1510 * Record compare function for sorting address book indices
1512 int abcmp(const void *ab1, const void *ab2) {
1514 (((const struct addrbookent *)ab1)->ab_name),
1515 (((const struct addrbookent *)ab2)->ab_name)
1521 * Helper function for do_addrbook_view()
1522 * Converts a name into a three-letter tab label
1524 void nametab(char *tabbuf, char *name) {
1525 stresc(tabbuf, name, 0, 0);
1526 tabbuf[0] = toupper(tabbuf[0]);
1527 tabbuf[1] = tolower(tabbuf[1]);
1528 tabbuf[2] = tolower(tabbuf[2]);
1534 * Render the address book using info we gathered during the scan
1536 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1540 static int NAMESPERPAGE = 60;
1544 char tabfirst_label[SIZ];
1546 char tablast_label[SIZ];
1549 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1550 wprintf(_("This address book is empty."));
1551 wprintf("</i></div>\n");
1556 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1559 num_pages = num_ab / NAMESPERPAGE;
1561 page = atoi(bstr("page"));
1564 for (i=0; i<=num_pages; ++i) {
1566 wprintf("<A HREF=\"/readfwd?page=%d\">", i);
1571 tabfirst = i * NAMESPERPAGE;
1572 tablast = tabfirst + NAMESPERPAGE - 1;
1573 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1574 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1575 nametab(tablast_label, addrbook[tablast].ab_name);
1576 wprintf("[%s - %s]",
1577 tabfirst_label, tablast_label
1586 wprintf("<br />\n");
1588 wprintf("<TABLE border=0 cellspacing=0 "
1589 "cellpadding=3 width=100%%>\n"
1592 for (i=0; i<num_ab; ++i) {
1594 if ((i / NAMESPERPAGE) == page) {
1596 if ((displayed % 4) == 0) {
1597 if (displayed > 0) {
1601 wprintf("<TR BGCOLOR=\"#%s\">",
1602 (bg ? "DDDDDD" : "FFFFFF")
1608 wprintf("<A HREF=\"/readfwd?startmsg=%ld&is_singlecard=1",
1609 addrbook[i].ab_msgnum);
1610 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1611 vcard_n_prettyize(addrbook[i].ab_name);
1612 escputs(addrbook[i].ab_name);
1613 wprintf("</A></TD>\n");
1618 wprintf("</TR></TABLE>\n");
1624 * load message pointers from the server
1626 int load_msg_ptrs(char *servcmd, int with_headers)
1630 char displayname[128];
1637 int num_summ_alloc = 0;
1640 if (WC->num_summ != 0) {
1645 num_summ_alloc = 100;
1647 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1650 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1652 serv_getln(buf, sizeof buf);
1653 if (buf[0] != '1') {
1654 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1657 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1658 if (nummsgs < maxload) {
1659 WC->msgarr[nummsgs] = extract_long(buf, 0);
1660 datestamp = extract_long(buf, 1);
1661 extract_token(displayname, buf, 2, '|', sizeof displayname);
1662 extract_token(nodename, buf, 3, '|', sizeof nodename);
1663 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1664 extract_token(subject, buf, 5, '|', sizeof subject);
1668 if (nummsgs > num_summ_alloc) {
1669 num_summ_alloc *= 2;
1670 WC->summ = realloc(WC->summ, num_summ_alloc * sizeof(struct message_summary));
1674 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1675 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1676 safestrncpy(WC->summ[nummsgs-1].subj, _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1677 if (strlen(displayname) > 0) {
1678 safestrncpy(WC->summ[nummsgs-1].from, displayname, sizeof WC->summ[nummsgs-1].from);
1680 if (strlen(subject) > 0) {
1681 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1682 sizeof WC->summ[nummsgs-1].subj);
1685 /* Handle subjects with RFC2047 encoding */
1686 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1688 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1689 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1692 if (strlen(nodename) > 0) {
1693 if ( ((WC->room_flags & QR_NETWORK)
1694 || ((strcasecmp(nodename, serv_info.serv_nodename)
1695 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1697 strcat(WC->summ[nummsgs-1].from, " @ ");
1698 strcat(WC->summ[nummsgs-1].from, nodename);
1702 WC->summ[nummsgs-1].date = datestamp;
1705 /* Handle senders with RFC2047 encoding */
1706 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1708 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1709 strcpy(&WC->summ[nummsgs-1].from[22], "...");
1718 int summcmp_subj(const void *s1, const void *s2) {
1719 struct message_summary *summ1;
1720 struct message_summary *summ2;
1722 summ1 = (struct message_summary *)s1;
1723 summ2 = (struct message_summary *)s2;
1724 return strcasecmp(summ1->subj, summ2->subj);
1727 int summcmp_rsubj(const void *s1, const void *s2) {
1728 struct message_summary *summ1;
1729 struct message_summary *summ2;
1731 summ1 = (struct message_summary *)s1;
1732 summ2 = (struct message_summary *)s2;
1733 return strcasecmp(summ2->subj, summ1->subj);
1736 int summcmp_sender(const void *s1, const void *s2) {
1737 struct message_summary *summ1;
1738 struct message_summary *summ2;
1740 summ1 = (struct message_summary *)s1;
1741 summ2 = (struct message_summary *)s2;
1742 return strcasecmp(summ1->from, summ2->from);
1745 int summcmp_rsender(const void *s1, const void *s2) {
1746 struct message_summary *summ1;
1747 struct message_summary *summ2;
1749 summ1 = (struct message_summary *)s1;
1750 summ2 = (struct message_summary *)s2;
1751 return strcasecmp(summ2->from, summ1->from);
1754 int summcmp_date(const void *s1, const void *s2) {
1755 struct message_summary *summ1;
1756 struct message_summary *summ2;
1758 summ1 = (struct message_summary *)s1;
1759 summ2 = (struct message_summary *)s2;
1761 if (summ1->date < summ2->date) return -1;
1762 else if (summ1->date > summ2->date) return +1;
1766 int summcmp_rdate(const void *s1, const void *s2) {
1767 struct message_summary *summ1;
1768 struct message_summary *summ2;
1770 summ1 = (struct message_summary *)s1;
1771 summ2 = (struct message_summary *)s2;
1773 if (summ1->date < summ2->date) return +1;
1774 else if (summ1->date > summ2->date) return -1;
1779 * command loop for reading messages
1781 void readloop(char *oper)
1790 int num_displayed = 0;
1792 int is_addressbook = 0;
1793 int is_singlecard = 0;
1794 int is_calendar = 0;
1797 int remaining_messages;
1799 int lowest_displayed = (-1);
1800 int highest_displayed = 0;
1801 long pn_previous = 0L;
1802 long pn_current = 0L;
1804 struct addrbookent *addrbook = NULL;
1806 char *sortby = NULL;
1807 char sortpref_name[128];
1808 char sortpref_value[128];
1809 char *subjsort_button;
1810 char *sendsort_button;
1811 char *datesort_button;
1813 startmsg = atol(bstr("startmsg"));
1814 maxmsgs = atoi(bstr("maxmsgs"));
1815 is_summary = atoi(bstr("summary"));
1816 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1818 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
1819 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
1821 sortby = bstr("sortby");
1822 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
1823 set_preference(sortpref_name, sortby, 1);
1825 if (strlen(sortby) == 0) sortby = sortpref_value;
1826 if (strlen(sortby) == 0) sortby = "rdate";
1828 output_headers(1, 1, 1, 0, 0, 0);
1830 /* When in summary mode, always show ALL messages instead of just
1831 * new or old. Otherwise, show what the user asked for.
1833 if (!strcmp(oper, "readnew")) {
1834 strcpy(cmd, "MSGS NEW");
1836 else if (!strcmp(oper, "readold")) {
1837 strcpy(cmd, "MSGS OLD");
1840 strcpy(cmd, "MSGS ALL");
1843 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
1845 strcpy(cmd, "MSGS ALL");
1848 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
1850 strcpy(cmd, "MSGS ALL");
1855 strcpy(cmd, "MSGS ALL|||1"); /* fetch header summary */
1860 /* Are we doing a summary view? If so, we need to know old messages
1861 * and new messages, so we can do that pretty boldface thing for the
1864 strcpy(old_msgs, "");
1867 serv_getln(buf, sizeof buf);
1868 if (buf[0] == '2') {
1869 strcpy(old_msgs, &buf[4]);
1873 is_singlecard = atoi(bstr("is_singlecard"));
1875 if (WC->wc_view == VIEW_CALENDAR) { /* calendar */
1877 strcpy(cmd, "MSGS ALL");
1880 if (WC->wc_view == VIEW_TASKS) { /* tasks */
1882 strcpy(cmd, "MSGS ALL");
1885 if (WC->wc_view == VIEW_NOTES) { /* notes */
1887 strcpy(cmd, "MSGS ALL");
1891 nummsgs = load_msg_ptrs(cmd, is_summary);
1894 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
1896 if (!strcmp(oper, "readnew")) {
1897 wprintf(_("No new messages."));
1898 } else if (!strcmp(oper, "readold")) {
1899 wprintf(_("No old messages."));
1901 wprintf(_("No messages here."));
1910 for (a = 0; a < nummsgs; ++a) {
1911 /* Are you a new message, or an old message? */
1913 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
1914 WC->summ[a].is_new = 0;
1917 WC->summ[a].is_new = 1;
1923 if (startmsg == 0L) startmsg = WC->msgarr[0];
1924 remaining_messages = 0;
1926 for (a = 0; a < nummsgs; ++a) {
1927 if (WC->msgarr[a] >= startmsg) {
1928 ++remaining_messages;
1933 if (!strcasecmp(sortby, "subject")) {
1934 qsort(WC->summ, WC->num_summ,
1935 sizeof(struct message_summary), summcmp_subj);
1937 else if (!strcasecmp(sortby, "rsubject")) {
1938 qsort(WC->summ, WC->num_summ,
1939 sizeof(struct message_summary), summcmp_rsubj);
1941 else if (!strcasecmp(sortby, "sender")) {
1942 qsort(WC->summ, WC->num_summ,
1943 sizeof(struct message_summary), summcmp_sender);
1945 else if (!strcasecmp(sortby, "rsender")) {
1946 qsort(WC->summ, WC->num_summ,
1947 sizeof(struct message_summary), summcmp_rsender);
1949 else if (!strcasecmp(sortby, "date")) {
1950 qsort(WC->summ, WC->num_summ,
1951 sizeof(struct message_summary), summcmp_date);
1953 else if (!strcasecmp(sortby, "rdate")) {
1954 qsort(WC->summ, WC->num_summ,
1955 sizeof(struct message_summary), summcmp_rdate);
1959 if (!strcasecmp(sortby, "subject")) {
1960 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1962 else if (!strcasecmp(sortby, "rsubject")) {
1963 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1966 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1969 if (!strcasecmp(sortby, "sender")) {
1970 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1972 else if (!strcasecmp(sortby, "rsender")) {
1973 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1976 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1979 if (!strcasecmp(sortby, "date")) {
1980 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1982 else if (!strcasecmp(sortby, "rdate")) {
1983 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1986 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1990 wprintf("</div>"); /* end of 'content' div */
1992 wprintf("<div id=\"message_list\">"
1994 "<div id=\"fix_scrollbar_bug\">\n"
1996 "<form name=\"msgomatic\" "
1997 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n"
1999 "<span class=\"mailbox_summary\">"
2000 "<table border=0 cellspacing=0 "
2001 "cellpadding=0 width=100%%>\n"
2003 "<TD align=center><b><i>%s</i></b> %s</TD>"
2004 "<TD align=center><b><i>%s</i></b> %s</TD>"
2005 "<TD align=center><b><i>%s</i></b> %s</TD>"
2006 "<TD><INPUT TYPE=\"submit\" NAME=\"delete_button\" "
2007 "STYLE=\"font-family: Bitstream Vera Sans,Arial,Helvetica,sans-serif;"
2008 " font-size: 6pt;\" "
2009 "VALUE=\"%s\"></TD>"
2012 _("Subject"), subjsort_button,
2013 _("Sender"), sendsort_button,
2014 _("Date"), datesort_button,
2019 for (a = 0; a < nummsgs; ++a) {
2020 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2022 /* Learn which msgs "Prev" & "Next" buttons go to */
2023 pn_current = WC->msgarr[a];
2024 if (a > 0) pn_previous = WC->msgarr[a-1];
2025 if (a < (nummsgs-1)) pn_next = WC->msgarr[a+1];
2027 /* Display the message */
2029 display_summarized(a);
2031 else if (is_addressbook) {
2032 fetch_ab_name(WC->msgarr[a], buf);
2034 addrbook = realloc(addrbook,
2035 (sizeof(struct addrbookent) * num_ab) );
2036 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2037 sizeof(addrbook[num_ab-1].ab_name));
2038 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
2040 else if (is_calendar) {
2041 display_calendar(WC->msgarr[a]);
2043 else if (is_tasks) {
2044 display_task(WC->msgarr[a]);
2046 else if (is_notes) {
2047 display_note(WC->msgarr[a]);
2050 read_message(WC->msgarr[a], 0, "");
2053 if (lowest_displayed < 0) lowest_displayed = a;
2054 highest_displayed = a;
2057 --remaining_messages;
2062 wprintf("</table></span></form>"
2063 "</div>\n"); /* end of 'fix_scrollbar_bug' div */
2064 wprintf("</div>"); /* end of 'message_list' div */
2066 wprintf("<div id=\"ml_slider\"></div>"); /* slider */
2068 wprintf("<div id=\"preview_pane\">"); /* The preview pane will initially be empty */
2070 /* Now register each message (whose element ID is "m9999",
2071 * where "9999" is the message number) as draggable.
2072 wprintf("<script type=\"text/javascript\">\n");
2073 for (a = 0; a < nummsgs; ++a) {
2074 wprintf("new Draggable('m%ld',{revert:true});\n",
2075 WC->summ[a].msgnum);
2077 wprintf("</script>\n");
2081 /* Bump these because although we're thinking in zero base, the user
2082 * is a drooling idiot and is thinking in one base.
2085 ++highest_displayed;
2087 /* If we're only looking at one message, do a prev/next thing */
2088 if (num_displayed == 1) {
2089 if ((!is_tasks) && (!is_calendar) && (!is_addressbook) && (!is_notes) && (!is_singlecard)) {
2091 wprintf("<div id=\"fix_scrollbar_bug\">"
2092 "<table border=0 width=100%% bgcolor=\"#dddddd\"><tr><td>");
2093 wprintf(_("Reading #%d of %d messages."), lowest_displayed, nummsgs);
2094 wprintf("</TD><TD ALIGN=RIGHT><FONT SIZE=+1>");
2096 if (pn_previous > 0L) {
2097 wprintf("<A HREF=\"/%s"
2108 wprintf("<A HREF=\"/%s"
2118 wprintf("<A HREF=\"/%s?startmsg=%ld"
2119 "?maxmsgs=%d?summary=1\">"
2128 wprintf("</td></tr></table></div>\n");
2133 * If we're not currently looking at ALL requested
2134 * messages, then display the selector bar
2136 if (num_displayed > 1) {
2137 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2138 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2140 wprintf("<form name=\"msgomatic\" "
2141 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n");
2143 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2145 wprintf("<select name=\"whichones\" size=\"1\" "
2146 "OnChange=\"location.href=msgomatic.whichones.options"
2147 "[selectedIndex].value\">\n");
2149 for (b=0; b<nummsgs; b = b + maxmsgs) {
2152 if (hi > nummsgs) hi = nummsgs;
2153 wprintf("<option %s value="
2158 "%d-%d</option> \n",
2159 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2166 wprintf("<option value=\"/%s?startmsg=%ld"
2167 "?maxmsgs=9999999?summary=%d\">"
2171 WC->msgarr[0], is_summary);
2173 wprintf("</select> ");
2174 wprintf(_("of %d messages."), nummsgs);
2175 wprintf("</form>\n");
2181 do_tasks_view(); /* Render the task list */
2185 do_calendar_view(); /* Render the calendar */
2188 if (is_addressbook) {
2189 do_addrbook_view(addrbook, num_ab); /* Render the address book */
2192 /* Put the data transfer hidden iframe in a hidden div, to make it *really* hidden */
2194 "<div display=\"hidden\">\n"
2195 "<iframe name=\"msgloader1\" id=\"msgloader1\" width=\"1\"></iframe>\n"
2198 /* Note: wDumpContent() will output one additional </div> tag. */
2200 if (addrbook != NULL) free(addrbook);
2202 /* free the summary */
2203 if (WC->num_summ != 0) {
2208 /* If we got here via a mailbox view and are reading a single
2209 * message, mark it as "seen." We do this after rendering the web page
2210 * so it doesn't keep the user waiting.
2212 if ( (maxmsgs == 1) && (WC->wc_view == VIEW_MAILBOX) ) {
2213 serv_printf("SEEN %ld|1", startmsg);
2214 serv_getln(buf, sizeof buf);
2220 * Back end for post_message() ... this is where the actual message
2221 * gets transmitted to the server.
2223 void post_mime_to_server(void) {
2225 int is_multipart = 0;
2227 struct wc_attachment *att;
2229 size_t encoded_length;
2231 /* RFC2045 requires this, and some clients look for it... */
2232 serv_puts("MIME-Version: 1.0");
2234 /* If there are attachments, we have to do multipart/mixed */
2235 if (WC->first_attachment != NULL) {
2240 sprintf(boundary, "---Citadel-Multipart-%s-%04x%04x---",
2241 serv_info.serv_fqdn,
2246 /* Remember, serv_printf() appends an extra newline */
2247 serv_printf("Content-type: multipart/mixed; "
2248 "boundary=\"%s\"\n", boundary);
2249 serv_printf("This is a multipart message in MIME format.\n");
2250 serv_printf("--%s", boundary);
2253 serv_puts("Content-type: text/html; charset=utf-8");
2255 serv_puts("<HTML><BODY>\n");
2256 text_to_server(bstr("msgtext"), 0);
2257 serv_puts("</BODY></HTML>\n");
2262 /* Add in the attachments */
2263 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2265 encoded_length = ((att->length * 150) / 100);
2266 encoded = malloc(encoded_length);
2267 if (encoded == NULL) break;
2268 CtdlEncodeBase64(encoded, att->data, att->length);
2270 serv_printf("--%s", boundary);
2271 serv_printf("Content-type: %s", att->content_type);
2272 serv_printf("Content-disposition: attachment; "
2273 "filename=\"%s\"", att->filename);
2274 serv_puts("Content-transfer-encoding: base64");
2276 serv_write(encoded, strlen(encoded));
2281 serv_printf("--%s--", boundary);
2289 * Post message (or don't post message)
2291 * Note regarding the "dont_post" variable:
2292 * A random value (actually, it's just a timestamp) is inserted as a hidden
2293 * field called "postseq" when the display_enter page is generated. This
2294 * value is checked when posting, using the static variable dont_post. If a
2295 * user attempts to post twice using the same dont_post value, the message is
2296 * discarded. This prevents the accidental double-saving of the same message
2297 * if the user happens to click the browser "back" button.
2299 void post_message(void)
2302 static long dont_post = (-1L);
2303 struct wc_attachment *att, *aptr;
2305 if (WC->upload_length > 0) {
2307 /* There's an attachment. Save it to this struct... */
2308 att = malloc(sizeof(struct wc_attachment));
2309 memset(att, 0, sizeof(struct wc_attachment));
2310 att->length = WC->upload_length;
2311 strcpy(att->content_type, WC->upload_content_type);
2312 strcpy(att->filename, WC->upload_filename);
2315 /* And add it to the list. */
2316 if (WC->first_attachment == NULL) {
2317 WC->first_attachment = att;
2320 aptr = WC->first_attachment;
2321 while (aptr->next != NULL) aptr = aptr->next;
2325 /* Mozilla sends a simple filename, which is what we want,
2326 * but Satan's Browser sends an entire pathname. Reduce
2327 * the path to just a filename if we need to.
2329 while (num_tokens(att->filename, '/') > 1) {
2330 remove_token(att->filename, 0, '/');
2332 while (num_tokens(att->filename, '\\') > 1) {
2333 remove_token(att->filename, 0, '\\');
2336 /* Transfer control of this memory from the upload struct
2337 * to the attachment struct.
2339 att->data = WC->upload;
2340 WC->upload_length = 0;
2346 if (strlen(bstr("cancel_button")) > 0) {
2347 sprintf(WC->ImportantMessage,
2348 _("Cancelled. Message was not posted."));
2349 } else if (strlen(bstr("attach_button")) > 0) {
2352 } else if (atol(bstr("postseq")) == dont_post) {
2353 sprintf(WC->ImportantMessage,
2354 _("Automatically cancelled because you have already "
2355 "saved this message."));
2357 sprintf(buf, "ENT0 1|%s|0|4|%s|||%s|%s",
2364 serv_getln(buf, sizeof buf);
2365 if (buf[0] == '4') {
2366 post_mime_to_server();
2367 if ( (strlen(bstr("recp")) > 0)
2368 || (strlen(bstr("cc")) > 0)
2369 || (strlen(bstr("bcc")) > 0)
2371 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2374 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2376 dont_post = atol(bstr("postseq"));
2378 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2384 free_attachments(WC);
2385 readloop("readnew");
2392 * display the message entry screen
2394 void display_enter(void)
2399 struct wc_attachment *att;
2400 int recipient_required = 0;
2401 int recipient_bad = 0;
2404 if (strlen(bstr("force_room")) > 0) {
2405 gotoroom(bstr("force_room"));
2408 /* Are we perhaps in an address book view? If so, then an "enter
2409 * message" command really means "add new entry."
2411 if (WC->wc_view == VIEW_ADDRESSBOOK) {
2412 do_edit_vcard(-1, "", "");
2416 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
2417 /* Are we perhaps in a calendar view? If so, then an "enter
2418 * message" command really means "add new calendar item."
2420 if (WC->wc_view == VIEW_CALENDAR) {
2421 display_edit_event();
2425 /* Are we perhaps in a tasks view? If so, then an "enter
2426 * message" command really means "add new task."
2428 if (WC->wc_view == VIEW_TASKS) {
2429 display_edit_task();
2435 * Otherwise proceed normally.
2436 * Do a custom room banner with no navbar...
2438 output_headers(1, 1, 2, 0, 0, 0);
2439 wprintf("<div id=\"banner\">\n");
2440 embed_room_banner(NULL, navbar_none);
2441 wprintf("</div>\n");
2442 wprintf("<div id=\"content\">\n"
2443 "<div id=\"fix_scrollbar_bug\">"
2444 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
2446 /* First test to see whether this is a room that requires recipients to be entered */
2447 serv_puts("ENT0 0");
2448 serv_getln(buf, sizeof buf);
2449 if (!strncmp(buf, "570", 3)) { /* 570 means that we need a recipient here */
2450 recipient_required = 1;
2452 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
2453 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2457 /* Now check our actual recipients if there are any */
2458 if (recipient_required) {
2459 sprintf(buf, "ENT0 0|%s|0|0||||%s|%s", bstr("recp"), bstr("cc"), bstr("bcc"));
2461 serv_getln(buf, sizeof buf);
2463 if (!strncmp(buf, "570", 3)) { /* 570 means we have an invalid recipient listed */
2464 if (strlen(bstr("recp")) + strlen(bstr("cc")) + strlen(bstr("bcc")) > 0) {
2468 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
2469 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2474 /* If we got this far, we can display the message entry screen. */
2477 fmt_date(buf, now, 0);
2478 strcat(&buf[strlen(buf)], _(" <I>from</I> "));
2479 stresc(&buf[strlen(buf)], WC->wc_username, 1, 1);
2481 /* Don't need this anymore, it's in the input box below
2482 if (strlen(bstr("recp")) > 0) {
2483 strcat(&buf[strlen(buf)], _(" <I>to</I> "));
2484 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
2488 strcat(&buf[strlen(buf)], _(" <I>in</I> "));
2489 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
2491 /* begin message entry screen */
2492 wprintf("<form enctype=\"multipart/form-data\" "
2493 "method=\"POST\" action=\"/post\" "
2494 "name=\"enterform\""
2496 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2498 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2499 wprintf("%s<br>\n", buf); /* header bar */
2501 wprintf("<table border=\"0\" width=\"100%%\">\n");
2502 if (recipient_required) {
2504 wprintf("<tr><td>");
2505 wprintf("<font size=-1>");
2509 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
2510 escputs(bstr("recp"));
2511 wprintf("\" size=50 maxlength=1000 />");
2512 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
2513 wprintf("</td><td></td></tr>\n");
2515 wprintf("<tr><td>");
2516 wprintf("<font size=-1>");
2520 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
2521 escputs(bstr("cc"));
2522 wprintf("\" size=50 maxlength=1000 />");
2523 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
2524 wprintf("</td><td></td></tr>\n");
2526 wprintf("<tr><td>");
2527 wprintf("<font size=-1>");
2531 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
2532 escputs(bstr("bcc"));
2533 wprintf("\" size=50 maxlength=1000 />");
2534 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
2535 wprintf("</td><td></td></tr>\n");
2537 /* Initialize the autocomplete ajax helpers (found in wclib.js) */
2538 wprintf("<script type=\"text/javascript\"> \n"
2539 " activate_entmsg_autocompleters(); \n"
2544 wprintf("<tr><td>");
2545 wprintf("<font size=-1>");
2546 wprintf(_("Subject (optional):"));
2549 "<input type=\"text\" name=\"subject\" value=\"");
2550 escputs(bstr("subject"));
2551 wprintf("\" size=50 maxlength=70></td><td>\n");
2553 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2554 if (recipient_required) {
2555 wprintf(_("Send message"));
2557 wprintf(_("Post message"));
2560 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2561 wprintf("</td></tr></table>\n");
2563 wprintf("<center>");
2565 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
2567 /* If we're continuing from a previous edit, put our partially-composed message back... */
2568 msgescputs(bstr("msgtext"));
2570 /* If we're forwarding a message, insert it here... */
2571 if (atol(bstr("fwdquote")) > 0L) {
2572 wprintf("<br><div align=center><i>");
2573 wprintf(_("--- forwarded message ---"));
2574 wprintf("</i></div><br>");
2575 pullquote_message(atol(bstr("fwdquote")), 1);
2578 /* If we're replying quoted, insert the quote here... */
2579 else if (atol(bstr("replyquote")) > 0L) {
2582 pullquote_message(atol(bstr("replyquote")), 0);
2583 wprintf("</blockquote>");
2586 /* Insert our signature if appropriate... */
2587 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
2588 get_preference("use_sig", buf, sizeof buf);
2589 if (!strcasecmp(buf, "yes")) {
2590 get_preference("signature", ebuf, sizeof ebuf);
2591 euid_unescapize(buf, ebuf);
2592 wprintf("<br>--<br>");
2593 for (i=0; i<strlen(buf); ++i) {
2594 if (buf[i] == '\n') {
2597 else if (buf[i] == '<') {
2600 else if (buf[i] == '>') {
2603 else if (buf[i] == '&') {
2606 else if (buf[i] == '\"') {
2609 else if (buf[i] == '\'') {
2612 else if (isprint(buf[i])) {
2613 wprintf("%c", buf[i]);
2619 wprintf("</textarea>");
2620 wprintf("</center><br />\n");
2623 * The following script embeds the TinyMCE richedit control, and automatically
2624 * transforms the textarea into a richedit textarea.
2627 "<script language=\"javascript\" type=\"text/javascript\" src=\"tiny_mce/tiny_mce.js\"></script>\n"
2628 "<script language=\"javascript\" type=\"text/javascript\">"
2630 " mode : \"textareas\", width : \"100%%\", browsers : \"msie,gecko\" "
2635 /* Enumerate any attachments which are already in place... */
2636 wprintf("<img src=\"/static/diskette_24x.gif\" border=0 "
2637 "align=middle height=16 width=16> Attachments: ");
2638 wprintf("<select name=\"which_attachment\" size=1>");
2639 for (att = WC->first_attachment; att != NULL; att = att->next) {
2640 wprintf("<option value=\"");
2641 urlescputs(att->filename);
2643 escputs(att->filename);
2644 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
2645 wprintf("</option>\n");
2647 wprintf("</select>");
2649 /* Now offer the ability to attach additional files... */
2650 wprintf(" "
2651 "Attach file: <input NAME=\"attachfile\" "
2652 "SIZE=16 TYPE=\"file\">\n "
2653 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
2655 /* Seth asked for these to be at the top *and* bottom... */
2656 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2657 if (recipient_required) {
2658 wprintf(_("Send message"));
2660 wprintf(_("Post message"));
2663 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2665 /* Make sure we only insert our signature once */
2666 if (strcmp(bstr("sig_inserted"), "yes")) {
2667 wprintf("<INPUT TYPE=\"hidden\" NAME=\"sig_inserted\" VALUE=\"yes\">\n");
2670 wprintf("</form>\n");
2672 wprintf("</td></tr></table></div>\n");
2673 DONE: wDumpContent(1);
2683 void delete_msg(void)
2688 msgid = atol(bstr("msgid"));
2690 output_headers(1, 1, 1, 0, 0, 0);
2692 sprintf(buf, "DELE %ld", msgid);
2694 serv_getln(buf, sizeof buf);
2695 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2704 * Confirm move of a message
2706 void confirm_move_msg(void)
2712 msgid = atol(bstr("msgid"));
2715 output_headers(1, 1, 2, 0, 0, 0);
2716 wprintf("<div id=\"banner\">\n");
2717 wprintf("<TABLE WIDTH=100%% BORDER=0><TR><TD>");
2718 wprintf("<SPAN CLASS=\"titlebar\">");
2719 wprintf(_("Confirm move of message"));
2720 wprintf("</SPAN>\n");
2721 wprintf("</TD></TR></TABLE>\n");
2722 wprintf("</div>\n<div id=\"content\">\n");
2724 wprintf("<CENTER>");
2726 wprintf(_("Move this message to:"));
2727 wprintf("<br />\n");
2729 wprintf("<form METHOD=\"POST\" ACTION=\"/move_msg\">\n");
2730 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
2732 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
2734 serv_getln(buf, sizeof buf);
2735 if (buf[0] == '1') {
2736 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2737 extract_token(targ, buf, 0, '|', sizeof targ);
2738 wprintf("<OPTION>");
2743 wprintf("</SELECT>\n");
2744 wprintf("<br />\n");
2746 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
2748 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
2749 wprintf("</form></CENTER>\n");
2751 wprintf("</CENTER>\n");
2762 msgid = atol(bstr("msgid"));
2764 if (strlen(bstr("move_button")) > 0) {
2765 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
2767 serv_getln(buf, sizeof buf);
2768 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2770 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
2773 readloop("readnew");
2778 * This gets called when a user selects multiple messages in a summary
2779 * list and then clicks to perform a transformation of some sort on them
2780 * (such as deleting them).
2782 void do_stuff_to_msgs(void) {
2786 struct stuff_t *next;
2790 struct stuff_t *stuff = NULL;
2791 struct stuff_t *ptr;
2792 int delete_button_pressed = 0;
2795 serv_puts("MSGS ALL");
2796 serv_getln(buf, sizeof buf);
2798 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2799 ptr = malloc(sizeof(struct stuff_t));
2800 ptr->msgnum = atol(buf);
2805 if (strlen(bstr("delete_button")) > 0) {
2806 delete_button_pressed = 1;
2809 while (stuff != NULL) {
2811 sprintf(buf, "msg_%ld", stuff->msgnum);
2812 if (!strcasecmp(bstr(buf), "yes")) {
2814 if (delete_button_pressed) {
2815 serv_printf("DELE %ld", stuff->msgnum);
2816 serv_getln(buf, sizeof buf);
2826 readloop("readfwd");