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];
485 char reply_all[4096];
491 char vcard_partnum[256];
492 char cal_partnum[256];
493 char *part_source = NULL;
495 iconv_t ic = (iconv_t)(-1) ;
496 char *ibuf; /* Buffer of characters to be converted */
497 char *obuf; /* Buffer for converted characters */
498 size_t ibuflen; /* Length of input buffer */
499 size_t obuflen; /* Length of output buffer */
500 char *osav; /* Saved pointer to output buffer */
506 strcpy(reply_to, "");
507 strcpy(reply_all, "");
508 strcpy(vcard_partnum, "");
509 strcpy(cal_partnum, "");
510 strcpy(mime_http, "");
511 strcpy(mime_content_type, "text/plain");
512 strcpy(mime_charset, "us-ascii");
514 serv_printf("MSG4 %ld", msgnum);
515 serv_getln(buf, sizeof buf);
518 wprintf(_("ERROR:"));
519 wprintf("</STRONG> %s<br />\n", &buf[4]);
523 /* begin everythingamundo table */
524 wprintf("<div id=\"fix_scrollbar_bug\">\n");
525 wprintf("<table width=100%% border=1 cellspacing=0 "
526 "cellpadding=0><TR><TD>\n");
528 /* begin message header table */
529 wprintf("<TABLE WIDTH=100%% BORDER=0 CELLSPACING=0 "
530 "CELLPADDING=1 BGCOLOR=\"#CCCCCC\"><TR><TD>\n");
532 wprintf("<SPAN CLASS=\"message_header\">");
533 strcpy(m_subject, "");
536 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
537 if (!strcmp(buf, "000")) {
539 wprintf(_("unexpected end of message"));
540 wprintf("</I><br /><br />\n");
541 wprintf("</SPAN>\n");
544 if (!strncasecmp(buf, "nhdr=yes", 8))
548 if (!strncasecmp(buf, "type=", 5))
549 format_type = atoi(&buf[5]);
550 if (!strncasecmp(buf, "from=", 5)) {
551 strcpy(from, &buf[5]);
553 wprintf("<A HREF=\"/showuser?who=");
555 utf8ify_rfc822_string(from);
562 if (!strncasecmp(buf, "subj=", 5)) {
563 safestrncpy(m_subject, &buf[5], sizeof m_subject);
565 if (!strncasecmp(buf, "cccc=", 5)) {
566 safestrncpy(m_cc, &buf[5], sizeof m_cc);
567 if (strlen(reply_all) > 0) {
568 strcat(reply_all, ", ");
570 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
571 (sizeof reply_all - strlen(reply_all)) );
573 if ((!strncasecmp(buf, "hnod=", 5))
574 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
575 wprintf("(%s) ", &buf[5]);
577 if ((!strncasecmp(buf, "room=", 5))
578 && (strcasecmp(&buf[5], WC->wc_roomname))
579 && (strlen(&buf[5])>0) ) {
581 wprintf("%s> ", &buf[5]);
583 if (!strncasecmp(buf, "rfca=", 5)) {
584 strcpy(rfca, &buf[5]);
590 if (!strncasecmp(buf, "node=", 5)) {
591 strcpy(node, &buf[5]);
592 if ( ((WC->room_flags & QR_NETWORK)
593 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
594 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
597 wprintf("@%s ", &buf[5]);
600 if (!strncasecmp(buf, "rcpt=", 5)) {
604 if (strlen(reply_all) > 0) {
605 strcat(reply_all, ", ");
607 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
608 (sizeof reply_all - strlen(reply_all)) );
610 if (!strncasecmp(buf, "time=", 5)) {
611 fmt_date(now, atol(&buf[5]), 0);
615 if (!strncasecmp(buf, "part=", 5)) {
616 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
617 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
618 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
619 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
620 mime_length = extract_int(&buf[5], 5);
622 if (!strcasecmp(mime_disposition, "attachment")) {
623 snprintf(&mime_http[strlen(mime_http)],
624 (sizeof(mime_http) - strlen(mime_http) - 1),
625 "<A HREF=\"/output_mimepart?"
626 "msgnum=%ld?partnum=%s\" "
627 "TARGET=\"wc.%ld.%s\">"
628 "<IMG SRC=\"/static/diskette_24x.gif\" "
629 "BORDER=0 ALIGN=MIDDLE>\n"
630 "Part %s: %s (%s, %d bytes)</A><br />\n",
631 msgnum, mime_partnum,
632 msgnum, mime_partnum,
633 mime_partnum, mime_filename,
634 mime_content_type, mime_length);
637 if ((!strcasecmp(mime_disposition, "inline"))
638 && (!strncasecmp(mime_content_type, "image/", 6)) ){
639 snprintf(&mime_http[strlen(mime_http)],
640 (sizeof(mime_http) - strlen(mime_http) - 1),
641 "<IMG SRC=\"/output_mimepart?"
642 "msgnum=%ld?partnum=%s\">",
643 msgnum, mime_partnum);
646 /*** begin handler prep ***/
647 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
648 strcpy(vcard_partnum, mime_partnum);
651 if (!strcasecmp(mime_content_type, "text/calendar")) {
652 strcpy(cal_partnum, mime_partnum);
655 /*** end handler prep ***/
661 /* Generate a reply-to address */
662 if (strlen(rfca) > 0) {
663 strcpy(reply_to, rfca);
666 if ( (strlen(node) > 0)
667 && (strcasecmp(node, serv_info.serv_nodename))
668 && (strcasecmp(node, serv_info.serv_humannode)) ) {
669 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
673 snprintf(reply_to, sizeof(reply_to), "%s", from);
683 utf8ify_rfc822_string(m_cc);
684 utf8ify_rfc822_string(m_subject);
686 if (strlen(m_cc) > 0) {
688 "<SPAN CLASS=\"message_subject\">");
694 if (strlen(m_subject) > 0) {
696 "<SPAN CLASS=\"message_subject\">");
697 wprintf(_("Subject:"));
704 /* start msg buttons */
705 if (!suppress_buttons) {
706 wprintf("<td align=right>\n");
709 wprintf("<a href=\"/display_enter?recp=");
710 urlescputs(reply_to);
711 wprintf("?subject=");
712 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
713 urlescputs(m_subject);
714 wprintf("\">[%s]</a> ", _("Reply"));
717 if (WC->wc_view == VIEW_MAILBOX) {
718 wprintf("<a href=\"/display_enter?recp=");
719 urlescputs(reply_to);
721 urlescputs(reply_all);
722 wprintf("?subject=");
723 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
724 urlescputs(m_subject);
725 wprintf("\">[%s]</a> ", _("ReplyAll"));
729 if (WC->wc_view == VIEW_MAILBOX) {
730 wprintf("<a href=\"/display_enter?pullquote=%ld?subject=", msgnum);
731 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
732 urlescputs(m_subject);
733 wprintf("\">[%s]</a> ", _("Forward"));
736 if (WC->is_room_aide) {
738 wprintf("<a href=\"/confirm_move_msg?msgid=%ld\">[%s]</a> ",
742 wprintf("<a href=\"/delete_msg?msgid=%ld\" "
743 "onClick=\"return confirm('%s');\">"
744 "[%s]</a> ", msgnum, _("Delete this message?"), _("Delete")
748 wprintf("<a href=\"/msg?msgnum=%ld?sourceiframe=msgloader1?print_it=yes\" target=\"msgloader1\">"
749 "[%s]</a>", msgnum, _("Print"));
754 wprintf("</TR></TABLE>\n");
757 wprintf("<TABLE BORDER=0 WIDTH=100%% BGCOLOR=#FFFFFF "
758 "CELLPADDING=1 CELLSPACING=0><TR><TD>");
761 * Learn the content type
763 strcpy(mime_content_type, "text/plain");
764 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
765 if (!strcmp(buf, "000")) {
767 wprintf(_("unexpected end of message"));
768 wprintf("</I><br /><br />\n");
771 if (!strncasecmp(buf, "Content-type: ", 14)) {
772 safestrncpy(mime_content_type, &buf[14],
773 sizeof(mime_content_type));
774 for (i=0; i<strlen(mime_content_type); ++i) {
775 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
776 safestrncpy(mime_charset, &mime_content_type[i+8],
777 sizeof mime_charset);
780 for (i=0; i<strlen(mime_content_type); ++i) {
781 if (mime_content_type[i] == ';') {
782 mime_content_type[i] = 0;
788 /* Set up a character set conversion if we need to (and if we can) */
790 if ( (strcasecmp(mime_charset, "us-ascii"))
791 && (strcasecmp(mime_charset, "UTF-8")) ) {
792 ic = iconv_open("UTF-8", mime_charset);
793 if (ic == (iconv_t)(-1) ) {
794 lprintf(5, "iconv_open() failed: %s\n", strerror(errno));
799 /* Messages in legacy Citadel variformat get handled thusly... */
800 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
804 /* Boring old 80-column fixed format text gets handled this way... */
805 else if ( (!strcasecmp(mime_content_type, "text/plain"))
806 || (!strcasecmp(mime_content_type, "text")) ) {
807 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
808 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
809 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
812 if (ic != (iconv_t)(-1) ) {
814 ibuflen = strlen(ibuf);
816 obuf = (char *) malloc(obuflen);
818 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
819 osav[SIZ-obuflen] = 0;
820 safestrncpy(buf, osav, sizeof buf);
825 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
826 buf[strlen(buf) - 1] = 0;
828 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
829 wprintf("<BLOCKQUOTE>");
831 } else if ((bq == 1) &&
832 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
833 wprintf("</BLOCKQUOTE>");
839 wprintf("</TT><br />\n");
841 wprintf("</I><br />");
844 else /* HTML is fun, but we've got to strip it first */
845 if (!strcasecmp(mime_content_type, "text/html")) {
846 output_html(mime_charset);
849 /* Unknown weirdness */
851 wprintf(_("I don't know how to display %s"), mime_content_type);
852 wprintf("<br />\n", mime_content_type);
853 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
856 /* Afterwards, offer links to download attachments 'n' such */
857 if (strlen(mime_http) > 0) {
858 wprintf("%s", mime_http);
861 /* Handler for vCard parts */
862 if (strlen(vcard_partnum) > 0) {
863 part_source = load_mimepart(msgnum, vcard_partnum);
864 if (part_source != NULL) {
866 /* If it's my vCard I can edit it */
867 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
868 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
869 || (WC->wc_view == VIEW_ADDRESSBOOK)
871 wprintf("<A HREF=\"/edit_vcard?"
872 "msgnum=%ld?partnum=%s\">",
873 msgnum, vcard_partnum);
874 wprintf("[%s]</A>", _("edit"));
877 /* In all cases, display the full card */
878 display_vcard(part_source, 0, 1, NULL);
882 /* Handler for calendar parts */
883 if (strlen(cal_partnum) > 0) {
884 part_source = load_mimepart(msgnum, cal_partnum);
885 if (part_source != NULL) {
886 cal_process_attachment(part_source,
887 msgnum, cal_partnum);
897 wprintf("</TD></TR></TABLE>\n");
899 /* end everythingamundo table */
900 wprintf("</TD></TR></TABLE>\n");
901 wprintf("</div><br />\n");
904 if (ic != (iconv_t)(-1) ) {
913 * Unadorned HTML output of an individual message, suitable
914 * for placing in a hidden iframe, for printing, or whatever
916 void embed_message(void) {
922 msgnum = atol(bstr("msgnum"));
923 sourceiframe = bstr("sourceiframe");
924 targetdiv = bstr("targetdiv");
925 print_it = bstr("print_it");
927 output_headers(1, 0, 0, 0, 1, 0);
930 wprintf("<html><head>");
932 /* If we're loading into a hidden iframe, chances are the caller told us
933 * about a target div somewhere that we need to copy into when we're done.
935 if (strlen(targetdiv) > 0) wprintf(
937 " <script type=\"text/javascript\"> \n"
938 " function loaded_now_copy_it() { \n"
939 " parent.document.getElementById(\"%s\").innerHTML = parent.frames['%s'].document.body.innerHTML; \n"
946 if (!strcasecmp(print_it, "yes")) wprintf(
948 " <script type=\"text/javascript\"> \n"
949 " function loaded_now_print_it() { \n"
950 " parent.frames['%s'].focus(); \n"
951 " parent.frames['%s'].print(); \n"
960 if (strlen(targetdiv) > 0) {
961 wprintf(" onLoad='loaded_now_copy_it();'");
963 if (!strcasecmp(print_it, "yes")) {
964 wprintf(" onLoad='loaded_now_print_it();'");
967 read_message(msgnum, (!strcasecmp(print_it, "yes") ? 1 : 0) );
968 wprintf("</body></html>\n");
976 * Read message in simple, JavaScript-embeddable form for 'forward'
977 * or 'reply quoted' operations.
979 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
980 * in this function. Doing so would throw a JavaScript error in the
981 * 'supplied text' argument to the editor.
983 void pullquote_message(long msgnum, int forward_attachments) {
985 char mime_partnum[256];
986 char mime_filename[256];
987 char mime_content_type[256];
988 char mime_charset[256];
989 char mime_disposition[256];
992 char *attachments = NULL;
993 int num_attachments = 0;
994 struct wc_attachment *att, *aptr;
1001 int format_type = 0;
1006 iconv_t ic = (iconv_t)(-1) ;
1007 char *ibuf; /* Buffer of characters to be converted */
1008 char *obuf; /* Buffer for converted characters */
1009 size_t ibuflen; /* Length of input buffer */
1010 size_t obuflen; /* Length of output buffer */
1011 char *osav; /* Saved pointer to output buffer */
1017 strcpy(reply_to, "");
1018 strcpy(mime_http, "");
1019 strcpy(mime_content_type, "text/plain");
1020 strcpy(mime_charset, "us-ascii");
1022 serv_printf("MSG4 %ld", msgnum);
1023 serv_getln(buf, sizeof buf);
1024 if (buf[0] != '1') {
1025 wprintf(_("ERROR:"));
1026 wprintf("%s<br />", &buf[4]);
1030 strcpy(m_subject, "");
1032 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1033 if (!strcmp(buf, "000")) {
1034 wprintf(_("unexpected end of message"));
1037 if (!strncasecmp(buf, "nhdr=yes", 8))
1041 if (!strncasecmp(buf, "type=", 5))
1042 format_type = atoi(&buf[5]);
1043 if (!strncasecmp(buf, "from=", 5)) {
1044 strcpy(from, &buf[5]);
1045 wprintf(_("from "));
1047 utf8ify_rfc822_string(from);
1051 if (!strncasecmp(buf, "subj=", 5)) {
1052 strcpy(m_subject, &buf[5]);
1054 if ((!strncasecmp(buf, "hnod=", 5))
1055 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1056 wprintf("(%s) ", &buf[5]);
1058 if ((!strncasecmp(buf, "room=", 5))
1059 && (strcasecmp(&buf[5], WC->wc_roomname))
1060 && (strlen(&buf[5])>0) ) {
1062 wprintf("%s> ", &buf[5]);
1064 if (!strncasecmp(buf, "rfca=", 5)) {
1065 strcpy(rfca, &buf[5]);
1071 if (!strncasecmp(buf, "node=", 5)) {
1072 strcpy(node, &buf[5]);
1073 if ( ((WC->room_flags & QR_NETWORK)
1074 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1075 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1076 && (strlen(rfca)==0)
1078 wprintf("@%s ", &buf[5]);
1081 if (!strncasecmp(buf, "rcpt=", 5)) {
1083 wprintf("%s ", &buf[5]);
1085 if (!strncasecmp(buf, "time=", 5)) {
1086 fmt_date(now, atol(&buf[5]), 0);
1087 wprintf("%s ", now);
1091 * Save attachment info for later. We can't start downloading them
1092 * yet because we're in the middle of a server transaction.
1094 if (!strncasecmp(buf, "part=", 5)) {
1096 attachments = realloc(attachments, (num_attachments * 1024));
1097 strcat(attachments, &buf[5]);
1098 strcat(attachments, "\n");
1106 utf8ify_rfc822_string(m_subject);
1108 if (strlen(m_subject) > 0) {
1109 wprintf(_("Subject:"));
1111 msgescputs(m_subject);
1121 * Learn the content type
1123 strcpy(mime_content_type, "text/plain");
1124 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1125 if (!strcmp(buf, "000")) {
1126 wprintf(_("unexpected end of message"));
1129 if (!strncasecmp(buf, "Content-type: ", 14)) {
1130 safestrncpy(mime_content_type, &buf[14],
1131 sizeof(mime_content_type));
1132 for (i=0; i<strlen(mime_content_type); ++i) {
1133 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1134 safestrncpy(mime_charset, &mime_content_type[i+8],
1135 sizeof mime_charset);
1138 for (i=0; i<strlen(mime_content_type); ++i) {
1139 if (mime_content_type[i] == ';') {
1140 mime_content_type[i] = 0;
1146 /* Set up a character set conversion if we need to (and if we can) */
1148 if ( (strcasecmp(mime_charset, "us-ascii"))
1149 && (strcasecmp(mime_charset, "UTF-8")) ) {
1150 ic = iconv_open("UTF-8", mime_charset);
1151 if (ic == (iconv_t)(-1) ) {
1152 lprintf(5, "iconv_open() failed: %s\n", strerror(errno));
1157 /* Messages in legacy Citadel variformat get handled thusly... */
1158 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1162 /* Boring old 80-column fixed format text gets handled this way... */
1163 else if (!strcasecmp(mime_content_type, "text/plain")) {
1164 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1165 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1166 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1169 if (ic != (iconv_t)(-1) ) {
1171 ibuflen = strlen(ibuf);
1173 obuf = (char *) malloc(obuflen);
1175 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1176 osav[SIZ-obuflen] = 0;
1177 safestrncpy(buf, osav, sizeof buf);
1182 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1183 buf[strlen(buf) - 1] = 0;
1185 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
1186 wprintf("<BLOCKQUOTE>");
1188 } else if ((bq == 1) &&
1189 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
1190 wprintf("</BLOCKQUOTE>");
1196 wprintf("</TT><br />");
1198 wprintf("</I><br />");
1201 /* HTML just gets escaped and stuffed back into the editor */
1202 else if (!strcasecmp(mime_content_type, "text/html")) {
1203 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1208 /* Unknown weirdness ... don't know how to handle this content type */
1210 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1214 /* end of body handler */
1217 * If there were attachments, we have to download them and insert them
1218 * into the attachment chain for the forwarded message we are composing.
1220 if (num_attachments) {
1221 for (i=0; i<num_attachments; ++i) {
1222 extract_token(buf, attachments, i, '\n', sizeof buf);
1223 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1224 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1225 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1226 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1227 mime_length = extract_int(buf, 5);
1230 * tracing ... uncomment if necessary
1232 lprintf(9, "fwd filename: %s\n", mime_filename);
1233 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1234 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1235 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1236 lprintf(9, "fwd length : %d\n", mime_length);
1239 if ( (!strcasecmp(mime_disposition, "inline"))
1240 || (!strcasecmp(mime_disposition, "attachment")) ) {
1242 /* Create an attachment struct from this mime part... */
1243 att = malloc(sizeof(struct wc_attachment));
1244 memset(att, 0, sizeof(struct wc_attachment));
1245 att->length = mime_length;
1246 strcpy(att->content_type, mime_content_type);
1247 strcpy(att->filename, mime_filename);
1249 att->data = load_mimepart(msgnum, mime_partnum);
1251 /* And add it to the list. */
1252 if (WC->first_attachment == NULL) {
1253 WC->first_attachment = att;
1256 aptr = WC->first_attachment;
1257 while (aptr->next != NULL) aptr = aptr->next;
1267 if (ic != (iconv_t)(-1) ) {
1278 void display_summarized(int num) {
1282 if (WC->summ[num].is_new) wprintf("<B>");
1283 wprintf("<A HREF=\"/msg?msgnum=%ld?sourceiframe=msgloader1?targetdiv=preview_pane\" target=\"msgloader1\">",
1284 WC->summ[num].msgnum);
1285 escputs(WC->summ[num].subj);
1287 if (WC->summ[num].is_new) wprintf("</B>");
1288 wprintf("</TD><TD>");
1289 if (WC->summ[num].is_new) wprintf("<B>");
1290 escputs(WC->summ[num].from);
1291 if (WC->summ[num].is_new) wprintf("</B>");
1292 wprintf(" </TD><TD>");
1293 if (WC->summ[num].is_new) wprintf("<B>");
1294 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1296 if (WC->summ[num].is_new) wprintf("</B>");
1299 "<INPUT TYPE=\"checkbox\" NAME=\"msg_%ld\" VALUE=\"yes\">"
1301 WC->summ[num].msgnum
1309 void display_addressbook(long msgnum, char alpha) {
1311 char mime_partnum[SIZ];
1312 char mime_filename[SIZ];
1313 char mime_content_type[SIZ];
1314 char mime_disposition[SIZ];
1316 char vcard_partnum[SIZ];
1317 char *vcard_source = NULL;
1318 struct message_summary summ;
1320 memset(&summ, 0, sizeof(summ));
1321 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1323 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1325 serv_getln(buf, sizeof buf);
1326 if (buf[0] != '1') return;
1328 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1329 if (!strncasecmp(buf, "part=", 5)) {
1330 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1331 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1332 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1333 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1334 mime_length = extract_int(&buf[5], 5);
1336 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1337 strcpy(vcard_partnum, mime_partnum);
1343 if (strlen(vcard_partnum) > 0) {
1344 vcard_source = load_mimepart(msgnum, vcard_partnum);
1345 if (vcard_source != NULL) {
1347 /* Display the summary line */
1348 display_vcard(vcard_source, alpha, 0, NULL);
1350 /* If it's my vCard I can edit it */
1351 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1352 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1353 || (WC->wc_view == VIEW_ADDRESSBOOK)
1355 wprintf("<A HREF=\"/edit_vcard?"
1356 "msgnum=%ld?partnum=%s\">",
1357 msgnum, vcard_partnum);
1358 wprintf("[%s]</A>", _("edit"));
1369 /* If it's an old "Firstname Lastname" style record, try to
1372 void lastfirst_firstlast(char *namebuf) {
1373 char firstname[SIZ];
1377 if (namebuf == NULL) return;
1378 if (strchr(namebuf, ';') != NULL) return;
1380 i = num_tokens(namebuf, ' ');
1383 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1384 remove_token(namebuf, i-1, ' ');
1385 strcpy(firstname, namebuf);
1386 sprintf(namebuf, "%s; %s", lastname, firstname);
1390 void fetch_ab_name(long msgnum, char *namebuf) {
1392 char mime_partnum[SIZ];
1393 char mime_filename[SIZ];
1394 char mime_content_type[SIZ];
1395 char mime_disposition[SIZ];
1397 char vcard_partnum[SIZ];
1398 char *vcard_source = NULL;
1400 struct message_summary summ;
1402 if (namebuf == NULL) return;
1403 strcpy(namebuf, "");
1405 memset(&summ, 0, sizeof(summ));
1406 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1408 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1410 serv_getln(buf, sizeof buf);
1411 if (buf[0] != '1') return;
1413 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1414 if (!strncasecmp(buf, "part=", 5)) {
1415 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1416 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1417 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1418 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1419 mime_length = extract_int(&buf[5], 5);
1421 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1422 strcpy(vcard_partnum, mime_partnum);
1428 if (strlen(vcard_partnum) > 0) {
1429 vcard_source = load_mimepart(msgnum, vcard_partnum);
1430 if (vcard_source != NULL) {
1432 /* Grab the name off the card */
1433 display_vcard(vcard_source, 0, 0, namebuf);
1439 lastfirst_firstlast(namebuf);
1441 for (i=0; i<strlen(namebuf); ++i) {
1442 if (namebuf[i] != ';') return;
1444 strcpy(namebuf, _("(no name)"));
1450 * Record compare function for sorting address book indices
1452 int abcmp(const void *ab1, const void *ab2) {
1454 (((const struct addrbookent *)ab1)->ab_name),
1455 (((const struct addrbookent *)ab2)->ab_name)
1461 * Helper function for do_addrbook_view()
1462 * Converts a name into a three-letter tab label
1464 void nametab(char *tabbuf, char *name) {
1465 stresc(tabbuf, name, 0, 0);
1466 tabbuf[0] = toupper(tabbuf[0]);
1467 tabbuf[1] = tolower(tabbuf[1]);
1468 tabbuf[2] = tolower(tabbuf[2]);
1474 * Render the address book using info we gathered during the scan
1476 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1480 static int NAMESPERPAGE = 60;
1484 char tabfirst_label[SIZ];
1486 char tablast_label[SIZ];
1489 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1490 wprintf(_("This address book is empty."));
1491 wprintf("</i></div>\n");
1496 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1499 num_pages = num_ab / NAMESPERPAGE;
1501 page = atoi(bstr("page"));
1504 for (i=0; i<=num_pages; ++i) {
1506 wprintf("<A HREF=\"/readfwd?page=%d\">", i);
1511 tabfirst = i * NAMESPERPAGE;
1512 tablast = tabfirst + NAMESPERPAGE - 1;
1513 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1514 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1515 nametab(tablast_label, addrbook[tablast].ab_name);
1516 wprintf("[%s - %s]",
1517 tabfirst_label, tablast_label
1526 wprintf("<br />\n");
1528 wprintf("<TABLE border=0 cellspacing=0 "
1529 "cellpadding=3 width=100%%>\n"
1532 for (i=0; i<num_ab; ++i) {
1534 if ((i / NAMESPERPAGE) == page) {
1536 if ((displayed % 4) == 0) {
1537 if (displayed > 0) {
1541 wprintf("<TR BGCOLOR=\"#%s\">",
1542 (bg ? "DDDDDD" : "FFFFFF")
1548 wprintf("<A HREF=\"/readfwd?startmsg=%ld&is_singlecard=1",
1549 addrbook[i].ab_msgnum);
1550 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1551 vcard_n_prettyize(addrbook[i].ab_name);
1552 escputs(addrbook[i].ab_name);
1553 wprintf("</A></TD>\n");
1558 wprintf("</TR></TABLE>\n");
1564 * load message pointers from the server
1566 int load_msg_ptrs(char *servcmd, int with_headers)
1570 char displayname[128];
1577 int num_summ_alloc = 0;
1580 if (WC->num_summ != 0) {
1585 num_summ_alloc = 100;
1587 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1590 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1592 serv_getln(buf, sizeof buf);
1593 if (buf[0] != '1') {
1594 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1597 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1598 if (nummsgs < maxload) {
1599 WC->msgarr[nummsgs] = extract_long(buf, 0);
1600 datestamp = extract_long(buf, 1);
1601 extract_token(displayname, buf, 2, '|', sizeof displayname);
1602 extract_token(nodename, buf, 3, '|', sizeof nodename);
1603 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1604 extract_token(subject, buf, 5, '|', sizeof subject);
1608 if (nummsgs > num_summ_alloc) {
1609 num_summ_alloc *= 2;
1610 WC->summ = realloc(WC->summ, num_summ_alloc * sizeof(struct message_summary));
1614 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1615 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1616 safestrncpy(WC->summ[nummsgs-1].subj, _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1617 if (strlen(displayname) > 0) {
1618 safestrncpy(WC->summ[nummsgs-1].from, displayname, sizeof WC->summ[nummsgs-1].from);
1620 if (strlen(subject) > 0) {
1621 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1622 sizeof WC->summ[nummsgs-1].subj);
1625 /* Handle subjects with RFC2047 encoding */
1626 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1628 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1629 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1632 if (strlen(nodename) > 0) {
1633 if ( ((WC->room_flags & QR_NETWORK)
1634 || ((strcasecmp(nodename, serv_info.serv_nodename)
1635 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1637 strcat(WC->summ[nummsgs-1].from, " @ ");
1638 strcat(WC->summ[nummsgs-1].from, nodename);
1642 WC->summ[nummsgs-1].date = datestamp;
1645 /* Handle senders with RFC2047 encoding */
1646 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1648 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1649 strcpy(&WC->summ[nummsgs-1].from[22], "...");
1658 int summcmp_subj(const void *s1, const void *s2) {
1659 struct message_summary *summ1;
1660 struct message_summary *summ2;
1662 summ1 = (struct message_summary *)s1;
1663 summ2 = (struct message_summary *)s2;
1664 return strcasecmp(summ1->subj, summ2->subj);
1667 int summcmp_rsubj(const void *s1, const void *s2) {
1668 struct message_summary *summ1;
1669 struct message_summary *summ2;
1671 summ1 = (struct message_summary *)s1;
1672 summ2 = (struct message_summary *)s2;
1673 return strcasecmp(summ2->subj, summ1->subj);
1676 int summcmp_sender(const void *s1, const void *s2) {
1677 struct message_summary *summ1;
1678 struct message_summary *summ2;
1680 summ1 = (struct message_summary *)s1;
1681 summ2 = (struct message_summary *)s2;
1682 return strcasecmp(summ1->from, summ2->from);
1685 int summcmp_rsender(const void *s1, const void *s2) {
1686 struct message_summary *summ1;
1687 struct message_summary *summ2;
1689 summ1 = (struct message_summary *)s1;
1690 summ2 = (struct message_summary *)s2;
1691 return strcasecmp(summ2->from, summ1->from);
1694 int summcmp_date(const void *s1, const void *s2) {
1695 struct message_summary *summ1;
1696 struct message_summary *summ2;
1698 summ1 = (struct message_summary *)s1;
1699 summ2 = (struct message_summary *)s2;
1701 if (summ1->date < summ2->date) return -1;
1702 else if (summ1->date > summ2->date) return +1;
1706 int summcmp_rdate(const void *s1, const void *s2) {
1707 struct message_summary *summ1;
1708 struct message_summary *summ2;
1710 summ1 = (struct message_summary *)s1;
1711 summ2 = (struct message_summary *)s2;
1713 if (summ1->date < summ2->date) return +1;
1714 else if (summ1->date > summ2->date) return -1;
1719 * command loop for reading messages
1721 void readloop(char *oper)
1730 int num_displayed = 0;
1732 int is_addressbook = 0;
1733 int is_singlecard = 0;
1734 int is_calendar = 0;
1737 int remaining_messages;
1739 int lowest_displayed = (-1);
1740 int highest_displayed = 0;
1741 long pn_previous = 0L;
1742 long pn_current = 0L;
1745 struct addrbookent *addrbook = NULL;
1747 char *sortby = NULL;
1748 char sortpref_name[128];
1749 char sortpref_value[128];
1750 char *subjsort_button;
1751 char *sendsort_button;
1752 char *datesort_button;
1754 startmsg = atol(bstr("startmsg"));
1755 maxmsgs = atoi(bstr("maxmsgs"));
1756 is_summary = atoi(bstr("summary"));
1757 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1759 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
1760 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
1762 sortby = bstr("sortby");
1763 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
1764 set_preference(sortpref_name, sortby, 1);
1766 if (strlen(sortby) == 0) sortby = sortpref_value;
1767 if (strlen(sortby) == 0) sortby = "msgid";
1769 output_headers(1, 1, 1, 0, 0, 0);
1771 /* When in summary mode, always show ALL messages instead of just
1772 * new or old. Otherwise, show what the user asked for.
1774 if (!strcmp(oper, "readnew")) {
1775 strcpy(cmd, "MSGS NEW");
1777 else if (!strcmp(oper, "readold")) {
1778 strcpy(cmd, "MSGS OLD");
1781 strcpy(cmd, "MSGS ALL");
1784 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
1786 strcpy(cmd, "MSGS ALL");
1789 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
1791 strcpy(cmd, "MSGS ALL");
1796 strcpy(cmd, "MSGS ALL|||1"); /* fetch header summary */
1801 /* Are we doing a summary view? If so, we need to know old messages
1802 * and new messages, so we can do that pretty boldface thing for the
1805 strcpy(old_msgs, "");
1808 serv_getln(buf, sizeof buf);
1809 if (buf[0] == '2') {
1810 strcpy(old_msgs, &buf[4]);
1814 is_singlecard = atoi(bstr("is_singlecard"));
1816 if (WC->wc_view == VIEW_CALENDAR) { /* calendar */
1818 strcpy(cmd, "MSGS ALL");
1821 if (WC->wc_view == VIEW_TASKS) { /* tasks */
1823 strcpy(cmd, "MSGS ALL");
1826 if (WC->wc_view == VIEW_NOTES) { /* notes */
1828 strcpy(cmd, "MSGS ALL");
1832 nummsgs = load_msg_ptrs(cmd, is_summary);
1835 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
1837 if (!strcmp(oper, "readnew")) {
1838 wprintf(_("No new messages."));
1839 } else if (!strcmp(oper, "readold")) {
1840 wprintf(_("No old messages."));
1842 wprintf(_("No messages here."));
1851 for (a = 0; a < nummsgs; ++a) {
1852 /* Are you a new message, or an old message? */
1854 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
1855 WC->summ[a].is_new = 0;
1858 WC->summ[a].is_new = 1;
1864 if (startmsg == 0L) startmsg = WC->msgarr[0];
1865 remaining_messages = 0;
1867 for (a = 0; a < nummsgs; ++a) {
1868 if (WC->msgarr[a] >= startmsg) {
1869 ++remaining_messages;
1874 if (!strcasecmp(sortby, "subject")) {
1875 qsort(WC->summ, WC->num_summ,
1876 sizeof(struct message_summary), summcmp_subj);
1878 else if (!strcasecmp(sortby, "rsubject")) {
1879 qsort(WC->summ, WC->num_summ,
1880 sizeof(struct message_summary), summcmp_rsubj);
1882 else if (!strcasecmp(sortby, "sender")) {
1883 qsort(WC->summ, WC->num_summ,
1884 sizeof(struct message_summary), summcmp_sender);
1886 else if (!strcasecmp(sortby, "rsender")) {
1887 qsort(WC->summ, WC->num_summ,
1888 sizeof(struct message_summary), summcmp_rsender);
1890 else if (!strcasecmp(sortby, "date")) {
1891 qsort(WC->summ, WC->num_summ,
1892 sizeof(struct message_summary), summcmp_date);
1894 else if (!strcasecmp(sortby, "rdate")) {
1895 qsort(WC->summ, WC->num_summ,
1896 sizeof(struct message_summary), summcmp_rdate);
1900 if (!strcasecmp(sortby, "subject")) {
1901 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1903 else if (!strcasecmp(sortby, "rsubject")) {
1904 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1907 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1910 if (!strcasecmp(sortby, "sender")) {
1911 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1913 else if (!strcasecmp(sortby, "rsender")) {
1914 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1917 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1920 if (!strcasecmp(sortby, "date")) {
1921 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1923 else if (!strcasecmp(sortby, "rdate")) {
1924 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1927 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1931 wprintf("</div>"); /* end of 'content' div */
1933 wprintf("<div id=\"message_list\">"
1935 "<div id=\"fix_scrollbar_bug\">\n"
1937 "<form name=\"msgomatic\" "
1938 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n"
1940 "<table border=0 cellspacing=0 "
1941 "cellpadding=0 width=100%%>\n"
1943 "<TD align=center><b><i>%s</i></b> %s</TD>"
1944 "<TD align=center><b><i>%s</i></b> %s</TD>"
1945 "<TD align=center><b><i>%s</i></b> %s</TD>"
1946 "<TD><INPUT TYPE=\"submit\" NAME=\"delete_button\" "
1947 "STYLE=\"font-family: Bitstream Vera Sans,Arial,Helvetica,sans-serif;"
1948 " font-size: 6pt;\" "
1949 "VALUE=\"%s\"></TD>"
1952 _("Subject"), subjsort_button,
1953 _("Sender"), sendsort_button,
1954 _("Date"), datesort_button,
1959 for (a = 0; a < nummsgs; ++a) {
1960 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
1962 /* Learn which msgs "Prev" & "Next" buttons go to */
1963 pn_current = WC->msgarr[a];
1964 if (a > 0) pn_previous = WC->msgarr[a-1];
1965 if (a < (nummsgs-1)) pn_next = WC->msgarr[a+1];
1967 /* If a tabular view, set up the line */
1970 wprintf("<TR BGCOLOR=\"#%s\">",
1971 (bg ? "DDDDDD" : "FFFFFF")
1975 /* Display the message */
1977 display_summarized(a);
1979 else if (is_addressbook) {
1980 fetch_ab_name(WC->msgarr[a], buf);
1982 addrbook = realloc(addrbook,
1983 (sizeof(struct addrbookent) * num_ab) );
1984 safestrncpy(addrbook[num_ab-1].ab_name, buf,
1985 sizeof(addrbook[num_ab-1].ab_name));
1986 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
1988 else if (is_calendar) {
1989 display_calendar(WC->msgarr[a]);
1991 else if (is_tasks) {
1992 display_task(WC->msgarr[a]);
1994 else if (is_notes) {
1995 display_note(WC->msgarr[a]);
1998 read_message(WC->msgarr[a], 0);
2001 /* If a tabular view, finish the line */
2006 if (lowest_displayed < 0) lowest_displayed = a;
2007 highest_displayed = a;
2010 --remaining_messages;
2015 wprintf("</table></form>"
2016 "</div>\n"); /* end of 'fix_scrollbar_bug' div */
2017 wprintf("</div>"); /* end of 'message_list' div */
2019 wprintf("<div id=\"ml_slider\"></div>"); /* slider */
2021 wprintf("<div id=\"preview_pane\">"); /* The preview pane will initially be empty */
2024 /* Bump these because although we're thinking in zero base, the user
2025 * is a drooling idiot and is thinking in one base.
2028 ++highest_displayed;
2030 /* If we're only looking at one message, do a prev/next thing */
2031 if (num_displayed == 1) {
2032 if ((!is_tasks) && (!is_calendar) && (!is_addressbook) && (!is_notes) && (!is_singlecard)) {
2034 wprintf("<div id=\"fix_scrollbar_bug\">"
2035 "<table border=0 width=100%% bgcolor=\"#dddddd\"><tr><td>");
2036 wprintf(_("Reading #%d of %d messages."), lowest_displayed, nummsgs);
2037 wprintf("</TD><TD ALIGN=RIGHT><FONT SIZE=+1>");
2039 if (pn_previous > 0L) {
2040 wprintf("<A HREF=\"/%s"
2051 wprintf("<A HREF=\"/%s"
2061 wprintf("<A HREF=\"/%s?startmsg=%ld"
2062 "?maxmsgs=%d?summary=1\">"
2071 wprintf("</td></tr></table></div>\n");
2076 * If we're not currently looking at ALL requested
2077 * messages, then display the selector bar
2079 if (num_displayed > 1) {
2080 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2081 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2083 wprintf("<form name=\"msgomatic\" "
2084 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n");
2086 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2088 wprintf("<select name=\"whichones\" size=\"1\" "
2089 "OnChange=\"location.href=msgomatic.whichones.options"
2090 "[selectedIndex].value\">\n");
2092 for (b=0; b<nummsgs; b = b + maxmsgs) {
2095 if (hi > nummsgs) hi = nummsgs;
2096 wprintf("<option %s value="
2101 "%d-%d</option> \n",
2102 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2109 wprintf("<option value=\"/%s?startmsg=%ld"
2110 "?maxmsgs=9999999?summary=%d\">"
2114 WC->msgarr[0], is_summary);
2116 wprintf("</select> ");
2117 wprintf(_("of %d messages."), nummsgs);
2118 wprintf("</form>\n");
2124 do_tasks_view(); /* Render the task list */
2128 do_calendar_view(); /* Render the calendar */
2131 if (is_addressbook) {
2132 do_addrbook_view(addrbook, num_ab); /* Render the address book */
2135 /* Put the data transfer hidden iframe in a hidden div, to make it *really* hidden */
2137 "<div display=\"hidden\">\n"
2138 "<iframe name=\"msgloader1\" id=\"msgloader1\" width=\"1\"></iframe>\n"
2141 /* Note: wDumpContent() will output one additional </div> tag. */
2143 if (addrbook != NULL) free(addrbook);
2145 /* free the summary */
2146 if (WC->num_summ != 0) {
2151 /* If we got here via a mailbox view and are reading a single
2152 * message, mark it as "seen." We do this after rendering the web page
2153 * so it doesn't keep the user waiting.
2155 if ( (maxmsgs == 1) && (WC->wc_view == VIEW_MAILBOX) ) {
2156 serv_printf("SEEN %ld|1", startmsg);
2157 serv_getln(buf, sizeof buf);
2163 * Back end for post_message() ... this is where the actual message
2164 * gets transmitted to the server.
2166 void post_mime_to_server(void) {
2168 int is_multipart = 0;
2170 struct wc_attachment *att;
2172 size_t encoded_length;
2174 /* RFC2045 requires this, and some clients look for it... */
2175 serv_puts("MIME-Version: 1.0");
2177 /* If there are attachments, we have to do multipart/mixed */
2178 if (WC->first_attachment != NULL) {
2183 sprintf(boundary, "---Citadel-Multipart-%s-%04x%04x---",
2184 serv_info.serv_fqdn,
2189 /* Remember, serv_printf() appends an extra newline */
2190 serv_printf("Content-type: multipart/mixed; "
2191 "boundary=\"%s\"\n", boundary);
2192 serv_printf("This is a multipart message in MIME format.\n");
2193 serv_printf("--%s", boundary);
2196 serv_puts("Content-type: text/html; charset=utf-8");
2198 serv_puts("<HTML><BODY>\n");
2199 text_to_server(bstr("msgtext"), 0);
2200 serv_puts("</BODY></HTML>\n");
2205 /* Add in the attachments */
2206 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2208 encoded_length = ((att->length * 150) / 100);
2209 encoded = malloc(encoded_length);
2210 if (encoded == NULL) break;
2211 CtdlEncodeBase64(encoded, att->data, att->length);
2213 serv_printf("--%s", boundary);
2214 serv_printf("Content-type: %s", att->content_type);
2215 serv_printf("Content-disposition: attachment; "
2216 "filename=\"%s\"", att->filename);
2217 serv_puts("Content-transfer-encoding: base64");
2219 serv_write(encoded, strlen(encoded));
2224 serv_printf("--%s--", boundary);
2232 * Post message (or don't post message)
2234 * Note regarding the "dont_post" variable:
2235 * A random value (actually, it's just a timestamp) is inserted as a hidden
2236 * field called "postseq" when the display_enter page is generated. This
2237 * value is checked when posting, using the static variable dont_post. If a
2238 * user attempts to post twice using the same dont_post value, the message is
2239 * discarded. This prevents the accidental double-saving of the same message
2240 * if the user happens to click the browser "back" button.
2242 void post_message(void)
2245 static long dont_post = (-1L);
2246 struct wc_attachment *att, *aptr;
2248 if (WC->upload_length > 0) {
2250 /* There's an attachment. Save it to this struct... */
2251 att = malloc(sizeof(struct wc_attachment));
2252 memset(att, 0, sizeof(struct wc_attachment));
2253 att->length = WC->upload_length;
2254 strcpy(att->content_type, WC->upload_content_type);
2255 strcpy(att->filename, WC->upload_filename);
2258 /* And add it to the list. */
2259 if (WC->first_attachment == NULL) {
2260 WC->first_attachment = att;
2263 aptr = WC->first_attachment;
2264 while (aptr->next != NULL) aptr = aptr->next;
2268 /* Mozilla sends a simple filename, which is what we want,
2269 * but Satan's Browser sends an entire pathname. Reduce
2270 * the path to just a filename if we need to.
2272 while (num_tokens(att->filename, '/') > 1) {
2273 remove_token(att->filename, 0, '/');
2275 while (num_tokens(att->filename, '\\') > 1) {
2276 remove_token(att->filename, 0, '\\');
2279 /* Transfer control of this memory from the upload struct
2280 * to the attachment struct.
2282 att->data = WC->upload;
2283 WC->upload_length = 0;
2289 if (strlen(bstr("cancel_button")) > 0) {
2290 sprintf(WC->ImportantMessage,
2291 _("Cancelled. Message was not posted."));
2292 } else if (strlen(bstr("attach_button")) > 0) {
2295 } else if (atol(bstr("postseq")) == dont_post) {
2296 sprintf(WC->ImportantMessage,
2297 _("Automatically cancelled because you have already "
2298 "saved this message."));
2300 sprintf(buf, "ENT0 1|%s|0|4|%s|||%s|%s",
2307 serv_getln(buf, sizeof buf);
2308 if (buf[0] == '4') {
2309 post_mime_to_server();
2310 if ( (strlen(bstr("recp")) > 0)
2311 || (strlen(bstr("cc")) > 0)
2312 || (strlen(bstr("bcc")) > 0)
2314 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2317 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2319 dont_post = atol(bstr("postseq"));
2321 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2327 free_attachments(WC);
2328 readloop("readnew");
2335 * display the message entry screen
2337 void display_enter(void)
2341 struct wc_attachment *att;
2342 int recipient_required = 0;
2343 int recipient_bad = 0;
2345 if (strlen(bstr("force_room")) > 0) {
2346 gotoroom(bstr("force_room"));
2349 /* Are we perhaps in an address book view? If so, then an "enter
2350 * message" command really means "add new entry."
2352 if (WC->wc_view == VIEW_ADDRESSBOOK) {
2353 do_edit_vcard(-1, "", "");
2357 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
2358 /* Are we perhaps in a calendar view? If so, then an "enter
2359 * message" command really means "add new calendar item."
2361 if (WC->wc_view == VIEW_CALENDAR) {
2362 display_edit_event();
2366 /* Are we perhaps in a tasks view? If so, then an "enter
2367 * message" command really means "add new task."
2369 if (WC->wc_view == VIEW_TASKS) {
2370 display_edit_task();
2376 * Otherwise proceed normally.
2377 * Do a custom room banner with no navbar...
2379 output_headers(1, 1, 2, 0, 0, 0);
2380 wprintf("<div id=\"banner\">\n");
2381 embed_room_banner(NULL, navbar_none);
2382 wprintf("</div>\n");
2383 wprintf("<div id=\"content\">\n"
2384 "<div id=\"fix_scrollbar_bug\">"
2385 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
2387 /* First test to see whether this is a room that requires recipients to be entered */
2388 serv_puts("ENT0 0");
2389 serv_getln(buf, sizeof buf);
2390 if (!strncmp(buf, "570", 3)) { /* 570 means that we need a recipient here */
2391 recipient_required = 1;
2393 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
2394 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2398 /* Now check our actual recipients if there are any */
2399 if (recipient_required) {
2400 sprintf(buf, "ENT0 0|%s|0|0||||%s|%s", bstr("recp"), bstr("cc"), bstr("bcc"));
2402 serv_getln(buf, sizeof buf);
2404 if (!strncmp(buf, "570", 3)) { /* 570 means we have an invalid recipient listed */
2405 if (strlen(bstr("recp")) + strlen(bstr("cc")) + strlen(bstr("bcc")) > 0) {
2409 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
2410 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2415 /* If we got this far, we can display the message entry screen. */
2418 fmt_date(buf, now, 0);
2419 strcat(&buf[strlen(buf)], _(" <I>from</I> "));
2420 stresc(&buf[strlen(buf)], WC->wc_username, 1, 1);
2422 /* Don't need this anymore, it's in the input box below
2423 if (strlen(bstr("recp")) > 0) {
2424 strcat(&buf[strlen(buf)], _(" <I>to</I> "));
2425 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
2429 strcat(&buf[strlen(buf)], _(" <I>in</I> "));
2430 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
2432 /* begin message entry screen */
2433 wprintf("<form enctype=\"multipart/form-data\" "
2434 "method=\"POST\" action=\"/post\" "
2435 "name=\"enterform\""
2436 "onSubmit=\"return submitForm();\""
2438 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2440 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2441 wprintf("%s<br>\n", buf); /* header bar */
2443 wprintf("<table border=\"0\" width=\"100%%\">\n");
2444 if (recipient_required) {
2446 wprintf("<tr><td>");
2447 wprintf("<font size=-1>");
2451 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
2452 escputs(bstr("recp"));
2453 wprintf("\" size=50 maxlength=1000 />");
2454 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
2455 wprintf("</td><td></td></tr>\n");
2457 wprintf("<tr><td>");
2458 wprintf("<font size=-1>");
2462 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
2463 escputs(bstr("cc"));
2464 wprintf("\" size=50 maxlength=1000 />");
2465 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
2466 wprintf("</td><td></td></tr>\n");
2468 wprintf("<tr><td>");
2469 wprintf("<font size=-1>");
2473 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
2474 escputs(bstr("bcc"));
2475 wprintf("\" size=50 maxlength=1000 />");
2476 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
2477 wprintf("</td><td></td></tr>\n");
2479 /* Initialize the autocomplete ajax helpers (found in wclib.js) */
2480 wprintf("<script type=\"text/javascript\"> \n"
2481 " activate_entmsg_autocompleters(); \n"
2486 wprintf("<tr><td>");
2487 wprintf("<font size=-1>");
2488 wprintf(_("Subject (optional):"));
2491 "<input type=\"text\" name=\"subject\" value=\"");
2492 escputs(bstr("subject"));
2493 wprintf("\" size=50 maxlength=70></td><td>\n");
2495 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2496 if (recipient_required) {
2497 wprintf(_("Send message"));
2499 wprintf(_("Post message"));
2502 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2503 wprintf("</td></tr></table>\n");
2505 wprintf("<center><script type=\"text/javascript\" "
2506 "src=\"static/richtext.js\"></script>\n"
2507 "<script type=\"text/javascript\">\n"
2508 "function submitForm() { \n"
2509 " updateRTE('msgtext'); \n"
2513 "initRTE(\"static/\", \"static/\", \"\"); \n"
2515 "<noscript>JavaScript must be enabled.</noscript> \n"
2516 "<script type=\"text/javascript\"> \n"
2517 "writeRichText('msgtext', '");
2518 msgescputs(bstr("msgtext"));
2519 if (atol(bstr("pullquote")) > 0L) {
2520 wprintf("<br><div align=center><i>");
2521 wprintf(_("--- forwarded message ---"));
2522 wprintf("</i></div><br>");
2523 pullquote_message(atol(bstr("pullquote")), 1);
2525 wprintf("', '96%%', '200', true, false); \n"
2526 "</script></center><br />\n");
2528 /* Enumerate any attachments which are already in place... */
2529 wprintf("<img src=\"/static/diskette_24x.gif\" border=0 "
2530 "align=middle height=16 width=16> Attachments: ");
2531 wprintf("<select name=\"which_attachment\" size=1>");
2532 for (att = WC->first_attachment; att != NULL; att = att->next) {
2533 wprintf("<option value=\"");
2534 urlescputs(att->filename);
2536 escputs(att->filename);
2537 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
2538 wprintf("</option>\n");
2540 wprintf("</select>");
2542 /* Now offer the ability to attach additional files... */
2543 wprintf(" "
2544 "Attach file: <input NAME=\"attachfile\" "
2545 "SIZE=16 TYPE=\"file\">\n "
2546 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
2548 /* Seth asked for these to be at the top *and* bottom... */
2549 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2550 if (recipient_required) {
2551 wprintf(_("Send message"));
2553 wprintf(_("Post message"));
2556 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2558 wprintf("</form>\n");
2560 wprintf("</td></tr></table></div>\n");
2561 DONE: wDumpContent(1);
2571 void delete_msg(void)
2576 msgid = atol(bstr("msgid"));
2578 output_headers(1, 1, 1, 0, 0, 0);
2580 sprintf(buf, "DELE %ld", msgid);
2582 serv_getln(buf, sizeof buf);
2583 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2592 * Confirm move of a message
2594 void confirm_move_msg(void)
2600 msgid = atol(bstr("msgid"));
2602 output_headers(1, 1, 1, 0, 0, 0);
2604 wprintf("<div id=\"fix_scrollbar_bug\">"
2605 "<table width=100%% border=0 bgcolor=\"#444455\"><tr><td>");
2606 wprintf("<font size=+1 color=\"#ffffff\"");
2608 wprintf(_("Confirm move of message"));
2610 wprintf("</font></td></tr></table></div>\n");
2612 wprintf("<CENTER>");
2614 wprintf(_("Move this message to:"));
2615 wprintf("<br />\n");
2617 wprintf("<form METHOD=\"POST\" ACTION=\"/move_msg\">\n");
2618 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
2622 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
2624 serv_getln(buf, sizeof buf);
2625 if (buf[0] == '1') {
2626 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2627 extract_token(targ, buf, 0, '|', sizeof targ);
2628 wprintf("<OPTION>");
2633 wprintf("</SELECT>\n");
2634 wprintf("<br />\n");
2636 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
2638 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
2639 wprintf("</form></CENTER>\n");
2641 wprintf("</CENTER>\n");
2652 msgid = atol(bstr("msgid"));
2654 output_headers(1, 1, 1, 0, 0, 0);
2656 if (strlen(bstr("move_button")) > 0) {
2657 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
2659 serv_getln(buf, sizeof buf);
2660 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2663 wprintf(_("The message was not moved."));
2664 wprintf("</EM><br />\n");
2671 * This gets called when a user selects multiple messages in a summary
2672 * list and then clicks to perform a transformation of some sort on them
2673 * (such as deleting them).
2675 void do_stuff_to_msgs(void) {
2679 struct stuff_t *next;
2683 struct stuff_t *stuff = NULL;
2684 struct stuff_t *ptr;
2685 int delete_button_pressed = 0;
2688 serv_puts("MSGS ALL");
2689 serv_getln(buf, sizeof buf);
2691 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2692 ptr = malloc(sizeof(struct stuff_t));
2693 ptr->msgnum = atol(buf);
2698 if (strlen(bstr("delete_button")) > 0) {
2699 delete_button_pressed = 1;
2702 while (stuff != NULL) {
2704 sprintf(buf, "msg_%ld", stuff->msgnum);
2705 if (!strcasecmp(bstr(buf), "yes")) {
2707 if (delete_button_pressed) {
2708 serv_printf("DELE %ld", stuff->msgnum);
2709 serv_getln(buf, sizeof buf);
2719 readloop("readfwd");