4 * Functions which deal with the fetching and displaying of messages.
10 #include "webserver.h"
13 /* Address book entry (keep it short and sweet, it's just a quickie lookup
14 * which we can use to get to the real meat and bones later)
24 /* Handle subjects with RFC2047 encoding, such as:
25 * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=
27 void utf8ify_rfc822_string(char *buf) {
33 iconv_t ic = (iconv_t)(-1) ;
34 char *ibuf; /* Buffer of characters to be converted */
35 char *obuf; /* Buffer for converted characters */
36 size_t ibuflen; /* Length of input buffer */
37 size_t obuflen; /* Length of output buffer */
38 char *isav; /* Saved pointer to input buffer */
39 char *osav; /* Saved pointer to output buffer */
41 while (start=strstr(buf, "=?"), end=strstr(buf, "?="),
42 ((start != NULL) && (end != NULL) && (end > start)) )
44 extract_token(charset, start, 1, '?', sizeof charset);
45 extract_token(encoding, start, 2, '?', sizeof encoding);
46 extract_token(istr, start, 3, '?', sizeof istr);
54 if (!strcasecmp(encoding, "B")) { /* base64 */
55 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
57 else if (!strcasecmp(encoding, "Q")) { /* quoted-printable */
58 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, strlen(istr));
61 strcpy(ibuf, istr); /* huh? */
62 ibuflen = strlen(istr);
65 ic = iconv_open("UTF-8", charset);
66 if (ic != (iconv_t)(-1) ) {
69 obuf = (char *) malloc(obuflen);
71 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
72 osav[1024-obuflen] = 0;
77 remove_token(end, 0, '?');
78 remove_token(end, 0, '?');
79 remove_token(end, 0, '?');
80 remove_token(end, 0, '?');
83 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
89 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
101 * Look for URL's embedded in a buffer and make them linkable. We use a
102 * target window in order to keep the BBS session in its own window.
118 for (pos = 0; pos < strlen(buf); ++pos) {
119 if (!strncasecmp(&buf[pos], "http://", 7))
121 if (!strncasecmp(&buf[pos], "ftp://", 6))
128 if ((start > 0) && (buf[start - 1] == '<'))
130 if ((start > 0) && (buf[start - 1] == '['))
132 if ((start > 0) && (buf[start - 1] == '('))
134 if ((start > 0) && (buf[start - 1] == '{'))
137 for (pos = strlen(buf); pos > start; --pos) {
138 if ((buf[pos] == ' ') || (buf[pos] == ench))
142 strncpy(urlbuf, &buf[start], end - start);
143 urlbuf[end - start] = 0;
145 strncpy(outbuf, buf, start);
146 sprintf(&outbuf[start], "%cA HREF=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
147 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
148 strcat(outbuf, &buf[end]);
149 if ( strlen(outbuf) < 250 )
155 * Turn a vCard "n" (name) field into something displayable.
157 void vcard_n_prettyize(char *name)
162 original_name = strdup(name);
163 for (i=0; i<5; ++i) {
164 if (strlen(original_name) > 0) {
165 if (original_name[strlen(original_name)-1] == ' ') {
166 original_name[strlen(original_name)-1] = 0;
168 if (original_name[strlen(original_name)-1] == ';') {
169 original_name[strlen(original_name)-1] = 0;
174 for (i=0; i<strlen(original_name); ++i) {
175 if (original_name[i] == ';') {
179 name[strlen(name)+1] = 0;
180 name[strlen(name)] = original_name[i];
189 /* display_vcard() calls this after parsing the textual vCard into
190 * our 'struct vCard' data object.
191 * This gets called instead of display_parsed_vcard() if we are only looking
192 * to extract the person's name instead of displaying the card.
194 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
197 strcpy(storename, "");
199 name = vcard_get_prop(v, "n", 1, 0, 0);
201 strcpy(storename, name);
202 /* vcard_n_prettyize(storename); */
209 /* display_vcard() calls this after parsing the textual vCard into
210 * our 'struct vCard' data object.
212 * Set 'full' to nonzero to display the full card, otherwise it will only
213 * show a summary line.
215 * This code is a bit ugly, so perhaps an explanation is due: we do this
216 * in two passes through the vCard fields. On the first pass, we process
217 * fields we understand, and then render them in a pretty fashion at the
218 * end. Then we make a second pass, outputting all the fields we don't
219 * understand in a simple two-column name/value format.
221 void display_parsed_vcard(struct vCard *v, int full) {
227 char *thisname, *thisvalue;
228 char firsttoken[SIZ];
231 char displayname[SIZ];
237 strcpy(displayname, "");
245 name = vcard_get_prop(v, "fn", 1, 0, 0);
249 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
250 strcpy(displayname, name);
251 vcard_n_prettyize(displayname);
252 escputs(displayname);
261 wprintf("<div align=center><table bgcolor=#aaaaaa width=50%%>");
262 for (pass=1; pass<=2; ++pass) {
264 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
266 thisname = strdup(v->prop[i].name);
267 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
269 for (j=0; j<num_tokens(thisname, ';'); ++j) {
270 extract_token(buf, thisname, j, ';', sizeof buf);
271 if (!strcasecmp(buf, "encoding=quoted-printable")) {
273 remove_token(thisname, j, ';');
275 if (!strcasecmp(buf, "encoding=base64")) {
277 remove_token(thisname, j, ';');
282 thisvalue = malloc(strlen(v->prop[i].value) + 50);
283 j = CtdlDecodeQuotedPrintable(
284 thisvalue, v->prop[i].value,
285 strlen(v->prop[i].value) );
289 thisvalue = malloc(strlen(v->prop[i].value) + 50);
291 thisvalue, v->prop[i].value,
292 strlen(v->prop[i].value) );
295 thisvalue = strdup(v->prop[i].value);
298 /*** Various fields we may encounter ***/
300 /* N is name, but only if there's no FN already there */
301 if (!strcasecmp(firsttoken, "n")) {
302 if (strlen(displayname) == 0) {
303 strcpy(displayname, thisvalue);
304 vcard_n_prettyize(displayname);
308 /* FN (full name) is a true 'display name' field */
309 else if (!strcasecmp(firsttoken, "fn")) {
310 strcpy(displayname, thisvalue);
314 else if (!strcasecmp(firsttoken, "title")) {
315 strcpy(title, thisvalue);
319 else if (!strcasecmp(firsttoken, "org")) {
320 strcpy(org, thisvalue);
323 else if (!strcasecmp(firsttoken, "email")) {
324 if (strlen(mailto) > 0) strcat(mailto, "<br />");
326 "<A HREF=\"/display_enter"
327 "?force_room=_MAIL_?recp=");
328 urlesc(&mailto[strlen(mailto)], thisvalue);
329 strcat(mailto, "\">");
330 urlesc(&mailto[strlen(mailto)], thisvalue);
331 strcat(mailto, "</A>");
333 else if (!strcasecmp(firsttoken, "tel")) {
334 if (strlen(phone) > 0) strcat(phone, "<br />");
335 strcat(phone, thisvalue);
336 for (j=0; j<num_tokens(thisname, ';'); ++j) {
337 extract_token(buf, thisname, j, ';', sizeof buf);
338 if (!strcasecmp(buf, "tel"))
340 else if (!strcasecmp(buf, "work"))
341 strcat(phone, _(" (work)"));
342 else if (!strcasecmp(buf, "home"))
343 strcat(phone, _(" (home)"));
344 else if (!strcasecmp(buf, "cell"))
345 strcat(phone, _(" (cell)"));
353 else if (!strcasecmp(firsttoken, "adr")) {
356 wprintf(_("Address:"));
357 wprintf("</TD><TD>");
358 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
359 extract_token(buf, thisvalue, j, ';', sizeof buf);
360 if (strlen(buf) > 0) {
362 if (j<3) wprintf("<br />");
366 wprintf("</TD></TR>\n");
369 else if (!strcasecmp(firsttoken, "version")) {
372 else if (!strcasecmp(firsttoken, "rev")) {
375 else if (!strcasecmp(firsttoken, "label")) {
380 /*** Don't show extra fields. They're ugly.
384 wprintf("</TD><TD>");
386 wprintf("</TD></TR>\n");
396 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
397 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
398 "<IMG ALIGN=CENTER SRC=\"/static/viewcontacts_48x.gif\">"
399 "<FONT SIZE=+1><B>");
400 escputs(displayname);
401 wprintf("</B></FONT>");
402 if (strlen(title) > 0) {
403 wprintf("<div align=right>");
407 if (strlen(org) > 0) {
408 wprintf("<div align=right>");
412 wprintf("</TD></TR>\n");
414 if (strlen(phone) > 0)
416 wprintf(_("Telephone:"));
417 wprintf("</TD><TD>%s</TD></TR>\n", phone);
418 if (strlen(mailto) > 0)
420 wprintf(_("E-mail:"));
421 wprintf("</TD><TD>%s</TD></TR>\n", mailto);
426 wprintf("</table></div>\n");
432 * Display a textual vCard
433 * (Converts to a vCard object and then calls the actual display function)
434 * Set 'full' to nonzero to display the whole card instead of a one-liner.
435 * Or, if "storename" is non-NULL, just store the person's name in that
436 * buffer instead of displaying the card at all.
438 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
444 v = vcard_load(vcard_source);
445 if (v == NULL) return;
447 name = vcard_get_prop(v, "n", 1, 0, 0);
453 if (storename != NULL) {
454 fetchname_parsed_vcard(v, storename);
456 else if ( (alpha == 0)
457 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
458 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
460 display_parsed_vcard(v, full);
470 * I wanna SEE that message!
472 void read_message(long msgnum, int suppress_buttons) {
474 char mime_partnum[256];
475 char mime_filename[256];
476 char mime_content_type[256];
477 char mime_charset[256];
478 char mime_disposition[256];
491 char vcard_partnum[256];
492 char cal_partnum[256];
493 char *part_source = NULL;
495 iconv_t ic = (iconv_t)(-1) ;
496 char *ibuf; /* Buffer of characters to be converted */
497 char *obuf; /* Buffer for converted characters */
498 size_t ibuflen; /* Length of input buffer */
499 size_t obuflen; /* Length of output buffer */
500 char *osav; /* Saved pointer to output buffer */
506 strcpy(reply_to, "");
507 strcpy(vcard_partnum, "");
508 strcpy(cal_partnum, "");
509 strcpy(mime_http, "");
510 strcpy(mime_content_type, "text/plain");
511 strcpy(mime_charset, "us-ascii");
513 serv_printf("MSG4 %ld", msgnum);
514 serv_getln(buf, sizeof buf);
517 wprintf(_("ERROR:"));
518 wprintf("</STRONG> %s<br />\n", &buf[4]);
522 /* begin everythingamundo table */
523 wprintf("<div id=\"fix_scrollbar_bug\">\n");
524 wprintf("<table width=100%% border=1 cellspacing=0 "
525 "cellpadding=0><TR><TD>\n");
527 /* begin message header table */
528 wprintf("<TABLE WIDTH=100%% BORDER=0 CELLSPACING=0 "
529 "CELLPADDING=1 BGCOLOR=\"#CCCCCC\"><TR><TD>\n");
531 wprintf("<SPAN CLASS=\"message_header\">");
532 strcpy(m_subject, "");
534 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
535 if (!strcmp(buf, "000")) {
537 wprintf(_("unexpected end of message"));
538 wprintf("</I><br /><br />\n");
539 wprintf("</SPAN>\n");
542 if (!strncasecmp(buf, "nhdr=yes", 8))
546 if (!strncasecmp(buf, "type=", 5))
547 format_type = atoi(&buf[5]);
548 if (!strncasecmp(buf, "from=", 5)) {
549 strcpy(from, &buf[5]);
551 wprintf("<A HREF=\"/showuser?who=");
553 utf8ify_rfc822_string(from);
560 if (!strncasecmp(buf, "subj=", 5)) {
561 strcpy(m_subject, &buf[5]);
563 if ((!strncasecmp(buf, "hnod=", 5))
564 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
565 wprintf("(%s) ", &buf[5]);
567 if ((!strncasecmp(buf, "room=", 5))
568 && (strcasecmp(&buf[5], WC->wc_roomname))
569 && (strlen(&buf[5])>0) ) {
571 wprintf("%s> ", &buf[5]);
573 if (!strncasecmp(buf, "rfca=", 5)) {
574 strcpy(rfca, &buf[5]);
580 if (!strncasecmp(buf, "node=", 5)) {
581 strcpy(node, &buf[5]);
582 if ( ((WC->room_flags & QR_NETWORK)
583 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
584 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
587 wprintf("@%s ", &buf[5]);
590 if (!strncasecmp(buf, "rcpt=", 5)) {
592 wprintf("%s ", &buf[5]);
594 if (!strncasecmp(buf, "time=", 5)) {
595 fmt_date(now, atol(&buf[5]), 0);
599 if (!strncasecmp(buf, "part=", 5)) {
600 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
601 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
602 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
603 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
604 mime_length = extract_int(&buf[5], 5);
606 if (!strcasecmp(mime_disposition, "attachment")) {
607 snprintf(&mime_http[strlen(mime_http)],
608 (sizeof(mime_http) - strlen(mime_http) - 1),
609 "<A HREF=\"/output_mimepart?"
610 "msgnum=%ld?partnum=%s\" "
611 "TARGET=\"wc.%ld.%s\">"
612 "<IMG SRC=\"/static/diskette_24x.gif\" "
613 "BORDER=0 ALIGN=MIDDLE>\n"
614 "Part %s: %s (%s, %d bytes)</A><br />\n",
615 msgnum, mime_partnum,
616 msgnum, mime_partnum,
617 mime_partnum, mime_filename,
618 mime_content_type, mime_length);
621 if ((!strcasecmp(mime_disposition, "inline"))
622 && (!strncasecmp(mime_content_type, "image/", 6)) ){
623 snprintf(&mime_http[strlen(mime_http)],
624 (sizeof(mime_http) - strlen(mime_http) - 1),
625 "<IMG SRC=\"/output_mimepart?"
626 "msgnum=%ld?partnum=%s\">",
627 msgnum, mime_partnum);
630 /*** begin handler prep ***/
631 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
632 strcpy(vcard_partnum, mime_partnum);
635 if (!strcasecmp(mime_content_type, "text/calendar")) {
636 strcpy(cal_partnum, mime_partnum);
639 /*** end handler prep ***/
645 /* Generate a reply-to address */
646 if (strlen(rfca) > 0) {
647 strcpy(reply_to, rfca);
650 if ( (strlen(node) > 0)
651 && (strcasecmp(node, serv_info.serv_nodename))
652 && (strcasecmp(node, serv_info.serv_humannode)) ) {
653 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
657 snprintf(reply_to, sizeof(reply_to), "%s", from);
667 utf8ify_rfc822_string(m_subject);
669 if (strlen(m_subject) > 0) {
671 "<SPAN CLASS=\"message_subject\">");
672 wprintf(_("Subject:"));
673 wprintf(" %s</SPAN>", m_subject
678 /* start msg buttons */
679 if (!suppress_buttons) {
680 wprintf("<td align=right>\n");
683 wprintf("<a href=\"/display_enter?recp=");
684 urlescputs(reply_to);
685 wprintf("?subject=");
686 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
687 urlescputs(m_subject);
688 wprintf("\">[%s]</a> ", _("Reply"));
690 if (WC->is_room_aide) {
692 wprintf("<a href=\"/confirm_move_msg?msgid=%ld\">[%s]</a> ",
696 wprintf("<a href=\"/delete_msg?msgid=%ld\" "
697 "onClick=\"return confirm('%s');\">"
698 "[%s]</a> ", msgnum, _("Delete this message?"), _("Delete")
702 wprintf("<a href=\"/msg?msgnum=%ld?sourceiframe=msgloader1?print_it=yes\" target=\"msgloader1\">"
703 "[%s]</a>", msgnum, _("Print"));
708 wprintf("</TR></TABLE>\n");
711 wprintf("<TABLE BORDER=0 WIDTH=100%% BGCOLOR=#FFFFFF "
712 "CELLPADDING=1 CELLSPACING=0><TR><TD>");
715 * Learn the content type
717 strcpy(mime_content_type, "text/plain");
718 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
719 if (!strcmp(buf, "000")) {
721 wprintf(_("unexpected end of message"));
722 wprintf("</I><br /><br />\n");
725 if (!strncasecmp(buf, "Content-type: ", 14)) {
726 safestrncpy(mime_content_type, &buf[14],
727 sizeof(mime_content_type));
728 for (i=0; i<strlen(mime_content_type); ++i) {
729 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
730 safestrncpy(mime_charset, &mime_content_type[i+8],
731 sizeof mime_charset);
734 for (i=0; i<strlen(mime_content_type); ++i) {
735 if (mime_content_type[i] == ';') {
736 mime_content_type[i] = 0;
742 /* Set up a character set conversion if we need to (and if we can) */
744 if ( (strcasecmp(mime_charset, "us-ascii"))
745 && (strcasecmp(mime_charset, "UTF-8")) ) {
746 ic = iconv_open("UTF-8", mime_charset);
747 if (ic == (iconv_t)(-1) ) {
748 lprintf(5, "iconv_open() failed: %s\n", strerror(errno));
753 /* Messages in legacy Citadel variformat get handled thusly... */
754 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
755 fmout(NULL, "JUSTIFY");
758 /* Boring old 80-column fixed format text gets handled this way... */
759 else if (!strcasecmp(mime_content_type, "text/plain")) {
760 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
761 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
762 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
765 if (ic != (iconv_t)(-1) ) {
767 ibuflen = strlen(ibuf);
769 obuf = (char *) malloc(obuflen);
771 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
772 osav[SIZ-obuflen] = 0;
773 safestrncpy(buf, osav, sizeof buf);
778 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
779 buf[strlen(buf) - 1] = 0;
781 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
782 wprintf("<BLOCKQUOTE>");
784 } else if ((bq == 1) &&
785 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
786 wprintf("</BLOCKQUOTE>");
792 wprintf("</TT><br />\n");
794 wprintf("</I><br />");
797 else /* HTML is fun, but we've got to strip it first */
798 if (!strcasecmp(mime_content_type, "text/html")) {
799 output_html(mime_charset);
802 /* Unknown weirdness */
804 wprintf(_("I don't know how to display %s"), mime_content_type);
805 wprintf("<br />\n", mime_content_type);
806 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
809 /* Afterwards, offer links to download attachments 'n' such */
810 if (strlen(mime_http) > 0) {
811 wprintf("%s", mime_http);
814 /* Handler for vCard parts */
815 if (strlen(vcard_partnum) > 0) {
816 part_source = load_mimepart(msgnum, vcard_partnum);
817 if (part_source != NULL) {
819 /* If it's my vCard I can edit it */
820 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
821 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
822 || (WC->wc_view == VIEW_ADDRESSBOOK)
824 wprintf("<A HREF=\"/edit_vcard?"
825 "msgnum=%ld?partnum=%s\">",
826 msgnum, vcard_partnum);
827 wprintf("[%s]</A>", _("edit"));
830 /* In all cases, display the full card */
831 display_vcard(part_source, 0, 1, NULL);
835 /* Handler for calendar parts */
836 if (strlen(cal_partnum) > 0) {
837 part_source = load_mimepart(msgnum, cal_partnum);
838 if (part_source != NULL) {
839 cal_process_attachment(part_source,
840 msgnum, cal_partnum);
850 wprintf("</TD></TR></TABLE>\n");
852 /* end everythingamundo table */
853 wprintf("</TD></TR></TABLE>\n");
854 wprintf("</div><br />\n");
857 if (ic != (iconv_t)(-1) ) {
866 * Unadorned HTML output of an individual message, suitable
867 * for placing in a hidden iframe, for printing, or whatever
869 void embed_message(void) {
875 msgnum = atol(bstr("msgnum"));
876 sourceiframe = bstr("sourceiframe");
877 targetdiv = bstr("targetdiv");
878 print_it = bstr("print_it");
880 output_headers(1, 0, 0, 0, 0, 1, 0);
883 wprintf("<html><head>");
885 /* If we're loading into a hidden iframe, chances are the caller told us
886 * about a target div somewhere that we need to copy into when we're done.
888 if (strlen(targetdiv) > 0) wprintf(
890 " <script type=\"text/javascript\"> \n"
891 " function loaded_now_copy_it() { \n"
892 " parent.document.getElementById(\"%s\").innerHTML = parent.frames['%s'].document.body.innerHTML; \n"
899 if (!strcasecmp(print_it, "yes")) wprintf(
901 " <script type=\"text/javascript\"> \n"
902 " function loaded_now_print_it() { \n"
903 " parent.frames['%s'].focus(); \n"
904 " parent.frames['%s'].print(); \n"
913 if (strlen(targetdiv) > 0) {
914 wprintf(" onLoad='loaded_now_copy_it();'");
916 if (!strcasecmp(print_it, "yes")) {
917 wprintf(" onLoad='loaded_now_print_it();'");
920 read_message(msgnum, (!strcasecmp(print_it, "yes") ? 1 : 0) );
921 wprintf("</body></html>\n");
928 void display_summarized(int num) {
932 if (WC->summ[num].is_new) wprintf("<B>");
933 wprintf("<A HREF=\"/msg?msgnum=%ld?sourceiframe=msgloader1?targetdiv=preview_pane\" target=\"msgloader1\">",
934 WC->summ[num].msgnum);
935 escputs(WC->summ[num].subj);
937 if (WC->summ[num].is_new) wprintf("</B>");
938 wprintf("</TD><TD>");
939 if (WC->summ[num].is_new) wprintf("<B>");
940 escputs(WC->summ[num].from);
941 if (WC->summ[num].is_new) wprintf("</B>");
942 wprintf(" </TD><TD>");
943 if (WC->summ[num].is_new) wprintf("<B>");
944 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
946 if (WC->summ[num].is_new) wprintf("</B>");
949 "<INPUT TYPE=\"checkbox\" NAME=\"msg_%ld\" VALUE=\"yes\">"
959 void display_addressbook(long msgnum, char alpha) {
961 char mime_partnum[SIZ];
962 char mime_filename[SIZ];
963 char mime_content_type[SIZ];
964 char mime_disposition[SIZ];
966 char vcard_partnum[SIZ];
967 char *vcard_source = NULL;
968 struct message_summary summ;
970 memset(&summ, 0, sizeof(summ));
971 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
973 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
975 serv_getln(buf, sizeof buf);
976 if (buf[0] != '1') return;
978 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
979 if (!strncasecmp(buf, "part=", 5)) {
980 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
981 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
982 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
983 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
984 mime_length = extract_int(&buf[5], 5);
986 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
987 strcpy(vcard_partnum, mime_partnum);
993 if (strlen(vcard_partnum) > 0) {
994 vcard_source = load_mimepart(msgnum, vcard_partnum);
995 if (vcard_source != NULL) {
997 /* Display the summary line */
998 display_vcard(vcard_source, alpha, 0, NULL);
1000 /* If it's my vCard I can edit it */
1001 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1002 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1003 || (WC->wc_view == VIEW_ADDRESSBOOK)
1005 wprintf("<A HREF=\"/edit_vcard?"
1006 "msgnum=%ld?partnum=%s\">",
1007 msgnum, vcard_partnum);
1008 wprintf("[%s]</A>", _("edit"));
1019 /* If it's an old "Firstname Lastname" style record, try to
1022 void lastfirst_firstlast(char *namebuf) {
1023 char firstname[SIZ];
1027 if (namebuf == NULL) return;
1028 if (strchr(namebuf, ';') != NULL) return;
1030 i = num_tokens(namebuf, ' ');
1033 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1034 remove_token(namebuf, i-1, ' ');
1035 strcpy(firstname, namebuf);
1036 sprintf(namebuf, "%s; %s", lastname, firstname);
1040 void fetch_ab_name(long msgnum, char *namebuf) {
1042 char mime_partnum[SIZ];
1043 char mime_filename[SIZ];
1044 char mime_content_type[SIZ];
1045 char mime_disposition[SIZ];
1047 char vcard_partnum[SIZ];
1048 char *vcard_source = NULL;
1050 struct message_summary summ;
1052 if (namebuf == NULL) return;
1053 strcpy(namebuf, "");
1055 memset(&summ, 0, sizeof(summ));
1056 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1058 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1060 serv_getln(buf, sizeof buf);
1061 if (buf[0] != '1') return;
1063 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1064 if (!strncasecmp(buf, "part=", 5)) {
1065 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1066 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1067 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1068 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1069 mime_length = extract_int(&buf[5], 5);
1071 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1072 strcpy(vcard_partnum, mime_partnum);
1078 if (strlen(vcard_partnum) > 0) {
1079 vcard_source = load_mimepart(msgnum, vcard_partnum);
1080 if (vcard_source != NULL) {
1082 /* Grab the name off the card */
1083 display_vcard(vcard_source, 0, 0, namebuf);
1089 lastfirst_firstlast(namebuf);
1091 for (i=0; i<strlen(namebuf); ++i) {
1092 if (namebuf[i] != ';') return;
1094 strcpy(namebuf, _("(no name)"));
1100 * Record compare function for sorting address book indices
1102 int abcmp(const void *ab1, const void *ab2) {
1104 (((const struct addrbookent *)ab1)->ab_name),
1105 (((const struct addrbookent *)ab2)->ab_name)
1111 * Helper function for do_addrbook_view()
1112 * Converts a name into a three-letter tab label
1114 void nametab(char *tabbuf, char *name) {
1115 stresc(tabbuf, name, 0, 0);
1116 tabbuf[0] = toupper(tabbuf[0]);
1117 tabbuf[1] = tolower(tabbuf[1]);
1118 tabbuf[2] = tolower(tabbuf[2]);
1124 * Render the address book using info we gathered during the scan
1126 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1130 static int NAMESPERPAGE = 60;
1134 char tabfirst_label[SIZ];
1136 char tablast_label[SIZ];
1140 wprintf(_("This address book is empty."));
1146 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1149 num_pages = num_ab / NAMESPERPAGE;
1151 page = atoi(bstr("page"));
1154 for (i=0; i<=num_pages; ++i) {
1156 wprintf("<A HREF=\"/readfwd?page=%d\">", i);
1161 tabfirst = i * NAMESPERPAGE;
1162 tablast = tabfirst + NAMESPERPAGE - 1;
1163 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1164 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1165 nametab(tablast_label, addrbook[tablast].ab_name);
1166 wprintf("[%s - %s]",
1167 tabfirst_label, tablast_label
1176 wprintf("<br />\n");
1178 wprintf("<TABLE border=0 cellspacing=0 "
1179 "cellpadding=3 width=100%%>\n"
1182 for (i=0; i<num_ab; ++i) {
1184 if ((i / NAMESPERPAGE) == page) {
1186 if ((displayed % 4) == 0) {
1187 if (displayed > 0) {
1191 wprintf("<TR BGCOLOR=\"#%s\">",
1192 (bg ? "DDDDDD" : "FFFFFF")
1198 wprintf("<A HREF=\"/readfwd?startmsg=%ld&is_singlecard=1",
1199 addrbook[i].ab_msgnum);
1200 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1201 vcard_n_prettyize(addrbook[i].ab_name);
1202 escputs(addrbook[i].ab_name);
1203 wprintf("</A></TD>\n");
1208 wprintf("</TR></TABLE>\n");
1214 * load message pointers from the server
1216 int load_msg_ptrs(char *servcmd, int with_headers)
1220 char displayname[128];
1227 int num_summ_alloc = 0;
1230 if (WC->num_summ != 0) {
1235 num_summ_alloc = 100;
1237 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1240 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1242 serv_getln(buf, sizeof buf);
1243 if (buf[0] != '1') {
1244 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1247 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1248 if (nummsgs < maxload) {
1249 WC->msgarr[nummsgs] = extract_long(buf, 0);
1250 datestamp = extract_long(buf, 1);
1251 extract_token(displayname, buf, 2, '|', sizeof displayname);
1252 extract_token(nodename, buf, 3, '|', sizeof nodename);
1253 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1254 extract_token(subject, buf, 5, '|', sizeof subject);
1258 if (nummsgs > num_summ_alloc) {
1259 num_summ_alloc *= 2;
1260 WC->summ = realloc(WC->summ, num_summ_alloc * sizeof(struct message_summary));
1264 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1265 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1266 safestrncpy(WC->summ[nummsgs-1].subj, _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1267 if (strlen(displayname) > 0) {
1268 safestrncpy(WC->summ[nummsgs-1].from, displayname, sizeof WC->summ[nummsgs-1].from);
1270 if (strlen(subject) > 0) {
1271 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1272 sizeof WC->summ[nummsgs-1].subj);
1275 /* Handle subjects with RFC2047 encoding */
1276 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1278 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1279 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1282 if (strlen(nodename) > 0) {
1283 if ( ((WC->room_flags & QR_NETWORK)
1284 || ((strcasecmp(nodename, serv_info.serv_nodename)
1285 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1287 strcat(WC->summ[nummsgs-1].from, " @ ");
1288 strcat(WC->summ[nummsgs-1].from, nodename);
1292 WC->summ[nummsgs-1].date = datestamp;
1295 /* Handle senders with RFC2047 encoding */
1296 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1298 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1299 strcpy(&WC->summ[nummsgs-1].from[22], "...");
1308 int summcmp_subj(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->subj, summ2->subj);
1317 int summcmp_rsubj(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->subj, summ1->subj);
1326 int summcmp_sender(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(summ1->from, summ2->from);
1335 int summcmp_rsender(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;
1341 return strcasecmp(summ2->from, summ1->from);
1344 int summcmp_date(const void *s1, const void *s2) {
1345 struct message_summary *summ1;
1346 struct message_summary *summ2;
1348 summ1 = (struct message_summary *)s1;
1349 summ2 = (struct message_summary *)s2;
1351 if (summ1->date < summ2->date) return -1;
1352 else if (summ1->date > summ2->date) return +1;
1356 int summcmp_rdate(const void *s1, const void *s2) {
1357 struct message_summary *summ1;
1358 struct message_summary *summ2;
1360 summ1 = (struct message_summary *)s1;
1361 summ2 = (struct message_summary *)s2;
1363 if (summ1->date < summ2->date) return +1;
1364 else if (summ1->date > summ2->date) return -1;
1369 * command loop for reading messages
1371 void readloop(char *oper)
1380 int num_displayed = 0;
1382 int is_addressbook = 0;
1383 int is_singlecard = 0;
1384 int is_calendar = 0;
1387 int remaining_messages;
1389 int lowest_displayed = (-1);
1390 int highest_displayed = 0;
1391 long pn_previous = 0L;
1392 long pn_current = 0L;
1395 struct addrbookent *addrbook = NULL;
1397 char *sortby = NULL;
1398 char sortpref_name[128];
1399 char sortpref_value[128];
1400 char *subjsort_button;
1401 char *sendsort_button;
1402 char *datesort_button;
1404 startmsg = atol(bstr("startmsg"));
1405 maxmsgs = atoi(bstr("maxmsgs"));
1406 is_summary = atoi(bstr("summary"));
1407 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1409 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
1410 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
1412 sortby = bstr("sortby");
1413 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
1414 set_preference(sortpref_name, sortby, 1);
1416 if (strlen(sortby) == 0) sortby = sortpref_value;
1417 if (strlen(sortby) == 0) sortby = "msgid";
1419 output_headers(1, 1, 1, 0, 0, 0, 0);
1421 /* When in summary mode, always show ALL messages instead of just
1422 * new or old. Otherwise, show what the user asked for.
1424 if (!strcmp(oper, "readnew")) {
1425 strcpy(cmd, "MSGS NEW");
1427 else if (!strcmp(oper, "readold")) {
1428 strcpy(cmd, "MSGS OLD");
1431 strcpy(cmd, "MSGS ALL");
1434 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
1436 strcpy(cmd, "MSGS ALL");
1439 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
1441 strcpy(cmd, "MSGS ALL");
1446 strcpy(cmd, "MSGS ALL|||1"); /* fetch header summary */
1451 /* Are we doing a summary view? If so, we need to know old messages
1452 * and new messages, so we can do that pretty boldface thing for the
1455 strcpy(old_msgs, "");
1458 serv_getln(buf, sizeof buf);
1459 if (buf[0] == '2') {
1460 strcpy(old_msgs, &buf[4]);
1464 is_singlecard = atoi(bstr("is_singlecard"));
1466 if (WC->wc_view == VIEW_CALENDAR) { /* calendar */
1468 strcpy(cmd, "MSGS ALL");
1471 if (WC->wc_view == VIEW_TASKS) { /* tasks */
1473 strcpy(cmd, "MSGS ALL");
1476 if (WC->wc_view == VIEW_NOTES) { /* notes */
1478 strcpy(cmd, "MSGS ALL");
1482 nummsgs = load_msg_ptrs(cmd, is_summary);
1485 if ((!is_tasks) && (!is_calendar) && (!is_notes)) {
1487 if (!strcmp(oper, "readnew")) {
1488 wprintf(_("No new messages."));
1489 } else if (!strcmp(oper, "readold")) {
1490 wprintf(_("No old messages."));
1492 wprintf(_("No messages here."));
1501 for (a = 0; a < nummsgs; ++a) {
1502 /* Are you a new message, or an old message? */
1504 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
1505 WC->summ[a].is_new = 0;
1508 WC->summ[a].is_new = 1;
1514 if (startmsg == 0L) startmsg = WC->msgarr[0];
1515 remaining_messages = 0;
1517 for (a = 0; a < nummsgs; ++a) {
1518 if (WC->msgarr[a] >= startmsg) {
1519 ++remaining_messages;
1524 if (!strcasecmp(sortby, "subject")) {
1525 qsort(WC->summ, WC->num_summ,
1526 sizeof(struct message_summary), summcmp_subj);
1528 else if (!strcasecmp(sortby, "rsubject")) {
1529 qsort(WC->summ, WC->num_summ,
1530 sizeof(struct message_summary), summcmp_rsubj);
1532 else if (!strcasecmp(sortby, "sender")) {
1533 qsort(WC->summ, WC->num_summ,
1534 sizeof(struct message_summary), summcmp_sender);
1536 else if (!strcasecmp(sortby, "rsender")) {
1537 qsort(WC->summ, WC->num_summ,
1538 sizeof(struct message_summary), summcmp_rsender);
1540 else if (!strcasecmp(sortby, "date")) {
1541 qsort(WC->summ, WC->num_summ,
1542 sizeof(struct message_summary), summcmp_date);
1544 else if (!strcasecmp(sortby, "rdate")) {
1545 qsort(WC->summ, WC->num_summ,
1546 sizeof(struct message_summary), summcmp_rdate);
1550 if (!strcasecmp(sortby, "subject")) {
1551 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1553 else if (!strcasecmp(sortby, "rsubject")) {
1554 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1557 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1560 if (!strcasecmp(sortby, "sender")) {
1561 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1563 else if (!strcasecmp(sortby, "rsender")) {
1564 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1567 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1570 if (!strcasecmp(sortby, "date")) {
1571 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1573 else if (!strcasecmp(sortby, "rdate")) {
1574 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1577 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1581 wprintf("</div>"); /* end of 'content' div */
1583 wprintf("<div id=\"message_list\">"
1585 "<div id=\"fix_scrollbar_bug\">\n"
1587 "<form name=\"msgomatic\" "
1588 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n"
1590 "<table border=0 cellspacing=0 "
1591 "cellpadding=0 width=100%%>\n"
1593 "<TD align=center><b><i>%s</i></b> %s</TD>"
1594 "<TD align=center><b><i>%s</i></b> %s</TD>"
1595 "<TD align=center><b><i>%s</i></b> %s</TD>"
1596 "<TD><INPUT TYPE=\"submit\" NAME=\"delete_button\" "
1597 "STYLE=\"font-family: Bitstream Vera Sans,Arial,Helvetica,sans-serif;"
1598 " font-size: 6pt;\" "
1599 "VALUE=\"%s\"></TD>"
1602 _("Subject"), subjsort_button,
1603 _("Sender"), sendsort_button,
1604 _("Date"), datesort_button,
1609 for (a = 0; a < nummsgs; ++a) {
1610 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
1612 /* Learn which msgs "Prev" & "Next" buttons go to */
1613 pn_current = WC->msgarr[a];
1614 if (a > 0) pn_previous = WC->msgarr[a-1];
1615 if (a < (nummsgs-1)) pn_next = WC->msgarr[a+1];
1617 /* If a tabular view, set up the line */
1620 wprintf("<TR BGCOLOR=\"#%s\">",
1621 (bg ? "DDDDDD" : "FFFFFF")
1625 /* Display the message */
1627 display_summarized(a);
1629 else if (is_addressbook) {
1630 fetch_ab_name(WC->msgarr[a], buf);
1632 addrbook = realloc(addrbook,
1633 (sizeof(struct addrbookent) * num_ab) );
1634 safestrncpy(addrbook[num_ab-1].ab_name, buf,
1635 sizeof(addrbook[num_ab-1].ab_name));
1636 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
1638 else if (is_calendar) {
1639 display_calendar(WC->msgarr[a]);
1641 else if (is_tasks) {
1642 display_task(WC->msgarr[a]);
1644 else if (is_notes) {
1645 display_note(WC->msgarr[a]);
1648 read_message(WC->msgarr[a], 0);
1651 /* If a tabular view, finish the line */
1656 if (lowest_displayed < 0) lowest_displayed = a;
1657 highest_displayed = a;
1660 --remaining_messages;
1665 wprintf("</table></form>"
1666 "</div>\n"); /* end of 'fix_scrollbar_bug' div */
1667 wprintf("</div>"); /* end of 'message_list' div */
1669 wprintf("<div id=\"preview_pane\">"); /* The preview pane will initially be empty */
1672 /* Bump these because although we're thinking in zero base, the user
1673 * is a drooling idiot and is thinking in one base.
1676 ++highest_displayed;
1678 /* If we're only looking at one message, do a prev/next thing */
1679 if (num_displayed == 1) {
1680 if ((!is_tasks) && (!is_calendar) && (!is_addressbook) && (!is_notes) && (!is_singlecard)) {
1682 wprintf("<div id=\"fix_scrollbar_bug\">"
1683 "<table border=0 width=100%% bgcolor=\"#dddddd\"><tr><td>");
1684 wprintf(_("Reading #%d of %d messages."), lowest_displayed, nummsgs);
1685 wprintf("</TD><TD ALIGN=RIGHT><FONT SIZE=+1>");
1687 if (pn_previous > 0L) {
1688 wprintf("<A HREF=\"/%s"
1699 wprintf("<A HREF=\"/%s"
1709 wprintf("<A HREF=\"/%s?startmsg=%ld"
1710 "?maxmsgs=%d?summary=1\">"
1719 wprintf("</td></tr></table></div>\n");
1724 * If we're not currently looking at ALL requested
1725 * messages, then display the selector bar
1727 if (num_displayed > 1) {
1728 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
1729 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
1731 wprintf("<form name=\"msgomatic\" "
1732 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n");
1734 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
1736 wprintf("<select name=\"whichones\" size=\"1\" "
1737 "OnChange=\"location.href=msgomatic.whichones.options"
1738 "[selectedIndex].value\">\n");
1740 for (b=0; b<nummsgs; b = b + maxmsgs) {
1743 if (hi > nummsgs) hi = nummsgs;
1744 wprintf("<option %s value="
1749 "%d-%d</option> \n",
1750 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
1757 wprintf("<option value=\"/%s?startmsg=%ld"
1758 "?maxmsgs=9999999?summary=%d\">"
1762 WC->msgarr[0], is_summary);
1764 wprintf("</select> ");
1765 wprintf(_("of %d messages."), nummsgs);
1766 wprintf("</form>\n");
1772 do_tasks_view(); /* Render the task list */
1776 do_calendar_view(); /* Render the calendar */
1779 if (is_addressbook) {
1780 do_addrbook_view(addrbook, num_ab); /* Render the address book */
1783 /* Put the data transfer hidden iframe in a hidden div, to make it *really* hidden */
1785 "<div display=\"hidden\">\n"
1786 "<iframe name=\"msgloader1\" id=\"msgloader1\" width=\"1\"></iframe>\n"
1789 /* Note: wDumpContent() will output one additional </div> tag. */
1791 if (addrbook != NULL) free(addrbook);
1793 /* free the summary */
1794 if (WC->num_summ != 0) {
1799 /* If we got here via a mailbox view and are reading a single
1800 * message, mark it as "seen." We do this after rendering the web page
1801 * so it doesn't keep the user waiting.
1803 if ( (maxmsgs == 1) && (WC->wc_view == VIEW_MAILBOX) ) {
1804 serv_printf("SEEN %ld|1", startmsg);
1805 serv_getln(buf, sizeof buf);
1811 * Back end for post_message() ... this is where the actual message
1812 * gets transmitted to the server.
1814 void post_mime_to_server(void) {
1816 int is_multipart = 0;
1818 struct wc_attachment *att;
1820 size_t encoded_length;
1822 /* RFC2045 requires this, and some clients look for it... */
1823 serv_puts("MIME-Version: 1.0");
1825 /* If there are attachments, we have to do multipart/mixed */
1826 if (WC->first_attachment != NULL) {
1831 sprintf(boundary, "---Citadel-Multipart-%s-%04x%04x---",
1832 serv_info.serv_fqdn,
1837 /* Remember, serv_printf() appends an extra newline */
1838 serv_printf("Content-type: multipart/mixed; "
1839 "boundary=\"%s\"\n", boundary);
1840 serv_printf("This is a multipart message in MIME format.\n");
1841 serv_printf("--%s", boundary);
1844 serv_puts("Content-type: text/html; charset=utf-8");
1846 serv_puts("<HTML><BODY>\n");
1847 text_to_server(bstr("msgtext"), 0);
1848 serv_puts("</BODY></HTML>\n");
1853 /* Add in the attachments */
1854 for (att = WC->first_attachment; att!=NULL; att=att->next) {
1856 encoded_length = ((att->length * 150) / 100);
1857 encoded = malloc(encoded_length);
1858 if (encoded == NULL) break;
1859 CtdlEncodeBase64(encoded, att->data, att->length);
1861 serv_printf("--%s", boundary);
1862 serv_printf("Content-type: %s", att->content_type);
1863 serv_printf("Content-disposition: attachment; "
1864 "filename=\"%s\"", att->filename);
1865 serv_puts("Content-transfer-encoding: base64");
1867 serv_write(encoded, strlen(encoded));
1872 serv_printf("--%s--", boundary);
1880 * Post message (or don't post message)
1882 * Note regarding the "dont_post" variable:
1883 * A random value (actually, it's just a timestamp) is inserted as a hidden
1884 * field called "postseq" when the display_enter page is generated. This
1885 * value is checked when posting, using the static variable dont_post. If a
1886 * user attempts to post twice using the same dont_post value, the message is
1887 * discarded. This prevents the accidental double-saving of the same message
1888 * if the user happens to click the browser "back" button.
1890 void post_message(void)
1893 static long dont_post = (-1L);
1894 struct wc_attachment *att, *aptr;
1896 if (WC->upload_length > 0) {
1898 /* There's an attachment. Save it to this struct... */
1899 att = malloc(sizeof(struct wc_attachment));
1900 memset(att, 0, sizeof(struct wc_attachment));
1901 att->length = WC->upload_length;
1902 strcpy(att->content_type, WC->upload_content_type);
1903 strcpy(att->filename, WC->upload_filename);
1906 /* And add it to the list. */
1907 if (WC->first_attachment == NULL) {
1908 WC->first_attachment = att;
1911 aptr = WC->first_attachment;
1912 while (aptr->next != NULL) aptr = aptr->next;
1916 /* Netscape sends a simple filename, which is what we want,
1917 * but Satan's browser sends an entire pathname. Reduce
1918 * the path to just a filename if we need to.
1920 while (num_tokens(att->filename, '/') > 1) {
1921 remove_token(att->filename, 0, '/');
1923 while (num_tokens(att->filename, '\\') > 1) {
1924 remove_token(att->filename, 0, '\\');
1927 /* Transfer control of this memory from the upload struct
1928 * to the attachment struct.
1930 att->data = WC->upload;
1931 WC->upload_length = 0;
1937 if (strlen(bstr("cancel_button")) > 0) {
1938 sprintf(WC->ImportantMessage,
1939 _("Cancelled. Message was not posted."));
1940 } else if (strlen(bstr("attach_button")) > 0) {
1943 } else if (atol(bstr("postseq")) == dont_post) {
1944 sprintf(WC->ImportantMessage,
1945 _("Automatically cancelled because you have already "
1946 "saved this message."));
1948 sprintf(buf, "ENT0 1|%s|0|4|%s",
1952 serv_getln(buf, sizeof buf);
1953 if (buf[0] == '4') {
1954 post_mime_to_server();
1955 if (strlen(bstr("recp")) > 0) {
1956 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
1959 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
1961 dont_post = atol(bstr("postseq"));
1963 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1969 free_attachments(WC);
1970 readloop("readnew");
1977 * display the message entry screen
1979 void display_enter(void)
1983 struct wc_attachment *att;
1984 int recipient_required = 0;
1985 int recipient_bad = 0;
1987 if (strlen(bstr("force_room")) > 0) {
1988 gotoroom(bstr("force_room"));
1991 /* Are we perhaps in an address book view? If so, then an "enter
1992 * message" command really means "add new entry."
1994 if (WC->wc_view == VIEW_ADDRESSBOOK) {
1995 do_edit_vcard(-1, "", "");
1999 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
2000 /* Are we perhaps in a calendar view? If so, then an "enter
2001 * message" command really means "add new calendar item."
2003 if (WC->wc_view == VIEW_CALENDAR) {
2004 display_edit_event();
2008 /* Are we perhaps in a tasks view? If so, then an "enter
2009 * message" command really means "add new task."
2011 if (WC->wc_view == VIEW_TASKS) {
2012 display_edit_task();
2018 * Otherwise proceed normally.
2019 ` * Do a custom room banner with no navbar...
2021 output_headers(1, 1, 2, 0, 0, 0, 0);
2022 wprintf("<div id=\"banner\">\n");
2023 embed_room_banner(NULL, navbar_none);
2024 wprintf("</div>\n");
2025 wprintf("<div id=\"content\">\n"
2026 "<div id=\"fix_scrollbar_bug\">"
2027 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
2029 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
2031 serv_getln(buf, sizeof buf);
2033 if (!strncmp(buf, "570", 3)) {
2034 recipient_required = 1;
2035 if (strlen(bstr("recp")) > 0) {
2039 else if (buf[0] != '2') {
2040 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2045 fmt_date(buf, now, 0);
2046 strcat(&buf[strlen(buf)], _(" <I>from</I> "));
2047 stresc(&buf[strlen(buf)], WC->wc_username, 1, 1);
2048 if (strlen(bstr("recp")) > 0) {
2049 strcat(&buf[strlen(buf)], _(" <I>to</I> "));
2050 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
2052 strcat(&buf[strlen(buf)], _(" <I>in</I> "));
2053 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
2055 /* begin message entry screen */
2059 "<style> div.auto_complete { width: 350px; background: #fff; } div.auto_complete ul { border:1px solid #888; margin:0; padding:0; width:100%; list-style-type:none; } div.auto_complete ul li { margin:0; padding:3px; } div.auto_complete ul li.selected { background-color: #ffb; } div.auto_complete ul strong.highlight { color: #800; margin:0; padding:0; } </style> \n "
2062 wprintf("<form enctype=\"multipart/form-data\" "
2063 "method=\"POST\" action=\"/post\" "
2064 "name=\"enterform\""
2065 "onSubmit=\"return submitForm();\""
2067 wprintf("<input type=\"hidden\" name=\"recp\" value=\"%s\">\n",
2069 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n",
2072 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2073 wprintf("%s<br>\n", buf); /* header bar */
2075 wprintf("<table border=\"0\" width=\"100%%\">\n");
2076 if (recipient_required) {
2077 wprintf("<tr><td>");
2078 wprintf("<font size=-1>");
2082 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_name\" value=\"");
2083 escputs(bstr("recp"));
2084 wprintf("\" size=50 maxlength=70>");
2086 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
2088 wprintf("<script type=\"text/javascript\"> "
2089 " new Ajax.Autocompleter('recp_name', 'recp_name_choices', "
2090 " '/recp_autocomplete', {} ); "
2094 wprintf("</td><td></td></tr>\n");
2097 wprintf("<tr><td>");
2098 wprintf("<font size=-1>");
2099 wprintf(_("Subject (optional):"));
2102 "<input type=\"text\" name=\"subject\" value=\"");
2103 escputs(bstr("subject"));
2104 wprintf("\" size=50 maxlength=70></td><td>\n");
2106 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2107 if (recipient_required) {
2108 wprintf(_("Send message"));
2110 wprintf(_("Post message"));
2113 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2114 wprintf("</td></tr></table>\n");
2116 wprintf("<center><script type=\"text/javascript\" "
2117 "src=\"static/richtext.js\"></script>\n"
2118 "<script type=\"text/javascript\">\n"
2119 "function submitForm() { \n"
2120 " updateRTE('msgtext'); \n"
2124 "initRTE(\"static/\", \"static/\", \"\"); \n"
2126 "<noscript>JavaScript must be enabled.</noscript> \n"
2127 "<script type=\"text/javascript\"> \n"
2128 "writeRichText('msgtext', '");
2129 msgescputs(bstr("msgtext"));
2130 wprintf("', '96%%', '200', true, false); \n"
2131 "</script></center><br />\n");
2133 /* Enumerate any attachments which are already in place... */
2134 wprintf("<img src=\"/static/diskette_24x.gif\" border=0 "
2135 "align=middle height=16 width=16> Attachments: ");
2136 wprintf("<select name=\"which_attachment\" size=1>");
2137 for (att = WC->first_attachment; att != NULL; att = att->next) {
2138 wprintf("<option value=\"");
2139 urlescputs(att->filename);
2141 escputs(att->filename);
2142 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
2143 wprintf("</option>\n");
2145 wprintf("</select>");
2147 /* Now offer the ability to attach additional files... */
2148 wprintf(" "
2149 "Attach file: <input NAME=\"attachfile\" "
2150 "SIZE=16 TYPE=\"file\">\n "
2151 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
2153 wprintf("</form>\n");
2155 wprintf("</td></tr></table></div>\n");
2156 DONE: wDumpContent(1);
2166 void delete_msg(void)
2171 msgid = atol(bstr("msgid"));
2173 output_headers(1, 1, 1, 0, 0, 0, 0);
2175 sprintf(buf, "DELE %ld", msgid);
2177 serv_getln(buf, sizeof buf);
2178 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2187 * Confirm move of a message
2189 void confirm_move_msg(void)
2195 msgid = atol(bstr("msgid"));
2197 output_headers(1, 1, 1, 0, 0, 0, 0);
2199 wprintf("<div id=\"fix_scrollbar_bug\">"
2200 "<table width=100%% border=0 bgcolor=\"#444455\"><tr><td>");
2201 wprintf("<font size=+1 color=\"#ffffff\"");
2203 wprintf(_("Confirm move of message"));
2205 wprintf("</font></td></tr></table></div>\n");
2207 wprintf("<CENTER>");
2209 wprintf(_("Move this message to:"));
2210 wprintf("<br />\n");
2212 wprintf("<form METHOD=\"POST\" ACTION=\"/move_msg\">\n");
2213 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
2217 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
2219 serv_getln(buf, sizeof buf);
2220 if (buf[0] == '1') {
2221 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2222 extract_token(targ, buf, 0, '|', sizeof targ);
2223 wprintf("<OPTION>");
2228 wprintf("</SELECT>\n");
2229 wprintf("<br />\n");
2231 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
2233 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
2234 wprintf("</form></CENTER>\n");
2236 wprintf("</CENTER>\n");
2247 msgid = atol(bstr("msgid"));
2249 output_headers(1, 1, 1, 0, 0, 0, 0);
2251 if (strlen(bstr("move_button")) > 0) {
2252 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
2254 serv_getln(buf, sizeof buf);
2255 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2258 wprintf(_("The message was not moved."));
2259 wprintf("</EM><br />\n");
2266 * This gets called when a user selects multiple messages in a summary
2267 * list and then clicks to perform a transformation of some sort on them
2268 * (such as deleting them).
2270 void do_stuff_to_msgs(void) {
2274 struct stuff_t *next;
2278 struct stuff_t *stuff = NULL;
2279 struct stuff_t *ptr;
2280 int delete_button_pressed = 0;
2283 serv_puts("MSGS ALL");
2284 serv_getln(buf, sizeof buf);
2286 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2287 ptr = malloc(sizeof(struct stuff_t));
2288 ptr->msgnum = atol(buf);
2293 if (strlen(bstr("delete_button")) > 0) {
2294 delete_button_pressed = 1;
2297 while (stuff != NULL) {
2299 sprintf(buf, "msg_%ld", stuff->msgnum);
2300 if (!strcasecmp(bstr(buf), "yes")) {
2302 if (delete_button_pressed) {
2303 serv_printf("DELE %ld", stuff->msgnum);
2304 serv_getln(buf, sizeof buf);
2314 readloop("readfwd");