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) {
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 wprintf("<TD ALIGN=RIGHT>\n");
678 wprintf("<a href=\"/display_enter?recp=");
679 urlescputs(reply_to);
680 wprintf("?subject=");
681 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
682 urlescputs(m_subject);
683 wprintf("\">[Reply]</a> ");
685 if (WC->is_room_aide) {
688 wprintf("<a href=\"/confirm_move_msg?msgid=%ld\">[Move]</a> ",
692 wprintf("<a href=\"/delete_msg?msgid=%ld\" "
693 "onClick=\"return confirm('Delete this message?');\">"
694 "[Delete]</a>", msgnum);
698 wprintf("</TD></TR></TABLE>\n");
701 wprintf("<TABLE BORDER=0 WIDTH=100%% BGCOLOR=#FFFFFF "
702 "CELLPADDING=1 CELLSPACING=0><TR><TD>");
705 * Learn the content type
707 strcpy(mime_content_type, "text/plain");
708 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
709 if (!strcmp(buf, "000")) {
710 wprintf("<I>unexpected end of message</I><br /><br />\n");
713 if (!strncasecmp(buf, "Content-type: ", 14)) {
714 safestrncpy(mime_content_type, &buf[14],
715 sizeof(mime_content_type));
716 for (i=0; i<strlen(mime_content_type); ++i) {
717 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
718 safestrncpy(mime_charset, &mime_content_type[i+8],
719 sizeof mime_charset);
722 for (i=0; i<strlen(mime_content_type); ++i) {
723 if (mime_content_type[i] == ';') {
724 mime_content_type[i] = 0;
730 /* Set up a character set conversion if we need to (and if we can) */
732 if ( (strcasecmp(mime_charset, "us-ascii"))
733 && (strcasecmp(mime_charset, "UTF-8")) ) {
734 ic = iconv_open("UTF-8", mime_charset);
735 if (ic == (iconv_t)(-1) ) {
736 lprintf(5, "iconv_open() failed: %s\n", strerror(errno));
741 /* Messages in legacy Citadel variformat get handled thusly... */
742 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
743 fmout(NULL, "JUSTIFY");
746 /* Boring old 80-column fixed format text gets handled this way... */
747 else if (!strcasecmp(mime_content_type, "text/plain")) {
748 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
749 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
750 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
753 if (ic != (iconv_t)(-1) ) {
755 ibuflen = strlen(ibuf);
757 obuf = (char *) malloc(obuflen);
759 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
760 osav[SIZ-obuflen] = 0;
761 safestrncpy(buf, osav, sizeof buf);
766 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
767 buf[strlen(buf) - 1] = 0;
769 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
770 wprintf("<BLOCKQUOTE>");
772 } else if ((bq == 1) &&
773 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
774 wprintf("</BLOCKQUOTE>");
780 wprintf("</TT><br />\n");
782 wprintf("</I><br />");
785 else /* HTML is fun, but we've got to strip it first */
786 if (!strcasecmp(mime_content_type, "text/html")) {
787 output_html(mime_charset);
790 /* Unknown weirdness */
792 wprintf("I don't know how to display %s<br />\n",
794 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
797 /* Afterwards, offer links to download attachments 'n' such */
798 if (strlen(mime_http) > 0) {
799 wprintf("%s", mime_http);
802 /* Handler for vCard parts */
803 if (strlen(vcard_partnum) > 0) {
804 part_source = load_mimepart(msgnum, vcard_partnum);
805 if (part_source != NULL) {
807 /* If it's my vCard I can edit it */
808 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
809 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
810 || (WC->wc_view == VIEW_ADDRESSBOOK)
812 wprintf("<A HREF=\"/edit_vcard?"
813 "msgnum=%ld?partnum=%s\">",
814 msgnum, vcard_partnum);
815 wprintf("[edit]</A>");
818 /* In all cases, display the full card */
819 display_vcard(part_source, 0, 1, NULL);
823 /* Handler for calendar parts */
824 if (strlen(cal_partnum) > 0) {
825 part_source = load_mimepart(msgnum, cal_partnum);
826 if (part_source != NULL) {
827 cal_process_attachment(part_source,
828 msgnum, cal_partnum);
838 wprintf("</TD></TR></TABLE>\n");
840 /* end everythingamundo table */
841 wprintf("</TD></TR></TABLE>\n");
842 wprintf("</div><br />\n");
845 if (ic != (iconv_t)(-1) ) {
854 * Unadorned HTML output of an individual message, suitable
855 * for placing in a hidden iframe, for printing, or whatever
857 void embed_message(void) {
862 msgnum = atol(bstr("msgnum"));
863 sourceiframe = bstr("sourceiframe");
864 targetdiv = bstr("targetdiv");
866 output_headers(1, 0, 0, 0, 0, 1, 0);
869 wprintf("<html><head>");
871 /* If we're loading into a hidden iframe, chances are the caller told us
872 * about a target div somewhere that we need to copy into when we're done.
874 if (strlen(targetdiv) > 0) wprintf(
876 " <script type=\"text/javascript\"> \n"
877 " function loaded_now_copy_it() { \n"
878 " parent.document.getElementById(\"%s\").innerHTML = parent.frames['%s'].document.body.innerHTML; \n"
887 if (strlen(targetdiv) > 0) {
888 wprintf(" onLoad='loaded_now_copy_it();'");
891 read_message(msgnum);
892 wprintf("</body></html>\n");
899 void display_summarized(int num) {
903 if (WC->summ[num].is_new) wprintf("<B>");
904 wprintf("<A HREF=\"/msg?msgnum=%ld?sourceiframe=msgloader1?targetdiv=preview_pane\" target=\"msgloader1\">",
905 WC->summ[num].msgnum);
906 escputs(WC->summ[num].subj);
908 if (WC->summ[num].is_new) wprintf("</B>");
909 wprintf("</TD><TD>");
910 if (WC->summ[num].is_new) wprintf("<B>");
911 escputs(WC->summ[num].from);
912 if (WC->summ[num].is_new) wprintf("</B>");
913 wprintf(" </TD><TD>");
914 if (WC->summ[num].is_new) wprintf("<B>");
915 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
917 if (WC->summ[num].is_new) wprintf("</B>");
920 "<INPUT TYPE=\"checkbox\" NAME=\"msg_%ld\" VALUE=\"yes\">"
927 void summarize_message(int num, long msgnum, int is_new) {
930 memset(&WC->summ[num], 0, sizeof(struct message_summary));
931 safestrncpy(WC->summ[num].subj, "(no subject)", sizeof WC->summ[num].subj);
932 WC->summ[num].is_new = is_new;
933 WC->summ[num].msgnum = msgnum;
935 /* ask for headers only with no MIME */
936 sprintf(buf, "MSG0 %ld|3", msgnum);
938 serv_getln(buf, sizeof buf);
939 if (buf[0] != '1') return;
941 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
942 if (!strncasecmp(buf, "from=", 5)) {
943 safestrncpy(WC->summ[num].from, &buf[5], sizeof WC->summ[num].from);
945 if (!strncasecmp(buf, "subj=", 5)) {
946 if (strlen(&buf[5]) > 0) {
947 safestrncpy(WC->summ[num].subj, &buf[5],
948 sizeof WC->summ[num].subj);
950 /* Handle subjects with RFC2047 encoding */
951 utf8ify_rfc822_string(WC->summ[num].subj);
953 if (strlen(WC->summ[num].subj) > 75) {
954 strcpy(&WC->summ[num].subj[72], "...");
959 if (!strncasecmp(buf, "node=", 5)) {
960 if ( ((WC->room_flags & QR_NETWORK)
961 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
962 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
964 strcat(WC->summ[num].from, " @ ");
965 strcat(WC->summ[num].from, &buf[5]);
969 if (!strncasecmp(buf, "rcpt=", 5)) {
970 safestrncpy(WC->summ[num].to, &buf[5], sizeof WC->summ[num].to);
973 if (!strncasecmp(buf, "time=", 5)) {
974 WC->summ[num].date = atol(&buf[5]);
979 /* Handle senders with RFC2047 encoding */
980 utf8ify_rfc822_string(WC->summ[num].from);
982 if (strlen(WC->summ[num].from) > 25) {
983 strcpy(&WC->summ[num].from[22], "...");
989 void display_addressbook(long msgnum, char alpha) {
991 char mime_partnum[SIZ];
992 char mime_filename[SIZ];
993 char mime_content_type[SIZ];
994 char mime_disposition[SIZ];
996 char vcard_partnum[SIZ];
997 char *vcard_source = NULL;
998 struct message_summary summ;
1000 memset(&summ, 0, sizeof(summ));
1001 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1003 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1005 serv_getln(buf, sizeof buf);
1006 if (buf[0] != '1') return;
1008 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1009 if (!strncasecmp(buf, "part=", 5)) {
1010 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1011 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1012 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1013 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1014 mime_length = extract_int(&buf[5], 5);
1016 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1017 strcpy(vcard_partnum, mime_partnum);
1023 if (strlen(vcard_partnum) > 0) {
1024 vcard_source = load_mimepart(msgnum, vcard_partnum);
1025 if (vcard_source != NULL) {
1027 /* Display the summary line */
1028 display_vcard(vcard_source, alpha, 0, NULL);
1030 /* If it's my vCard I can edit it */
1031 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1032 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1033 || (WC->wc_view == VIEW_ADDRESSBOOK)
1035 wprintf("<A HREF=\"/edit_vcard?"
1036 "msgnum=%ld?partnum=%s\">",
1037 msgnum, vcard_partnum);
1038 wprintf("[edit]</A>");
1049 /* If it's an old "Firstname Lastname" style record, try to
1052 void lastfirst_firstlast(char *namebuf) {
1053 char firstname[SIZ];
1057 if (namebuf == NULL) return;
1058 if (strchr(namebuf, ';') != NULL) return;
1060 i = num_tokens(namebuf, ' ');
1063 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1064 remove_token(namebuf, i-1, ' ');
1065 strcpy(firstname, namebuf);
1066 sprintf(namebuf, "%s; %s", lastname, firstname);
1070 void fetch_ab_name(long msgnum, char *namebuf) {
1072 char mime_partnum[SIZ];
1073 char mime_filename[SIZ];
1074 char mime_content_type[SIZ];
1075 char mime_disposition[SIZ];
1077 char vcard_partnum[SIZ];
1078 char *vcard_source = NULL;
1080 struct message_summary summ;
1082 if (namebuf == NULL) return;
1083 strcpy(namebuf, "");
1085 memset(&summ, 0, sizeof(summ));
1086 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1088 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1090 serv_getln(buf, sizeof buf);
1091 if (buf[0] != '1') return;
1093 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1094 if (!strncasecmp(buf, "part=", 5)) {
1095 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1096 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1097 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1098 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1099 mime_length = extract_int(&buf[5], 5);
1101 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1102 strcpy(vcard_partnum, mime_partnum);
1108 if (strlen(vcard_partnum) > 0) {
1109 vcard_source = load_mimepart(msgnum, vcard_partnum);
1110 if (vcard_source != NULL) {
1112 /* Grab the name off the card */
1113 display_vcard(vcard_source, 0, 0, namebuf);
1119 lastfirst_firstlast(namebuf);
1121 for (i=0; i<strlen(namebuf); ++i) {
1122 if (namebuf[i] != ';') return;
1124 strcpy(namebuf, "(no name)");
1130 * Record compare function for sorting address book indices
1132 int abcmp(const void *ab1, const void *ab2) {
1134 (((const struct addrbookent *)ab1)->ab_name),
1135 (((const struct addrbookent *)ab2)->ab_name)
1141 * Helper function for do_addrbook_view()
1142 * Converts a name into a three-letter tab label
1144 void nametab(char *tabbuf, char *name) {
1145 stresc(tabbuf, name, 0, 0);
1146 tabbuf[0] = toupper(tabbuf[0]);
1147 tabbuf[1] = tolower(tabbuf[1]);
1148 tabbuf[2] = tolower(tabbuf[2]);
1154 * Render the address book using info we gathered during the scan
1156 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1160 static int NAMESPERPAGE = 60;
1164 char tabfirst_label[SIZ];
1166 char tablast_label[SIZ];
1169 wprintf("<I>This address book is empty.</I>\n");
1174 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1177 num_pages = num_ab / NAMESPERPAGE;
1179 page = atoi(bstr("page"));
1182 for (i=0; i<=num_pages; ++i) {
1184 wprintf("<A HREF=\"/readfwd?page=%d\">", i);
1189 tabfirst = i * NAMESPERPAGE;
1190 tablast = tabfirst + NAMESPERPAGE - 1;
1191 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1192 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1193 nametab(tablast_label, addrbook[tablast].ab_name);
1194 wprintf("[%s - %s]",
1195 tabfirst_label, tablast_label
1204 wprintf("<br />\n");
1206 wprintf("<TABLE border=0 cellspacing=0 "
1207 "cellpadding=3 width=100%%>\n"
1210 for (i=0; i<num_ab; ++i) {
1212 if ((i / NAMESPERPAGE) == page) {
1214 if ((displayed % 4) == 0) {
1215 if (displayed > 0) {
1219 wprintf("<TR BGCOLOR=\"#%s\">",
1220 (bg ? "DDDDDD" : "FFFFFF")
1226 wprintf("<A HREF=\"/readfwd?startmsg=%ld&is_singlecard=1",
1227 addrbook[i].ab_msgnum);
1228 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1229 vcard_n_prettyize(addrbook[i].ab_name);
1230 escputs(addrbook[i].ab_name);
1231 wprintf("</A></TD>\n");
1236 wprintf("</TR></TABLE>\n");
1242 * load message pointers from the server
1244 int load_msg_ptrs(char *servcmd)
1251 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1253 serv_getln(buf, sizeof buf);
1254 if (buf[0] != '1') {
1255 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1258 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1259 if (nummsgs < maxload) {
1260 WC->msgarr[nummsgs] = atol(buf);
1268 int summcmp_subj(const void *s1, const void *s2) {
1269 struct message_summary *summ1;
1270 struct message_summary *summ2;
1272 summ1 = (struct message_summary *)s1;
1273 summ2 = (struct message_summary *)s2;
1274 return strcasecmp(summ1->subj, summ2->subj);
1277 int summcmp_rsubj(const void *s1, const void *s2) {
1278 struct message_summary *summ1;
1279 struct message_summary *summ2;
1281 summ1 = (struct message_summary *)s1;
1282 summ2 = (struct message_summary *)s2;
1283 return strcasecmp(summ2->subj, summ1->subj);
1286 int summcmp_sender(const void *s1, const void *s2) {
1287 struct message_summary *summ1;
1288 struct message_summary *summ2;
1290 summ1 = (struct message_summary *)s1;
1291 summ2 = (struct message_summary *)s2;
1292 return strcasecmp(summ1->from, summ2->from);
1295 int summcmp_rsender(const void *s1, const void *s2) {
1296 struct message_summary *summ1;
1297 struct message_summary *summ2;
1299 summ1 = (struct message_summary *)s1;
1300 summ2 = (struct message_summary *)s2;
1301 return strcasecmp(summ2->from, summ1->from);
1304 int summcmp_date(const void *s1, const void *s2) {
1305 struct message_summary *summ1;
1306 struct message_summary *summ2;
1308 summ1 = (struct message_summary *)s1;
1309 summ2 = (struct message_summary *)s2;
1311 if (summ1->date < summ2->date) return -1;
1312 else if (summ1->date > summ2->date) return +1;
1316 int summcmp_rdate(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;
1329 * command loop for reading messages
1331 void readloop(char *oper)
1341 int num_displayed = 0;
1343 int is_addressbook = 0;
1344 int is_singlecard = 0;
1345 int is_calendar = 0;
1348 int remaining_messages;
1350 int lowest_displayed = (-1);
1351 int highest_displayed = 0;
1352 long pn_previous = 0L;
1353 long pn_current = 0L;
1356 struct addrbookent *addrbook = NULL;
1358 char *sortby = NULL;
1359 char sortpref_name[128];
1360 char sortpref_value[128];
1361 char *subjsort_button;
1362 char *sendsort_button;
1363 char *datesort_button;
1365 startmsg = atol(bstr("startmsg"));
1366 maxmsgs = atoi(bstr("maxmsgs"));
1367 is_summary = atoi(bstr("summary"));
1368 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1370 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
1371 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
1373 sortby = bstr("sortby");
1374 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
1375 set_preference(sortpref_name, sortby, 1);
1377 if (strlen(sortby) == 0) sortby = sortpref_value;
1378 if (strlen(sortby) == 0) sortby = "msgid";
1380 output_headers(1, 1, 1, 0, 0, 0, 0);
1382 /* When in summary mode, always show ALL messages instead of just
1383 * new or old. Otherwise, show what the user asked for.
1385 if (!strcmp(oper, "readnew")) {
1386 strcpy(cmd, "MSGS NEW");
1388 else if (!strcmp(oper, "readold")) {
1389 strcpy(cmd, "MSGS OLD");
1392 strcpy(cmd, "MSGS ALL");
1395 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
1397 strcpy(cmd, "MSGS ALL");
1400 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
1402 strcpy(cmd, "MSGS ALL");
1407 strcpy(cmd, "MSGS ALL");
1412 /* Are we doing a summary view? If so, we need to know old messages
1413 * and new messages, so we can do that pretty boldface thing for the
1416 strcpy(old_msgs, "");
1419 serv_getln(buf, sizeof buf);
1420 if (buf[0] == '2') {
1421 strcpy(old_msgs, &buf[4]);
1425 is_singlecard = atoi(bstr("is_singlecard"));
1427 if (WC->wc_view == VIEW_CALENDAR) { /* calendar */
1429 strcpy(cmd, "MSGS ALL");
1432 if (WC->wc_view == VIEW_TASKS) { /* tasks */
1434 strcpy(cmd, "MSGS ALL");
1437 if (WC->wc_view == VIEW_NOTES) { /* notes */
1439 strcpy(cmd, "MSGS ALL");
1443 nummsgs = load_msg_ptrs(cmd);
1446 if ((!is_tasks) && (!is_calendar) && (!is_notes)) {
1447 if (!strcmp(oper, "readnew")) {
1448 wprintf("<EM>No new messages.</EM>\n");
1449 } else if (!strcmp(oper, "readold")) {
1450 wprintf("<EM>No old messages.</EM>\n");
1452 wprintf("<EM>No messages here.</EM>\n");
1460 if (WC->num_summ != 0) {
1464 WC->num_summ = nummsgs;
1465 WC->summ = malloc(WC->num_summ*sizeof(struct message_summary));
1466 for (a = 0; a < nummsgs; ++a) {
1467 /* Gather summary information */
1468 summarize_message(a, WC->msgarr[a], is_new);
1470 /* Are you a new message, or an old message? */
1472 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
1473 WC->summ[a].is_new = 0;
1476 WC->summ[a].is_new = 1;
1482 if (startmsg == 0L) startmsg = WC->msgarr[0];
1483 remaining_messages = 0;
1485 for (a = 0; a < nummsgs; ++a) {
1486 if (WC->msgarr[a] >= startmsg) {
1487 ++remaining_messages;
1492 if (!strcasecmp(sortby, "subject")) {
1493 qsort(WC->summ, WC->num_summ,
1494 sizeof(struct message_summary), summcmp_subj);
1496 else if (!strcasecmp(sortby, "rsubject")) {
1497 qsort(WC->summ, WC->num_summ,
1498 sizeof(struct message_summary), summcmp_rsubj);
1500 else if (!strcasecmp(sortby, "sender")) {
1501 qsort(WC->summ, WC->num_summ,
1502 sizeof(struct message_summary), summcmp_sender);
1504 else if (!strcasecmp(sortby, "rsender")) {
1505 qsort(WC->summ, WC->num_summ,
1506 sizeof(struct message_summary), summcmp_rsender);
1508 else if (!strcasecmp(sortby, "date")) {
1509 qsort(WC->summ, WC->num_summ,
1510 sizeof(struct message_summary), summcmp_date);
1512 else if (!strcasecmp(sortby, "rdate")) {
1513 qsort(WC->summ, WC->num_summ,
1514 sizeof(struct message_summary), summcmp_rdate);
1518 if (!strcasecmp(sortby, "subject")) {
1519 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1521 else if (!strcasecmp(sortby, "rsubject")) {
1522 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1525 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1528 if (!strcasecmp(sortby, "sender")) {
1529 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1531 else if (!strcasecmp(sortby, "rsender")) {
1532 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1535 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1538 if (!strcasecmp(sortby, "date")) {
1539 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1541 else if (!strcasecmp(sortby, "rdate")) {
1542 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1545 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1549 wprintf("</div>"); /* end of 'content' div */
1551 wprintf("<div id=\"message_list\">"
1553 "<div id=\"fix_scrollbar_bug\">\n"
1555 "<form name=\"msgomatic\" "
1556 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n"
1558 "<table border=0 cellspacing=0 "
1559 "cellpadding=0 width=100%%>\n"
1561 "<TD align=center><b><i>Subject</i></b> %s</TD>"
1562 "<TD align=center><b><i>Sender</i></b> %s</TD>"
1563 "<TD align=center><b><i>Date</i></b> %s</TD>"
1564 "<TD><INPUT TYPE=\"submit\" NAME=\"sc\" "
1565 "STYLE=\"font-family: Bitstream Vera Sans,Arial,Helvetica,sans-serif;"
1566 " font-size: 6pt;\" "
1567 "VALUE=\"Delete\"></TD>"
1576 for (a = 0; a < nummsgs; ++a) {
1577 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
1579 /* Learn which msgs "Prev" & "Next" buttons go to */
1580 pn_current = WC->msgarr[a];
1581 if (a > 0) pn_previous = WC->msgarr[a-1];
1582 if (a < (nummsgs-1)) pn_next = WC->msgarr[a+1];
1584 /* If a tabular view, set up the line */
1587 wprintf("<TR BGCOLOR=\"#%s\">",
1588 (bg ? "DDDDDD" : "FFFFFF")
1592 /* Display the message */
1594 display_summarized(a);
1596 else if (is_addressbook) {
1597 fetch_ab_name(WC->msgarr[a], buf);
1599 addrbook = realloc(addrbook,
1600 (sizeof(struct addrbookent) * num_ab) );
1601 safestrncpy(addrbook[num_ab-1].ab_name, buf,
1602 sizeof(addrbook[num_ab-1].ab_name));
1603 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
1605 else if (is_calendar) {
1606 display_calendar(WC->msgarr[a]);
1608 else if (is_tasks) {
1609 display_task(WC->msgarr[a]);
1611 else if (is_notes) {
1612 display_note(WC->msgarr[a]);
1615 read_message(WC->msgarr[a]);
1618 /* If a tabular view, finish the line */
1623 if (lowest_displayed < 0) lowest_displayed = a;
1624 highest_displayed = a;
1627 --remaining_messages;
1632 wprintf("</table></form>"
1633 "</div>\n"); /* end of 'fix_scrollbar_bug' div */
1634 wprintf("</div>"); /* end of 'message_list' div */
1636 /* Put the data transfer hidden iframe in a hidden div, to make it *really* hidden */
1637 wprintf("<div display=\"hidden\">\n"
1638 "<iframe name=\"msgloader1\" id=\"msgloader1\" width=\"1\"></iframe>\n"
1642 wprintf("<div id=\"preview_pane\">"); /* The preview pane will initially be empty */
1645 /* Bump these because although we're thinking in zero base, the user
1646 * is a drooling idiot and is thinking in one base.
1649 ++highest_displayed;
1651 /* If we're only looking at one message, do a prev/next thing */
1652 if (num_displayed == 1) {
1653 if ((!is_tasks) && (!is_calendar) && (!is_addressbook) && (!is_notes) && (!is_singlecard)) {
1655 wprintf("<div id=\"fix_scrollbar_bug\">"
1656 "<table border=0 width=100%% bgcolor=\"#dddddd\"><tr><td>"
1657 "Reading #%d of %d messages.</TD>\n"
1658 "<TD ALIGN=RIGHT><FONT SIZE=+1>",
1659 lowest_displayed, nummsgs);
1661 if (pn_previous > 0L) {
1662 wprintf("<A HREF=\"/%s"
1672 wprintf("<A HREF=\"/%s"
1681 wprintf("<A HREF=\"/%s?startmsg=%ld"
1682 "?maxmsgs=%d?summary=1\">"
1690 wprintf("</td></tr></table></div>\n");
1695 * If we're not currently looking at ALL requested
1696 * messages, then display the selector bar
1698 if (num_displayed > 1) {
1699 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
1700 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
1702 wprintf("<form name=\"msgomatic\" "
1703 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n");
1705 wprintf("Reading #", lowest_displayed, highest_displayed);
1707 wprintf("<select name=\"whichones\" size=\"1\" "
1708 "OnChange=\"location.href=msgomatic.whichones.options"
1709 "[selectedIndex].value\">\n");
1711 for (b=0; b<nummsgs; b = b + maxmsgs) {
1714 if (hi > nummsgs) hi = nummsgs;
1715 wprintf("<option %s value="
1720 "%d-%d</option> \n",
1721 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
1728 wprintf("<option value=\"/%s?startmsg=%ld"
1729 "?maxmsgs=9999999?summary=%d\">"
1733 WC->msgarr[0], is_summary);
1735 wprintf("</select> of %d messages.", nummsgs);
1736 wprintf("</form>\n");
1742 do_tasks_view(); /* Render the task list */
1746 do_calendar_view(); /* Render the calendar */
1749 if (is_addressbook) {
1750 do_addrbook_view(addrbook, num_ab); /* Render the address book */
1753 /* Note: wDumpContent() will output one additional </div> tag.
1754 * Which div it is the end of depends on what mode we're viewing in.
1755 * If we're in summary mode, it's the end of the preview pane.
1756 * Otherwise it's the end of the usual content div.
1759 if (addrbook != NULL) free(addrbook);
1761 /* free the summary */
1762 if (WC->num_summ != 0) {
1767 /* If we got here via a mailbox view and are reading a single
1768 * message, mark it as "seen." We do this after rendering the web page
1769 * so it doesn't keep the user waiting.
1771 if ( (maxmsgs == 1) && (WC->wc_view == VIEW_MAILBOX) ) {
1772 serv_printf("SEEN %ld|1", startmsg);
1773 serv_getln(buf, sizeof buf);
1779 * Back end for post_message() ... this is where the actual message
1780 * gets transmitted to the server.
1782 void post_mime_to_server(void) {
1784 int is_multipart = 0;
1786 struct wc_attachment *att;
1788 size_t encoded_length;
1790 /* If there are attachments, we have to do multipart/mixed */
1791 if (WC->first_attachment != NULL) {
1796 sprintf(boundary, "---Citadel-Multipart-%s-%04x%04x---",
1797 serv_info.serv_fqdn,
1802 /* Remember, serv_printf() appends an extra newline */
1803 serv_printf("Content-type: multipart/mixed; "
1804 "boundary=\"%s\"\n", boundary);
1805 serv_printf("This is a multipart message in MIME format.\n");
1806 serv_printf("--%s", boundary);
1809 serv_puts("Content-type: text/html; charset=utf-8");
1811 serv_puts("<HTML><BODY>\n");
1812 text_to_server(bstr("msgtext"), 0);
1813 serv_puts("</BODY></HTML>\n");
1818 /* Add in the attachments */
1819 for (att = WC->first_attachment; att!=NULL; att=att->next) {
1821 encoded_length = ((att->length * 150) / 100);
1822 encoded = malloc(encoded_length);
1823 if (encoded == NULL) break;
1824 CtdlEncodeBase64(encoded, att->data, att->length);
1826 serv_printf("--%s", boundary);
1827 serv_printf("Content-type: %s", att->content_type);
1828 serv_printf("Content-disposition: attachment; "
1829 "filename=\"%s\"", att->filename);
1830 serv_puts("Content-transfer-encoding: base64");
1832 serv_write(encoded, strlen(encoded));
1837 serv_printf("--%s--", boundary);
1845 * Post message (or don't post message)
1847 * Note regarding the "dont_post" variable:
1848 * A random value (actually, it's just a timestamp) is inserted as a hidden
1849 * field called "postseq" when the display_enter page is generated. This
1850 * value is checked when posting, using the static variable dont_post. If a
1851 * user attempts to post twice using the same dont_post value, the message is
1852 * discarded. This prevents the accidental double-saving of the same message
1853 * if the user happens to click the browser "back" button.
1855 void post_message(void)
1858 static long dont_post = (-1L);
1859 struct wc_attachment *att, *aptr;
1861 if (WC->upload_length > 0) {
1863 /* There's an attachment. Save it to this struct... */
1864 att = malloc(sizeof(struct wc_attachment));
1865 memset(att, 0, sizeof(struct wc_attachment));
1866 att->length = WC->upload_length;
1867 strcpy(att->content_type, WC->upload_content_type);
1868 strcpy(att->filename, WC->upload_filename);
1871 /* And add it to the list. */
1872 if (WC->first_attachment == NULL) {
1873 WC->first_attachment = att;
1876 aptr = WC->first_attachment;
1877 while (aptr->next != NULL) aptr = aptr->next;
1881 /* Netscape sends a simple filename, which is what we want,
1882 * but Satan's browser sends an entire pathname. Reduce
1883 * the path to just a filename if we need to.
1885 while (num_tokens(att->filename, '/') > 1) {
1886 remove_token(att->filename, 0, '/');
1888 while (num_tokens(att->filename, '\\') > 1) {
1889 remove_token(att->filename, 0, '\\');
1892 /* Transfer control of this memory from the upload struct
1893 * to the attachment struct.
1895 att->data = WC->upload;
1896 WC->upload_length = 0;
1902 if (!strcasecmp(bstr("sc"), "Cancel")) {
1903 sprintf(WC->ImportantMessage,
1904 "Cancelled. Message was not posted.");
1905 } else if (!strcasecmp(bstr("attach"), "Add")) {
1908 } else if (atol(bstr("postseq")) == dont_post) {
1909 sprintf(WC->ImportantMessage,
1910 "Automatically cancelled because you have already "
1911 "saved this message.");
1913 sprintf(buf, "ENT0 1|%s|0|4|%s",
1917 serv_getln(buf, sizeof buf);
1918 if (buf[0] == '4') {
1919 post_mime_to_server();
1920 if (strlen(bstr("recp")) > 0) {
1921 sprintf(WC->ImportantMessage, "Message has been sent.\n");
1924 sprintf(WC->ImportantMessage, "Message has been posted.\n");
1926 dont_post = atol(bstr("postseq"));
1928 sprintf(WC->ImportantMessage,
1933 free_attachments(WC);
1934 readloop("readnew");
1941 * display the message entry screen
1943 void display_enter(void)
1947 struct wc_attachment *att;
1949 if (strlen(bstr("force_room")) > 0) {
1950 gotoroom(bstr("force_room"));
1953 /* Are we perhaps in an address book view? If so, then an "enter
1954 * message" command really means "add new entry."
1956 if (WC->wc_view == VIEW_ADDRESSBOOK) {
1957 do_edit_vcard(-1, "", "");
1961 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1962 /* Are we perhaps in a calendar view? If so, then an "enter
1963 * message" command really means "add new calendar item."
1965 if (WC->wc_view == VIEW_CALENDAR) {
1966 display_edit_event();
1970 /* Are we perhaps in a tasks view? If so, then an "enter
1971 * message" command really means "add new task."
1973 if (WC->wc_view == VIEW_TASKS) {
1974 display_edit_task();
1979 /* Otherwise proceed normally. Do a custom room banner with no navbar... */
1980 output_headers(1, 1, 2, 0, 0, 0, 0);
1981 wprintf("<div id=\"banner\">\n");
1982 embed_room_banner(NULL, navbar_none);
1983 wprintf("</div>\n");
1984 wprintf("<div id=\"content\">\n"
1985 "<div id=\"fix_scrollbar_bug\">"
1986 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
1988 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
1990 serv_getln(buf, sizeof buf);
1992 if (!strncmp(buf, "570", 3)) {
1993 if (strlen(bstr("recp")) > 0) {
1994 svprintf("RECPERROR", WCS_STRING,
1995 "<SPAN CLASS=\"errormsg\">%s</SPAN><br />\n",
1999 do_template("prompt_for_recipient");
2002 if (buf[0] != '2') {
2003 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2008 fmt_date(buf, now, 0);
2009 strcat(&buf[strlen(buf)], " <I>from</I> ");
2010 stresc(&buf[strlen(buf)], WC->wc_username, 1, 1);
2011 if (strlen(bstr("recp")) > 0) {
2012 strcat(&buf[strlen(buf)], " <I>to</I> ");
2013 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
2015 strcat(&buf[strlen(buf)], " <I>in</I> ");
2016 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
2018 /* begin message entry screen */
2019 // wprintf("<div style=\"position:absolute; left:1%%; width:96%%; height:100%%\">\n");
2021 wprintf("<form enctype=\"multipart/form-data\" "
2022 "method=\"POST\" action=\"/post\" "
2023 "name=\"enterform\""
2024 "onSubmit=\"return submitForm();\""
2026 wprintf("<input type=\"hidden\" name=\"recp\" value=\"%s\">\n",
2028 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n",
2031 wprintf("%s<br>\n", buf); /* header bar */
2032 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2033 /* "onLoad=\"document.enterform.msgtext.focus();\" " */
2034 wprintf("<font size=-1>Subject (optional):</font>"
2035 "<input type=\"text\" name=\"subject\" value=\"");
2036 escputs(bstr("subject"));
2037 wprintf("\" size=40 maxlength=70>"
2041 wprintf("<input type=\"submit\" name=\"sc\" value=\"");
2042 if (strlen(bstr("recp")) > 0) {
2043 wprintf("Send message");
2045 wprintf("Post message");
2048 "<input type=\"submit\" name=\"sc\" value=\"Cancel\">\n");
2050 wprintf("<center><script type=\"text/javascript\" "
2051 "src=\"static/richtext.js\"></script>\n"
2052 "<script type=\"text/javascript\">\n"
2053 "function submitForm() { \n"
2054 " updateRTE('msgtext'); \n"
2058 "initRTE(\"static/\", \"static/\", \"\"); \n"
2060 "<noscript>JavaScript must be enabled.</noscript> \n"
2061 "<script type=\"text/javascript\"> \n"
2062 "writeRichText('msgtext', '");
2063 msgescputs(bstr("msgtext"));
2064 wprintf("', '96%%', '200', true, false); \n"
2065 "</script></center><br />\n");
2067 /* Enumerate any attachments which are already in place... */
2068 wprintf("<img src=\"/static/diskette_24x.gif\" border=0 "
2069 "align=middle height=16 width=16> Attachments: ");
2070 wprintf("<select name=\"which_attachment\" size=1>");
2071 for (att = WC->first_attachment; att != NULL; att = att->next) {
2072 wprintf("<option value=\"");
2073 urlescputs(att->filename);
2075 escputs(att->filename);
2076 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
2077 wprintf("</option>\n");
2079 wprintf("</select>");
2081 /* Now offer the ability to attach additional files... */
2082 wprintf(" "
2083 "Attach file: <input NAME=\"attachfile\" "
2084 "SIZE=16 TYPE=\"file\">\n "
2085 "<input type=\"submit\" name=\"attach\" value=\"Add\">\n");
2087 wprintf("</form>\n");
2089 wprintf("</td></tr></table></div>\n");
2090 DONE: wDumpContent(1);
2100 void delete_msg(void)
2105 msgid = atol(bstr("msgid"));
2107 output_headers(1, 1, 1, 0, 0, 0, 0);
2109 sprintf(buf, "DELE %ld", msgid);
2111 serv_getln(buf, sizeof buf);
2112 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2121 * Confirm move of a message
2123 void confirm_move_msg(void)
2129 msgid = atol(bstr("msgid"));
2131 output_headers(1, 1, 1, 0, 0, 0, 0);
2133 wprintf("<div id=\"fix_scrollbar_bug\">"
2134 "<table width=100%% border=0 bgcolor=\"#444455\"><tr><td>");
2135 wprintf("<font size=+1 color=\"#ffffff\"");
2136 wprintf("<b>Confirm move of message</b>\n");
2137 wprintf("</font></td></tr></table></div>\n");
2139 wprintf("<CENTER>");
2141 wprintf("Move this message to:<br />\n");
2143 wprintf("<form METHOD=\"POST\" ACTION=\"/move_msg\">\n");
2144 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
2148 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
2150 serv_getln(buf, sizeof buf);
2151 if (buf[0] == '1') {
2152 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2153 extract_token(targ, buf, 0, '|', sizeof targ);
2154 wprintf("<OPTION>");
2159 wprintf("</SELECT>\n");
2160 wprintf("<br />\n");
2162 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
2164 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
2165 wprintf("</form></CENTER>\n");
2167 wprintf("</CENTER>\n");
2178 msgid = atol(bstr("msgid"));
2180 output_headers(1, 1, 1, 0, 0, 0, 0);
2182 if (!strcasecmp(bstr("yesno"), "Move")) {
2183 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
2185 serv_getln(buf, sizeof buf);
2186 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2188 wprintf("<EM>Message not moved.</EM><br />\n");
2195 * This gets called when a user selects multiple messages in a summary
2196 * list and then clicks to perform a transformation of some sort on them
2197 * (such as deleting them).
2199 void do_stuff_to_msgs(void) {
2204 struct stuff_t *next;
2208 struct stuff_t *stuff = NULL;
2209 struct stuff_t *ptr;
2212 serv_puts("MSGS ALL");
2213 serv_getln(buf, sizeof buf);
2215 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2216 ptr = malloc(sizeof(struct stuff_t));
2217 ptr->msgnum = atol(buf);
2222 strcpy(sc, bstr("sc"));
2224 while (stuff != NULL) {
2226 sprintf(buf, "msg_%ld", stuff->msgnum);
2227 if (!strcasecmp(bstr(buf), "yes")) {
2229 if (!strcasecmp(sc, "Delete")) {
2230 serv_printf("DELE %ld", stuff->msgnum);
2231 serv_getln(buf, sizeof buf);
2241 readloop("readfwd");