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);
468 * I wanna SEE that message!
470 void read_message(long msgnum, int suppress_buttons) {
472 char mime_partnum[256];
473 char mime_filename[256];
474 char mime_content_type[256];
475 char mime_charset[256];
476 char mime_disposition[256];
490 char vcard_partnum[256];
491 char cal_partnum[256];
492 char *part_source = NULL;
494 iconv_t ic = (iconv_t)(-1) ;
495 char *ibuf; /* Buffer of characters to be converted */
496 char *obuf; /* Buffer for converted characters */
497 size_t ibuflen; /* Length of input buffer */
498 size_t obuflen; /* Length of output buffer */
499 char *osav; /* Saved pointer to output buffer */
505 strcpy(reply_to, "");
506 strcpy(vcard_partnum, "");
507 strcpy(cal_partnum, "");
508 strcpy(mime_http, "");
509 strcpy(mime_content_type, "text/plain");
510 strcpy(mime_charset, "us-ascii");
512 serv_printf("MSG4 %ld", msgnum);
513 serv_getln(buf, sizeof buf);
516 wprintf(_("ERROR:"));
517 wprintf("</STRONG> %s<br />\n", &buf[4]);
521 /* begin everythingamundo table */
522 wprintf("<div id=\"fix_scrollbar_bug\">\n");
523 wprintf("<table width=100%% border=1 cellspacing=0 "
524 "cellpadding=0><TR><TD>\n");
526 /* begin message header table */
527 wprintf("<TABLE WIDTH=100%% BORDER=0 CELLSPACING=0 "
528 "CELLPADDING=1 BGCOLOR=\"#CCCCCC\"><TR><TD>\n");
530 wprintf("<SPAN CLASS=\"message_header\">");
531 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 safestrncpy(m_subject, &buf[5], sizeof m_subject);
563 if (!strncasecmp(buf, "cccc=", 5)) {
564 safestrncpy(m_cc, &buf[5], sizeof m_cc);
566 if ((!strncasecmp(buf, "hnod=", 5))
567 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
568 wprintf("(%s) ", &buf[5]);
570 if ((!strncasecmp(buf, "room=", 5))
571 && (strcasecmp(&buf[5], WC->wc_roomname))
572 && (strlen(&buf[5])>0) ) {
574 wprintf("%s> ", &buf[5]);
576 if (!strncasecmp(buf, "rfca=", 5)) {
577 strcpy(rfca, &buf[5]);
583 if (!strncasecmp(buf, "node=", 5)) {
584 strcpy(node, &buf[5]);
585 if ( ((WC->room_flags & QR_NETWORK)
586 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
587 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
590 wprintf("@%s ", &buf[5]);
593 if (!strncasecmp(buf, "rcpt=", 5)) {
598 if (!strncasecmp(buf, "time=", 5)) {
599 fmt_date(now, atol(&buf[5]), 0);
603 if (!strncasecmp(buf, "part=", 5)) {
604 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
605 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
606 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
607 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
608 mime_length = extract_int(&buf[5], 5);
610 if (!strcasecmp(mime_disposition, "attachment")) {
611 snprintf(&mime_http[strlen(mime_http)],
612 (sizeof(mime_http) - strlen(mime_http) - 1),
613 "<A HREF=\"/output_mimepart?"
614 "msgnum=%ld?partnum=%s\" "
615 "TARGET=\"wc.%ld.%s\">"
616 "<IMG SRC=\"/static/diskette_24x.gif\" "
617 "BORDER=0 ALIGN=MIDDLE>\n"
618 "Part %s: %s (%s, %d bytes)</A><br />\n",
619 msgnum, mime_partnum,
620 msgnum, mime_partnum,
621 mime_partnum, mime_filename,
622 mime_content_type, mime_length);
625 if ((!strcasecmp(mime_disposition, "inline"))
626 && (!strncasecmp(mime_content_type, "image/", 6)) ){
627 snprintf(&mime_http[strlen(mime_http)],
628 (sizeof(mime_http) - strlen(mime_http) - 1),
629 "<IMG SRC=\"/output_mimepart?"
630 "msgnum=%ld?partnum=%s\">",
631 msgnum, mime_partnum);
634 /*** begin handler prep ***/
635 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
636 strcpy(vcard_partnum, mime_partnum);
639 if (!strcasecmp(mime_content_type, "text/calendar")) {
640 strcpy(cal_partnum, mime_partnum);
643 /*** end handler prep ***/
649 /* Generate a reply-to address */
650 if (strlen(rfca) > 0) {
651 strcpy(reply_to, rfca);
654 if ( (strlen(node) > 0)
655 && (strcasecmp(node, serv_info.serv_nodename))
656 && (strcasecmp(node, serv_info.serv_humannode)) ) {
657 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
661 snprintf(reply_to, sizeof(reply_to), "%s", from);
671 utf8ify_rfc822_string(m_cc);
672 utf8ify_rfc822_string(m_subject);
674 if (strlen(m_cc) > 0) {
676 "<SPAN CLASS=\"message_subject\">");
682 if (strlen(m_subject) > 0) {
684 "<SPAN CLASS=\"message_subject\">");
685 wprintf(_("Subject:"));
692 /* start msg buttons */
693 if (!suppress_buttons) {
694 wprintf("<td align=right>\n");
697 wprintf("<a href=\"/display_enter?recp=");
698 urlescputs(reply_to);
699 wprintf("?subject=");
700 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
701 urlescputs(m_subject);
702 wprintf("\">[%s]</a> ", _("Reply"));
705 if (WC->wc_view == VIEW_MAILBOX) {
706 wprintf("<a href=\"/display_enter?pullquote=%ld?subject=", msgnum);
707 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
708 urlescputs(m_subject);
709 wprintf("\">[%s]</a> ", _("Forward"));
712 if (WC->is_room_aide) {
714 wprintf("<a href=\"/confirm_move_msg?msgid=%ld\">[%s]</a> ",
718 wprintf("<a href=\"/delete_msg?msgid=%ld\" "
719 "onClick=\"return confirm('%s');\">"
720 "[%s]</a> ", msgnum, _("Delete this message?"), _("Delete")
724 wprintf("<a href=\"/msg?msgnum=%ld?sourceiframe=msgloader1?print_it=yes\" target=\"msgloader1\">"
725 "[%s]</a>", msgnum, _("Print"));
730 wprintf("</TR></TABLE>\n");
733 wprintf("<TABLE BORDER=0 WIDTH=100%% BGCOLOR=#FFFFFF "
734 "CELLPADDING=1 CELLSPACING=0><TR><TD>");
737 * Learn the content type
739 strcpy(mime_content_type, "text/plain");
740 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
741 if (!strcmp(buf, "000")) {
743 wprintf(_("unexpected end of message"));
744 wprintf("</I><br /><br />\n");
747 if (!strncasecmp(buf, "Content-type: ", 14)) {
748 safestrncpy(mime_content_type, &buf[14],
749 sizeof(mime_content_type));
750 for (i=0; i<strlen(mime_content_type); ++i) {
751 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
752 safestrncpy(mime_charset, &mime_content_type[i+8],
753 sizeof mime_charset);
756 for (i=0; i<strlen(mime_content_type); ++i) {
757 if (mime_content_type[i] == ';') {
758 mime_content_type[i] = 0;
764 /* Set up a character set conversion if we need to (and if we can) */
766 if ( (strcasecmp(mime_charset, "us-ascii"))
767 && (strcasecmp(mime_charset, "UTF-8")) ) {
768 ic = iconv_open("UTF-8", mime_charset);
769 if (ic == (iconv_t)(-1) ) {
770 lprintf(5, "iconv_open() failed: %s\n", strerror(errno));
775 /* Messages in legacy Citadel variformat get handled thusly... */
776 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
780 /* Boring old 80-column fixed format text gets handled this way... */
781 else if ( (!strcasecmp(mime_content_type, "text/plain"))
782 || (!strcasecmp(mime_content_type, "text")) ) {
783 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
784 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
785 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
788 if (ic != (iconv_t)(-1) ) {
790 ibuflen = strlen(ibuf);
792 obuf = (char *) malloc(obuflen);
794 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
795 osav[SIZ-obuflen] = 0;
796 safestrncpy(buf, osav, sizeof buf);
801 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
802 buf[strlen(buf) - 1] = 0;
804 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
805 wprintf("<BLOCKQUOTE>");
807 } else if ((bq == 1) &&
808 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
809 wprintf("</BLOCKQUOTE>");
815 wprintf("</TT><br />\n");
817 wprintf("</I><br />");
820 else /* HTML is fun, but we've got to strip it first */
821 if (!strcasecmp(mime_content_type, "text/html")) {
822 output_html(mime_charset);
825 /* Unknown weirdness */
827 wprintf(_("I don't know how to display %s"), mime_content_type);
828 wprintf("<br />\n", mime_content_type);
829 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
832 /* Afterwards, offer links to download attachments 'n' such */
833 if (strlen(mime_http) > 0) {
834 wprintf("%s", mime_http);
837 /* Handler for vCard parts */
838 if (strlen(vcard_partnum) > 0) {
839 part_source = load_mimepart(msgnum, vcard_partnum);
840 if (part_source != NULL) {
842 /* If it's my vCard I can edit it */
843 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
844 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
845 || (WC->wc_view == VIEW_ADDRESSBOOK)
847 wprintf("<A HREF=\"/edit_vcard?"
848 "msgnum=%ld?partnum=%s\">",
849 msgnum, vcard_partnum);
850 wprintf("[%s]</A>", _("edit"));
853 /* In all cases, display the full card */
854 display_vcard(part_source, 0, 1, NULL);
858 /* Handler for calendar parts */
859 if (strlen(cal_partnum) > 0) {
860 part_source = load_mimepart(msgnum, cal_partnum);
861 if (part_source != NULL) {
862 cal_process_attachment(part_source,
863 msgnum, cal_partnum);
873 wprintf("</TD></TR></TABLE>\n");
875 /* end everythingamundo table */
876 wprintf("</TD></TR></TABLE>\n");
877 wprintf("</div><br />\n");
880 if (ic != (iconv_t)(-1) ) {
889 * Unadorned HTML output of an individual message, suitable
890 * for placing in a hidden iframe, for printing, or whatever
892 void embed_message(void) {
898 msgnum = atol(bstr("msgnum"));
899 sourceiframe = bstr("sourceiframe");
900 targetdiv = bstr("targetdiv");
901 print_it = bstr("print_it");
903 output_headers(1, 0, 0, 0, 0, 1, 0);
906 wprintf("<html><head>");
908 /* If we're loading into a hidden iframe, chances are the caller told us
909 * about a target div somewhere that we need to copy into when we're done.
911 if (strlen(targetdiv) > 0) wprintf(
913 " <script type=\"text/javascript\"> \n"
914 " function loaded_now_copy_it() { \n"
915 " parent.document.getElementById(\"%s\").innerHTML = parent.frames['%s'].document.body.innerHTML; \n"
922 if (!strcasecmp(print_it, "yes")) wprintf(
924 " <script type=\"text/javascript\"> \n"
925 " function loaded_now_print_it() { \n"
926 " parent.frames['%s'].focus(); \n"
927 " parent.frames['%s'].print(); \n"
936 if (strlen(targetdiv) > 0) {
937 wprintf(" onLoad='loaded_now_copy_it();'");
939 if (!strcasecmp(print_it, "yes")) {
940 wprintf(" onLoad='loaded_now_print_it();'");
943 read_message(msgnum, (!strcasecmp(print_it, "yes") ? 1 : 0) );
944 wprintf("</body></html>\n");
952 * Read message in simple, JavaScript-embeddable form for 'forward'
953 * or 'reply quoted' operations.
955 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
956 * in this function. Doing so would throw a JavaScript error in the
957 * 'supplied text' argument to the editor.
959 void pullquote_message(long msgnum, int forward_attachments) {
961 char mime_partnum[256];
962 char mime_filename[256];
963 char mime_content_type[256];
964 char mime_charset[256];
965 char mime_disposition[256];
968 char *attachments = NULL;
969 int num_attachments = 0;
970 struct wc_attachment *att, *aptr;
982 iconv_t ic = (iconv_t)(-1) ;
983 char *ibuf; /* Buffer of characters to be converted */
984 char *obuf; /* Buffer for converted characters */
985 size_t ibuflen; /* Length of input buffer */
986 size_t obuflen; /* Length of output buffer */
987 char *osav; /* Saved pointer to output buffer */
993 strcpy(reply_to, "");
994 strcpy(mime_http, "");
995 strcpy(mime_content_type, "text/plain");
996 strcpy(mime_charset, "us-ascii");
998 serv_printf("MSG4 %ld", msgnum);
999 serv_getln(buf, sizeof buf);
1000 if (buf[0] != '1') {
1001 wprintf(_("ERROR:"));
1002 wprintf("%s<br />", &buf[4]);
1006 strcpy(m_subject, "");
1008 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1009 if (!strcmp(buf, "000")) {
1010 wprintf(_("unexpected end of message"));
1013 if (!strncasecmp(buf, "nhdr=yes", 8))
1017 if (!strncasecmp(buf, "type=", 5))
1018 format_type = atoi(&buf[5]);
1019 if (!strncasecmp(buf, "from=", 5)) {
1020 strcpy(from, &buf[5]);
1021 wprintf(_("from "));
1023 utf8ify_rfc822_string(from);
1027 if (!strncasecmp(buf, "subj=", 5)) {
1028 strcpy(m_subject, &buf[5]);
1030 if ((!strncasecmp(buf, "hnod=", 5))
1031 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1032 wprintf("(%s) ", &buf[5]);
1034 if ((!strncasecmp(buf, "room=", 5))
1035 && (strcasecmp(&buf[5], WC->wc_roomname))
1036 && (strlen(&buf[5])>0) ) {
1038 wprintf("%s> ", &buf[5]);
1040 if (!strncasecmp(buf, "rfca=", 5)) {
1041 strcpy(rfca, &buf[5]);
1047 if (!strncasecmp(buf, "node=", 5)) {
1048 strcpy(node, &buf[5]);
1049 if ( ((WC->room_flags & QR_NETWORK)
1050 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1051 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1052 && (strlen(rfca)==0)
1054 wprintf("@%s ", &buf[5]);
1057 if (!strncasecmp(buf, "rcpt=", 5)) {
1059 wprintf("%s ", &buf[5]);
1061 if (!strncasecmp(buf, "time=", 5)) {
1062 fmt_date(now, atol(&buf[5]), 0);
1063 wprintf("%s ", now);
1067 * Save attachment info for later. We can't start downloading them
1068 * yet because we're in the middle of a server transaction.
1070 if (!strncasecmp(buf, "part=", 5)) {
1072 attachments = realloc(attachments, (num_attachments * 1024));
1073 strcat(attachments, &buf[5]);
1074 strcat(attachments, "\n");
1082 utf8ify_rfc822_string(m_subject);
1084 if (strlen(m_subject) > 0) {
1085 wprintf(_("Subject:"));
1087 msgescputs(m_subject);
1097 * Learn the content type
1099 strcpy(mime_content_type, "text/plain");
1100 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1101 if (!strcmp(buf, "000")) {
1102 wprintf(_("unexpected end of message"));
1105 if (!strncasecmp(buf, "Content-type: ", 14)) {
1106 safestrncpy(mime_content_type, &buf[14],
1107 sizeof(mime_content_type));
1108 for (i=0; i<strlen(mime_content_type); ++i) {
1109 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1110 safestrncpy(mime_charset, &mime_content_type[i+8],
1111 sizeof mime_charset);
1114 for (i=0; i<strlen(mime_content_type); ++i) {
1115 if (mime_content_type[i] == ';') {
1116 mime_content_type[i] = 0;
1122 /* Set up a character set conversion if we need to (and if we can) */
1124 if ( (strcasecmp(mime_charset, "us-ascii"))
1125 && (strcasecmp(mime_charset, "UTF-8")) ) {
1126 ic = iconv_open("UTF-8", mime_charset);
1127 if (ic == (iconv_t)(-1) ) {
1128 lprintf(5, "iconv_open() failed: %s\n", strerror(errno));
1133 /* Messages in legacy Citadel variformat get handled thusly... */
1134 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1138 /* Boring old 80-column fixed format text gets handled this way... */
1139 else if (!strcasecmp(mime_content_type, "text/plain")) {
1140 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1141 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1142 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1145 if (ic != (iconv_t)(-1) ) {
1147 ibuflen = strlen(ibuf);
1149 obuf = (char *) malloc(obuflen);
1151 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1152 osav[SIZ-obuflen] = 0;
1153 safestrncpy(buf, osav, sizeof buf);
1158 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1159 buf[strlen(buf) - 1] = 0;
1161 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
1162 wprintf("<BLOCKQUOTE>");
1164 } else if ((bq == 1) &&
1165 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
1166 wprintf("</BLOCKQUOTE>");
1172 wprintf("</TT><br />");
1174 wprintf("</I><br />");
1177 /* HTML just gets escaped and stuffed back into the editor */
1178 else if (!strcasecmp(mime_content_type, "text/html")) {
1179 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1184 /* Unknown weirdness ... don't know how to handle this content type */
1186 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1190 /* end of body handler */
1193 * If there were attachments, we have to download them and insert them
1194 * into the attachment chain for the forwarded message we are composing.
1196 if (num_attachments) {
1197 for (i=0; i<num_attachments; ++i) {
1198 extract_token(buf, attachments, i, '\n', sizeof buf);
1199 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1200 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1201 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1202 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1203 mime_length = extract_int(buf, 5);
1206 * tracing ... uncomment if necessary
1208 lprintf(9, "fwd filename: %s\n", mime_filename);
1209 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1210 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1211 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1212 lprintf(9, "fwd length : %d\n", mime_length);
1215 if ( (!strcasecmp(mime_disposition, "inline"))
1216 || (!strcasecmp(mime_disposition, "attachment")) ) {
1218 /* Create an attachment struct from this mime part... */
1219 att = malloc(sizeof(struct wc_attachment));
1220 memset(att, 0, sizeof(struct wc_attachment));
1221 att->length = mime_length;
1222 strcpy(att->content_type, mime_content_type);
1223 strcpy(att->filename, mime_filename);
1225 att->data = load_mimepart(msgnum, mime_partnum);
1227 /* And add it to the list. */
1228 if (WC->first_attachment == NULL) {
1229 WC->first_attachment = att;
1232 aptr = WC->first_attachment;
1233 while (aptr->next != NULL) aptr = aptr->next;
1243 if (ic != (iconv_t)(-1) ) {
1254 void display_summarized(int num) {
1258 if (WC->summ[num].is_new) wprintf("<B>");
1259 wprintf("<A HREF=\"/msg?msgnum=%ld?sourceiframe=msgloader1?targetdiv=preview_pane\" target=\"msgloader1\">",
1260 WC->summ[num].msgnum);
1261 escputs(WC->summ[num].subj);
1263 if (WC->summ[num].is_new) wprintf("</B>");
1264 wprintf("</TD><TD>");
1265 if (WC->summ[num].is_new) wprintf("<B>");
1266 escputs(WC->summ[num].from);
1267 if (WC->summ[num].is_new) wprintf("</B>");
1268 wprintf(" </TD><TD>");
1269 if (WC->summ[num].is_new) wprintf("<B>");
1270 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1272 if (WC->summ[num].is_new) wprintf("</B>");
1275 "<INPUT TYPE=\"checkbox\" NAME=\"msg_%ld\" VALUE=\"yes\">"
1277 WC->summ[num].msgnum
1285 void display_addressbook(long msgnum, char alpha) {
1287 char mime_partnum[SIZ];
1288 char mime_filename[SIZ];
1289 char mime_content_type[SIZ];
1290 char mime_disposition[SIZ];
1292 char vcard_partnum[SIZ];
1293 char *vcard_source = NULL;
1294 struct message_summary summ;
1296 memset(&summ, 0, sizeof(summ));
1297 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1299 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1301 serv_getln(buf, sizeof buf);
1302 if (buf[0] != '1') return;
1304 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1305 if (!strncasecmp(buf, "part=", 5)) {
1306 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1307 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1308 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1309 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1310 mime_length = extract_int(&buf[5], 5);
1312 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1313 strcpy(vcard_partnum, mime_partnum);
1319 if (strlen(vcard_partnum) > 0) {
1320 vcard_source = load_mimepart(msgnum, vcard_partnum);
1321 if (vcard_source != NULL) {
1323 /* Display the summary line */
1324 display_vcard(vcard_source, alpha, 0, NULL);
1326 /* If it's my vCard I can edit it */
1327 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1328 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1329 || (WC->wc_view == VIEW_ADDRESSBOOK)
1331 wprintf("<A HREF=\"/edit_vcard?"
1332 "msgnum=%ld?partnum=%s\">",
1333 msgnum, vcard_partnum);
1334 wprintf("[%s]</A>", _("edit"));
1345 /* If it's an old "Firstname Lastname" style record, try to
1348 void lastfirst_firstlast(char *namebuf) {
1349 char firstname[SIZ];
1353 if (namebuf == NULL) return;
1354 if (strchr(namebuf, ';') != NULL) return;
1356 i = num_tokens(namebuf, ' ');
1359 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1360 remove_token(namebuf, i-1, ' ');
1361 strcpy(firstname, namebuf);
1362 sprintf(namebuf, "%s; %s", lastname, firstname);
1366 void fetch_ab_name(long msgnum, char *namebuf) {
1368 char mime_partnum[SIZ];
1369 char mime_filename[SIZ];
1370 char mime_content_type[SIZ];
1371 char mime_disposition[SIZ];
1373 char vcard_partnum[SIZ];
1374 char *vcard_source = NULL;
1376 struct message_summary summ;
1378 if (namebuf == NULL) return;
1379 strcpy(namebuf, "");
1381 memset(&summ, 0, sizeof(summ));
1382 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1384 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1386 serv_getln(buf, sizeof buf);
1387 if (buf[0] != '1') return;
1389 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1390 if (!strncasecmp(buf, "part=", 5)) {
1391 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1392 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1393 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1394 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1395 mime_length = extract_int(&buf[5], 5);
1397 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1398 strcpy(vcard_partnum, mime_partnum);
1404 if (strlen(vcard_partnum) > 0) {
1405 vcard_source = load_mimepart(msgnum, vcard_partnum);
1406 if (vcard_source != NULL) {
1408 /* Grab the name off the card */
1409 display_vcard(vcard_source, 0, 0, namebuf);
1415 lastfirst_firstlast(namebuf);
1417 for (i=0; i<strlen(namebuf); ++i) {
1418 if (namebuf[i] != ';') return;
1420 strcpy(namebuf, _("(no name)"));
1426 * Record compare function for sorting address book indices
1428 int abcmp(const void *ab1, const void *ab2) {
1430 (((const struct addrbookent *)ab1)->ab_name),
1431 (((const struct addrbookent *)ab2)->ab_name)
1437 * Helper function for do_addrbook_view()
1438 * Converts a name into a three-letter tab label
1440 void nametab(char *tabbuf, char *name) {
1441 stresc(tabbuf, name, 0, 0);
1442 tabbuf[0] = toupper(tabbuf[0]);
1443 tabbuf[1] = tolower(tabbuf[1]);
1444 tabbuf[2] = tolower(tabbuf[2]);
1450 * Render the address book using info we gathered during the scan
1452 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1456 static int NAMESPERPAGE = 60;
1460 char tabfirst_label[SIZ];
1462 char tablast_label[SIZ];
1466 wprintf(_("This address book is empty."));
1472 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1475 num_pages = num_ab / NAMESPERPAGE;
1477 page = atoi(bstr("page"));
1480 for (i=0; i<=num_pages; ++i) {
1482 wprintf("<A HREF=\"/readfwd?page=%d\">", i);
1487 tabfirst = i * NAMESPERPAGE;
1488 tablast = tabfirst + NAMESPERPAGE - 1;
1489 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1490 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1491 nametab(tablast_label, addrbook[tablast].ab_name);
1492 wprintf("[%s - %s]",
1493 tabfirst_label, tablast_label
1502 wprintf("<br />\n");
1504 wprintf("<TABLE border=0 cellspacing=0 "
1505 "cellpadding=3 width=100%%>\n"
1508 for (i=0; i<num_ab; ++i) {
1510 if ((i / NAMESPERPAGE) == page) {
1512 if ((displayed % 4) == 0) {
1513 if (displayed > 0) {
1517 wprintf("<TR BGCOLOR=\"#%s\">",
1518 (bg ? "DDDDDD" : "FFFFFF")
1524 wprintf("<A HREF=\"/readfwd?startmsg=%ld&is_singlecard=1",
1525 addrbook[i].ab_msgnum);
1526 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1527 vcard_n_prettyize(addrbook[i].ab_name);
1528 escputs(addrbook[i].ab_name);
1529 wprintf("</A></TD>\n");
1534 wprintf("</TR></TABLE>\n");
1540 * load message pointers from the server
1542 int load_msg_ptrs(char *servcmd, int with_headers)
1546 char displayname[128];
1553 int num_summ_alloc = 0;
1556 if (WC->num_summ != 0) {
1561 num_summ_alloc = 100;
1563 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1566 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1568 serv_getln(buf, sizeof buf);
1569 if (buf[0] != '1') {
1570 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1573 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1574 if (nummsgs < maxload) {
1575 WC->msgarr[nummsgs] = extract_long(buf, 0);
1576 datestamp = extract_long(buf, 1);
1577 extract_token(displayname, buf, 2, '|', sizeof displayname);
1578 extract_token(nodename, buf, 3, '|', sizeof nodename);
1579 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1580 extract_token(subject, buf, 5, '|', sizeof subject);
1584 if (nummsgs > num_summ_alloc) {
1585 num_summ_alloc *= 2;
1586 WC->summ = realloc(WC->summ, num_summ_alloc * sizeof(struct message_summary));
1590 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1591 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1592 safestrncpy(WC->summ[nummsgs-1].subj, _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1593 if (strlen(displayname) > 0) {
1594 safestrncpy(WC->summ[nummsgs-1].from, displayname, sizeof WC->summ[nummsgs-1].from);
1596 if (strlen(subject) > 0) {
1597 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1598 sizeof WC->summ[nummsgs-1].subj);
1601 /* Handle subjects with RFC2047 encoding */
1602 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1604 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1605 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1608 if (strlen(nodename) > 0) {
1609 if ( ((WC->room_flags & QR_NETWORK)
1610 || ((strcasecmp(nodename, serv_info.serv_nodename)
1611 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1613 strcat(WC->summ[nummsgs-1].from, " @ ");
1614 strcat(WC->summ[nummsgs-1].from, nodename);
1618 WC->summ[nummsgs-1].date = datestamp;
1621 /* Handle senders with RFC2047 encoding */
1622 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1624 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1625 strcpy(&WC->summ[nummsgs-1].from[22], "...");
1634 int summcmp_subj(const void *s1, const void *s2) {
1635 struct message_summary *summ1;
1636 struct message_summary *summ2;
1638 summ1 = (struct message_summary *)s1;
1639 summ2 = (struct message_summary *)s2;
1640 return strcasecmp(summ1->subj, summ2->subj);
1643 int summcmp_rsubj(const void *s1, const void *s2) {
1644 struct message_summary *summ1;
1645 struct message_summary *summ2;
1647 summ1 = (struct message_summary *)s1;
1648 summ2 = (struct message_summary *)s2;
1649 return strcasecmp(summ2->subj, summ1->subj);
1652 int summcmp_sender(const void *s1, const void *s2) {
1653 struct message_summary *summ1;
1654 struct message_summary *summ2;
1656 summ1 = (struct message_summary *)s1;
1657 summ2 = (struct message_summary *)s2;
1658 return strcasecmp(summ1->from, summ2->from);
1661 int summcmp_rsender(const void *s1, const void *s2) {
1662 struct message_summary *summ1;
1663 struct message_summary *summ2;
1665 summ1 = (struct message_summary *)s1;
1666 summ2 = (struct message_summary *)s2;
1667 return strcasecmp(summ2->from, summ1->from);
1670 int summcmp_date(const void *s1, const void *s2) {
1671 struct message_summary *summ1;
1672 struct message_summary *summ2;
1674 summ1 = (struct message_summary *)s1;
1675 summ2 = (struct message_summary *)s2;
1677 if (summ1->date < summ2->date) return -1;
1678 else if (summ1->date > summ2->date) return +1;
1682 int summcmp_rdate(const void *s1, const void *s2) {
1683 struct message_summary *summ1;
1684 struct message_summary *summ2;
1686 summ1 = (struct message_summary *)s1;
1687 summ2 = (struct message_summary *)s2;
1689 if (summ1->date < summ2->date) return +1;
1690 else if (summ1->date > summ2->date) return -1;
1695 * command loop for reading messages
1697 void readloop(char *oper)
1706 int num_displayed = 0;
1708 int is_addressbook = 0;
1709 int is_singlecard = 0;
1710 int is_calendar = 0;
1713 int remaining_messages;
1715 int lowest_displayed = (-1);
1716 int highest_displayed = 0;
1717 long pn_previous = 0L;
1718 long pn_current = 0L;
1721 struct addrbookent *addrbook = NULL;
1723 char *sortby = NULL;
1724 char sortpref_name[128];
1725 char sortpref_value[128];
1726 char *subjsort_button;
1727 char *sendsort_button;
1728 char *datesort_button;
1730 startmsg = atol(bstr("startmsg"));
1731 maxmsgs = atoi(bstr("maxmsgs"));
1732 is_summary = atoi(bstr("summary"));
1733 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1735 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
1736 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
1738 sortby = bstr("sortby");
1739 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
1740 set_preference(sortpref_name, sortby, 1);
1742 if (strlen(sortby) == 0) sortby = sortpref_value;
1743 if (strlen(sortby) == 0) sortby = "msgid";
1745 output_headers(1, 1, 1, 0, 0, 0, 0);
1747 /* When in summary mode, always show ALL messages instead of just
1748 * new or old. Otherwise, show what the user asked for.
1750 if (!strcmp(oper, "readnew")) {
1751 strcpy(cmd, "MSGS NEW");
1753 else if (!strcmp(oper, "readold")) {
1754 strcpy(cmd, "MSGS OLD");
1757 strcpy(cmd, "MSGS ALL");
1760 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
1762 strcpy(cmd, "MSGS ALL");
1765 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
1767 strcpy(cmd, "MSGS ALL");
1772 strcpy(cmd, "MSGS ALL|||1"); /* fetch header summary */
1777 /* Are we doing a summary view? If so, we need to know old messages
1778 * and new messages, so we can do that pretty boldface thing for the
1781 strcpy(old_msgs, "");
1784 serv_getln(buf, sizeof buf);
1785 if (buf[0] == '2') {
1786 strcpy(old_msgs, &buf[4]);
1790 is_singlecard = atoi(bstr("is_singlecard"));
1792 if (WC->wc_view == VIEW_CALENDAR) { /* calendar */
1794 strcpy(cmd, "MSGS ALL");
1797 if (WC->wc_view == VIEW_TASKS) { /* tasks */
1799 strcpy(cmd, "MSGS ALL");
1802 if (WC->wc_view == VIEW_NOTES) { /* notes */
1804 strcpy(cmd, "MSGS ALL");
1808 nummsgs = load_msg_ptrs(cmd, is_summary);
1811 if ((!is_tasks) && (!is_calendar) && (!is_notes)) {
1813 if (!strcmp(oper, "readnew")) {
1814 wprintf(_("No new messages."));
1815 } else if (!strcmp(oper, "readold")) {
1816 wprintf(_("No old messages."));
1818 wprintf(_("No messages here."));
1827 for (a = 0; a < nummsgs; ++a) {
1828 /* Are you a new message, or an old message? */
1830 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
1831 WC->summ[a].is_new = 0;
1834 WC->summ[a].is_new = 1;
1840 if (startmsg == 0L) startmsg = WC->msgarr[0];
1841 remaining_messages = 0;
1843 for (a = 0; a < nummsgs; ++a) {
1844 if (WC->msgarr[a] >= startmsg) {
1845 ++remaining_messages;
1850 if (!strcasecmp(sortby, "subject")) {
1851 qsort(WC->summ, WC->num_summ,
1852 sizeof(struct message_summary), summcmp_subj);
1854 else if (!strcasecmp(sortby, "rsubject")) {
1855 qsort(WC->summ, WC->num_summ,
1856 sizeof(struct message_summary), summcmp_rsubj);
1858 else if (!strcasecmp(sortby, "sender")) {
1859 qsort(WC->summ, WC->num_summ,
1860 sizeof(struct message_summary), summcmp_sender);
1862 else if (!strcasecmp(sortby, "rsender")) {
1863 qsort(WC->summ, WC->num_summ,
1864 sizeof(struct message_summary), summcmp_rsender);
1866 else if (!strcasecmp(sortby, "date")) {
1867 qsort(WC->summ, WC->num_summ,
1868 sizeof(struct message_summary), summcmp_date);
1870 else if (!strcasecmp(sortby, "rdate")) {
1871 qsort(WC->summ, WC->num_summ,
1872 sizeof(struct message_summary), summcmp_rdate);
1876 if (!strcasecmp(sortby, "subject")) {
1877 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1879 else if (!strcasecmp(sortby, "rsubject")) {
1880 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1883 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1886 if (!strcasecmp(sortby, "sender")) {
1887 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1889 else if (!strcasecmp(sortby, "rsender")) {
1890 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1893 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1896 if (!strcasecmp(sortby, "date")) {
1897 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1899 else if (!strcasecmp(sortby, "rdate")) {
1900 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1903 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1907 wprintf("</div>"); /* end of 'content' div */
1909 wprintf("<div id=\"message_list\">"
1911 "<div id=\"fix_scrollbar_bug\">\n"
1913 "<form name=\"msgomatic\" "
1914 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n"
1916 "<table border=0 cellspacing=0 "
1917 "cellpadding=0 width=100%%>\n"
1919 "<TD align=center><b><i>%s</i></b> %s</TD>"
1920 "<TD align=center><b><i>%s</i></b> %s</TD>"
1921 "<TD align=center><b><i>%s</i></b> %s</TD>"
1922 "<TD><INPUT TYPE=\"submit\" NAME=\"delete_button\" "
1923 "STYLE=\"font-family: Bitstream Vera Sans,Arial,Helvetica,sans-serif;"
1924 " font-size: 6pt;\" "
1925 "VALUE=\"%s\"></TD>"
1928 _("Subject"), subjsort_button,
1929 _("Sender"), sendsort_button,
1930 _("Date"), datesort_button,
1935 for (a = 0; a < nummsgs; ++a) {
1936 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
1938 /* Learn which msgs "Prev" & "Next" buttons go to */
1939 pn_current = WC->msgarr[a];
1940 if (a > 0) pn_previous = WC->msgarr[a-1];
1941 if (a < (nummsgs-1)) pn_next = WC->msgarr[a+1];
1943 /* If a tabular view, set up the line */
1946 wprintf("<TR BGCOLOR=\"#%s\">",
1947 (bg ? "DDDDDD" : "FFFFFF")
1951 /* Display the message */
1953 display_summarized(a);
1955 else if (is_addressbook) {
1956 fetch_ab_name(WC->msgarr[a], buf);
1958 addrbook = realloc(addrbook,
1959 (sizeof(struct addrbookent) * num_ab) );
1960 safestrncpy(addrbook[num_ab-1].ab_name, buf,
1961 sizeof(addrbook[num_ab-1].ab_name));
1962 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
1964 else if (is_calendar) {
1965 display_calendar(WC->msgarr[a]);
1967 else if (is_tasks) {
1968 display_task(WC->msgarr[a]);
1970 else if (is_notes) {
1971 display_note(WC->msgarr[a]);
1974 read_message(WC->msgarr[a], 0);
1977 /* If a tabular view, finish the line */
1982 if (lowest_displayed < 0) lowest_displayed = a;
1983 highest_displayed = a;
1986 --remaining_messages;
1991 wprintf("</table></form>"
1992 "</div>\n"); /* end of 'fix_scrollbar_bug' div */
1993 wprintf("</div>"); /* end of 'message_list' div */
1995 wprintf("<div id=\"ml_slider\"></div>"); /* slider */
1997 wprintf("<div id=\"preview_pane\">"); /* The preview pane will initially be empty */
2000 /* Bump these because although we're thinking in zero base, the user
2001 * is a drooling idiot and is thinking in one base.
2004 ++highest_displayed;
2006 /* If we're only looking at one message, do a prev/next thing */
2007 if (num_displayed == 1) {
2008 if ((!is_tasks) && (!is_calendar) && (!is_addressbook) && (!is_notes) && (!is_singlecard)) {
2010 wprintf("<div id=\"fix_scrollbar_bug\">"
2011 "<table border=0 width=100%% bgcolor=\"#dddddd\"><tr><td>");
2012 wprintf(_("Reading #%d of %d messages."), lowest_displayed, nummsgs);
2013 wprintf("</TD><TD ALIGN=RIGHT><FONT SIZE=+1>");
2015 if (pn_previous > 0L) {
2016 wprintf("<A HREF=\"/%s"
2027 wprintf("<A HREF=\"/%s"
2037 wprintf("<A HREF=\"/%s?startmsg=%ld"
2038 "?maxmsgs=%d?summary=1\">"
2047 wprintf("</td></tr></table></div>\n");
2052 * If we're not currently looking at ALL requested
2053 * messages, then display the selector bar
2055 if (num_displayed > 1) {
2056 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2057 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2059 wprintf("<form name=\"msgomatic\" "
2060 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n");
2062 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2064 wprintf("<select name=\"whichones\" size=\"1\" "
2065 "OnChange=\"location.href=msgomatic.whichones.options"
2066 "[selectedIndex].value\">\n");
2068 for (b=0; b<nummsgs; b = b + maxmsgs) {
2071 if (hi > nummsgs) hi = nummsgs;
2072 wprintf("<option %s value="
2077 "%d-%d</option> \n",
2078 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2085 wprintf("<option value=\"/%s?startmsg=%ld"
2086 "?maxmsgs=9999999?summary=%d\">"
2090 WC->msgarr[0], is_summary);
2092 wprintf("</select> ");
2093 wprintf(_("of %d messages."), nummsgs);
2094 wprintf("</form>\n");
2100 do_tasks_view(); /* Render the task list */
2104 do_calendar_view(); /* Render the calendar */
2107 if (is_addressbook) {
2108 do_addrbook_view(addrbook, num_ab); /* Render the address book */
2111 /* Put the data transfer hidden iframe in a hidden div, to make it *really* hidden */
2113 "<div display=\"hidden\">\n"
2114 "<iframe name=\"msgloader1\" id=\"msgloader1\" width=\"1\"></iframe>\n"
2117 /* Note: wDumpContent() will output one additional </div> tag. */
2119 if (addrbook != NULL) free(addrbook);
2121 /* free the summary */
2122 if (WC->num_summ != 0) {
2127 /* If we got here via a mailbox view and are reading a single
2128 * message, mark it as "seen." We do this after rendering the web page
2129 * so it doesn't keep the user waiting.
2131 if ( (maxmsgs == 1) && (WC->wc_view == VIEW_MAILBOX) ) {
2132 serv_printf("SEEN %ld|1", startmsg);
2133 serv_getln(buf, sizeof buf);
2139 * Back end for post_message() ... this is where the actual message
2140 * gets transmitted to the server.
2142 void post_mime_to_server(void) {
2144 int is_multipart = 0;
2146 struct wc_attachment *att;
2148 size_t encoded_length;
2150 /* RFC2045 requires this, and some clients look for it... */
2151 serv_puts("MIME-Version: 1.0");
2153 /* If there are attachments, we have to do multipart/mixed */
2154 if (WC->first_attachment != NULL) {
2159 sprintf(boundary, "---Citadel-Multipart-%s-%04x%04x---",
2160 serv_info.serv_fqdn,
2165 /* Remember, serv_printf() appends an extra newline */
2166 serv_printf("Content-type: multipart/mixed; "
2167 "boundary=\"%s\"\n", boundary);
2168 serv_printf("This is a multipart message in MIME format.\n");
2169 serv_printf("--%s", boundary);
2172 serv_puts("Content-type: text/html; charset=utf-8");
2174 serv_puts("<HTML><BODY>\n");
2175 text_to_server(bstr("msgtext"), 0);
2176 serv_puts("</BODY></HTML>\n");
2181 /* Add in the attachments */
2182 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2184 encoded_length = ((att->length * 150) / 100);
2185 encoded = malloc(encoded_length);
2186 if (encoded == NULL) break;
2187 CtdlEncodeBase64(encoded, att->data, att->length);
2189 serv_printf("--%s", boundary);
2190 serv_printf("Content-type: %s", att->content_type);
2191 serv_printf("Content-disposition: attachment; "
2192 "filename=\"%s\"", att->filename);
2193 serv_puts("Content-transfer-encoding: base64");
2195 serv_write(encoded, strlen(encoded));
2200 serv_printf("--%s--", boundary);
2208 * Post message (or don't post message)
2210 * Note regarding the "dont_post" variable:
2211 * A random value (actually, it's just a timestamp) is inserted as a hidden
2212 * field called "postseq" when the display_enter page is generated. This
2213 * value is checked when posting, using the static variable dont_post. If a
2214 * user attempts to post twice using the same dont_post value, the message is
2215 * discarded. This prevents the accidental double-saving of the same message
2216 * if the user happens to click the browser "back" button.
2218 void post_message(void)
2221 static long dont_post = (-1L);
2222 struct wc_attachment *att, *aptr;
2224 if (WC->upload_length > 0) {
2226 /* There's an attachment. Save it to this struct... */
2227 att = malloc(sizeof(struct wc_attachment));
2228 memset(att, 0, sizeof(struct wc_attachment));
2229 att->length = WC->upload_length;
2230 strcpy(att->content_type, WC->upload_content_type);
2231 strcpy(att->filename, WC->upload_filename);
2234 /* And add it to the list. */
2235 if (WC->first_attachment == NULL) {
2236 WC->first_attachment = att;
2239 aptr = WC->first_attachment;
2240 while (aptr->next != NULL) aptr = aptr->next;
2244 /* Mozilla sends a simple filename, which is what we want,
2245 * but Satan's Browser sends an entire pathname. Reduce
2246 * the path to just a filename if we need to.
2248 while (num_tokens(att->filename, '/') > 1) {
2249 remove_token(att->filename, 0, '/');
2251 while (num_tokens(att->filename, '\\') > 1) {
2252 remove_token(att->filename, 0, '\\');
2255 /* Transfer control of this memory from the upload struct
2256 * to the attachment struct.
2258 att->data = WC->upload;
2259 WC->upload_length = 0;
2265 if (strlen(bstr("cancel_button")) > 0) {
2266 sprintf(WC->ImportantMessage,
2267 _("Cancelled. Message was not posted."));
2268 } else if (strlen(bstr("attach_button")) > 0) {
2271 } else if (atol(bstr("postseq")) == dont_post) {
2272 sprintf(WC->ImportantMessage,
2273 _("Automatically cancelled because you have already "
2274 "saved this message."));
2276 sprintf(buf, "ENT0 1|%s|0|4|%s|||%s|%s",
2283 serv_getln(buf, sizeof buf);
2284 if (buf[0] == '4') {
2285 post_mime_to_server();
2286 if ( (strlen(bstr("recp")) > 0)
2287 || (strlen(bstr("cc")) > 0)
2288 || (strlen(bstr("bcc")) > 0)
2290 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2293 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2295 dont_post = atol(bstr("postseq"));
2297 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2303 free_attachments(WC);
2304 readloop("readnew");
2311 * display the message entry screen
2313 void display_enter(void)
2317 struct wc_attachment *att;
2318 int recipient_required = 0;
2319 int recipient_bad = 0;
2321 if (strlen(bstr("force_room")) > 0) {
2322 gotoroom(bstr("force_room"));
2325 /* Are we perhaps in an address book view? If so, then an "enter
2326 * message" command really means "add new entry."
2328 if (WC->wc_view == VIEW_ADDRESSBOOK) {
2329 do_edit_vcard(-1, "", "");
2333 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
2334 /* Are we perhaps in a calendar view? If so, then an "enter
2335 * message" command really means "add new calendar item."
2337 if (WC->wc_view == VIEW_CALENDAR) {
2338 display_edit_event();
2342 /* Are we perhaps in a tasks view? If so, then an "enter
2343 * message" command really means "add new task."
2345 if (WC->wc_view == VIEW_TASKS) {
2346 display_edit_task();
2352 * Otherwise proceed normally.
2353 ` * Do a custom room banner with no navbar...
2355 output_headers(1, 1, 2, 0, 0, 0, 0);
2356 wprintf("<div id=\"banner\">\n");
2357 embed_room_banner(NULL, navbar_none);
2358 wprintf("</div>\n");
2359 wprintf("<div id=\"content\">\n"
2360 "<div id=\"fix_scrollbar_bug\">"
2361 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
2363 sprintf(buf, "ENT0 0|%s|0|0||||%s|%s", bstr("recp"), bstr("cc"), bstr("bcc"));
2365 serv_getln(buf, sizeof buf);
2367 if (!strncmp(buf, "570", 3)) {
2368 recipient_required = 1;
2369 if (strlen(bstr("recp")) + strlen(bstr("cc")) + strlen(bstr("bcc")) > 0) {
2373 else if (buf[0] != '2') {
2374 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2379 fmt_date(buf, now, 0);
2380 strcat(&buf[strlen(buf)], _(" <I>from</I> "));
2381 stresc(&buf[strlen(buf)], WC->wc_username, 1, 1);
2382 if (strlen(bstr("recp")) > 0) {
2383 strcat(&buf[strlen(buf)], _(" <I>to</I> "));
2384 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
2386 strcat(&buf[strlen(buf)], _(" <I>in</I> "));
2387 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
2389 /* begin message entry screen */
2390 wprintf("<form enctype=\"multipart/form-data\" "
2391 "method=\"POST\" action=\"/post\" "
2392 "name=\"enterform\""
2393 "onSubmit=\"return submitForm();\""
2395 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2397 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2398 wprintf("%s<br>\n", buf); /* header bar */
2400 wprintf("<table border=\"0\" width=\"100%%\">\n");
2401 if (recipient_required) {
2403 wprintf("<tr><td>");
2404 wprintf("<font size=-1>");
2408 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
2409 escputs(bstr("recp"));
2410 wprintf("\" size=50 maxlength=1000 />");
2411 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
2412 wprintf("</td><td></td></tr>\n");
2414 wprintf("<tr><td>");
2415 wprintf("<font size=-1>");
2419 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
2420 escputs(bstr("cc"));
2421 wprintf("\" size=50 maxlength=1000 />");
2422 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
2423 wprintf("</td><td></td></tr>\n");
2425 wprintf("<tr><td>");
2426 wprintf("<font size=-1>");
2430 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
2431 escputs(bstr("bcc"));
2432 wprintf("\" size=50 maxlength=1000 />");
2433 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
2434 wprintf("</td><td></td></tr>\n");
2436 /* Initialize the autocomplete ajax helpers */
2437 wprintf("<script type=\"text/javascript\"> \n"
2438 " new Ajax.Autocompleter('cc_id', 'cc_name_choices', \n"
2439 " '/cc_autocomplete', {} ); \n"
2440 " new Ajax.Autocompleter('bcc_id', 'bcc_name_choices', \n"
2441 " '/bcc_autocomplete', {} ); \n"
2442 " new Ajax.Autocompleter('recp_id', 'recp_name_choices', \n"
2443 " '/recp_autocomplete', {} ); \n"
2449 wprintf("<tr><td>");
2450 wprintf("<font size=-1>");
2451 wprintf(_("Subject (optional):"));
2454 "<input type=\"text\" name=\"subject\" value=\"");
2455 escputs(bstr("subject"));
2456 wprintf("\" size=50 maxlength=70></td><td>\n");
2458 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2459 if (recipient_required) {
2460 wprintf(_("Send message"));
2462 wprintf(_("Post message"));
2465 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2466 wprintf("</td></tr></table>\n");
2468 wprintf("<center><script type=\"text/javascript\" "
2469 "src=\"static/richtext.js\"></script>\n"
2470 "<script type=\"text/javascript\">\n"
2471 "function submitForm() { \n"
2472 " updateRTE('msgtext'); \n"
2476 "initRTE(\"static/\", \"static/\", \"\"); \n"
2478 "<noscript>JavaScript must be enabled.</noscript> \n"
2479 "<script type=\"text/javascript\"> \n"
2480 "writeRichText('msgtext', '");
2481 msgescputs(bstr("msgtext"));
2482 if (atol(bstr("pullquote")) > 0L) {
2483 wprintf("<br><div align=center><i>");
2484 wprintf(_("--- forwarded message ---"));
2485 wprintf("</i></div><br>");
2486 pullquote_message(atol(bstr("pullquote")), 1);
2488 wprintf("', '96%%', '200', true, false); \n"
2489 "</script></center><br />\n");
2491 /* Enumerate any attachments which are already in place... */
2492 wprintf("<img src=\"/static/diskette_24x.gif\" border=0 "
2493 "align=middle height=16 width=16> Attachments: ");
2494 wprintf("<select name=\"which_attachment\" size=1>");
2495 for (att = WC->first_attachment; att != NULL; att = att->next) {
2496 wprintf("<option value=\"");
2497 urlescputs(att->filename);
2499 escputs(att->filename);
2500 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
2501 wprintf("</option>\n");
2503 wprintf("</select>");
2505 /* Now offer the ability to attach additional files... */
2506 wprintf(" "
2507 "Attach file: <input NAME=\"attachfile\" "
2508 "SIZE=16 TYPE=\"file\">\n "
2509 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
2511 /* Seth asked for these to be at the top *and* bottom... */
2512 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2513 if (recipient_required) {
2514 wprintf(_("Send message"));
2516 wprintf(_("Post message"));
2519 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2521 wprintf("</form>\n");
2523 wprintf("</td></tr></table></div>\n");
2524 DONE: wDumpContent(1);
2534 void delete_msg(void)
2539 msgid = atol(bstr("msgid"));
2541 output_headers(1, 1, 1, 0, 0, 0, 0);
2543 sprintf(buf, "DELE %ld", msgid);
2545 serv_getln(buf, sizeof buf);
2546 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2555 * Confirm move of a message
2557 void confirm_move_msg(void)
2563 msgid = atol(bstr("msgid"));
2565 output_headers(1, 1, 1, 0, 0, 0, 0);
2567 wprintf("<div id=\"fix_scrollbar_bug\">"
2568 "<table width=100%% border=0 bgcolor=\"#444455\"><tr><td>");
2569 wprintf("<font size=+1 color=\"#ffffff\"");
2571 wprintf(_("Confirm move of message"));
2573 wprintf("</font></td></tr></table></div>\n");
2575 wprintf("<CENTER>");
2577 wprintf(_("Move this message to:"));
2578 wprintf("<br />\n");
2580 wprintf("<form METHOD=\"POST\" ACTION=\"/move_msg\">\n");
2581 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
2585 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
2587 serv_getln(buf, sizeof buf);
2588 if (buf[0] == '1') {
2589 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2590 extract_token(targ, buf, 0, '|', sizeof targ);
2591 wprintf("<OPTION>");
2596 wprintf("</SELECT>\n");
2597 wprintf("<br />\n");
2599 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
2601 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
2602 wprintf("</form></CENTER>\n");
2604 wprintf("</CENTER>\n");
2615 msgid = atol(bstr("msgid"));
2617 output_headers(1, 1, 1, 0, 0, 0, 0);
2619 if (strlen(bstr("move_button")) > 0) {
2620 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
2622 serv_getln(buf, sizeof buf);
2623 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2626 wprintf(_("The message was not moved."));
2627 wprintf("</EM><br />\n");
2634 * This gets called when a user selects multiple messages in a summary
2635 * list and then clicks to perform a transformation of some sort on them
2636 * (such as deleting them).
2638 void do_stuff_to_msgs(void) {
2642 struct stuff_t *next;
2646 struct stuff_t *stuff = NULL;
2647 struct stuff_t *ptr;
2648 int delete_button_pressed = 0;
2651 serv_puts("MSGS ALL");
2652 serv_getln(buf, sizeof buf);
2654 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2655 ptr = malloc(sizeof(struct stuff_t));
2656 ptr->msgnum = atol(buf);
2661 if (strlen(bstr("delete_button")) > 0) {
2662 delete_button_pressed = 1;
2665 while (stuff != NULL) {
2667 sprintf(buf, "msg_%ld", stuff->msgnum);
2668 if (!strcasecmp(bstr(buf), "yes")) {
2670 if (delete_button_pressed) {
2671 serv_printf("DELE %ld", stuff->msgnum);
2672 serv_getln(buf, sizeof buf);
2682 readloop("readfwd");