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=");
328 urlesc(&mailto[strlen(mailto)], thisvalue);
329 strcat(mailto, "\">");
330 urlesc(&mailto[strlen(mailto)], thisvalue);
331 strcat(mailto, "</A>");
333 else if (!strcasecmp(firsttoken, "tel")) {
334 if (strlen(phone) > 0) strcat(phone, "<br />");
335 strcat(phone, thisvalue);
336 for (j=0; j<num_tokens(thisname, ';'); ++j) {
337 extract_token(buf, thisname, j, ';', sizeof buf);
338 if (!strcasecmp(buf, "tel"))
340 else if (!strcasecmp(buf, "work"))
341 strcat(phone, " (work)");
342 else if (!strcasecmp(buf, "home"))
343 strcat(phone, " (home)");
344 else if (!strcasecmp(buf, "cell"))
345 strcat(phone, " (cell)");
353 else if (!strcasecmp(firsttoken, "adr")) {
355 wprintf("<TR><TD>Address:</TD><TD>");
356 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
357 extract_token(buf, thisvalue, j, ';', sizeof buf);
358 if (strlen(buf) > 0) {
360 if (j<3) wprintf("<br />");
364 wprintf("</TD></TR>\n");
367 else if (!strcasecmp(firsttoken, "version")) {
370 else if (!strcasecmp(firsttoken, "rev")) {
373 else if (!strcasecmp(firsttoken, "label")) {
378 /*** Don't show extra fields. They're ugly.
382 wprintf("</TD><TD>");
384 wprintf("</TD></TR>\n");
394 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
395 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
396 "<IMG ALIGN=CENTER SRC=\"/static/viewcontacts_48x.gif\">"
397 "<FONT SIZE=+1><B>");
398 escputs(displayname);
399 wprintf("</B></FONT>");
400 if (strlen(title) > 0) {
401 wprintf("<div align=right>");
405 if (strlen(org) > 0) {
406 wprintf("<div align=right>");
410 wprintf("</TD></TR>\n");
412 if (strlen(phone) > 0)
413 wprintf("<TR><TD>Telephone:</TD><TD>%s</TD></TR>\n", phone);
414 if (strlen(mailto) > 0)
415 wprintf("<TR><TD>E-mail:</TD><TD>%s</TD></TR>\n", mailto);
420 wprintf("</table></div>\n");
426 * Display a textual vCard
427 * (Converts to a vCard object and then calls the actual display function)
428 * Set 'full' to nonzero to display the whole card instead of a one-liner.
429 * Or, if "storename" is non-NULL, just store the person's name in that
430 * buffer instead of displaying the card at all.
432 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
438 v = vcard_load(vcard_source);
439 if (v == NULL) return;
441 name = vcard_get_prop(v, "n", 1, 0, 0);
447 if (storename != NULL) {
448 fetchname_parsed_vcard(v, storename);
450 else if ( (alpha == 0)
451 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
452 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
454 display_parsed_vcard(v, full);
464 * I wanna SEE that message!
466 void read_message(long msgnum, int suppress_buttons) {
468 char mime_partnum[256];
469 char mime_filename[256];
470 char mime_content_type[256];
471 char mime_charset[256];
472 char mime_disposition[256];
485 char vcard_partnum[256];
486 char cal_partnum[256];
487 char *part_source = NULL;
489 iconv_t ic = (iconv_t)(-1) ;
490 char *ibuf; /* Buffer of characters to be converted */
491 char *obuf; /* Buffer for converted characters */
492 size_t ibuflen; /* Length of input buffer */
493 size_t obuflen; /* Length of output buffer */
494 char *osav; /* Saved pointer to output buffer */
500 strcpy(reply_to, "");
501 strcpy(vcard_partnum, "");
502 strcpy(cal_partnum, "");
503 strcpy(mime_http, "");
504 strcpy(mime_content_type, "text/plain");
505 strcpy(mime_charset, "us-ascii");
507 serv_printf("MSG4 %ld", msgnum);
508 serv_getln(buf, sizeof buf);
510 wprintf("<STRONG>ERROR:</STRONG> %s<br />\n", &buf[4]);
514 /* begin everythingamundo table */
515 wprintf("<div id=\"fix_scrollbar_bug\">\n");
516 wprintf("<table width=100%% border=1 cellspacing=0 "
517 "cellpadding=0><TR><TD>\n");
519 /* begin message header table */
520 wprintf("<TABLE WIDTH=100%% BORDER=0 CELLSPACING=0 "
521 "CELLPADDING=1 BGCOLOR=\"#CCCCCC\"><TR><TD>\n");
523 wprintf("<SPAN CLASS=\"message_header\">");
524 strcpy(m_subject, "");
526 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
527 if (!strcmp(buf, "000")) {
528 wprintf("<I>unexpected end of message</I><br /><br />\n");
529 wprintf("</SPAN>\n");
532 if (!strncasecmp(buf, "nhdr=yes", 8))
536 if (!strncasecmp(buf, "type=", 5))
537 format_type = atoi(&buf[5]);
538 if (!strncasecmp(buf, "from=", 5)) {
539 strcpy(from, &buf[5]);
540 wprintf("from <A HREF=\"/showuser?who=");
542 utf8ify_rfc822_string(from);
549 if (!strncasecmp(buf, "subj=", 5))
550 strcpy(m_subject, &buf[5]);
551 if ((!strncasecmp(buf, "hnod=", 5))
552 && (strcasecmp(&buf[5], serv_info.serv_humannode)))
553 wprintf("(%s) ", &buf[5]);
554 if ((!strncasecmp(buf, "room=", 5))
555 && (strcasecmp(&buf[5], WC->wc_roomname))
556 && (strlen(&buf[5])>0) )
557 wprintf("in %s> ", &buf[5]);
558 if (!strncasecmp(buf, "rfca=", 5)) {
559 strcpy(rfca, &buf[5]);
565 if (!strncasecmp(buf, "node=", 5)) {
566 strcpy(node, &buf[5]);
567 if ( ((WC->room_flags & QR_NETWORK)
568 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
569 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
572 wprintf("@%s ", &buf[5]);
575 if (!strncasecmp(buf, "rcpt=", 5))
576 wprintf("to %s ", &buf[5]);
577 if (!strncasecmp(buf, "time=", 5)) {
578 fmt_date(now, atol(&buf[5]), 0);
582 if (!strncasecmp(buf, "part=", 5)) {
583 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
584 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
585 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
586 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
587 mime_length = extract_int(&buf[5], 5);
589 if (!strcasecmp(mime_disposition, "attachment")) {
590 snprintf(&mime_http[strlen(mime_http)],
591 (sizeof(mime_http) - strlen(mime_http) - 1),
592 "<A HREF=\"/output_mimepart?"
593 "msgnum=%ld?partnum=%s\" "
594 "TARGET=\"wc.%ld.%s\">"
595 "<IMG SRC=\"/static/diskette_24x.gif\" "
596 "BORDER=0 ALIGN=MIDDLE>\n"
597 "Part %s: %s (%s, %d bytes)</A><br />\n",
598 msgnum, mime_partnum,
599 msgnum, mime_partnum,
600 mime_partnum, mime_filename,
601 mime_content_type, mime_length);
604 if ((!strcasecmp(mime_disposition, "inline"))
605 && (!strncasecmp(mime_content_type, "image/", 6)) ){
606 snprintf(&mime_http[strlen(mime_http)],
607 (sizeof(mime_http) - strlen(mime_http) - 1),
608 "<IMG SRC=\"/output_mimepart?"
609 "msgnum=%ld?partnum=%s\">",
610 msgnum, mime_partnum);
613 /*** begin handler prep ***/
614 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
615 strcpy(vcard_partnum, mime_partnum);
618 if (!strcasecmp(mime_content_type, "text/calendar")) {
619 strcpy(cal_partnum, mime_partnum);
622 /*** end handler prep ***/
628 /* Generate a reply-to address */
629 if (strlen(rfca) > 0) {
630 strcpy(reply_to, rfca);
633 if ( (strlen(node) > 0)
634 && (strcasecmp(node, serv_info.serv_nodename))
635 && (strcasecmp(node, serv_info.serv_humannode)) ) {
636 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
640 snprintf(reply_to, sizeof(reply_to), "%s", from);
650 utf8ify_rfc822_string(m_subject);
652 if (strlen(m_subject) > 0) {
654 "<SPAN CLASS=\"message_subject\">"
661 /* start msg buttons */
662 if (!suppress_buttons) {
663 wprintf("<td align=right>\n");
666 wprintf("<a href=\"/display_enter?recp=");
667 urlescputs(reply_to);
668 wprintf("?subject=");
669 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
670 urlescputs(m_subject);
671 wprintf("\">[Reply]</a> ");
673 if (WC->is_room_aide) {
676 wprintf("<a href=\"/confirm_move_msg?msgid=%ld\">[Move]</a> ",
680 wprintf("<a href=\"/delete_msg?msgid=%ld\" "
681 "onClick=\"return confirm('Delete this message?');\">"
682 "[Delete]</a> ", msgnum);
686 wprintf("<a href=\"/msg?msgnum=%ld?print_it=yes\" target=\"msgloader1\">"
687 "[Print]</a>", msgnum);
692 wprintf("</TR></TABLE>\n");
695 wprintf("<TABLE BORDER=0 WIDTH=100%% BGCOLOR=#FFFFFF "
696 "CELLPADDING=1 CELLSPACING=0><TR><TD>");
699 * Learn the content type
701 strcpy(mime_content_type, "text/plain");
702 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
703 if (!strcmp(buf, "000")) {
704 wprintf("<I>unexpected end of message</I><br /><br />\n");
707 if (!strncasecmp(buf, "Content-type: ", 14)) {
708 safestrncpy(mime_content_type, &buf[14],
709 sizeof(mime_content_type));
710 for (i=0; i<strlen(mime_content_type); ++i) {
711 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
712 safestrncpy(mime_charset, &mime_content_type[i+8],
713 sizeof mime_charset);
716 for (i=0; i<strlen(mime_content_type); ++i) {
717 if (mime_content_type[i] == ';') {
718 mime_content_type[i] = 0;
724 /* Set up a character set conversion if we need to (and if we can) */
726 if ( (strcasecmp(mime_charset, "us-ascii"))
727 && (strcasecmp(mime_charset, "UTF-8")) ) {
728 ic = iconv_open("UTF-8", mime_charset);
729 if (ic == (iconv_t)(-1) ) {
730 lprintf(5, "iconv_open() failed: %s\n", strerror(errno));
735 /* Messages in legacy Citadel variformat get handled thusly... */
736 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
737 fmout(NULL, "JUSTIFY");
740 /* Boring old 80-column fixed format text gets handled this way... */
741 else if (!strcasecmp(mime_content_type, "text/plain")) {
742 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
743 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
744 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
747 if (ic != (iconv_t)(-1) ) {
749 ibuflen = strlen(ibuf);
751 obuf = (char *) malloc(obuflen);
753 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
754 osav[SIZ-obuflen] = 0;
755 safestrncpy(buf, osav, sizeof buf);
760 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
761 buf[strlen(buf) - 1] = 0;
763 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
764 wprintf("<BLOCKQUOTE>");
766 } else if ((bq == 1) &&
767 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
768 wprintf("</BLOCKQUOTE>");
774 wprintf("</TT><br />\n");
776 wprintf("</I><br />");
779 else /* HTML is fun, but we've got to strip it first */
780 if (!strcasecmp(mime_content_type, "text/html")) {
781 output_html(mime_charset);
784 /* Unknown weirdness */
786 wprintf("I don't know how to display %s<br />\n",
788 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
791 /* Afterwards, offer links to download attachments 'n' such */
792 if (strlen(mime_http) > 0) {
793 wprintf("%s", mime_http);
796 /* Handler for vCard parts */
797 if (strlen(vcard_partnum) > 0) {
798 part_source = load_mimepart(msgnum, vcard_partnum);
799 if (part_source != NULL) {
801 /* If it's my vCard I can edit it */
802 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
803 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
804 || (WC->wc_view == VIEW_ADDRESSBOOK)
806 wprintf("<A HREF=\"/edit_vcard?"
807 "msgnum=%ld?partnum=%s\">",
808 msgnum, vcard_partnum);
809 wprintf("[edit]</A>");
812 /* In all cases, display the full card */
813 display_vcard(part_source, 0, 1, NULL);
817 /* Handler for calendar parts */
818 if (strlen(cal_partnum) > 0) {
819 part_source = load_mimepart(msgnum, cal_partnum);
820 if (part_source != NULL) {
821 cal_process_attachment(part_source,
822 msgnum, cal_partnum);
832 wprintf("</TD></TR></TABLE>\n");
834 /* end everythingamundo table */
835 wprintf("</TD></TR></TABLE>\n");
836 wprintf("</div><br />\n");
839 if (ic != (iconv_t)(-1) ) {
848 * Unadorned HTML output of an individual message, suitable
849 * for placing in a hidden iframe, for printing, or whatever
851 void embed_message(void) {
857 msgnum = atol(bstr("msgnum"));
858 sourceiframe = bstr("sourceiframe");
859 targetdiv = bstr("targetdiv");
860 print_it = bstr("print_it");
862 output_headers(1, 0, 0, 0, 0, 1, 0);
865 wprintf("<html><head>");
867 /* If we're loading into a hidden iframe, chances are the caller told us
868 * about a target div somewhere that we need to copy into when we're done.
870 if (strlen(targetdiv) > 0) wprintf(
872 " <script type=\"text/javascript\"> \n"
873 " function loaded_now_copy_it() { \n"
874 " parent.document.getElementById(\"%s\").innerHTML = parent.frames['%s'].document.body.innerHTML; \n"
883 if (strlen(targetdiv) > 0) {
884 wprintf(" onLoad='loaded_now_copy_it();'");
886 if (!strcasecmp(print_it, "yes")) {
887 wprintf(" onLoad='window.print();'");
890 read_message(msgnum, (!strcasecmp(print_it, "yes") ? 1 : 0) );
891 wprintf("</body></html>\n");
898 void display_summarized(int num) {
902 if (WC->summ[num].is_new) wprintf("<B>");
903 wprintf("<A HREF=\"/msg?msgnum=%ld?sourceiframe=msgloader1?targetdiv=preview_pane\" target=\"msgloader1\">",
904 WC->summ[num].msgnum);
905 escputs(WC->summ[num].subj);
907 if (WC->summ[num].is_new) wprintf("</B>");
908 wprintf("</TD><TD>");
909 if (WC->summ[num].is_new) wprintf("<B>");
910 escputs(WC->summ[num].from);
911 if (WC->summ[num].is_new) wprintf("</B>");
912 wprintf(" </TD><TD>");
913 if (WC->summ[num].is_new) wprintf("<B>");
914 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
916 if (WC->summ[num].is_new) wprintf("</B>");
919 "<INPUT TYPE=\"checkbox\" NAME=\"msg_%ld\" VALUE=\"yes\">"
929 void display_addressbook(long msgnum, char alpha) {
931 char mime_partnum[SIZ];
932 char mime_filename[SIZ];
933 char mime_content_type[SIZ];
934 char mime_disposition[SIZ];
936 char vcard_partnum[SIZ];
937 char *vcard_source = NULL;
938 struct message_summary summ;
940 memset(&summ, 0, sizeof(summ));
941 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
943 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
945 serv_getln(buf, sizeof buf);
946 if (buf[0] != '1') return;
948 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
949 if (!strncasecmp(buf, "part=", 5)) {
950 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
951 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
952 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
953 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
954 mime_length = extract_int(&buf[5], 5);
956 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
957 strcpy(vcard_partnum, mime_partnum);
963 if (strlen(vcard_partnum) > 0) {
964 vcard_source = load_mimepart(msgnum, vcard_partnum);
965 if (vcard_source != NULL) {
967 /* Display the summary line */
968 display_vcard(vcard_source, alpha, 0, NULL);
970 /* If it's my vCard I can edit it */
971 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
972 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
973 || (WC->wc_view == VIEW_ADDRESSBOOK)
975 wprintf("<A HREF=\"/edit_vcard?"
976 "msgnum=%ld?partnum=%s\">",
977 msgnum, vcard_partnum);
978 wprintf("[edit]</A>");
989 /* If it's an old "Firstname Lastname" style record, try to
992 void lastfirst_firstlast(char *namebuf) {
997 if (namebuf == NULL) return;
998 if (strchr(namebuf, ';') != NULL) return;
1000 i = num_tokens(namebuf, ' ');
1003 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1004 remove_token(namebuf, i-1, ' ');
1005 strcpy(firstname, namebuf);
1006 sprintf(namebuf, "%s; %s", lastname, firstname);
1010 void fetch_ab_name(long msgnum, char *namebuf) {
1012 char mime_partnum[SIZ];
1013 char mime_filename[SIZ];
1014 char mime_content_type[SIZ];
1015 char mime_disposition[SIZ];
1017 char vcard_partnum[SIZ];
1018 char *vcard_source = NULL;
1020 struct message_summary summ;
1022 if (namebuf == NULL) return;
1023 strcpy(namebuf, "");
1025 memset(&summ, 0, sizeof(summ));
1026 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1028 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1030 serv_getln(buf, sizeof buf);
1031 if (buf[0] != '1') return;
1033 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1034 if (!strncasecmp(buf, "part=", 5)) {
1035 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1036 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1037 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1038 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1039 mime_length = extract_int(&buf[5], 5);
1041 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1042 strcpy(vcard_partnum, mime_partnum);
1048 if (strlen(vcard_partnum) > 0) {
1049 vcard_source = load_mimepart(msgnum, vcard_partnum);
1050 if (vcard_source != NULL) {
1052 /* Grab the name off the card */
1053 display_vcard(vcard_source, 0, 0, namebuf);
1059 lastfirst_firstlast(namebuf);
1061 for (i=0; i<strlen(namebuf); ++i) {
1062 if (namebuf[i] != ';') return;
1064 strcpy(namebuf, "(no name)");
1070 * Record compare function for sorting address book indices
1072 int abcmp(const void *ab1, const void *ab2) {
1074 (((const struct addrbookent *)ab1)->ab_name),
1075 (((const struct addrbookent *)ab2)->ab_name)
1081 * Helper function for do_addrbook_view()
1082 * Converts a name into a three-letter tab label
1084 void nametab(char *tabbuf, char *name) {
1085 stresc(tabbuf, name, 0, 0);
1086 tabbuf[0] = toupper(tabbuf[0]);
1087 tabbuf[1] = tolower(tabbuf[1]);
1088 tabbuf[2] = tolower(tabbuf[2]);
1094 * Render the address book using info we gathered during the scan
1096 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1100 static int NAMESPERPAGE = 60;
1104 char tabfirst_label[SIZ];
1106 char tablast_label[SIZ];
1109 wprintf("<I>This address book is empty.</I>\n");
1114 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1117 num_pages = num_ab / NAMESPERPAGE;
1119 page = atoi(bstr("page"));
1122 for (i=0; i<=num_pages; ++i) {
1124 wprintf("<A HREF=\"/readfwd?page=%d\">", i);
1129 tabfirst = i * NAMESPERPAGE;
1130 tablast = tabfirst + NAMESPERPAGE - 1;
1131 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1132 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1133 nametab(tablast_label, addrbook[tablast].ab_name);
1134 wprintf("[%s - %s]",
1135 tabfirst_label, tablast_label
1144 wprintf("<br />\n");
1146 wprintf("<TABLE border=0 cellspacing=0 "
1147 "cellpadding=3 width=100%%>\n"
1150 for (i=0; i<num_ab; ++i) {
1152 if ((i / NAMESPERPAGE) == page) {
1154 if ((displayed % 4) == 0) {
1155 if (displayed > 0) {
1159 wprintf("<TR BGCOLOR=\"#%s\">",
1160 (bg ? "DDDDDD" : "FFFFFF")
1166 wprintf("<A HREF=\"/readfwd?startmsg=%ld&is_singlecard=1",
1167 addrbook[i].ab_msgnum);
1168 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1169 vcard_n_prettyize(addrbook[i].ab_name);
1170 escputs(addrbook[i].ab_name);
1171 wprintf("</A></TD>\n");
1176 wprintf("</TR></TABLE>\n");
1182 * load message pointers from the server
1184 int load_msg_ptrs(char *servcmd, int with_headers)
1188 char displayname[128];
1195 int num_summ_alloc = 0;
1198 if (WC->num_summ != 0) {
1203 num_summ_alloc = 100;
1205 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1208 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1210 serv_getln(buf, sizeof buf);
1211 if (buf[0] != '1') {
1212 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1215 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1216 if (nummsgs < maxload) {
1217 WC->msgarr[nummsgs] = extract_long(buf, 0);
1218 datestamp = extract_long(buf, 1);
1219 extract_token(displayname, buf, 2, '|', sizeof displayname);
1220 extract_token(nodename, buf, 3, '|', sizeof nodename);
1221 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1222 extract_token(subject, buf, 5, '|', sizeof subject);
1226 if (nummsgs > num_summ_alloc) {
1227 num_summ_alloc *= 2;
1228 WC->summ = realloc(WC->summ, num_summ_alloc * sizeof(struct message_summary));
1232 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1233 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1234 safestrncpy(WC->summ[nummsgs-1].subj, "(no subject)", sizeof WC->summ[nummsgs-1].subj);
1235 if (strlen(displayname) > 0) {
1236 safestrncpy(WC->summ[nummsgs-1].from, displayname, sizeof WC->summ[nummsgs-1].from);
1238 if (strlen(subject) > 0) {
1239 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1240 sizeof WC->summ[nummsgs-1].subj);
1243 /* Handle subjects with RFC2047 encoding */
1244 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1246 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1247 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1250 if (strlen(nodename) > 0) {
1251 if ( ((WC->room_flags & QR_NETWORK)
1252 || ((strcasecmp(nodename, serv_info.serv_nodename)
1253 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1255 strcat(WC->summ[nummsgs-1].from, " @ ");
1256 strcat(WC->summ[nummsgs-1].from, nodename);
1260 WC->summ[nummsgs-1].date = datestamp;
1263 /* Handle senders with RFC2047 encoding */
1264 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1266 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1267 strcpy(&WC->summ[nummsgs-1].from[22], "...");
1276 int summcmp_subj(const void *s1, const void *s2) {
1277 struct message_summary *summ1;
1278 struct message_summary *summ2;
1280 summ1 = (struct message_summary *)s1;
1281 summ2 = (struct message_summary *)s2;
1282 return strcasecmp(summ1->subj, summ2->subj);
1285 int summcmp_rsubj(const void *s1, const void *s2) {
1286 struct message_summary *summ1;
1287 struct message_summary *summ2;
1289 summ1 = (struct message_summary *)s1;
1290 summ2 = (struct message_summary *)s2;
1291 return strcasecmp(summ2->subj, summ1->subj);
1294 int summcmp_sender(const void *s1, const void *s2) {
1295 struct message_summary *summ1;
1296 struct message_summary *summ2;
1298 summ1 = (struct message_summary *)s1;
1299 summ2 = (struct message_summary *)s2;
1300 return strcasecmp(summ1->from, summ2->from);
1303 int summcmp_rsender(const void *s1, const void *s2) {
1304 struct message_summary *summ1;
1305 struct message_summary *summ2;
1307 summ1 = (struct message_summary *)s1;
1308 summ2 = (struct message_summary *)s2;
1309 return strcasecmp(summ2->from, summ1->from);
1312 int summcmp_date(const void *s1, const void *s2) {
1313 struct message_summary *summ1;
1314 struct message_summary *summ2;
1316 summ1 = (struct message_summary *)s1;
1317 summ2 = (struct message_summary *)s2;
1319 if (summ1->date < summ2->date) return -1;
1320 else if (summ1->date > summ2->date) return +1;
1324 int summcmp_rdate(const void *s1, const void *s2) {
1325 struct message_summary *summ1;
1326 struct message_summary *summ2;
1328 summ1 = (struct message_summary *)s1;
1329 summ2 = (struct message_summary *)s2;
1331 if (summ1->date < summ2->date) return +1;
1332 else if (summ1->date > summ2->date) return -1;
1337 * command loop for reading messages
1339 void readloop(char *oper)
1348 int num_displayed = 0;
1350 int is_addressbook = 0;
1351 int is_singlecard = 0;
1352 int is_calendar = 0;
1355 int remaining_messages;
1357 int lowest_displayed = (-1);
1358 int highest_displayed = 0;
1359 long pn_previous = 0L;
1360 long pn_current = 0L;
1363 struct addrbookent *addrbook = NULL;
1365 char *sortby = NULL;
1366 char sortpref_name[128];
1367 char sortpref_value[128];
1368 char *subjsort_button;
1369 char *sendsort_button;
1370 char *datesort_button;
1372 startmsg = atol(bstr("startmsg"));
1373 maxmsgs = atoi(bstr("maxmsgs"));
1374 is_summary = atoi(bstr("summary"));
1375 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1377 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
1378 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
1380 sortby = bstr("sortby");
1381 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
1382 set_preference(sortpref_name, sortby, 1);
1384 if (strlen(sortby) == 0) sortby = sortpref_value;
1385 if (strlen(sortby) == 0) sortby = "msgid";
1387 output_headers(1, 1, 1, 0, 0, 0, 0);
1389 /* When in summary mode, always show ALL messages instead of just
1390 * new or old. Otherwise, show what the user asked for.
1392 if (!strcmp(oper, "readnew")) {
1393 strcpy(cmd, "MSGS NEW");
1395 else if (!strcmp(oper, "readold")) {
1396 strcpy(cmd, "MSGS OLD");
1399 strcpy(cmd, "MSGS ALL");
1402 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
1404 strcpy(cmd, "MSGS ALL");
1407 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
1409 strcpy(cmd, "MSGS ALL");
1414 strcpy(cmd, "MSGS ALL|||1"); /* fetch header summary */
1419 /* Are we doing a summary view? If so, we need to know old messages
1420 * and new messages, so we can do that pretty boldface thing for the
1423 strcpy(old_msgs, "");
1426 serv_getln(buf, sizeof buf);
1427 if (buf[0] == '2') {
1428 strcpy(old_msgs, &buf[4]);
1432 is_singlecard = atoi(bstr("is_singlecard"));
1434 if (WC->wc_view == VIEW_CALENDAR) { /* calendar */
1436 strcpy(cmd, "MSGS ALL");
1439 if (WC->wc_view == VIEW_TASKS) { /* tasks */
1441 strcpy(cmd, "MSGS ALL");
1444 if (WC->wc_view == VIEW_NOTES) { /* notes */
1446 strcpy(cmd, "MSGS ALL");
1450 nummsgs = load_msg_ptrs(cmd, is_summary);
1453 if ((!is_tasks) && (!is_calendar) && (!is_notes)) {
1454 if (!strcmp(oper, "readnew")) {
1455 wprintf("<EM>No new messages.</EM>\n");
1456 } else if (!strcmp(oper, "readold")) {
1457 wprintf("<EM>No old messages.</EM>\n");
1459 wprintf("<EM>No messages here.</EM>\n");
1467 for (a = 0; a < nummsgs; ++a) {
1468 /* Are you a new message, or an old message? */
1470 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
1471 WC->summ[a].is_new = 0;
1474 WC->summ[a].is_new = 1;
1480 if (startmsg == 0L) startmsg = WC->msgarr[0];
1481 remaining_messages = 0;
1483 for (a = 0; a < nummsgs; ++a) {
1484 if (WC->msgarr[a] >= startmsg) {
1485 ++remaining_messages;
1490 if (!strcasecmp(sortby, "subject")) {
1491 qsort(WC->summ, WC->num_summ,
1492 sizeof(struct message_summary), summcmp_subj);
1494 else if (!strcasecmp(sortby, "rsubject")) {
1495 qsort(WC->summ, WC->num_summ,
1496 sizeof(struct message_summary), summcmp_rsubj);
1498 else if (!strcasecmp(sortby, "sender")) {
1499 qsort(WC->summ, WC->num_summ,
1500 sizeof(struct message_summary), summcmp_sender);
1502 else if (!strcasecmp(sortby, "rsender")) {
1503 qsort(WC->summ, WC->num_summ,
1504 sizeof(struct message_summary), summcmp_rsender);
1506 else if (!strcasecmp(sortby, "date")) {
1507 qsort(WC->summ, WC->num_summ,
1508 sizeof(struct message_summary), summcmp_date);
1510 else if (!strcasecmp(sortby, "rdate")) {
1511 qsort(WC->summ, WC->num_summ,
1512 sizeof(struct message_summary), summcmp_rdate);
1516 if (!strcasecmp(sortby, "subject")) {
1517 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1519 else if (!strcasecmp(sortby, "rsubject")) {
1520 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1523 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1526 if (!strcasecmp(sortby, "sender")) {
1527 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1529 else if (!strcasecmp(sortby, "rsender")) {
1530 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1533 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1536 if (!strcasecmp(sortby, "date")) {
1537 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1539 else if (!strcasecmp(sortby, "rdate")) {
1540 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1543 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1547 wprintf("</div>"); /* end of 'content' div */
1549 wprintf("<div id=\"message_list\">"
1551 "<div id=\"fix_scrollbar_bug\">\n"
1553 "<form name=\"msgomatic\" "
1554 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n"
1556 "<table border=0 cellspacing=0 "
1557 "cellpadding=0 width=100%%>\n"
1559 "<TD align=center><b><i>Subject</i></b> %s</TD>"
1560 "<TD align=center><b><i>Sender</i></b> %s</TD>"
1561 "<TD align=center><b><i>Date</i></b> %s</TD>"
1562 "<TD><INPUT TYPE=\"submit\" NAME=\"sc\" "
1563 "STYLE=\"font-family: Bitstream Vera Sans,Arial,Helvetica,sans-serif;"
1564 " font-size: 6pt;\" "
1565 "VALUE=\"Delete\"></TD>"
1574 for (a = 0; a < nummsgs; ++a) {
1575 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
1577 /* Learn which msgs "Prev" & "Next" buttons go to */
1578 pn_current = WC->msgarr[a];
1579 if (a > 0) pn_previous = WC->msgarr[a-1];
1580 if (a < (nummsgs-1)) pn_next = WC->msgarr[a+1];
1582 /* If a tabular view, set up the line */
1585 wprintf("<TR BGCOLOR=\"#%s\">",
1586 (bg ? "DDDDDD" : "FFFFFF")
1590 /* Display the message */
1592 display_summarized(a);
1594 else if (is_addressbook) {
1595 fetch_ab_name(WC->msgarr[a], buf);
1597 addrbook = realloc(addrbook,
1598 (sizeof(struct addrbookent) * num_ab) );
1599 safestrncpy(addrbook[num_ab-1].ab_name, buf,
1600 sizeof(addrbook[num_ab-1].ab_name));
1601 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
1603 else if (is_calendar) {
1604 display_calendar(WC->msgarr[a]);
1606 else if (is_tasks) {
1607 display_task(WC->msgarr[a]);
1609 else if (is_notes) {
1610 display_note(WC->msgarr[a]);
1613 read_message(WC->msgarr[a], 0);
1616 /* If a tabular view, finish the line */
1621 if (lowest_displayed < 0) lowest_displayed = a;
1622 highest_displayed = a;
1625 --remaining_messages;
1630 wprintf("</table></form>"
1631 "</div>\n"); /* end of 'fix_scrollbar_bug' div */
1632 wprintf("</div>"); /* end of 'message_list' div */
1634 wprintf("<div id=\"preview_pane\">"); /* The preview pane will initially be empty */
1637 /* Bump these because although we're thinking in zero base, the user
1638 * is a drooling idiot and is thinking in one base.
1641 ++highest_displayed;
1643 /* If we're only looking at one message, do a prev/next thing */
1644 if (num_displayed == 1) {
1645 if ((!is_tasks) && (!is_calendar) && (!is_addressbook) && (!is_notes) && (!is_singlecard)) {
1647 wprintf("<div id=\"fix_scrollbar_bug\">"
1648 "<table border=0 width=100%% bgcolor=\"#dddddd\"><tr><td>"
1649 "Reading #%d of %d messages.</TD>\n"
1650 "<TD ALIGN=RIGHT><FONT SIZE=+1>",
1651 lowest_displayed, nummsgs);
1653 if (pn_previous > 0L) {
1654 wprintf("<A HREF=\"/%s"
1664 wprintf("<A HREF=\"/%s"
1673 wprintf("<A HREF=\"/%s?startmsg=%ld"
1674 "?maxmsgs=%d?summary=1\">"
1682 wprintf("</td></tr></table></div>\n");
1687 * If we're not currently looking at ALL requested
1688 * messages, then display the selector bar
1690 if (num_displayed > 1) {
1691 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
1692 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
1694 wprintf("<form name=\"msgomatic\" "
1695 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n");
1697 wprintf("Reading #", lowest_displayed, highest_displayed);
1699 wprintf("<select name=\"whichones\" size=\"1\" "
1700 "OnChange=\"location.href=msgomatic.whichones.options"
1701 "[selectedIndex].value\">\n");
1703 for (b=0; b<nummsgs; b = b + maxmsgs) {
1706 if (hi > nummsgs) hi = nummsgs;
1707 wprintf("<option %s value="
1712 "%d-%d</option> \n",
1713 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
1720 wprintf("<option value=\"/%s?startmsg=%ld"
1721 "?maxmsgs=9999999?summary=%d\">"
1725 WC->msgarr[0], is_summary);
1727 wprintf("</select> of %d messages.", nummsgs);
1728 wprintf("</form>\n");
1734 do_tasks_view(); /* Render the task list */
1738 do_calendar_view(); /* Render the calendar */
1741 if (is_addressbook) {
1742 do_addrbook_view(addrbook, num_ab); /* Render the address book */
1745 /* Put the data transfer hidden iframe in a hidden div, to make it *really* hidden */
1747 "<div display=\"hidden\">\n"
1748 "<iframe name=\"msgloader1\" id=\"msgloader1\" width=\"1\"></iframe>\n"
1751 /* Note: wDumpContent() will output one additional </div> tag. */
1753 if (addrbook != NULL) free(addrbook);
1755 /* free the summary */
1756 if (WC->num_summ != 0) {
1761 /* If we got here via a mailbox view and are reading a single
1762 * message, mark it as "seen." We do this after rendering the web page
1763 * so it doesn't keep the user waiting.
1765 if ( (maxmsgs == 1) && (WC->wc_view == VIEW_MAILBOX) ) {
1766 serv_printf("SEEN %ld|1", startmsg);
1767 serv_getln(buf, sizeof buf);
1773 * Back end for post_message() ... this is where the actual message
1774 * gets transmitted to the server.
1776 void post_mime_to_server(void) {
1778 int is_multipart = 0;
1780 struct wc_attachment *att;
1782 size_t encoded_length;
1784 /* If there are attachments, we have to do multipart/mixed */
1785 if (WC->first_attachment != NULL) {
1790 sprintf(boundary, "---Citadel-Multipart-%s-%04x%04x---",
1791 serv_info.serv_fqdn,
1796 /* Remember, serv_printf() appends an extra newline */
1797 serv_printf("Content-type: multipart/mixed; "
1798 "boundary=\"%s\"\n", boundary);
1799 serv_printf("This is a multipart message in MIME format.\n");
1800 serv_printf("--%s", boundary);
1803 serv_puts("Content-type: text/html; charset=utf-8");
1805 serv_puts("<HTML><BODY>\n");
1806 text_to_server(bstr("msgtext"), 0);
1807 serv_puts("</BODY></HTML>\n");
1812 /* Add in the attachments */
1813 for (att = WC->first_attachment; att!=NULL; att=att->next) {
1815 encoded_length = ((att->length * 150) / 100);
1816 encoded = malloc(encoded_length);
1817 if (encoded == NULL) break;
1818 CtdlEncodeBase64(encoded, att->data, att->length);
1820 serv_printf("--%s", boundary);
1821 serv_printf("Content-type: %s", att->content_type);
1822 serv_printf("Content-disposition: attachment; "
1823 "filename=\"%s\"", att->filename);
1824 serv_puts("Content-transfer-encoding: base64");
1826 serv_write(encoded, strlen(encoded));
1831 serv_printf("--%s--", boundary);
1839 * Post message (or don't post message)
1841 * Note regarding the "dont_post" variable:
1842 * A random value (actually, it's just a timestamp) is inserted as a hidden
1843 * field called "postseq" when the display_enter page is generated. This
1844 * value is checked when posting, using the static variable dont_post. If a
1845 * user attempts to post twice using the same dont_post value, the message is
1846 * discarded. This prevents the accidental double-saving of the same message
1847 * if the user happens to click the browser "back" button.
1849 void post_message(void)
1852 static long dont_post = (-1L);
1853 struct wc_attachment *att, *aptr;
1855 if (WC->upload_length > 0) {
1857 /* There's an attachment. Save it to this struct... */
1858 att = malloc(sizeof(struct wc_attachment));
1859 memset(att, 0, sizeof(struct wc_attachment));
1860 att->length = WC->upload_length;
1861 strcpy(att->content_type, WC->upload_content_type);
1862 strcpy(att->filename, WC->upload_filename);
1865 /* And add it to the list. */
1866 if (WC->first_attachment == NULL) {
1867 WC->first_attachment = att;
1870 aptr = WC->first_attachment;
1871 while (aptr->next != NULL) aptr = aptr->next;
1875 /* Netscape sends a simple filename, which is what we want,
1876 * but Satan's browser sends an entire pathname. Reduce
1877 * the path to just a filename if we need to.
1879 while (num_tokens(att->filename, '/') > 1) {
1880 remove_token(att->filename, 0, '/');
1882 while (num_tokens(att->filename, '\\') > 1) {
1883 remove_token(att->filename, 0, '\\');
1886 /* Transfer control of this memory from the upload struct
1887 * to the attachment struct.
1889 att->data = WC->upload;
1890 WC->upload_length = 0;
1896 if (!strcasecmp(bstr("sc"), "Cancel")) {
1897 sprintf(WC->ImportantMessage,
1898 "Cancelled. Message was not posted.");
1899 } else if (!strcasecmp(bstr("attach"), "Add")) {
1902 } else if (atol(bstr("postseq")) == dont_post) {
1903 sprintf(WC->ImportantMessage,
1904 "Automatically cancelled because you have already "
1905 "saved this message.");
1907 sprintf(buf, "ENT0 1|%s|0|4|%s",
1911 serv_getln(buf, sizeof buf);
1912 if (buf[0] == '4') {
1913 post_mime_to_server();
1914 if (strlen(bstr("recp")) > 0) {
1915 sprintf(WC->ImportantMessage, "Message has been sent.\n");
1918 sprintf(WC->ImportantMessage, "Message has been posted.\n");
1920 dont_post = atol(bstr("postseq"));
1922 sprintf(WC->ImportantMessage,
1927 free_attachments(WC);
1928 readloop("readnew");
1935 * display the message entry screen
1937 void display_enter(void)
1941 struct wc_attachment *att;
1943 if (strlen(bstr("force_room")) > 0) {
1944 gotoroom(bstr("force_room"));
1947 /* Are we perhaps in an address book view? If so, then an "enter
1948 * message" command really means "add new entry."
1950 if (WC->wc_view == VIEW_ADDRESSBOOK) {
1951 do_edit_vcard(-1, "", "");
1955 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1956 /* Are we perhaps in a calendar view? If so, then an "enter
1957 * message" command really means "add new calendar item."
1959 if (WC->wc_view == VIEW_CALENDAR) {
1960 display_edit_event();
1964 /* Are we perhaps in a tasks view? If so, then an "enter
1965 * message" command really means "add new task."
1967 if (WC->wc_view == VIEW_TASKS) {
1968 display_edit_task();
1974 * Otherwise proceed normally.
1975 ` * Do a custom room banner with no navbar...
1977 output_headers(1, 1, 2, 0, 0, 0, 0);
1978 wprintf("<div id=\"banner\">\n");
1979 embed_room_banner(NULL, navbar_none);
1980 wprintf("</div>\n");
1981 wprintf("<div id=\"content\">\n"
1982 "<div id=\"fix_scrollbar_bug\">"
1983 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
1985 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
1987 serv_getln(buf, sizeof buf);
1989 if (!strncmp(buf, "570", 3)) {
1990 if (strlen(bstr("recp")) > 0) {
1991 svprintf("RECPERROR", WCS_STRING,
1992 "<SPAN CLASS=\"errormsg\">%s</SPAN><br />\n",
1996 do_template("prompt_for_recipient");
1999 if (buf[0] != '2') {
2000 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2005 fmt_date(buf, now, 0);
2006 strcat(&buf[strlen(buf)], " <I>from</I> ");
2007 stresc(&buf[strlen(buf)], WC->wc_username, 1, 1);
2008 if (strlen(bstr("recp")) > 0) {
2009 strcat(&buf[strlen(buf)], " <I>to</I> ");
2010 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
2012 strcat(&buf[strlen(buf)], " <I>in</I> ");
2013 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
2015 /* begin message entry screen */
2016 // wprintf("<div style=\"position:absolute; left:1%%; width:96%%; height:100%%\">\n");
2018 wprintf("<form enctype=\"multipart/form-data\" "
2019 "method=\"POST\" action=\"/post\" "
2020 "name=\"enterform\""
2021 "onSubmit=\"return submitForm();\""
2023 wprintf("<input type=\"hidden\" name=\"recp\" value=\"%s\">\n",
2025 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n",
2028 wprintf("%s<br>\n", buf); /* header bar */
2029 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2030 /* "onLoad=\"document.enterform.msgtext.focus();\" " */
2031 wprintf("<font size=-1>Subject (optional):</font>"
2032 "<input type=\"text\" name=\"subject\" value=\"");
2033 escputs(bstr("subject"));
2034 wprintf("\" size=40 maxlength=70>"
2038 wprintf("<input type=\"submit\" name=\"sc\" value=\"");
2039 if (strlen(bstr("recp")) > 0) {
2040 wprintf("Send message");
2042 wprintf("Post message");
2045 "<input type=\"submit\" name=\"sc\" value=\"Cancel\">\n");
2047 wprintf("<center><script type=\"text/javascript\" "
2048 "src=\"static/richtext.js\"></script>\n"
2049 "<script type=\"text/javascript\">\n"
2050 "function submitForm() { \n"
2051 " updateRTE('msgtext'); \n"
2055 "initRTE(\"static/\", \"static/\", \"\"); \n"
2057 "<noscript>JavaScript must be enabled.</noscript> \n"
2058 "<script type=\"text/javascript\"> \n"
2059 "writeRichText('msgtext', '");
2060 msgescputs(bstr("msgtext"));
2061 wprintf("', '96%%', '200', true, false); \n"
2062 "</script></center><br />\n");
2064 /* Enumerate any attachments which are already in place... */
2065 wprintf("<img src=\"/static/diskette_24x.gif\" border=0 "
2066 "align=middle height=16 width=16> Attachments: ");
2067 wprintf("<select name=\"which_attachment\" size=1>");
2068 for (att = WC->first_attachment; att != NULL; att = att->next) {
2069 wprintf("<option value=\"");
2070 urlescputs(att->filename);
2072 escputs(att->filename);
2073 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
2074 wprintf("</option>\n");
2076 wprintf("</select>");
2078 /* Now offer the ability to attach additional files... */
2079 wprintf(" "
2080 "Attach file: <input NAME=\"attachfile\" "
2081 "SIZE=16 TYPE=\"file\">\n "
2082 "<input type=\"submit\" name=\"attach\" value=\"Add\">\n");
2084 wprintf("</form>\n");
2086 wprintf("</td></tr></table></div>\n");
2087 DONE: wDumpContent(1);
2097 void delete_msg(void)
2102 msgid = atol(bstr("msgid"));
2104 output_headers(1, 1, 1, 0, 0, 0, 0);
2106 sprintf(buf, "DELE %ld", msgid);
2108 serv_getln(buf, sizeof buf);
2109 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2118 * Confirm move of a message
2120 void confirm_move_msg(void)
2126 msgid = atol(bstr("msgid"));
2128 output_headers(1, 1, 1, 0, 0, 0, 0);
2130 wprintf("<div id=\"fix_scrollbar_bug\">"
2131 "<table width=100%% border=0 bgcolor=\"#444455\"><tr><td>");
2132 wprintf("<font size=+1 color=\"#ffffff\"");
2133 wprintf("<b>Confirm move of message</b>\n");
2134 wprintf("</font></td></tr></table></div>\n");
2136 wprintf("<CENTER>");
2138 wprintf("Move this message to:<br />\n");
2140 wprintf("<form METHOD=\"POST\" ACTION=\"/move_msg\">\n");
2141 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
2145 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
2147 serv_getln(buf, sizeof buf);
2148 if (buf[0] == '1') {
2149 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2150 extract_token(targ, buf, 0, '|', sizeof targ);
2151 wprintf("<OPTION>");
2156 wprintf("</SELECT>\n");
2157 wprintf("<br />\n");
2159 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
2161 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
2162 wprintf("</form></CENTER>\n");
2164 wprintf("</CENTER>\n");
2175 msgid = atol(bstr("msgid"));
2177 output_headers(1, 1, 1, 0, 0, 0, 0);
2179 if (!strcasecmp(bstr("yesno"), "Move")) {
2180 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
2182 serv_getln(buf, sizeof buf);
2183 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2185 wprintf("<EM>Message not moved.</EM><br />\n");
2192 * This gets called when a user selects multiple messages in a summary
2193 * list and then clicks to perform a transformation of some sort on them
2194 * (such as deleting them).
2196 void do_stuff_to_msgs(void) {
2201 struct stuff_t *next;
2205 struct stuff_t *stuff = NULL;
2206 struct stuff_t *ptr;
2209 serv_puts("MSGS ALL");
2210 serv_getln(buf, sizeof buf);
2212 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2213 ptr = malloc(sizeof(struct stuff_t));
2214 ptr->msgnum = atol(buf);
2219 strcpy(sc, bstr("sc"));
2221 while (stuff != NULL) {
2223 sprintf(buf, "msg_%ld", stuff->msgnum);
2224 if (!strcasecmp(bstr(buf), "yes")) {
2226 if (!strcasecmp(sc, "Delete")) {
2227 serv_printf("DELE %ld", stuff->msgnum);
2228 serv_getln(buf, sizeof buf);
2238 readloop("readfwd");