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\">"
952 void display_addressbook(long msgnum, char alpha) {
954 char mime_partnum[SIZ];
955 char mime_filename[SIZ];
956 char mime_content_type[SIZ];
957 char mime_disposition[SIZ];
959 char vcard_partnum[SIZ];
960 char *vcard_source = NULL;
961 struct message_summary summ;
963 memset(&summ, 0, sizeof(summ));
964 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
966 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
968 serv_getln(buf, sizeof buf);
969 if (buf[0] != '1') return;
971 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
972 if (!strncasecmp(buf, "part=", 5)) {
973 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
974 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
975 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
976 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
977 mime_length = extract_int(&buf[5], 5);
979 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
980 strcpy(vcard_partnum, mime_partnum);
986 if (strlen(vcard_partnum) > 0) {
987 vcard_source = load_mimepart(msgnum, vcard_partnum);
988 if (vcard_source != NULL) {
990 /* Display the summary line */
991 display_vcard(vcard_source, alpha, 0, NULL);
993 /* If it's my vCard I can edit it */
994 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
995 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
996 || (WC->wc_view == VIEW_ADDRESSBOOK)
998 wprintf("<A HREF=\"/edit_vcard?"
999 "msgnum=%ld?partnum=%s\">",
1000 msgnum, vcard_partnum);
1001 wprintf("[edit]</A>");
1012 /* If it's an old "Firstname Lastname" style record, try to
1015 void lastfirst_firstlast(char *namebuf) {
1016 char firstname[SIZ];
1020 if (namebuf == NULL) return;
1021 if (strchr(namebuf, ';') != NULL) return;
1023 i = num_tokens(namebuf, ' ');
1026 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1027 remove_token(namebuf, i-1, ' ');
1028 strcpy(firstname, namebuf);
1029 sprintf(namebuf, "%s; %s", lastname, firstname);
1033 void fetch_ab_name(long msgnum, char *namebuf) {
1035 char mime_partnum[SIZ];
1036 char mime_filename[SIZ];
1037 char mime_content_type[SIZ];
1038 char mime_disposition[SIZ];
1040 char vcard_partnum[SIZ];
1041 char *vcard_source = NULL;
1043 struct message_summary summ;
1045 if (namebuf == NULL) return;
1046 strcpy(namebuf, "");
1048 memset(&summ, 0, sizeof(summ));
1049 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1051 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1053 serv_getln(buf, sizeof buf);
1054 if (buf[0] != '1') return;
1056 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1057 if (!strncasecmp(buf, "part=", 5)) {
1058 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1059 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1060 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1061 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1062 mime_length = extract_int(&buf[5], 5);
1064 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1065 strcpy(vcard_partnum, mime_partnum);
1071 if (strlen(vcard_partnum) > 0) {
1072 vcard_source = load_mimepart(msgnum, vcard_partnum);
1073 if (vcard_source != NULL) {
1075 /* Grab the name off the card */
1076 display_vcard(vcard_source, 0, 0, namebuf);
1082 lastfirst_firstlast(namebuf);
1084 for (i=0; i<strlen(namebuf); ++i) {
1085 if (namebuf[i] != ';') return;
1087 strcpy(namebuf, "(no name)");
1093 * Record compare function for sorting address book indices
1095 int abcmp(const void *ab1, const void *ab2) {
1097 (((const struct addrbookent *)ab1)->ab_name),
1098 (((const struct addrbookent *)ab2)->ab_name)
1104 * Helper function for do_addrbook_view()
1105 * Converts a name into a three-letter tab label
1107 void nametab(char *tabbuf, char *name) {
1108 stresc(tabbuf, name, 0, 0);
1109 tabbuf[0] = toupper(tabbuf[0]);
1110 tabbuf[1] = tolower(tabbuf[1]);
1111 tabbuf[2] = tolower(tabbuf[2]);
1117 * Render the address book using info we gathered during the scan
1119 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1123 static int NAMESPERPAGE = 60;
1127 char tabfirst_label[SIZ];
1129 char tablast_label[SIZ];
1132 wprintf("<I>This address book is empty.</I>\n");
1137 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1140 num_pages = num_ab / NAMESPERPAGE;
1142 page = atoi(bstr("page"));
1145 for (i=0; i<=num_pages; ++i) {
1147 wprintf("<A HREF=\"/readfwd?page=%d\">", i);
1152 tabfirst = i * NAMESPERPAGE;
1153 tablast = tabfirst + NAMESPERPAGE - 1;
1154 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1155 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1156 nametab(tablast_label, addrbook[tablast].ab_name);
1157 wprintf("[%s - %s]",
1158 tabfirst_label, tablast_label
1167 wprintf("<br />\n");
1169 wprintf("<TABLE border=0 cellspacing=0 "
1170 "cellpadding=3 width=100%%>\n"
1173 for (i=0; i<num_ab; ++i) {
1175 if ((i / NAMESPERPAGE) == page) {
1177 if ((displayed % 4) == 0) {
1178 if (displayed > 0) {
1182 wprintf("<TR BGCOLOR=\"#%s\">",
1183 (bg ? "DDDDDD" : "FFFFFF")
1189 wprintf("<A HREF=\"/readfwd?startmsg=%ld&is_singlecard=1",
1190 addrbook[i].ab_msgnum);
1191 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1192 vcard_n_prettyize(addrbook[i].ab_name);
1193 escputs(addrbook[i].ab_name);
1194 wprintf("</A></TD>\n");
1199 wprintf("</TR></TABLE>\n");
1205 * load message pointers from the server
1207 int load_msg_ptrs(char *servcmd, int with_headers)
1211 char displayname[128];
1218 int num_summ_alloc = 0;
1221 if (WC->num_summ != 0) {
1226 num_summ_alloc = 100;
1228 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1231 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1233 serv_getln(buf, sizeof buf);
1234 if (buf[0] != '1') {
1235 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1238 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1239 if (nummsgs < maxload) {
1240 WC->msgarr[nummsgs] = extract_long(buf, 0);
1241 datestamp = extract_long(buf, 1);
1242 extract_token(displayname, buf, 2, '|', sizeof displayname);
1243 extract_token(nodename, buf, 3, '|', sizeof nodename);
1244 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1245 extract_token(subject, buf, 5, '|', sizeof subject);
1249 if (nummsgs > num_summ_alloc) {
1250 num_summ_alloc *= 2;
1251 WC->summ = realloc(WC->summ, num_summ_alloc * sizeof(struct message_summary));
1255 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1256 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1257 safestrncpy(WC->summ[nummsgs-1].subj, "(no subject)", sizeof WC->summ[nummsgs-1].subj);
1258 if (strlen(displayname) > 0) {
1259 safestrncpy(WC->summ[nummsgs-1].from, displayname, sizeof WC->summ[nummsgs-1].from);
1261 if (strlen(subject) > 0) {
1262 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1263 sizeof WC->summ[nummsgs-1].subj);
1266 /* Handle subjects with RFC2047 encoding */
1267 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1269 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1270 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1273 if (strlen(nodename) > 0) {
1274 if ( ((WC->room_flags & QR_NETWORK)
1275 || ((strcasecmp(nodename, serv_info.serv_nodename)
1276 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1278 strcat(WC->summ[nummsgs-1].from, " @ ");
1279 strcat(WC->summ[nummsgs-1].from, nodename);
1283 WC->summ[nummsgs-1].date = datestamp;
1286 /* Handle senders with RFC2047 encoding */
1287 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1289 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1290 strcpy(&WC->summ[nummsgs-1].from[22], "...");
1299 int summcmp_subj(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(summ1->subj, summ2->subj);
1308 int summcmp_rsubj(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(summ2->subj, summ1->subj);
1317 int summcmp_sender(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(summ1->from, summ2->from);
1326 int summcmp_rsender(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;
1332 return strcasecmp(summ2->from, summ1->from);
1335 int summcmp_date(const void *s1, const void *s2) {
1336 struct message_summary *summ1;
1337 struct message_summary *summ2;
1339 summ1 = (struct message_summary *)s1;
1340 summ2 = (struct message_summary *)s2;
1342 if (summ1->date < summ2->date) return -1;
1343 else if (summ1->date > summ2->date) return +1;
1347 int summcmp_rdate(const void *s1, const void *s2) {
1348 struct message_summary *summ1;
1349 struct message_summary *summ2;
1351 summ1 = (struct message_summary *)s1;
1352 summ2 = (struct message_summary *)s2;
1354 if (summ1->date < summ2->date) return +1;
1355 else if (summ1->date > summ2->date) return -1;
1360 * command loop for reading messages
1362 void readloop(char *oper)
1371 int num_displayed = 0;
1373 int is_addressbook = 0;
1374 int is_singlecard = 0;
1375 int is_calendar = 0;
1378 int remaining_messages;
1380 int lowest_displayed = (-1);
1381 int highest_displayed = 0;
1382 long pn_previous = 0L;
1383 long pn_current = 0L;
1386 struct addrbookent *addrbook = NULL;
1388 char *sortby = NULL;
1389 char sortpref_name[128];
1390 char sortpref_value[128];
1391 char *subjsort_button;
1392 char *sendsort_button;
1393 char *datesort_button;
1395 startmsg = atol(bstr("startmsg"));
1396 maxmsgs = atoi(bstr("maxmsgs"));
1397 is_summary = atoi(bstr("summary"));
1398 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1400 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
1401 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
1403 sortby = bstr("sortby");
1404 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
1405 set_preference(sortpref_name, sortby, 1);
1407 if (strlen(sortby) == 0) sortby = sortpref_value;
1408 if (strlen(sortby) == 0) sortby = "msgid";
1410 output_headers(1, 1, 1, 0, 0, 0, 0);
1412 /* When in summary mode, always show ALL messages instead of just
1413 * new or old. Otherwise, show what the user asked for.
1415 if (!strcmp(oper, "readnew")) {
1416 strcpy(cmd, "MSGS NEW");
1418 else if (!strcmp(oper, "readold")) {
1419 strcpy(cmd, "MSGS OLD");
1422 strcpy(cmd, "MSGS ALL");
1425 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
1427 strcpy(cmd, "MSGS ALL");
1430 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
1432 strcpy(cmd, "MSGS ALL");
1437 strcpy(cmd, "MSGS ALL|||1"); /* fetch header summary */
1442 /* Are we doing a summary view? If so, we need to know old messages
1443 * and new messages, so we can do that pretty boldface thing for the
1446 strcpy(old_msgs, "");
1449 serv_getln(buf, sizeof buf);
1450 if (buf[0] == '2') {
1451 strcpy(old_msgs, &buf[4]);
1455 is_singlecard = atoi(bstr("is_singlecard"));
1457 if (WC->wc_view == VIEW_CALENDAR) { /* calendar */
1459 strcpy(cmd, "MSGS ALL");
1462 if (WC->wc_view == VIEW_TASKS) { /* tasks */
1464 strcpy(cmd, "MSGS ALL");
1467 if (WC->wc_view == VIEW_NOTES) { /* notes */
1469 strcpy(cmd, "MSGS ALL");
1473 nummsgs = load_msg_ptrs(cmd, is_summary);
1476 if ((!is_tasks) && (!is_calendar) && (!is_notes)) {
1477 if (!strcmp(oper, "readnew")) {
1478 wprintf("<EM>No new messages.</EM>\n");
1479 } else if (!strcmp(oper, "readold")) {
1480 wprintf("<EM>No old messages.</EM>\n");
1482 wprintf("<EM>No messages here.</EM>\n");
1490 for (a = 0; a < nummsgs; ++a) {
1491 /* Are you a new message, or an old message? */
1493 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
1494 WC->summ[a].is_new = 0;
1497 WC->summ[a].is_new = 1;
1503 if (startmsg == 0L) startmsg = WC->msgarr[0];
1504 remaining_messages = 0;
1506 for (a = 0; a < nummsgs; ++a) {
1507 if (WC->msgarr[a] >= startmsg) {
1508 ++remaining_messages;
1513 if (!strcasecmp(sortby, "subject")) {
1514 qsort(WC->summ, WC->num_summ,
1515 sizeof(struct message_summary), summcmp_subj);
1517 else if (!strcasecmp(sortby, "rsubject")) {
1518 qsort(WC->summ, WC->num_summ,
1519 sizeof(struct message_summary), summcmp_rsubj);
1521 else if (!strcasecmp(sortby, "sender")) {
1522 qsort(WC->summ, WC->num_summ,
1523 sizeof(struct message_summary), summcmp_sender);
1525 else if (!strcasecmp(sortby, "rsender")) {
1526 qsort(WC->summ, WC->num_summ,
1527 sizeof(struct message_summary), summcmp_rsender);
1529 else if (!strcasecmp(sortby, "date")) {
1530 qsort(WC->summ, WC->num_summ,
1531 sizeof(struct message_summary), summcmp_date);
1533 else if (!strcasecmp(sortby, "rdate")) {
1534 qsort(WC->summ, WC->num_summ,
1535 sizeof(struct message_summary), summcmp_rdate);
1539 if (!strcasecmp(sortby, "subject")) {
1540 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1542 else if (!strcasecmp(sortby, "rsubject")) {
1543 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1546 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1549 if (!strcasecmp(sortby, "sender")) {
1550 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1552 else if (!strcasecmp(sortby, "rsender")) {
1553 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1556 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1559 if (!strcasecmp(sortby, "date")) {
1560 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1562 else if (!strcasecmp(sortby, "rdate")) {
1563 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1566 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1570 wprintf("</div>"); /* end of 'content' div */
1572 wprintf("<div id=\"message_list\">"
1574 "<div id=\"fix_scrollbar_bug\">\n"
1576 "<form name=\"msgomatic\" "
1577 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n"
1579 "<table border=0 cellspacing=0 "
1580 "cellpadding=0 width=100%%>\n"
1582 "<TD align=center><b><i>Subject</i></b> %s</TD>"
1583 "<TD align=center><b><i>Sender</i></b> %s</TD>"
1584 "<TD align=center><b><i>Date</i></b> %s</TD>"
1585 "<TD><INPUT TYPE=\"submit\" NAME=\"sc\" "
1586 "STYLE=\"font-family: Bitstream Vera Sans,Arial,Helvetica,sans-serif;"
1587 " font-size: 6pt;\" "
1588 "VALUE=\"Delete\"></TD>"
1597 for (a = 0; a < nummsgs; ++a) {
1598 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
1600 /* Learn which msgs "Prev" & "Next" buttons go to */
1601 pn_current = WC->msgarr[a];
1602 if (a > 0) pn_previous = WC->msgarr[a-1];
1603 if (a < (nummsgs-1)) pn_next = WC->msgarr[a+1];
1605 /* If a tabular view, set up the line */
1608 wprintf("<TR BGCOLOR=\"#%s\">",
1609 (bg ? "DDDDDD" : "FFFFFF")
1613 /* Display the message */
1615 display_summarized(a);
1617 else if (is_addressbook) {
1618 fetch_ab_name(WC->msgarr[a], buf);
1620 addrbook = realloc(addrbook,
1621 (sizeof(struct addrbookent) * num_ab) );
1622 safestrncpy(addrbook[num_ab-1].ab_name, buf,
1623 sizeof(addrbook[num_ab-1].ab_name));
1624 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
1626 else if (is_calendar) {
1627 display_calendar(WC->msgarr[a]);
1629 else if (is_tasks) {
1630 display_task(WC->msgarr[a]);
1632 else if (is_notes) {
1633 display_note(WC->msgarr[a]);
1636 read_message(WC->msgarr[a], 0);
1639 /* If a tabular view, finish the line */
1644 if (lowest_displayed < 0) lowest_displayed = a;
1645 highest_displayed = a;
1648 --remaining_messages;
1653 wprintf("</table></form>"
1654 "</div>\n"); /* end of 'fix_scrollbar_bug' div */
1655 wprintf("</div>"); /* end of 'message_list' div */
1657 wprintf("<div id=\"preview_pane\">"); /* The preview pane will initially be empty */
1660 /* Bump these because although we're thinking in zero base, the user
1661 * is a drooling idiot and is thinking in one base.
1664 ++highest_displayed;
1666 /* If we're only looking at one message, do a prev/next thing */
1667 if (num_displayed == 1) {
1668 if ((!is_tasks) && (!is_calendar) && (!is_addressbook) && (!is_notes) && (!is_singlecard)) {
1670 wprintf("<div id=\"fix_scrollbar_bug\">"
1671 "<table border=0 width=100%% bgcolor=\"#dddddd\"><tr><td>"
1672 "Reading #%d of %d messages.</TD>\n"
1673 "<TD ALIGN=RIGHT><FONT SIZE=+1>",
1674 lowest_displayed, nummsgs);
1676 if (pn_previous > 0L) {
1677 wprintf("<A HREF=\"/%s"
1687 wprintf("<A HREF=\"/%s"
1696 wprintf("<A HREF=\"/%s?startmsg=%ld"
1697 "?maxmsgs=%d?summary=1\">"
1705 wprintf("</td></tr></table></div>\n");
1710 * If we're not currently looking at ALL requested
1711 * messages, then display the selector bar
1713 if (num_displayed > 1) {
1714 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
1715 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
1717 wprintf("<form name=\"msgomatic\" "
1718 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n");
1720 wprintf("Reading #", lowest_displayed, highest_displayed);
1722 wprintf("<select name=\"whichones\" size=\"1\" "
1723 "OnChange=\"location.href=msgomatic.whichones.options"
1724 "[selectedIndex].value\">\n");
1726 for (b=0; b<nummsgs; b = b + maxmsgs) {
1729 if (hi > nummsgs) hi = nummsgs;
1730 wprintf("<option %s value="
1735 "%d-%d</option> \n",
1736 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
1743 wprintf("<option value=\"/%s?startmsg=%ld"
1744 "?maxmsgs=9999999?summary=%d\">"
1748 WC->msgarr[0], is_summary);
1750 wprintf("</select> of %d messages.", nummsgs);
1751 wprintf("</form>\n");
1757 do_tasks_view(); /* Render the task list */
1761 do_calendar_view(); /* Render the calendar */
1764 if (is_addressbook) {
1765 do_addrbook_view(addrbook, num_ab); /* Render the address book */
1768 /* Put the data transfer hidden iframe in a hidden div, to make it *really* hidden */
1770 "<div display=\"hidden\">\n"
1771 "<iframe name=\"msgloader1\" id=\"msgloader1\" width=\"1\"></iframe>\n"
1774 /* Note: wDumpContent() will output one additional </div> tag. */
1776 if (addrbook != NULL) free(addrbook);
1778 /* free the summary */
1779 if (WC->num_summ != 0) {
1784 /* If we got here via a mailbox view and are reading a single
1785 * message, mark it as "seen." We do this after rendering the web page
1786 * so it doesn't keep the user waiting.
1788 if ( (maxmsgs == 1) && (WC->wc_view == VIEW_MAILBOX) ) {
1789 serv_printf("SEEN %ld|1", startmsg);
1790 serv_getln(buf, sizeof buf);
1796 * Back end for post_message() ... this is where the actual message
1797 * gets transmitted to the server.
1799 void post_mime_to_server(void) {
1801 int is_multipart = 0;
1803 struct wc_attachment *att;
1805 size_t encoded_length;
1807 /* If there are attachments, we have to do multipart/mixed */
1808 if (WC->first_attachment != NULL) {
1813 sprintf(boundary, "---Citadel-Multipart-%s-%04x%04x---",
1814 serv_info.serv_fqdn,
1819 /* Remember, serv_printf() appends an extra newline */
1820 serv_printf("Content-type: multipart/mixed; "
1821 "boundary=\"%s\"\n", boundary);
1822 serv_printf("This is a multipart message in MIME format.\n");
1823 serv_printf("--%s", boundary);
1826 serv_puts("Content-type: text/html; charset=utf-8");
1828 serv_puts("<HTML><BODY>\n");
1829 text_to_server(bstr("msgtext"), 0);
1830 serv_puts("</BODY></HTML>\n");
1835 /* Add in the attachments */
1836 for (att = WC->first_attachment; att!=NULL; att=att->next) {
1838 encoded_length = ((att->length * 150) / 100);
1839 encoded = malloc(encoded_length);
1840 if (encoded == NULL) break;
1841 CtdlEncodeBase64(encoded, att->data, att->length);
1843 serv_printf("--%s", boundary);
1844 serv_printf("Content-type: %s", att->content_type);
1845 serv_printf("Content-disposition: attachment; "
1846 "filename=\"%s\"", att->filename);
1847 serv_puts("Content-transfer-encoding: base64");
1849 serv_write(encoded, strlen(encoded));
1854 serv_printf("--%s--", boundary);
1862 * Post message (or don't post message)
1864 * Note regarding the "dont_post" variable:
1865 * A random value (actually, it's just a timestamp) is inserted as a hidden
1866 * field called "postseq" when the display_enter page is generated. This
1867 * value is checked when posting, using the static variable dont_post. If a
1868 * user attempts to post twice using the same dont_post value, the message is
1869 * discarded. This prevents the accidental double-saving of the same message
1870 * if the user happens to click the browser "back" button.
1872 void post_message(void)
1875 static long dont_post = (-1L);
1876 struct wc_attachment *att, *aptr;
1878 if (WC->upload_length > 0) {
1880 /* There's an attachment. Save it to this struct... */
1881 att = malloc(sizeof(struct wc_attachment));
1882 memset(att, 0, sizeof(struct wc_attachment));
1883 att->length = WC->upload_length;
1884 strcpy(att->content_type, WC->upload_content_type);
1885 strcpy(att->filename, WC->upload_filename);
1888 /* And add it to the list. */
1889 if (WC->first_attachment == NULL) {
1890 WC->first_attachment = att;
1893 aptr = WC->first_attachment;
1894 while (aptr->next != NULL) aptr = aptr->next;
1898 /* Netscape sends a simple filename, which is what we want,
1899 * but Satan's browser sends an entire pathname. Reduce
1900 * the path to just a filename if we need to.
1902 while (num_tokens(att->filename, '/') > 1) {
1903 remove_token(att->filename, 0, '/');
1905 while (num_tokens(att->filename, '\\') > 1) {
1906 remove_token(att->filename, 0, '\\');
1909 /* Transfer control of this memory from the upload struct
1910 * to the attachment struct.
1912 att->data = WC->upload;
1913 WC->upload_length = 0;
1919 if (!strcasecmp(bstr("sc"), "Cancel")) {
1920 sprintf(WC->ImportantMessage,
1921 "Cancelled. Message was not posted.");
1922 } else if (!strcasecmp(bstr("attach"), "Add")) {
1925 } else if (atol(bstr("postseq")) == dont_post) {
1926 sprintf(WC->ImportantMessage,
1927 "Automatically cancelled because you have already "
1928 "saved this message.");
1930 sprintf(buf, "ENT0 1|%s|0|4|%s",
1934 serv_getln(buf, sizeof buf);
1935 if (buf[0] == '4') {
1936 post_mime_to_server();
1937 if (strlen(bstr("recp")) > 0) {
1938 sprintf(WC->ImportantMessage, "Message has been sent.\n");
1941 sprintf(WC->ImportantMessage, "Message has been posted.\n");
1943 dont_post = atol(bstr("postseq"));
1945 sprintf(WC->ImportantMessage,
1950 free_attachments(WC);
1951 readloop("readnew");
1958 * display the message entry screen
1960 void display_enter(void)
1964 struct wc_attachment *att;
1966 if (strlen(bstr("force_room")) > 0) {
1967 gotoroom(bstr("force_room"));
1970 /* Are we perhaps in an address book view? If so, then an "enter
1971 * message" command really means "add new entry."
1973 if (WC->wc_view == VIEW_ADDRESSBOOK) {
1974 do_edit_vcard(-1, "", "");
1978 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1979 /* Are we perhaps in a calendar view? If so, then an "enter
1980 * message" command really means "add new calendar item."
1982 if (WC->wc_view == VIEW_CALENDAR) {
1983 display_edit_event();
1987 /* Are we perhaps in a tasks view? If so, then an "enter
1988 * message" command really means "add new task."
1990 if (WC->wc_view == VIEW_TASKS) {
1991 display_edit_task();
1996 /* Otherwise proceed normally. Do a custom room banner with no navbar... */
1997 output_headers(1, 1, 2, 0, 0, 0, 0);
1998 wprintf("<div id=\"banner\">\n");
1999 embed_room_banner(NULL, navbar_none);
2000 wprintf("</div>\n");
2001 wprintf("<div id=\"content\">\n"
2002 "<div id=\"fix_scrollbar_bug\">"
2003 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
2005 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
2007 serv_getln(buf, sizeof buf);
2009 if (!strncmp(buf, "570", 3)) {
2010 if (strlen(bstr("recp")) > 0) {
2011 svprintf("RECPERROR", WCS_STRING,
2012 "<SPAN CLASS=\"errormsg\">%s</SPAN><br />\n",
2016 do_template("prompt_for_recipient");
2019 if (buf[0] != '2') {
2020 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2025 fmt_date(buf, now, 0);
2026 strcat(&buf[strlen(buf)], " <I>from</I> ");
2027 stresc(&buf[strlen(buf)], WC->wc_username, 1, 1);
2028 if (strlen(bstr("recp")) > 0) {
2029 strcat(&buf[strlen(buf)], " <I>to</I> ");
2030 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
2032 strcat(&buf[strlen(buf)], " <I>in</I> ");
2033 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
2035 /* begin message entry screen */
2036 // wprintf("<div style=\"position:absolute; left:1%%; width:96%%; height:100%%\">\n");
2038 wprintf("<form enctype=\"multipart/form-data\" "
2039 "method=\"POST\" action=\"/post\" "
2040 "name=\"enterform\""
2041 "onSubmit=\"return submitForm();\""
2043 wprintf("<input type=\"hidden\" name=\"recp\" value=\"%s\">\n",
2045 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n",
2048 wprintf("%s<br>\n", buf); /* header bar */
2049 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2050 /* "onLoad=\"document.enterform.msgtext.focus();\" " */
2051 wprintf("<font size=-1>Subject (optional):</font>"
2052 "<input type=\"text\" name=\"subject\" value=\"");
2053 escputs(bstr("subject"));
2054 wprintf("\" size=40 maxlength=70>"
2058 wprintf("<input type=\"submit\" name=\"sc\" value=\"");
2059 if (strlen(bstr("recp")) > 0) {
2060 wprintf("Send message");
2062 wprintf("Post message");
2065 "<input type=\"submit\" name=\"sc\" value=\"Cancel\">\n");
2067 wprintf("<center><script type=\"text/javascript\" "
2068 "src=\"static/richtext.js\"></script>\n"
2069 "<script type=\"text/javascript\">\n"
2070 "function submitForm() { \n"
2071 " updateRTE('msgtext'); \n"
2075 "initRTE(\"static/\", \"static/\", \"\"); \n"
2077 "<noscript>JavaScript must be enabled.</noscript> \n"
2078 "<script type=\"text/javascript\"> \n"
2079 "writeRichText('msgtext', '");
2080 msgescputs(bstr("msgtext"));
2081 wprintf("', '96%%', '200', true, false); \n"
2082 "</script></center><br />\n");
2084 /* Enumerate any attachments which are already in place... */
2085 wprintf("<img src=\"/static/diskette_24x.gif\" border=0 "
2086 "align=middle height=16 width=16> Attachments: ");
2087 wprintf("<select name=\"which_attachment\" size=1>");
2088 for (att = WC->first_attachment; att != NULL; att = att->next) {
2089 wprintf("<option value=\"");
2090 urlescputs(att->filename);
2092 escputs(att->filename);
2093 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
2094 wprintf("</option>\n");
2096 wprintf("</select>");
2098 /* Now offer the ability to attach additional files... */
2099 wprintf(" "
2100 "Attach file: <input NAME=\"attachfile\" "
2101 "SIZE=16 TYPE=\"file\">\n "
2102 "<input type=\"submit\" name=\"attach\" value=\"Add\">\n");
2104 wprintf("</form>\n");
2106 wprintf("</td></tr></table></div>\n");
2107 DONE: wDumpContent(1);
2117 void delete_msg(void)
2122 msgid = atol(bstr("msgid"));
2124 output_headers(1, 1, 1, 0, 0, 0, 0);
2126 sprintf(buf, "DELE %ld", msgid);
2128 serv_getln(buf, sizeof buf);
2129 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2138 * Confirm move of a message
2140 void confirm_move_msg(void)
2146 msgid = atol(bstr("msgid"));
2148 output_headers(1, 1, 1, 0, 0, 0, 0);
2150 wprintf("<div id=\"fix_scrollbar_bug\">"
2151 "<table width=100%% border=0 bgcolor=\"#444455\"><tr><td>");
2152 wprintf("<font size=+1 color=\"#ffffff\"");
2153 wprintf("<b>Confirm move of message</b>\n");
2154 wprintf("</font></td></tr></table></div>\n");
2156 wprintf("<CENTER>");
2158 wprintf("Move this message to:<br />\n");
2160 wprintf("<form METHOD=\"POST\" ACTION=\"/move_msg\">\n");
2161 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
2165 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
2167 serv_getln(buf, sizeof buf);
2168 if (buf[0] == '1') {
2169 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2170 extract_token(targ, buf, 0, '|', sizeof targ);
2171 wprintf("<OPTION>");
2176 wprintf("</SELECT>\n");
2177 wprintf("<br />\n");
2179 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
2181 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
2182 wprintf("</form></CENTER>\n");
2184 wprintf("</CENTER>\n");
2195 msgid = atol(bstr("msgid"));
2197 output_headers(1, 1, 1, 0, 0, 0, 0);
2199 if (!strcasecmp(bstr("yesno"), "Move")) {
2200 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
2202 serv_getln(buf, sizeof buf);
2203 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2205 wprintf("<EM>Message not moved.</EM><br />\n");
2212 * This gets called when a user selects multiple messages in a summary
2213 * list and then clicks to perform a transformation of some sort on them
2214 * (such as deleting them).
2216 void do_stuff_to_msgs(void) {
2221 struct stuff_t *next;
2225 struct stuff_t *stuff = NULL;
2226 struct stuff_t *ptr;
2229 serv_puts("MSGS ALL");
2230 serv_getln(buf, sizeof buf);
2232 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2233 ptr = malloc(sizeof(struct stuff_t));
2234 ptr->msgnum = atol(buf);
2239 strcpy(sc, bstr("sc"));
2241 while (stuff != NULL) {
2243 sprintf(buf, "msg_%ld", stuff->msgnum);
2244 if (!strcasecmp(bstr(buf), "yes")) {
2246 if (!strcasecmp(sc, "Delete")) {
2247 serv_printf("DELE %ld", stuff->msgnum);
2248 serv_getln(buf, sizeof buf);
2258 readloop("readfwd");