4 * Functions which deal with the fetching and displaying of messages.
14 #include <sys/types.h>
16 #include <sys/socket.h>
18 #include <netinet/in.h>
33 #include "webserver.h"
36 /* Address book entry (keep it short and sweet, it's just a quickie lookup
37 * which we can use to get to the real meat and bones later)
47 /* Handle subjects with RFC2047 encoding, such as:
48 * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=
50 void utf8ify_rfc822_string(char *buf) {
56 iconv_t ic = (iconv_t)(-1) ;
57 char *ibuf; /* Buffer of characters to be converted */
58 char *obuf; /* Buffer for converted characters */
59 size_t ibuflen; /* Length of input buffer */
60 size_t obuflen; /* Length of output buffer */
61 char *isav; /* Saved pointer to input buffer */
62 char *osav; /* Saved pointer to output buffer */
64 while (start=strstr(buf, "=?"), end=strstr(buf, "?="),
65 ((start != NULL) && (end != NULL) && (end > start)) )
67 extract_token(charset, start, 1, '?', sizeof charset);
68 extract_token(encoding, start, 2, '?', sizeof encoding);
69 extract_token(istr, start, 3, '?', sizeof istr);
77 if (!strcasecmp(encoding, "B")) { /* base64 */
78 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
80 else if (!strcasecmp(encoding, "Q")) { /* quoted-printable */
81 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, strlen(istr));
84 strcpy(ibuf, istr); /* huh? */
85 ibuflen = strlen(istr);
88 ic = iconv_open("UTF-8", charset);
89 if (ic != (iconv_t)(-1) ) {
92 obuf = (char *) malloc(obuflen);
94 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
95 osav[1024-obuflen] = 0;
96 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
102 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
114 * Look for URL's embedded in a buffer and make them linkable. We use a
115 * target window in order to keep the BBS session in its own window.
131 for (pos = 0; pos < strlen(buf); ++pos) {
132 if (!strncasecmp(&buf[pos], "http://", 7))
134 if (!strncasecmp(&buf[pos], "ftp://", 6))
141 if ((start > 0) && (buf[start - 1] == '<'))
143 if ((start > 0) && (buf[start - 1] == '['))
145 if ((start > 0) && (buf[start - 1] == '('))
147 if ((start > 0) && (buf[start - 1] == '{'))
150 for (pos = strlen(buf); pos > start; --pos) {
151 if ((buf[pos] == ' ') || (buf[pos] == ench))
155 strncpy(urlbuf, &buf[start], end - start);
156 urlbuf[end - start] = 0;
158 strncpy(outbuf, buf, start);
159 sprintf(&outbuf[start], "%cA HREF=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
160 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
161 strcat(outbuf, &buf[end]);
162 if ( strlen(outbuf) < 250 )
168 * Turn a vCard "n" (name) field into something displayable.
170 void vcard_n_prettyize(char *name)
175 original_name = strdup(name);
176 for (i=0; i<5; ++i) {
177 if (strlen(original_name) > 0) {
178 if (original_name[strlen(original_name)-1] == ' ') {
179 original_name[strlen(original_name)-1] = 0;
181 if (original_name[strlen(original_name)-1] == ';') {
182 original_name[strlen(original_name)-1] = 0;
187 for (i=0; i<strlen(original_name); ++i) {
188 if (original_name[i] == ';') {
192 name[strlen(name)+1] = 0;
193 name[strlen(name)] = original_name[i];
202 /* display_vcard() calls this after parsing the textual vCard into
203 * our 'struct vCard' data object.
204 * This gets called instead of display_parsed_vcard() if we are only looking
205 * to extract the person's name instead of displaying the card.
207 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
210 strcpy(storename, "");
212 name = vcard_get_prop(v, "n", 1, 0, 0);
214 strcpy(storename, name);
215 /* vcard_n_prettyize(storename); */
222 /* display_vcard() calls this after parsing the textual vCard into
223 * our 'struct vCard' data object.
225 * Set 'full' to nonzero to display the full card, otherwise it will only
226 * show a summary line.
228 * This code is a bit ugly, so perhaps an explanation is due: we do this
229 * in two passes through the vCard fields. On the first pass, we process
230 * fields we understand, and then render them in a pretty fashion at the
231 * end. Then we make a second pass, outputting all the fields we don't
232 * understand in a simple two-column name/value format.
234 void display_parsed_vcard(struct vCard *v, int full) {
240 char *thisname, *thisvalue;
241 char firsttoken[SIZ];
244 char displayname[SIZ];
250 strcpy(displayname, "");
258 name = vcard_get_prop(v, "fn", 1, 0, 0);
262 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
263 strcpy(displayname, name);
264 vcard_n_prettyize(displayname);
265 escputs(displayname);
274 wprintf("<div align=center><table bgcolor=#aaaaaa width=50%%>");
275 for (pass=1; pass<=2; ++pass) {
277 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
279 thisname = strdup(v->prop[i].name);
280 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
282 for (j=0; j<num_tokens(thisname, ';'); ++j) {
283 extract_token(buf, thisname, j, ';', sizeof buf);
284 if (!strcasecmp(buf, "encoding=quoted-printable")) {
286 remove_token(thisname, j, ';');
288 if (!strcasecmp(buf, "encoding=base64")) {
290 remove_token(thisname, j, ';');
295 thisvalue = malloc(strlen(v->prop[i].value) + 50);
296 j = CtdlDecodeQuotedPrintable(
297 thisvalue, v->prop[i].value,
298 strlen(v->prop[i].value) );
302 thisvalue = malloc(strlen(v->prop[i].value) + 50);
304 thisvalue, v->prop[i].value,
305 strlen(v->prop[i].value) );
308 thisvalue = strdup(v->prop[i].value);
311 /*** Various fields we may encounter ***/
313 /* N is name, but only if there's no FN already there */
314 if (!strcasecmp(firsttoken, "n")) {
315 if (strlen(displayname) == 0) {
316 strcpy(displayname, thisvalue);
317 vcard_n_prettyize(displayname);
321 /* FN (full name) is a true 'display name' field */
322 else if (!strcasecmp(firsttoken, "fn")) {
323 strcpy(displayname, thisvalue);
327 else if (!strcasecmp(firsttoken, "title")) {
328 strcpy(title, thisvalue);
332 else if (!strcasecmp(firsttoken, "org")) {
333 strcpy(org, thisvalue);
336 else if (!strcasecmp(firsttoken, "email")) {
337 if (strlen(mailto) > 0) strcat(mailto, "<br />");
339 "<A HREF=\"/display_enter"
340 "?force_room=_MAIL_?recp=");
341 urlesc(&mailto[strlen(mailto)], thisvalue);
342 strcat(mailto, "\">");
343 urlesc(&mailto[strlen(mailto)], thisvalue);
344 strcat(mailto, "</A>");
346 else if (!strcasecmp(firsttoken, "tel")) {
347 if (strlen(phone) > 0) strcat(phone, "<br />");
348 strcat(phone, thisvalue);
349 for (j=0; j<num_tokens(thisname, ';'); ++j) {
350 extract_token(buf, thisname, j, ';', sizeof buf);
351 if (!strcasecmp(buf, "tel"))
353 else if (!strcasecmp(buf, "work"))
354 strcat(phone, " (work)");
355 else if (!strcasecmp(buf, "home"))
356 strcat(phone, " (home)");
357 else if (!strcasecmp(buf, "cell"))
358 strcat(phone, " (cell)");
366 else if (!strcasecmp(firsttoken, "adr")) {
368 wprintf("<TR><TD>Address:</TD><TD>");
369 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
370 extract_token(buf, thisvalue, j, ';', sizeof buf);
371 if (strlen(buf) > 0) {
373 if (j<3) wprintf("<br />");
377 wprintf("</TD></TR>\n");
380 else if (!strcasecmp(firsttoken, "version")) {
383 else if (!strcasecmp(firsttoken, "rev")) {
386 else if (!strcasecmp(firsttoken, "label")) {
391 /*** Don't show extra fields. They're ugly.
395 wprintf("</TD><TD>");
397 wprintf("</TD></TR>\n");
407 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
408 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
409 "<IMG ALIGN=CENTER SRC=\"/static/viewcontacts_48x.gif\">"
410 "<FONT SIZE=+1><B>");
411 escputs(displayname);
412 wprintf("</B></FONT>");
413 if (strlen(title) > 0) {
414 wprintf("<div align=right>");
418 if (strlen(org) > 0) {
419 wprintf("<div align=right>");
423 wprintf("</TD></TR>\n");
425 if (strlen(phone) > 0)
426 wprintf("<TR><TD>Telephone:</TD><TD>%s</TD></TR>\n", phone);
427 if (strlen(mailto) > 0)
428 wprintf("<TR><TD>E-mail:</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);
477 * I wanna SEE that message!
479 void read_message(long msgnum, int suppress_buttons) {
481 char mime_partnum[256];
482 char mime_filename[256];
483 char mime_content_type[256];
484 char mime_charset[256];
485 char mime_disposition[256];
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(vcard_partnum, "");
515 strcpy(cal_partnum, "");
516 strcpy(mime_http, "");
517 strcpy(mime_content_type, "text/plain");
518 strcpy(mime_charset, "us-ascii");
520 serv_printf("MSG4 %ld", msgnum);
521 serv_getln(buf, sizeof buf);
523 wprintf("<STRONG>ERROR:</STRONG> %s<br />\n", &buf[4]);
527 /* begin everythingamundo table */
528 wprintf("<div id=\"fix_scrollbar_bug\">\n");
529 wprintf("<table width=100%% border=1 cellspacing=0 "
530 "cellpadding=0><TR><TD>\n");
532 /* begin message header table */
533 wprintf("<TABLE WIDTH=100%% BORDER=0 CELLSPACING=0 "
534 "CELLPADDING=1 BGCOLOR=\"#CCCCCC\"><TR><TD>\n");
536 wprintf("<SPAN CLASS=\"message_header\">");
537 strcpy(m_subject, "");
539 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
540 if (!strcmp(buf, "000")) {
541 wprintf("<I>unexpected end of message</I><br /><br />\n");
542 wprintf("</SPAN>\n");
545 if (!strncasecmp(buf, "nhdr=yes", 8))
549 if (!strncasecmp(buf, "type=", 5))
550 format_type = atoi(&buf[5]);
551 if (!strncasecmp(buf, "from=", 5)) {
552 strcpy(from, &buf[5]);
553 wprintf("from <A HREF=\"/showuser?who=");
555 utf8ify_rfc822_string(from);
562 if (!strncasecmp(buf, "subj=", 5))
563 strcpy(m_subject, &buf[5]);
564 if ((!strncasecmp(buf, "hnod=", 5))
565 && (strcasecmp(&buf[5], serv_info.serv_humannode)))
566 wprintf("(%s) ", &buf[5]);
567 if ((!strncasecmp(buf, "room=", 5))
568 && (strcasecmp(&buf[5], WC->wc_roomname))
569 && (strlen(&buf[5])>0) )
570 wprintf("in %s> ", &buf[5]);
571 if (!strncasecmp(buf, "rfca=", 5)) {
572 strcpy(rfca, &buf[5]);
578 if (!strncasecmp(buf, "node=", 5)) {
579 strcpy(node, &buf[5]);
580 if ( ((WC->room_flags & QR_NETWORK)
581 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
582 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
585 wprintf("@%s ", &buf[5]);
588 if (!strncasecmp(buf, "rcpt=", 5))
589 wprintf("to %s ", &buf[5]);
590 if (!strncasecmp(buf, "time=", 5)) {
591 fmt_date(now, atol(&buf[5]), 0);
595 if (!strncasecmp(buf, "part=", 5)) {
596 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
597 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
598 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
599 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
600 mime_length = extract_int(&buf[5], 5);
602 if (!strcasecmp(mime_disposition, "attachment")) {
603 snprintf(&mime_http[strlen(mime_http)],
604 (sizeof(mime_http) - strlen(mime_http) - 1),
605 "<A HREF=\"/output_mimepart?"
606 "msgnum=%ld?partnum=%s\" "
607 "TARGET=\"wc.%ld.%s\">"
608 "<IMG SRC=\"/static/diskette_24x.gif\" "
609 "BORDER=0 ALIGN=MIDDLE>\n"
610 "Part %s: %s (%s, %d bytes)</A><br />\n",
611 msgnum, mime_partnum,
612 msgnum, mime_partnum,
613 mime_partnum, mime_filename,
614 mime_content_type, mime_length);
617 if ((!strcasecmp(mime_disposition, "inline"))
618 && (!strncasecmp(mime_content_type, "image/", 6)) ){
619 snprintf(&mime_http[strlen(mime_http)],
620 (sizeof(mime_http) - strlen(mime_http) - 1),
621 "<IMG SRC=\"/output_mimepart?"
622 "msgnum=%ld?partnum=%s\">",
623 msgnum, mime_partnum);
626 /*** begin handler prep ***/
627 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
628 strcpy(vcard_partnum, mime_partnum);
631 if (!strcasecmp(mime_content_type, "text/calendar")) {
632 strcpy(cal_partnum, mime_partnum);
635 /*** end handler prep ***/
641 /* Generate a reply-to address */
642 if (strlen(rfca) > 0) {
643 strcpy(reply_to, rfca);
646 if ( (strlen(node) > 0)
647 && (strcasecmp(node, serv_info.serv_nodename))
648 && (strcasecmp(node, serv_info.serv_humannode)) ) {
649 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
653 snprintf(reply_to, sizeof(reply_to), "%s", from);
663 utf8ify_rfc822_string(m_subject);
665 if (strlen(m_subject) > 0) {
667 "<SPAN CLASS=\"message_subject\">"
674 /* start msg buttons */
675 if (!suppress_buttons) {
676 wprintf("<td align=right>\n");
679 wprintf("<a href=\"/display_enter?recp=");
680 urlescputs(reply_to);
681 wprintf("?subject=");
682 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
683 urlescputs(m_subject);
684 wprintf("\">[Reply]</a> ");
686 if (WC->is_room_aide) {
689 wprintf("<a href=\"/confirm_move_msg?msgid=%ld\">[Move]</a> ",
693 wprintf("<a href=\"/delete_msg?msgid=%ld\" "
694 "onClick=\"return confirm('Delete this message?');\">"
695 "[Delete]</a> ", msgnum);
699 wprintf("<a href=\"/msg?msgnum=%ld?print_it=yes\" target=\"msgloader1\">"
700 "[Print]</a>", msgnum);
705 wprintf("</TR></TABLE>\n");
708 wprintf("<TABLE BORDER=0 WIDTH=100%% BGCOLOR=#FFFFFF "
709 "CELLPADDING=1 CELLSPACING=0><TR><TD>");
712 * Learn the content type
714 strcpy(mime_content_type, "text/plain");
715 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
716 if (!strcmp(buf, "000")) {
717 wprintf("<I>unexpected end of message</I><br /><br />\n");
720 if (!strncasecmp(buf, "Content-type: ", 14)) {
721 safestrncpy(mime_content_type, &buf[14],
722 sizeof(mime_content_type));
723 for (i=0; i<strlen(mime_content_type); ++i) {
724 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
725 safestrncpy(mime_charset, &mime_content_type[i+8],
726 sizeof mime_charset);
729 for (i=0; i<strlen(mime_content_type); ++i) {
730 if (mime_content_type[i] == ';') {
731 mime_content_type[i] = 0;
737 /* Set up a character set conversion if we need to (and if we can) */
739 if ( (strcasecmp(mime_charset, "us-ascii"))
740 && (strcasecmp(mime_charset, "UTF-8")) ) {
741 ic = iconv_open("UTF-8", mime_charset);
742 if (ic == (iconv_t)(-1) ) {
743 lprintf(5, "iconv_open() failed: %s\n", strerror(errno));
748 /* Messages in legacy Citadel variformat get handled thusly... */
749 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
750 fmout(NULL, "JUSTIFY");
753 /* Boring old 80-column fixed format text gets handled this way... */
754 else if (!strcasecmp(mime_content_type, "text/plain")) {
755 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
756 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
757 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
760 if (ic != (iconv_t)(-1) ) {
762 ibuflen = strlen(ibuf);
764 obuf = (char *) malloc(obuflen);
766 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
767 osav[SIZ-obuflen] = 0;
768 safestrncpy(buf, osav, sizeof buf);
773 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
774 buf[strlen(buf) - 1] = 0;
776 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
777 wprintf("<BLOCKQUOTE>");
779 } else if ((bq == 1) &&
780 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
781 wprintf("</BLOCKQUOTE>");
787 wprintf("</TT><br />\n");
789 wprintf("</I><br />");
792 else /* HTML is fun, but we've got to strip it first */
793 if (!strcasecmp(mime_content_type, "text/html")) {
794 output_html(mime_charset);
797 /* Unknown weirdness */
799 wprintf("I don't know how to display %s<br />\n",
801 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
804 /* Afterwards, offer links to download attachments 'n' such */
805 if (strlen(mime_http) > 0) {
806 wprintf("%s", mime_http);
809 /* Handler for vCard parts */
810 if (strlen(vcard_partnum) > 0) {
811 part_source = load_mimepart(msgnum, vcard_partnum);
812 if (part_source != NULL) {
814 /* If it's my vCard I can edit it */
815 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
816 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
817 || (WC->wc_view == VIEW_ADDRESSBOOK)
819 wprintf("<A HREF=\"/edit_vcard?"
820 "msgnum=%ld?partnum=%s\">",
821 msgnum, vcard_partnum);
822 wprintf("[edit]</A>");
825 /* In all cases, display the full card */
826 display_vcard(part_source, 0, 1, NULL);
830 /* Handler for calendar parts */
831 if (strlen(cal_partnum) > 0) {
832 part_source = load_mimepart(msgnum, cal_partnum);
833 if (part_source != NULL) {
834 cal_process_attachment(part_source,
835 msgnum, cal_partnum);
845 wprintf("</TD></TR></TABLE>\n");
847 /* end everythingamundo table */
848 wprintf("</TD></TR></TABLE>\n");
849 wprintf("</div><br />\n");
852 if (ic != (iconv_t)(-1) ) {
861 * Unadorned HTML output of an individual message, suitable
862 * for placing in a hidden iframe, for printing, or whatever
864 void embed_message(void) {
870 msgnum = atol(bstr("msgnum"));
871 sourceiframe = bstr("sourceiframe");
872 targetdiv = bstr("targetdiv");
873 print_it = bstr("print_it");
875 output_headers(1, 0, 0, 0, 0, 1, 0);
878 wprintf("<html><head>");
880 /* If we're loading into a hidden iframe, chances are the caller told us
881 * about a target div somewhere that we need to copy into when we're done.
883 if (strlen(targetdiv) > 0) wprintf(
885 " <script type=\"text/javascript\"> \n"
886 " function loaded_now_copy_it() { \n"
887 " parent.document.getElementById(\"%s\").innerHTML = parent.frames['%s'].document.body.innerHTML; \n"
896 if (strlen(targetdiv) > 0) {
897 wprintf(" onLoad='loaded_now_copy_it();'");
899 if (!strcasecmp(print_it, "yes")) {
900 wprintf(" onLoad='window.print();'");
903 read_message(msgnum, (!strcasecmp(print_it, "yes") ? 1 : 0) );
904 wprintf("</body></html>\n");
911 void display_summarized(int num) {
915 if (WC->summ[num].is_new) wprintf("<B>");
916 wprintf("<A HREF=\"/msg?msgnum=%ld?sourceiframe=msgloader1?targetdiv=preview_pane\" target=\"msgloader1\">",
917 WC->summ[num].msgnum);
918 escputs(WC->summ[num].subj);
920 if (WC->summ[num].is_new) wprintf("</B>");
921 wprintf("</TD><TD>");
922 if (WC->summ[num].is_new) wprintf("<B>");
923 escputs(WC->summ[num].from);
924 if (WC->summ[num].is_new) wprintf("</B>");
925 wprintf(" </TD><TD>");
926 if (WC->summ[num].is_new) wprintf("<B>");
927 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
929 if (WC->summ[num].is_new) wprintf("</B>");
932 "<INPUT TYPE=\"checkbox\" NAME=\"msg_%ld\" VALUE=\"yes\">"
939 void summarize_message(int num, long msgnum, int is_new) {
942 memset(&WC->summ[num], 0, sizeof(struct message_summary));
943 safestrncpy(WC->summ[num].subj, "(no subject)", sizeof WC->summ[num].subj);
944 WC->summ[num].is_new = is_new;
945 WC->summ[num].msgnum = msgnum;
947 /* ask for headers only with no MIME */
948 sprintf(buf, "MSG0 %ld|3", msgnum);
950 serv_getln(buf, sizeof buf);
951 if (buf[0] != '1') return;
953 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
954 if (!strncasecmp(buf, "from=", 5)) {
955 safestrncpy(WC->summ[num].from, &buf[5], sizeof WC->summ[num].from);
957 if (!strncasecmp(buf, "subj=", 5)) {
958 if (strlen(&buf[5]) > 0) {
959 safestrncpy(WC->summ[num].subj, &buf[5],
960 sizeof WC->summ[num].subj);
962 /* Handle subjects with RFC2047 encoding */
963 utf8ify_rfc822_string(WC->summ[num].subj);
965 if (strlen(WC->summ[num].subj) > 75) {
966 strcpy(&WC->summ[num].subj[72], "...");
971 if (!strncasecmp(buf, "node=", 5)) {
972 if ( ((WC->room_flags & QR_NETWORK)
973 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
974 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
976 strcat(WC->summ[num].from, " @ ");
977 strcat(WC->summ[num].from, &buf[5]);
981 if (!strncasecmp(buf, "rcpt=", 5)) {
982 safestrncpy(WC->summ[num].to, &buf[5], sizeof WC->summ[num].to);
985 if (!strncasecmp(buf, "time=", 5)) {
986 WC->summ[num].date = atol(&buf[5]);
991 /* Handle senders with RFC2047 encoding */
992 utf8ify_rfc822_string(WC->summ[num].from);
994 if (strlen(WC->summ[num].from) > 25) {
995 strcpy(&WC->summ[num].from[22], "...");
1001 void display_addressbook(long msgnum, char alpha) {
1003 char mime_partnum[SIZ];
1004 char mime_filename[SIZ];
1005 char mime_content_type[SIZ];
1006 char mime_disposition[SIZ];
1008 char vcard_partnum[SIZ];
1009 char *vcard_source = NULL;
1010 struct message_summary summ;
1012 memset(&summ, 0, sizeof(summ));
1013 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1015 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1017 serv_getln(buf, sizeof buf);
1018 if (buf[0] != '1') return;
1020 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1021 if (!strncasecmp(buf, "part=", 5)) {
1022 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1023 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1024 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1025 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1026 mime_length = extract_int(&buf[5], 5);
1028 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1029 strcpy(vcard_partnum, mime_partnum);
1035 if (strlen(vcard_partnum) > 0) {
1036 vcard_source = load_mimepart(msgnum, vcard_partnum);
1037 if (vcard_source != NULL) {
1039 /* Display the summary line */
1040 display_vcard(vcard_source, alpha, 0, NULL);
1042 /* If it's my vCard I can edit it */
1043 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1044 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1045 || (WC->wc_view == VIEW_ADDRESSBOOK)
1047 wprintf("<A HREF=\"/edit_vcard?"
1048 "msgnum=%ld?partnum=%s\">",
1049 msgnum, vcard_partnum);
1050 wprintf("[edit]</A>");
1061 /* If it's an old "Firstname Lastname" style record, try to
1064 void lastfirst_firstlast(char *namebuf) {
1065 char firstname[SIZ];
1069 if (namebuf == NULL) return;
1070 if (strchr(namebuf, ';') != NULL) return;
1072 i = num_tokens(namebuf, ' ');
1075 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1076 remove_token(namebuf, i-1, ' ');
1077 strcpy(firstname, namebuf);
1078 sprintf(namebuf, "%s; %s", lastname, firstname);
1082 void fetch_ab_name(long msgnum, char *namebuf) {
1084 char mime_partnum[SIZ];
1085 char mime_filename[SIZ];
1086 char mime_content_type[SIZ];
1087 char mime_disposition[SIZ];
1089 char vcard_partnum[SIZ];
1090 char *vcard_source = NULL;
1092 struct message_summary summ;
1094 if (namebuf == NULL) return;
1095 strcpy(namebuf, "");
1097 memset(&summ, 0, sizeof(summ));
1098 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1100 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1102 serv_getln(buf, sizeof buf);
1103 if (buf[0] != '1') return;
1105 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1106 if (!strncasecmp(buf, "part=", 5)) {
1107 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1108 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1109 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1110 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1111 mime_length = extract_int(&buf[5], 5);
1113 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1114 strcpy(vcard_partnum, mime_partnum);
1120 if (strlen(vcard_partnum) > 0) {
1121 vcard_source = load_mimepart(msgnum, vcard_partnum);
1122 if (vcard_source != NULL) {
1124 /* Grab the name off the card */
1125 display_vcard(vcard_source, 0, 0, namebuf);
1131 lastfirst_firstlast(namebuf);
1133 for (i=0; i<strlen(namebuf); ++i) {
1134 if (namebuf[i] != ';') return;
1136 strcpy(namebuf, "(no name)");
1142 * Record compare function for sorting address book indices
1144 int abcmp(const void *ab1, const void *ab2) {
1146 (((const struct addrbookent *)ab1)->ab_name),
1147 (((const struct addrbookent *)ab2)->ab_name)
1153 * Helper function for do_addrbook_view()
1154 * Converts a name into a three-letter tab label
1156 void nametab(char *tabbuf, char *name) {
1157 stresc(tabbuf, name, 0, 0);
1158 tabbuf[0] = toupper(tabbuf[0]);
1159 tabbuf[1] = tolower(tabbuf[1]);
1160 tabbuf[2] = tolower(tabbuf[2]);
1166 * Render the address book using info we gathered during the scan
1168 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1172 static int NAMESPERPAGE = 60;
1176 char tabfirst_label[SIZ];
1178 char tablast_label[SIZ];
1181 wprintf("<I>This address book is empty.</I>\n");
1186 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1189 num_pages = num_ab / NAMESPERPAGE;
1191 page = atoi(bstr("page"));
1194 for (i=0; i<=num_pages; ++i) {
1196 wprintf("<A HREF=\"/readfwd?page=%d\">", i);
1201 tabfirst = i * NAMESPERPAGE;
1202 tablast = tabfirst + NAMESPERPAGE - 1;
1203 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1204 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1205 nametab(tablast_label, addrbook[tablast].ab_name);
1206 wprintf("[%s - %s]",
1207 tabfirst_label, tablast_label
1216 wprintf("<br />\n");
1218 wprintf("<TABLE border=0 cellspacing=0 "
1219 "cellpadding=3 width=100%%>\n"
1222 for (i=0; i<num_ab; ++i) {
1224 if ((i / NAMESPERPAGE) == page) {
1226 if ((displayed % 4) == 0) {
1227 if (displayed > 0) {
1231 wprintf("<TR BGCOLOR=\"#%s\">",
1232 (bg ? "DDDDDD" : "FFFFFF")
1238 wprintf("<A HREF=\"/readfwd?startmsg=%ld&is_singlecard=1",
1239 addrbook[i].ab_msgnum);
1240 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1241 vcard_n_prettyize(addrbook[i].ab_name);
1242 escputs(addrbook[i].ab_name);
1243 wprintf("</A></TD>\n");
1248 wprintf("</TR></TABLE>\n");
1254 * load message pointers from the server
1256 int load_msg_ptrs(char *servcmd)
1263 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1265 serv_getln(buf, sizeof buf);
1266 if (buf[0] != '1') {
1267 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1270 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1271 if (nummsgs < maxload) {
1272 WC->msgarr[nummsgs] = atol(buf);
1280 int summcmp_subj(const void *s1, const void *s2) {
1281 struct message_summary *summ1;
1282 struct message_summary *summ2;
1284 summ1 = (struct message_summary *)s1;
1285 summ2 = (struct message_summary *)s2;
1286 return strcasecmp(summ1->subj, summ2->subj);
1289 int summcmp_rsubj(const void *s1, const void *s2) {
1290 struct message_summary *summ1;
1291 struct message_summary *summ2;
1293 summ1 = (struct message_summary *)s1;
1294 summ2 = (struct message_summary *)s2;
1295 return strcasecmp(summ2->subj, summ1->subj);
1298 int summcmp_sender(const void *s1, const void *s2) {
1299 struct message_summary *summ1;
1300 struct message_summary *summ2;
1302 summ1 = (struct message_summary *)s1;
1303 summ2 = (struct message_summary *)s2;
1304 return strcasecmp(summ1->from, summ2->from);
1307 int summcmp_rsender(const void *s1, const void *s2) {
1308 struct message_summary *summ1;
1309 struct message_summary *summ2;
1311 summ1 = (struct message_summary *)s1;
1312 summ2 = (struct message_summary *)s2;
1313 return strcasecmp(summ2->from, summ1->from);
1316 int summcmp_date(const void *s1, const void *s2) {
1317 struct message_summary *summ1;
1318 struct message_summary *summ2;
1320 summ1 = (struct message_summary *)s1;
1321 summ2 = (struct message_summary *)s2;
1323 if (summ1->date < summ2->date) return -1;
1324 else if (summ1->date > summ2->date) return +1;
1328 int summcmp_rdate(const void *s1, const void *s2) {
1329 struct message_summary *summ1;
1330 struct message_summary *summ2;
1332 summ1 = (struct message_summary *)s1;
1333 summ2 = (struct message_summary *)s2;
1335 if (summ1->date < summ2->date) return +1;
1336 else if (summ1->date > summ2->date) return -1;
1341 * command loop for reading messages
1343 void readloop(char *oper)
1353 int num_displayed = 0;
1355 int is_addressbook = 0;
1356 int is_singlecard = 0;
1357 int is_calendar = 0;
1360 int remaining_messages;
1362 int lowest_displayed = (-1);
1363 int highest_displayed = 0;
1364 long pn_previous = 0L;
1365 long pn_current = 0L;
1368 struct addrbookent *addrbook = NULL;
1370 char *sortby = NULL;
1371 char sortpref_name[128];
1372 char sortpref_value[128];
1373 char *subjsort_button;
1374 char *sendsort_button;
1375 char *datesort_button;
1377 startmsg = atol(bstr("startmsg"));
1378 maxmsgs = atoi(bstr("maxmsgs"));
1379 is_summary = atoi(bstr("summary"));
1380 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1382 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
1383 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
1385 sortby = bstr("sortby");
1386 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
1387 set_preference(sortpref_name, sortby, 1);
1389 if (strlen(sortby) == 0) sortby = sortpref_value;
1390 if (strlen(sortby) == 0) sortby = "msgid";
1392 output_headers(1, 1, 1, 0, 0, 0, 0);
1394 /* When in summary mode, always show ALL messages instead of just
1395 * new or old. Otherwise, show what the user asked for.
1397 if (!strcmp(oper, "readnew")) {
1398 strcpy(cmd, "MSGS NEW");
1400 else if (!strcmp(oper, "readold")) {
1401 strcpy(cmd, "MSGS OLD");
1404 strcpy(cmd, "MSGS ALL");
1407 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
1409 strcpy(cmd, "MSGS ALL");
1412 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
1414 strcpy(cmd, "MSGS ALL");
1419 strcpy(cmd, "MSGS ALL");
1424 /* Are we doing a summary view? If so, we need to know old messages
1425 * and new messages, so we can do that pretty boldface thing for the
1428 strcpy(old_msgs, "");
1431 serv_getln(buf, sizeof buf);
1432 if (buf[0] == '2') {
1433 strcpy(old_msgs, &buf[4]);
1437 is_singlecard = atoi(bstr("is_singlecard"));
1439 if (WC->wc_view == VIEW_CALENDAR) { /* calendar */
1441 strcpy(cmd, "MSGS ALL");
1444 if (WC->wc_view == VIEW_TASKS) { /* tasks */
1446 strcpy(cmd, "MSGS ALL");
1449 if (WC->wc_view == VIEW_NOTES) { /* notes */
1451 strcpy(cmd, "MSGS ALL");
1455 nummsgs = load_msg_ptrs(cmd);
1458 if ((!is_tasks) && (!is_calendar) && (!is_notes)) {
1459 if (!strcmp(oper, "readnew")) {
1460 wprintf("<EM>No new messages.</EM>\n");
1461 } else if (!strcmp(oper, "readold")) {
1462 wprintf("<EM>No old messages.</EM>\n");
1464 wprintf("<EM>No messages here.</EM>\n");
1472 if (WC->num_summ != 0) {
1476 WC->num_summ = nummsgs;
1477 WC->summ = malloc(WC->num_summ*sizeof(struct message_summary));
1478 for (a = 0; a < nummsgs; ++a) {
1479 /* Gather summary information */
1480 summarize_message(a, WC->msgarr[a], is_new);
1482 /* Are you a new message, or an old message? */
1484 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
1485 WC->summ[a].is_new = 0;
1488 WC->summ[a].is_new = 1;
1494 if (startmsg == 0L) startmsg = WC->msgarr[0];
1495 remaining_messages = 0;
1497 for (a = 0; a < nummsgs; ++a) {
1498 if (WC->msgarr[a] >= startmsg) {
1499 ++remaining_messages;
1504 if (!strcasecmp(sortby, "subject")) {
1505 qsort(WC->summ, WC->num_summ,
1506 sizeof(struct message_summary), summcmp_subj);
1508 else if (!strcasecmp(sortby, "rsubject")) {
1509 qsort(WC->summ, WC->num_summ,
1510 sizeof(struct message_summary), summcmp_rsubj);
1512 else if (!strcasecmp(sortby, "sender")) {
1513 qsort(WC->summ, WC->num_summ,
1514 sizeof(struct message_summary), summcmp_sender);
1516 else if (!strcasecmp(sortby, "rsender")) {
1517 qsort(WC->summ, WC->num_summ,
1518 sizeof(struct message_summary), summcmp_rsender);
1520 else if (!strcasecmp(sortby, "date")) {
1521 qsort(WC->summ, WC->num_summ,
1522 sizeof(struct message_summary), summcmp_date);
1524 else if (!strcasecmp(sortby, "rdate")) {
1525 qsort(WC->summ, WC->num_summ,
1526 sizeof(struct message_summary), summcmp_rdate);
1530 if (!strcasecmp(sortby, "subject")) {
1531 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1533 else if (!strcasecmp(sortby, "rsubject")) {
1534 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1537 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1540 if (!strcasecmp(sortby, "sender")) {
1541 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1543 else if (!strcasecmp(sortby, "rsender")) {
1544 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1547 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1550 if (!strcasecmp(sortby, "date")) {
1551 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1553 else if (!strcasecmp(sortby, "rdate")) {
1554 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1557 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1561 wprintf("</div>"); /* end of 'content' div */
1563 wprintf("<div id=\"message_list\">"
1565 "<div id=\"fix_scrollbar_bug\">\n"
1567 "<form name=\"msgomatic\" "
1568 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n"
1570 "<table border=0 cellspacing=0 "
1571 "cellpadding=0 width=100%%>\n"
1573 "<TD align=center><b><i>Subject</i></b> %s</TD>"
1574 "<TD align=center><b><i>Sender</i></b> %s</TD>"
1575 "<TD align=center><b><i>Date</i></b> %s</TD>"
1576 "<TD><INPUT TYPE=\"submit\" NAME=\"sc\" "
1577 "STYLE=\"font-family: Bitstream Vera Sans,Arial,Helvetica,sans-serif;"
1578 " font-size: 6pt;\" "
1579 "VALUE=\"Delete\"></TD>"
1588 for (a = 0; a < nummsgs; ++a) {
1589 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
1591 /* Learn which msgs "Prev" & "Next" buttons go to */
1592 pn_current = WC->msgarr[a];
1593 if (a > 0) pn_previous = WC->msgarr[a-1];
1594 if (a < (nummsgs-1)) pn_next = WC->msgarr[a+1];
1596 /* If a tabular view, set up the line */
1599 wprintf("<TR BGCOLOR=\"#%s\">",
1600 (bg ? "DDDDDD" : "FFFFFF")
1604 /* Display the message */
1606 display_summarized(a);
1608 else if (is_addressbook) {
1609 fetch_ab_name(WC->msgarr[a], buf);
1611 addrbook = realloc(addrbook,
1612 (sizeof(struct addrbookent) * num_ab) );
1613 safestrncpy(addrbook[num_ab-1].ab_name, buf,
1614 sizeof(addrbook[num_ab-1].ab_name));
1615 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
1617 else if (is_calendar) {
1618 display_calendar(WC->msgarr[a]);
1620 else if (is_tasks) {
1621 display_task(WC->msgarr[a]);
1623 else if (is_notes) {
1624 display_note(WC->msgarr[a]);
1627 read_message(WC->msgarr[a], 0);
1630 /* If a tabular view, finish the line */
1635 if (lowest_displayed < 0) lowest_displayed = a;
1636 highest_displayed = a;
1639 --remaining_messages;
1644 wprintf("</table></form>"
1645 "</div>\n"); /* end of 'fix_scrollbar_bug' div */
1646 wprintf("</div>"); /* end of 'message_list' div */
1648 wprintf("<div id=\"preview_pane\">"); /* The preview pane will initially be empty */
1651 /* Bump these because although we're thinking in zero base, the user
1652 * is a drooling idiot and is thinking in one base.
1655 ++highest_displayed;
1657 /* If we're only looking at one message, do a prev/next thing */
1658 if (num_displayed == 1) {
1659 if ((!is_tasks) && (!is_calendar) && (!is_addressbook) && (!is_notes) && (!is_singlecard)) {
1661 wprintf("<div id=\"fix_scrollbar_bug\">"
1662 "<table border=0 width=100%% bgcolor=\"#dddddd\"><tr><td>"
1663 "Reading #%d of %d messages.</TD>\n"
1664 "<TD ALIGN=RIGHT><FONT SIZE=+1>",
1665 lowest_displayed, nummsgs);
1667 if (pn_previous > 0L) {
1668 wprintf("<A HREF=\"/%s"
1678 wprintf("<A HREF=\"/%s"
1687 wprintf("<A HREF=\"/%s?startmsg=%ld"
1688 "?maxmsgs=%d?summary=1\">"
1696 wprintf("</td></tr></table></div>\n");
1701 * If we're not currently looking at ALL requested
1702 * messages, then display the selector bar
1704 if (num_displayed > 1) {
1705 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
1706 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
1708 wprintf("<form name=\"msgomatic\" "
1709 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n");
1711 wprintf("Reading #", lowest_displayed, highest_displayed);
1713 wprintf("<select name=\"whichones\" size=\"1\" "
1714 "OnChange=\"location.href=msgomatic.whichones.options"
1715 "[selectedIndex].value\">\n");
1717 for (b=0; b<nummsgs; b = b + maxmsgs) {
1720 if (hi > nummsgs) hi = nummsgs;
1721 wprintf("<option %s value="
1726 "%d-%d</option> \n",
1727 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
1734 wprintf("<option value=\"/%s?startmsg=%ld"
1735 "?maxmsgs=9999999?summary=%d\">"
1739 WC->msgarr[0], is_summary);
1741 wprintf("</select> of %d messages.", nummsgs);
1742 wprintf("</form>\n");
1748 do_tasks_view(); /* Render the task list */
1752 do_calendar_view(); /* Render the calendar */
1755 if (is_addressbook) {
1756 do_addrbook_view(addrbook, num_ab); /* Render the address book */
1759 /* Put the data transfer hidden iframe in a hidden div, to make it *really* hidden */
1761 "<div display=\"hidden\">\n"
1762 "<iframe name=\"msgloader1\" id=\"msgloader1\" width=\"1\"></iframe>\n"
1765 /* Note: wDumpContent() will output one additional </div> tag. */
1767 if (addrbook != NULL) free(addrbook);
1769 /* free the summary */
1770 if (WC->num_summ != 0) {
1775 /* If we got here via a mailbox view and are reading a single
1776 * message, mark it as "seen." We do this after rendering the web page
1777 * so it doesn't keep the user waiting.
1779 if ( (maxmsgs == 1) && (WC->wc_view == VIEW_MAILBOX) ) {
1780 serv_printf("SEEN %ld|1", startmsg);
1781 serv_getln(buf, sizeof buf);
1787 * Back end for post_message() ... this is where the actual message
1788 * gets transmitted to the server.
1790 void post_mime_to_server(void) {
1792 int is_multipart = 0;
1794 struct wc_attachment *att;
1796 size_t encoded_length;
1798 /* If there are attachments, we have to do multipart/mixed */
1799 if (WC->first_attachment != NULL) {
1804 sprintf(boundary, "---Citadel-Multipart-%s-%04x%04x---",
1805 serv_info.serv_fqdn,
1810 /* Remember, serv_printf() appends an extra newline */
1811 serv_printf("Content-type: multipart/mixed; "
1812 "boundary=\"%s\"\n", boundary);
1813 serv_printf("This is a multipart message in MIME format.\n");
1814 serv_printf("--%s", boundary);
1817 serv_puts("Content-type: text/html; charset=utf-8");
1819 serv_puts("<HTML><BODY>\n");
1820 text_to_server(bstr("msgtext"), 0);
1821 serv_puts("</BODY></HTML>\n");
1826 /* Add in the attachments */
1827 for (att = WC->first_attachment; att!=NULL; att=att->next) {
1829 encoded_length = ((att->length * 150) / 100);
1830 encoded = malloc(encoded_length);
1831 if (encoded == NULL) break;
1832 CtdlEncodeBase64(encoded, att->data, att->length);
1834 serv_printf("--%s", boundary);
1835 serv_printf("Content-type: %s", att->content_type);
1836 serv_printf("Content-disposition: attachment; "
1837 "filename=\"%s\"", att->filename);
1838 serv_puts("Content-transfer-encoding: base64");
1840 serv_write(encoded, strlen(encoded));
1845 serv_printf("--%s--", boundary);
1853 * Post message (or don't post message)
1855 * Note regarding the "dont_post" variable:
1856 * A random value (actually, it's just a timestamp) is inserted as a hidden
1857 * field called "postseq" when the display_enter page is generated. This
1858 * value is checked when posting, using the static variable dont_post. If a
1859 * user attempts to post twice using the same dont_post value, the message is
1860 * discarded. This prevents the accidental double-saving of the same message
1861 * if the user happens to click the browser "back" button.
1863 void post_message(void)
1866 static long dont_post = (-1L);
1867 struct wc_attachment *att, *aptr;
1869 if (WC->upload_length > 0) {
1871 /* There's an attachment. Save it to this struct... */
1872 att = malloc(sizeof(struct wc_attachment));
1873 memset(att, 0, sizeof(struct wc_attachment));
1874 att->length = WC->upload_length;
1875 strcpy(att->content_type, WC->upload_content_type);
1876 strcpy(att->filename, WC->upload_filename);
1879 /* And add it to the list. */
1880 if (WC->first_attachment == NULL) {
1881 WC->first_attachment = att;
1884 aptr = WC->first_attachment;
1885 while (aptr->next != NULL) aptr = aptr->next;
1889 /* Netscape sends a simple filename, which is what we want,
1890 * but Satan's browser sends an entire pathname. Reduce
1891 * the path to just a filename if we need to.
1893 while (num_tokens(att->filename, '/') > 1) {
1894 remove_token(att->filename, 0, '/');
1896 while (num_tokens(att->filename, '\\') > 1) {
1897 remove_token(att->filename, 0, '\\');
1900 /* Transfer control of this memory from the upload struct
1901 * to the attachment struct.
1903 att->data = WC->upload;
1904 WC->upload_length = 0;
1910 if (!strcasecmp(bstr("sc"), "Cancel")) {
1911 sprintf(WC->ImportantMessage,
1912 "Cancelled. Message was not posted.");
1913 } else if (!strcasecmp(bstr("attach"), "Add")) {
1916 } else if (atol(bstr("postseq")) == dont_post) {
1917 sprintf(WC->ImportantMessage,
1918 "Automatically cancelled because you have already "
1919 "saved this message.");
1921 sprintf(buf, "ENT0 1|%s|0|4|%s",
1925 serv_getln(buf, sizeof buf);
1926 if (buf[0] == '4') {
1927 post_mime_to_server();
1928 if (strlen(bstr("recp")) > 0) {
1929 sprintf(WC->ImportantMessage, "Message has been sent.\n");
1932 sprintf(WC->ImportantMessage, "Message has been posted.\n");
1934 dont_post = atol(bstr("postseq"));
1936 sprintf(WC->ImportantMessage,
1941 free_attachments(WC);
1942 readloop("readnew");
1949 * display the message entry screen
1951 void display_enter(void)
1955 struct wc_attachment *att;
1957 if (strlen(bstr("force_room")) > 0) {
1958 gotoroom(bstr("force_room"));
1961 /* Are we perhaps in an address book view? If so, then an "enter
1962 * message" command really means "add new entry."
1964 if (WC->wc_view == VIEW_ADDRESSBOOK) {
1965 do_edit_vcard(-1, "", "");
1969 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1970 /* Are we perhaps in a calendar view? If so, then an "enter
1971 * message" command really means "add new calendar item."
1973 if (WC->wc_view == VIEW_CALENDAR) {
1974 display_edit_event();
1978 /* Are we perhaps in a tasks view? If so, then an "enter
1979 * message" command really means "add new task."
1981 if (WC->wc_view == VIEW_TASKS) {
1982 display_edit_task();
1987 /* Otherwise proceed normally. Do a custom room banner with no navbar... */
1988 output_headers(1, 1, 2, 0, 0, 0, 0);
1989 wprintf("<div id=\"banner\">\n");
1990 embed_room_banner(NULL, navbar_none);
1991 wprintf("</div>\n");
1992 wprintf("<div id=\"content\">\n"
1993 "<div id=\"fix_scrollbar_bug\">"
1994 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
1996 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
1998 serv_getln(buf, sizeof buf);
2000 if (!strncmp(buf, "570", 3)) {
2001 if (strlen(bstr("recp")) > 0) {
2002 svprintf("RECPERROR", WCS_STRING,
2003 "<SPAN CLASS=\"errormsg\">%s</SPAN><br />\n",
2007 do_template("prompt_for_recipient");
2010 if (buf[0] != '2') {
2011 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2016 fmt_date(buf, now, 0);
2017 strcat(&buf[strlen(buf)], " <I>from</I> ");
2018 stresc(&buf[strlen(buf)], WC->wc_username, 1, 1);
2019 if (strlen(bstr("recp")) > 0) {
2020 strcat(&buf[strlen(buf)], " <I>to</I> ");
2021 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
2023 strcat(&buf[strlen(buf)], " <I>in</I> ");
2024 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
2026 /* begin message entry screen */
2027 // wprintf("<div style=\"position:absolute; left:1%%; width:96%%; height:100%%\">\n");
2029 wprintf("<form enctype=\"multipart/form-data\" "
2030 "method=\"POST\" action=\"/post\" "
2031 "name=\"enterform\""
2032 "onSubmit=\"return submitForm();\""
2034 wprintf("<input type=\"hidden\" name=\"recp\" value=\"%s\">\n",
2036 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n",
2039 wprintf("%s<br>\n", buf); /* header bar */
2040 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2041 /* "onLoad=\"document.enterform.msgtext.focus();\" " */
2042 wprintf("<font size=-1>Subject (optional):</font>"
2043 "<input type=\"text\" name=\"subject\" value=\"");
2044 escputs(bstr("subject"));
2045 wprintf("\" size=40 maxlength=70>"
2049 wprintf("<input type=\"submit\" name=\"sc\" value=\"");
2050 if (strlen(bstr("recp")) > 0) {
2051 wprintf("Send message");
2053 wprintf("Post message");
2056 "<input type=\"submit\" name=\"sc\" value=\"Cancel\">\n");
2058 wprintf("<center><script type=\"text/javascript\" "
2059 "src=\"static/richtext.js\"></script>\n"
2060 "<script type=\"text/javascript\">\n"
2061 "function submitForm() { \n"
2062 " updateRTE('msgtext'); \n"
2066 "initRTE(\"static/\", \"static/\", \"\"); \n"
2068 "<noscript>JavaScript must be enabled.</noscript> \n"
2069 "<script type=\"text/javascript\"> \n"
2070 "writeRichText('msgtext', '");
2071 msgescputs(bstr("msgtext"));
2072 wprintf("', '96%%', '200', true, false); \n"
2073 "</script></center><br />\n");
2075 /* Enumerate any attachments which are already in place... */
2076 wprintf("<img src=\"/static/diskette_24x.gif\" border=0 "
2077 "align=middle height=16 width=16> Attachments: ");
2078 wprintf("<select name=\"which_attachment\" size=1>");
2079 for (att = WC->first_attachment; att != NULL; att = att->next) {
2080 wprintf("<option value=\"");
2081 urlescputs(att->filename);
2083 escputs(att->filename);
2084 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
2085 wprintf("</option>\n");
2087 wprintf("</select>");
2089 /* Now offer the ability to attach additional files... */
2090 wprintf(" "
2091 "Attach file: <input NAME=\"attachfile\" "
2092 "SIZE=16 TYPE=\"file\">\n "
2093 "<input type=\"submit\" name=\"attach\" value=\"Add\">\n");
2095 wprintf("</form>\n");
2097 wprintf("</td></tr></table></div>\n");
2098 DONE: wDumpContent(1);
2108 void delete_msg(void)
2113 msgid = atol(bstr("msgid"));
2115 output_headers(1, 1, 1, 0, 0, 0, 0);
2117 sprintf(buf, "DELE %ld", msgid);
2119 serv_getln(buf, sizeof buf);
2120 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2129 * Confirm move of a message
2131 void confirm_move_msg(void)
2137 msgid = atol(bstr("msgid"));
2139 output_headers(1, 1, 1, 0, 0, 0, 0);
2141 wprintf("<div id=\"fix_scrollbar_bug\">"
2142 "<table width=100%% border=0 bgcolor=\"#444455\"><tr><td>");
2143 wprintf("<font size=+1 color=\"#ffffff\"");
2144 wprintf("<b>Confirm move of message</b>\n");
2145 wprintf("</font></td></tr></table></div>\n");
2147 wprintf("<CENTER>");
2149 wprintf("Move this message to:<br />\n");
2151 wprintf("<form METHOD=\"POST\" ACTION=\"/move_msg\">\n");
2152 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
2156 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
2158 serv_getln(buf, sizeof buf);
2159 if (buf[0] == '1') {
2160 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2161 extract_token(targ, buf, 0, '|', sizeof targ);
2162 wprintf("<OPTION>");
2167 wprintf("</SELECT>\n");
2168 wprintf("<br />\n");
2170 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
2172 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
2173 wprintf("</form></CENTER>\n");
2175 wprintf("</CENTER>\n");
2186 msgid = atol(bstr("msgid"));
2188 output_headers(1, 1, 1, 0, 0, 0, 0);
2190 if (!strcasecmp(bstr("yesno"), "Move")) {
2191 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
2193 serv_getln(buf, sizeof buf);
2194 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2196 wprintf("<EM>Message not moved.</EM><br />\n");
2203 * This gets called when a user selects multiple messages in a summary
2204 * list and then clicks to perform a transformation of some sort on them
2205 * (such as deleting them).
2207 void do_stuff_to_msgs(void) {
2212 struct stuff_t *next;
2216 struct stuff_t *stuff = NULL;
2217 struct stuff_t *ptr;
2220 serv_puts("MSGS ALL");
2221 serv_getln(buf, sizeof buf);
2223 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2224 ptr = malloc(sizeof(struct stuff_t));
2225 ptr->msgnum = atol(buf);
2230 strcpy(sc, bstr("sc"));
2232 while (stuff != NULL) {
2234 sprintf(buf, "msg_%ld", stuff->msgnum);
2235 if (!strcasecmp(bstr(buf), "yes")) {
2237 if (!strcasecmp(sc, "Delete")) {
2238 serv_printf("DELE %ld", stuff->msgnum);
2239 serv_getln(buf, sizeof buf);
2249 readloop("readfwd");