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!
496 void read_message(long msgnum, int printable_view) {
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];
511 char reply_all[4096];
517 char vcard_partnum[256];
518 char cal_partnum[256];
519 char *part_source = NULL;
521 iconv_t ic = (iconv_t)(-1) ;
522 char *ibuf; /* Buffer of characters to be converted */
523 char *obuf; /* Buffer for converted characters */
524 size_t ibuflen; /* Length of input buffer */
525 size_t obuflen; /* Length of output buffer */
526 char *osav; /* Saved pointer to output buffer */
532 strcpy(reply_to, "");
533 strcpy(reply_all, "");
534 strcpy(vcard_partnum, "");
535 strcpy(cal_partnum, "");
536 strcpy(mime_http, "");
537 strcpy(mime_content_type, "text/plain");
538 strcpy(mime_charset, "us-ascii");
540 serv_printf("MSG4 %ld", msgnum);
541 serv_getln(buf, sizeof buf);
544 wprintf(_("ERROR:"));
545 wprintf("</STRONG> %s<br />\n", &buf[4]);
549 /* begin everythingamundo table */
550 if (!printable_view) {
551 wprintf("<div id=\"fix_scrollbar_bug\">\n");
552 wprintf("<table width=100%% border=1 cellspacing=0 "
553 "cellpadding=0><TR><TD>\n");
556 /* begin message header table */
557 wprintf("<TABLE WIDTH=100%% BORDER=0 CELLSPACING=0 "
558 "CELLPADDING=1 BGCOLOR=\"#CCCCCC\"><TR><TD>\n");
560 wprintf("<SPAN CLASS=\"message_header\">");
561 strcpy(m_subject, "");
564 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
565 if (!strcmp(buf, "000")) {
567 wprintf(_("unexpected end of message"));
568 wprintf("</I><br /><br />\n");
569 wprintf("</SPAN>\n");
572 if (!strncasecmp(buf, "nhdr=yes", 8))
576 if (!strncasecmp(buf, "type=", 5))
577 format_type = atoi(&buf[5]);
578 if (!strncasecmp(buf, "from=", 5)) {
579 strcpy(from, &buf[5]);
581 wprintf("<A HREF=\"/showuser?who=");
583 utf8ify_rfc822_string(from);
590 if (!strncasecmp(buf, "subj=", 5)) {
591 safestrncpy(m_subject, &buf[5], sizeof m_subject);
593 if (!strncasecmp(buf, "cccc=", 5)) {
594 safestrncpy(m_cc, &buf[5], sizeof m_cc);
595 if (strlen(reply_all) > 0) {
596 strcat(reply_all, ", ");
598 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
599 (sizeof reply_all - strlen(reply_all)) );
601 if ((!strncasecmp(buf, "hnod=", 5))
602 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
603 wprintf("(%s) ", &buf[5]);
605 if ((!strncasecmp(buf, "room=", 5))
606 && (strcasecmp(&buf[5], WC->wc_roomname))
607 && (strlen(&buf[5])>0) ) {
609 wprintf("%s> ", &buf[5]);
611 if (!strncasecmp(buf, "rfca=", 5)) {
612 strcpy(rfca, &buf[5]);
618 if (!strncasecmp(buf, "node=", 5)) {
619 strcpy(node, &buf[5]);
620 if ( ((WC->room_flags & QR_NETWORK)
621 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
622 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
625 wprintf("@%s ", &buf[5]);
628 if (!strncasecmp(buf, "rcpt=", 5)) {
632 if (strlen(reply_all) > 0) {
633 strcat(reply_all, ", ");
635 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
636 (sizeof reply_all - strlen(reply_all)) );
638 if (!strncasecmp(buf, "time=", 5)) {
639 fmt_date(now, atol(&buf[5]), 0);
643 if (!strncasecmp(buf, "part=", 5)) {
644 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
645 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
646 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
647 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
648 mime_length = extract_int(&buf[5], 5);
650 if ((!strcasecmp(mime_disposition, "inline"))
651 && (!strncasecmp(mime_content_type, "image/", 6)) ){
652 snprintf(&mime_http[strlen(mime_http)],
653 (sizeof(mime_http) - strlen(mime_http) - 1),
654 "<IMG SRC=\"/mimepart/%ld/%s/%s\">",
655 msgnum, mime_partnum, mime_filename);
657 else if ( (!strcasecmp(mime_disposition, "attachment"))
658 || (!strcasecmp(mime_disposition, "inline")) ) {
659 snprintf(&mime_http[strlen(mime_http)],
660 (sizeof(mime_http) - strlen(mime_http) - 1),
661 "<A HREF=\"/mimepart/%ld/%s/%s\" "
662 "TARGET=\"wc.%ld.%s\">"
663 "<IMG SRC=\"/static/diskette_24x.gif\" "
664 "BORDER=0 ALIGN=MIDDLE>\n"
665 "Part %s: %s (%s, %d bytes)</A><br />\n",
666 msgnum, mime_partnum, mime_filename,
667 msgnum, mime_partnum,
668 mime_partnum, mime_filename,
669 mime_content_type, mime_length);
672 /*** begin handler prep ***/
673 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
674 strcpy(vcard_partnum, mime_partnum);
677 if (!strcasecmp(mime_content_type, "text/calendar")) {
678 strcpy(cal_partnum, mime_partnum);
681 /*** end handler prep ***/
687 /* Generate a reply-to address */
688 if (strlen(rfca) > 0) {
689 strcpy(reply_to, rfca);
692 if ( (strlen(node) > 0)
693 && (strcasecmp(node, serv_info.serv_nodename))
694 && (strcasecmp(node, serv_info.serv_humannode)) ) {
695 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
699 snprintf(reply_to, sizeof(reply_to), "%s", from);
709 utf8ify_rfc822_string(m_cc);
710 utf8ify_rfc822_string(m_subject);
712 if (strlen(m_cc) > 0) {
714 "<SPAN CLASS=\"message_subject\">");
720 if (strlen(m_subject) > 0) {
722 "<SPAN CLASS=\"message_subject\">");
723 wprintf(_("Subject:"));
730 /* start msg buttons */
731 if (!printable_view) {
732 wprintf("<td align=right>\n");
735 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
736 wprintf("<a href=\"/display_enter");
737 if (WC->is_mailbox) {
738 wprintf("?replyquote=%ld", msgnum);
741 urlescputs(reply_to);
742 wprintf("?subject=");
743 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
744 urlescputs(m_subject);
745 wprintf("\">[%s]</a> ", _("Reply"));
749 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
750 if (!WC->is_mailbox) {
751 wprintf("<a href=\"/display_enter");
752 wprintf("?replyquote=%ld", msgnum);
754 urlescputs(reply_to);
755 wprintf("?subject=");
756 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
757 urlescputs(m_subject);
758 wprintf("\">[%s]</a> ", _("ReplyQuoted"));
763 if (WC->wc_view == VIEW_MAILBOX) {
764 wprintf("<a href=\"/display_enter");
765 wprintf("?replyquote=%ld", msgnum);
767 urlescputs(reply_to);
769 urlescputs(reply_all);
770 wprintf("?subject=");
771 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
772 urlescputs(m_subject);
773 wprintf("\">[%s]</a> ", _("ReplyAll"));
777 if (WC->wc_view == VIEW_MAILBOX) {
778 wprintf("<a href=\"/display_enter?fwdquote=%ld?subject=", msgnum);
779 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
780 urlescputs(m_subject);
781 wprintf("\">[%s]</a> ", _("Forward"));
784 /* If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
785 if ( (WC->is_room_aide) || (WC->is_mailbox) ) {
787 wprintf("<a href=\"/confirm_move_msg?msgid=%ld\">[%s]</a> ",
791 wprintf("<a href=\"/delete_msg?msgid=%ld\" "
792 "onClick=\"return confirm('%s');\">"
793 "[%s]</a> ", msgnum, _("Delete this message?"), _("Delete")
797 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'); \" >"
798 "[%s]</a>", msgnum, msgnum, _("Print"));
803 wprintf("</TR></TABLE>\n");
806 wprintf("<TABLE BORDER=0 WIDTH=100%% BGCOLOR=#FFFFFF "
807 "CELLPADDING=1 CELLSPACING=0><TR><TD>");
810 * Learn the content type
812 strcpy(mime_content_type, "text/plain");
813 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
814 if (!strcmp(buf, "000")) {
816 wprintf(_("unexpected end of message"));
817 wprintf("</I><br /><br />\n");
820 if (!strncasecmp(buf, "Content-type: ", 14)) {
821 safestrncpy(mime_content_type, &buf[14],
822 sizeof(mime_content_type));
823 for (i=0; i<strlen(mime_content_type); ++i) {
824 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
825 safestrncpy(mime_charset, &mime_content_type[i+8],
826 sizeof mime_charset);
829 for (i=0; i<strlen(mime_content_type); ++i) {
830 if (mime_content_type[i] == ';') {
831 mime_content_type[i] = 0;
837 /* Set up a character set conversion if we need to (and if we can) */
839 if ( (strcasecmp(mime_charset, "us-ascii"))
840 && (strcasecmp(mime_charset, "UTF-8")) ) {
841 ic = iconv_open("UTF-8", mime_charset);
842 if (ic == (iconv_t)(-1) ) {
843 lprintf(5, "iconv_open() failed: %s\n", strerror(errno));
848 /* Messages in legacy Citadel variformat get handled thusly... */
849 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
853 /* Boring old 80-column fixed format text gets handled this way... */
854 else if ( (!strcasecmp(mime_content_type, "text/plain"))
855 || (!strcasecmp(mime_content_type, "text")) ) {
856 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
857 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
858 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
861 if (ic != (iconv_t)(-1) ) {
863 ibuflen = strlen(ibuf);
865 obuf = (char *) malloc(obuflen);
867 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
868 osav[SIZ-obuflen] = 0;
869 safestrncpy(buf, osav, sizeof buf);
874 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
875 buf[strlen(buf) - 1] = 0;
877 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
878 wprintf("<BLOCKQUOTE>");
880 } else if ((bq == 1) &&
881 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
882 wprintf("</BLOCKQUOTE>");
888 wprintf("</TT><br />\n");
890 wprintf("</I><br />");
893 else /* HTML is fun, but we've got to strip it first */
894 if (!strcasecmp(mime_content_type, "text/html")) {
895 output_html(mime_charset);
898 /* Unknown weirdness */
900 wprintf(_("I don't know how to display %s"), mime_content_type);
901 wprintf("<br />\n", mime_content_type);
902 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
905 /* Afterwards, offer links to download attachments 'n' such */
906 if (strlen(mime_http) > 0) {
907 wprintf("%s", mime_http);
910 /* Handler for vCard parts */
911 if (strlen(vcard_partnum) > 0) {
912 part_source = load_mimepart(msgnum, vcard_partnum);
913 if (part_source != NULL) {
915 /* If it's my vCard I can edit it */
916 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
917 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
918 || (WC->wc_view == VIEW_ADDRESSBOOK)
920 wprintf("<A HREF=\"/edit_vcard?"
921 "msgnum=%ld?partnum=%s\">",
922 msgnum, vcard_partnum);
923 wprintf("[%s]</A>", _("edit"));
926 /* In all cases, display the full card */
927 display_vcard(part_source, 0, 1, NULL);
931 /* Handler for calendar parts */
932 if (strlen(cal_partnum) > 0) {
933 part_source = load_mimepart(msgnum, cal_partnum);
934 if (part_source != NULL) {
935 cal_process_attachment(part_source,
936 msgnum, cal_partnum);
946 wprintf("</TD></TR></TABLE>\n");
948 /* end everythingamundo table */
949 if (!printable_view) {
950 wprintf("</TD></TR></TABLE>\n");
951 wprintf("</div><br />\n");
955 if (ic != (iconv_t)(-1) ) {
964 * Unadorned HTML output of an individual message, suitable
965 * for placing in a hidden iframe, for printing, or whatever
967 void embed_message(void) {
970 msgnum = atol(bstr("msgnum"));
971 begin_ajax_response();
972 read_message(msgnum, 0);
978 * Printable view of a message
980 void print_message(void) {
983 msgnum = atol(bstr("msgnum"));
984 output_headers(0, 0, 0, 0, 0, 0);
986 wprintf("Content-type: text/html\r\n"
988 "Connection: close\r\n",
992 wprintf("\r\n\r\n<html>\n"
993 "<head><title>Printable view</title></head>\n"
994 "<body onLoad=\" window.print(); window.close(); \">\n"
997 read_message(msgnum, 1);
999 wprintf("\n</body></html>\n\n");
1006 * Read message in simple, JavaScript-embeddable form for 'forward'
1007 * or 'reply quoted' operations.
1009 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1010 * in this function. Doing so would throw a JavaScript error in the
1011 * 'supplied text' argument to the editor.
1013 void pullquote_message(long msgnum, int forward_attachments) {
1015 char mime_partnum[256];
1016 char mime_filename[256];
1017 char mime_content_type[256];
1018 char mime_charset[256];
1019 char mime_disposition[256];
1021 char mime_http[SIZ];
1022 char *attachments = NULL;
1023 int num_attachments = 0;
1024 struct wc_attachment *att, *aptr;
1025 char m_subject[256];
1031 int format_type = 0;
1036 iconv_t ic = (iconv_t)(-1) ;
1037 char *ibuf; /* Buffer of characters to be converted */
1038 char *obuf; /* Buffer for converted characters */
1039 size_t ibuflen; /* Length of input buffer */
1040 size_t obuflen; /* Length of output buffer */
1041 char *osav; /* Saved pointer to output buffer */
1047 strcpy(reply_to, "");
1048 strcpy(mime_http, "");
1049 strcpy(mime_content_type, "text/plain");
1050 strcpy(mime_charset, "us-ascii");
1052 serv_printf("MSG4 %ld", msgnum);
1053 serv_getln(buf, sizeof buf);
1054 if (buf[0] != '1') {
1055 wprintf(_("ERROR:"));
1056 wprintf("%s<br />", &buf[4]);
1060 strcpy(m_subject, "");
1062 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1063 if (!strcmp(buf, "000")) {
1064 wprintf(_("unexpected end of message"));
1067 if (!strncasecmp(buf, "nhdr=yes", 8))
1071 if (!strncasecmp(buf, "type=", 5))
1072 format_type = atoi(&buf[5]);
1073 if (!strncasecmp(buf, "from=", 5)) {
1074 strcpy(from, &buf[5]);
1075 wprintf(_("from "));
1077 utf8ify_rfc822_string(from);
1081 if (!strncasecmp(buf, "subj=", 5)) {
1082 strcpy(m_subject, &buf[5]);
1084 if ((!strncasecmp(buf, "hnod=", 5))
1085 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1086 wprintf("(%s) ", &buf[5]);
1088 if ((!strncasecmp(buf, "room=", 5))
1089 && (strcasecmp(&buf[5], WC->wc_roomname))
1090 && (strlen(&buf[5])>0) ) {
1092 wprintf("%s> ", &buf[5]);
1094 if (!strncasecmp(buf, "rfca=", 5)) {
1095 strcpy(rfca, &buf[5]);
1101 if (!strncasecmp(buf, "node=", 5)) {
1102 strcpy(node, &buf[5]);
1103 if ( ((WC->room_flags & QR_NETWORK)
1104 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1105 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1106 && (strlen(rfca)==0)
1108 wprintf("@%s ", &buf[5]);
1111 if (!strncasecmp(buf, "rcpt=", 5)) {
1113 wprintf("%s ", &buf[5]);
1115 if (!strncasecmp(buf, "time=", 5)) {
1116 fmt_date(now, atol(&buf[5]), 0);
1117 wprintf("%s ", now);
1121 * Save attachment info for later. We can't start downloading them
1122 * yet because we're in the middle of a server transaction.
1124 if (!strncasecmp(buf, "part=", 5)) {
1126 attachments = realloc(attachments, (num_attachments * 1024));
1127 strcat(attachments, &buf[5]);
1128 strcat(attachments, "\n");
1136 utf8ify_rfc822_string(m_subject);
1138 if (strlen(m_subject) > 0) {
1139 wprintf(_("Subject:"));
1141 msgescputs(m_subject);
1151 * Learn the content type
1153 strcpy(mime_content_type, "text/plain");
1154 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1155 if (!strcmp(buf, "000")) {
1156 wprintf(_("unexpected end of message"));
1159 if (!strncasecmp(buf, "Content-type: ", 14)) {
1160 safestrncpy(mime_content_type, &buf[14],
1161 sizeof(mime_content_type));
1162 for (i=0; i<strlen(mime_content_type); ++i) {
1163 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1164 safestrncpy(mime_charset, &mime_content_type[i+8],
1165 sizeof mime_charset);
1168 for (i=0; i<strlen(mime_content_type); ++i) {
1169 if (mime_content_type[i] == ';') {
1170 mime_content_type[i] = 0;
1176 /* Set up a character set conversion if we need to (and if we can) */
1178 if ( (strcasecmp(mime_charset, "us-ascii"))
1179 && (strcasecmp(mime_charset, "UTF-8")) ) {
1180 ic = iconv_open("UTF-8", mime_charset);
1181 if (ic == (iconv_t)(-1) ) {
1182 lprintf(5, "iconv_open() failed: %s\n", strerror(errno));
1187 /* Messages in legacy Citadel variformat get handled thusly... */
1188 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1192 /* Boring old 80-column fixed format text gets handled this way... */
1193 else if (!strcasecmp(mime_content_type, "text/plain")) {
1194 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1195 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1196 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1199 if (ic != (iconv_t)(-1) ) {
1201 ibuflen = strlen(ibuf);
1203 obuf = (char *) malloc(obuflen);
1205 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1206 osav[SIZ-obuflen] = 0;
1207 safestrncpy(buf, osav, sizeof buf);
1212 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1213 buf[strlen(buf) - 1] = 0;
1215 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
1216 wprintf("<BLOCKQUOTE>");
1218 } else if ((bq == 1) &&
1219 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
1220 wprintf("</BLOCKQUOTE>");
1226 wprintf("</TT><br />");
1228 wprintf("</I><br />");
1231 /* HTML just gets escaped and stuffed back into the editor */
1232 else if (!strcasecmp(mime_content_type, "text/html")) {
1233 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1238 /* Unknown weirdness ... don't know how to handle this content type */
1240 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1244 /* end of body handler */
1247 * If there were attachments, we have to download them and insert them
1248 * into the attachment chain for the forwarded message we are composing.
1250 if ( (forward_attachments) && (num_attachments) ) {
1251 for (i=0; i<num_attachments; ++i) {
1252 extract_token(buf, attachments, i, '\n', sizeof buf);
1253 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1254 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1255 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1256 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1257 mime_length = extract_int(buf, 5);
1260 * tracing ... uncomment if necessary
1262 lprintf(9, "fwd filename: %s\n", mime_filename);
1263 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1264 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1265 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1266 lprintf(9, "fwd length : %d\n", mime_length);
1269 if ( (!strcasecmp(mime_disposition, "inline"))
1270 || (!strcasecmp(mime_disposition, "attachment")) ) {
1272 /* Create an attachment struct from this mime part... */
1273 att = malloc(sizeof(struct wc_attachment));
1274 memset(att, 0, sizeof(struct wc_attachment));
1275 att->length = mime_length;
1276 strcpy(att->content_type, mime_content_type);
1277 strcpy(att->filename, mime_filename);
1279 att->data = load_mimepart(msgnum, mime_partnum);
1281 /* And add it to the list. */
1282 if (WC->first_attachment == NULL) {
1283 WC->first_attachment = att;
1286 aptr = WC->first_attachment;
1287 while (aptr->next != NULL) aptr = aptr->next;
1297 if (ic != (iconv_t)(-1) ) {
1308 void display_summarized(int num) {
1311 wprintf("<tr bgcolor=\"#%s\" ",
1312 ((num % 2) ? "DDDDDD" : "FFFFFF")
1317 wprintf("onClick=\" new Ajax.Updater('preview_pane', '/msg', { method: 'get', parameters: 'msgnum=%ld' } ); \" ", WC->summ[num].msgnum);
1321 if (WC->summ[num].is_new) wprintf("<B>");
1322 escputs(WC->summ[num].subj);
1323 if (WC->summ[num].is_new) wprintf("</B>");
1324 wprintf("</TD><TD>");
1325 if (WC->summ[num].is_new) wprintf("<B>");
1326 escputs(WC->summ[num].from);
1327 if (WC->summ[num].is_new) wprintf("</B>");
1328 wprintf(" </TD><TD>");
1329 if (WC->summ[num].is_new) wprintf("<B>");
1330 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1332 if (WC->summ[num].is_new) wprintf("</B>");
1335 "<INPUT TYPE=\"checkbox\" NAME=\"msg_%ld\" VALUE=\"yes\">"
1337 WC->summ[num].msgnum
1347 void display_addressbook(long msgnum, char alpha) {
1349 char mime_partnum[SIZ];
1350 char mime_filename[SIZ];
1351 char mime_content_type[SIZ];
1352 char mime_disposition[SIZ];
1354 char vcard_partnum[SIZ];
1355 char *vcard_source = NULL;
1356 struct message_summary summ;
1358 memset(&summ, 0, sizeof(summ));
1359 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1361 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1363 serv_getln(buf, sizeof buf);
1364 if (buf[0] != '1') return;
1366 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1367 if (!strncasecmp(buf, "part=", 5)) {
1368 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1369 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1370 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1371 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1372 mime_length = extract_int(&buf[5], 5);
1374 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1375 strcpy(vcard_partnum, mime_partnum);
1381 if (strlen(vcard_partnum) > 0) {
1382 vcard_source = load_mimepart(msgnum, vcard_partnum);
1383 if (vcard_source != NULL) {
1385 /* Display the summary line */
1386 display_vcard(vcard_source, alpha, 0, NULL);
1388 /* If it's my vCard I can edit it */
1389 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1390 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1391 || (WC->wc_view == VIEW_ADDRESSBOOK)
1393 wprintf("<A HREF=\"/edit_vcard?"
1394 "msgnum=%ld?partnum=%s\">",
1395 msgnum, vcard_partnum);
1396 wprintf("[%s]</A>", _("edit"));
1407 /* If it's an old "Firstname Lastname" style record, try to
1410 void lastfirst_firstlast(char *namebuf) {
1411 char firstname[SIZ];
1415 if (namebuf == NULL) return;
1416 if (strchr(namebuf, ';') != NULL) return;
1418 i = num_tokens(namebuf, ' ');
1421 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1422 remove_token(namebuf, i-1, ' ');
1423 strcpy(firstname, namebuf);
1424 sprintf(namebuf, "%s; %s", lastname, firstname);
1428 void fetch_ab_name(long msgnum, char *namebuf) {
1430 char mime_partnum[SIZ];
1431 char mime_filename[SIZ];
1432 char mime_content_type[SIZ];
1433 char mime_disposition[SIZ];
1435 char vcard_partnum[SIZ];
1436 char *vcard_source = NULL;
1438 struct message_summary summ;
1440 if (namebuf == NULL) return;
1441 strcpy(namebuf, "");
1443 memset(&summ, 0, sizeof(summ));
1444 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1446 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1448 serv_getln(buf, sizeof buf);
1449 if (buf[0] != '1') return;
1451 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1452 if (!strncasecmp(buf, "part=", 5)) {
1453 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1454 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1455 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1456 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1457 mime_length = extract_int(&buf[5], 5);
1459 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1460 strcpy(vcard_partnum, mime_partnum);
1466 if (strlen(vcard_partnum) > 0) {
1467 vcard_source = load_mimepart(msgnum, vcard_partnum);
1468 if (vcard_source != NULL) {
1470 /* Grab the name off the card */
1471 display_vcard(vcard_source, 0, 0, namebuf);
1477 lastfirst_firstlast(namebuf);
1479 for (i=0; i<strlen(namebuf); ++i) {
1480 if (namebuf[i] != ';') return;
1482 strcpy(namebuf, _("(no name)"));
1488 * Record compare function for sorting address book indices
1490 int abcmp(const void *ab1, const void *ab2) {
1492 (((const struct addrbookent *)ab1)->ab_name),
1493 (((const struct addrbookent *)ab2)->ab_name)
1499 * Helper function for do_addrbook_view()
1500 * Converts a name into a three-letter tab label
1502 void nametab(char *tabbuf, char *name) {
1503 stresc(tabbuf, name, 0, 0);
1504 tabbuf[0] = toupper(tabbuf[0]);
1505 tabbuf[1] = tolower(tabbuf[1]);
1506 tabbuf[2] = tolower(tabbuf[2]);
1512 * Render the address book using info we gathered during the scan
1514 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1518 static int NAMESPERPAGE = 60;
1522 char tabfirst_label[SIZ];
1524 char tablast_label[SIZ];
1527 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1528 wprintf(_("This address book is empty."));
1529 wprintf("</i></div>\n");
1534 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1537 num_pages = num_ab / NAMESPERPAGE;
1539 page = atoi(bstr("page"));
1542 for (i=0; i<=num_pages; ++i) {
1544 wprintf("<A HREF=\"/readfwd?page=%d\">", i);
1549 tabfirst = i * NAMESPERPAGE;
1550 tablast = tabfirst + NAMESPERPAGE - 1;
1551 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1552 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1553 nametab(tablast_label, addrbook[tablast].ab_name);
1554 wprintf("[%s - %s]",
1555 tabfirst_label, tablast_label
1564 wprintf("<br />\n");
1566 wprintf("<TABLE border=0 cellspacing=0 "
1567 "cellpadding=3 width=100%%>\n"
1570 for (i=0; i<num_ab; ++i) {
1572 if ((i / NAMESPERPAGE) == page) {
1574 if ((displayed % 4) == 0) {
1575 if (displayed > 0) {
1579 wprintf("<TR BGCOLOR=\"#%s\">",
1580 (bg ? "DDDDDD" : "FFFFFF")
1586 wprintf("<A HREF=\"/readfwd?startmsg=%ld&is_singlecard=1",
1587 addrbook[i].ab_msgnum);
1588 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1589 vcard_n_prettyize(addrbook[i].ab_name);
1590 escputs(addrbook[i].ab_name);
1591 wprintf("</A></TD>\n");
1596 wprintf("</TR></TABLE>\n");
1602 * load message pointers from the server
1604 int load_msg_ptrs(char *servcmd, int with_headers)
1608 char displayname[128];
1615 int num_summ_alloc = 0;
1618 if (WC->num_summ != 0) {
1623 num_summ_alloc = 100;
1625 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1628 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1630 serv_getln(buf, sizeof buf);
1631 if (buf[0] != '1') {
1632 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1635 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1636 if (nummsgs < maxload) {
1637 WC->msgarr[nummsgs] = extract_long(buf, 0);
1638 datestamp = extract_long(buf, 1);
1639 extract_token(displayname, buf, 2, '|', sizeof displayname);
1640 extract_token(nodename, buf, 3, '|', sizeof nodename);
1641 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1642 extract_token(subject, buf, 5, '|', sizeof subject);
1646 if (nummsgs > num_summ_alloc) {
1647 num_summ_alloc *= 2;
1648 WC->summ = realloc(WC->summ, num_summ_alloc * sizeof(struct message_summary));
1652 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1653 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1654 safestrncpy(WC->summ[nummsgs-1].subj, _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1655 if (strlen(displayname) > 0) {
1656 safestrncpy(WC->summ[nummsgs-1].from, displayname, sizeof WC->summ[nummsgs-1].from);
1658 if (strlen(subject) > 0) {
1659 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1660 sizeof WC->summ[nummsgs-1].subj);
1663 /* Handle subjects with RFC2047 encoding */
1664 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1666 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1667 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1670 if (strlen(nodename) > 0) {
1671 if ( ((WC->room_flags & QR_NETWORK)
1672 || ((strcasecmp(nodename, serv_info.serv_nodename)
1673 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1675 strcat(WC->summ[nummsgs-1].from, " @ ");
1676 strcat(WC->summ[nummsgs-1].from, nodename);
1680 WC->summ[nummsgs-1].date = datestamp;
1683 /* Handle senders with RFC2047 encoding */
1684 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1686 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1687 strcpy(&WC->summ[nummsgs-1].from[22], "...");
1696 int summcmp_subj(const void *s1, const void *s2) {
1697 struct message_summary *summ1;
1698 struct message_summary *summ2;
1700 summ1 = (struct message_summary *)s1;
1701 summ2 = (struct message_summary *)s2;
1702 return strcasecmp(summ1->subj, summ2->subj);
1705 int summcmp_rsubj(const void *s1, const void *s2) {
1706 struct message_summary *summ1;
1707 struct message_summary *summ2;
1709 summ1 = (struct message_summary *)s1;
1710 summ2 = (struct message_summary *)s2;
1711 return strcasecmp(summ2->subj, summ1->subj);
1714 int summcmp_sender(const void *s1, const void *s2) {
1715 struct message_summary *summ1;
1716 struct message_summary *summ2;
1718 summ1 = (struct message_summary *)s1;
1719 summ2 = (struct message_summary *)s2;
1720 return strcasecmp(summ1->from, summ2->from);
1723 int summcmp_rsender(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(summ2->from, summ1->from);
1732 int summcmp_date(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;
1739 if (summ1->date < summ2->date) return -1;
1740 else if (summ1->date > summ2->date) return +1;
1744 int summcmp_rdate(const void *s1, const void *s2) {
1745 struct message_summary *summ1;
1746 struct message_summary *summ2;
1748 summ1 = (struct message_summary *)s1;
1749 summ2 = (struct message_summary *)s2;
1751 if (summ1->date < summ2->date) return +1;
1752 else if (summ1->date > summ2->date) return -1;
1757 * command loop for reading messages
1759 void readloop(char *oper)
1768 int num_displayed = 0;
1770 int is_addressbook = 0;
1771 int is_singlecard = 0;
1772 int is_calendar = 0;
1775 int remaining_messages;
1777 int lowest_displayed = (-1);
1778 int highest_displayed = 0;
1779 long pn_previous = 0L;
1780 long pn_current = 0L;
1782 struct addrbookent *addrbook = NULL;
1784 char *sortby = NULL;
1785 char sortpref_name[128];
1786 char sortpref_value[128];
1787 char *subjsort_button;
1788 char *sendsort_button;
1789 char *datesort_button;
1791 startmsg = atol(bstr("startmsg"));
1792 maxmsgs = atoi(bstr("maxmsgs"));
1793 is_summary = atoi(bstr("summary"));
1794 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1796 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
1797 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
1799 sortby = bstr("sortby");
1800 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
1801 set_preference(sortpref_name, sortby, 1);
1803 if (strlen(sortby) == 0) sortby = sortpref_value;
1804 if (strlen(sortby) == 0) sortby = "msgid";
1806 output_headers(1, 1, 1, 0, 0, 0);
1808 /* When in summary mode, always show ALL messages instead of just
1809 * new or old. Otherwise, show what the user asked for.
1811 if (!strcmp(oper, "readnew")) {
1812 strcpy(cmd, "MSGS NEW");
1814 else if (!strcmp(oper, "readold")) {
1815 strcpy(cmd, "MSGS OLD");
1818 strcpy(cmd, "MSGS ALL");
1821 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
1823 strcpy(cmd, "MSGS ALL");
1826 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
1828 strcpy(cmd, "MSGS ALL");
1833 strcpy(cmd, "MSGS ALL|||1"); /* fetch header summary */
1838 /* Are we doing a summary view? If so, we need to know old messages
1839 * and new messages, so we can do that pretty boldface thing for the
1842 strcpy(old_msgs, "");
1845 serv_getln(buf, sizeof buf);
1846 if (buf[0] == '2') {
1847 strcpy(old_msgs, &buf[4]);
1851 is_singlecard = atoi(bstr("is_singlecard"));
1853 if (WC->wc_view == VIEW_CALENDAR) { /* calendar */
1855 strcpy(cmd, "MSGS ALL");
1858 if (WC->wc_view == VIEW_TASKS) { /* tasks */
1860 strcpy(cmd, "MSGS ALL");
1863 if (WC->wc_view == VIEW_NOTES) { /* notes */
1865 strcpy(cmd, "MSGS ALL");
1869 nummsgs = load_msg_ptrs(cmd, is_summary);
1872 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
1874 if (!strcmp(oper, "readnew")) {
1875 wprintf(_("No new messages."));
1876 } else if (!strcmp(oper, "readold")) {
1877 wprintf(_("No old messages."));
1879 wprintf(_("No messages here."));
1888 for (a = 0; a < nummsgs; ++a) {
1889 /* Are you a new message, or an old message? */
1891 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
1892 WC->summ[a].is_new = 0;
1895 WC->summ[a].is_new = 1;
1901 if (startmsg == 0L) startmsg = WC->msgarr[0];
1902 remaining_messages = 0;
1904 for (a = 0; a < nummsgs; ++a) {
1905 if (WC->msgarr[a] >= startmsg) {
1906 ++remaining_messages;
1911 if (!strcasecmp(sortby, "subject")) {
1912 qsort(WC->summ, WC->num_summ,
1913 sizeof(struct message_summary), summcmp_subj);
1915 else if (!strcasecmp(sortby, "rsubject")) {
1916 qsort(WC->summ, WC->num_summ,
1917 sizeof(struct message_summary), summcmp_rsubj);
1919 else if (!strcasecmp(sortby, "sender")) {
1920 qsort(WC->summ, WC->num_summ,
1921 sizeof(struct message_summary), summcmp_sender);
1923 else if (!strcasecmp(sortby, "rsender")) {
1924 qsort(WC->summ, WC->num_summ,
1925 sizeof(struct message_summary), summcmp_rsender);
1927 else if (!strcasecmp(sortby, "date")) {
1928 qsort(WC->summ, WC->num_summ,
1929 sizeof(struct message_summary), summcmp_date);
1931 else if (!strcasecmp(sortby, "rdate")) {
1932 qsort(WC->summ, WC->num_summ,
1933 sizeof(struct message_summary), summcmp_rdate);
1937 if (!strcasecmp(sortby, "subject")) {
1938 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1940 else if (!strcasecmp(sortby, "rsubject")) {
1941 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1944 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1947 if (!strcasecmp(sortby, "sender")) {
1948 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1950 else if (!strcasecmp(sortby, "rsender")) {
1951 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1954 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1957 if (!strcasecmp(sortby, "date")) {
1958 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1960 else if (!strcasecmp(sortby, "rdate")) {
1961 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1964 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1968 wprintf("</div>"); /* end of 'content' div */
1970 wprintf("<div id=\"message_list\">"
1972 "<div id=\"fix_scrollbar_bug\">\n"
1974 "<form name=\"msgomatic\" "
1975 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n"
1977 "<span class=\"mailbox_summary\">"
1978 "<table border=0 cellspacing=0 "
1979 "cellpadding=0 width=100%%>\n"
1981 "<TD align=center><b><i>%s</i></b> %s</TD>"
1982 "<TD align=center><b><i>%s</i></b> %s</TD>"
1983 "<TD align=center><b><i>%s</i></b> %s</TD>"
1984 "<TD><INPUT TYPE=\"submit\" NAME=\"delete_button\" "
1985 "STYLE=\"font-family: Bitstream Vera Sans,Arial,Helvetica,sans-serif;"
1986 " font-size: 6pt;\" "
1987 "VALUE=\"%s\"></TD>"
1990 _("Subject"), subjsort_button,
1991 _("Sender"), sendsort_button,
1992 _("Date"), datesort_button,
1997 for (a = 0; a < nummsgs; ++a) {
1998 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2000 /* Learn which msgs "Prev" & "Next" buttons go to */
2001 pn_current = WC->msgarr[a];
2002 if (a > 0) pn_previous = WC->msgarr[a-1];
2003 if (a < (nummsgs-1)) pn_next = WC->msgarr[a+1];
2005 /* Display the message */
2007 display_summarized(a);
2009 else if (is_addressbook) {
2010 fetch_ab_name(WC->msgarr[a], buf);
2012 addrbook = realloc(addrbook,
2013 (sizeof(struct addrbookent) * num_ab) );
2014 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2015 sizeof(addrbook[num_ab-1].ab_name));
2016 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
2018 else if (is_calendar) {
2019 display_calendar(WC->msgarr[a]);
2021 else if (is_tasks) {
2022 display_task(WC->msgarr[a]);
2024 else if (is_notes) {
2025 display_note(WC->msgarr[a]);
2028 read_message(WC->msgarr[a], 0);
2031 if (lowest_displayed < 0) lowest_displayed = a;
2032 highest_displayed = a;
2035 --remaining_messages;
2040 wprintf("</table></span></form>"
2041 "</div>\n"); /* end of 'fix_scrollbar_bug' div */
2042 wprintf("</div>"); /* end of 'message_list' div */
2044 wprintf("<div id=\"ml_slider\"></div>"); /* slider */
2046 wprintf("<div id=\"preview_pane\">"); /* The preview pane will initially be empty */
2049 /* Bump these because although we're thinking in zero base, the user
2050 * is a drooling idiot and is thinking in one base.
2053 ++highest_displayed;
2055 /* If we're only looking at one message, do a prev/next thing */
2056 if (num_displayed == 1) {
2057 if ((!is_tasks) && (!is_calendar) && (!is_addressbook) && (!is_notes) && (!is_singlecard)) {
2059 wprintf("<div id=\"fix_scrollbar_bug\">"
2060 "<table border=0 width=100%% bgcolor=\"#dddddd\"><tr><td>");
2061 wprintf(_("Reading #%d of %d messages."), lowest_displayed, nummsgs);
2062 wprintf("</TD><TD ALIGN=RIGHT><FONT SIZE=+1>");
2064 if (pn_previous > 0L) {
2065 wprintf("<A HREF=\"/%s"
2076 wprintf("<A HREF=\"/%s"
2086 wprintf("<A HREF=\"/%s?startmsg=%ld"
2087 "?maxmsgs=%d?summary=1\">"
2096 wprintf("</td></tr></table></div>\n");
2101 * If we're not currently looking at ALL requested
2102 * messages, then display the selector bar
2104 if (num_displayed > 1) {
2105 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2106 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2108 wprintf("<form name=\"msgomatic\" "
2109 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n");
2111 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2113 wprintf("<select name=\"whichones\" size=\"1\" "
2114 "OnChange=\"location.href=msgomatic.whichones.options"
2115 "[selectedIndex].value\">\n");
2117 for (b=0; b<nummsgs; b = b + maxmsgs) {
2120 if (hi > nummsgs) hi = nummsgs;
2121 wprintf("<option %s value="
2126 "%d-%d</option> \n",
2127 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2134 wprintf("<option value=\"/%s?startmsg=%ld"
2135 "?maxmsgs=9999999?summary=%d\">"
2139 WC->msgarr[0], is_summary);
2141 wprintf("</select> ");
2142 wprintf(_("of %d messages."), nummsgs);
2143 wprintf("</form>\n");
2149 do_tasks_view(); /* Render the task list */
2153 do_calendar_view(); /* Render the calendar */
2156 if (is_addressbook) {
2157 do_addrbook_view(addrbook, num_ab); /* Render the address book */
2160 /* Put the data transfer hidden iframe in a hidden div, to make it *really* hidden */
2162 "<div display=\"hidden\">\n"
2163 "<iframe name=\"msgloader1\" id=\"msgloader1\" width=\"1\"></iframe>\n"
2166 /* Note: wDumpContent() will output one additional </div> tag. */
2168 if (addrbook != NULL) free(addrbook);
2170 /* free the summary */
2171 if (WC->num_summ != 0) {
2176 /* If we got here via a mailbox view and are reading a single
2177 * message, mark it as "seen." We do this after rendering the web page
2178 * so it doesn't keep the user waiting.
2180 if ( (maxmsgs == 1) && (WC->wc_view == VIEW_MAILBOX) ) {
2181 serv_printf("SEEN %ld|1", startmsg);
2182 serv_getln(buf, sizeof buf);
2188 * Back end for post_message() ... this is where the actual message
2189 * gets transmitted to the server.
2191 void post_mime_to_server(void) {
2193 int is_multipart = 0;
2195 struct wc_attachment *att;
2197 size_t encoded_length;
2199 /* RFC2045 requires this, and some clients look for it... */
2200 serv_puts("MIME-Version: 1.0");
2202 /* If there are attachments, we have to do multipart/mixed */
2203 if (WC->first_attachment != NULL) {
2208 sprintf(boundary, "---Citadel-Multipart-%s-%04x%04x---",
2209 serv_info.serv_fqdn,
2214 /* Remember, serv_printf() appends an extra newline */
2215 serv_printf("Content-type: multipart/mixed; "
2216 "boundary=\"%s\"\n", boundary);
2217 serv_printf("This is a multipart message in MIME format.\n");
2218 serv_printf("--%s", boundary);
2221 serv_puts("Content-type: text/html; charset=utf-8");
2223 serv_puts("<HTML><BODY>\n");
2224 text_to_server(bstr("msgtext"), 0);
2225 serv_puts("</BODY></HTML>\n");
2230 /* Add in the attachments */
2231 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2233 encoded_length = ((att->length * 150) / 100);
2234 encoded = malloc(encoded_length);
2235 if (encoded == NULL) break;
2236 CtdlEncodeBase64(encoded, att->data, att->length);
2238 serv_printf("--%s", boundary);
2239 serv_printf("Content-type: %s", att->content_type);
2240 serv_printf("Content-disposition: attachment; "
2241 "filename=\"%s\"", att->filename);
2242 serv_puts("Content-transfer-encoding: base64");
2244 serv_write(encoded, strlen(encoded));
2249 serv_printf("--%s--", boundary);
2257 * Post message (or don't post message)
2259 * Note regarding the "dont_post" variable:
2260 * A random value (actually, it's just a timestamp) is inserted as a hidden
2261 * field called "postseq" when the display_enter page is generated. This
2262 * value is checked when posting, using the static variable dont_post. If a
2263 * user attempts to post twice using the same dont_post value, the message is
2264 * discarded. This prevents the accidental double-saving of the same message
2265 * if the user happens to click the browser "back" button.
2267 void post_message(void)
2270 static long dont_post = (-1L);
2271 struct wc_attachment *att, *aptr;
2273 if (WC->upload_length > 0) {
2275 /* There's an attachment. Save it to this struct... */
2276 att = malloc(sizeof(struct wc_attachment));
2277 memset(att, 0, sizeof(struct wc_attachment));
2278 att->length = WC->upload_length;
2279 strcpy(att->content_type, WC->upload_content_type);
2280 strcpy(att->filename, WC->upload_filename);
2283 /* And add it to the list. */
2284 if (WC->first_attachment == NULL) {
2285 WC->first_attachment = att;
2288 aptr = WC->first_attachment;
2289 while (aptr->next != NULL) aptr = aptr->next;
2293 /* Mozilla sends a simple filename, which is what we want,
2294 * but Satan's Browser sends an entire pathname. Reduce
2295 * the path to just a filename if we need to.
2297 while (num_tokens(att->filename, '/') > 1) {
2298 remove_token(att->filename, 0, '/');
2300 while (num_tokens(att->filename, '\\') > 1) {
2301 remove_token(att->filename, 0, '\\');
2304 /* Transfer control of this memory from the upload struct
2305 * to the attachment struct.
2307 att->data = WC->upload;
2308 WC->upload_length = 0;
2314 if (strlen(bstr("cancel_button")) > 0) {
2315 sprintf(WC->ImportantMessage,
2316 _("Cancelled. Message was not posted."));
2317 } else if (strlen(bstr("attach_button")) > 0) {
2320 } else if (atol(bstr("postseq")) == dont_post) {
2321 sprintf(WC->ImportantMessage,
2322 _("Automatically cancelled because you have already "
2323 "saved this message."));
2325 sprintf(buf, "ENT0 1|%s|0|4|%s|||%s|%s",
2332 serv_getln(buf, sizeof buf);
2333 if (buf[0] == '4') {
2334 post_mime_to_server();
2335 if ( (strlen(bstr("recp")) > 0)
2336 || (strlen(bstr("cc")) > 0)
2337 || (strlen(bstr("bcc")) > 0)
2339 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2342 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2344 dont_post = atol(bstr("postseq"));
2346 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2352 free_attachments(WC);
2353 readloop("readnew");
2360 * display the message entry screen
2362 void display_enter(void)
2367 struct wc_attachment *att;
2368 int recipient_required = 0;
2369 int recipient_bad = 0;
2372 if (strlen(bstr("force_room")) > 0) {
2373 gotoroom(bstr("force_room"));
2376 /* Are we perhaps in an address book view? If so, then an "enter
2377 * message" command really means "add new entry."
2379 if (WC->wc_view == VIEW_ADDRESSBOOK) {
2380 do_edit_vcard(-1, "", "");
2384 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
2385 /* Are we perhaps in a calendar view? If so, then an "enter
2386 * message" command really means "add new calendar item."
2388 if (WC->wc_view == VIEW_CALENDAR) {
2389 display_edit_event();
2393 /* Are we perhaps in a tasks view? If so, then an "enter
2394 * message" command really means "add new task."
2396 if (WC->wc_view == VIEW_TASKS) {
2397 display_edit_task();
2403 * Otherwise proceed normally.
2404 * Do a custom room banner with no navbar...
2406 output_headers(1, 1, 2, 0, 0, 0);
2407 wprintf("<div id=\"banner\">\n");
2408 embed_room_banner(NULL, navbar_none);
2409 wprintf("</div>\n");
2410 wprintf("<div id=\"content\">\n"
2411 "<div id=\"fix_scrollbar_bug\">"
2412 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
2414 /* First test to see whether this is a room that requires recipients to be entered */
2415 serv_puts("ENT0 0");
2416 serv_getln(buf, sizeof buf);
2417 if (!strncmp(buf, "570", 3)) { /* 570 means that we need a recipient here */
2418 recipient_required = 1;
2420 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
2421 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2425 /* Now check our actual recipients if there are any */
2426 if (recipient_required) {
2427 sprintf(buf, "ENT0 0|%s|0|0||||%s|%s", bstr("recp"), bstr("cc"), bstr("bcc"));
2429 serv_getln(buf, sizeof buf);
2431 if (!strncmp(buf, "570", 3)) { /* 570 means we have an invalid recipient listed */
2432 if (strlen(bstr("recp")) + strlen(bstr("cc")) + strlen(bstr("bcc")) > 0) {
2436 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
2437 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2442 /* If we got this far, we can display the message entry screen. */
2445 fmt_date(buf, now, 0);
2446 strcat(&buf[strlen(buf)], _(" <I>from</I> "));
2447 stresc(&buf[strlen(buf)], WC->wc_username, 1, 1);
2449 /* Don't need this anymore, it's in the input box below
2450 if (strlen(bstr("recp")) > 0) {
2451 strcat(&buf[strlen(buf)], _(" <I>to</I> "));
2452 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
2456 strcat(&buf[strlen(buf)], _(" <I>in</I> "));
2457 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
2459 /* begin message entry screen */
2460 wprintf("<form enctype=\"multipart/form-data\" "
2461 "method=\"POST\" action=\"/post\" "
2462 "name=\"enterform\""
2464 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2466 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2467 wprintf("%s<br>\n", buf); /* header bar */
2469 wprintf("<table border=\"0\" width=\"100%%\">\n");
2470 if (recipient_required) {
2472 wprintf("<tr><td>");
2473 wprintf("<font size=-1>");
2477 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
2478 escputs(bstr("recp"));
2479 wprintf("\" size=50 maxlength=1000 />");
2480 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
2481 wprintf("</td><td></td></tr>\n");
2483 wprintf("<tr><td>");
2484 wprintf("<font size=-1>");
2488 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
2489 escputs(bstr("cc"));
2490 wprintf("\" size=50 maxlength=1000 />");
2491 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
2492 wprintf("</td><td></td></tr>\n");
2494 wprintf("<tr><td>");
2495 wprintf("<font size=-1>");
2499 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
2500 escputs(bstr("bcc"));
2501 wprintf("\" size=50 maxlength=1000 />");
2502 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
2503 wprintf("</td><td></td></tr>\n");
2505 /* Initialize the autocomplete ajax helpers (found in wclib.js) */
2506 wprintf("<script type=\"text/javascript\"> \n"
2507 " activate_entmsg_autocompleters(); \n"
2512 wprintf("<tr><td>");
2513 wprintf("<font size=-1>");
2514 wprintf(_("Subject (optional):"));
2517 "<input type=\"text\" name=\"subject\" value=\"");
2518 escputs(bstr("subject"));
2519 wprintf("\" size=50 maxlength=70></td><td>\n");
2521 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2522 if (recipient_required) {
2523 wprintf(_("Send message"));
2525 wprintf(_("Post message"));
2528 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2529 wprintf("</td></tr></table>\n");
2531 wprintf("<center>");
2533 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
2535 /* If we're continuing from a previous edit, put our partially-composed message back... */
2536 msgescputs(bstr("msgtext"));
2538 /* If we're forwarding a message, insert it here... */
2539 if (atol(bstr("fwdquote")) > 0L) {
2540 wprintf("<br><div align=center><i>");
2541 wprintf(_("--- forwarded message ---"));
2542 wprintf("</i></div><br>");
2543 pullquote_message(atol(bstr("fwdquote")), 1);
2546 /* If we're replying quoted, insert the quote here... */
2547 else if (atol(bstr("replyquote")) > 0L) {
2550 pullquote_message(atol(bstr("replyquote")), 0);
2551 wprintf("</blockquote>");
2554 /* Insert our signature if appropriate... */
2555 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
2556 get_preference("use_sig", buf, sizeof buf);
2557 if (!strcasecmp(buf, "yes")) {
2558 get_preference("signature", ebuf, sizeof ebuf);
2559 euid_unescapize(buf, ebuf);
2560 wprintf("<br>--<br>");
2561 for (i=0; i<strlen(buf); ++i) {
2562 if (buf[i] == '\n') {
2565 else if (buf[i] == '<') {
2568 else if (buf[i] == '>') {
2571 else if (buf[i] == '&') {
2574 else if (buf[i] == '\"') {
2577 else if (buf[i] == '\'') {
2580 else if (isprint(buf[i])) {
2581 wprintf("%c", buf[i]);
2587 wprintf("</textarea>");
2588 wprintf("</center><br />\n");
2591 * The following script embeds the TinyMCE richedit control, and automatically
2592 * transforms the textarea into a richedit textarea.
2595 "<script language=\"javascript\" type=\"text/javascript\" src=\"tiny_mce/tiny_mce.js\"></script>\n"
2596 "<script language=\"javascript\" type=\"text/javascript\">"
2598 " mode : \"textareas\", width : \"100%%\", browsers : \"msie,gecko\" "
2603 /* Enumerate any attachments which are already in place... */
2604 wprintf("<img src=\"/static/diskette_24x.gif\" border=0 "
2605 "align=middle height=16 width=16> Attachments: ");
2606 wprintf("<select name=\"which_attachment\" size=1>");
2607 for (att = WC->first_attachment; att != NULL; att = att->next) {
2608 wprintf("<option value=\"");
2609 urlescputs(att->filename);
2611 escputs(att->filename);
2612 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
2613 wprintf("</option>\n");
2615 wprintf("</select>");
2617 /* Now offer the ability to attach additional files... */
2618 wprintf(" "
2619 "Attach file: <input NAME=\"attachfile\" "
2620 "SIZE=16 TYPE=\"file\">\n "
2621 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
2623 /* Seth asked for these to be at the top *and* bottom... */
2624 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2625 if (recipient_required) {
2626 wprintf(_("Send message"));
2628 wprintf(_("Post message"));
2631 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2633 /* Make sure we only insert our signature once */
2634 if (strcmp(bstr("sig_inserted"), "yes")) {
2635 wprintf("<INPUT TYPE=\"hidden\" NAME=\"sig_inserted\" VALUE=\"yes\">\n");
2638 wprintf("</form>\n");
2640 wprintf("</td></tr></table></div>\n");
2641 DONE: wDumpContent(1);
2651 void delete_msg(void)
2656 msgid = atol(bstr("msgid"));
2658 output_headers(1, 1, 1, 0, 0, 0);
2660 sprintf(buf, "DELE %ld", msgid);
2662 serv_getln(buf, sizeof buf);
2663 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2672 * Confirm move of a message
2674 void confirm_move_msg(void)
2680 msgid = atol(bstr("msgid"));
2683 output_headers(1, 1, 2, 0, 0, 0);
2684 wprintf("<div id=\"banner\">\n");
2685 wprintf("<TABLE WIDTH=100%% BORDER=0><TR><TD>");
2686 wprintf("<SPAN CLASS=\"titlebar\">");
2687 wprintf(_("Confirm move of message"));
2688 wprintf("</SPAN>\n");
2689 wprintf("</TD></TR></TABLE>\n");
2690 wprintf("</div>\n<div id=\"content\">\n");
2692 wprintf("<CENTER>");
2694 wprintf(_("Move this message to:"));
2695 wprintf("<br />\n");
2697 wprintf("<form METHOD=\"POST\" ACTION=\"/move_msg\">\n");
2698 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
2700 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
2702 serv_getln(buf, sizeof buf);
2703 if (buf[0] == '1') {
2704 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2705 extract_token(targ, buf, 0, '|', sizeof targ);
2706 wprintf("<OPTION>");
2711 wprintf("</SELECT>\n");
2712 wprintf("<br />\n");
2714 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
2716 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
2717 wprintf("</form></CENTER>\n");
2719 wprintf("</CENTER>\n");
2730 msgid = atol(bstr("msgid"));
2732 if (strlen(bstr("move_button")) > 0) {
2733 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
2735 serv_getln(buf, sizeof buf);
2736 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2738 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
2741 readloop("readnew");
2746 * This gets called when a user selects multiple messages in a summary
2747 * list and then clicks to perform a transformation of some sort on them
2748 * (such as deleting them).
2750 void do_stuff_to_msgs(void) {
2754 struct stuff_t *next;
2758 struct stuff_t *stuff = NULL;
2759 struct stuff_t *ptr;
2760 int delete_button_pressed = 0;
2763 serv_puts("MSGS ALL");
2764 serv_getln(buf, sizeof buf);
2766 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2767 ptr = malloc(sizeof(struct stuff_t));
2768 ptr->msgnum = atol(buf);
2773 if (strlen(bstr("delete_button")) > 0) {
2774 delete_button_pressed = 1;
2777 while (stuff != NULL) {
2779 sprintf(buf, "msg_%ld", stuff->msgnum);
2780 if (!strcasecmp(bstr(buf), "yes")) {
2782 if (delete_button_pressed) {
2783 serv_printf("DELE %ld", stuff->msgnum);
2784 serv_getln(buf, sizeof buf);
2794 readloop("readfwd");