4 * Functions which deal with the fetching and displaying of messages.
10 #include "webserver.h"
13 /* Address book entry (keep it short and sweet, it's just a quickie lookup
14 * which we can use to get to the real meat and bones later)
24 /* Handle subjects with RFC2047 encoding, such as:
25 * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=
27 void utf8ify_rfc822_string(char *buf) {
33 iconv_t ic = (iconv_t)(-1) ;
34 char *ibuf; /* Buffer of characters to be converted */
35 char *obuf; /* Buffer for converted characters */
36 size_t ibuflen; /* Length of input buffer */
37 size_t obuflen; /* Length of output buffer */
38 char *isav; /* Saved pointer to input buffer */
39 char *osav; /* Saved pointer to output buffer */
41 while (start=strstr(buf, "=?"), end=strstr(buf, "?="),
42 ((start != NULL) && (end != NULL) && (end > start)) )
44 extract_token(charset, start, 1, '?', sizeof charset);
45 extract_token(encoding, start, 2, '?', sizeof encoding);
46 extract_token(istr, start, 3, '?', sizeof istr);
54 if (!strcasecmp(encoding, "B")) { /* base64 */
55 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
57 else if (!strcasecmp(encoding, "Q")) { /* quoted-printable */
58 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, strlen(istr));
61 strcpy(ibuf, istr); /* huh? */
62 ibuflen = strlen(istr);
65 ic = iconv_open("UTF-8", charset);
66 if (ic != (iconv_t)(-1) ) {
69 obuf = (char *) malloc(obuflen);
71 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
72 osav[1024-obuflen] = 0;
77 remove_token(end, 0, '?');
78 remove_token(end, 0, '?');
79 remove_token(end, 0, '?');
80 remove_token(end, 0, '?');
83 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
89 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
101 * Look for URL's embedded in a buffer and make them linkable. We use a
102 * target window in order to keep the BBS session in its own window.
118 for (pos = 0; pos < strlen(buf); ++pos) {
119 if (!strncasecmp(&buf[pos], "http://", 7))
121 if (!strncasecmp(&buf[pos], "ftp://", 6))
128 if ((start > 0) && (buf[start - 1] == '<'))
130 if ((start > 0) && (buf[start - 1] == '['))
132 if ((start > 0) && (buf[start - 1] == '('))
134 if ((start > 0) && (buf[start - 1] == '{'))
137 for (pos = strlen(buf); pos > start; --pos) {
138 if ((buf[pos] == ' ') || (buf[pos] == ench))
142 strncpy(urlbuf, &buf[start], end - start);
143 urlbuf[end - start] = 0;
145 strncpy(outbuf, buf, start);
146 sprintf(&outbuf[start], "%cA HREF=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
147 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
148 strcat(outbuf, &buf[end]);
149 if ( strlen(outbuf) < 250 )
155 * Turn a vCard "n" (name) field into something displayable.
157 void vcard_n_prettyize(char *name)
162 original_name = strdup(name);
163 for (i=0; i<5; ++i) {
164 if (strlen(original_name) > 0) {
165 if (original_name[strlen(original_name)-1] == ' ') {
166 original_name[strlen(original_name)-1] = 0;
168 if (original_name[strlen(original_name)-1] == ';') {
169 original_name[strlen(original_name)-1] = 0;
174 for (i=0; i<strlen(original_name); ++i) {
175 if (original_name[i] == ';') {
179 name[strlen(name)+1] = 0;
180 name[strlen(name)] = original_name[i];
189 /* display_vcard() calls this after parsing the textual vCard into
190 * our 'struct vCard' data object.
191 * This gets called instead of display_parsed_vcard() if we are only looking
192 * to extract the person's name instead of displaying the card.
194 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
197 strcpy(storename, "");
199 name = vcard_get_prop(v, "n", 1, 0, 0);
201 strcpy(storename, name);
202 /* vcard_n_prettyize(storename); */
209 /* display_vcard() calls this after parsing the textual vCard into
210 * our 'struct vCard' data object.
212 * Set 'full' to nonzero to display the full card, otherwise it will only
213 * show a summary line.
215 * This code is a bit ugly, so perhaps an explanation is due: we do this
216 * in two passes through the vCard fields. On the first pass, we process
217 * fields we understand, and then render them in a pretty fashion at the
218 * end. Then we make a second pass, outputting all the fields we don't
219 * understand in a simple two-column name/value format.
221 void display_parsed_vcard(struct vCard *v, int full) {
227 char *thisname, *thisvalue;
228 char firsttoken[SIZ];
231 char displayname[SIZ];
237 strcpy(displayname, "");
245 name = vcard_get_prop(v, "fn", 1, 0, 0);
249 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
250 strcpy(displayname, name);
251 vcard_n_prettyize(displayname);
252 escputs(displayname);
261 wprintf("<div align=center><table bgcolor=#aaaaaa width=50%%>");
262 for (pass=1; pass<=2; ++pass) {
264 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
266 thisname = strdup(v->prop[i].name);
267 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
269 for (j=0; j<num_tokens(thisname, ';'); ++j) {
270 extract_token(buf, thisname, j, ';', sizeof buf);
271 if (!strcasecmp(buf, "encoding=quoted-printable")) {
273 remove_token(thisname, j, ';');
275 if (!strcasecmp(buf, "encoding=base64")) {
277 remove_token(thisname, j, ';');
282 thisvalue = malloc(strlen(v->prop[i].value) + 50);
283 j = CtdlDecodeQuotedPrintable(
284 thisvalue, v->prop[i].value,
285 strlen(v->prop[i].value) );
289 thisvalue = malloc(strlen(v->prop[i].value) + 50);
291 thisvalue, v->prop[i].value,
292 strlen(v->prop[i].value) );
295 thisvalue = strdup(v->prop[i].value);
298 /*** Various fields we may encounter ***/
300 /* N is name, but only if there's no FN already there */
301 if (!strcasecmp(firsttoken, "n")) {
302 if (strlen(displayname) == 0) {
303 strcpy(displayname, thisvalue);
304 vcard_n_prettyize(displayname);
308 /* FN (full name) is a true 'display name' field */
309 else if (!strcasecmp(firsttoken, "fn")) {
310 strcpy(displayname, thisvalue);
314 else if (!strcasecmp(firsttoken, "title")) {
315 strcpy(title, thisvalue);
319 else if (!strcasecmp(firsttoken, "org")) {
320 strcpy(org, thisvalue);
323 else if (!strcasecmp(firsttoken, "email")) {
324 if (strlen(mailto) > 0) strcat(mailto, "<br />");
326 "<A HREF=\"/display_enter"
327 "?force_room=_MAIL_?recp=");
329 urlesc(&mailto[strlen(mailto)], displayname);
330 urlesc(&mailto[strlen(mailto)], " <");
331 urlesc(&mailto[strlen(mailto)], thisvalue);
332 urlesc(&mailto[strlen(mailto)], ">");
334 strcat(mailto, "\">");
335 stresc(&mailto[strlen(mailto)], thisvalue, 1, 1);
336 strcat(mailto, "</A>");
338 else if (!strcasecmp(firsttoken, "tel")) {
339 if (strlen(phone) > 0) strcat(phone, "<br />");
340 strcat(phone, thisvalue);
341 for (j=0; j<num_tokens(thisname, ';'); ++j) {
342 extract_token(buf, thisname, j, ';', sizeof buf);
343 if (!strcasecmp(buf, "tel"))
345 else if (!strcasecmp(buf, "work"))
346 strcat(phone, _(" (work)"));
347 else if (!strcasecmp(buf, "home"))
348 strcat(phone, _(" (home)"));
349 else if (!strcasecmp(buf, "cell"))
350 strcat(phone, _(" (cell)"));
358 else if (!strcasecmp(firsttoken, "adr")) {
361 wprintf(_("Address:"));
362 wprintf("</TD><TD>");
363 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
364 extract_token(buf, thisvalue, j, ';', sizeof buf);
365 if (strlen(buf) > 0) {
367 if (j<3) wprintf("<br />");
371 wprintf("</TD></TR>\n");
374 else if (!strcasecmp(firsttoken, "version")) {
377 else if (!strcasecmp(firsttoken, "rev")) {
380 else if (!strcasecmp(firsttoken, "label")) {
385 /*** Don't show extra fields. They're ugly.
389 wprintf("</TD><TD>");
391 wprintf("</TD></TR>\n");
401 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
402 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
403 "<IMG ALIGN=CENTER SRC=\"/static/viewcontacts_48x.gif\">"
404 "<FONT SIZE=+1><B>");
405 escputs(displayname);
406 wprintf("</B></FONT>");
407 if (strlen(title) > 0) {
408 wprintf("<div align=right>");
412 if (strlen(org) > 0) {
413 wprintf("<div align=right>");
417 wprintf("</TD></TR>\n");
419 if (strlen(phone) > 0) {
421 wprintf(_("Telephone:"));
422 wprintf("</td><td>%s</td></tr>\n", phone);
424 if (strlen(mailto) > 0) {
426 wprintf(_("E-mail:"));
427 wprintf("</td><td>%s</td></tr>\n", mailto);
433 wprintf("</table></div>\n");
439 * Display a textual vCard
440 * (Converts to a vCard object and then calls the actual display function)
441 * Set 'full' to nonzero to display the whole card instead of a one-liner.
442 * Or, if "storename" is non-NULL, just store the person's name in that
443 * buffer instead of displaying the card at all.
445 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
451 v = vcard_load(vcard_source);
452 if (v == NULL) return;
454 name = vcard_get_prop(v, "n", 1, 0, 0);
460 if (storename != NULL) {
461 fetchname_parsed_vcard(v, storename);
463 else if ( (alpha == 0)
464 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
465 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
467 display_parsed_vcard(v, full);
475 * I wanna SEE that message!
477 void read_message(long msgnum, int printable_view) {
479 char mime_partnum[256];
480 char mime_filename[256];
481 char mime_content_type[256];
482 char mime_charset[256];
483 char mime_disposition[256];
492 char reply_all[4096];
498 char vcard_partnum[256];
499 char cal_partnum[256];
500 char *part_source = NULL;
502 iconv_t ic = (iconv_t)(-1) ;
503 char *ibuf; /* Buffer of characters to be converted */
504 char *obuf; /* Buffer for converted characters */
505 size_t ibuflen; /* Length of input buffer */
506 size_t obuflen; /* Length of output buffer */
507 char *osav; /* Saved pointer to output buffer */
513 strcpy(reply_to, "");
514 strcpy(reply_all, "");
515 strcpy(vcard_partnum, "");
516 strcpy(cal_partnum, "");
517 strcpy(mime_http, "");
518 strcpy(mime_content_type, "text/plain");
519 strcpy(mime_charset, "us-ascii");
521 serv_printf("MSG4 %ld", msgnum);
522 serv_getln(buf, sizeof buf);
525 wprintf(_("ERROR:"));
526 wprintf("</STRONG> %s<br />\n", &buf[4]);
530 /* begin everythingamundo table */
531 if (!printable_view) {
532 wprintf("<div id=\"fix_scrollbar_bug\">\n");
533 wprintf("<table width=100%% border=1 cellspacing=0 "
534 "cellpadding=0><TR><TD>\n");
537 /* begin message header table */
538 wprintf("<TABLE WIDTH=100%% BORDER=0 CELLSPACING=0 "
539 "CELLPADDING=1 BGCOLOR=\"#CCCCCC\"><TR><TD>\n");
541 wprintf("<SPAN CLASS=\"message_header\">");
542 strcpy(m_subject, "");
545 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
546 if (!strcmp(buf, "000")) {
548 wprintf(_("unexpected end of message"));
549 wprintf("</I><br /><br />\n");
550 wprintf("</SPAN>\n");
553 if (!strncasecmp(buf, "nhdr=yes", 8))
557 if (!strncasecmp(buf, "type=", 5))
558 format_type = atoi(&buf[5]);
559 if (!strncasecmp(buf, "from=", 5)) {
560 strcpy(from, &buf[5]);
562 wprintf("<A HREF=\"/showuser?who=");
564 utf8ify_rfc822_string(from);
571 if (!strncasecmp(buf, "subj=", 5)) {
572 safestrncpy(m_subject, &buf[5], sizeof m_subject);
574 if (!strncasecmp(buf, "cccc=", 5)) {
575 safestrncpy(m_cc, &buf[5], sizeof m_cc);
576 if (strlen(reply_all) > 0) {
577 strcat(reply_all, ", ");
579 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
580 (sizeof reply_all - strlen(reply_all)) );
582 if ((!strncasecmp(buf, "hnod=", 5))
583 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
584 wprintf("(%s) ", &buf[5]);
586 if ((!strncasecmp(buf, "room=", 5))
587 && (strcasecmp(&buf[5], WC->wc_roomname))
588 && (strlen(&buf[5])>0) ) {
590 wprintf("%s> ", &buf[5]);
592 if (!strncasecmp(buf, "rfca=", 5)) {
593 strcpy(rfca, &buf[5]);
599 if (!strncasecmp(buf, "node=", 5)) {
600 strcpy(node, &buf[5]);
601 if ( ((WC->room_flags & QR_NETWORK)
602 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
603 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
606 wprintf("@%s ", &buf[5]);
609 if (!strncasecmp(buf, "rcpt=", 5)) {
613 if (strlen(reply_all) > 0) {
614 strcat(reply_all, ", ");
616 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
617 (sizeof reply_all - strlen(reply_all)) );
619 if (!strncasecmp(buf, "time=", 5)) {
620 fmt_date(now, atol(&buf[5]), 0);
624 if (!strncasecmp(buf, "part=", 5)) {
625 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
626 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
627 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
628 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
629 mime_length = extract_int(&buf[5], 5);
631 if ((!strcasecmp(mime_disposition, "inline"))
632 && (!strncasecmp(mime_content_type, "image/", 6)) ){
633 snprintf(&mime_http[strlen(mime_http)],
634 (sizeof(mime_http) - strlen(mime_http) - 1),
635 "<IMG SRC=\"/mimepart/%ld/%s/%s\">",
636 msgnum, mime_partnum, mime_filename);
638 else if ( (!strcasecmp(mime_disposition, "attachment"))
639 || (!strcasecmp(mime_disposition, "inline")) ) {
640 snprintf(&mime_http[strlen(mime_http)],
641 (sizeof(mime_http) - strlen(mime_http) - 1),
642 "<A HREF=\"/mimepart/%ld/%s/%s\" "
643 "TARGET=\"wc.%ld.%s\">"
644 "<IMG SRC=\"/static/diskette_24x.gif\" "
645 "BORDER=0 ALIGN=MIDDLE>\n"
646 "Part %s: %s (%s, %d bytes)</A><br />\n",
647 msgnum, mime_partnum, mime_filename,
648 msgnum, mime_partnum,
649 mime_partnum, mime_filename,
650 mime_content_type, mime_length);
653 /*** begin handler prep ***/
654 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
655 strcpy(vcard_partnum, mime_partnum);
658 if (!strcasecmp(mime_content_type, "text/calendar")) {
659 strcpy(cal_partnum, mime_partnum);
662 /*** end handler prep ***/
668 /* Generate a reply-to address */
669 if (strlen(rfca) > 0) {
670 strcpy(reply_to, rfca);
673 if ( (strlen(node) > 0)
674 && (strcasecmp(node, serv_info.serv_nodename))
675 && (strcasecmp(node, serv_info.serv_humannode)) ) {
676 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
680 snprintf(reply_to, sizeof(reply_to), "%s", from);
690 utf8ify_rfc822_string(m_cc);
691 utf8ify_rfc822_string(m_subject);
693 if (strlen(m_cc) > 0) {
695 "<SPAN CLASS=\"message_subject\">");
701 if (strlen(m_subject) > 0) {
703 "<SPAN CLASS=\"message_subject\">");
704 wprintf(_("Subject:"));
711 /* start msg buttons */
712 if (!printable_view) {
713 wprintf("<td align=right>\n");
716 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
717 wprintf("<a href=\"/display_enter");
718 if (WC->is_mailbox) {
719 wprintf("?replyquote=%ld", msgnum);
722 urlescputs(reply_to);
723 wprintf("?subject=");
724 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
725 urlescputs(m_subject);
726 wprintf("\">[%s]</a> ", _("Reply"));
730 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
731 if (!WC->is_mailbox) {
732 wprintf("<a href=\"/display_enter");
733 wprintf("?replyquote=%ld", msgnum);
735 urlescputs(reply_to);
736 wprintf("?subject=");
737 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
738 urlescputs(m_subject);
739 wprintf("\">[%s]</a> ", _("ReplyQuoted"));
744 if (WC->wc_view == VIEW_MAILBOX) {
745 wprintf("<a href=\"/display_enter");
746 wprintf("?replyquote=%ld", msgnum);
748 urlescputs(reply_to);
750 urlescputs(reply_all);
751 wprintf("?subject=");
752 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
753 urlescputs(m_subject);
754 wprintf("\">[%s]</a> ", _("ReplyAll"));
758 if (WC->wc_view == VIEW_MAILBOX) {
759 wprintf("<a href=\"/display_enter?fwdquote=%ld?subject=", msgnum);
760 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
761 urlescputs(m_subject);
762 wprintf("\">[%s]</a> ", _("Forward"));
765 /* If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
766 if ( (WC->is_room_aide) || (WC->is_mailbox) ) {
768 wprintf("<a href=\"/confirm_move_msg?msgid=%ld\">[%s]</a> ",
772 wprintf("<a href=\"/delete_msg?msgid=%ld\" "
773 "onClick=\"return confirm('%s');\">"
774 "[%s]</a> ", msgnum, _("Delete this message?"), _("Delete")
778 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'); \" >"
779 "[%s]</a>", msgnum, msgnum, _("Print"));
784 wprintf("</TR></TABLE>\n");
787 wprintf("<TABLE BORDER=0 WIDTH=100%% BGCOLOR=#FFFFFF "
788 "CELLPADDING=1 CELLSPACING=0><TR><TD>");
791 * Learn the content type
793 strcpy(mime_content_type, "text/plain");
794 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
795 if (!strcmp(buf, "000")) {
797 wprintf(_("unexpected end of message"));
798 wprintf("</I><br /><br />\n");
801 if (!strncasecmp(buf, "Content-type: ", 14)) {
802 safestrncpy(mime_content_type, &buf[14],
803 sizeof(mime_content_type));
804 for (i=0; i<strlen(mime_content_type); ++i) {
805 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
806 safestrncpy(mime_charset, &mime_content_type[i+8],
807 sizeof mime_charset);
810 for (i=0; i<strlen(mime_content_type); ++i) {
811 if (mime_content_type[i] == ';') {
812 mime_content_type[i] = 0;
818 /* Set up a character set conversion if we need to (and if we can) */
820 if ( (strcasecmp(mime_charset, "us-ascii"))
821 && (strcasecmp(mime_charset, "UTF-8")) ) {
822 ic = iconv_open("UTF-8", mime_charset);
823 if (ic == (iconv_t)(-1) ) {
824 lprintf(5, "iconv_open() failed: %s\n", strerror(errno));
829 /* Messages in legacy Citadel variformat get handled thusly... */
830 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
834 /* Boring old 80-column fixed format text gets handled this way... */
835 else if ( (!strcasecmp(mime_content_type, "text/plain"))
836 || (!strcasecmp(mime_content_type, "text")) ) {
837 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
838 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
839 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
842 if (ic != (iconv_t)(-1) ) {
844 ibuflen = strlen(ibuf);
846 obuf = (char *) malloc(obuflen);
848 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
849 osav[SIZ-obuflen] = 0;
850 safestrncpy(buf, osav, sizeof buf);
855 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
856 buf[strlen(buf) - 1] = 0;
858 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
859 wprintf("<BLOCKQUOTE>");
861 } else if ((bq == 1) &&
862 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
863 wprintf("</BLOCKQUOTE>");
869 wprintf("</TT><br />\n");
871 wprintf("</I><br />");
874 else /* HTML is fun, but we've got to strip it first */
875 if (!strcasecmp(mime_content_type, "text/html")) {
876 output_html(mime_charset);
879 /* Unknown weirdness */
881 wprintf(_("I don't know how to display %s"), mime_content_type);
882 wprintf("<br />\n", mime_content_type);
883 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
886 /* Afterwards, offer links to download attachments 'n' such */
887 if (strlen(mime_http) > 0) {
888 wprintf("%s", mime_http);
891 /* Handler for vCard parts */
892 if (strlen(vcard_partnum) > 0) {
893 part_source = load_mimepart(msgnum, vcard_partnum);
894 if (part_source != NULL) {
896 /* If it's my vCard I can edit it */
897 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
898 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
899 || (WC->wc_view == VIEW_ADDRESSBOOK)
901 wprintf("<A HREF=\"/edit_vcard?"
902 "msgnum=%ld?partnum=%s\">",
903 msgnum, vcard_partnum);
904 wprintf("[%s]</A>", _("edit"));
907 /* In all cases, display the full card */
908 display_vcard(part_source, 0, 1, NULL);
912 /* Handler for calendar parts */
913 if (strlen(cal_partnum) > 0) {
914 part_source = load_mimepart(msgnum, cal_partnum);
915 if (part_source != NULL) {
916 cal_process_attachment(part_source,
917 msgnum, cal_partnum);
927 wprintf("</TD></TR></TABLE>\n");
929 /* end everythingamundo table */
930 if (!printable_view) {
931 wprintf("</TD></TR></TABLE>\n");
932 wprintf("</div><br />\n");
936 if (ic != (iconv_t)(-1) ) {
945 * Unadorned HTML output of an individual message, suitable
946 * for placing in a hidden iframe, for printing, or whatever
948 void embed_message(void) {
951 msgnum = atol(bstr("msgnum"));
952 begin_ajax_response();
953 read_message(msgnum, 0);
959 * Printable view of a message
961 void print_message(void) {
964 msgnum = atol(bstr("msgnum"));
965 output_headers(0, 0, 0, 0, 0, 0);
967 wprintf("Content-type: text/html\r\n"
969 "Connection: close\r\n",
973 wprintf("\r\n\r\n<html>\n"
974 "<head><title>Printable view</title></head>\n"
975 "<body onLoad=\" window.print(); window.close(); \">\n"
978 read_message(msgnum, 1);
980 wprintf("\n</body></html>\n\n");
987 * Read message in simple, JavaScript-embeddable form for 'forward'
988 * or 'reply quoted' operations.
990 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
991 * in this function. Doing so would throw a JavaScript error in the
992 * 'supplied text' argument to the editor.
994 void pullquote_message(long msgnum, int forward_attachments) {
996 char mime_partnum[256];
997 char mime_filename[256];
998 char mime_content_type[256];
999 char mime_charset[256];
1000 char mime_disposition[256];
1002 char mime_http[SIZ];
1003 char *attachments = NULL;
1004 int num_attachments = 0;
1005 struct wc_attachment *att, *aptr;
1006 char m_subject[256];
1012 int format_type = 0;
1017 iconv_t ic = (iconv_t)(-1) ;
1018 char *ibuf; /* Buffer of characters to be converted */
1019 char *obuf; /* Buffer for converted characters */
1020 size_t ibuflen; /* Length of input buffer */
1021 size_t obuflen; /* Length of output buffer */
1022 char *osav; /* Saved pointer to output buffer */
1028 strcpy(reply_to, "");
1029 strcpy(mime_http, "");
1030 strcpy(mime_content_type, "text/plain");
1031 strcpy(mime_charset, "us-ascii");
1033 serv_printf("MSG4 %ld", msgnum);
1034 serv_getln(buf, sizeof buf);
1035 if (buf[0] != '1') {
1036 wprintf(_("ERROR:"));
1037 wprintf("%s<br />", &buf[4]);
1041 strcpy(m_subject, "");
1043 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1044 if (!strcmp(buf, "000")) {
1045 wprintf(_("unexpected end of message"));
1048 if (!strncasecmp(buf, "nhdr=yes", 8))
1052 if (!strncasecmp(buf, "type=", 5))
1053 format_type = atoi(&buf[5]);
1054 if (!strncasecmp(buf, "from=", 5)) {
1055 strcpy(from, &buf[5]);
1056 wprintf(_("from "));
1058 utf8ify_rfc822_string(from);
1062 if (!strncasecmp(buf, "subj=", 5)) {
1063 strcpy(m_subject, &buf[5]);
1065 if ((!strncasecmp(buf, "hnod=", 5))
1066 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1067 wprintf("(%s) ", &buf[5]);
1069 if ((!strncasecmp(buf, "room=", 5))
1070 && (strcasecmp(&buf[5], WC->wc_roomname))
1071 && (strlen(&buf[5])>0) ) {
1073 wprintf("%s> ", &buf[5]);
1075 if (!strncasecmp(buf, "rfca=", 5)) {
1076 strcpy(rfca, &buf[5]);
1082 if (!strncasecmp(buf, "node=", 5)) {
1083 strcpy(node, &buf[5]);
1084 if ( ((WC->room_flags & QR_NETWORK)
1085 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1086 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1087 && (strlen(rfca)==0)
1089 wprintf("@%s ", &buf[5]);
1092 if (!strncasecmp(buf, "rcpt=", 5)) {
1094 wprintf("%s ", &buf[5]);
1096 if (!strncasecmp(buf, "time=", 5)) {
1097 fmt_date(now, atol(&buf[5]), 0);
1098 wprintf("%s ", now);
1102 * Save attachment info for later. We can't start downloading them
1103 * yet because we're in the middle of a server transaction.
1105 if (!strncasecmp(buf, "part=", 5)) {
1107 attachments = realloc(attachments, (num_attachments * 1024));
1108 strcat(attachments, &buf[5]);
1109 strcat(attachments, "\n");
1117 utf8ify_rfc822_string(m_subject);
1119 if (strlen(m_subject) > 0) {
1120 wprintf(_("Subject:"));
1122 msgescputs(m_subject);
1132 * Learn the content type
1134 strcpy(mime_content_type, "text/plain");
1135 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1136 if (!strcmp(buf, "000")) {
1137 wprintf(_("unexpected end of message"));
1140 if (!strncasecmp(buf, "Content-type: ", 14)) {
1141 safestrncpy(mime_content_type, &buf[14],
1142 sizeof(mime_content_type));
1143 for (i=0; i<strlen(mime_content_type); ++i) {
1144 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1145 safestrncpy(mime_charset, &mime_content_type[i+8],
1146 sizeof mime_charset);
1149 for (i=0; i<strlen(mime_content_type); ++i) {
1150 if (mime_content_type[i] == ';') {
1151 mime_content_type[i] = 0;
1157 /* Set up a character set conversion if we need to (and if we can) */
1159 if ( (strcasecmp(mime_charset, "us-ascii"))
1160 && (strcasecmp(mime_charset, "UTF-8")) ) {
1161 ic = iconv_open("UTF-8", mime_charset);
1162 if (ic == (iconv_t)(-1) ) {
1163 lprintf(5, "iconv_open() failed: %s\n", strerror(errno));
1168 /* Messages in legacy Citadel variformat get handled thusly... */
1169 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1173 /* Boring old 80-column fixed format text gets handled this way... */
1174 else if (!strcasecmp(mime_content_type, "text/plain")) {
1175 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1176 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1177 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1180 if (ic != (iconv_t)(-1) ) {
1182 ibuflen = strlen(ibuf);
1184 obuf = (char *) malloc(obuflen);
1186 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1187 osav[SIZ-obuflen] = 0;
1188 safestrncpy(buf, osav, sizeof buf);
1193 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1194 buf[strlen(buf) - 1] = 0;
1196 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
1197 wprintf("<BLOCKQUOTE>");
1199 } else if ((bq == 1) &&
1200 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
1201 wprintf("</BLOCKQUOTE>");
1207 wprintf("</TT><br />");
1209 wprintf("</I><br />");
1212 /* HTML just gets escaped and stuffed back into the editor */
1213 else if (!strcasecmp(mime_content_type, "text/html")) {
1214 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1219 /* Unknown weirdness ... don't know how to handle this content type */
1221 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1225 /* end of body handler */
1228 * If there were attachments, we have to download them and insert them
1229 * into the attachment chain for the forwarded message we are composing.
1231 if ( (forward_attachments) && (num_attachments) ) {
1232 for (i=0; i<num_attachments; ++i) {
1233 extract_token(buf, attachments, i, '\n', sizeof buf);
1234 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1235 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1236 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1237 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1238 mime_length = extract_int(buf, 5);
1241 * tracing ... uncomment if necessary
1243 lprintf(9, "fwd filename: %s\n", mime_filename);
1244 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1245 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1246 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1247 lprintf(9, "fwd length : %d\n", mime_length);
1250 if ( (!strcasecmp(mime_disposition, "inline"))
1251 || (!strcasecmp(mime_disposition, "attachment")) ) {
1253 /* Create an attachment struct from this mime part... */
1254 att = malloc(sizeof(struct wc_attachment));
1255 memset(att, 0, sizeof(struct wc_attachment));
1256 att->length = mime_length;
1257 strcpy(att->content_type, mime_content_type);
1258 strcpy(att->filename, mime_filename);
1260 att->data = load_mimepart(msgnum, mime_partnum);
1262 /* And add it to the list. */
1263 if (WC->first_attachment == NULL) {
1264 WC->first_attachment = att;
1267 aptr = WC->first_attachment;
1268 while (aptr->next != NULL) aptr = aptr->next;
1278 if (ic != (iconv_t)(-1) ) {
1289 void display_summarized(int num) {
1293 if (WC->summ[num].is_new) wprintf("<B>");
1294 escputs(WC->summ[num].subj);
1295 if (WC->summ[num].is_new) wprintf("</B>");
1296 wprintf("</TD><TD>");
1297 if (WC->summ[num].is_new) wprintf("<B>");
1298 escputs(WC->summ[num].from);
1299 if (WC->summ[num].is_new) wprintf("</B>");
1300 wprintf(" </TD><TD>");
1301 if (WC->summ[num].is_new) wprintf("<B>");
1302 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1304 if (WC->summ[num].is_new) wprintf("</B>");
1307 "<INPUT TYPE=\"checkbox\" NAME=\"msg_%ld\" VALUE=\"yes\">"
1309 WC->summ[num].msgnum
1317 void display_addressbook(long msgnum, char alpha) {
1319 char mime_partnum[SIZ];
1320 char mime_filename[SIZ];
1321 char mime_content_type[SIZ];
1322 char mime_disposition[SIZ];
1324 char vcard_partnum[SIZ];
1325 char *vcard_source = NULL;
1326 struct message_summary summ;
1328 memset(&summ, 0, sizeof(summ));
1329 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1331 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1333 serv_getln(buf, sizeof buf);
1334 if (buf[0] != '1') return;
1336 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1337 if (!strncasecmp(buf, "part=", 5)) {
1338 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1339 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1340 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1341 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1342 mime_length = extract_int(&buf[5], 5);
1344 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1345 strcpy(vcard_partnum, mime_partnum);
1351 if (strlen(vcard_partnum) > 0) {
1352 vcard_source = load_mimepart(msgnum, vcard_partnum);
1353 if (vcard_source != NULL) {
1355 /* Display the summary line */
1356 display_vcard(vcard_source, alpha, 0, NULL);
1358 /* If it's my vCard I can edit it */
1359 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1360 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1361 || (WC->wc_view == VIEW_ADDRESSBOOK)
1363 wprintf("<A HREF=\"/edit_vcard?"
1364 "msgnum=%ld?partnum=%s\">",
1365 msgnum, vcard_partnum);
1366 wprintf("[%s]</A>", _("edit"));
1377 /* If it's an old "Firstname Lastname" style record, try to
1380 void lastfirst_firstlast(char *namebuf) {
1381 char firstname[SIZ];
1385 if (namebuf == NULL) return;
1386 if (strchr(namebuf, ';') != NULL) return;
1388 i = num_tokens(namebuf, ' ');
1391 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1392 remove_token(namebuf, i-1, ' ');
1393 strcpy(firstname, namebuf);
1394 sprintf(namebuf, "%s; %s", lastname, firstname);
1398 void fetch_ab_name(long msgnum, char *namebuf) {
1400 char mime_partnum[SIZ];
1401 char mime_filename[SIZ];
1402 char mime_content_type[SIZ];
1403 char mime_disposition[SIZ];
1405 char vcard_partnum[SIZ];
1406 char *vcard_source = NULL;
1408 struct message_summary summ;
1410 if (namebuf == NULL) return;
1411 strcpy(namebuf, "");
1413 memset(&summ, 0, sizeof(summ));
1414 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1416 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1418 serv_getln(buf, sizeof buf);
1419 if (buf[0] != '1') return;
1421 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1422 if (!strncasecmp(buf, "part=", 5)) {
1423 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1424 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1425 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1426 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1427 mime_length = extract_int(&buf[5], 5);
1429 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1430 strcpy(vcard_partnum, mime_partnum);
1436 if (strlen(vcard_partnum) > 0) {
1437 vcard_source = load_mimepart(msgnum, vcard_partnum);
1438 if (vcard_source != NULL) {
1440 /* Grab the name off the card */
1441 display_vcard(vcard_source, 0, 0, namebuf);
1447 lastfirst_firstlast(namebuf);
1449 for (i=0; i<strlen(namebuf); ++i) {
1450 if (namebuf[i] != ';') return;
1452 strcpy(namebuf, _("(no name)"));
1458 * Record compare function for sorting address book indices
1460 int abcmp(const void *ab1, const void *ab2) {
1462 (((const struct addrbookent *)ab1)->ab_name),
1463 (((const struct addrbookent *)ab2)->ab_name)
1469 * Helper function for do_addrbook_view()
1470 * Converts a name into a three-letter tab label
1472 void nametab(char *tabbuf, char *name) {
1473 stresc(tabbuf, name, 0, 0);
1474 tabbuf[0] = toupper(tabbuf[0]);
1475 tabbuf[1] = tolower(tabbuf[1]);
1476 tabbuf[2] = tolower(tabbuf[2]);
1482 * Render the address book using info we gathered during the scan
1484 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1488 static int NAMESPERPAGE = 60;
1492 char tabfirst_label[SIZ];
1494 char tablast_label[SIZ];
1497 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1498 wprintf(_("This address book is empty."));
1499 wprintf("</i></div>\n");
1504 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1507 num_pages = num_ab / NAMESPERPAGE;
1509 page = atoi(bstr("page"));
1512 for (i=0; i<=num_pages; ++i) {
1514 wprintf("<A HREF=\"/readfwd?page=%d\">", i);
1519 tabfirst = i * NAMESPERPAGE;
1520 tablast = tabfirst + NAMESPERPAGE - 1;
1521 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1522 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1523 nametab(tablast_label, addrbook[tablast].ab_name);
1524 wprintf("[%s - %s]",
1525 tabfirst_label, tablast_label
1534 wprintf("<br />\n");
1536 wprintf("<TABLE border=0 cellspacing=0 "
1537 "cellpadding=3 width=100%%>\n"
1540 for (i=0; i<num_ab; ++i) {
1542 if ((i / NAMESPERPAGE) == page) {
1544 if ((displayed % 4) == 0) {
1545 if (displayed > 0) {
1549 wprintf("<TR BGCOLOR=\"#%s\">",
1550 (bg ? "DDDDDD" : "FFFFFF")
1556 wprintf("<A HREF=\"/readfwd?startmsg=%ld&is_singlecard=1",
1557 addrbook[i].ab_msgnum);
1558 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1559 vcard_n_prettyize(addrbook[i].ab_name);
1560 escputs(addrbook[i].ab_name);
1561 wprintf("</A></TD>\n");
1566 wprintf("</TR></TABLE>\n");
1572 * load message pointers from the server
1574 int load_msg_ptrs(char *servcmd, int with_headers)
1578 char displayname[128];
1585 int num_summ_alloc = 0;
1588 if (WC->num_summ != 0) {
1593 num_summ_alloc = 100;
1595 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1598 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1600 serv_getln(buf, sizeof buf);
1601 if (buf[0] != '1') {
1602 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1605 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1606 if (nummsgs < maxload) {
1607 WC->msgarr[nummsgs] = extract_long(buf, 0);
1608 datestamp = extract_long(buf, 1);
1609 extract_token(displayname, buf, 2, '|', sizeof displayname);
1610 extract_token(nodename, buf, 3, '|', sizeof nodename);
1611 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1612 extract_token(subject, buf, 5, '|', sizeof subject);
1616 if (nummsgs > num_summ_alloc) {
1617 num_summ_alloc *= 2;
1618 WC->summ = realloc(WC->summ, num_summ_alloc * sizeof(struct message_summary));
1622 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1623 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1624 safestrncpy(WC->summ[nummsgs-1].subj, _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1625 if (strlen(displayname) > 0) {
1626 safestrncpy(WC->summ[nummsgs-1].from, displayname, sizeof WC->summ[nummsgs-1].from);
1628 if (strlen(subject) > 0) {
1629 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1630 sizeof WC->summ[nummsgs-1].subj);
1633 /* Handle subjects with RFC2047 encoding */
1634 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1636 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1637 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1640 if (strlen(nodename) > 0) {
1641 if ( ((WC->room_flags & QR_NETWORK)
1642 || ((strcasecmp(nodename, serv_info.serv_nodename)
1643 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1645 strcat(WC->summ[nummsgs-1].from, " @ ");
1646 strcat(WC->summ[nummsgs-1].from, nodename);
1650 WC->summ[nummsgs-1].date = datestamp;
1653 /* Handle senders with RFC2047 encoding */
1654 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1656 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1657 strcpy(&WC->summ[nummsgs-1].from[22], "...");
1666 int summcmp_subj(const void *s1, const void *s2) {
1667 struct message_summary *summ1;
1668 struct message_summary *summ2;
1670 summ1 = (struct message_summary *)s1;
1671 summ2 = (struct message_summary *)s2;
1672 return strcasecmp(summ1->subj, summ2->subj);
1675 int summcmp_rsubj(const void *s1, const void *s2) {
1676 struct message_summary *summ1;
1677 struct message_summary *summ2;
1679 summ1 = (struct message_summary *)s1;
1680 summ2 = (struct message_summary *)s2;
1681 return strcasecmp(summ2->subj, summ1->subj);
1684 int summcmp_sender(const void *s1, const void *s2) {
1685 struct message_summary *summ1;
1686 struct message_summary *summ2;
1688 summ1 = (struct message_summary *)s1;
1689 summ2 = (struct message_summary *)s2;
1690 return strcasecmp(summ1->from, summ2->from);
1693 int summcmp_rsender(const void *s1, const void *s2) {
1694 struct message_summary *summ1;
1695 struct message_summary *summ2;
1697 summ1 = (struct message_summary *)s1;
1698 summ2 = (struct message_summary *)s2;
1699 return strcasecmp(summ2->from, summ1->from);
1702 int summcmp_date(const void *s1, const void *s2) {
1703 struct message_summary *summ1;
1704 struct message_summary *summ2;
1706 summ1 = (struct message_summary *)s1;
1707 summ2 = (struct message_summary *)s2;
1709 if (summ1->date < summ2->date) return -1;
1710 else if (summ1->date > summ2->date) return +1;
1714 int summcmp_rdate(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;
1721 if (summ1->date < summ2->date) return +1;
1722 else if (summ1->date > summ2->date) return -1;
1727 * command loop for reading messages
1729 void readloop(char *oper)
1738 int num_displayed = 0;
1740 int is_addressbook = 0;
1741 int is_singlecard = 0;
1742 int is_calendar = 0;
1745 int remaining_messages;
1747 int lowest_displayed = (-1);
1748 int highest_displayed = 0;
1749 long pn_previous = 0L;
1750 long pn_current = 0L;
1753 struct addrbookent *addrbook = NULL;
1755 char *sortby = NULL;
1756 char sortpref_name[128];
1757 char sortpref_value[128];
1758 char *subjsort_button;
1759 char *sendsort_button;
1760 char *datesort_button;
1762 startmsg = atol(bstr("startmsg"));
1763 maxmsgs = atoi(bstr("maxmsgs"));
1764 is_summary = atoi(bstr("summary"));
1765 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1767 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
1768 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
1770 sortby = bstr("sortby");
1771 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
1772 set_preference(sortpref_name, sortby, 1);
1774 if (strlen(sortby) == 0) sortby = sortpref_value;
1775 if (strlen(sortby) == 0) sortby = "msgid";
1777 output_headers(1, 1, 1, 0, 0, 0);
1779 /* When in summary mode, always show ALL messages instead of just
1780 * new or old. Otherwise, show what the user asked for.
1782 if (!strcmp(oper, "readnew")) {
1783 strcpy(cmd, "MSGS NEW");
1785 else if (!strcmp(oper, "readold")) {
1786 strcpy(cmd, "MSGS OLD");
1789 strcpy(cmd, "MSGS ALL");
1792 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
1794 strcpy(cmd, "MSGS ALL");
1797 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
1799 strcpy(cmd, "MSGS ALL");
1804 strcpy(cmd, "MSGS ALL|||1"); /* fetch header summary */
1809 /* Are we doing a summary view? If so, we need to know old messages
1810 * and new messages, so we can do that pretty boldface thing for the
1813 strcpy(old_msgs, "");
1816 serv_getln(buf, sizeof buf);
1817 if (buf[0] == '2') {
1818 strcpy(old_msgs, &buf[4]);
1822 is_singlecard = atoi(bstr("is_singlecard"));
1824 if (WC->wc_view == VIEW_CALENDAR) { /* calendar */
1826 strcpy(cmd, "MSGS ALL");
1829 if (WC->wc_view == VIEW_TASKS) { /* tasks */
1831 strcpy(cmd, "MSGS ALL");
1834 if (WC->wc_view == VIEW_NOTES) { /* notes */
1836 strcpy(cmd, "MSGS ALL");
1840 nummsgs = load_msg_ptrs(cmd, is_summary);
1843 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
1845 if (!strcmp(oper, "readnew")) {
1846 wprintf(_("No new messages."));
1847 } else if (!strcmp(oper, "readold")) {
1848 wprintf(_("No old messages."));
1850 wprintf(_("No messages here."));
1859 for (a = 0; a < nummsgs; ++a) {
1860 /* Are you a new message, or an old message? */
1862 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
1863 WC->summ[a].is_new = 0;
1866 WC->summ[a].is_new = 1;
1872 if (startmsg == 0L) startmsg = WC->msgarr[0];
1873 remaining_messages = 0;
1875 for (a = 0; a < nummsgs; ++a) {
1876 if (WC->msgarr[a] >= startmsg) {
1877 ++remaining_messages;
1882 if (!strcasecmp(sortby, "subject")) {
1883 qsort(WC->summ, WC->num_summ,
1884 sizeof(struct message_summary), summcmp_subj);
1886 else if (!strcasecmp(sortby, "rsubject")) {
1887 qsort(WC->summ, WC->num_summ,
1888 sizeof(struct message_summary), summcmp_rsubj);
1890 else if (!strcasecmp(sortby, "sender")) {
1891 qsort(WC->summ, WC->num_summ,
1892 sizeof(struct message_summary), summcmp_sender);
1894 else if (!strcasecmp(sortby, "rsender")) {
1895 qsort(WC->summ, WC->num_summ,
1896 sizeof(struct message_summary), summcmp_rsender);
1898 else if (!strcasecmp(sortby, "date")) {
1899 qsort(WC->summ, WC->num_summ,
1900 sizeof(struct message_summary), summcmp_date);
1902 else if (!strcasecmp(sortby, "rdate")) {
1903 qsort(WC->summ, WC->num_summ,
1904 sizeof(struct message_summary), summcmp_rdate);
1908 if (!strcasecmp(sortby, "subject")) {
1909 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1911 else if (!strcasecmp(sortby, "rsubject")) {
1912 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1915 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1918 if (!strcasecmp(sortby, "sender")) {
1919 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1921 else if (!strcasecmp(sortby, "rsender")) {
1922 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1925 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1928 if (!strcasecmp(sortby, "date")) {
1929 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1931 else if (!strcasecmp(sortby, "rdate")) {
1932 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1935 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1939 wprintf("</div>"); /* end of 'content' div */
1941 wprintf("<div id=\"message_list\">"
1943 "<div id=\"fix_scrollbar_bug\">\n"
1945 "<form name=\"msgomatic\" "
1946 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n"
1948 "<table border=0 cellspacing=0 "
1949 "cellpadding=0 width=100%%>\n"
1951 "<TD align=center><b><i>%s</i></b> %s</TD>"
1952 "<TD align=center><b><i>%s</i></b> %s</TD>"
1953 "<TD align=center><b><i>%s</i></b> %s</TD>"
1954 "<TD><INPUT TYPE=\"submit\" NAME=\"delete_button\" "
1955 "STYLE=\"font-family: Bitstream Vera Sans,Arial,Helvetica,sans-serif;"
1956 " font-size: 6pt;\" "
1957 "VALUE=\"%s\"></TD>"
1960 _("Subject"), subjsort_button,
1961 _("Sender"), sendsort_button,
1962 _("Date"), datesort_button,
1967 for (a = 0; a < nummsgs; ++a) {
1968 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
1970 /* Learn which msgs "Prev" & "Next" buttons go to */
1971 pn_current = WC->msgarr[a];
1972 if (a > 0) pn_previous = WC->msgarr[a-1];
1973 if (a < (nummsgs-1)) pn_next = WC->msgarr[a+1];
1975 /* If a tabular view, set up the line */
1978 wprintf("<tr bgcolor=\"#%s\" ",
1979 (bg ? "DDDDDD" : "FFFFFF")
1982 wprintf("onClick=\" new Ajax.Updater('preview_pane', '/msg', { method: 'get', parameters: 'msgnum=%ld' } ); \" ", WC->summ[a].msgnum);
1987 /* Display the message */
1989 display_summarized(a);
1991 else if (is_addressbook) {
1992 fetch_ab_name(WC->msgarr[a], buf);
1994 addrbook = realloc(addrbook,
1995 (sizeof(struct addrbookent) * num_ab) );
1996 safestrncpy(addrbook[num_ab-1].ab_name, buf,
1997 sizeof(addrbook[num_ab-1].ab_name));
1998 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
2000 else if (is_calendar) {
2001 display_calendar(WC->msgarr[a]);
2003 else if (is_tasks) {
2004 display_task(WC->msgarr[a]);
2006 else if (is_notes) {
2007 display_note(WC->msgarr[a]);
2010 read_message(WC->msgarr[a], 0);
2013 /* If a tabular view, finish the line */
2018 if (lowest_displayed < 0) lowest_displayed = a;
2019 highest_displayed = a;
2022 --remaining_messages;
2027 wprintf("</table></form>"
2028 "</div>\n"); /* end of 'fix_scrollbar_bug' div */
2029 wprintf("</div>"); /* end of 'message_list' div */
2031 wprintf("<div id=\"ml_slider\"></div>"); /* slider */
2033 wprintf("<div id=\"preview_pane\">"); /* The preview pane will initially be empty */
2036 /* Bump these because although we're thinking in zero base, the user
2037 * is a drooling idiot and is thinking in one base.
2040 ++highest_displayed;
2042 /* If we're only looking at one message, do a prev/next thing */
2043 if (num_displayed == 1) {
2044 if ((!is_tasks) && (!is_calendar) && (!is_addressbook) && (!is_notes) && (!is_singlecard)) {
2046 wprintf("<div id=\"fix_scrollbar_bug\">"
2047 "<table border=0 width=100%% bgcolor=\"#dddddd\"><tr><td>");
2048 wprintf(_("Reading #%d of %d messages."), lowest_displayed, nummsgs);
2049 wprintf("</TD><TD ALIGN=RIGHT><FONT SIZE=+1>");
2051 if (pn_previous > 0L) {
2052 wprintf("<A HREF=\"/%s"
2063 wprintf("<A HREF=\"/%s"
2073 wprintf("<A HREF=\"/%s?startmsg=%ld"
2074 "?maxmsgs=%d?summary=1\">"
2083 wprintf("</td></tr></table></div>\n");
2088 * If we're not currently looking at ALL requested
2089 * messages, then display the selector bar
2091 if (num_displayed > 1) {
2092 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2093 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2095 wprintf("<form name=\"msgomatic\" "
2096 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n");
2098 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2100 wprintf("<select name=\"whichones\" size=\"1\" "
2101 "OnChange=\"location.href=msgomatic.whichones.options"
2102 "[selectedIndex].value\">\n");
2104 for (b=0; b<nummsgs; b = b + maxmsgs) {
2107 if (hi > nummsgs) hi = nummsgs;
2108 wprintf("<option %s value="
2113 "%d-%d</option> \n",
2114 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2121 wprintf("<option value=\"/%s?startmsg=%ld"
2122 "?maxmsgs=9999999?summary=%d\">"
2126 WC->msgarr[0], is_summary);
2128 wprintf("</select> ");
2129 wprintf(_("of %d messages."), nummsgs);
2130 wprintf("</form>\n");
2136 do_tasks_view(); /* Render the task list */
2140 do_calendar_view(); /* Render the calendar */
2143 if (is_addressbook) {
2144 do_addrbook_view(addrbook, num_ab); /* Render the address book */
2147 /* Put the data transfer hidden iframe in a hidden div, to make it *really* hidden */
2149 "<div display=\"hidden\">\n"
2150 "<iframe name=\"msgloader1\" id=\"msgloader1\" width=\"1\"></iframe>\n"
2153 /* Note: wDumpContent() will output one additional </div> tag. */
2155 if (addrbook != NULL) free(addrbook);
2157 /* free the summary */
2158 if (WC->num_summ != 0) {
2163 /* If we got here via a mailbox view and are reading a single
2164 * message, mark it as "seen." We do this after rendering the web page
2165 * so it doesn't keep the user waiting.
2167 if ( (maxmsgs == 1) && (WC->wc_view == VIEW_MAILBOX) ) {
2168 serv_printf("SEEN %ld|1", startmsg);
2169 serv_getln(buf, sizeof buf);
2175 * Back end for post_message() ... this is where the actual message
2176 * gets transmitted to the server.
2178 void post_mime_to_server(void) {
2180 int is_multipart = 0;
2182 struct wc_attachment *att;
2184 size_t encoded_length;
2186 /* RFC2045 requires this, and some clients look for it... */
2187 serv_puts("MIME-Version: 1.0");
2189 /* If there are attachments, we have to do multipart/mixed */
2190 if (WC->first_attachment != NULL) {
2195 sprintf(boundary, "---Citadel-Multipart-%s-%04x%04x---",
2196 serv_info.serv_fqdn,
2201 /* Remember, serv_printf() appends an extra newline */
2202 serv_printf("Content-type: multipart/mixed; "
2203 "boundary=\"%s\"\n", boundary);
2204 serv_printf("This is a multipart message in MIME format.\n");
2205 serv_printf("--%s", boundary);
2208 serv_puts("Content-type: text/html; charset=utf-8");
2210 serv_puts("<HTML><BODY>\n");
2211 text_to_server(bstr("msgtext"), 0);
2212 serv_puts("</BODY></HTML>\n");
2217 /* Add in the attachments */
2218 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2220 encoded_length = ((att->length * 150) / 100);
2221 encoded = malloc(encoded_length);
2222 if (encoded == NULL) break;
2223 CtdlEncodeBase64(encoded, att->data, att->length);
2225 serv_printf("--%s", boundary);
2226 serv_printf("Content-type: %s", att->content_type);
2227 serv_printf("Content-disposition: attachment; "
2228 "filename=\"%s\"", att->filename);
2229 serv_puts("Content-transfer-encoding: base64");
2231 serv_write(encoded, strlen(encoded));
2236 serv_printf("--%s--", boundary);
2244 * Post message (or don't post message)
2246 * Note regarding the "dont_post" variable:
2247 * A random value (actually, it's just a timestamp) is inserted as a hidden
2248 * field called "postseq" when the display_enter page is generated. This
2249 * value is checked when posting, using the static variable dont_post. If a
2250 * user attempts to post twice using the same dont_post value, the message is
2251 * discarded. This prevents the accidental double-saving of the same message
2252 * if the user happens to click the browser "back" button.
2254 void post_message(void)
2257 static long dont_post = (-1L);
2258 struct wc_attachment *att, *aptr;
2260 if (WC->upload_length > 0) {
2262 /* There's an attachment. Save it to this struct... */
2263 att = malloc(sizeof(struct wc_attachment));
2264 memset(att, 0, sizeof(struct wc_attachment));
2265 att->length = WC->upload_length;
2266 strcpy(att->content_type, WC->upload_content_type);
2267 strcpy(att->filename, WC->upload_filename);
2270 /* And add it to the list. */
2271 if (WC->first_attachment == NULL) {
2272 WC->first_attachment = att;
2275 aptr = WC->first_attachment;
2276 while (aptr->next != NULL) aptr = aptr->next;
2280 /* Mozilla sends a simple filename, which is what we want,
2281 * but Satan's Browser sends an entire pathname. Reduce
2282 * the path to just a filename if we need to.
2284 while (num_tokens(att->filename, '/') > 1) {
2285 remove_token(att->filename, 0, '/');
2287 while (num_tokens(att->filename, '\\') > 1) {
2288 remove_token(att->filename, 0, '\\');
2291 /* Transfer control of this memory from the upload struct
2292 * to the attachment struct.
2294 att->data = WC->upload;
2295 WC->upload_length = 0;
2301 if (strlen(bstr("cancel_button")) > 0) {
2302 sprintf(WC->ImportantMessage,
2303 _("Cancelled. Message was not posted."));
2304 } else if (strlen(bstr("attach_button")) > 0) {
2307 } else if (atol(bstr("postseq")) == dont_post) {
2308 sprintf(WC->ImportantMessage,
2309 _("Automatically cancelled because you have already "
2310 "saved this message."));
2312 sprintf(buf, "ENT0 1|%s|0|4|%s|||%s|%s",
2319 serv_getln(buf, sizeof buf);
2320 if (buf[0] == '4') {
2321 post_mime_to_server();
2322 if ( (strlen(bstr("recp")) > 0)
2323 || (strlen(bstr("cc")) > 0)
2324 || (strlen(bstr("bcc")) > 0)
2326 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2329 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2331 dont_post = atol(bstr("postseq"));
2333 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2339 free_attachments(WC);
2340 readloop("readnew");
2347 * display the message entry screen
2349 void display_enter(void)
2353 struct wc_attachment *att;
2354 int recipient_required = 0;
2355 int recipient_bad = 0;
2357 if (strlen(bstr("force_room")) > 0) {
2358 gotoroom(bstr("force_room"));
2361 /* Are we perhaps in an address book view? If so, then an "enter
2362 * message" command really means "add new entry."
2364 if (WC->wc_view == VIEW_ADDRESSBOOK) {
2365 do_edit_vcard(-1, "", "");
2369 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
2370 /* Are we perhaps in a calendar view? If so, then an "enter
2371 * message" command really means "add new calendar item."
2373 if (WC->wc_view == VIEW_CALENDAR) {
2374 display_edit_event();
2378 /* Are we perhaps in a tasks view? If so, then an "enter
2379 * message" command really means "add new task."
2381 if (WC->wc_view == VIEW_TASKS) {
2382 display_edit_task();
2388 * Otherwise proceed normally.
2389 * Do a custom room banner with no navbar...
2391 output_headers(1, 1, 2, 0, 0, 0);
2392 wprintf("<div id=\"banner\">\n");
2393 embed_room_banner(NULL, navbar_none);
2394 wprintf("</div>\n");
2395 wprintf("<div id=\"content\">\n"
2396 "<div id=\"fix_scrollbar_bug\">"
2397 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
2399 /* First test to see whether this is a room that requires recipients to be entered */
2400 serv_puts("ENT0 0");
2401 serv_getln(buf, sizeof buf);
2402 if (!strncmp(buf, "570", 3)) { /* 570 means that we need a recipient here */
2403 recipient_required = 1;
2405 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
2406 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2410 /* Now check our actual recipients if there are any */
2411 if (recipient_required) {
2412 sprintf(buf, "ENT0 0|%s|0|0||||%s|%s", bstr("recp"), bstr("cc"), bstr("bcc"));
2414 serv_getln(buf, sizeof buf);
2416 if (!strncmp(buf, "570", 3)) { /* 570 means we have an invalid recipient listed */
2417 if (strlen(bstr("recp")) + strlen(bstr("cc")) + strlen(bstr("bcc")) > 0) {
2421 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
2422 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2427 /* If we got this far, we can display the message entry screen. */
2430 fmt_date(buf, now, 0);
2431 strcat(&buf[strlen(buf)], _(" <I>from</I> "));
2432 stresc(&buf[strlen(buf)], WC->wc_username, 1, 1);
2434 /* Don't need this anymore, it's in the input box below
2435 if (strlen(bstr("recp")) > 0) {
2436 strcat(&buf[strlen(buf)], _(" <I>to</I> "));
2437 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
2441 strcat(&buf[strlen(buf)], _(" <I>in</I> "));
2442 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
2444 /* begin message entry screen */
2445 wprintf("<form enctype=\"multipart/form-data\" "
2446 "method=\"POST\" action=\"/post\" "
2447 "name=\"enterform\""
2449 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2451 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2452 wprintf("%s<br>\n", buf); /* header bar */
2454 wprintf("<table border=\"0\" width=\"100%%\">\n");
2455 if (recipient_required) {
2457 wprintf("<tr><td>");
2458 wprintf("<font size=-1>");
2462 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
2463 escputs(bstr("recp"));
2464 wprintf("\" size=50 maxlength=1000 />");
2465 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
2466 wprintf("</td><td></td></tr>\n");
2468 wprintf("<tr><td>");
2469 wprintf("<font size=-1>");
2473 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
2474 escputs(bstr("cc"));
2475 wprintf("\" size=50 maxlength=1000 />");
2476 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
2477 wprintf("</td><td></td></tr>\n");
2479 wprintf("<tr><td>");
2480 wprintf("<font size=-1>");
2484 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
2485 escputs(bstr("bcc"));
2486 wprintf("\" size=50 maxlength=1000 />");
2487 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
2488 wprintf("</td><td></td></tr>\n");
2490 /* Initialize the autocomplete ajax helpers (found in wclib.js) */
2491 wprintf("<script type=\"text/javascript\"> \n"
2492 " activate_entmsg_autocompleters(); \n"
2497 wprintf("<tr><td>");
2498 wprintf("<font size=-1>");
2499 wprintf(_("Subject (optional):"));
2502 "<input type=\"text\" name=\"subject\" value=\"");
2503 escputs(bstr("subject"));
2504 wprintf("\" size=50 maxlength=70></td><td>\n");
2506 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2507 if (recipient_required) {
2508 wprintf(_("Send message"));
2510 wprintf(_("Post message"));
2513 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2514 wprintf("</td></tr></table>\n");
2516 wprintf("<center>");
2518 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
2520 msgescputs(bstr("msgtext"));
2521 if (atol(bstr("fwdquote")) > 0L) {
2522 wprintf("<br><div align=center><i>");
2523 wprintf(_("--- forwarded message ---"));
2524 wprintf("</i></div><br>");
2525 pullquote_message(atol(bstr("fwdquote")), 1);
2527 else if (atol(bstr("replyquote")) > 0L) {
2530 pullquote_message(atol(bstr("replyquote")), 0);
2531 wprintf("</blockquote>");
2533 wprintf("</textarea>");
2534 wprintf("</center><br />\n");
2537 * The following script embeds the TinyMCE richedit control, and automatically
2538 * transforms the textarea into a richedit textarea.
2541 "<script language=\"javascript\" type=\"text/javascript\" src=\"tiny_mce/tiny_mce.js\"></script>\n"
2542 "<script language=\"javascript\" type=\"text/javascript\">"
2544 " mode : \"textareas\", width : \"100%%\", browsers : \"msie,gecko\" "
2549 /* Enumerate any attachments which are already in place... */
2550 wprintf("<img src=\"/static/diskette_24x.gif\" border=0 "
2551 "align=middle height=16 width=16> Attachments: ");
2552 wprintf("<select name=\"which_attachment\" size=1>");
2553 for (att = WC->first_attachment; att != NULL; att = att->next) {
2554 wprintf("<option value=\"");
2555 urlescputs(att->filename);
2557 escputs(att->filename);
2558 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
2559 wprintf("</option>\n");
2561 wprintf("</select>");
2563 /* Now offer the ability to attach additional files... */
2564 wprintf(" "
2565 "Attach file: <input NAME=\"attachfile\" "
2566 "SIZE=16 TYPE=\"file\">\n "
2567 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
2569 /* Seth asked for these to be at the top *and* bottom... */
2570 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2571 if (recipient_required) {
2572 wprintf(_("Send message"));
2574 wprintf(_("Post message"));
2577 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2579 wprintf("</form>\n");
2581 wprintf("</td></tr></table></div>\n");
2582 DONE: wDumpContent(1);
2592 void delete_msg(void)
2597 msgid = atol(bstr("msgid"));
2599 output_headers(1, 1, 1, 0, 0, 0);
2601 sprintf(buf, "DELE %ld", msgid);
2603 serv_getln(buf, sizeof buf);
2604 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2613 * Confirm move of a message
2615 void confirm_move_msg(void)
2621 msgid = atol(bstr("msgid"));
2624 output_headers(1, 1, 2, 0, 0, 0);
2625 wprintf("<div id=\"banner\">\n");
2626 wprintf("<TABLE WIDTH=100%% BORDER=0><TR><TD>");
2627 wprintf("<SPAN CLASS=\"titlebar\">");
2628 wprintf(_("Confirm move of message"));
2629 wprintf("</SPAN>\n");
2630 wprintf("</TD></TR></TABLE>\n");
2631 wprintf("</div>\n<div id=\"content\">\n");
2633 wprintf("<CENTER>");
2635 wprintf(_("Move this message to:"));
2636 wprintf("<br />\n");
2638 wprintf("<form METHOD=\"POST\" ACTION=\"/move_msg\">\n");
2639 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
2643 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
2645 serv_getln(buf, sizeof buf);
2646 if (buf[0] == '1') {
2647 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2648 extract_token(targ, buf, 0, '|', sizeof targ);
2649 wprintf("<OPTION>");
2654 wprintf("</SELECT>\n");
2655 wprintf("<br />\n");
2657 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
2659 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
2660 wprintf("</form></CENTER>\n");
2662 wprintf("</CENTER>\n");
2673 msgid = atol(bstr("msgid"));
2675 if (strlen(bstr("move_button")) > 0) {
2676 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
2678 serv_getln(buf, sizeof buf);
2679 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2681 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
2684 readloop("readnew");
2689 * This gets called when a user selects multiple messages in a summary
2690 * list and then clicks to perform a transformation of some sort on them
2691 * (such as deleting them).
2693 void do_stuff_to_msgs(void) {
2697 struct stuff_t *next;
2701 struct stuff_t *stuff = NULL;
2702 struct stuff_t *ptr;
2703 int delete_button_pressed = 0;
2706 serv_puts("MSGS ALL");
2707 serv_getln(buf, sizeof buf);
2709 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2710 ptr = malloc(sizeof(struct stuff_t));
2711 ptr->msgnum = atol(buf);
2716 if (strlen(bstr("delete_button")) > 0) {
2717 delete_button_pressed = 1;
2720 while (stuff != NULL) {
2722 sprintf(buf, "msg_%ld", stuff->msgnum);
2723 if (!strcasecmp(bstr(buf), "yes")) {
2725 if (delete_button_pressed) {
2726 serv_printf("DELE %ld", stuff->msgnum);
2727 serv_getln(buf, sizeof buf);
2737 readloop("readfwd");