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;
100 remove_token(end, 0, '?');
101 remove_token(end, 0, '?');
102 remove_token(end, 0, '?');
103 remove_token(end, 0, '?');
104 strcpy(end, &end[1]);
106 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
112 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
124 * Look for URL's embedded in a buffer and make them linkable. We use a
125 * target window in order to keep the BBS session in its own window.
141 for (pos = 0; pos < strlen(buf); ++pos) {
142 if (!strncasecmp(&buf[pos], "http://", 7))
144 if (!strncasecmp(&buf[pos], "ftp://", 6))
151 if ((start > 0) && (buf[start - 1] == '<'))
153 if ((start > 0) && (buf[start - 1] == '['))
155 if ((start > 0) && (buf[start - 1] == '('))
157 if ((start > 0) && (buf[start - 1] == '{'))
160 for (pos = strlen(buf); pos > start; --pos) {
161 if ((buf[pos] == ' ') || (buf[pos] == ench))
165 strncpy(urlbuf, &buf[start], end - start);
166 urlbuf[end - start] = 0;
168 strncpy(outbuf, buf, start);
169 sprintf(&outbuf[start], "%cA HREF=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
170 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
171 strcat(outbuf, &buf[end]);
172 if ( strlen(outbuf) < 250 )
178 * Turn a vCard "n" (name) field into something displayable.
180 void vcard_n_prettyize(char *name)
185 original_name = strdup(name);
186 for (i=0; i<5; ++i) {
187 if (strlen(original_name) > 0) {
188 if (original_name[strlen(original_name)-1] == ' ') {
189 original_name[strlen(original_name)-1] = 0;
191 if (original_name[strlen(original_name)-1] == ';') {
192 original_name[strlen(original_name)-1] = 0;
197 for (i=0; i<strlen(original_name); ++i) {
198 if (original_name[i] == ';') {
202 name[strlen(name)+1] = 0;
203 name[strlen(name)] = original_name[i];
212 /* display_vcard() calls this after parsing the textual vCard into
213 * our 'struct vCard' data object.
214 * This gets called instead of display_parsed_vcard() if we are only looking
215 * to extract the person's name instead of displaying the card.
217 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
220 strcpy(storename, "");
222 name = vcard_get_prop(v, "n", 1, 0, 0);
224 strcpy(storename, name);
225 /* vcard_n_prettyize(storename); */
232 /* display_vcard() calls this after parsing the textual vCard into
233 * our 'struct vCard' data object.
235 * Set 'full' to nonzero to display the full card, otherwise it will only
236 * show a summary line.
238 * This code is a bit ugly, so perhaps an explanation is due: we do this
239 * in two passes through the vCard fields. On the first pass, we process
240 * fields we understand, and then render them in a pretty fashion at the
241 * end. Then we make a second pass, outputting all the fields we don't
242 * understand in a simple two-column name/value format.
244 void display_parsed_vcard(struct vCard *v, int full) {
250 char *thisname, *thisvalue;
251 char firsttoken[SIZ];
254 char displayname[SIZ];
260 strcpy(displayname, "");
268 name = vcard_get_prop(v, "fn", 1, 0, 0);
272 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
273 strcpy(displayname, name);
274 vcard_n_prettyize(displayname);
275 escputs(displayname);
284 wprintf("<div align=center><table bgcolor=#aaaaaa width=50%%>");
285 for (pass=1; pass<=2; ++pass) {
287 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
289 thisname = strdup(v->prop[i].name);
290 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
292 for (j=0; j<num_tokens(thisname, ';'); ++j) {
293 extract_token(buf, thisname, j, ';', sizeof buf);
294 if (!strcasecmp(buf, "encoding=quoted-printable")) {
296 remove_token(thisname, j, ';');
298 if (!strcasecmp(buf, "encoding=base64")) {
300 remove_token(thisname, j, ';');
305 thisvalue = malloc(strlen(v->prop[i].value) + 50);
306 j = CtdlDecodeQuotedPrintable(
307 thisvalue, v->prop[i].value,
308 strlen(v->prop[i].value) );
312 thisvalue = malloc(strlen(v->prop[i].value) + 50);
314 thisvalue, v->prop[i].value,
315 strlen(v->prop[i].value) );
318 thisvalue = strdup(v->prop[i].value);
321 /*** Various fields we may encounter ***/
323 /* N is name, but only if there's no FN already there */
324 if (!strcasecmp(firsttoken, "n")) {
325 if (strlen(displayname) == 0) {
326 strcpy(displayname, thisvalue);
327 vcard_n_prettyize(displayname);
331 /* FN (full name) is a true 'display name' field */
332 else if (!strcasecmp(firsttoken, "fn")) {
333 strcpy(displayname, thisvalue);
337 else if (!strcasecmp(firsttoken, "title")) {
338 strcpy(title, thisvalue);
342 else if (!strcasecmp(firsttoken, "org")) {
343 strcpy(org, thisvalue);
346 else if (!strcasecmp(firsttoken, "email")) {
347 if (strlen(mailto) > 0) strcat(mailto, "<br />");
349 "<A HREF=\"/display_enter"
350 "?force_room=_MAIL_?recp=");
351 urlesc(&mailto[strlen(mailto)], thisvalue);
352 strcat(mailto, "\">");
353 urlesc(&mailto[strlen(mailto)], thisvalue);
354 strcat(mailto, "</A>");
356 else if (!strcasecmp(firsttoken, "tel")) {
357 if (strlen(phone) > 0) strcat(phone, "<br />");
358 strcat(phone, thisvalue);
359 for (j=0; j<num_tokens(thisname, ';'); ++j) {
360 extract_token(buf, thisname, j, ';', sizeof buf);
361 if (!strcasecmp(buf, "tel"))
363 else if (!strcasecmp(buf, "work"))
364 strcat(phone, " (work)");
365 else if (!strcasecmp(buf, "home"))
366 strcat(phone, " (home)");
367 else if (!strcasecmp(buf, "cell"))
368 strcat(phone, " (cell)");
376 else if (!strcasecmp(firsttoken, "adr")) {
378 wprintf("<TR><TD>Address:</TD><TD>");
379 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
380 extract_token(buf, thisvalue, j, ';', sizeof buf);
381 if (strlen(buf) > 0) {
383 if (j<3) wprintf("<br />");
387 wprintf("</TD></TR>\n");
390 else if (!strcasecmp(firsttoken, "version")) {
393 else if (!strcasecmp(firsttoken, "rev")) {
396 else if (!strcasecmp(firsttoken, "label")) {
401 /*** Don't show extra fields. They're ugly.
405 wprintf("</TD><TD>");
407 wprintf("</TD></TR>\n");
417 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
418 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
419 "<IMG ALIGN=CENTER SRC=\"/static/viewcontacts_48x.gif\">"
420 "<FONT SIZE=+1><B>");
421 escputs(displayname);
422 wprintf("</B></FONT>");
423 if (strlen(title) > 0) {
424 wprintf("<div align=right>");
428 if (strlen(org) > 0) {
429 wprintf("<div align=right>");
433 wprintf("</TD></TR>\n");
435 if (strlen(phone) > 0)
436 wprintf("<TR><TD>Telephone:</TD><TD>%s</TD></TR>\n", phone);
437 if (strlen(mailto) > 0)
438 wprintf("<TR><TD>E-mail:</TD><TD>%s</TD></TR>\n", mailto);
443 wprintf("</table></div>\n");
449 * Display a textual vCard
450 * (Converts to a vCard object and then calls the actual display function)
451 * Set 'full' to nonzero to display the whole card instead of a one-liner.
452 * Or, if "storename" is non-NULL, just store the person's name in that
453 * buffer instead of displaying the card at all.
455 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
461 v = vcard_load(vcard_source);
462 if (v == NULL) return;
464 name = vcard_get_prop(v, "n", 1, 0, 0);
470 if (storename != NULL) {
471 fetchname_parsed_vcard(v, storename);
473 else if ( (alpha == 0)
474 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
475 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
477 display_parsed_vcard(v, full);
487 * I wanna SEE that message!
489 void read_message(long msgnum, int suppress_buttons) {
491 char mime_partnum[256];
492 char mime_filename[256];
493 char mime_content_type[256];
494 char mime_charset[256];
495 char mime_disposition[256];
508 char vcard_partnum[256];
509 char cal_partnum[256];
510 char *part_source = NULL;
512 iconv_t ic = (iconv_t)(-1) ;
513 char *ibuf; /* Buffer of characters to be converted */
514 char *obuf; /* Buffer for converted characters */
515 size_t ibuflen; /* Length of input buffer */
516 size_t obuflen; /* Length of output buffer */
517 char *osav; /* Saved pointer to output buffer */
523 strcpy(reply_to, "");
524 strcpy(vcard_partnum, "");
525 strcpy(cal_partnum, "");
526 strcpy(mime_http, "");
527 strcpy(mime_content_type, "text/plain");
528 strcpy(mime_charset, "us-ascii");
530 serv_printf("MSG4 %ld", msgnum);
531 serv_getln(buf, sizeof buf);
533 wprintf("<STRONG>ERROR:</STRONG> %s<br />\n", &buf[4]);
537 /* begin everythingamundo table */
538 wprintf("<div id=\"fix_scrollbar_bug\">\n");
539 wprintf("<table width=100%% border=1 cellspacing=0 "
540 "cellpadding=0><TR><TD>\n");
542 /* begin message header table */
543 wprintf("<TABLE WIDTH=100%% BORDER=0 CELLSPACING=0 "
544 "CELLPADDING=1 BGCOLOR=\"#CCCCCC\"><TR><TD>\n");
546 wprintf("<SPAN CLASS=\"message_header\">");
547 strcpy(m_subject, "");
549 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
550 if (!strcmp(buf, "000")) {
551 wprintf("<I>unexpected end of message</I><br /><br />\n");
552 wprintf("</SPAN>\n");
555 if (!strncasecmp(buf, "nhdr=yes", 8))
559 if (!strncasecmp(buf, "type=", 5))
560 format_type = atoi(&buf[5]);
561 if (!strncasecmp(buf, "from=", 5)) {
562 strcpy(from, &buf[5]);
563 wprintf("from <A HREF=\"/showuser?who=");
565 utf8ify_rfc822_string(from);
572 if (!strncasecmp(buf, "subj=", 5))
573 strcpy(m_subject, &buf[5]);
574 if ((!strncasecmp(buf, "hnod=", 5))
575 && (strcasecmp(&buf[5], serv_info.serv_humannode)))
576 wprintf("(%s) ", &buf[5]);
577 if ((!strncasecmp(buf, "room=", 5))
578 && (strcasecmp(&buf[5], WC->wc_roomname))
579 && (strlen(&buf[5])>0) )
580 wprintf("in %s> ", &buf[5]);
581 if (!strncasecmp(buf, "rfca=", 5)) {
582 strcpy(rfca, &buf[5]);
588 if (!strncasecmp(buf, "node=", 5)) {
589 strcpy(node, &buf[5]);
590 if ( ((WC->room_flags & QR_NETWORK)
591 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
592 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
595 wprintf("@%s ", &buf[5]);
598 if (!strncasecmp(buf, "rcpt=", 5))
599 wprintf("to %s ", &buf[5]);
600 if (!strncasecmp(buf, "time=", 5)) {
601 fmt_date(now, atol(&buf[5]), 0);
605 if (!strncasecmp(buf, "part=", 5)) {
606 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
607 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
608 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
609 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
610 mime_length = extract_int(&buf[5], 5);
612 if (!strcasecmp(mime_disposition, "attachment")) {
613 snprintf(&mime_http[strlen(mime_http)],
614 (sizeof(mime_http) - strlen(mime_http) - 1),
615 "<A HREF=\"/output_mimepart?"
616 "msgnum=%ld?partnum=%s\" "
617 "TARGET=\"wc.%ld.%s\">"
618 "<IMG SRC=\"/static/diskette_24x.gif\" "
619 "BORDER=0 ALIGN=MIDDLE>\n"
620 "Part %s: %s (%s, %d bytes)</A><br />\n",
621 msgnum, mime_partnum,
622 msgnum, mime_partnum,
623 mime_partnum, mime_filename,
624 mime_content_type, mime_length);
627 if ((!strcasecmp(mime_disposition, "inline"))
628 && (!strncasecmp(mime_content_type, "image/", 6)) ){
629 snprintf(&mime_http[strlen(mime_http)],
630 (sizeof(mime_http) - strlen(mime_http) - 1),
631 "<IMG SRC=\"/output_mimepart?"
632 "msgnum=%ld?partnum=%s\">",
633 msgnum, mime_partnum);
636 /*** begin handler prep ***/
637 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
638 strcpy(vcard_partnum, mime_partnum);
641 if (!strcasecmp(mime_content_type, "text/calendar")) {
642 strcpy(cal_partnum, mime_partnum);
645 /*** end handler prep ***/
651 /* Generate a reply-to address */
652 if (strlen(rfca) > 0) {
653 strcpy(reply_to, rfca);
656 if ( (strlen(node) > 0)
657 && (strcasecmp(node, serv_info.serv_nodename))
658 && (strcasecmp(node, serv_info.serv_humannode)) ) {
659 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
663 snprintf(reply_to, sizeof(reply_to), "%s", from);
673 utf8ify_rfc822_string(m_subject);
675 if (strlen(m_subject) > 0) {
677 "<SPAN CLASS=\"message_subject\">"
684 /* start msg buttons */
685 if (!suppress_buttons) {
686 wprintf("<td align=right>\n");
689 wprintf("<a href=\"/display_enter?recp=");
690 urlescputs(reply_to);
691 wprintf("?subject=");
692 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
693 urlescputs(m_subject);
694 wprintf("\">[Reply]</a> ");
696 if (WC->is_room_aide) {
699 wprintf("<a href=\"/confirm_move_msg?msgid=%ld\">[Move]</a> ",
703 wprintf("<a href=\"/delete_msg?msgid=%ld\" "
704 "onClick=\"return confirm('Delete this message?');\">"
705 "[Delete]</a> ", msgnum);
709 wprintf("<a href=\"/msg?msgnum=%ld?print_it=yes\" target=\"msgloader1\">"
710 "[Print]</a>", msgnum);
715 wprintf("</TR></TABLE>\n");
718 wprintf("<TABLE BORDER=0 WIDTH=100%% BGCOLOR=#FFFFFF "
719 "CELLPADDING=1 CELLSPACING=0><TR><TD>");
722 * Learn the content type
724 strcpy(mime_content_type, "text/plain");
725 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
726 if (!strcmp(buf, "000")) {
727 wprintf("<I>unexpected end of message</I><br /><br />\n");
730 if (!strncasecmp(buf, "Content-type: ", 14)) {
731 safestrncpy(mime_content_type, &buf[14],
732 sizeof(mime_content_type));
733 for (i=0; i<strlen(mime_content_type); ++i) {
734 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
735 safestrncpy(mime_charset, &mime_content_type[i+8],
736 sizeof mime_charset);
739 for (i=0; i<strlen(mime_content_type); ++i) {
740 if (mime_content_type[i] == ';') {
741 mime_content_type[i] = 0;
747 /* Set up a character set conversion if we need to (and if we can) */
749 if ( (strcasecmp(mime_charset, "us-ascii"))
750 && (strcasecmp(mime_charset, "UTF-8")) ) {
751 ic = iconv_open("UTF-8", mime_charset);
752 if (ic == (iconv_t)(-1) ) {
753 lprintf(5, "iconv_open() failed: %s\n", strerror(errno));
758 /* Messages in legacy Citadel variformat get handled thusly... */
759 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
760 fmout(NULL, "JUSTIFY");
763 /* Boring old 80-column fixed format text gets handled this way... */
764 else if (!strcasecmp(mime_content_type, "text/plain")) {
765 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
766 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
767 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
770 if (ic != (iconv_t)(-1) ) {
772 ibuflen = strlen(ibuf);
774 obuf = (char *) malloc(obuflen);
776 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
777 osav[SIZ-obuflen] = 0;
778 safestrncpy(buf, osav, sizeof buf);
783 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
784 buf[strlen(buf) - 1] = 0;
786 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
787 wprintf("<BLOCKQUOTE>");
789 } else if ((bq == 1) &&
790 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
791 wprintf("</BLOCKQUOTE>");
797 wprintf("</TT><br />\n");
799 wprintf("</I><br />");
802 else /* HTML is fun, but we've got to strip it first */
803 if (!strcasecmp(mime_content_type, "text/html")) {
804 output_html(mime_charset);
807 /* Unknown weirdness */
809 wprintf("I don't know how to display %s<br />\n",
811 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
814 /* Afterwards, offer links to download attachments 'n' such */
815 if (strlen(mime_http) > 0) {
816 wprintf("%s", mime_http);
819 /* Handler for vCard parts */
820 if (strlen(vcard_partnum) > 0) {
821 part_source = load_mimepart(msgnum, vcard_partnum);
822 if (part_source != NULL) {
824 /* If it's my vCard I can edit it */
825 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
826 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
827 || (WC->wc_view == VIEW_ADDRESSBOOK)
829 wprintf("<A HREF=\"/edit_vcard?"
830 "msgnum=%ld?partnum=%s\">",
831 msgnum, vcard_partnum);
832 wprintf("[edit]</A>");
835 /* In all cases, display the full card */
836 display_vcard(part_source, 0, 1, NULL);
840 /* Handler for calendar parts */
841 if (strlen(cal_partnum) > 0) {
842 part_source = load_mimepart(msgnum, cal_partnum);
843 if (part_source != NULL) {
844 cal_process_attachment(part_source,
845 msgnum, cal_partnum);
855 wprintf("</TD></TR></TABLE>\n");
857 /* end everythingamundo table */
858 wprintf("</TD></TR></TABLE>\n");
859 wprintf("</div><br />\n");
862 if (ic != (iconv_t)(-1) ) {
871 * Unadorned HTML output of an individual message, suitable
872 * for placing in a hidden iframe, for printing, or whatever
874 void embed_message(void) {
880 msgnum = atol(bstr("msgnum"));
881 sourceiframe = bstr("sourceiframe");
882 targetdiv = bstr("targetdiv");
883 print_it = bstr("print_it");
885 output_headers(1, 0, 0, 0, 0, 1, 0);
888 wprintf("<html><head>");
890 /* If we're loading into a hidden iframe, chances are the caller told us
891 * about a target div somewhere that we need to copy into when we're done.
893 if (strlen(targetdiv) > 0) wprintf(
895 " <script type=\"text/javascript\"> \n"
896 " function loaded_now_copy_it() { \n"
897 " parent.document.getElementById(\"%s\").innerHTML = parent.frames['%s'].document.body.innerHTML; \n"
906 if (strlen(targetdiv) > 0) {
907 wprintf(" onLoad='loaded_now_copy_it();'");
909 if (!strcasecmp(print_it, "yes")) {
910 wprintf(" onLoad='window.print();'");
913 read_message(msgnum, (!strcasecmp(print_it, "yes") ? 1 : 0) );
914 wprintf("</body></html>\n");
921 void display_summarized(int num) {
925 if (WC->summ[num].is_new) wprintf("<B>");
926 wprintf("<A HREF=\"/msg?msgnum=%ld?sourceiframe=msgloader1?targetdiv=preview_pane\" target=\"msgloader1\">",
927 WC->summ[num].msgnum);
928 escputs(WC->summ[num].subj);
930 if (WC->summ[num].is_new) wprintf("</B>");
931 wprintf("</TD><TD>");
932 if (WC->summ[num].is_new) wprintf("<B>");
933 escputs(WC->summ[num].from);
934 if (WC->summ[num].is_new) wprintf("</B>");
935 wprintf(" </TD><TD>");
936 if (WC->summ[num].is_new) wprintf("<B>");
937 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
939 if (WC->summ[num].is_new) wprintf("</B>");
942 "<INPUT TYPE=\"checkbox\" NAME=\"msg_%ld\" VALUE=\"yes\">"
949 void summarize_message(int num, long msgnum, int is_new) {
952 memset(&WC->summ[num], 0, sizeof(struct message_summary));
953 safestrncpy(WC->summ[num].subj, "(no subject)", sizeof WC->summ[num].subj);
954 WC->summ[num].is_new = is_new;
955 WC->summ[num].msgnum = msgnum;
957 /* ask for headers only with no MIME */
958 sprintf(buf, "MSG0 %ld|3", msgnum);
960 serv_getln(buf, sizeof buf);
961 if (buf[0] != '1') return;
963 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
964 if (!strncasecmp(buf, "from=", 5)) {
965 safestrncpy(WC->summ[num].from, &buf[5], sizeof WC->summ[num].from);
967 if (!strncasecmp(buf, "subj=", 5)) {
968 if (strlen(&buf[5]) > 0) {
969 safestrncpy(WC->summ[num].subj, &buf[5],
970 sizeof WC->summ[num].subj);
972 /* Handle subjects with RFC2047 encoding */
973 utf8ify_rfc822_string(WC->summ[num].subj);
975 if (strlen(WC->summ[num].subj) > 75) {
976 strcpy(&WC->summ[num].subj[72], "...");
981 if (!strncasecmp(buf, "node=", 5)) {
982 if ( ((WC->room_flags & QR_NETWORK)
983 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
984 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
986 strcat(WC->summ[num].from, " @ ");
987 strcat(WC->summ[num].from, &buf[5]);
991 if (!strncasecmp(buf, "rcpt=", 5)) {
992 safestrncpy(WC->summ[num].to, &buf[5], sizeof WC->summ[num].to);
995 if (!strncasecmp(buf, "time=", 5)) {
996 WC->summ[num].date = atol(&buf[5]);
1001 /* Handle senders with RFC2047 encoding */
1002 utf8ify_rfc822_string(WC->summ[num].from);
1004 if (strlen(WC->summ[num].from) > 25) {
1005 strcpy(&WC->summ[num].from[22], "...");
1011 void display_addressbook(long msgnum, char alpha) {
1013 char mime_partnum[SIZ];
1014 char mime_filename[SIZ];
1015 char mime_content_type[SIZ];
1016 char mime_disposition[SIZ];
1018 char vcard_partnum[SIZ];
1019 char *vcard_source = NULL;
1020 struct message_summary summ;
1022 memset(&summ, 0, sizeof(summ));
1023 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1025 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1027 serv_getln(buf, sizeof buf);
1028 if (buf[0] != '1') return;
1030 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1031 if (!strncasecmp(buf, "part=", 5)) {
1032 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1033 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1034 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1035 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1036 mime_length = extract_int(&buf[5], 5);
1038 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1039 strcpy(vcard_partnum, mime_partnum);
1045 if (strlen(vcard_partnum) > 0) {
1046 vcard_source = load_mimepart(msgnum, vcard_partnum);
1047 if (vcard_source != NULL) {
1049 /* Display the summary line */
1050 display_vcard(vcard_source, alpha, 0, NULL);
1052 /* If it's my vCard I can edit it */
1053 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1054 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1055 || (WC->wc_view == VIEW_ADDRESSBOOK)
1057 wprintf("<A HREF=\"/edit_vcard?"
1058 "msgnum=%ld?partnum=%s\">",
1059 msgnum, vcard_partnum);
1060 wprintf("[edit]</A>");
1071 /* If it's an old "Firstname Lastname" style record, try to
1074 void lastfirst_firstlast(char *namebuf) {
1075 char firstname[SIZ];
1079 if (namebuf == NULL) return;
1080 if (strchr(namebuf, ';') != NULL) return;
1082 i = num_tokens(namebuf, ' ');
1085 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1086 remove_token(namebuf, i-1, ' ');
1087 strcpy(firstname, namebuf);
1088 sprintf(namebuf, "%s; %s", lastname, firstname);
1092 void fetch_ab_name(long msgnum, char *namebuf) {
1094 char mime_partnum[SIZ];
1095 char mime_filename[SIZ];
1096 char mime_content_type[SIZ];
1097 char mime_disposition[SIZ];
1099 char vcard_partnum[SIZ];
1100 char *vcard_source = NULL;
1102 struct message_summary summ;
1104 if (namebuf == NULL) return;
1105 strcpy(namebuf, "");
1107 memset(&summ, 0, sizeof(summ));
1108 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1110 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1112 serv_getln(buf, sizeof buf);
1113 if (buf[0] != '1') return;
1115 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1116 if (!strncasecmp(buf, "part=", 5)) {
1117 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1118 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1119 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1120 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1121 mime_length = extract_int(&buf[5], 5);
1123 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1124 strcpy(vcard_partnum, mime_partnum);
1130 if (strlen(vcard_partnum) > 0) {
1131 vcard_source = load_mimepart(msgnum, vcard_partnum);
1132 if (vcard_source != NULL) {
1134 /* Grab the name off the card */
1135 display_vcard(vcard_source, 0, 0, namebuf);
1141 lastfirst_firstlast(namebuf);
1143 for (i=0; i<strlen(namebuf); ++i) {
1144 if (namebuf[i] != ';') return;
1146 strcpy(namebuf, "(no name)");
1152 * Record compare function for sorting address book indices
1154 int abcmp(const void *ab1, const void *ab2) {
1156 (((const struct addrbookent *)ab1)->ab_name),
1157 (((const struct addrbookent *)ab2)->ab_name)
1163 * Helper function for do_addrbook_view()
1164 * Converts a name into a three-letter tab label
1166 void nametab(char *tabbuf, char *name) {
1167 stresc(tabbuf, name, 0, 0);
1168 tabbuf[0] = toupper(tabbuf[0]);
1169 tabbuf[1] = tolower(tabbuf[1]);
1170 tabbuf[2] = tolower(tabbuf[2]);
1176 * Render the address book using info we gathered during the scan
1178 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1182 static int NAMESPERPAGE = 60;
1186 char tabfirst_label[SIZ];
1188 char tablast_label[SIZ];
1191 wprintf("<I>This address book is empty.</I>\n");
1196 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1199 num_pages = num_ab / NAMESPERPAGE;
1201 page = atoi(bstr("page"));
1204 for (i=0; i<=num_pages; ++i) {
1206 wprintf("<A HREF=\"/readfwd?page=%d\">", i);
1211 tabfirst = i * NAMESPERPAGE;
1212 tablast = tabfirst + NAMESPERPAGE - 1;
1213 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1214 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1215 nametab(tablast_label, addrbook[tablast].ab_name);
1216 wprintf("[%s - %s]",
1217 tabfirst_label, tablast_label
1226 wprintf("<br />\n");
1228 wprintf("<TABLE border=0 cellspacing=0 "
1229 "cellpadding=3 width=100%%>\n"
1232 for (i=0; i<num_ab; ++i) {
1234 if ((i / NAMESPERPAGE) == page) {
1236 if ((displayed % 4) == 0) {
1237 if (displayed > 0) {
1241 wprintf("<TR BGCOLOR=\"#%s\">",
1242 (bg ? "DDDDDD" : "FFFFFF")
1248 wprintf("<A HREF=\"/readfwd?startmsg=%ld&is_singlecard=1",
1249 addrbook[i].ab_msgnum);
1250 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1251 vcard_n_prettyize(addrbook[i].ab_name);
1252 escputs(addrbook[i].ab_name);
1253 wprintf("</A></TD>\n");
1258 wprintf("</TR></TABLE>\n");
1264 * load message pointers from the server
1266 int load_msg_ptrs(char *servcmd)
1273 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1275 serv_getln(buf, sizeof buf);
1276 if (buf[0] != '1') {
1277 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1280 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1281 if (nummsgs < maxload) {
1282 WC->msgarr[nummsgs] = atol(buf);
1290 int summcmp_subj(const void *s1, const void *s2) {
1291 struct message_summary *summ1;
1292 struct message_summary *summ2;
1294 summ1 = (struct message_summary *)s1;
1295 summ2 = (struct message_summary *)s2;
1296 return strcasecmp(summ1->subj, summ2->subj);
1299 int summcmp_rsubj(const void *s1, const void *s2) {
1300 struct message_summary *summ1;
1301 struct message_summary *summ2;
1303 summ1 = (struct message_summary *)s1;
1304 summ2 = (struct message_summary *)s2;
1305 return strcasecmp(summ2->subj, summ1->subj);
1308 int summcmp_sender(const void *s1, const void *s2) {
1309 struct message_summary *summ1;
1310 struct message_summary *summ2;
1312 summ1 = (struct message_summary *)s1;
1313 summ2 = (struct message_summary *)s2;
1314 return strcasecmp(summ1->from, summ2->from);
1317 int summcmp_rsender(const void *s1, const void *s2) {
1318 struct message_summary *summ1;
1319 struct message_summary *summ2;
1321 summ1 = (struct message_summary *)s1;
1322 summ2 = (struct message_summary *)s2;
1323 return strcasecmp(summ2->from, summ1->from);
1326 int summcmp_date(const void *s1, const void *s2) {
1327 struct message_summary *summ1;
1328 struct message_summary *summ2;
1330 summ1 = (struct message_summary *)s1;
1331 summ2 = (struct message_summary *)s2;
1333 if (summ1->date < summ2->date) return -1;
1334 else if (summ1->date > summ2->date) return +1;
1338 int summcmp_rdate(const void *s1, const void *s2) {
1339 struct message_summary *summ1;
1340 struct message_summary *summ2;
1342 summ1 = (struct message_summary *)s1;
1343 summ2 = (struct message_summary *)s2;
1345 if (summ1->date < summ2->date) return +1;
1346 else if (summ1->date > summ2->date) return -1;
1351 * command loop for reading messages
1353 void readloop(char *oper)
1363 int num_displayed = 0;
1365 int is_addressbook = 0;
1366 int is_singlecard = 0;
1367 int is_calendar = 0;
1370 int remaining_messages;
1372 int lowest_displayed = (-1);
1373 int highest_displayed = 0;
1374 long pn_previous = 0L;
1375 long pn_current = 0L;
1378 struct addrbookent *addrbook = NULL;
1380 char *sortby = NULL;
1381 char sortpref_name[128];
1382 char sortpref_value[128];
1383 char *subjsort_button;
1384 char *sendsort_button;
1385 char *datesort_button;
1387 startmsg = atol(bstr("startmsg"));
1388 maxmsgs = atoi(bstr("maxmsgs"));
1389 is_summary = atoi(bstr("summary"));
1390 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1392 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
1393 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
1395 sortby = bstr("sortby");
1396 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
1397 set_preference(sortpref_name, sortby, 1);
1399 if (strlen(sortby) == 0) sortby = sortpref_value;
1400 if (strlen(sortby) == 0) sortby = "msgid";
1402 output_headers(1, 1, 1, 0, 0, 0, 0);
1404 /* When in summary mode, always show ALL messages instead of just
1405 * new or old. Otherwise, show what the user asked for.
1407 if (!strcmp(oper, "readnew")) {
1408 strcpy(cmd, "MSGS NEW");
1410 else if (!strcmp(oper, "readold")) {
1411 strcpy(cmd, "MSGS OLD");
1414 strcpy(cmd, "MSGS ALL");
1417 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
1419 strcpy(cmd, "MSGS ALL");
1422 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
1424 strcpy(cmd, "MSGS ALL");
1429 strcpy(cmd, "MSGS ALL");
1434 /* Are we doing a summary view? If so, we need to know old messages
1435 * and new messages, so we can do that pretty boldface thing for the
1438 strcpy(old_msgs, "");
1441 serv_getln(buf, sizeof buf);
1442 if (buf[0] == '2') {
1443 strcpy(old_msgs, &buf[4]);
1447 is_singlecard = atoi(bstr("is_singlecard"));
1449 if (WC->wc_view == VIEW_CALENDAR) { /* calendar */
1451 strcpy(cmd, "MSGS ALL");
1454 if (WC->wc_view == VIEW_TASKS) { /* tasks */
1456 strcpy(cmd, "MSGS ALL");
1459 if (WC->wc_view == VIEW_NOTES) { /* notes */
1461 strcpy(cmd, "MSGS ALL");
1465 nummsgs = load_msg_ptrs(cmd);
1468 if ((!is_tasks) && (!is_calendar) && (!is_notes)) {
1469 if (!strcmp(oper, "readnew")) {
1470 wprintf("<EM>No new messages.</EM>\n");
1471 } else if (!strcmp(oper, "readold")) {
1472 wprintf("<EM>No old messages.</EM>\n");
1474 wprintf("<EM>No messages here.</EM>\n");
1482 if (WC->num_summ != 0) {
1486 WC->num_summ = nummsgs;
1487 WC->summ = malloc(WC->num_summ*sizeof(struct message_summary));
1488 for (a = 0; a < nummsgs; ++a) {
1489 /* Gather summary information */
1490 summarize_message(a, WC->msgarr[a], is_new);
1492 /* Are you a new message, or an old message? */
1494 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
1495 WC->summ[a].is_new = 0;
1498 WC->summ[a].is_new = 1;
1504 if (startmsg == 0L) startmsg = WC->msgarr[0];
1505 remaining_messages = 0;
1507 for (a = 0; a < nummsgs; ++a) {
1508 if (WC->msgarr[a] >= startmsg) {
1509 ++remaining_messages;
1514 if (!strcasecmp(sortby, "subject")) {
1515 qsort(WC->summ, WC->num_summ,
1516 sizeof(struct message_summary), summcmp_subj);
1518 else if (!strcasecmp(sortby, "rsubject")) {
1519 qsort(WC->summ, WC->num_summ,
1520 sizeof(struct message_summary), summcmp_rsubj);
1522 else if (!strcasecmp(sortby, "sender")) {
1523 qsort(WC->summ, WC->num_summ,
1524 sizeof(struct message_summary), summcmp_sender);
1526 else if (!strcasecmp(sortby, "rsender")) {
1527 qsort(WC->summ, WC->num_summ,
1528 sizeof(struct message_summary), summcmp_rsender);
1530 else if (!strcasecmp(sortby, "date")) {
1531 qsort(WC->summ, WC->num_summ,
1532 sizeof(struct message_summary), summcmp_date);
1534 else if (!strcasecmp(sortby, "rdate")) {
1535 qsort(WC->summ, WC->num_summ,
1536 sizeof(struct message_summary), summcmp_rdate);
1540 if (!strcasecmp(sortby, "subject")) {
1541 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1543 else if (!strcasecmp(sortby, "rsubject")) {
1544 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1547 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1550 if (!strcasecmp(sortby, "sender")) {
1551 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1553 else if (!strcasecmp(sortby, "rsender")) {
1554 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1557 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1560 if (!strcasecmp(sortby, "date")) {
1561 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1563 else if (!strcasecmp(sortby, "rdate")) {
1564 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1567 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1571 wprintf("</div>"); /* end of 'content' div */
1573 wprintf("<div id=\"message_list\">"
1575 "<div id=\"fix_scrollbar_bug\">\n"
1577 "<form name=\"msgomatic\" "
1578 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n"
1580 "<table border=0 cellspacing=0 "
1581 "cellpadding=0 width=100%%>\n"
1583 "<TD align=center><b><i>Subject</i></b> %s</TD>"
1584 "<TD align=center><b><i>Sender</i></b> %s</TD>"
1585 "<TD align=center><b><i>Date</i></b> %s</TD>"
1586 "<TD><INPUT TYPE=\"submit\" NAME=\"sc\" "
1587 "STYLE=\"font-family: Bitstream Vera Sans,Arial,Helvetica,sans-serif;"
1588 " font-size: 6pt;\" "
1589 "VALUE=\"Delete\"></TD>"
1598 for (a = 0; a < nummsgs; ++a) {
1599 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
1601 /* Learn which msgs "Prev" & "Next" buttons go to */
1602 pn_current = WC->msgarr[a];
1603 if (a > 0) pn_previous = WC->msgarr[a-1];
1604 if (a < (nummsgs-1)) pn_next = WC->msgarr[a+1];
1606 /* If a tabular view, set up the line */
1609 wprintf("<TR BGCOLOR=\"#%s\">",
1610 (bg ? "DDDDDD" : "FFFFFF")
1614 /* Display the message */
1616 display_summarized(a);
1618 else if (is_addressbook) {
1619 fetch_ab_name(WC->msgarr[a], buf);
1621 addrbook = realloc(addrbook,
1622 (sizeof(struct addrbookent) * num_ab) );
1623 safestrncpy(addrbook[num_ab-1].ab_name, buf,
1624 sizeof(addrbook[num_ab-1].ab_name));
1625 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
1627 else if (is_calendar) {
1628 display_calendar(WC->msgarr[a]);
1630 else if (is_tasks) {
1631 display_task(WC->msgarr[a]);
1633 else if (is_notes) {
1634 display_note(WC->msgarr[a]);
1637 read_message(WC->msgarr[a], 0);
1640 /* If a tabular view, finish the line */
1645 if (lowest_displayed < 0) lowest_displayed = a;
1646 highest_displayed = a;
1649 --remaining_messages;
1654 wprintf("</table></form>"
1655 "</div>\n"); /* end of 'fix_scrollbar_bug' div */
1656 wprintf("</div>"); /* end of 'message_list' div */
1658 wprintf("<div id=\"preview_pane\">"); /* The preview pane will initially be empty */
1661 /* Bump these because although we're thinking in zero base, the user
1662 * is a drooling idiot and is thinking in one base.
1665 ++highest_displayed;
1667 /* If we're only looking at one message, do a prev/next thing */
1668 if (num_displayed == 1) {
1669 if ((!is_tasks) && (!is_calendar) && (!is_addressbook) && (!is_notes) && (!is_singlecard)) {
1671 wprintf("<div id=\"fix_scrollbar_bug\">"
1672 "<table border=0 width=100%% bgcolor=\"#dddddd\"><tr><td>"
1673 "Reading #%d of %d messages.</TD>\n"
1674 "<TD ALIGN=RIGHT><FONT SIZE=+1>",
1675 lowest_displayed, nummsgs);
1677 if (pn_previous > 0L) {
1678 wprintf("<A HREF=\"/%s"
1688 wprintf("<A HREF=\"/%s"
1697 wprintf("<A HREF=\"/%s?startmsg=%ld"
1698 "?maxmsgs=%d?summary=1\">"
1706 wprintf("</td></tr></table></div>\n");
1711 * If we're not currently looking at ALL requested
1712 * messages, then display the selector bar
1714 if (num_displayed > 1) {
1715 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
1716 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
1718 wprintf("<form name=\"msgomatic\" "
1719 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n");
1721 wprintf("Reading #", lowest_displayed, highest_displayed);
1723 wprintf("<select name=\"whichones\" size=\"1\" "
1724 "OnChange=\"location.href=msgomatic.whichones.options"
1725 "[selectedIndex].value\">\n");
1727 for (b=0; b<nummsgs; b = b + maxmsgs) {
1730 if (hi > nummsgs) hi = nummsgs;
1731 wprintf("<option %s value="
1736 "%d-%d</option> \n",
1737 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
1744 wprintf("<option value=\"/%s?startmsg=%ld"
1745 "?maxmsgs=9999999?summary=%d\">"
1749 WC->msgarr[0], is_summary);
1751 wprintf("</select> of %d messages.", nummsgs);
1752 wprintf("</form>\n");
1758 do_tasks_view(); /* Render the task list */
1762 do_calendar_view(); /* Render the calendar */
1765 if (is_addressbook) {
1766 do_addrbook_view(addrbook, num_ab); /* Render the address book */
1769 /* Put the data transfer hidden iframe in a hidden div, to make it *really* hidden */
1771 "<div display=\"hidden\">\n"
1772 "<iframe name=\"msgloader1\" id=\"msgloader1\" width=\"1\"></iframe>\n"
1775 /* Note: wDumpContent() will output one additional </div> tag. */
1777 if (addrbook != NULL) free(addrbook);
1779 /* free the summary */
1780 if (WC->num_summ != 0) {
1785 /* If we got here via a mailbox view and are reading a single
1786 * message, mark it as "seen." We do this after rendering the web page
1787 * so it doesn't keep the user waiting.
1789 if ( (maxmsgs == 1) && (WC->wc_view == VIEW_MAILBOX) ) {
1790 serv_printf("SEEN %ld|1", startmsg);
1791 serv_getln(buf, sizeof buf);
1797 * Back end for post_message() ... this is where the actual message
1798 * gets transmitted to the server.
1800 void post_mime_to_server(void) {
1802 int is_multipart = 0;
1804 struct wc_attachment *att;
1806 size_t encoded_length;
1808 /* If there are attachments, we have to do multipart/mixed */
1809 if (WC->first_attachment != NULL) {
1814 sprintf(boundary, "---Citadel-Multipart-%s-%04x%04x---",
1815 serv_info.serv_fqdn,
1820 /* Remember, serv_printf() appends an extra newline */
1821 serv_printf("Content-type: multipart/mixed; "
1822 "boundary=\"%s\"\n", boundary);
1823 serv_printf("This is a multipart message in MIME format.\n");
1824 serv_printf("--%s", boundary);
1827 serv_puts("Content-type: text/html; charset=utf-8");
1829 serv_puts("<HTML><BODY>\n");
1830 text_to_server(bstr("msgtext"), 0);
1831 serv_puts("</BODY></HTML>\n");
1836 /* Add in the attachments */
1837 for (att = WC->first_attachment; att!=NULL; att=att->next) {
1839 encoded_length = ((att->length * 150) / 100);
1840 encoded = malloc(encoded_length);
1841 if (encoded == NULL) break;
1842 CtdlEncodeBase64(encoded, att->data, att->length);
1844 serv_printf("--%s", boundary);
1845 serv_printf("Content-type: %s", att->content_type);
1846 serv_printf("Content-disposition: attachment; "
1847 "filename=\"%s\"", att->filename);
1848 serv_puts("Content-transfer-encoding: base64");
1850 serv_write(encoded, strlen(encoded));
1855 serv_printf("--%s--", boundary);
1863 * Post message (or don't post message)
1865 * Note regarding the "dont_post" variable:
1866 * A random value (actually, it's just a timestamp) is inserted as a hidden
1867 * field called "postseq" when the display_enter page is generated. This
1868 * value is checked when posting, using the static variable dont_post. If a
1869 * user attempts to post twice using the same dont_post value, the message is
1870 * discarded. This prevents the accidental double-saving of the same message
1871 * if the user happens to click the browser "back" button.
1873 void post_message(void)
1876 static long dont_post = (-1L);
1877 struct wc_attachment *att, *aptr;
1879 if (WC->upload_length > 0) {
1881 /* There's an attachment. Save it to this struct... */
1882 att = malloc(sizeof(struct wc_attachment));
1883 memset(att, 0, sizeof(struct wc_attachment));
1884 att->length = WC->upload_length;
1885 strcpy(att->content_type, WC->upload_content_type);
1886 strcpy(att->filename, WC->upload_filename);
1889 /* And add it to the list. */
1890 if (WC->first_attachment == NULL) {
1891 WC->first_attachment = att;
1894 aptr = WC->first_attachment;
1895 while (aptr->next != NULL) aptr = aptr->next;
1899 /* Netscape sends a simple filename, which is what we want,
1900 * but Satan's browser sends an entire pathname. Reduce
1901 * the path to just a filename if we need to.
1903 while (num_tokens(att->filename, '/') > 1) {
1904 remove_token(att->filename, 0, '/');
1906 while (num_tokens(att->filename, '\\') > 1) {
1907 remove_token(att->filename, 0, '\\');
1910 /* Transfer control of this memory from the upload struct
1911 * to the attachment struct.
1913 att->data = WC->upload;
1914 WC->upload_length = 0;
1920 if (!strcasecmp(bstr("sc"), "Cancel")) {
1921 sprintf(WC->ImportantMessage,
1922 "Cancelled. Message was not posted.");
1923 } else if (!strcasecmp(bstr("attach"), "Add")) {
1926 } else if (atol(bstr("postseq")) == dont_post) {
1927 sprintf(WC->ImportantMessage,
1928 "Automatically cancelled because you have already "
1929 "saved this message.");
1931 sprintf(buf, "ENT0 1|%s|0|4|%s",
1935 serv_getln(buf, sizeof buf);
1936 if (buf[0] == '4') {
1937 post_mime_to_server();
1938 if (strlen(bstr("recp")) > 0) {
1939 sprintf(WC->ImportantMessage, "Message has been sent.\n");
1942 sprintf(WC->ImportantMessage, "Message has been posted.\n");
1944 dont_post = atol(bstr("postseq"));
1946 sprintf(WC->ImportantMessage,
1951 free_attachments(WC);
1952 readloop("readnew");
1959 * display the message entry screen
1961 void display_enter(void)
1965 struct wc_attachment *att;
1967 if (strlen(bstr("force_room")) > 0) {
1968 gotoroom(bstr("force_room"));
1971 /* Are we perhaps in an address book view? If so, then an "enter
1972 * message" command really means "add new entry."
1974 if (WC->wc_view == VIEW_ADDRESSBOOK) {
1975 do_edit_vcard(-1, "", "");
1979 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1980 /* Are we perhaps in a calendar view? If so, then an "enter
1981 * message" command really means "add new calendar item."
1983 if (WC->wc_view == VIEW_CALENDAR) {
1984 display_edit_event();
1988 /* Are we perhaps in a tasks view? If so, then an "enter
1989 * message" command really means "add new task."
1991 if (WC->wc_view == VIEW_TASKS) {
1992 display_edit_task();
1997 /* Otherwise proceed normally. Do a custom room banner with no navbar... */
1998 output_headers(1, 1, 2, 0, 0, 0, 0);
1999 wprintf("<div id=\"banner\">\n");
2000 embed_room_banner(NULL, navbar_none);
2001 wprintf("</div>\n");
2002 wprintf("<div id=\"content\">\n"
2003 "<div id=\"fix_scrollbar_bug\">"
2004 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
2006 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
2008 serv_getln(buf, sizeof buf);
2010 if (!strncmp(buf, "570", 3)) {
2011 if (strlen(bstr("recp")) > 0) {
2012 svprintf("RECPERROR", WCS_STRING,
2013 "<SPAN CLASS=\"errormsg\">%s</SPAN><br />\n",
2017 do_template("prompt_for_recipient");
2020 if (buf[0] != '2') {
2021 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2026 fmt_date(buf, now, 0);
2027 strcat(&buf[strlen(buf)], " <I>from</I> ");
2028 stresc(&buf[strlen(buf)], WC->wc_username, 1, 1);
2029 if (strlen(bstr("recp")) > 0) {
2030 strcat(&buf[strlen(buf)], " <I>to</I> ");
2031 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
2033 strcat(&buf[strlen(buf)], " <I>in</I> ");
2034 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
2036 /* begin message entry screen */
2037 // wprintf("<div style=\"position:absolute; left:1%%; width:96%%; height:100%%\">\n");
2039 wprintf("<form enctype=\"multipart/form-data\" "
2040 "method=\"POST\" action=\"/post\" "
2041 "name=\"enterform\""
2042 "onSubmit=\"return submitForm();\""
2044 wprintf("<input type=\"hidden\" name=\"recp\" value=\"%s\">\n",
2046 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n",
2049 wprintf("%s<br>\n", buf); /* header bar */
2050 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2051 /* "onLoad=\"document.enterform.msgtext.focus();\" " */
2052 wprintf("<font size=-1>Subject (optional):</font>"
2053 "<input type=\"text\" name=\"subject\" value=\"");
2054 escputs(bstr("subject"));
2055 wprintf("\" size=40 maxlength=70>"
2059 wprintf("<input type=\"submit\" name=\"sc\" value=\"");
2060 if (strlen(bstr("recp")) > 0) {
2061 wprintf("Send message");
2063 wprintf("Post message");
2066 "<input type=\"submit\" name=\"sc\" value=\"Cancel\">\n");
2068 wprintf("<center><script type=\"text/javascript\" "
2069 "src=\"static/richtext.js\"></script>\n"
2070 "<script type=\"text/javascript\">\n"
2071 "function submitForm() { \n"
2072 " updateRTE('msgtext'); \n"
2076 "initRTE(\"static/\", \"static/\", \"\"); \n"
2078 "<noscript>JavaScript must be enabled.</noscript> \n"
2079 "<script type=\"text/javascript\"> \n"
2080 "writeRichText('msgtext', '");
2081 msgescputs(bstr("msgtext"));
2082 wprintf("', '96%%', '200', true, false); \n"
2083 "</script></center><br />\n");
2085 /* Enumerate any attachments which are already in place... */
2086 wprintf("<img src=\"/static/diskette_24x.gif\" border=0 "
2087 "align=middle height=16 width=16> Attachments: ");
2088 wprintf("<select name=\"which_attachment\" size=1>");
2089 for (att = WC->first_attachment; att != NULL; att = att->next) {
2090 wprintf("<option value=\"");
2091 urlescputs(att->filename);
2093 escputs(att->filename);
2094 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
2095 wprintf("</option>\n");
2097 wprintf("</select>");
2099 /* Now offer the ability to attach additional files... */
2100 wprintf(" "
2101 "Attach file: <input NAME=\"attachfile\" "
2102 "SIZE=16 TYPE=\"file\">\n "
2103 "<input type=\"submit\" name=\"attach\" value=\"Add\">\n");
2105 wprintf("</form>\n");
2107 wprintf("</td></tr></table></div>\n");
2108 DONE: wDumpContent(1);
2118 void delete_msg(void)
2123 msgid = atol(bstr("msgid"));
2125 output_headers(1, 1, 1, 0, 0, 0, 0);
2127 sprintf(buf, "DELE %ld", msgid);
2129 serv_getln(buf, sizeof buf);
2130 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2139 * Confirm move of a message
2141 void confirm_move_msg(void)
2147 msgid = atol(bstr("msgid"));
2149 output_headers(1, 1, 1, 0, 0, 0, 0);
2151 wprintf("<div id=\"fix_scrollbar_bug\">"
2152 "<table width=100%% border=0 bgcolor=\"#444455\"><tr><td>");
2153 wprintf("<font size=+1 color=\"#ffffff\"");
2154 wprintf("<b>Confirm move of message</b>\n");
2155 wprintf("</font></td></tr></table></div>\n");
2157 wprintf("<CENTER>");
2159 wprintf("Move this message to:<br />\n");
2161 wprintf("<form METHOD=\"POST\" ACTION=\"/move_msg\">\n");
2162 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
2166 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
2168 serv_getln(buf, sizeof buf);
2169 if (buf[0] == '1') {
2170 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2171 extract_token(targ, buf, 0, '|', sizeof targ);
2172 wprintf("<OPTION>");
2177 wprintf("</SELECT>\n");
2178 wprintf("<br />\n");
2180 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
2182 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
2183 wprintf("</form></CENTER>\n");
2185 wprintf("</CENTER>\n");
2196 msgid = atol(bstr("msgid"));
2198 output_headers(1, 1, 1, 0, 0, 0, 0);
2200 if (!strcasecmp(bstr("yesno"), "Move")) {
2201 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
2203 serv_getln(buf, sizeof buf);
2204 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2206 wprintf("<EM>Message not moved.</EM><br />\n");
2213 * This gets called when a user selects multiple messages in a summary
2214 * list and then clicks to perform a transformation of some sort on them
2215 * (such as deleting them).
2217 void do_stuff_to_msgs(void) {
2222 struct stuff_t *next;
2226 struct stuff_t *stuff = NULL;
2227 struct stuff_t *ptr;
2230 serv_puts("MSGS ALL");
2231 serv_getln(buf, sizeof buf);
2233 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2234 ptr = malloc(sizeof(struct stuff_t));
2235 ptr->msgnum = atol(buf);
2240 strcpy(sc, bstr("sc"));
2242 while (stuff != NULL) {
2244 sprintf(buf, "msg_%ld", stuff->msgnum);
2245 if (!strcasecmp(bstr(buf), "yes")) {
2247 if (!strcasecmp(sc, "Delete")) {
2248 serv_printf("DELE %ld", stuff->msgnum);
2249 serv_getln(buf, sizeof buf);
2259 readloop("readfwd");