4 * Functions which deal with the fetching and displaying of messages.
14 #include <sys/types.h>
16 #include <sys/socket.h>
18 #include <netinet/in.h>
33 #include "webserver.h"
36 /* Address book entry (keep it short and sweet, it's just a quickie lookup
37 * which we can use to get to the real meat and bones later)
47 /* Handle subjects with RFC2047 encoding, such as:
48 * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=
50 void utf8ify_rfc822_string(char *buf) {
56 iconv_t ic = (iconv_t)(-1) ;
57 char *ibuf; /* Buffer of characters to be converted */
58 char *obuf; /* Buffer for converted characters */
59 size_t ibuflen; /* Length of input buffer */
60 size_t obuflen; /* Length of output buffer */
61 char *isav; /* Saved pointer to input buffer */
62 char *osav; /* Saved pointer to output buffer */
64 while (start=strstr(buf, "=?"), end=strstr(buf, "?="),
65 ((start != NULL) && (end != NULL) && (end > start)) )
67 extract_token(charset, start, 1, '?', sizeof charset);
68 extract_token(encoding, start, 2, '?', sizeof encoding);
69 extract_token(istr, start, 3, '?', sizeof istr);
77 if (!strcasecmp(encoding, "B")) { /* base64 */
78 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
80 else if (!strcasecmp(encoding, "Q")) { /* quoted-printable */
81 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, strlen(istr));
84 strcpy(ibuf, istr); /* huh? */
85 ibuflen = strlen(istr);
88 ic = iconv_open("UTF-8", charset);
89 if (ic != (iconv_t)(-1) ) {
92 obuf = (char *) malloc(obuflen);
94 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
95 osav[1024-obuflen] = 0;
96 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
102 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
114 * Look for URL's embedded in a buffer and make them linkable. We use a
115 * target window in order to keep the BBS session in its own window.
131 for (pos = 0; pos < strlen(buf); ++pos) {
132 if (!strncasecmp(&buf[pos], "http://", 7))
134 if (!strncasecmp(&buf[pos], "ftp://", 6))
141 if ((start > 0) && (buf[start - 1] == '<'))
143 if ((start > 0) && (buf[start - 1] == '['))
145 if ((start > 0) && (buf[start - 1] == '('))
147 if ((start > 0) && (buf[start - 1] == '{'))
150 for (pos = strlen(buf); pos > start; --pos) {
151 if ((buf[pos] == ' ') || (buf[pos] == ench))
155 strncpy(urlbuf, &buf[start], end - start);
156 urlbuf[end - start] = 0;
158 strncpy(outbuf, buf, start);
159 sprintf(&outbuf[start], "%cA HREF=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
160 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
161 strcat(outbuf, &buf[end]);
162 if ( strlen(outbuf) < 250 )
168 * Turn a vCard "n" (name) field into something displayable.
170 void vcard_n_prettyize(char *name)
175 original_name = strdup(name);
176 for (i=0; i<5; ++i) {
177 if (strlen(original_name) > 0) {
178 if (original_name[strlen(original_name)-1] == ' ') {
179 original_name[strlen(original_name)-1] = 0;
181 if (original_name[strlen(original_name)-1] == ';') {
182 original_name[strlen(original_name)-1] = 0;
187 for (i=0; i<strlen(original_name); ++i) {
188 if (original_name[i] == ';') {
192 name[strlen(name)+1] = 0;
193 name[strlen(name)] = original_name[i];
202 /* display_vcard() calls this after parsing the textual vCard into
203 * our 'struct vCard' data object.
204 * This gets called instead of display_parsed_vcard() if we are only looking
205 * to extract the person's name instead of displaying the card.
207 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
210 strcpy(storename, "");
212 name = vcard_get_prop(v, "n", 1, 0, 0);
214 strcpy(storename, name);
215 /* vcard_n_prettyize(storename); */
222 /* display_vcard() calls this after parsing the textual vCard into
223 * our 'struct vCard' data object.
225 * Set 'full' to nonzero to display the full card, otherwise it will only
226 * show a summary line.
228 * This code is a bit ugly, so perhaps an explanation is due: we do this
229 * in two passes through the vCard fields. On the first pass, we process
230 * fields we understand, and then render them in a pretty fashion at the
231 * end. Then we make a second pass, outputting all the fields we don't
232 * understand in a simple two-column name/value format.
234 void display_parsed_vcard(struct vCard *v, int full) {
240 char *thisname, *thisvalue;
241 char firsttoken[SIZ];
244 char displayname[SIZ];
250 strcpy(displayname, "");
258 name = vcard_get_prop(v, "fn", 1, 0, 0);
262 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
263 strcpy(displayname, name);
264 vcard_n_prettyize(displayname);
265 escputs(displayname);
274 wprintf("<div align=center><table bgcolor=#aaaaaa width=50%%>");
275 for (pass=1; pass<=2; ++pass) {
277 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
279 thisname = strdup(v->prop[i].name);
280 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
282 for (j=0; j<num_tokens(thisname, ';'); ++j) {
283 extract_token(buf, thisname, j, ';', sizeof buf);
284 if (!strcasecmp(buf, "encoding=quoted-printable")) {
286 remove_token(thisname, j, ';');
288 if (!strcasecmp(buf, "encoding=base64")) {
290 remove_token(thisname, j, ';');
295 thisvalue = malloc(strlen(v->prop[i].value) + 50);
296 j = CtdlDecodeQuotedPrintable(
297 thisvalue, v->prop[i].value,
298 strlen(v->prop[i].value) );
302 thisvalue = malloc(strlen(v->prop[i].value) + 50);
304 thisvalue, v->prop[i].value,
305 strlen(v->prop[i].value) );
308 thisvalue = strdup(v->prop[i].value);
311 /*** Various fields we may encounter ***/
313 /* N is name, but only if there's no FN already there */
314 if (!strcasecmp(firsttoken, "n")) {
315 if (strlen(displayname) == 0) {
316 strcpy(displayname, thisvalue);
317 vcard_n_prettyize(displayname);
321 /* FN (full name) is a true 'display name' field */
322 else if (!strcasecmp(firsttoken, "fn")) {
323 strcpy(displayname, thisvalue);
327 else if (!strcasecmp(firsttoken, "title")) {
328 strcpy(title, thisvalue);
332 else if (!strcasecmp(firsttoken, "org")) {
333 strcpy(org, thisvalue);
336 else if (!strcasecmp(firsttoken, "email")) {
337 if (strlen(mailto) > 0) strcat(mailto, "<br />");
339 "<A HREF=\"/display_enter"
340 "?force_room=_MAIL_&recp=");
341 urlesc(&mailto[strlen(mailto)], thisvalue);
342 strcat(mailto, "\">");
343 urlesc(&mailto[strlen(mailto)], thisvalue);
344 strcat(mailto, "</A>");
346 else if (!strcasecmp(firsttoken, "tel")) {
347 if (strlen(phone) > 0) strcat(phone, "<br />");
348 strcat(phone, thisvalue);
349 for (j=0; j<num_tokens(thisname, ';'); ++j) {
350 extract_token(buf, thisname, j, ';', sizeof buf);
351 if (!strcasecmp(buf, "tel"))
353 else if (!strcasecmp(buf, "work"))
354 strcat(phone, " (work)");
355 else if (!strcasecmp(buf, "home"))
356 strcat(phone, " (home)");
357 else if (!strcasecmp(buf, "cell"))
358 strcat(phone, " (cell)");
366 else if (!strcasecmp(firsttoken, "adr")) {
368 wprintf("<TR><TD>Address:</TD><TD>");
369 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
370 extract_token(buf, thisvalue, j, ';', sizeof buf);
371 if (strlen(buf) > 0) {
373 if (j<3) wprintf("<br />");
377 wprintf("</TD></TR>\n");
380 else if (!strcasecmp(firsttoken, "version")) {
383 else if (!strcasecmp(firsttoken, "rev")) {
386 else if (!strcasecmp(firsttoken, "label")) {
391 /*** Don't show extra fields. They're ugly.
395 wprintf("</TD><TD>");
397 wprintf("</TD></TR>\n");
407 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
408 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
409 "<IMG ALIGN=CENTER SRC=\"/static/viewcontacts_48x.gif\">"
410 "<FONT SIZE=+1><B>");
411 escputs(displayname);
412 wprintf("</B></FONT>");
413 if (strlen(title) > 0) {
414 wprintf("<div align=right>");
418 if (strlen(org) > 0) {
419 wprintf("<div align=right>");
423 wprintf("</TD></TR>\n");
425 if (strlen(phone) > 0)
426 wprintf("<TR><TD>Telephone:</TD><TD>%s</TD></TR>\n", phone);
427 if (strlen(mailto) > 0)
428 wprintf("<TR><TD>E-mail:</TD><TD>%s</TD></TR>\n", mailto);
433 wprintf("</table></div>\n");
439 * Display a textual vCard
440 * (Converts to a vCard object and then calls the actual display function)
441 * Set 'full' to nonzero to display the whole card instead of a one-liner.
442 * Or, if "storename" is non-NULL, just store the person's name in that
443 * buffer instead of displaying the card at all.
445 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
451 v = vcard_load(vcard_source);
452 if (v == NULL) return;
454 name = vcard_get_prop(v, "n", 1, 0, 0);
460 if (storename != NULL) {
461 fetchname_parsed_vcard(v, storename);
463 else if ( (alpha == 0)
464 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
465 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
467 display_parsed_vcard(v, full);
477 * I wanna SEE that message!
479 void read_message(long msgnum) {
481 char mime_partnum[256];
482 char mime_filename[256];
483 char mime_content_type[256];
484 char mime_charset[256];
485 char mime_disposition[256];
498 char vcard_partnum[256];
499 char cal_partnum[256];
500 char *part_source = NULL;
502 iconv_t ic = (iconv_t)(-1) ;
503 char *ibuf; /* Buffer of characters to be converted */
504 char *obuf; /* Buffer for converted characters */
505 size_t ibuflen; /* Length of input buffer */
506 size_t obuflen; /* Length of output buffer */
507 char *osav; /* Saved pointer to output buffer */
513 strcpy(reply_to, "");
514 strcpy(vcard_partnum, "");
515 strcpy(cal_partnum, "");
516 strcpy(mime_http, "");
517 strcpy(mime_content_type, "text/plain");
518 strcpy(mime_charset, "us-ascii");
520 serv_printf("MSG4 %ld", msgnum);
521 serv_getln(buf, sizeof buf);
523 wprintf("<STRONG>ERROR:</STRONG> %s<br />\n", &buf[4]);
527 /* begin everythingamundo table */
528 wprintf("<div id=\"fix_scrollbar_bug\">\n");
529 wprintf("<table width=100%% border=1 cellspacing=0 "
530 "cellpadding=0><TR><TD>\n");
532 /* begin message header table */
533 wprintf("<TABLE WIDTH=100%% BORDER=0 CELLSPACING=0 "
534 "CELLPADDING=1 BGCOLOR=\"#CCCCCC\"><TR><TD>\n");
536 wprintf("<SPAN CLASS=\"message_header\">");
537 strcpy(m_subject, "");
539 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
540 if (!strcmp(buf, "000")) {
541 wprintf("<I>unexpected end of message</I><br /><br />\n");
542 wprintf("</SPAN>\n");
545 if (!strncasecmp(buf, "nhdr=yes", 8))
549 if (!strncasecmp(buf, "type=", 5))
550 format_type = atoi(&buf[5]);
551 if (!strncasecmp(buf, "from=", 5)) {
552 strcpy(from, &buf[5]);
553 wprintf("from <A HREF=\"/showuser&who=");
555 utf8ify_rfc822_string(from);
562 if (!strncasecmp(buf, "subj=", 5))
563 strcpy(m_subject, &buf[5]);
564 if ((!strncasecmp(buf, "hnod=", 5))
565 && (strcasecmp(&buf[5], serv_info.serv_humannode)))
566 wprintf("(%s) ", &buf[5]);
567 if ((!strncasecmp(buf, "room=", 5))
568 && (strcasecmp(&buf[5], WC->wc_roomname))
569 && (strlen(&buf[5])>0) )
570 wprintf("in %s> ", &buf[5]);
571 if (!strncasecmp(buf, "rfca=", 5)) {
572 strcpy(rfca, &buf[5]);
578 if (!strncasecmp(buf, "node=", 5)) {
579 strcpy(node, &buf[5]);
580 if ( ((WC->room_flags & QR_NETWORK)
581 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
582 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
585 wprintf("@%s ", &buf[5]);
588 if (!strncasecmp(buf, "rcpt=", 5))
589 wprintf("to %s ", &buf[5]);
590 if (!strncasecmp(buf, "time=", 5)) {
591 fmt_date(now, atol(&buf[5]), 0);
595 if (!strncasecmp(buf, "part=", 5)) {
596 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
597 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
598 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
599 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
600 mime_length = extract_int(&buf[5], 5);
602 if (!strcasecmp(mime_disposition, "attachment")) {
603 snprintf(&mime_http[strlen(mime_http)],
604 (sizeof(mime_http) - strlen(mime_http) - 1),
605 "<A HREF=\"/output_mimepart?"
606 "msgnum=%ld&partnum=%s\" "
607 "TARGET=\"wc.%ld.%s\">"
608 "<IMG SRC=\"/static/diskette_24x.gif\" "
609 "BORDER=0 ALIGN=MIDDLE>\n"
610 "Part %s: %s (%s, %d bytes)</A><br />\n",
611 msgnum, mime_partnum,
612 msgnum, mime_partnum,
613 mime_partnum, mime_filename,
614 mime_content_type, mime_length);
617 if ((!strcasecmp(mime_disposition, "inline"))
618 && (!strncasecmp(mime_content_type, "image/", 6)) ){
619 snprintf(&mime_http[strlen(mime_http)],
620 (sizeof(mime_http) - strlen(mime_http) - 1),
621 "<IMG SRC=\"/output_mimepart?"
622 "msgnum=%ld&partnum=%s\">",
623 msgnum, mime_partnum);
626 /*** begin handler prep ***/
627 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
628 strcpy(vcard_partnum, mime_partnum);
631 if (!strcasecmp(mime_content_type, "text/calendar")) {
632 strcpy(cal_partnum, mime_partnum);
635 /*** end handler prep ***/
641 /* Generate a reply-to address */
642 if (strlen(rfca) > 0) {
643 strcpy(reply_to, rfca);
646 if ( (strlen(node) > 0)
647 && (strcasecmp(node, serv_info.serv_nodename))
648 && (strcasecmp(node, serv_info.serv_humannode)) ) {
649 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
653 snprintf(reply_to, sizeof(reply_to), "%s", from);
663 utf8ify_rfc822_string(m_subject);
665 if (strlen(m_subject) > 0) {
667 "<SPAN CLASS=\"message_subject\">"
674 /* start msg buttons */
675 wprintf("<TD ALIGN=RIGHT>\n");
678 wprintf("<a href=\"/display_enter?recp=");
679 urlescputs(reply_to);
680 wprintf("&subject=");
681 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
682 urlescputs(m_subject);
683 wprintf("\">[Reply]</a> ");
685 if (WC->is_room_aide) {
688 wprintf("<a href=\"/confirm_move_msg?msgid=%ld\">[Move]</a> ",
692 wprintf("<a href=\"/delete_msg?msgid=%ld\" "
693 "onClick=\"return confirm('Delete this message?');\">"
694 "[Delete]</a>", msgnum);
698 wprintf("</TD></TR></TABLE>\n");
701 wprintf("<TABLE BORDER=0 WIDTH=100%% BGCOLOR=#FFFFFF "
702 "CELLPADDING=1 CELLSPACING=0><TR><TD>");
705 * Learn the content type
707 strcpy(mime_content_type, "text/plain");
708 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
709 if (!strcmp(buf, "000")) {
710 wprintf("<I>unexpected end of message</I><br /><br />\n");
713 if (!strncasecmp(buf, "Content-type: ", 14)) {
714 safestrncpy(mime_content_type, &buf[14],
715 sizeof(mime_content_type));
716 for (i=0; i<strlen(mime_content_type); ++i) {
717 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
718 safestrncpy(mime_charset, &mime_content_type[i+8],
719 sizeof mime_charset);
722 for (i=0; i<strlen(mime_content_type); ++i) {
723 if (mime_content_type[i] == ';') {
724 mime_content_type[i] = 0;
730 /* Set up a character set conversion if we need to (and if we can) */
732 if ( (strcasecmp(mime_charset, "us-ascii"))
733 && (strcasecmp(mime_charset, "UTF-8")) ) {
734 ic = iconv_open("UTF-8", mime_charset);
735 if (ic == (iconv_t)(-1) ) {
736 lprintf(5, "iconv_open() failed: %s\n", strerror(errno));
741 /* Messages in legacy Citadel variformat get handled thusly... */
742 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
743 fmout(NULL, "JUSTIFY");
746 /* Boring old 80-column fixed format text gets handled this way... */
747 else if (!strcasecmp(mime_content_type, "text/plain")) {
748 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
749 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
750 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
753 if (ic != (iconv_t)(-1) ) {
755 ibuflen = strlen(ibuf);
757 obuf = (char *) malloc(obuflen);
759 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
760 osav[SIZ-obuflen] = 0;
761 safestrncpy(buf, osav, sizeof buf);
766 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
767 buf[strlen(buf) - 1] = 0;
769 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
770 wprintf("<BLOCKQUOTE>");
772 } else if ((bq == 1) &&
773 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
774 wprintf("</BLOCKQUOTE>");
780 wprintf("</TT><br />\n");
782 wprintf("</I><br />");
785 else /* HTML is fun, but we've got to strip it first */
786 if (!strcasecmp(mime_content_type, "text/html")) {
787 output_html(mime_charset);
790 /* Unknown weirdness */
792 wprintf("I don't know how to display %s<br />\n",
794 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
797 /* Afterwards, offer links to download attachments 'n' such */
798 if (strlen(mime_http) > 0) {
799 wprintf("%s", mime_http);
802 /* Handler for vCard parts */
803 if (strlen(vcard_partnum) > 0) {
804 part_source = load_mimepart(msgnum, vcard_partnum);
805 if (part_source != NULL) {
807 /* If it's my vCard I can edit it */
808 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
809 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
810 || (WC->wc_view == VIEW_ADDRESSBOOK)
812 wprintf("<A HREF=\"/edit_vcard?"
813 "msgnum=%ld&partnum=%s\">",
814 msgnum, vcard_partnum);
815 wprintf("[edit]</A>");
818 /* In all cases, display the full card */
819 display_vcard(part_source, 0, 1, NULL);
823 /* Handler for calendar parts */
824 if (strlen(cal_partnum) > 0) {
825 part_source = load_mimepart(msgnum, cal_partnum);
826 if (part_source != NULL) {
827 cal_process_attachment(part_source,
828 msgnum, cal_partnum);
838 wprintf("</TD></TR></TABLE>\n");
840 /* end everythingamundo table */
841 wprintf("</TD></TR></TABLE>\n");
842 wprintf("</div><br />\n");
845 if (ic != (iconv_t)(-1) ) {
852 void display_summarized(int num) {
856 if (WC->summ[num].is_new) wprintf("<B>");
857 wprintf("<A HREF=\"/readfwd?startmsg=%ld"
858 "&maxmsgs=1&summary=0\">",
860 escputs(WC->summ[num].subj);
862 if (WC->summ[num].is_new) wprintf("</B>");
863 wprintf("</TD><TD>");
864 if (WC->summ[num].is_new) wprintf("<B>");
865 escputs(WC->summ[num].from);
866 if (WC->summ[num].is_new) wprintf("</B>");
867 wprintf(" </TD><TD>");
868 if (WC->summ[num].is_new) wprintf("<B>");
869 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
871 if (WC->summ[num].is_new) wprintf("</B>");
874 "<INPUT TYPE=\"checkbox\" NAME=\"msg_%ld\" VALUE=\"yes\">"
880 void summarize_message(int num, long msgnum, int is_new) {
883 memset(&WC->summ[num], 0, sizeof(struct message_summary));
884 safestrncpy(WC->summ[num].subj, "(no subject)", sizeof WC->summ[num].subj);
885 WC->summ[num].is_new = is_new;
886 WC->summ[num].msgnum = msgnum;
888 /* ask for headers only with no MIME */
889 sprintf(buf, "MSG0 %ld|3", msgnum);
891 serv_getln(buf, sizeof buf);
892 if (buf[0] != '1') return;
894 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
895 if (!strncasecmp(buf, "from=", 5)) {
896 safestrncpy(WC->summ[num].from, &buf[5], sizeof WC->summ[num].from);
898 if (!strncasecmp(buf, "subj=", 5)) {
899 if (strlen(&buf[5]) > 0) {
900 safestrncpy(WC->summ[num].subj, &buf[5],
901 sizeof WC->summ[num].subj);
903 /* Handle subjects with RFC2047 encoding */
904 utf8ify_rfc822_string(WC->summ[num].subj);
906 if (strlen(WC->summ[num].subj) > 75) {
907 strcpy(&WC->summ[num].subj[72], "...");
912 if (!strncasecmp(buf, "node=", 5)) {
913 if ( ((WC->room_flags & QR_NETWORK)
914 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
915 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
917 strcat(WC->summ[num].from, " @ ");
918 strcat(WC->summ[num].from, &buf[5]);
922 if (!strncasecmp(buf, "rcpt=", 5)) {
923 safestrncpy(WC->summ[num].to, &buf[5], sizeof WC->summ[num].to);
926 if (!strncasecmp(buf, "time=", 5)) {
927 WC->summ[num].date = atol(&buf[5]);
932 /* Handle senders with RFC2047 encoding */
933 utf8ify_rfc822_string(WC->summ[num].from);
935 if (strlen(WC->summ[num].from) > 25) {
936 strcpy(&WC->summ[num].from[22], "...");
942 void display_addressbook(long msgnum, char alpha) {
944 char mime_partnum[SIZ];
945 char mime_filename[SIZ];
946 char mime_content_type[SIZ];
947 char mime_disposition[SIZ];
949 char vcard_partnum[SIZ];
950 char *vcard_source = NULL;
951 struct message_summary summ;
953 memset(&summ, 0, sizeof(summ));
954 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
956 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
958 serv_getln(buf, sizeof buf);
959 if (buf[0] != '1') return;
961 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
962 if (!strncasecmp(buf, "part=", 5)) {
963 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
964 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
965 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
966 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
967 mime_length = extract_int(&buf[5], 5);
969 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
970 strcpy(vcard_partnum, mime_partnum);
976 if (strlen(vcard_partnum) > 0) {
977 vcard_source = load_mimepart(msgnum, vcard_partnum);
978 if (vcard_source != NULL) {
980 /* Display the summary line */
981 display_vcard(vcard_source, alpha, 0, NULL);
983 /* If it's my vCard I can edit it */
984 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
985 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
986 || (WC->wc_view == VIEW_ADDRESSBOOK)
988 wprintf("<A HREF=\"/edit_vcard?"
989 "msgnum=%ld&partnum=%s\">",
990 msgnum, vcard_partnum);
991 wprintf("[edit]</A>");
1002 /* If it's an old "Firstname Lastname" style record, try to
1005 void lastfirst_firstlast(char *namebuf) {
1006 char firstname[SIZ];
1010 if (namebuf == NULL) return;
1011 if (strchr(namebuf, ';') != NULL) return;
1013 i = num_tokens(namebuf, ' ');
1016 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1017 remove_token(namebuf, i-1, ' ');
1018 strcpy(firstname, namebuf);
1019 sprintf(namebuf, "%s; %s", lastname, firstname);
1023 void fetch_ab_name(long msgnum, char *namebuf) {
1025 char mime_partnum[SIZ];
1026 char mime_filename[SIZ];
1027 char mime_content_type[SIZ];
1028 char mime_disposition[SIZ];
1030 char vcard_partnum[SIZ];
1031 char *vcard_source = NULL;
1033 struct message_summary summ;
1035 if (namebuf == NULL) return;
1036 strcpy(namebuf, "");
1038 memset(&summ, 0, sizeof(summ));
1039 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1041 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1043 serv_getln(buf, sizeof buf);
1044 if (buf[0] != '1') return;
1046 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1047 if (!strncasecmp(buf, "part=", 5)) {
1048 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1049 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1050 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1051 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1052 mime_length = extract_int(&buf[5], 5);
1054 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1055 strcpy(vcard_partnum, mime_partnum);
1061 if (strlen(vcard_partnum) > 0) {
1062 vcard_source = load_mimepart(msgnum, vcard_partnum);
1063 if (vcard_source != NULL) {
1065 /* Grab the name off the card */
1066 display_vcard(vcard_source, 0, 0, namebuf);
1072 lastfirst_firstlast(namebuf);
1074 for (i=0; i<strlen(namebuf); ++i) {
1075 if (namebuf[i] != ';') return;
1077 strcpy(namebuf, "(no name)");
1083 * Record compare function for sorting address book indices
1085 int abcmp(const void *ab1, const void *ab2) {
1087 (((const struct addrbookent *)ab1)->ab_name),
1088 (((const struct addrbookent *)ab2)->ab_name)
1094 * Helper function for do_addrbook_view()
1095 * Converts a name into a three-letter tab label
1097 void nametab(char *tabbuf, char *name) {
1098 stresc(tabbuf, name, 0, 0);
1099 tabbuf[0] = toupper(tabbuf[0]);
1100 tabbuf[1] = tolower(tabbuf[1]);
1101 tabbuf[2] = tolower(tabbuf[2]);
1107 * Render the address book using info we gathered during the scan
1109 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1113 static int NAMESPERPAGE = 60;
1117 char tabfirst_label[SIZ];
1119 char tablast_label[SIZ];
1122 wprintf("<I>This address book is empty.</I>\n");
1127 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1130 num_pages = num_ab / NAMESPERPAGE;
1132 page = atoi(bstr("page"));
1135 for (i=0; i<=num_pages; ++i) {
1137 wprintf("<A HREF=\"/readfwd?page=%d\">", i);
1142 tabfirst = i * NAMESPERPAGE;
1143 tablast = tabfirst + NAMESPERPAGE - 1;
1144 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1145 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1146 nametab(tablast_label, addrbook[tablast].ab_name);
1147 wprintf("[%s - %s]",
1148 tabfirst_label, tablast_label
1157 wprintf("<br />\n");
1159 wprintf("<TABLE border=0 cellspacing=0 "
1160 "cellpadding=3 width=100%%>\n"
1163 for (i=0; i<num_ab; ++i) {
1165 if ((i / NAMESPERPAGE) == page) {
1167 if ((displayed % 4) == 0) {
1168 if (displayed > 0) {
1172 wprintf("<TR BGCOLOR=\"#%s\">",
1173 (bg ? "DDDDDD" : "FFFFFF")
1179 wprintf("<A HREF=\"/readfwd?startmsg=%ld&is_singlecard=1",
1180 addrbook[i].ab_msgnum);
1181 wprintf("&maxmsgs=1&summary=0&alpha=%s\">", bstr("alpha"));
1182 vcard_n_prettyize(addrbook[i].ab_name);
1183 escputs(addrbook[i].ab_name);
1184 wprintf("</A></TD>\n");
1189 wprintf("</TR></TABLE>\n");
1195 * load message pointers from the server
1197 int load_msg_ptrs(char *servcmd)
1204 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1206 serv_getln(buf, sizeof buf);
1207 if (buf[0] != '1') {
1208 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1211 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1212 if (nummsgs < maxload) {
1213 WC->msgarr[nummsgs] = atol(buf);
1221 int summcmp_subj(const void *s1, const void *s2) {
1222 struct message_summary *summ1;
1223 struct message_summary *summ2;
1225 summ1 = (struct message_summary *)s1;
1226 summ2 = (struct message_summary *)s2;
1227 return strcasecmp(summ1->subj, summ2->subj);
1230 int summcmp_sender(const void *s1, const void *s2) {
1231 struct message_summary *summ1;
1232 struct message_summary *summ2;
1234 summ1 = (struct message_summary *)s1;
1235 summ2 = (struct message_summary *)s2;
1236 return strcasecmp(summ1->from, summ2->from);
1239 int summcmp_date(const void *s1, const void *s2) {
1240 struct message_summary *summ1;
1241 struct message_summary *summ2;
1243 summ1 = (struct message_summary *)s1;
1244 summ2 = (struct message_summary *)s2;
1246 if (summ1->date < summ2->date) return -1;
1247 else if (summ1->date > summ2->date) return +1;
1252 * command loop for reading messages
1254 void readloop(char *oper)
1264 int num_displayed = 0;
1266 int is_addressbook = 0;
1267 int is_singlecard = 0;
1268 int is_calendar = 0;
1271 int remaining_messages;
1273 int lowest_displayed = (-1);
1274 int highest_displayed = 0;
1275 long pn_previous = 0L;
1276 long pn_current = 0L;
1279 struct addrbookent *addrbook = NULL;
1281 char *sortby = NULL;
1283 startmsg = atol(bstr("startmsg"));
1284 maxmsgs = atoi(bstr("maxmsgs"));
1285 is_summary = atoi(bstr("summary"));
1286 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1287 sortby = bstr("sortby");
1288 if (strlen(sortby) == 0) sortby = "msgid";
1289 if (strcasecmp(sortby, "msgid")) maxmsgs = 9999999;
1291 output_headers(1, 1, 1, 0, 0, 0, 0);
1293 /* When in summary mode, always show ALL messages instead of just
1294 * new or old. Otherwise, show what the user asked for.
1296 if (!strcmp(oper, "readnew")) {
1297 strcpy(cmd, "MSGS NEW");
1299 else if (!strcmp(oper, "readold")) {
1300 strcpy(cmd, "MSGS OLD");
1303 strcpy(cmd, "MSGS ALL");
1306 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
1308 strcpy(cmd, "MSGS ALL");
1311 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
1313 strcpy(cmd, "MSGS ALL");
1318 strcpy(cmd, "MSGS ALL");
1321 /* Are we doing a summary view? If so, we need to know old messages
1322 * and new messages, so we can do that pretty boldface thing for the
1325 strcpy(old_msgs, "");
1328 serv_getln(buf, sizeof buf);
1329 if (buf[0] == '2') {
1330 strcpy(old_msgs, &buf[4]);
1334 is_singlecard = atoi(bstr("is_singlecard"));
1336 if (WC->wc_view == VIEW_CALENDAR) { /* calendar */
1338 strcpy(cmd, "MSGS ALL");
1341 if (WC->wc_view == VIEW_TASKS) { /* tasks */
1343 strcpy(cmd, "MSGS ALL");
1346 if (WC->wc_view == VIEW_NOTES) { /* notes */
1348 strcpy(cmd, "MSGS ALL");
1352 nummsgs = load_msg_ptrs(cmd);
1355 if ((!is_tasks) && (!is_calendar) && (!is_notes)) {
1356 if (!strcmp(oper, "readnew")) {
1357 wprintf("<EM>No new messages.</EM>\n");
1358 } else if (!strcmp(oper, "readold")) {
1359 wprintf("<EM>No old messages.</EM>\n");
1361 wprintf("<EM>No messages here.</EM>\n");
1369 if (WC->num_summ != 0) {
1373 WC->num_summ = nummsgs;
1374 WC->summ = malloc(WC->num_summ*sizeof(struct message_summary));
1375 for (a = 0; a < nummsgs; ++a) {
1376 /* Gather summary information */
1377 summarize_message(a, WC->msgarr[a], is_new);
1379 /* Are you a new message, or an old message? */
1381 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
1382 WC->summ[a].is_new = 0;
1385 WC->summ[a].is_new = 1;
1391 if (startmsg == 0L) startmsg = WC->msgarr[0];
1392 remaining_messages = 0;
1394 for (a = 0; a < nummsgs; ++a) {
1395 if (WC->msgarr[a] >= startmsg) {
1396 ++remaining_messages;
1401 if (!strcasecmp(sortby, "subject")) {
1402 qsort(WC->summ, WC->num_summ,
1403 sizeof(struct message_summary), summcmp_subj);
1405 else if (!strcasecmp(sortby, "sender")) {
1406 qsort(WC->summ, WC->num_summ,
1407 sizeof(struct message_summary), summcmp_sender);
1409 else if (!strcasecmp(sortby, "date")) {
1410 qsort(WC->summ, WC->num_summ,
1411 sizeof(struct message_summary), summcmp_date);
1415 wprintf("<form name=\"msgomatic\" "
1416 "METHOD=\"POST\" ACTION=\"/do_stuff_to_msgs\">\n");
1418 wprintf("<div id=\"fix_scrollbar_bug\">"
1419 "<table border=0 cellspacing=0 "
1420 "cellpadding=0 width=100%%>\n"
1422 "<TD align=center><b><i>Subject</i></b>%s</TD>"
1423 "<TD align=center><b><i>Sender</i></b>%s</TD>"
1424 "<TD align=center><b><i>Date</i></b>%s</TD>"
1428 (!strcasecmp(sortby, "subject") ? "" : " <a href=\"/readfwd?startmsg=1&maxmsgs=9999999&summary=1&sortby=subject\"><img border=\"0\" src=\"/static/sort_none.gif\"></img></a>"),
1429 (!strcasecmp(sortby, "sender") ? "" : " <a href=\"/readfwd?startmsg=1&maxmsgs=9999999&summary=1&sortby=sender\"><img border=\"0\" src=\"/static/sort_none.gif\"></img></a>"),
1430 (!strcasecmp(sortby, "date") ? "" : " <a href=\"/readfwd?startmsg=1&maxmsgs=9999999&summary=1&sortby=date\"><img border=\"0\" src=\"/static/sort_none.gif\"></img></a>")
1434 for (a = 0; a < nummsgs; ++a) {
1435 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
1437 /* Learn which msgs "Prev" & "Next" buttons go to */
1438 pn_current = WC->msgarr[a];
1439 if (a > 0) pn_previous = WC->msgarr[a-1];
1440 if (a < (nummsgs-1)) pn_next = WC->msgarr[a+1];
1442 /* If a tabular view, set up the line */
1445 wprintf("<TR BGCOLOR=\"#%s\">",
1446 (bg ? "DDDDDD" : "FFFFFF")
1450 /* Display the message */
1452 display_summarized(a);
1454 else if (is_addressbook) {
1455 fetch_ab_name(WC->msgarr[a], buf);
1457 addrbook = realloc(addrbook,
1458 (sizeof(struct addrbookent) * num_ab) );
1459 safestrncpy(addrbook[num_ab-1].ab_name, buf,
1460 sizeof(addrbook[num_ab-1].ab_name));
1461 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
1463 else if (is_calendar) {
1464 display_calendar(WC->msgarr[a]);
1466 else if (is_tasks) {
1467 display_task(WC->msgarr[a]);
1469 else if (is_notes) {
1470 display_note(WC->msgarr[a]);
1473 read_message(WC->msgarr[a]);
1476 /* If a tabular view, finish the line */
1481 if (lowest_displayed < 0) lowest_displayed = a;
1482 highest_displayed = a;
1485 --remaining_messages;
1490 wprintf("</table></div>\n");
1493 /* Bump these because although we're thinking in zero base, the user
1494 * is a drooling idiot and is thinking in one base.
1497 ++highest_displayed;
1499 /* If we're only looking at one message, do a prev/next thing */
1500 if (num_displayed == 1) {
1501 if ((!is_tasks) && (!is_calendar) && (!is_addressbook) && (!is_notes) && (!is_singlecard)) {
1503 wprintf("<div id=\"fix_scrollbar_bug\">"
1504 "<table border=0 width=100%% bgcolor=\"#dddddd\"><tr><td>"
1505 "Reading #%d of %d messages.</TD>\n"
1506 "<TD ALIGN=RIGHT><FONT SIZE=+1>",
1507 lowest_displayed, nummsgs);
1510 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" "
1511 "VALUE=\"Delete selected\">\n");
1514 if (pn_previous > 0L) {
1515 wprintf("<A HREF=\"/%s"
1525 wprintf("<A HREF=\"/%s"
1534 wprintf("<A HREF=\"/%s?startmsg=%ld"
1535 "&maxmsgs=%d&summary=1\">"
1543 wprintf("</td></tr></table></div>\n");
1548 * If we're not currently looking at ALL requested
1549 * messages, then display the selector bar
1551 if (num_displayed > 1) {
1552 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
1553 && (!is_notes) && (!is_singlecard)) {
1555 wprintf("Reading #", lowest_displayed, highest_displayed);
1557 wprintf("<SELECT NAME=\"whichones\" SIZE=\"1\" "
1558 "OnChange=\"location.href=msgomatic.whichones.options"
1559 "[selectedIndex].value\">\n");
1561 for (b=0; b<nummsgs; b = b + maxmsgs) {
1564 if (hi > nummsgs) hi = nummsgs;
1565 wprintf("<OPTION %s VALUE="
1570 "%d-%d</OPTION> \n",
1571 ((WC->msgarr[b] == startmsg) ? "SELECTED" : ""),
1578 wprintf("<OPTION VALUE=\"/%s?startmsg=%ld"
1579 "&maxmsgs=9999999&summary=%d\">"
1583 WC->msgarr[0], is_summary);
1585 wprintf("</SELECT> of %d messages.", nummsgs);
1588 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" "
1589 "VALUE=\"Delete selected\">\n");
1594 wprintf("</form>\n");
1598 do_tasks_view(); /* Render the task list */
1602 do_calendar_view(); /* Render the calendar */
1605 if (is_addressbook) {
1606 do_addrbook_view(addrbook, num_ab); /* Render the address book */
1610 if (addrbook != NULL) free(addrbook);
1612 /* free the summary */
1613 if (WC->num_summ != 0) {
1618 /* If we got here via a mailbox view and are reading a single
1619 * message, mark it as "seen." We do this after rendering the web page
1620 * so it doesn't keep the user waiting.
1622 if ( (maxmsgs == 1) && (WC->wc_view == VIEW_MAILBOX) ) {
1623 serv_printf("SEEN %ld|1", startmsg);
1624 serv_getln(buf, sizeof buf);
1630 * Back end for post_message() ... this is where the actual message
1631 * gets transmitted to the server.
1633 void post_mime_to_server(void) {
1635 int is_multipart = 0;
1637 struct wc_attachment *att;
1639 size_t encoded_length;
1641 /* If there are attachments, we have to do multipart/mixed */
1642 if (WC->first_attachment != NULL) {
1647 sprintf(boundary, "---Citadel-Multipart-%s-%04x%04x---",
1648 serv_info.serv_fqdn,
1653 /* Remember, serv_printf() appends an extra newline */
1654 serv_printf("Content-type: multipart/mixed; "
1655 "boundary=\"%s\"\n", boundary);
1656 serv_printf("This is a multipart message in MIME format.\n");
1657 serv_printf("--%s", boundary);
1660 serv_puts("Content-type: text/html; charset=utf-8");
1662 serv_puts("<HTML><BODY>\n");
1663 text_to_server(bstr("msgtext"), 0);
1664 serv_puts("</BODY></HTML>\n");
1669 /* Add in the attachments */
1670 for (att = WC->first_attachment; att!=NULL; att=att->next) {
1672 encoded_length = ((att->length * 150) / 100);
1673 encoded = malloc(encoded_length);
1674 if (encoded == NULL) break;
1675 CtdlEncodeBase64(encoded, att->data, att->length);
1677 serv_printf("--%s", boundary);
1678 serv_printf("Content-type: %s", att->content_type);
1679 serv_printf("Content-disposition: attachment; "
1680 "filename=\"%s\"", att->filename);
1681 serv_puts("Content-transfer-encoding: base64");
1683 serv_write(encoded, strlen(encoded));
1688 serv_printf("--%s--", boundary);
1696 * Post message (or don't post message)
1698 * Note regarding the "dont_post" variable:
1699 * A random value (actually, it's just a timestamp) is inserted as a hidden
1700 * field called "postseq" when the display_enter page is generated. This
1701 * value is checked when posting, using the static variable dont_post. If a
1702 * user attempts to post twice using the same dont_post value, the message is
1703 * discarded. This prevents the accidental double-saving of the same message
1704 * if the user happens to click the browser "back" button.
1706 void post_message(void)
1709 static long dont_post = (-1L);
1710 struct wc_attachment *att, *aptr;
1712 if (WC->upload_length > 0) {
1714 /* There's an attachment. Save it to this struct... */
1715 att = malloc(sizeof(struct wc_attachment));
1716 memset(att, 0, sizeof(struct wc_attachment));
1717 att->length = WC->upload_length;
1718 strcpy(att->content_type, WC->upload_content_type);
1719 strcpy(att->filename, WC->upload_filename);
1722 /* And add it to the list. */
1723 if (WC->first_attachment == NULL) {
1724 WC->first_attachment = att;
1727 aptr = WC->first_attachment;
1728 while (aptr->next != NULL) aptr = aptr->next;
1732 /* Netscape sends a simple filename, which is what we want,
1733 * but Satan's browser sends an entire pathname. Reduce
1734 * the path to just a filename if we need to.
1736 while (num_tokens(att->filename, '/') > 1) {
1737 remove_token(att->filename, 0, '/');
1739 while (num_tokens(att->filename, '\\') > 1) {
1740 remove_token(att->filename, 0, '\\');
1743 /* Transfer control of this memory from the upload struct
1744 * to the attachment struct.
1746 att->data = WC->upload;
1747 WC->upload_length = 0;
1753 if (!strcasecmp(bstr("sc"), "Cancel")) {
1754 sprintf(WC->ImportantMessage,
1755 "Cancelled. Message was not posted.");
1756 } else if (!strcasecmp(bstr("attach"), "Add")) {
1759 } else if (atol(bstr("postseq")) == dont_post) {
1760 sprintf(WC->ImportantMessage,
1761 "Automatically cancelled because you have already "
1762 "saved this message.");
1764 sprintf(buf, "ENT0 1|%s|0|4|%s",
1768 serv_getln(buf, sizeof buf);
1769 if (buf[0] == '4') {
1770 post_mime_to_server();
1771 if (strlen(bstr("recp")) > 0) {
1772 sprintf(WC->ImportantMessage, "Message has been sent.\n");
1775 sprintf(WC->ImportantMessage, "Message has been posted.\n");
1777 dont_post = atol(bstr("postseq"));
1779 sprintf(WC->ImportantMessage,
1784 free_attachments(WC);
1785 readloop("readnew");
1792 * display the message entry screen
1794 void display_enter(void)
1798 struct wc_attachment *att;
1800 if (strlen(bstr("force_room")) > 0) {
1801 gotoroom(bstr("force_room"));
1804 /* Are we perhaps in an address book view? If so, then an "enter
1805 * message" command really means "add new entry."
1807 if (WC->wc_view == VIEW_ADDRESSBOOK) {
1808 do_edit_vcard(-1, "", "");
1812 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1813 /* Are we perhaps in a calendar view? If so, then an "enter
1814 * message" command really means "add new calendar item."
1816 if (WC->wc_view == VIEW_CALENDAR) {
1817 display_edit_event();
1821 /* Are we perhaps in a tasks view? If so, then an "enter
1822 * message" command really means "add new task."
1824 if (WC->wc_view == VIEW_TASKS) {
1825 display_edit_task();
1830 /* Otherwise proceed normally. Do a custom room banner with no navbar... */
1831 output_headers(1, 1, 2, 0, 0, 0, 0);
1832 wprintf("<div id=\"banner\">\n");
1833 embed_room_banner(NULL, navbar_none);
1834 wprintf("</div>\n");
1835 wprintf("<div id=\"content\">\n"
1836 "<div id=\"fix_scrollbar_bug\">"
1837 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
1839 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
1841 serv_getln(buf, sizeof buf);
1843 if (!strncmp(buf, "570", 3)) {
1844 if (strlen(bstr("recp")) > 0) {
1845 svprintf("RECPERROR", WCS_STRING,
1846 "<SPAN CLASS=\"errormsg\">%s</SPAN><br />\n",
1850 do_template("prompt_for_recipient");
1853 if (buf[0] != '2') {
1854 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1859 fmt_date(buf, now, 0);
1860 strcat(&buf[strlen(buf)], " <I>from</I> ");
1861 stresc(&buf[strlen(buf)], WC->wc_username, 1, 1);
1862 if (strlen(bstr("recp")) > 0) {
1863 strcat(&buf[strlen(buf)], " <I>to</I> ");
1864 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
1866 strcat(&buf[strlen(buf)], " <I>in</I> ");
1867 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
1869 /* begin message entry screen */
1870 // wprintf("<div style=\"position:absolute; left:1%%; width:96%%; height:100%%\">\n");
1872 wprintf("<form enctype=\"multipart/form-data\" "
1873 "method=\"POST\" action=\"/post\" "
1874 "name=\"enterform\""
1875 "onSubmit=\"return submitForm();\""
1877 wprintf("<input type=\"hidden\" name=\"recp\" value=\"%s\">\n",
1879 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n",
1882 wprintf("%s<br>\n", buf); /* header bar */
1883 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
1884 /* "onLoad=\"document.enterform.msgtext.focus();\" " */
1885 wprintf("<font size=-1>Subject (optional):</font>"
1886 "<input type=\"text\" name=\"subject\" value=\"");
1887 escputs(bstr("subject"));
1888 wprintf("\" size=40 maxlength=70>"
1892 wprintf("<input type=\"submit\" name=\"sc\" value=\"");
1893 if (strlen(bstr("recp")) > 0) {
1894 wprintf("Send message");
1896 wprintf("Post message");
1899 "<input type=\"submit\" name=\"sc\" value=\"Cancel\">\n");
1901 wprintf("<center><script type=\"text/javascript\" "
1902 "src=\"static/richtext.js\"></script>\n"
1903 "<script type=\"text/javascript\">\n"
1904 "function submitForm() { \n"
1905 " updateRTE('msgtext'); \n"
1909 "initRTE(\"static/\", \"static/\", \"\"); \n"
1911 "<noscript>JavaScript must be enabled.</noscript> \n"
1912 "<script type=\"text/javascript\"> \n"
1913 "writeRichText('msgtext', '");
1914 msgescputs(bstr("msgtext"));
1915 wprintf("', '96%%', '200', true, false); \n"
1916 "</script></center><br />\n");
1918 /* Enumerate any attachments which are already in place... */
1919 wprintf("<img src=\"/static/diskette_24x.gif\" border=0 "
1920 "align=middle height=16 width=16> Attachments: ");
1921 wprintf("<select name=\"which_attachment\" size=1>");
1922 for (att = WC->first_attachment; att != NULL; att = att->next) {
1923 wprintf("<option value=\"");
1924 urlescputs(att->filename);
1926 escputs(att->filename);
1927 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
1928 wprintf("</option>\n");
1930 wprintf("</select>");
1932 /* Now offer the ability to attach additional files... */
1933 wprintf(" "
1934 "Attach file: <input NAME=\"attachfile\" "
1935 "SIZE=16 TYPE=\"file\">\n "
1936 "<input type=\"submit\" name=\"attach\" value=\"Add\">\n");
1938 wprintf("</form>\n");
1940 wprintf("</td></tr></table></div>\n");
1941 DONE: wDumpContent(1);
1951 void delete_msg(void)
1956 msgid = atol(bstr("msgid"));
1958 output_headers(1, 1, 1, 0, 0, 0, 0);
1960 sprintf(buf, "DELE %ld", msgid);
1962 serv_getln(buf, sizeof buf);
1963 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1972 * Confirm move of a message
1974 void confirm_move_msg(void)
1980 msgid = atol(bstr("msgid"));
1982 output_headers(1, 1, 1, 0, 0, 0, 0);
1984 wprintf("<div id=\"fix_scrollbar_bug\">"
1985 "<table width=100%% border=0 bgcolor=\"#444455\"><tr><td>");
1986 wprintf("<font size=+1 color=\"#ffffff\"");
1987 wprintf("<b>Confirm move of message</b>\n");
1988 wprintf("</font></td></tr></table></div>\n");
1990 wprintf("<CENTER>");
1992 wprintf("Move this message to:<br />\n");
1994 wprintf("<form METHOD=\"POST\" ACTION=\"/move_msg\">\n");
1995 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
1999 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
2001 serv_getln(buf, sizeof buf);
2002 if (buf[0] == '1') {
2003 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2004 extract_token(targ, buf, 0, '|', sizeof targ);
2005 wprintf("<OPTION>");
2010 wprintf("</SELECT>\n");
2011 wprintf("<br />\n");
2013 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
2015 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
2016 wprintf("</form></CENTER>\n");
2018 wprintf("</CENTER>\n");
2029 msgid = atol(bstr("msgid"));
2031 output_headers(1, 1, 1, 0, 0, 0, 0);
2033 if (!strcasecmp(bstr("yesno"), "Move")) {
2034 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
2036 serv_getln(buf, sizeof buf);
2037 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2039 wprintf("<EM>Message not moved.</EM><br />\n");
2046 * This gets called when a user selects multiple messages in a summary
2047 * list and then clicks to perform a transformation of some sort on them
2048 * (such as deleting them).
2050 void do_stuff_to_msgs(void) {
2055 struct stuff_t *next;
2059 struct stuff_t *stuff = NULL;
2060 struct stuff_t *ptr;
2063 serv_puts("MSGS ALL");
2064 serv_getln(buf, sizeof buf);
2066 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2067 ptr = malloc(sizeof(struct stuff_t));
2068 ptr->msgnum = atol(buf);
2073 strcpy(sc, bstr("sc"));
2075 while (stuff != NULL) {
2077 sprintf(buf, "msg_%ld", stuff->msgnum);
2078 if (!strcasecmp(bstr(buf), "yes")) {
2080 if (!strcasecmp(sc, "Delete selected")) {
2081 serv_printf("DELE %ld", stuff->msgnum);
2082 serv_getln(buf, sizeof buf);
2092 readloop("readfwd");