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 summarize_message(long msgnum, int is_new) {
863 memset(&summ, 0, sizeof(summ));
864 strcpy(summ.subj, "(no subject)");
866 /* ask for headers only with no MIME */
867 sprintf(buf, "MSG0 %ld|3", msgnum);
869 serv_getln(buf, sizeof buf);
870 if (buf[0] != '1') return;
872 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
873 if (!strncasecmp(buf, "from=", 5)) {
874 strcpy(summ.from, &buf[5]);
876 if (!strncasecmp(buf, "subj=", 5)) {
877 if (strlen(&buf[5]) > 0) {
878 strcpy(summ.subj, &buf[5]);
880 /* Handle subjects with RFC2047 encoding */
881 utf8ify_rfc822_string(summ.subj);
883 if (strlen(summ.subj) > 75) {
884 strcpy(&summ.subj[72], "...");
888 /* if (!strncasecmp(buf, "rfca=", 5)) {
889 strcat(summ.from, " <");
890 strcat(summ.from, &buf[5]);
891 strcat(summ.from, ">");
894 if (!strncasecmp(buf, "node=", 5)) {
895 if ( ((WC->room_flags & QR_NETWORK)
896 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
897 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
899 strcat(summ.from, " @ ");
900 strcat(summ.from, &buf[5]);
904 if (!strncasecmp(buf, "rcpt=", 5)) {
905 strcpy(summ.to, &buf[5]);
908 if (!strncasecmp(buf, "time=", 5)) {
909 fmt_date(summ.date, atol(&buf[5]), 1); /* brief */
914 /* Handle senders with RFC2047 encoding */
915 utf8ify_rfc822_string(summ.from);
917 if (strlen(summ.from) > 25) {
918 strcpy(&summ.from[22], "...");
922 if (is_new) wprintf("<B>");
923 wprintf("<A HREF=\"/readfwd?startmsg=%ld"
924 "&maxmsgs=1&summary=0\">",
928 if (is_new) wprintf("</B>");
929 wprintf("</TD><TD>");
930 if (is_new) wprintf("<B>");
932 if (is_new) wprintf("</B>");
933 wprintf(" </TD><TD>");
934 if (is_new) wprintf("<B>");
936 if (is_new) wprintf("</B>");
939 "<INPUT TYPE=\"checkbox\" NAME=\"msg_%ld\" VALUE=\"yes\">"
947 void display_addressbook(long msgnum, char alpha) {
949 char mime_partnum[SIZ];
950 char mime_filename[SIZ];
951 char mime_content_type[SIZ];
952 char mime_disposition[SIZ];
954 char vcard_partnum[SIZ];
955 char *vcard_source = NULL;
965 memset(&summ, 0, sizeof(summ));
966 strcpy(summ.subj, "(no subject)");
968 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
970 serv_getln(buf, sizeof buf);
971 if (buf[0] != '1') return;
973 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
974 if (!strncasecmp(buf, "part=", 5)) {
975 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
976 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
977 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
978 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
979 mime_length = extract_int(&buf[5], 5);
981 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
982 strcpy(vcard_partnum, mime_partnum);
988 if (strlen(vcard_partnum) > 0) {
989 vcard_source = load_mimepart(msgnum, vcard_partnum);
990 if (vcard_source != NULL) {
992 /* Display the summary line */
993 display_vcard(vcard_source, alpha, 0, NULL);
995 /* If it's my vCard I can edit it */
996 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
997 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
998 || (WC->wc_view == VIEW_ADDRESSBOOK)
1000 wprintf("<A HREF=\"/edit_vcard?"
1001 "msgnum=%ld&partnum=%s\">",
1002 msgnum, vcard_partnum);
1003 wprintf("[edit]</A>");
1014 /* If it's an old "Firstname Lastname" style record, try to
1017 void lastfirst_firstlast(char *namebuf) {
1018 char firstname[SIZ];
1022 if (namebuf == NULL) return;
1023 if (strchr(namebuf, ';') != NULL) return;
1025 i = num_tokens(namebuf, ' ');
1028 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1029 remove_token(namebuf, i-1, ' ');
1030 strcpy(firstname, namebuf);
1031 sprintf(namebuf, "%s; %s", lastname, firstname);
1035 void fetch_ab_name(long msgnum, char *namebuf) {
1037 char mime_partnum[SIZ];
1038 char mime_filename[SIZ];
1039 char mime_content_type[SIZ];
1040 char mime_disposition[SIZ];
1042 char vcard_partnum[SIZ];
1043 char *vcard_source = NULL;
1054 if (namebuf == NULL) return;
1055 strcpy(namebuf, "");
1057 memset(&summ, 0, sizeof(summ));
1058 strcpy(summ.subj, "(no subject)");
1060 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1062 serv_getln(buf, sizeof buf);
1063 if (buf[0] != '1') return;
1065 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1066 if (!strncasecmp(buf, "part=", 5)) {
1067 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1068 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1069 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1070 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1071 mime_length = extract_int(&buf[5], 5);
1073 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1074 strcpy(vcard_partnum, mime_partnum);
1080 if (strlen(vcard_partnum) > 0) {
1081 vcard_source = load_mimepart(msgnum, vcard_partnum);
1082 if (vcard_source != NULL) {
1084 /* Grab the name off the card */
1085 display_vcard(vcard_source, 0, 0, namebuf);
1091 lastfirst_firstlast(namebuf);
1093 for (i=0; i<strlen(namebuf); ++i) {
1094 if (namebuf[i] != ';') return;
1096 strcpy(namebuf, "(no name)");
1102 * Record compare function for sorting address book indices
1104 int abcmp(const void *ab1, const void *ab2) {
1106 (((const struct addrbookent *)ab1)->ab_name),
1107 (((const struct addrbookent *)ab2)->ab_name)
1113 * Helper function for do_addrbook_view()
1114 * Converts a name into a three-letter tab label
1116 void nametab(char *tabbuf, char *name) {
1117 stresc(tabbuf, name, 0, 0);
1118 tabbuf[0] = toupper(tabbuf[0]);
1119 tabbuf[1] = tolower(tabbuf[1]);
1120 tabbuf[2] = tolower(tabbuf[2]);
1126 * Render the address book using info we gathered during the scan
1128 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1132 static int NAMESPERPAGE = 60;
1136 char tabfirst_label[SIZ];
1138 char tablast_label[SIZ];
1141 wprintf("<I>This address book is empty.</I>\n");
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)
1223 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1225 serv_getln(buf, sizeof buf);
1226 if (buf[0] != '1') {
1227 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1230 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1231 if (nummsgs < maxload) {
1232 WC->msgarr[nummsgs] = atol(buf);
1241 * command loop for reading messages
1243 void readloop(char *oper)
1253 int num_displayed = 0;
1255 int is_addressbook = 0;
1256 int is_singlecard = 0;
1257 int is_calendar = 0;
1260 int remaining_messages;
1262 int lowest_displayed = (-1);
1263 int highest_displayed = 0;
1264 long pn_previous = 0L;
1265 long pn_current = 0L;
1268 struct addrbookent *addrbook = NULL;
1271 startmsg = atol(bstr("startmsg"));
1272 maxmsgs = atoi(bstr("maxmsgs"));
1273 is_summary = atoi(bstr("summary"));
1274 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1276 output_headers(1, 1, 1, 0, 0, 0, 0);
1278 /* When in summary mode, always show ALL messages instead of just
1279 * new or old. Otherwise, show what the user asked for.
1281 if (!strcmp(oper, "readnew")) {
1282 strcpy(cmd, "MSGS NEW");
1284 else if (!strcmp(oper, "readold")) {
1285 strcpy(cmd, "MSGS OLD");
1288 strcpy(cmd, "MSGS ALL");
1291 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
1293 strcpy(cmd, "MSGS ALL");
1296 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
1298 strcpy(cmd, "MSGS ALL");
1303 strcpy(cmd, "MSGS ALL");
1306 /* Are we doing a summary view? If so, we need to know old messages
1307 * and new messages, so we can do that pretty boldface thing for the
1310 strcpy(old_msgs, "");
1313 serv_getln(buf, sizeof buf);
1314 if (buf[0] == '2') {
1315 strcpy(old_msgs, &buf[4]);
1319 is_singlecard = atoi(bstr("is_singlecard"));
1321 if (WC->wc_view == VIEW_CALENDAR) { /* calendar */
1323 strcpy(cmd, "MSGS ALL");
1326 if (WC->wc_view == VIEW_TASKS) { /* tasks */
1328 strcpy(cmd, "MSGS ALL");
1331 if (WC->wc_view == VIEW_NOTES) { /* notes */
1333 strcpy(cmd, "MSGS ALL");
1337 nummsgs = load_msg_ptrs(cmd);
1340 if ((!is_tasks) && (!is_calendar) && (!is_notes)) {
1341 if (!strcmp(oper, "readnew")) {
1342 wprintf("<EM>No new messages.</EM>\n");
1343 } else if (!strcmp(oper, "readold")) {
1344 wprintf("<EM>No old messages.</EM>\n");
1346 wprintf("<EM>No messages here.</EM>\n");
1353 if (startmsg == 0L) startmsg = WC->msgarr[0];
1354 remaining_messages = 0;
1356 for (a = 0; a < nummsgs; ++a) {
1357 if (WC->msgarr[a] >= startmsg) {
1358 ++remaining_messages;
1362 wprintf("<form name=\"msgomatic\" "
1363 "METHOD=\"POST\" ACTION=\"/do_stuff_to_msgs\">\n");
1365 wprintf("<div id=\"fix_scrollbar_bug\">"
1366 "<table border=0 cellspacing=0 "
1367 "cellpadding=0 width=100%%>\n"
1369 "<TD align=center><b><i>Subject</i></b></TD>"
1370 "<TD align=center><b><i>Sender</i></b></TD>"
1371 "<TD align=center><b><i>Date</i></b></TD>"
1377 for (a = 0; a < nummsgs; ++a) {
1378 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
1380 /* Are you a new message, or an old message? */
1383 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
1391 /* Learn which msgs "Prev" & "Next" buttons go to */
1392 pn_current = WC->msgarr[a];
1393 if (a > 0) pn_previous = WC->msgarr[a-1];
1394 if (a < (nummsgs-1)) pn_next = WC->msgarr[a+1];
1396 /* If a tabular view, set up the line */
1399 wprintf("<TR BGCOLOR=\"#%s\">",
1400 (bg ? "DDDDDD" : "FFFFFF")
1404 /* Display the message */
1406 summarize_message(WC->msgarr[a], is_new);
1408 else if (is_addressbook) {
1409 fetch_ab_name(WC->msgarr[a], buf);
1411 addrbook = realloc(addrbook,
1412 (sizeof(struct addrbookent) * num_ab) );
1413 safestrncpy(addrbook[num_ab-1].ab_name, buf,
1414 sizeof(addrbook[num_ab-1].ab_name));
1415 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
1417 else if (is_calendar) {
1418 display_calendar(WC->msgarr[a]);
1420 else if (is_tasks) {
1421 display_task(WC->msgarr[a]);
1423 else if (is_notes) {
1424 display_note(WC->msgarr[a]);
1427 read_message(WC->msgarr[a]);
1430 /* If a tabular view, finish the line */
1435 if (lowest_displayed < 0) lowest_displayed = a;
1436 highest_displayed = a;
1439 --remaining_messages;
1444 wprintf("</table></div>\n");
1447 /* Bump these because although we're thinking in zero base, the user
1448 * is a drooling idiot and is thinking in one base.
1451 ++highest_displayed;
1453 /* If we're only looking at one message, do a prev/next thing */
1454 if (num_displayed == 1) {
1455 if ((!is_tasks) && (!is_calendar) && (!is_addressbook) && (!is_notes) && (!is_singlecard)) {
1457 wprintf("<div id=\"fix_scrollbar_bug\">"
1458 "<table border=0 width=100%% bgcolor=\"#dddddd\"><tr><td>"
1459 "Reading #%d of %d messages.</TD>\n"
1460 "<TD ALIGN=RIGHT><FONT SIZE=+1>",
1461 lowest_displayed, nummsgs);
1464 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" "
1465 "VALUE=\"Delete selected\">\n");
1468 if (pn_previous > 0L) {
1469 wprintf("<A HREF=\"/%s"
1479 wprintf("<A HREF=\"/%s"
1488 wprintf("<A HREF=\"/%s?startmsg=%ld"
1489 "&maxmsgs=%d&summary=1\">"
1497 wprintf("</td></tr></table></div>\n");
1502 * If we're not currently looking at ALL requested
1503 * messages, then display the selector bar
1505 if (num_displayed > 1) {
1506 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
1507 && (!is_notes) && (!is_singlecard)) {
1509 wprintf("Reading #", lowest_displayed, highest_displayed);
1511 wprintf("<SELECT NAME=\"whichones\" SIZE=\"1\" "
1512 "OnChange=\"location.href=msgomatic.whichones.options"
1513 "[selectedIndex].value\">\n");
1515 for (b=0; b<nummsgs; b = b + maxmsgs) {
1518 if (hi > nummsgs) hi = nummsgs;
1519 wprintf("<OPTION %s VALUE="
1524 "%d-%d</OPTION> \n",
1525 ((WC->msgarr[b] == startmsg) ? "SELECTED" : ""),
1532 wprintf("<OPTION VALUE=\"/%s?startmsg=%ld"
1533 "&maxmsgs=9999999&summary=%d\">"
1537 WC->msgarr[0], is_summary);
1539 wprintf("</SELECT> of %d messages.", nummsgs);
1542 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" "
1543 "VALUE=\"Delete selected\">\n");
1548 wprintf("</form>\n");
1552 do_tasks_view(); /* Render the task list */
1556 do_calendar_view(); /* Render the calendar */
1559 if (is_addressbook) {
1560 do_addrbook_view(addrbook, num_ab); /* Render the address book */
1564 if (addrbook != NULL) free(addrbook);
1566 /* If we got here via a mailbox view and are reading a single
1567 * message, mark it as "seen." We do this after rendering the web page
1568 * so it doesn't keep the user waiting.
1570 if ( (maxmsgs == 1) && (WC->wc_view == VIEW_MAILBOX) ) {
1571 serv_printf("SEEN %ld|1", startmsg);
1572 serv_getln(buf, sizeof buf);
1578 * Back end for post_message() ... this is where the actual message
1579 * gets transmitted to the server.
1581 void post_mime_to_server(void) {
1583 int is_multipart = 0;
1585 struct wc_attachment *att;
1587 size_t encoded_length;
1589 /* If there are attachments, we have to do multipart/mixed */
1590 if (WC->first_attachment != NULL) {
1595 sprintf(boundary, "---Citadel-Multipart-%s-%04x%04x---",
1596 serv_info.serv_fqdn,
1601 /* Remember, serv_printf() appends an extra newline */
1602 serv_printf("Content-type: multipart/mixed; "
1603 "boundary=\"%s\"\n", boundary);
1604 serv_printf("This is a multipart message in MIME format.\n");
1605 serv_printf("--%s", boundary);
1608 serv_puts("Content-type: text/html; charset=utf-8");
1610 serv_puts("<HTML><BODY>\n");
1611 text_to_server(bstr("msgtext"), 0);
1612 serv_puts("</BODY></HTML>\n");
1617 /* Add in the attachments */
1618 for (att = WC->first_attachment; att!=NULL; att=att->next) {
1620 encoded_length = ((att->length * 150) / 100);
1621 encoded = malloc(encoded_length);
1622 if (encoded == NULL) break;
1623 CtdlEncodeBase64(encoded, att->data, att->length);
1625 serv_printf("--%s", boundary);
1626 serv_printf("Content-type: %s", att->content_type);
1627 serv_printf("Content-disposition: attachment; "
1628 "filename=\"%s\"", att->filename);
1629 serv_puts("Content-transfer-encoding: base64");
1631 serv_write(encoded, strlen(encoded));
1636 serv_printf("--%s--", boundary);
1644 * Post message (or don't post message)
1646 * Note regarding the "dont_post" variable:
1647 * A random value (actually, it's just a timestamp) is inserted as a hidden
1648 * field called "postseq" when the display_enter page is generated. This
1649 * value is checked when posting, using the static variable dont_post. If a
1650 * user attempts to post twice using the same dont_post value, the message is
1651 * discarded. This prevents the accidental double-saving of the same message
1652 * if the user happens to click the browser "back" button.
1654 void post_message(void)
1657 static long dont_post = (-1L);
1658 struct wc_attachment *att, *aptr;
1660 if (WC->upload_length > 0) {
1662 /* There's an attachment. Save it to this struct... */
1663 att = malloc(sizeof(struct wc_attachment));
1664 memset(att, 0, sizeof(struct wc_attachment));
1665 att->length = WC->upload_length;
1666 strcpy(att->content_type, WC->upload_content_type);
1667 strcpy(att->filename, WC->upload_filename);
1670 /* And add it to the list. */
1671 if (WC->first_attachment == NULL) {
1672 WC->first_attachment = att;
1675 aptr = WC->first_attachment;
1676 while (aptr->next != NULL) aptr = aptr->next;
1680 /* Netscape sends a simple filename, which is what we want,
1681 * but Satan's browser sends an entire pathname. Reduce
1682 * the path to just a filename if we need to.
1684 while (num_tokens(att->filename, '/') > 1) {
1685 remove_token(att->filename, 0, '/');
1687 while (num_tokens(att->filename, '\\') > 1) {
1688 remove_token(att->filename, 0, '\\');
1691 /* Transfer control of this memory from the upload struct
1692 * to the attachment struct.
1694 att->data = WC->upload;
1695 WC->upload_length = 0;
1701 if (!strcasecmp(bstr("sc"), "Cancel")) {
1702 sprintf(WC->ImportantMessage,
1703 "Cancelled. Message was not posted.");
1704 } else if (!strcasecmp(bstr("attach"), "Add")) {
1707 } else if (atol(bstr("postseq")) == dont_post) {
1708 sprintf(WC->ImportantMessage,
1709 "Automatically cancelled because you have already "
1710 "saved this message.");
1712 sprintf(buf, "ENT0 1|%s|0|4|%s",
1716 serv_getln(buf, sizeof buf);
1717 if (buf[0] == '4') {
1718 post_mime_to_server();
1719 if (strlen(bstr("recp")) > 0) {
1720 sprintf(WC->ImportantMessage, "Message has been sent.\n");
1723 sprintf(WC->ImportantMessage, "Message has been posted.\n");
1725 dont_post = atol(bstr("postseq"));
1727 sprintf(WC->ImportantMessage,
1732 free_attachments(WC);
1733 readloop("readnew");
1740 * display the message entry screen
1742 void display_enter(void)
1746 struct wc_attachment *att;
1748 if (strlen(bstr("force_room")) > 0) {
1749 gotoroom(bstr("force_room"));
1752 /* Are we perhaps in an address book view? If so, then an "enter
1753 * message" command really means "add new entry."
1755 if (WC->wc_view == VIEW_ADDRESSBOOK) {
1756 do_edit_vcard(-1, "", "");
1760 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1761 /* Are we perhaps in a calendar view? If so, then an "enter
1762 * message" command really means "add new calendar item."
1764 if (WC->wc_view == VIEW_CALENDAR) {
1765 display_edit_event();
1769 /* Are we perhaps in a tasks view? If so, then an "enter
1770 * message" command really means "add new task."
1772 if (WC->wc_view == VIEW_TASKS) {
1773 display_edit_task();
1778 /* Otherwise proceed normally. Do a custom room banner with no navbar... */
1779 output_headers(1, 1, 2, 0, 0, 0, 0);
1780 wprintf("<div id=\"banner\">\n");
1781 embed_room_banner(NULL, navbar_none);
1782 wprintf("</div>\n");
1783 wprintf("<div id=\"content\">\n"
1784 "<div id=\"fix_scrollbar_bug\">"
1785 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
1787 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
1789 serv_getln(buf, sizeof buf);
1791 if (!strncmp(buf, "570", 3)) {
1792 if (strlen(bstr("recp")) > 0) {
1793 svprintf("RECPERROR", WCS_STRING,
1794 "<SPAN CLASS=\"errormsg\">%s</SPAN><br />\n",
1798 do_template("prompt_for_recipient");
1801 if (buf[0] != '2') {
1802 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1807 fmt_date(buf, now, 0);
1808 strcat(&buf[strlen(buf)], " <I>from</I> ");
1809 stresc(&buf[strlen(buf)], WC->wc_username, 1, 1);
1810 if (strlen(bstr("recp")) > 0) {
1811 strcat(&buf[strlen(buf)], " <I>to</I> ");
1812 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
1814 strcat(&buf[strlen(buf)], " <I>in</I> ");
1815 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
1817 /* begin message entry screen */
1818 // wprintf("<div style=\"position:absolute; left:1%%; width:96%%; height:100%%\">\n");
1820 wprintf("<form enctype=\"multipart/form-data\" "
1821 "method=\"POST\" action=\"/post\" "
1822 "name=\"enterform\""
1823 "onSubmit=\"return submitForm();\""
1825 wprintf("<input type=\"hidden\" name=\"recp\" value=\"%s\">\n",
1827 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n",
1830 wprintf("%s<br>\n", buf); /* header bar */
1831 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
1832 /* "onLoad=\"document.enterform.msgtext.focus();\" " */
1833 wprintf("<font size=-1>Subject (optional):</font>"
1834 "<input type=\"text\" name=\"subject\" value=\"");
1835 escputs(bstr("subject"));
1836 wprintf("\" size=40 maxlength=70>"
1840 wprintf("<input type=\"submit\" name=\"sc\" value=\"");
1841 if (strlen(bstr("recp")) > 0) {
1842 wprintf("Send message");
1844 wprintf("Post message");
1847 "<input type=\"submit\" name=\"sc\" value=\"Cancel\">\n");
1849 wprintf("<center><script type=\"text/javascript\" "
1850 "src=\"static/richtext.js\"></script>\n"
1851 "<script type=\"text/javascript\">\n"
1852 "function submitForm() { \n"
1853 " updateRTE('msgtext'); \n"
1857 "initRTE(\"static/\", \"static/\", \"\"); \n"
1859 "<noscript>JavaScript must be enabled.</noscript> \n"
1860 "<script type=\"text/javascript\"> \n"
1861 "writeRichText('msgtext', '");
1862 msgescputs(bstr("msgtext"));
1863 wprintf("', '96%%', '200', true, false); \n"
1864 "</script></center><br />\n");
1866 /* Enumerate any attachments which are already in place... */
1867 wprintf("<img src=\"/static/diskette_24x.gif\" border=0 "
1868 "align=middle height=16 width=16> Attachments: ");
1869 wprintf("<select name=\"which_attachment\" size=1>");
1870 for (att = WC->first_attachment; att != NULL; att = att->next) {
1871 wprintf("<option value=\"");
1872 urlescputs(att->filename);
1874 escputs(att->filename);
1875 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
1876 wprintf("</option>\n");
1878 wprintf("</select>");
1880 /* Now offer the ability to attach additional files... */
1881 wprintf(" "
1882 "Attach file: <input NAME=\"attachfile\" "
1883 "SIZE=16 TYPE=\"file\">\n "
1884 "<input type=\"submit\" name=\"attach\" value=\"Add\">\n");
1886 wprintf("</form>\n");
1888 wprintf("</td></tr></table></div>\n");
1889 DONE: wDumpContent(1);
1899 void delete_msg(void)
1904 msgid = atol(bstr("msgid"));
1906 output_headers(1, 1, 1, 0, 0, 0, 0);
1908 sprintf(buf, "DELE %ld", msgid);
1910 serv_getln(buf, sizeof buf);
1911 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1920 * Confirm move of a message
1922 void confirm_move_msg(void)
1928 msgid = atol(bstr("msgid"));
1930 output_headers(1, 1, 1, 0, 0, 0, 0);
1932 wprintf("<div id=\"fix_scrollbar_bug\">"
1933 "<table width=100%% border=0 bgcolor=\"#444455\"><tr><td>");
1934 wprintf("<font size=+1 color=\"#ffffff\"");
1935 wprintf("<b>Confirm move of message</b>\n");
1936 wprintf("</font></td></tr></table></div>\n");
1938 wprintf("<CENTER>");
1940 wprintf("Move this message to:<br />\n");
1942 wprintf("<form METHOD=\"POST\" ACTION=\"/move_msg\">\n");
1943 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
1947 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
1949 serv_getln(buf, sizeof buf);
1950 if (buf[0] == '1') {
1951 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1952 extract_token(targ, buf, 0, '|', sizeof targ);
1953 wprintf("<OPTION>");
1958 wprintf("</SELECT>\n");
1959 wprintf("<br />\n");
1961 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
1963 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
1964 wprintf("</form></CENTER>\n");
1966 wprintf("</CENTER>\n");
1977 msgid = atol(bstr("msgid"));
1979 output_headers(1, 1, 1, 0, 0, 0, 0);
1981 if (!strcasecmp(bstr("yesno"), "Move")) {
1982 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
1984 serv_getln(buf, sizeof buf);
1985 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1987 wprintf("<EM>Message not moved.</EM><br />\n");
1994 * This gets called when a user selects multiple messages in a summary
1995 * list and then clicks to perform a transformation of some sort on them
1996 * (such as deleting them).
1998 void do_stuff_to_msgs(void) {
2003 struct stuff_t *next;
2007 struct stuff_t *stuff = NULL;
2008 struct stuff_t *ptr;
2011 serv_puts("MSGS ALL");
2012 serv_getln(buf, sizeof buf);
2014 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2015 ptr = malloc(sizeof(struct stuff_t));
2016 ptr->msgnum = atol(buf);
2021 strcpy(sc, bstr("sc"));
2023 while (stuff != NULL) {
2025 sprintf(buf, "msg_%ld", stuff->msgnum);
2026 if (!strcasecmp(bstr(buf), "yes")) {
2028 if (!strcasecmp(sc, "Delete selected")) {
2029 serv_printf("DELE %ld", stuff->msgnum);
2030 serv_getln(buf, sizeof buf);
2040 readloop("readfwd");