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);
419 if (strlen(mailto) > 0) {
421 wprintf(_("E-mail:"));
422 wprintf("</td><td>%s</td></tr>\n", mailto);
428 wprintf("</table></div>\n");
434 * Display a textual vCard
435 * (Converts to a vCard object and then calls the actual display function)
436 * Set 'full' to nonzero to display the whole card instead of a one-liner.
437 * Or, if "storename" is non-NULL, just store the person's name in that
438 * buffer instead of displaying the card at all.
440 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
446 v = vcard_load(vcard_source);
447 if (v == NULL) return;
449 name = vcard_get_prop(v, "n", 1, 0, 0);
455 if (storename != NULL) {
456 fetchname_parsed_vcard(v, storename);
458 else if ( (alpha == 0)
459 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
460 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
462 display_parsed_vcard(v, full);
470 * I wanna SEE that message!
472 void read_message(long msgnum, int suppress_buttons) {
474 char mime_partnum[256];
475 char mime_filename[256];
476 char mime_content_type[256];
477 char mime_charset[256];
478 char mime_disposition[256];
487 char reply_all[4096];
493 char vcard_partnum[256];
494 char cal_partnum[256];
495 char *part_source = NULL;
497 iconv_t ic = (iconv_t)(-1) ;
498 char *ibuf; /* Buffer of characters to be converted */
499 char *obuf; /* Buffer for converted characters */
500 size_t ibuflen; /* Length of input buffer */
501 size_t obuflen; /* Length of output buffer */
502 char *osav; /* Saved pointer to output buffer */
508 strcpy(reply_to, "");
509 strcpy(reply_all, "");
510 strcpy(vcard_partnum, "");
511 strcpy(cal_partnum, "");
512 strcpy(mime_http, "");
513 strcpy(mime_content_type, "text/plain");
514 strcpy(mime_charset, "us-ascii");
516 serv_printf("MSG4 %ld", msgnum);
517 serv_getln(buf, sizeof buf);
520 wprintf(_("ERROR:"));
521 wprintf("</STRONG> %s<br />\n", &buf[4]);
525 /* begin everythingamundo table */
526 wprintf("<div id=\"fix_scrollbar_bug\">\n");
527 wprintf("<table width=100%% border=1 cellspacing=0 "
528 "cellpadding=0><TR><TD>\n");
530 /* begin message header table */
531 wprintf("<TABLE WIDTH=100%% BORDER=0 CELLSPACING=0 "
532 "CELLPADDING=1 BGCOLOR=\"#CCCCCC\"><TR><TD>\n");
534 wprintf("<SPAN CLASS=\"message_header\">");
535 strcpy(m_subject, "");
538 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
539 if (!strcmp(buf, "000")) {
541 wprintf(_("unexpected end of message"));
542 wprintf("</I><br /><br />\n");
543 wprintf("</SPAN>\n");
546 if (!strncasecmp(buf, "nhdr=yes", 8))
550 if (!strncasecmp(buf, "type=", 5))
551 format_type = atoi(&buf[5]);
552 if (!strncasecmp(buf, "from=", 5)) {
553 strcpy(from, &buf[5]);
555 wprintf("<A HREF=\"/showuser?who=");
557 utf8ify_rfc822_string(from);
564 if (!strncasecmp(buf, "subj=", 5)) {
565 safestrncpy(m_subject, &buf[5], sizeof m_subject);
567 if (!strncasecmp(buf, "cccc=", 5)) {
568 safestrncpy(m_cc, &buf[5], sizeof m_cc);
569 if (strlen(reply_all) > 0) {
570 strcat(reply_all, ", ");
572 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
573 (sizeof reply_all - strlen(reply_all)) );
575 if ((!strncasecmp(buf, "hnod=", 5))
576 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
577 wprintf("(%s) ", &buf[5]);
579 if ((!strncasecmp(buf, "room=", 5))
580 && (strcasecmp(&buf[5], WC->wc_roomname))
581 && (strlen(&buf[5])>0) ) {
583 wprintf("%s> ", &buf[5]);
585 if (!strncasecmp(buf, "rfca=", 5)) {
586 strcpy(rfca, &buf[5]);
592 if (!strncasecmp(buf, "node=", 5)) {
593 strcpy(node, &buf[5]);
594 if ( ((WC->room_flags & QR_NETWORK)
595 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
596 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
599 wprintf("@%s ", &buf[5]);
602 if (!strncasecmp(buf, "rcpt=", 5)) {
606 if (strlen(reply_all) > 0) {
607 strcat(reply_all, ", ");
609 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
610 (sizeof reply_all - strlen(reply_all)) );
612 if (!strncasecmp(buf, "time=", 5)) {
613 fmt_date(now, atol(&buf[5]), 0);
617 if (!strncasecmp(buf, "part=", 5)) {
618 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
619 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
620 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
621 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
622 mime_length = extract_int(&buf[5], 5);
624 if (!strcasecmp(mime_disposition, "attachment")) {
625 snprintf(&mime_http[strlen(mime_http)],
626 (sizeof(mime_http) - strlen(mime_http) - 1),
627 "<A HREF=\"/output_mimepart?"
628 "msgnum=%ld?partnum=%s\" "
629 "TARGET=\"wc.%ld.%s\">"
630 "<IMG SRC=\"/static/diskette_24x.gif\" "
631 "BORDER=0 ALIGN=MIDDLE>\n"
632 "Part %s: %s (%s, %d bytes)</A><br />\n",
633 msgnum, mime_partnum,
634 msgnum, mime_partnum,
635 mime_partnum, mime_filename,
636 mime_content_type, mime_length);
639 if ((!strcasecmp(mime_disposition, "inline"))
640 && (!strncasecmp(mime_content_type, "image/", 6)) ){
641 snprintf(&mime_http[strlen(mime_http)],
642 (sizeof(mime_http) - strlen(mime_http) - 1),
643 "<IMG SRC=\"/output_mimepart?"
644 "msgnum=%ld?partnum=%s\">",
645 msgnum, mime_partnum);
648 /*** begin handler prep ***/
649 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
650 strcpy(vcard_partnum, mime_partnum);
653 if (!strcasecmp(mime_content_type, "text/calendar")) {
654 strcpy(cal_partnum, mime_partnum);
657 /*** end handler prep ***/
663 /* Generate a reply-to address */
664 if (strlen(rfca) > 0) {
665 strcpy(reply_to, rfca);
668 if ( (strlen(node) > 0)
669 && (strcasecmp(node, serv_info.serv_nodename))
670 && (strcasecmp(node, serv_info.serv_humannode)) ) {
671 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
675 snprintf(reply_to, sizeof(reply_to), "%s", from);
685 utf8ify_rfc822_string(m_cc);
686 utf8ify_rfc822_string(m_subject);
688 if (strlen(m_cc) > 0) {
690 "<SPAN CLASS=\"message_subject\">");
696 if (strlen(m_subject) > 0) {
698 "<SPAN CLASS=\"message_subject\">");
699 wprintf(_("Subject:"));
706 /* start msg buttons */
707 if (!suppress_buttons) {
708 wprintf("<td align=right>\n");
711 wprintf("<a href=\"/display_enter?recp=");
712 urlescputs(reply_to);
713 wprintf("?subject=");
714 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
715 urlescputs(m_subject);
716 wprintf("\">[%s]</a> ", _("Reply"));
719 if (WC->wc_view == VIEW_MAILBOX) {
720 wprintf("<a href=\"/display_enter?recp=");
721 urlescputs(reply_to);
723 urlescputs(reply_all);
724 wprintf("?subject=");
725 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
726 urlescputs(m_subject);
727 wprintf("\">[%s]</a> ", _("ReplyAll"));
731 if (WC->wc_view == VIEW_MAILBOX) {
732 wprintf("<a href=\"/display_enter?pullquote=%ld?subject=", msgnum);
733 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
734 urlescputs(m_subject);
735 wprintf("\">[%s]</a> ", _("Forward"));
738 if (WC->is_room_aide) {
740 wprintf("<a href=\"/confirm_move_msg?msgid=%ld\">[%s]</a> ",
744 wprintf("<a href=\"/delete_msg?msgid=%ld\" "
745 "onClick=\"return confirm('%s');\">"
746 "[%s]</a> ", msgnum, _("Delete this message?"), _("Delete")
750 wprintf("<a href=\"/msg?msgnum=%ld?sourceiframe=msgloader1?print_it=yes\" target=\"msgloader1\">"
751 "[%s]</a>", msgnum, _("Print"));
756 wprintf("</TR></TABLE>\n");
759 wprintf("<TABLE BORDER=0 WIDTH=100%% BGCOLOR=#FFFFFF "
760 "CELLPADDING=1 CELLSPACING=0><TR><TD>");
763 * Learn the content type
765 strcpy(mime_content_type, "text/plain");
766 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
767 if (!strcmp(buf, "000")) {
769 wprintf(_("unexpected end of message"));
770 wprintf("</I><br /><br />\n");
773 if (!strncasecmp(buf, "Content-type: ", 14)) {
774 safestrncpy(mime_content_type, &buf[14],
775 sizeof(mime_content_type));
776 for (i=0; i<strlen(mime_content_type); ++i) {
777 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
778 safestrncpy(mime_charset, &mime_content_type[i+8],
779 sizeof mime_charset);
782 for (i=0; i<strlen(mime_content_type); ++i) {
783 if (mime_content_type[i] == ';') {
784 mime_content_type[i] = 0;
790 /* Set up a character set conversion if we need to (and if we can) */
792 if ( (strcasecmp(mime_charset, "us-ascii"))
793 && (strcasecmp(mime_charset, "UTF-8")) ) {
794 ic = iconv_open("UTF-8", mime_charset);
795 if (ic == (iconv_t)(-1) ) {
796 lprintf(5, "iconv_open() failed: %s\n", strerror(errno));
801 /* Messages in legacy Citadel variformat get handled thusly... */
802 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
806 /* Boring old 80-column fixed format text gets handled this way... */
807 else if ( (!strcasecmp(mime_content_type, "text/plain"))
808 || (!strcasecmp(mime_content_type, "text")) ) {
809 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
810 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
811 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
814 if (ic != (iconv_t)(-1) ) {
816 ibuflen = strlen(ibuf);
818 obuf = (char *) malloc(obuflen);
820 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
821 osav[SIZ-obuflen] = 0;
822 safestrncpy(buf, osav, sizeof buf);
827 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
828 buf[strlen(buf) - 1] = 0;
830 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
831 wprintf("<BLOCKQUOTE>");
833 } else if ((bq == 1) &&
834 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
835 wprintf("</BLOCKQUOTE>");
841 wprintf("</TT><br />\n");
843 wprintf("</I><br />");
846 else /* HTML is fun, but we've got to strip it first */
847 if (!strcasecmp(mime_content_type, "text/html")) {
848 output_html(mime_charset);
851 /* Unknown weirdness */
853 wprintf(_("I don't know how to display %s"), mime_content_type);
854 wprintf("<br />\n", mime_content_type);
855 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
858 /* Afterwards, offer links to download attachments 'n' such */
859 if (strlen(mime_http) > 0) {
860 wprintf("%s", mime_http);
863 /* Handler for vCard parts */
864 if (strlen(vcard_partnum) > 0) {
865 part_source = load_mimepart(msgnum, vcard_partnum);
866 if (part_source != NULL) {
868 /* If it's my vCard I can edit it */
869 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
870 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
871 || (WC->wc_view == VIEW_ADDRESSBOOK)
873 wprintf("<A HREF=\"/edit_vcard?"
874 "msgnum=%ld?partnum=%s\">",
875 msgnum, vcard_partnum);
876 wprintf("[%s]</A>", _("edit"));
879 /* In all cases, display the full card */
880 display_vcard(part_source, 0, 1, NULL);
884 /* Handler for calendar parts */
885 if (strlen(cal_partnum) > 0) {
886 part_source = load_mimepart(msgnum, cal_partnum);
887 if (part_source != NULL) {
888 cal_process_attachment(part_source,
889 msgnum, cal_partnum);
899 wprintf("</TD></TR></TABLE>\n");
901 /* end everythingamundo table */
902 wprintf("</TD></TR></TABLE>\n");
903 wprintf("</div><br />\n");
906 if (ic != (iconv_t)(-1) ) {
915 * Unadorned HTML output of an individual message, suitable
916 * for placing in a hidden iframe, for printing, or whatever
918 void embed_message(void) {
924 msgnum = atol(bstr("msgnum"));
925 sourceiframe = bstr("sourceiframe");
926 targetdiv = bstr("targetdiv");
927 print_it = bstr("print_it");
929 output_headers(1, 0, 0, 0, 1, 0);
932 wprintf("<html><head>");
934 /* If we're loading into a hidden iframe, chances are the caller told us
935 * about a target div somewhere that we need to copy into when we're done.
937 if (strlen(targetdiv) > 0) wprintf(
939 " <script type=\"text/javascript\"> \n"
940 " function loaded_now_copy_it() { \n"
941 " parent.document.getElementById(\"%s\").innerHTML = parent.frames['%s'].document.body.innerHTML; \n"
948 if (!strcasecmp(print_it, "yes")) wprintf(
950 " <script type=\"text/javascript\"> \n"
951 " function loaded_now_print_it() { \n"
952 " parent.frames['%s'].focus(); \n"
953 " parent.frames['%s'].print(); \n"
962 if (strlen(targetdiv) > 0) {
963 wprintf(" onLoad='loaded_now_copy_it();'");
965 if (!strcasecmp(print_it, "yes")) {
966 wprintf(" onLoad='loaded_now_print_it();'");
969 read_message(msgnum, (!strcasecmp(print_it, "yes") ? 1 : 0) );
970 wprintf("</body></html>\n");
978 * Read message in simple, JavaScript-embeddable form for 'forward'
979 * or 'reply quoted' operations.
981 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
982 * in this function. Doing so would throw a JavaScript error in the
983 * 'supplied text' argument to the editor.
985 void pullquote_message(long msgnum, int forward_attachments) {
987 char mime_partnum[256];
988 char mime_filename[256];
989 char mime_content_type[256];
990 char mime_charset[256];
991 char mime_disposition[256];
994 char *attachments = NULL;
995 int num_attachments = 0;
996 struct wc_attachment *att, *aptr;
1003 int format_type = 0;
1008 iconv_t ic = (iconv_t)(-1) ;
1009 char *ibuf; /* Buffer of characters to be converted */
1010 char *obuf; /* Buffer for converted characters */
1011 size_t ibuflen; /* Length of input buffer */
1012 size_t obuflen; /* Length of output buffer */
1013 char *osav; /* Saved pointer to output buffer */
1019 strcpy(reply_to, "");
1020 strcpy(mime_http, "");
1021 strcpy(mime_content_type, "text/plain");
1022 strcpy(mime_charset, "us-ascii");
1024 serv_printf("MSG4 %ld", msgnum);
1025 serv_getln(buf, sizeof buf);
1026 if (buf[0] != '1') {
1027 wprintf(_("ERROR:"));
1028 wprintf("%s<br />", &buf[4]);
1032 strcpy(m_subject, "");
1034 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1035 if (!strcmp(buf, "000")) {
1036 wprintf(_("unexpected end of message"));
1039 if (!strncasecmp(buf, "nhdr=yes", 8))
1043 if (!strncasecmp(buf, "type=", 5))
1044 format_type = atoi(&buf[5]);
1045 if (!strncasecmp(buf, "from=", 5)) {
1046 strcpy(from, &buf[5]);
1047 wprintf(_("from "));
1049 utf8ify_rfc822_string(from);
1053 if (!strncasecmp(buf, "subj=", 5)) {
1054 strcpy(m_subject, &buf[5]);
1056 if ((!strncasecmp(buf, "hnod=", 5))
1057 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1058 wprintf("(%s) ", &buf[5]);
1060 if ((!strncasecmp(buf, "room=", 5))
1061 && (strcasecmp(&buf[5], WC->wc_roomname))
1062 && (strlen(&buf[5])>0) ) {
1064 wprintf("%s> ", &buf[5]);
1066 if (!strncasecmp(buf, "rfca=", 5)) {
1067 strcpy(rfca, &buf[5]);
1073 if (!strncasecmp(buf, "node=", 5)) {
1074 strcpy(node, &buf[5]);
1075 if ( ((WC->room_flags & QR_NETWORK)
1076 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1077 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1078 && (strlen(rfca)==0)
1080 wprintf("@%s ", &buf[5]);
1083 if (!strncasecmp(buf, "rcpt=", 5)) {
1085 wprintf("%s ", &buf[5]);
1087 if (!strncasecmp(buf, "time=", 5)) {
1088 fmt_date(now, atol(&buf[5]), 0);
1089 wprintf("%s ", now);
1093 * Save attachment info for later. We can't start downloading them
1094 * yet because we're in the middle of a server transaction.
1096 if (!strncasecmp(buf, "part=", 5)) {
1098 attachments = realloc(attachments, (num_attachments * 1024));
1099 strcat(attachments, &buf[5]);
1100 strcat(attachments, "\n");
1108 utf8ify_rfc822_string(m_subject);
1110 if (strlen(m_subject) > 0) {
1111 wprintf(_("Subject:"));
1113 msgescputs(m_subject);
1123 * Learn the content type
1125 strcpy(mime_content_type, "text/plain");
1126 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1127 if (!strcmp(buf, "000")) {
1128 wprintf(_("unexpected end of message"));
1131 if (!strncasecmp(buf, "Content-type: ", 14)) {
1132 safestrncpy(mime_content_type, &buf[14],
1133 sizeof(mime_content_type));
1134 for (i=0; i<strlen(mime_content_type); ++i) {
1135 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1136 safestrncpy(mime_charset, &mime_content_type[i+8],
1137 sizeof mime_charset);
1140 for (i=0; i<strlen(mime_content_type); ++i) {
1141 if (mime_content_type[i] == ';') {
1142 mime_content_type[i] = 0;
1148 /* Set up a character set conversion if we need to (and if we can) */
1150 if ( (strcasecmp(mime_charset, "us-ascii"))
1151 && (strcasecmp(mime_charset, "UTF-8")) ) {
1152 ic = iconv_open("UTF-8", mime_charset);
1153 if (ic == (iconv_t)(-1) ) {
1154 lprintf(5, "iconv_open() failed: %s\n", strerror(errno));
1159 /* Messages in legacy Citadel variformat get handled thusly... */
1160 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1164 /* Boring old 80-column fixed format text gets handled this way... */
1165 else if (!strcasecmp(mime_content_type, "text/plain")) {
1166 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1167 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1168 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1171 if (ic != (iconv_t)(-1) ) {
1173 ibuflen = strlen(ibuf);
1175 obuf = (char *) malloc(obuflen);
1177 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1178 osav[SIZ-obuflen] = 0;
1179 safestrncpy(buf, osav, sizeof buf);
1184 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1185 buf[strlen(buf) - 1] = 0;
1187 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
1188 wprintf("<BLOCKQUOTE>");
1190 } else if ((bq == 1) &&
1191 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
1192 wprintf("</BLOCKQUOTE>");
1198 wprintf("</TT><br />");
1200 wprintf("</I><br />");
1203 /* HTML just gets escaped and stuffed back into the editor */
1204 else if (!strcasecmp(mime_content_type, "text/html")) {
1205 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1210 /* Unknown weirdness ... don't know how to handle this content type */
1212 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1216 /* end of body handler */
1219 * If there were attachments, we have to download them and insert them
1220 * into the attachment chain for the forwarded message we are composing.
1222 if (num_attachments) {
1223 for (i=0; i<num_attachments; ++i) {
1224 extract_token(buf, attachments, i, '\n', sizeof buf);
1225 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1226 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1227 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1228 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1229 mime_length = extract_int(buf, 5);
1232 * tracing ... uncomment if necessary
1234 lprintf(9, "fwd filename: %s\n", mime_filename);
1235 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1236 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1237 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1238 lprintf(9, "fwd length : %d\n", mime_length);
1241 if ( (!strcasecmp(mime_disposition, "inline"))
1242 || (!strcasecmp(mime_disposition, "attachment")) ) {
1244 /* Create an attachment struct from this mime part... */
1245 att = malloc(sizeof(struct wc_attachment));
1246 memset(att, 0, sizeof(struct wc_attachment));
1247 att->length = mime_length;
1248 strcpy(att->content_type, mime_content_type);
1249 strcpy(att->filename, mime_filename);
1251 att->data = load_mimepart(msgnum, mime_partnum);
1253 /* And add it to the list. */
1254 if (WC->first_attachment == NULL) {
1255 WC->first_attachment = att;
1258 aptr = WC->first_attachment;
1259 while (aptr->next != NULL) aptr = aptr->next;
1269 if (ic != (iconv_t)(-1) ) {
1280 void display_summarized(int num) {
1284 if (WC->summ[num].is_new) wprintf("<B>");
1285 wprintf("<A HREF=\"/msg?msgnum=%ld?sourceiframe=msgloader1?targetdiv=preview_pane\" target=\"msgloader1\">",
1286 WC->summ[num].msgnum);
1287 escputs(WC->summ[num].subj);
1289 if (WC->summ[num].is_new) wprintf("</B>");
1290 wprintf("</TD><TD>");
1291 if (WC->summ[num].is_new) wprintf("<B>");
1292 escputs(WC->summ[num].from);
1293 if (WC->summ[num].is_new) wprintf("</B>");
1294 wprintf(" </TD><TD>");
1295 if (WC->summ[num].is_new) wprintf("<B>");
1296 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1298 if (WC->summ[num].is_new) wprintf("</B>");
1301 "<INPUT TYPE=\"checkbox\" NAME=\"msg_%ld\" VALUE=\"yes\">"
1303 WC->summ[num].msgnum
1311 void display_addressbook(long msgnum, char alpha) {
1313 char mime_partnum[SIZ];
1314 char mime_filename[SIZ];
1315 char mime_content_type[SIZ];
1316 char mime_disposition[SIZ];
1318 char vcard_partnum[SIZ];
1319 char *vcard_source = NULL;
1320 struct message_summary summ;
1322 memset(&summ, 0, sizeof(summ));
1323 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1325 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1327 serv_getln(buf, sizeof buf);
1328 if (buf[0] != '1') return;
1330 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1331 if (!strncasecmp(buf, "part=", 5)) {
1332 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1333 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1334 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1335 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1336 mime_length = extract_int(&buf[5], 5);
1338 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1339 strcpy(vcard_partnum, mime_partnum);
1345 if (strlen(vcard_partnum) > 0) {
1346 vcard_source = load_mimepart(msgnum, vcard_partnum);
1347 if (vcard_source != NULL) {
1349 /* Display the summary line */
1350 display_vcard(vcard_source, alpha, 0, NULL);
1352 /* If it's my vCard I can edit it */
1353 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1354 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1355 || (WC->wc_view == VIEW_ADDRESSBOOK)
1357 wprintf("<A HREF=\"/edit_vcard?"
1358 "msgnum=%ld?partnum=%s\">",
1359 msgnum, vcard_partnum);
1360 wprintf("[%s]</A>", _("edit"));
1371 /* If it's an old "Firstname Lastname" style record, try to
1374 void lastfirst_firstlast(char *namebuf) {
1375 char firstname[SIZ];
1379 if (namebuf == NULL) return;
1380 if (strchr(namebuf, ';') != NULL) return;
1382 i = num_tokens(namebuf, ' ');
1385 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1386 remove_token(namebuf, i-1, ' ');
1387 strcpy(firstname, namebuf);
1388 sprintf(namebuf, "%s; %s", lastname, firstname);
1392 void fetch_ab_name(long msgnum, char *namebuf) {
1394 char mime_partnum[SIZ];
1395 char mime_filename[SIZ];
1396 char mime_content_type[SIZ];
1397 char mime_disposition[SIZ];
1399 char vcard_partnum[SIZ];
1400 char *vcard_source = NULL;
1402 struct message_summary summ;
1404 if (namebuf == NULL) return;
1405 strcpy(namebuf, "");
1407 memset(&summ, 0, sizeof(summ));
1408 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1410 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1412 serv_getln(buf, sizeof buf);
1413 if (buf[0] != '1') return;
1415 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1416 if (!strncasecmp(buf, "part=", 5)) {
1417 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1418 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1419 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1420 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1421 mime_length = extract_int(&buf[5], 5);
1423 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1424 strcpy(vcard_partnum, mime_partnum);
1430 if (strlen(vcard_partnum) > 0) {
1431 vcard_source = load_mimepart(msgnum, vcard_partnum);
1432 if (vcard_source != NULL) {
1434 /* Grab the name off the card */
1435 display_vcard(vcard_source, 0, 0, namebuf);
1441 lastfirst_firstlast(namebuf);
1443 for (i=0; i<strlen(namebuf); ++i) {
1444 if (namebuf[i] != ';') return;
1446 strcpy(namebuf, _("(no name)"));
1452 * Record compare function for sorting address book indices
1454 int abcmp(const void *ab1, const void *ab2) {
1456 (((const struct addrbookent *)ab1)->ab_name),
1457 (((const struct addrbookent *)ab2)->ab_name)
1463 * Helper function for do_addrbook_view()
1464 * Converts a name into a three-letter tab label
1466 void nametab(char *tabbuf, char *name) {
1467 stresc(tabbuf, name, 0, 0);
1468 tabbuf[0] = toupper(tabbuf[0]);
1469 tabbuf[1] = tolower(tabbuf[1]);
1470 tabbuf[2] = tolower(tabbuf[2]);
1476 * Render the address book using info we gathered during the scan
1478 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1482 static int NAMESPERPAGE = 60;
1486 char tabfirst_label[SIZ];
1488 char tablast_label[SIZ];
1491 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1492 wprintf(_("This address book is empty."));
1493 wprintf("</i></div>\n");
1498 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1501 num_pages = num_ab / NAMESPERPAGE;
1503 page = atoi(bstr("page"));
1506 for (i=0; i<=num_pages; ++i) {
1508 wprintf("<A HREF=\"/readfwd?page=%d\">", i);
1513 tabfirst = i * NAMESPERPAGE;
1514 tablast = tabfirst + NAMESPERPAGE - 1;
1515 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1516 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1517 nametab(tablast_label, addrbook[tablast].ab_name);
1518 wprintf("[%s - %s]",
1519 tabfirst_label, tablast_label
1528 wprintf("<br />\n");
1530 wprintf("<TABLE border=0 cellspacing=0 "
1531 "cellpadding=3 width=100%%>\n"
1534 for (i=0; i<num_ab; ++i) {
1536 if ((i / NAMESPERPAGE) == page) {
1538 if ((displayed % 4) == 0) {
1539 if (displayed > 0) {
1543 wprintf("<TR BGCOLOR=\"#%s\">",
1544 (bg ? "DDDDDD" : "FFFFFF")
1550 wprintf("<A HREF=\"/readfwd?startmsg=%ld&is_singlecard=1",
1551 addrbook[i].ab_msgnum);
1552 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1553 vcard_n_prettyize(addrbook[i].ab_name);
1554 escputs(addrbook[i].ab_name);
1555 wprintf("</A></TD>\n");
1560 wprintf("</TR></TABLE>\n");
1566 * load message pointers from the server
1568 int load_msg_ptrs(char *servcmd, int with_headers)
1572 char displayname[128];
1579 int num_summ_alloc = 0;
1582 if (WC->num_summ != 0) {
1587 num_summ_alloc = 100;
1589 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1592 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1594 serv_getln(buf, sizeof buf);
1595 if (buf[0] != '1') {
1596 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1599 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1600 if (nummsgs < maxload) {
1601 WC->msgarr[nummsgs] = extract_long(buf, 0);
1602 datestamp = extract_long(buf, 1);
1603 extract_token(displayname, buf, 2, '|', sizeof displayname);
1604 extract_token(nodename, buf, 3, '|', sizeof nodename);
1605 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1606 extract_token(subject, buf, 5, '|', sizeof subject);
1610 if (nummsgs > num_summ_alloc) {
1611 num_summ_alloc *= 2;
1612 WC->summ = realloc(WC->summ, num_summ_alloc * sizeof(struct message_summary));
1616 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1617 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1618 safestrncpy(WC->summ[nummsgs-1].subj, _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1619 if (strlen(displayname) > 0) {
1620 safestrncpy(WC->summ[nummsgs-1].from, displayname, sizeof WC->summ[nummsgs-1].from);
1622 if (strlen(subject) > 0) {
1623 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1624 sizeof WC->summ[nummsgs-1].subj);
1627 /* Handle subjects with RFC2047 encoding */
1628 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1630 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1631 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1634 if (strlen(nodename) > 0) {
1635 if ( ((WC->room_flags & QR_NETWORK)
1636 || ((strcasecmp(nodename, serv_info.serv_nodename)
1637 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1639 strcat(WC->summ[nummsgs-1].from, " @ ");
1640 strcat(WC->summ[nummsgs-1].from, nodename);
1644 WC->summ[nummsgs-1].date = datestamp;
1647 /* Handle senders with RFC2047 encoding */
1648 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1650 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1651 strcpy(&WC->summ[nummsgs-1].from[22], "...");
1660 int summcmp_subj(const void *s1, const void *s2) {
1661 struct message_summary *summ1;
1662 struct message_summary *summ2;
1664 summ1 = (struct message_summary *)s1;
1665 summ2 = (struct message_summary *)s2;
1666 return strcasecmp(summ1->subj, summ2->subj);
1669 int summcmp_rsubj(const void *s1, const void *s2) {
1670 struct message_summary *summ1;
1671 struct message_summary *summ2;
1673 summ1 = (struct message_summary *)s1;
1674 summ2 = (struct message_summary *)s2;
1675 return strcasecmp(summ2->subj, summ1->subj);
1678 int summcmp_sender(const void *s1, const void *s2) {
1679 struct message_summary *summ1;
1680 struct message_summary *summ2;
1682 summ1 = (struct message_summary *)s1;
1683 summ2 = (struct message_summary *)s2;
1684 return strcasecmp(summ1->from, summ2->from);
1687 int summcmp_rsender(const void *s1, const void *s2) {
1688 struct message_summary *summ1;
1689 struct message_summary *summ2;
1691 summ1 = (struct message_summary *)s1;
1692 summ2 = (struct message_summary *)s2;
1693 return strcasecmp(summ2->from, summ1->from);
1696 int summcmp_date(const void *s1, const void *s2) {
1697 struct message_summary *summ1;
1698 struct message_summary *summ2;
1700 summ1 = (struct message_summary *)s1;
1701 summ2 = (struct message_summary *)s2;
1703 if (summ1->date < summ2->date) return -1;
1704 else if (summ1->date > summ2->date) return +1;
1708 int summcmp_rdate(const void *s1, const void *s2) {
1709 struct message_summary *summ1;
1710 struct message_summary *summ2;
1712 summ1 = (struct message_summary *)s1;
1713 summ2 = (struct message_summary *)s2;
1715 if (summ1->date < summ2->date) return +1;
1716 else if (summ1->date > summ2->date) return -1;
1721 * command loop for reading messages
1723 void readloop(char *oper)
1732 int num_displayed = 0;
1734 int is_addressbook = 0;
1735 int is_singlecard = 0;
1736 int is_calendar = 0;
1739 int remaining_messages;
1741 int lowest_displayed = (-1);
1742 int highest_displayed = 0;
1743 long pn_previous = 0L;
1744 long pn_current = 0L;
1747 struct addrbookent *addrbook = NULL;
1749 char *sortby = NULL;
1750 char sortpref_name[128];
1751 char sortpref_value[128];
1752 char *subjsort_button;
1753 char *sendsort_button;
1754 char *datesort_button;
1756 startmsg = atol(bstr("startmsg"));
1757 maxmsgs = atoi(bstr("maxmsgs"));
1758 is_summary = atoi(bstr("summary"));
1759 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1761 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
1762 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
1764 sortby = bstr("sortby");
1765 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
1766 set_preference(sortpref_name, sortby, 1);
1768 if (strlen(sortby) == 0) sortby = sortpref_value;
1769 if (strlen(sortby) == 0) sortby = "msgid";
1771 output_headers(1, 1, 1, 0, 0, 0);
1773 /* When in summary mode, always show ALL messages instead of just
1774 * new or old. Otherwise, show what the user asked for.
1776 if (!strcmp(oper, "readnew")) {
1777 strcpy(cmd, "MSGS NEW");
1779 else if (!strcmp(oper, "readold")) {
1780 strcpy(cmd, "MSGS OLD");
1783 strcpy(cmd, "MSGS ALL");
1786 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
1788 strcpy(cmd, "MSGS ALL");
1791 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
1793 strcpy(cmd, "MSGS ALL");
1798 strcpy(cmd, "MSGS ALL|||1"); /* fetch header summary */
1803 /* Are we doing a summary view? If so, we need to know old messages
1804 * and new messages, so we can do that pretty boldface thing for the
1807 strcpy(old_msgs, "");
1810 serv_getln(buf, sizeof buf);
1811 if (buf[0] == '2') {
1812 strcpy(old_msgs, &buf[4]);
1816 is_singlecard = atoi(bstr("is_singlecard"));
1818 if (WC->wc_view == VIEW_CALENDAR) { /* calendar */
1820 strcpy(cmd, "MSGS ALL");
1823 if (WC->wc_view == VIEW_TASKS) { /* tasks */
1825 strcpy(cmd, "MSGS ALL");
1828 if (WC->wc_view == VIEW_NOTES) { /* notes */
1830 strcpy(cmd, "MSGS ALL");
1834 nummsgs = load_msg_ptrs(cmd, is_summary);
1837 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
1839 if (!strcmp(oper, "readnew")) {
1840 wprintf(_("No new messages."));
1841 } else if (!strcmp(oper, "readold")) {
1842 wprintf(_("No old messages."));
1844 wprintf(_("No messages here."));
1853 for (a = 0; a < nummsgs; ++a) {
1854 /* Are you a new message, or an old message? */
1856 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
1857 WC->summ[a].is_new = 0;
1860 WC->summ[a].is_new = 1;
1866 if (startmsg == 0L) startmsg = WC->msgarr[0];
1867 remaining_messages = 0;
1869 for (a = 0; a < nummsgs; ++a) {
1870 if (WC->msgarr[a] >= startmsg) {
1871 ++remaining_messages;
1876 if (!strcasecmp(sortby, "subject")) {
1877 qsort(WC->summ, WC->num_summ,
1878 sizeof(struct message_summary), summcmp_subj);
1880 else if (!strcasecmp(sortby, "rsubject")) {
1881 qsort(WC->summ, WC->num_summ,
1882 sizeof(struct message_summary), summcmp_rsubj);
1884 else if (!strcasecmp(sortby, "sender")) {
1885 qsort(WC->summ, WC->num_summ,
1886 sizeof(struct message_summary), summcmp_sender);
1888 else if (!strcasecmp(sortby, "rsender")) {
1889 qsort(WC->summ, WC->num_summ,
1890 sizeof(struct message_summary), summcmp_rsender);
1892 else if (!strcasecmp(sortby, "date")) {
1893 qsort(WC->summ, WC->num_summ,
1894 sizeof(struct message_summary), summcmp_date);
1896 else if (!strcasecmp(sortby, "rdate")) {
1897 qsort(WC->summ, WC->num_summ,
1898 sizeof(struct message_summary), summcmp_rdate);
1902 if (!strcasecmp(sortby, "subject")) {
1903 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1905 else if (!strcasecmp(sortby, "rsubject")) {
1906 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1909 subjsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1912 if (!strcasecmp(sortby, "sender")) {
1913 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1915 else if (!strcasecmp(sortby, "rsender")) {
1916 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1919 sendsort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1922 if (!strcasecmp(sortby, "date")) {
1923 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"/static/down_pointer.gif\" /></a>" ;
1925 else if (!strcasecmp(sortby, "rdate")) {
1926 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/up_pointer.gif\" /></a>" ;
1929 datesort_button = "<a href=\"/readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"/static/sort_none.gif\" /></a>" ;
1933 wprintf("</div>"); /* end of 'content' div */
1935 wprintf("<div id=\"message_list\">"
1937 "<div id=\"fix_scrollbar_bug\">\n"
1939 "<form name=\"msgomatic\" "
1940 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n"
1942 "<table border=0 cellspacing=0 "
1943 "cellpadding=0 width=100%%>\n"
1945 "<TD align=center><b><i>%s</i></b> %s</TD>"
1946 "<TD align=center><b><i>%s</i></b> %s</TD>"
1947 "<TD align=center><b><i>%s</i></b> %s</TD>"
1948 "<TD><INPUT TYPE=\"submit\" NAME=\"delete_button\" "
1949 "STYLE=\"font-family: Bitstream Vera Sans,Arial,Helvetica,sans-serif;"
1950 " font-size: 6pt;\" "
1951 "VALUE=\"%s\"></TD>"
1954 _("Subject"), subjsort_button,
1955 _("Sender"), sendsort_button,
1956 _("Date"), datesort_button,
1961 for (a = 0; a < nummsgs; ++a) {
1962 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
1964 /* Learn which msgs "Prev" & "Next" buttons go to */
1965 pn_current = WC->msgarr[a];
1966 if (a > 0) pn_previous = WC->msgarr[a-1];
1967 if (a < (nummsgs-1)) pn_next = WC->msgarr[a+1];
1969 /* If a tabular view, set up the line */
1972 wprintf("<TR BGCOLOR=\"#%s\">",
1973 (bg ? "DDDDDD" : "FFFFFF")
1977 /* Display the message */
1979 display_summarized(a);
1981 else if (is_addressbook) {
1982 fetch_ab_name(WC->msgarr[a], buf);
1984 addrbook = realloc(addrbook,
1985 (sizeof(struct addrbookent) * num_ab) );
1986 safestrncpy(addrbook[num_ab-1].ab_name, buf,
1987 sizeof(addrbook[num_ab-1].ab_name));
1988 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
1990 else if (is_calendar) {
1991 display_calendar(WC->msgarr[a]);
1993 else if (is_tasks) {
1994 display_task(WC->msgarr[a]);
1996 else if (is_notes) {
1997 display_note(WC->msgarr[a]);
2000 read_message(WC->msgarr[a], 0);
2003 /* If a tabular view, finish the line */
2008 if (lowest_displayed < 0) lowest_displayed = a;
2009 highest_displayed = a;
2012 --remaining_messages;
2017 wprintf("</table></form>"
2018 "</div>\n"); /* end of 'fix_scrollbar_bug' div */
2019 wprintf("</div>"); /* end of 'message_list' div */
2021 wprintf("<div id=\"ml_slider\"></div>"); /* slider */
2023 wprintf("<div id=\"preview_pane\">"); /* The preview pane will initially be empty */
2026 /* Bump these because although we're thinking in zero base, the user
2027 * is a drooling idiot and is thinking in one base.
2030 ++highest_displayed;
2032 /* If we're only looking at one message, do a prev/next thing */
2033 if (num_displayed == 1) {
2034 if ((!is_tasks) && (!is_calendar) && (!is_addressbook) && (!is_notes) && (!is_singlecard)) {
2036 wprintf("<div id=\"fix_scrollbar_bug\">"
2037 "<table border=0 width=100%% bgcolor=\"#dddddd\"><tr><td>");
2038 wprintf(_("Reading #%d of %d messages."), lowest_displayed, nummsgs);
2039 wprintf("</TD><TD ALIGN=RIGHT><FONT SIZE=+1>");
2041 if (pn_previous > 0L) {
2042 wprintf("<A HREF=\"/%s"
2053 wprintf("<A HREF=\"/%s"
2063 wprintf("<A HREF=\"/%s?startmsg=%ld"
2064 "?maxmsgs=%d?summary=1\">"
2073 wprintf("</td></tr></table></div>\n");
2078 * If we're not currently looking at ALL requested
2079 * messages, then display the selector bar
2081 if (num_displayed > 1) {
2082 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2083 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2085 wprintf("<form name=\"msgomatic\" "
2086 "method=\"POST\" action=\"/do_stuff_to_msgs\">\n");
2088 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2090 wprintf("<select name=\"whichones\" size=\"1\" "
2091 "OnChange=\"location.href=msgomatic.whichones.options"
2092 "[selectedIndex].value\">\n");
2094 for (b=0; b<nummsgs; b = b + maxmsgs) {
2097 if (hi > nummsgs) hi = nummsgs;
2098 wprintf("<option %s value="
2103 "%d-%d</option> \n",
2104 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2111 wprintf("<option value=\"/%s?startmsg=%ld"
2112 "?maxmsgs=9999999?summary=%d\">"
2116 WC->msgarr[0], is_summary);
2118 wprintf("</select> ");
2119 wprintf(_("of %d messages."), nummsgs);
2120 wprintf("</form>\n");
2126 do_tasks_view(); /* Render the task list */
2130 do_calendar_view(); /* Render the calendar */
2133 if (is_addressbook) {
2134 do_addrbook_view(addrbook, num_ab); /* Render the address book */
2137 /* Put the data transfer hidden iframe in a hidden div, to make it *really* hidden */
2139 "<div display=\"hidden\">\n"
2140 "<iframe name=\"msgloader1\" id=\"msgloader1\" width=\"1\"></iframe>\n"
2143 /* Note: wDumpContent() will output one additional </div> tag. */
2145 if (addrbook != NULL) free(addrbook);
2147 /* free the summary */
2148 if (WC->num_summ != 0) {
2153 /* If we got here via a mailbox view and are reading a single
2154 * message, mark it as "seen." We do this after rendering the web page
2155 * so it doesn't keep the user waiting.
2157 if ( (maxmsgs == 1) && (WC->wc_view == VIEW_MAILBOX) ) {
2158 serv_printf("SEEN %ld|1", startmsg);
2159 serv_getln(buf, sizeof buf);
2165 * Back end for post_message() ... this is where the actual message
2166 * gets transmitted to the server.
2168 void post_mime_to_server(void) {
2170 int is_multipart = 0;
2172 struct wc_attachment *att;
2174 size_t encoded_length;
2176 /* RFC2045 requires this, and some clients look for it... */
2177 serv_puts("MIME-Version: 1.0");
2179 /* If there are attachments, we have to do multipart/mixed */
2180 if (WC->first_attachment != NULL) {
2185 sprintf(boundary, "---Citadel-Multipart-%s-%04x%04x---",
2186 serv_info.serv_fqdn,
2191 /* Remember, serv_printf() appends an extra newline */
2192 serv_printf("Content-type: multipart/mixed; "
2193 "boundary=\"%s\"\n", boundary);
2194 serv_printf("This is a multipart message in MIME format.\n");
2195 serv_printf("--%s", boundary);
2198 serv_puts("Content-type: text/html; charset=utf-8");
2200 serv_puts("<HTML><BODY>\n");
2201 text_to_server(bstr("msgtext"), 0);
2202 serv_puts("</BODY></HTML>\n");
2207 /* Add in the attachments */
2208 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2210 encoded_length = ((att->length * 150) / 100);
2211 encoded = malloc(encoded_length);
2212 if (encoded == NULL) break;
2213 CtdlEncodeBase64(encoded, att->data, att->length);
2215 serv_printf("--%s", boundary);
2216 serv_printf("Content-type: %s", att->content_type);
2217 serv_printf("Content-disposition: attachment; "
2218 "filename=\"%s\"", att->filename);
2219 serv_puts("Content-transfer-encoding: base64");
2221 serv_write(encoded, strlen(encoded));
2226 serv_printf("--%s--", boundary);
2234 * Post message (or don't post message)
2236 * Note regarding the "dont_post" variable:
2237 * A random value (actually, it's just a timestamp) is inserted as a hidden
2238 * field called "postseq" when the display_enter page is generated. This
2239 * value is checked when posting, using the static variable dont_post. If a
2240 * user attempts to post twice using the same dont_post value, the message is
2241 * discarded. This prevents the accidental double-saving of the same message
2242 * if the user happens to click the browser "back" button.
2244 void post_message(void)
2247 static long dont_post = (-1L);
2248 struct wc_attachment *att, *aptr;
2250 if (WC->upload_length > 0) {
2252 /* There's an attachment. Save it to this struct... */
2253 att = malloc(sizeof(struct wc_attachment));
2254 memset(att, 0, sizeof(struct wc_attachment));
2255 att->length = WC->upload_length;
2256 strcpy(att->content_type, WC->upload_content_type);
2257 strcpy(att->filename, WC->upload_filename);
2260 /* And add it to the list. */
2261 if (WC->first_attachment == NULL) {
2262 WC->first_attachment = att;
2265 aptr = WC->first_attachment;
2266 while (aptr->next != NULL) aptr = aptr->next;
2270 /* Mozilla sends a simple filename, which is what we want,
2271 * but Satan's Browser sends an entire pathname. Reduce
2272 * the path to just a filename if we need to.
2274 while (num_tokens(att->filename, '/') > 1) {
2275 remove_token(att->filename, 0, '/');
2277 while (num_tokens(att->filename, '\\') > 1) {
2278 remove_token(att->filename, 0, '\\');
2281 /* Transfer control of this memory from the upload struct
2282 * to the attachment struct.
2284 att->data = WC->upload;
2285 WC->upload_length = 0;
2291 if (strlen(bstr("cancel_button")) > 0) {
2292 sprintf(WC->ImportantMessage,
2293 _("Cancelled. Message was not posted."));
2294 } else if (strlen(bstr("attach_button")) > 0) {
2297 } else if (atol(bstr("postseq")) == dont_post) {
2298 sprintf(WC->ImportantMessage,
2299 _("Automatically cancelled because you have already "
2300 "saved this message."));
2302 sprintf(buf, "ENT0 1|%s|0|4|%s|||%s|%s",
2309 serv_getln(buf, sizeof buf);
2310 if (buf[0] == '4') {
2311 post_mime_to_server();
2312 if ( (strlen(bstr("recp")) > 0)
2313 || (strlen(bstr("cc")) > 0)
2314 || (strlen(bstr("bcc")) > 0)
2316 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2319 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2321 dont_post = atol(bstr("postseq"));
2323 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2329 free_attachments(WC);
2330 readloop("readnew");
2337 * display the message entry screen
2339 void display_enter(void)
2343 struct wc_attachment *att;
2344 int recipient_required = 0;
2345 int recipient_bad = 0;
2347 if (strlen(bstr("force_room")) > 0) {
2348 gotoroom(bstr("force_room"));
2351 /* Are we perhaps in an address book view? If so, then an "enter
2352 * message" command really means "add new entry."
2354 if (WC->wc_view == VIEW_ADDRESSBOOK) {
2355 do_edit_vcard(-1, "", "");
2359 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
2360 /* Are we perhaps in a calendar view? If so, then an "enter
2361 * message" command really means "add new calendar item."
2363 if (WC->wc_view == VIEW_CALENDAR) {
2364 display_edit_event();
2368 /* Are we perhaps in a tasks view? If so, then an "enter
2369 * message" command really means "add new task."
2371 if (WC->wc_view == VIEW_TASKS) {
2372 display_edit_task();
2378 * Otherwise proceed normally.
2379 * Do a custom room banner with no navbar...
2381 output_headers(1, 1, 2, 0, 0, 0);
2382 wprintf("<div id=\"banner\">\n");
2383 embed_room_banner(NULL, navbar_none);
2384 wprintf("</div>\n");
2385 wprintf("<div id=\"content\">\n"
2386 "<div id=\"fix_scrollbar_bug\">"
2387 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
2389 /* First test to see whether this is a room that requires recipients to be entered */
2390 serv_puts("ENT0 0");
2391 serv_getln(buf, sizeof buf);
2392 if (!strncmp(buf, "570", 3)) { /* 570 means that we need a recipient here */
2393 recipient_required = 1;
2395 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
2396 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2400 /* Now check our actual recipients if there are any */
2401 if (recipient_required) {
2402 sprintf(buf, "ENT0 0|%s|0|0||||%s|%s", bstr("recp"), bstr("cc"), bstr("bcc"));
2404 serv_getln(buf, sizeof buf);
2406 if (!strncmp(buf, "570", 3)) { /* 570 means we have an invalid recipient listed */
2407 if (strlen(bstr("recp")) + strlen(bstr("cc")) + strlen(bstr("bcc")) > 0) {
2411 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
2412 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2417 /* If we got this far, we can display the message entry screen. */
2420 fmt_date(buf, now, 0);
2421 strcat(&buf[strlen(buf)], _(" <I>from</I> "));
2422 stresc(&buf[strlen(buf)], WC->wc_username, 1, 1);
2424 /* Don't need this anymore, it's in the input box below
2425 if (strlen(bstr("recp")) > 0) {
2426 strcat(&buf[strlen(buf)], _(" <I>to</I> "));
2427 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
2431 strcat(&buf[strlen(buf)], _(" <I>in</I> "));
2432 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
2434 /* begin message entry screen */
2435 wprintf("<form enctype=\"multipart/form-data\" "
2436 "method=\"POST\" action=\"/post\" "
2437 "name=\"enterform\""
2438 "onSubmit=\"return submitForm();\""
2440 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2442 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2443 wprintf("%s<br>\n", buf); /* header bar */
2445 wprintf("<table border=\"0\" width=\"100%%\">\n");
2446 if (recipient_required) {
2448 wprintf("<tr><td>");
2449 wprintf("<font size=-1>");
2453 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
2454 escputs(bstr("recp"));
2455 wprintf("\" size=50 maxlength=1000 />");
2456 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
2457 wprintf("</td><td></td></tr>\n");
2459 wprintf("<tr><td>");
2460 wprintf("<font size=-1>");
2464 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
2465 escputs(bstr("cc"));
2466 wprintf("\" size=50 maxlength=1000 />");
2467 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
2468 wprintf("</td><td></td></tr>\n");
2470 wprintf("<tr><td>");
2471 wprintf("<font size=-1>");
2475 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
2476 escputs(bstr("bcc"));
2477 wprintf("\" size=50 maxlength=1000 />");
2478 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
2479 wprintf("</td><td></td></tr>\n");
2481 /* Initialize the autocomplete ajax helpers (found in wclib.js) */
2482 wprintf("<script type=\"text/javascript\"> \n"
2483 " activate_entmsg_autocompleters(); \n"
2488 wprintf("<tr><td>");
2489 wprintf("<font size=-1>");
2490 wprintf(_("Subject (optional):"));
2493 "<input type=\"text\" name=\"subject\" value=\"");
2494 escputs(bstr("subject"));
2495 wprintf("\" size=50 maxlength=70></td><td>\n");
2497 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2498 if (recipient_required) {
2499 wprintf(_("Send message"));
2501 wprintf(_("Post message"));
2504 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2505 wprintf("</td></tr></table>\n");
2507 wprintf("<center><script type=\"text/javascript\" "
2508 "src=\"static/richtext.js\"></script>\n"
2509 "<script type=\"text/javascript\">\n"
2510 "function submitForm() { \n"
2511 " updateRTE('msgtext'); \n"
2515 "initRTE(\"static/\", \"static/\", \"\"); \n"
2517 "<noscript>JavaScript must be enabled.</noscript> \n"
2518 "<script type=\"text/javascript\"> \n"
2519 "writeRichText('msgtext', '");
2520 msgescputs(bstr("msgtext"));
2521 if (atol(bstr("pullquote")) > 0L) {
2522 wprintf("<br><div align=center><i>");
2523 wprintf(_("--- forwarded message ---"));
2524 wprintf("</i></div><br>");
2525 pullquote_message(atol(bstr("pullquote")), 1);
2527 wprintf("', '96%%', '200', true, false); \n"
2528 "</script></center><br />\n");
2530 /* Enumerate any attachments which are already in place... */
2531 wprintf("<img src=\"/static/diskette_24x.gif\" border=0 "
2532 "align=middle height=16 width=16> Attachments: ");
2533 wprintf("<select name=\"which_attachment\" size=1>");
2534 for (att = WC->first_attachment; att != NULL; att = att->next) {
2535 wprintf("<option value=\"");
2536 urlescputs(att->filename);
2538 escputs(att->filename);
2539 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
2540 wprintf("</option>\n");
2542 wprintf("</select>");
2544 /* Now offer the ability to attach additional files... */
2545 wprintf(" "
2546 "Attach file: <input NAME=\"attachfile\" "
2547 "SIZE=16 TYPE=\"file\">\n "
2548 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
2550 /* Seth asked for these to be at the top *and* bottom... */
2551 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2552 if (recipient_required) {
2553 wprintf(_("Send message"));
2555 wprintf(_("Post message"));
2558 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2560 wprintf("</form>\n");
2562 wprintf("</td></tr></table></div>\n");
2563 DONE: wDumpContent(1);
2573 void delete_msg(void)
2578 msgid = atol(bstr("msgid"));
2580 output_headers(1, 1, 1, 0, 0, 0);
2582 sprintf(buf, "DELE %ld", msgid);
2584 serv_getln(buf, sizeof buf);
2585 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2594 * Confirm move of a message
2596 void confirm_move_msg(void)
2602 msgid = atol(bstr("msgid"));
2604 output_headers(1, 1, 1, 0, 0, 0);
2606 wprintf("<div id=\"fix_scrollbar_bug\">"
2607 "<table width=100%% border=0 bgcolor=\"#444455\"><tr><td>");
2608 wprintf("<font size=+1 color=\"#ffffff\"");
2610 wprintf(_("Confirm move of message"));
2612 wprintf("</font></td></tr></table></div>\n");
2614 wprintf("<CENTER>");
2616 wprintf(_("Move this message to:"));
2617 wprintf("<br />\n");
2619 wprintf("<form METHOD=\"POST\" ACTION=\"/move_msg\">\n");
2620 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
2624 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
2626 serv_getln(buf, sizeof buf);
2627 if (buf[0] == '1') {
2628 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2629 extract_token(targ, buf, 0, '|', sizeof targ);
2630 wprintf("<OPTION>");
2635 wprintf("</SELECT>\n");
2636 wprintf("<br />\n");
2638 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
2640 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
2641 wprintf("</form></CENTER>\n");
2643 wprintf("</CENTER>\n");
2654 msgid = atol(bstr("msgid"));
2656 output_headers(1, 1, 1, 0, 0, 0);
2658 if (strlen(bstr("move_button")) > 0) {
2659 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
2661 serv_getln(buf, sizeof buf);
2662 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2665 wprintf(_("The message was not moved."));
2666 wprintf("</EM><br />\n");
2673 * This gets called when a user selects multiple messages in a summary
2674 * list and then clicks to perform a transformation of some sort on them
2675 * (such as deleting them).
2677 void do_stuff_to_msgs(void) {
2681 struct stuff_t *next;
2685 struct stuff_t *stuff = NULL;
2686 struct stuff_t *ptr;
2687 int delete_button_pressed = 0;
2690 serv_puts("MSGS ALL");
2691 serv_getln(buf, sizeof buf);
2693 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2694 ptr = malloc(sizeof(struct stuff_t));
2695 ptr->msgnum = atol(buf);
2700 if (strlen(bstr("delete_button")) > 0) {
2701 delete_button_pressed = 1;
2704 while (stuff != NULL) {
2706 sprintf(buf, "msg_%ld", stuff->msgnum);
2707 if (!strcasecmp(bstr(buf), "yes")) {
2709 if (delete_button_pressed) {
2710 serv_printf("DELE %ld", stuff->msgnum);
2711 serv_getln(buf, sizeof buf);
2721 readloop("readfwd");