5 * \defgroup MsgDisp Functions which deal with the fetching and displaying of messages.
11 #include "webserver.h"
14 #define SUBJ_COL_WIDTH_PCT 50 /**< ??? */
15 #define SENDER_COL_WIDTH_PCT 30 /**< ??? */
16 #define DATE_PLUS_BUTTONS_WIDTH_PCT 20 /**< ??? */
19 * Address book entry (keep it short and sweet, it's just a quickie lookup
20 * which we can use to get to the real meat and bones later)
23 char ab_name[64]; /**< name string */
24 long ab_msgnum; /**< number in the citadel???? */
31 * \brief Handle subjects with RFC2047 encoding
33 * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=
34 * \param buf the stringbuffer to process
36 void utf8ify_rfc822_string(char *buf) {
42 iconv_t ic = (iconv_t)(-1) ;
43 char *ibuf; /**< Buffer of characters to be converted */
44 char *obuf; /**< Buffer for converted characters */
45 size_t ibuflen; /**< Length of input buffer */
46 size_t obuflen; /**< Length of output buffer */
47 char *isav; /**< Saved pointer to input buffer */
48 char *osav; /**< Saved pointer to output buffer */
51 while (start=strstr(buf, "=?"), end=strstr(buf, "?="),
52 ((start != NULL) && (end != NULL) && (end > start)) )
54 extract_token(charset, start, 1, '?', sizeof charset);
55 extract_token(encoding, start, 2, '?', sizeof encoding);
56 extract_token(istr, start, 3, '?', sizeof istr);
64 if (!strcasecmp(encoding, "B")) { /**< base64 */
65 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
67 else if (!strcasecmp(encoding, "Q")) { /**< quoted-printable */
68 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, strlen(istr));
71 strcpy(ibuf, istr); /**< huh? */
72 ibuflen = strlen(istr);
75 ic = iconv_open("UTF-8", charset);
76 if (ic != (iconv_t)(-1) ) {
79 obuf = (char *) malloc(obuflen);
81 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
82 osav[1024-obuflen] = 0;
87 remove_token(end, 0, '?');
88 remove_token(end, 0, '?');
89 remove_token(end, 0, '?');
90 remove_token(end, 0, '?');
93 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
102 remove_token(end, 0, '?');
103 remove_token(end, 0, '?');
104 remove_token(end, 0, '?');
105 remove_token(end, 0, '?');
106 strcpy(end, &end[1]);
108 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
115 * Since spammers will go to all sorts of absurd lengths to get their
116 * messages through, there are LOTS of corrupt headers out there.
117 * So, prevent a really badly formed RFC2047 header from throwing
118 * this function into an infinite loop.
121 if (passes > 20) return;
129 * \brief Look for URL's embedded in a buffer and make them linkable. We use a
130 * target window in order to keep the BBS session in its own window.
131 * \param buf the message buffer
146 for (pos = 0; pos < strlen(buf); ++pos) {
147 if (!strncasecmp(&buf[pos], "http://", 7))
149 if (!strncasecmp(&buf[pos], "ftp://", 6))
156 if ((start > 0) && (buf[start - 1] == '<'))
158 if ((start > 0) && (buf[start - 1] == '['))
160 if ((start > 0) && (buf[start - 1] == '('))
162 if ((start > 0) && (buf[start - 1] == '{'))
165 for (pos = strlen(buf); pos > start; --pos) {
166 if ((buf[pos] == ' ') || (buf[pos] == ench))
170 strncpy(urlbuf, &buf[start], end - start);
171 urlbuf[end - start] = 0;
173 strncpy(outbuf, buf, start);
174 sprintf(&outbuf[start], "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
175 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
176 strcat(outbuf, &buf[end]);
177 if ( strlen(outbuf) < 250 )
183 * \brief Turn a vCard "n" (name) field into something displayable.
184 * \param name the name field to convert
186 void vcard_n_prettyize(char *name)
191 original_name = strdup(name);
192 for (i=0; i<5; ++i) {
193 if (strlen(original_name) > 0) {
194 if (original_name[strlen(original_name)-1] == ' ') {
195 original_name[strlen(original_name)-1] = 0;
197 if (original_name[strlen(original_name)-1] == ';') {
198 original_name[strlen(original_name)-1] = 0;
203 for (i=0; i<strlen(original_name); ++i) {
204 if (original_name[i] == ';') {
208 name[strlen(name)+1] = 0;
209 name[strlen(name)] = original_name[i];
219 * \brief preparse a vcard name
220 * display_vcard() calls this after parsing the textual vCard into
221 * our 'struct vCard' data object.
222 * This gets called instead of display_parsed_vcard() if we are only looking
223 * to extract the person's name instead of displaying the card.
224 * \param v the vcard to retrieve the name from
225 * \param storename where to put the name at
227 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
230 strcpy(storename, "");
232 name = vcard_get_prop(v, "n", 1, 0, 0);
234 strcpy(storename, name);
235 /* vcard_n_prettyize(storename); */
243 * \brief html print a vcard
244 * display_vcard() calls this after parsing the textual vCard into
245 * our 'struct vCard' data object.
247 * Set 'full' to nonzero to display the full card, otherwise it will only
248 * show a summary line.
250 * This code is a bit ugly, so perhaps an explanation is due: we do this
251 * in two passes through the vCard fields. On the first pass, we process
252 * fields we understand, and then render them in a pretty fashion at the
253 * end. Then we make a second pass, outputting all the fields we don't
254 * understand in a simple two-column name/value format.
255 * \param v the vCard to display
256 * \param full display all items of the vcard?
258 void display_parsed_vcard(struct vCard *v, int full) {
264 char *thisname, *thisvalue;
265 char firsttoken[SIZ];
274 strcpy(fullname, "");
282 name = vcard_get_prop(v, "fn", 1, 0, 0);
286 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
287 strcpy(fullname, name);
288 vcard_n_prettyize(fullname);
298 wprintf("<div align=center><table bgcolor=#aaaaaa width=50%%>");
299 for (pass=1; pass<=2; ++pass) {
301 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
303 thisname = strdup(v->prop[i].name);
304 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
306 for (j=0; j<num_tokens(thisname, ';'); ++j) {
307 extract_token(buf, thisname, j, ';', sizeof buf);
308 if (!strcasecmp(buf, "encoding=quoted-printable")) {
310 remove_token(thisname, j, ';');
312 if (!strcasecmp(buf, "encoding=base64")) {
314 remove_token(thisname, j, ';');
319 thisvalue = malloc(strlen(v->prop[i].value) + 50);
320 j = CtdlDecodeQuotedPrintable(
321 thisvalue, v->prop[i].value,
322 strlen(v->prop[i].value) );
326 thisvalue = malloc(strlen(v->prop[i].value) + 50);
328 thisvalue, v->prop[i].value,
329 strlen(v->prop[i].value) );
332 thisvalue = strdup(v->prop[i].value);
335 /** Various fields we may encounter ***/
337 /** N is name, but only if there's no FN already there */
338 if (!strcasecmp(firsttoken, "n")) {
339 if (strlen(fullname) == 0) {
340 strcpy(fullname, thisvalue);
341 vcard_n_prettyize(fullname);
345 /** FN (full name) is a true 'display name' field */
346 else if (!strcasecmp(firsttoken, "fn")) {
347 strcpy(fullname, thisvalue);
351 else if (!strcasecmp(firsttoken, "title")) {
352 strcpy(title, thisvalue);
356 else if (!strcasecmp(firsttoken, "org")) {
357 strcpy(org, thisvalue);
360 else if (!strcasecmp(firsttoken, "email")) {
361 if (strlen(mailto) > 0) strcat(mailto, "<br />");
363 "<a href=\"display_enter"
364 "?force_room=_MAIL_?recp=");
366 urlesc(&mailto[strlen(mailto)], fullname);
367 urlesc(&mailto[strlen(mailto)], " <");
368 urlesc(&mailto[strlen(mailto)], thisvalue);
369 urlesc(&mailto[strlen(mailto)], ">");
371 strcat(mailto, "\">");
372 stresc(&mailto[strlen(mailto)], thisvalue, 1, 1);
373 strcat(mailto, "</A>");
375 else if (!strcasecmp(firsttoken, "tel")) {
376 if (strlen(phone) > 0) strcat(phone, "<br />");
377 strcat(phone, thisvalue);
378 for (j=0; j<num_tokens(thisname, ';'); ++j) {
379 extract_token(buf, thisname, j, ';', sizeof buf);
380 if (!strcasecmp(buf, "tel"))
382 else if (!strcasecmp(buf, "work"))
383 strcat(phone, _(" (work)"));
384 else if (!strcasecmp(buf, "home"))
385 strcat(phone, _(" (home)"));
386 else if (!strcasecmp(buf, "cell"))
387 strcat(phone, _(" (cell)"));
395 else if (!strcasecmp(firsttoken, "adr")) {
398 wprintf(_("Address:"));
399 wprintf("</TD><TD>");
400 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
401 extract_token(buf, thisvalue, j, ';', sizeof buf);
402 if (strlen(buf) > 0) {
404 if (j<3) wprintf("<br />");
408 wprintf("</TD></TR>\n");
411 else if (!strcasecmp(firsttoken, "version")) {
414 else if (!strcasecmp(firsttoken, "rev")) {
417 else if (!strcasecmp(firsttoken, "label")) {
422 /*** Don't show extra fields. They're ugly.
426 wprintf("</TD><TD>");
428 wprintf("</TD></TR>\n");
438 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
439 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
440 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
441 "<FONT SIZE=+1><B>");
443 wprintf("</B></FONT>");
444 if (strlen(title) > 0) {
445 wprintf("<div align=right>");
449 if (strlen(org) > 0) {
450 wprintf("<div align=right>");
454 wprintf("</TD></TR>\n");
456 if (strlen(phone) > 0) {
458 wprintf(_("Telephone:"));
459 wprintf("</td><td>%s</td></tr>\n", phone);
461 if (strlen(mailto) > 0) {
463 wprintf(_("E-mail:"));
464 wprintf("</td><td>%s</td></tr>\n", mailto);
470 wprintf("</table></div>\n");
476 * \brief Display a textual vCard
477 * (Converts to a vCard object and then calls the actual display function)
478 * Set 'full' to nonzero to display the whole card instead of a one-liner.
479 * Or, if "storename" is non-NULL, just store the person's name in that
480 * buffer instead of displaying the card at all.
481 * \param vcard_source the buffer containing the vcard text
482 * \param alpha what???
483 * \param full should we usse all lines?
484 * \param storename where to store???
486 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
492 v = vcard_load(vcard_source);
493 if (v == NULL) return;
495 name = vcard_get_prop(v, "n", 1, 0, 0);
501 if (storename != NULL) {
502 fetchname_parsed_vcard(v, storename);
504 else if ( (alpha == 0)
505 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
506 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
508 display_parsed_vcard(v, full);
516 * \brief I wanna SEE that message!
517 * \param msgnum the citadel number of the message to display
518 * \param printable_view are we doing a print view?
519 * \param section Optional for encapsulated message/rfc822 submessage)
521 void read_message(long msgnum, int printable_view, char *section) {
523 char mime_partnum[256];
524 char mime_filename[256];
525 char mime_content_type[256];
526 char mime_charset[256];
527 char mime_disposition[256];
530 char mime_submessages[256];
537 char reply_all[4096];
543 char vcard_partnum[256];
544 char cal_partnum[256];
545 char *part_source = NULL;
547 iconv_t ic = (iconv_t)(-1) ;
548 char *ibuf; /**< Buffer of characters to be converted */
549 char *obuf; /**< Buffer for converted characters */
550 size_t ibuflen; /**< Length of input buffer */
551 size_t obuflen; /**< Length of output buffer */
552 char *osav; /**< Saved pointer to output buffer */
558 strcpy(reply_to, "");
559 strcpy(reply_all, "");
560 strcpy(vcard_partnum, "");
561 strcpy(cal_partnum, "");
562 strcpy(mime_http, "");
563 strcpy(mime_content_type, "text/plain");
564 strcpy(mime_charset, "us-ascii");
565 strcpy(mime_submessages, "");
567 serv_printf("MSG4 %ld|%s", msgnum, section);
568 serv_getln(buf, sizeof buf);
571 wprintf(_("ERROR:"));
572 wprintf("</STRONG> %s<br />\n", &buf[4]);
576 /** begin everythingamundo table */
577 if (!printable_view) {
578 wprintf("<div class=\"fix_scrollbar_bug\">\n");
579 wprintf("<table width=100%% border=1 cellspacing=0 "
580 "cellpadding=0><TR><TD>\n");
583 /** begin message header table */
584 wprintf("<table width=100%% border=0 cellspacing=0 "
585 "cellpadding=1 bgcolor=\"#CCCCCC\"><tr><td>\n");
587 wprintf("<span class=\"message_header\">");
588 strcpy(m_subject, "");
591 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
592 if (!strcmp(buf, "000")) {
594 wprintf(_("unexpected end of message"));
595 wprintf("</i><br /><br />\n");
596 wprintf("</span>\n");
599 if (!strncasecmp(buf, "nhdr=yes", 8))
603 if (!strncasecmp(buf, "type=", 5))
604 format_type = atoi(&buf[5]);
605 if (!strncasecmp(buf, "from=", 5)) {
606 strcpy(from, &buf[5]);
608 wprintf("<a href=\"showuser?who=");
610 utf8ify_rfc822_string(from);
617 if (!strncasecmp(buf, "subj=", 5)) {
618 safestrncpy(m_subject, &buf[5], sizeof m_subject);
620 if (!strncasecmp(buf, "cccc=", 5)) {
621 safestrncpy(m_cc, &buf[5], sizeof m_cc);
622 if (strlen(reply_all) > 0) {
623 strcat(reply_all, ", ");
625 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
626 (sizeof reply_all - strlen(reply_all)) );
628 if ((!strncasecmp(buf, "hnod=", 5))
629 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
630 wprintf("(%s) ", &buf[5]);
632 if ((!strncasecmp(buf, "room=", 5))
633 && (strcasecmp(&buf[5], WC->wc_roomname))
634 && (strlen(&buf[5])>0) ) {
636 wprintf("%s> ", &buf[5]);
638 if (!strncasecmp(buf, "rfca=", 5)) {
639 strcpy(rfca, &buf[5]);
645 if (!strncasecmp(buf, "node=", 5)) {
646 strcpy(node, &buf[5]);
647 if ( ((WC->room_flags & QR_NETWORK)
648 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
649 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
652 wprintf("@%s ", &buf[5]);
655 if (!strncasecmp(buf, "rcpt=", 5)) {
659 if (strlen(reply_all) > 0) {
660 strcat(reply_all, ", ");
662 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
663 (sizeof reply_all - strlen(reply_all)) );
665 if (!strncasecmp(buf, "time=", 5)) {
666 fmt_date(now, atol(&buf[5]), 0);
670 if (!strncasecmp(buf, "part=", 5)) {
671 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
672 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
673 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
674 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
675 mime_length = extract_int(&buf[5], 5);
677 if (!strcasecmp(mime_content_type, "message/rfc822")) {
678 if (strlen(mime_submessages) > 0) {
679 strcat(mime_submessages, "|");
681 strcat(mime_submessages, mime_partnum);
683 else if ((!strcasecmp(mime_disposition, "inline"))
684 && (!strncasecmp(mime_content_type, "image/", 6)) ){
685 snprintf(&mime_http[strlen(mime_http)],
686 (sizeof(mime_http) - strlen(mime_http) - 1),
687 "<img src=\"mimepart/%ld/%s/%s\">",
688 msgnum, mime_partnum, mime_filename);
690 else if ( (!strcasecmp(mime_disposition, "attachment"))
691 || (!strcasecmp(mime_disposition, "inline")) ) {
692 snprintf(&mime_http[strlen(mime_http)],
693 (sizeof(mime_http) - strlen(mime_http) - 1),
694 "<a href=\"mimepart/%ld/%s/%s\" "
695 "target=\"wc.%ld.%s\">"
696 "<img src=\"static/diskette_24x.gif\" "
697 "border=0 align=middle>\n"
698 "%s (%s, %d bytes)</a><br />\n",
699 msgnum, mime_partnum, mime_filename,
700 msgnum, mime_partnum,
702 mime_content_type, mime_length
706 /** begin handler prep ***/
707 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
708 strcpy(vcard_partnum, mime_partnum);
711 if (!strcasecmp(mime_content_type, "text/calendar")) {
712 strcpy(cal_partnum, mime_partnum);
715 /** end handler prep ***/
721 /** Generate a reply-to address */
722 if (strlen(rfca) > 0) {
723 strcpy(reply_to, rfca);
726 if ( (strlen(node) > 0)
727 && (strcasecmp(node, serv_info.serv_nodename))
728 && (strcasecmp(node, serv_info.serv_humannode)) ) {
729 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
733 snprintf(reply_to, sizeof(reply_to), "%s", from);
743 utf8ify_rfc822_string(m_cc);
744 utf8ify_rfc822_string(m_subject);
746 if (strlen(m_cc) > 0) {
748 "<span class=\"message_subject\">");
754 if (strlen(m_subject) > 0) {
756 "<span class=\"message_subject\">");
757 wprintf(_("Subject:"));
764 /** start msg buttons */
765 if (!printable_view) {
766 wprintf("<td align=right><span class=\"msgbuttons\">\n");
769 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
770 wprintf("<a href=\"display_enter");
771 if (WC->is_mailbox) {
772 wprintf("?replyquote=%ld", msgnum);
775 urlescputs(reply_to);
776 if (strlen(m_subject) > 0) {
777 wprintf("?subject=");
778 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
779 urlescputs(m_subject);
781 wprintf("\">[%s]</a> ", _("Reply"));
785 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
786 if (!WC->is_mailbox) {
787 wprintf("<a href=\"display_enter");
788 wprintf("?replyquote=%ld", msgnum);
790 urlescputs(reply_to);
791 if (strlen(m_subject) > 0) {
792 wprintf("?subject=");
793 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
794 urlescputs(m_subject);
796 wprintf("\">[%s]</a> ", _("ReplyQuoted"));
801 if (WC->wc_view == VIEW_MAILBOX) {
802 wprintf("<a href=\"display_enter");
803 wprintf("?replyquote=%ld", msgnum);
805 urlescputs(reply_to);
807 urlescputs(reply_all);
808 if (strlen(m_subject) > 0) {
809 wprintf("?subject=");
810 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
811 urlescputs(m_subject);
813 wprintf("\">[%s]</a> ", _("ReplyAll"));
817 if (WC->wc_view == VIEW_MAILBOX) {
818 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
819 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
820 urlescputs(m_subject);
821 wprintf("\">[%s]</a> ", _("Forward"));
824 /** If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
825 if ( (WC->is_room_aide) || (WC->is_mailbox) ) {
827 wprintf("<a href=\"confirm_move_msg?msgid=%ld\">[%s]</a> ",
831 wprintf("<a href=\"delete_msg?msgid=%ld\" "
832 "onClick=\"return confirm('%s');\">"
833 "[%s]</a> ", msgnum, _("Delete this message?"), _("Delete")
838 wprintf("<a href=\"#\" onClick=\"window.open('msgheaders/%ld', 'headers%ld', 'toolbar=no,location=no,directories=no,copyhistory=no,status=yes,scrollbars=yes,resizable=yes,width=600,height=400'); \" >"
839 "[%s]</a>", msgnum, msgnum, _("Headers"));
843 wprintf("<a href=\"#\" onClick=\"window.open('printmsg/%ld', 'print%ld', 'toolbar=no,location=no,directories=no,copyhistory=no,status=yes,scrollbars=yes,resizable=yes,width=600,height=400'); \" >"
844 "[%s]</a>", msgnum, msgnum, _("Print"));
846 wprintf("</span></td>");
849 wprintf("</tr></table>\n");
852 wprintf("<table border=0 width=100%% bgcolor=\"#FFFFFF\" "
853 "cellpadding=1 cellspacing=0><tr><td>");
856 * Learn the content type
858 strcpy(mime_content_type, "text/plain");
859 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
860 if (!strcmp(buf, "000")) {
862 wprintf(_("unexpected end of message"));
863 wprintf("</i><br /><br />\n");
866 if (!strncasecmp(buf, "Content-type: ", 14)) {
867 safestrncpy(mime_content_type, &buf[14],
868 sizeof(mime_content_type));
869 for (i=0; i<strlen(mime_content_type); ++i) {
870 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
871 safestrncpy(mime_charset, &mime_content_type[i+8],
872 sizeof mime_charset);
875 for (i=0; i<strlen(mime_content_type); ++i) {
876 if (mime_content_type[i] == ';') {
877 mime_content_type[i] = 0;
883 /** Set up a character set conversion if we need to (and if we can) */
885 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
886 if ( (strcasecmp(mime_charset, "us-ascii"))
887 && (strcasecmp(mime_charset, "UTF-8"))
888 && (strcasecmp(mime_charset, ""))
890 ic = iconv_open("UTF-8", mime_charset);
891 if (ic == (iconv_t)(-1) ) {
892 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
893 __FILE__, __LINE__, mime_charset, strerror(errno));
898 /** Messages in legacy Citadel variformat get handled thusly... */
899 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
903 /** Boring old 80-column fixed format text gets handled this way... */
904 else if ( (!strcasecmp(mime_content_type, "text/plain"))
905 || (!strcasecmp(mime_content_type, "text")) ) {
906 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
907 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
908 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
911 if (ic != (iconv_t)(-1) ) {
913 ibuflen = strlen(ibuf);
915 obuf = (char *) malloc(obuflen);
917 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
918 osav[SIZ-obuflen] = 0;
919 safestrncpy(buf, osav, sizeof buf);
924 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
925 buf[strlen(buf) - 1] = 0;
927 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
928 wprintf("<blockquote>");
930 } else if ((bq == 1) &&
931 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
932 wprintf("</blockquote>");
938 wprintf("</tt><br />\n");
940 wprintf("</i><br />");
943 else /** HTML is fun, but we've got to strip it first */
944 if (!strcasecmp(mime_content_type, "text/html")) {
945 output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
948 /** Unknown weirdness */
950 wprintf(_("I don't know how to display %s"), mime_content_type);
951 wprintf("<br />\n", mime_content_type);
952 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
955 /** If there are attached submessages, display them now... */
956 if ( (strlen(mime_submessages) > 0) && (!section[0]) ) {
957 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
958 extract_token(buf, mime_submessages, i, '|', sizeof buf);
959 /** use printable_view to suppress buttons */
960 wprintf("<blockquote>");
961 read_message(msgnum, 1, buf);
962 wprintf("</blockquote>");
967 /** Afterwards, offer links to download attachments 'n' such */
968 if ( (strlen(mime_http) > 0) && (!section[0]) ) {
969 wprintf("%s", mime_http);
972 /** Handler for vCard parts */
973 if (strlen(vcard_partnum) > 0) {
974 part_source = load_mimepart(msgnum, vcard_partnum);
975 if (part_source != NULL) {
977 /** If it's my vCard I can edit it */
978 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
979 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
980 || (WC->wc_view == VIEW_ADDRESSBOOK)
982 wprintf("<a href=\"edit_vcard?"
983 "msgnum=%ld?partnum=%s\">",
984 msgnum, vcard_partnum);
985 wprintf("[%s]</a>", _("edit"));
988 /** In all cases, display the full card */
989 display_vcard(part_source, 0, 1, NULL);
993 /** Handler for calendar parts */
994 if (strlen(cal_partnum) > 0) {
995 part_source = load_mimepart(msgnum, cal_partnum);
996 if (part_source != NULL) {
997 cal_process_attachment(part_source,
998 msgnum, cal_partnum);
1008 wprintf("</td></tr></table>\n");
1010 /** end everythingamundo table */
1011 if (!printable_view) {
1012 wprintf("</td></tr></table>\n");
1013 wprintf("</div><br />\n");
1017 if (ic != (iconv_t)(-1) ) {
1026 * \brief Unadorned HTML output of an individual message, suitable
1027 * for placing in a hidden iframe, for printing, or whatever
1028 * \param msgnum_as_string the message to embed???
1030 void embed_message(char *msgnum_as_string) {
1033 msgnum = atol(msgnum_as_string);
1034 begin_ajax_response();
1035 read_message(msgnum, 0, "");
1036 end_ajax_response();
1041 * \brief Printable view of a message
1042 * \param msgnum_as_string the message to print???
1044 void print_message(char *msgnum_as_string) {
1047 msgnum = atol(msgnum_as_string);
1048 output_headers(0, 0, 0, 0, 0, 0);
1050 wprintf("Content-type: text/html\r\n"
1052 "Connection: close\r\n",
1056 wprintf("\r\n\r\n<html>\n"
1057 "<head><title>Printable view</title></head>\n"
1058 "<body onLoad=\" window.print(); window.close(); \">\n"
1061 read_message(msgnum, 1, "");
1063 wprintf("\n</body></html>\n\n");
1070 * \brief Display a message's headers
1071 * \param msgnum_as_string the message headers to print???
1073 void display_headers(char *msgnum_as_string) {
1077 msgnum = atol(msgnum_as_string);
1078 output_headers(0, 0, 0, 0, 0, 0);
1080 wprintf("Content-type: text/plain\r\n"
1082 "Connection: close\r\n",
1086 serv_printf("MSG2 %ld|3", msgnum);
1087 serv_getln(buf, sizeof buf);
1088 if (buf[0] == '1') {
1089 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1090 wprintf("%s\n", buf);
1100 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1101 * or 'reply quoted' operations.
1103 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1104 * in this function. Doing so would throw a JavaScript error in the
1105 * 'supplied text' argument to the editor.
1106 * \param msgnum the citadel message number
1107 * \param forward_attachments atachment to forward???
1109 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1111 char mime_partnum[256];
1112 char mime_filename[256];
1113 char mime_content_type[256];
1114 char mime_charset[256];
1115 char mime_disposition[256];
1117 char mime_http[SIZ];
1118 char *attachments = NULL;
1119 int num_attachments = 0;
1120 struct wc_attachment *att, *aptr;
1121 char m_subject[256];
1127 int format_type = 0;
1132 iconv_t ic = (iconv_t)(-1) ;
1133 char *ibuf; /**< Buffer of characters to be converted */
1134 char *obuf; /**< Buffer for converted characters */
1135 size_t ibuflen; /**< Length of input buffer */
1136 size_t obuflen; /**< Length of output buffer */
1137 char *osav; /**< Saved pointer to output buffer */
1143 strcpy(reply_to, "");
1144 strcpy(mime_http, "");
1145 strcpy(mime_content_type, "text/plain");
1146 strcpy(mime_charset, "us-ascii");
1148 serv_printf("MSG4 %ld", msgnum);
1149 serv_getln(buf, sizeof buf);
1150 if (buf[0] != '1') {
1151 wprintf(_("ERROR:"));
1152 wprintf("%s<br />", &buf[4]);
1156 strcpy(m_subject, "");
1158 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1159 if (!strcmp(buf, "000")) {
1160 wprintf(_("unexpected end of message"));
1163 if (include_headers) {
1164 if (!strncasecmp(buf, "nhdr=yes", 8))
1168 if (!strncasecmp(buf, "type=", 5))
1169 format_type = atoi(&buf[5]);
1170 if (!strncasecmp(buf, "from=", 5)) {
1171 strcpy(from, &buf[5]);
1172 wprintf(_("from "));
1174 utf8ify_rfc822_string(from);
1178 if (!strncasecmp(buf, "subj=", 5)) {
1179 strcpy(m_subject, &buf[5]);
1181 if ((!strncasecmp(buf, "hnod=", 5))
1182 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1183 wprintf("(%s) ", &buf[5]);
1185 if ((!strncasecmp(buf, "room=", 5))
1186 && (strcasecmp(&buf[5], WC->wc_roomname))
1187 && (strlen(&buf[5])>0) ) {
1189 wprintf("%s> ", &buf[5]);
1191 if (!strncasecmp(buf, "rfca=", 5)) {
1192 strcpy(rfca, &buf[5]);
1198 if (!strncasecmp(buf, "node=", 5)) {
1199 strcpy(node, &buf[5]);
1200 if ( ((WC->room_flags & QR_NETWORK)
1201 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1202 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1203 && (strlen(rfca)==0)
1205 wprintf("@%s ", &buf[5]);
1208 if (!strncasecmp(buf, "rcpt=", 5)) {
1210 wprintf("%s ", &buf[5]);
1212 if (!strncasecmp(buf, "time=", 5)) {
1213 fmt_date(now, atol(&buf[5]), 0);
1214 wprintf("%s ", now);
1219 * Save attachment info for later. We can't start downloading them
1220 * yet because we're in the middle of a server transaction.
1222 if (!strncasecmp(buf, "part=", 5)) {
1224 attachments = realloc(attachments, (num_attachments * 1024));
1225 strcat(attachments, &buf[5]);
1226 strcat(attachments, "\n");
1231 if (include_headers) {
1235 utf8ify_rfc822_string(m_subject);
1237 if (strlen(m_subject) > 0) {
1238 wprintf(_("Subject:"));
1240 msgescputs(m_subject);
1251 * Learn the content type
1253 strcpy(mime_content_type, "text/plain");
1254 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1255 if (!strcmp(buf, "000")) {
1256 wprintf(_("unexpected end of message"));
1259 if (!strncasecmp(buf, "Content-type: ", 14)) {
1260 safestrncpy(mime_content_type, &buf[14],
1261 sizeof(mime_content_type));
1262 for (i=0; i<strlen(mime_content_type); ++i) {
1263 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1264 safestrncpy(mime_charset, &mime_content_type[i+8],
1265 sizeof mime_charset);
1268 for (i=0; i<strlen(mime_content_type); ++i) {
1269 if (mime_content_type[i] == ';') {
1270 mime_content_type[i] = 0;
1276 /** Set up a character set conversion if we need to (and if we can) */
1278 if ( (strcasecmp(mime_charset, "us-ascii"))
1279 && (strcasecmp(mime_charset, "UTF-8"))
1280 && (strcasecmp(mime_charset, ""))
1282 ic = iconv_open("UTF-8", mime_charset);
1283 if (ic == (iconv_t)(-1) ) {
1284 lprintf(5, "%s:%d iconv_open() failed: %s\n",
1285 __FILE__, __LINE__, strerror(errno));
1290 /** Messages in legacy Citadel variformat get handled thusly... */
1291 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1295 /* Boring old 80-column fixed format text gets handled this way... */
1296 else if (!strcasecmp(mime_content_type, "text/plain")) {
1297 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1298 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1299 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1302 if (ic != (iconv_t)(-1) ) {
1304 ibuflen = strlen(ibuf);
1306 obuf = (char *) malloc(obuflen);
1308 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1309 osav[SIZ-obuflen] = 0;
1310 safestrncpy(buf, osav, sizeof buf);
1315 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1316 buf[strlen(buf) - 1] = 0;
1318 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1319 wprintf("<blockquote>");
1321 } else if ((bq == 1) &&
1322 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1323 wprintf("</blockquote>");
1329 wprintf("</tt><br />");
1331 wprintf("</i><br />");
1334 /** HTML just gets escaped and stuffed back into the editor */
1335 else if (!strcasecmp(mime_content_type, "text/html")) {
1336 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1342 /** Unknown weirdness ... don't know how to handle this content type */
1344 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1348 /** end of body handler */
1351 * If there were attachments, we have to download them and insert them
1352 * into the attachment chain for the forwarded message we are composing.
1354 if ( (forward_attachments) && (num_attachments) ) {
1355 for (i=0; i<num_attachments; ++i) {
1356 extract_token(buf, attachments, i, '\n', sizeof buf);
1357 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1358 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1359 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1360 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1361 mime_length = extract_int(buf, 5);
1364 * tracing ... uncomment if necessary
1366 lprintf(9, "fwd filename: %s\n", mime_filename);
1367 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1368 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1369 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1370 lprintf(9, "fwd length : %d\n", mime_length);
1373 if ( (!strcasecmp(mime_disposition, "inline"))
1374 || (!strcasecmp(mime_disposition, "attachment")) ) {
1376 /* Create an attachment struct from this mime part... */
1377 att = malloc(sizeof(struct wc_attachment));
1378 memset(att, 0, sizeof(struct wc_attachment));
1379 att->length = mime_length;
1380 strcpy(att->content_type, mime_content_type);
1381 strcpy(att->filename, mime_filename);
1383 att->data = load_mimepart(msgnum, mime_partnum);
1385 /* And add it to the list. */
1386 if (WC->first_attachment == NULL) {
1387 WC->first_attachment = att;
1390 aptr = WC->first_attachment;
1391 while (aptr->next != NULL) aptr = aptr->next;
1401 if (ic != (iconv_t)(-1) ) {
1408 * \brief display sumarized item???
1409 * \param num hom many? which???
1411 void display_summarized(int num) {
1414 wprintf("<tr id=\"m%ld\" style=\"width:100%%;font-weight:%s;background-color:#ffffff\" "
1415 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1416 WC->summ[num].msgnum,
1417 (WC->summ[num].is_new ? "bold" : "normal"),
1418 WC->summ[num].msgnum
1421 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1422 escputs(WC->summ[num].subj);
1425 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1426 escputs(WC->summ[num].from);
1429 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1430 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1440 * \brief display the adressbook overview
1441 * \param msgnum the citadel message number
1442 * \param alpha what????
1444 void display_addressbook(long msgnum, char alpha) {
1446 char mime_partnum[SIZ];
1447 char mime_filename[SIZ];
1448 char mime_content_type[SIZ];
1449 char mime_disposition[SIZ];
1451 char vcard_partnum[SIZ];
1452 char *vcard_source = NULL;
1453 struct message_summary summ;
1455 memset(&summ, 0, sizeof(summ));
1456 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1458 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1460 serv_getln(buf, sizeof buf);
1461 if (buf[0] != '1') return;
1463 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1464 if (!strncasecmp(buf, "part=", 5)) {
1465 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1466 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1467 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1468 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1469 mime_length = extract_int(&buf[5], 5);
1471 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1472 strcpy(vcard_partnum, mime_partnum);
1478 if (strlen(vcard_partnum) > 0) {
1479 vcard_source = load_mimepart(msgnum, vcard_partnum);
1480 if (vcard_source != NULL) {
1482 /** Display the summary line */
1483 display_vcard(vcard_source, alpha, 0, NULL);
1485 /** If it's my vCard I can edit it */
1486 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1487 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1488 || (WC->wc_view == VIEW_ADDRESSBOOK)
1490 wprintf("<a href=\"edit_vcard?"
1491 "msgnum=%ld?partnum=%s\">",
1492 msgnum, vcard_partnum);
1493 wprintf("[%s]</a>", _("edit"));
1505 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1506 * \param namebuf name to analyze, reverse if nescessary
1508 void lastfirst_firstlast(char *namebuf) {
1509 char firstname[SIZ];
1513 if (namebuf == NULL) return;
1514 if (strchr(namebuf, ';') != NULL) return;
1516 i = num_tokens(namebuf, ' ');
1519 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1520 remove_token(namebuf, i-1, ' ');
1521 strcpy(firstname, namebuf);
1522 sprintf(namebuf, "%s; %s", lastname, firstname);
1526 * \brief fetch what??? name
1527 * \param msgnum the citadel message number
1528 * \param namebuf where to put the name in???
1530 void fetch_ab_name(long msgnum, char *namebuf) {
1532 char mime_partnum[SIZ];
1533 char mime_filename[SIZ];
1534 char mime_content_type[SIZ];
1535 char mime_disposition[SIZ];
1537 char vcard_partnum[SIZ];
1538 char *vcard_source = NULL;
1540 struct message_summary summ;
1542 if (namebuf == NULL) return;
1543 strcpy(namebuf, "");
1545 memset(&summ, 0, sizeof(summ));
1546 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1548 sprintf(buf, "MSG0 %ld|1", msgnum); /** ask for headers only */
1550 serv_getln(buf, sizeof buf);
1551 if (buf[0] != '1') return;
1553 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1554 if (!strncasecmp(buf, "part=", 5)) {
1555 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1556 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1557 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1558 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1559 mime_length = extract_int(&buf[5], 5);
1561 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1562 strcpy(vcard_partnum, mime_partnum);
1568 if (strlen(vcard_partnum) > 0) {
1569 vcard_source = load_mimepart(msgnum, vcard_partnum);
1570 if (vcard_source != NULL) {
1572 /* Grab the name off the card */
1573 display_vcard(vcard_source, 0, 0, namebuf);
1579 lastfirst_firstlast(namebuf);
1581 for (i=0; i<strlen(namebuf); ++i) {
1582 if (namebuf[i] != ';') return;
1584 strcpy(namebuf, _("(no name)"));
1590 * \brief Record compare function for sorting address book indices
1591 * \param ab1 adressbook one
1592 * \param ab2 adressbook two
1594 int abcmp(const void *ab1, const void *ab2) {
1596 (((const struct addrbookent *)ab1)->ab_name),
1597 (((const struct addrbookent *)ab2)->ab_name)
1603 * \brief Helper function for do_addrbook_view()
1604 * Converts a name into a three-letter tab label
1605 * \param tabbuf the tabbuffer to add name to
1606 * \param name the name to add to the tabbuffer
1608 void nametab(char *tabbuf, char *name) {
1609 stresc(tabbuf, name, 0, 0);
1610 tabbuf[0] = toupper(tabbuf[0]);
1611 tabbuf[1] = tolower(tabbuf[1]);
1612 tabbuf[2] = tolower(tabbuf[2]);
1618 * \brief Render the address book using info we gathered during the scan
1619 * \param addrbook the addressbook to render
1620 * \param num_ab the number of the addressbook
1622 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1626 static int NAMESPERPAGE = 60;
1630 char tabfirst_label[SIZ];
1632 char tablast_label[SIZ];
1635 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1636 wprintf(_("This address book is empty."));
1637 wprintf("</i></div>\n");
1642 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1645 num_pages = num_ab / NAMESPERPAGE;
1647 page = atoi(bstr("page"));
1650 for (i=0; i<=num_pages; ++i) {
1652 wprintf("<a href=\"readfwd?page=%d\">", i);
1657 tabfirst = i * NAMESPERPAGE;
1658 tablast = tabfirst + NAMESPERPAGE - 1;
1659 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1660 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1661 nametab(tablast_label, addrbook[tablast].ab_name);
1662 wprintf("[%s - %s]",
1663 tabfirst_label, tablast_label
1672 wprintf("<br />\n");
1674 wprintf("<table border=0 cellspacing=0 "
1675 "cellpadding=3 width=100%%>\n"
1678 for (i=0; i<num_ab; ++i) {
1680 if ((i / NAMESPERPAGE) == page) {
1682 if ((displayed % 4) == 0) {
1683 if (displayed > 0) {
1687 wprintf("<tr bgcolor=\"#%s\">",
1688 (bg ? "DDDDDD" : "FFFFFF")
1694 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
1695 addrbook[i].ab_msgnum);
1696 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1697 vcard_n_prettyize(addrbook[i].ab_name);
1698 escputs(addrbook[i].ab_name);
1699 wprintf("</a></td>\n");
1704 wprintf("</tr></table>\n");
1710 * \brief load message pointers from the server
1711 * \param servcmd the citadel command to send to the citserver
1712 * \param with_headers what headers???
1714 int load_msg_ptrs(char *servcmd, int with_headers)
1725 int num_summ_alloc = 0;
1727 if (WC->summ != NULL) {
1732 num_summ_alloc = 100;
1734 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1737 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1739 serv_getln(buf, sizeof buf);
1740 if (buf[0] != '1') {
1741 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1744 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1745 if (nummsgs < maxload) {
1746 WC->msgarr[nummsgs] = extract_long(buf, 0);
1747 datestamp = extract_long(buf, 1);
1748 extract_token(fullname, buf, 2, '|', sizeof fullname);
1749 extract_token(nodename, buf, 3, '|', sizeof nodename);
1750 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1751 extract_token(subject, buf, 5, '|', sizeof subject);
1755 if (nummsgs > num_summ_alloc) {
1756 num_summ_alloc *= 2;
1757 WC->summ = realloc(WC->summ,
1758 num_summ_alloc * sizeof(struct message_summary));
1762 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1763 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1764 safestrncpy(WC->summ[nummsgs-1].subj,
1765 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1766 if (strlen(fullname) > 0) {
1767 safestrncpy(WC->summ[nummsgs-1].from,
1768 fullname, sizeof WC->summ[nummsgs-1].from);
1770 if (strlen(subject) > 0) {
1771 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1772 sizeof WC->summ[nummsgs-1].subj);
1775 /** Handle subjects with RFC2047 encoding */
1776 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1778 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1779 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1782 if (strlen(nodename) > 0) {
1783 if ( ((WC->room_flags & QR_NETWORK)
1784 || ((strcasecmp(nodename, serv_info.serv_nodename)
1785 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1787 strcat(WC->summ[nummsgs-1].from, " @ ");
1788 strcat(WC->summ[nummsgs-1].from, nodename);
1792 WC->summ[nummsgs-1].date = datestamp;
1795 /** Handle senders with RFC2047 encoding */
1796 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1798 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1799 strcpy(&WC->summ[nummsgs-1].from[22], "...");
1808 * \brief compare what????
1809 * \param s1 first thing to compare
1810 * \param s2 second thing to compare
1812 int longcmp_r(const void *s1, const void *s2) {
1819 if (l1 > l2) return(-1);
1820 if (l1 < l2) return(+1);
1826 * \brief compare what????
1827 * \param s1 first thing to compare
1828 * \param s2 second thing to compare
1830 int summcmp_subj(const void *s1, const void *s2) {
1831 struct message_summary *summ1;
1832 struct message_summary *summ2;
1834 summ1 = (struct message_summary *)s1;
1835 summ2 = (struct message_summary *)s2;
1836 return strcasecmp(summ1->subj, summ2->subj);
1840 * \brief compare what????
1841 * \param s1 first thing to compare
1842 * \param s2 second thing to compare
1844 int summcmp_rsubj(const void *s1, const void *s2) {
1845 struct message_summary *summ1;
1846 struct message_summary *summ2;
1848 summ1 = (struct message_summary *)s1;
1849 summ2 = (struct message_summary *)s2;
1850 return strcasecmp(summ2->subj, summ1->subj);
1854 * \brief compare what????
1855 * \param s1 first thing to compare
1856 * \param s2 second thing to compare
1858 int summcmp_sender(const void *s1, const void *s2) {
1859 struct message_summary *summ1;
1860 struct message_summary *summ2;
1862 summ1 = (struct message_summary *)s1;
1863 summ2 = (struct message_summary *)s2;
1864 return strcasecmp(summ1->from, summ2->from);
1868 * \brief compare what????
1869 * \param s1 first thing to compare
1870 * \param s2 second thing to compare
1872 int summcmp_rsender(const void *s1, const void *s2) {
1873 struct message_summary *summ1;
1874 struct message_summary *summ2;
1876 summ1 = (struct message_summary *)s1;
1877 summ2 = (struct message_summary *)s2;
1878 return strcasecmp(summ2->from, summ1->from);
1882 * \brief compare what????
1883 * \param s1 first thing to compare
1884 * \param s2 second thing to compare
1886 int summcmp_date(const void *s1, const void *s2) {
1887 struct message_summary *summ1;
1888 struct message_summary *summ2;
1890 summ1 = (struct message_summary *)s1;
1891 summ2 = (struct message_summary *)s2;
1893 if (summ1->date < summ2->date) return -1;
1894 else if (summ1->date > summ2->date) return +1;
1899 * \brief compare what????
1900 * \param s1 first thing to compare
1901 * \param s2 second thing to compare
1903 int summcmp_rdate(const void *s1, const void *s2) {
1904 struct message_summary *summ1;
1905 struct message_summary *summ2;
1907 summ1 = (struct message_summary *)s1;
1908 summ2 = (struct message_summary *)s2;
1910 if (summ1->date < summ2->date) return +1;
1911 else if (summ1->date > summ2->date) return -1;
1916 * \brief command loop for reading messages
1917 * \param oper what???
1919 void readloop(char *oper)
1928 long *displayed_msgs = NULL;
1929 int num_displayed = 0;
1931 int is_addressbook = 0;
1932 int is_singlecard = 0;
1933 int is_calendar = 0;
1938 int lowest_displayed = (-1);
1939 int highest_displayed = 0;
1940 struct addrbookent *addrbook = NULL;
1942 char *sortby = NULL;
1943 char sortpref_name[128];
1944 char sortpref_value[128];
1945 char *subjsort_button;
1946 char *sendsort_button;
1947 char *datesort_button;
1948 int bbs_reverse = 0;
1950 if (WC->wc_view == VIEW_WIKI) {
1951 sprintf(buf, "wiki?room=%s?page=home", WC->wc_roomname);
1956 startmsg = atol(bstr("startmsg"));
1957 maxmsgs = atoi(bstr("maxmsgs"));
1958 is_summary = atoi(bstr("summary"));
1959 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1961 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
1962 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
1964 sortby = bstr("sortby");
1965 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
1966 set_preference(sortpref_name, sortby, 1);
1968 if (strlen(sortby) == 0) sortby = sortpref_value;
1971 if (strlen(sortby) == 0) sortby = "rdate";
1973 /** message board sort */
1974 if (!strcasecmp(sortby, "reverse")) {
1981 output_headers(1, 1, 1, 0, 0, 0);
1984 * When in summary mode, always show ALL messages instead of just
1985 * new or old. Otherwise, show what the user asked for.
1987 if (!strcmp(oper, "readnew")) {
1988 strcpy(cmd, "MSGS NEW");
1990 else if (!strcmp(oper, "readold")) {
1991 strcpy(cmd, "MSGS OLD");
1994 strcpy(cmd, "MSGS ALL");
1997 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
1999 strcpy(cmd, "MSGS ALL");
2002 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2004 strcpy(cmd, "MSGS ALL");
2009 strcpy(cmd, "MSGS ALL|||1"); /**< fetch header summary */
2015 * Are we doing a summary view? If so, we need to know old messages
2016 * and new messages, so we can do that pretty boldface thing for the
2019 strcpy(old_msgs, "");
2022 serv_getln(buf, sizeof buf);
2023 if (buf[0] == '2') {
2024 strcpy(old_msgs, &buf[4]);
2028 is_singlecard = atoi(bstr("is_singlecard"));
2030 if (WC->wc_view == VIEW_CALENDAR) { /**< calendar */
2032 strcpy(cmd, "MSGS ALL");
2035 if (WC->wc_view == VIEW_TASKS) { /**< tasks */
2037 strcpy(cmd, "MSGS ALL");
2040 if (WC->wc_view == VIEW_NOTES) { /**< notes */
2042 strcpy(cmd, "MSGS ALL");
2046 nummsgs = load_msg_ptrs(cmd, is_summary);
2049 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2051 if (!strcmp(oper, "readnew")) {
2052 wprintf(_("No new messages."));
2053 } else if (!strcmp(oper, "readold")) {
2054 wprintf(_("No old messages."));
2056 wprintf(_("No messages here."));
2065 for (a = 0; a < nummsgs; ++a) {
2066 /** Are you a new message, or an old message? */
2068 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
2069 WC->summ[a].is_new = 0;
2072 WC->summ[a].is_new = 1;
2078 if (startmsg == 0L) {
2080 startmsg = WC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2083 startmsg = WC->msgarr[0];
2088 if (!strcasecmp(sortby, "subject")) {
2089 qsort(WC->summ, WC->num_summ,
2090 sizeof(struct message_summary), summcmp_subj);
2092 else if (!strcasecmp(sortby, "rsubject")) {
2093 qsort(WC->summ, WC->num_summ,
2094 sizeof(struct message_summary), summcmp_rsubj);
2096 else if (!strcasecmp(sortby, "sender")) {
2097 qsort(WC->summ, WC->num_summ,
2098 sizeof(struct message_summary), summcmp_sender);
2100 else if (!strcasecmp(sortby, "rsender")) {
2101 qsort(WC->summ, WC->num_summ,
2102 sizeof(struct message_summary), summcmp_rsender);
2104 else if (!strcasecmp(sortby, "date")) {
2105 qsort(WC->summ, WC->num_summ,
2106 sizeof(struct message_summary), summcmp_date);
2108 else if (!strcasecmp(sortby, "rdate")) {
2109 qsort(WC->summ, WC->num_summ,
2110 sizeof(struct message_summary), summcmp_rdate);
2114 if (!strcasecmp(sortby, "subject")) {
2115 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2117 else if (!strcasecmp(sortby, "rsubject")) {
2118 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2121 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2124 if (!strcasecmp(sortby, "sender")) {
2125 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2127 else if (!strcasecmp(sortby, "rsender")) {
2128 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2131 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2134 if (!strcasecmp(sortby, "date")) {
2135 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2137 else if (!strcasecmp(sortby, "rdate")) {
2138 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2141 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2145 wprintf("</div>\n"); /** end of 'content' div */
2147 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2148 " document.onkeydown = CtdlMsgListKeyPress; "
2149 " if (document.layers) { "
2150 " document.captureEvents(Event.KEYPRESS); "
2155 /** note that Date and Delete are now in the same column */
2156 wprintf("<div id=\"message_list_hdr\">"
2157 "<div class=\"fix_scrollbar_bug\">"
2158 "<table cellspacing=0 style=\"width:100%%\">"
2161 wprintf("<td width=%d%%><b><i>%s</i></b> %s</td>"
2162 "<td width=%d%%><b><i>%s</i></b> %s</td>"
2163 "<td width=%d%%><b><i>%s</i></b> %s"
2165 "<input type=\"submit\" name=\"delete_button\" style=\"font-size:6pt\" "
2166 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2172 _("Subject"), subjsort_button,
2173 SENDER_COL_WIDTH_PCT,
2174 _("Sender"), sendsort_button,
2175 DATE_PLUS_BUTTONS_WIDTH_PCT,
2176 _("Date"), datesort_button,
2179 wprintf("</table></div></div>\n");
2181 wprintf("<div id=\"message_list\">"
2183 "<div class=\"fix_scrollbar_bug\">\n"
2185 "<table class=\"mailbox_summary\" id=\"summary_headers\" rules=rows "
2186 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2190 for (a = 0; a < nummsgs; ++a) {
2191 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2193 /** Display the message */
2195 display_summarized(a);
2197 else if (is_addressbook) {
2198 fetch_ab_name(WC->msgarr[a], buf);
2200 addrbook = realloc(addrbook,
2201 (sizeof(struct addrbookent) * num_ab) );
2202 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2203 sizeof(addrbook[num_ab-1].ab_name));
2204 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
2206 else if (is_calendar) {
2207 display_calendar(WC->msgarr[a]);
2209 else if (is_tasks) {
2210 display_task(WC->msgarr[a]);
2212 else if (is_notes) {
2213 display_note(WC->msgarr[a]);
2216 if (displayed_msgs == NULL) {
2217 displayed_msgs = malloc(sizeof(long) *
2218 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2220 displayed_msgs[num_displayed] = WC->msgarr[a];
2223 if (lowest_displayed < 0) lowest_displayed = a;
2224 highest_displayed = a;
2231 * Set the "is_bbview" variable if it appears that we are looking at
2232 * a classic bulletin board view.
2234 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2235 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2240 if (displayed_msgs != NULL) {
2242 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2245 /** if we do a split bbview in the future, begin messages div here */
2247 for (a=0; a<num_displayed; ++a) {
2248 read_message(displayed_msgs[a], 0, "");
2251 /** if we do a split bbview in the future, end messages div here */
2253 free(displayed_msgs);
2254 displayed_msgs = NULL;
2259 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2260 wprintf("</div>"); /**< end of 'message_list' div */
2262 /** Here's the grab-it-to-resize-the-message-list widget */
2263 wprintf("<div id=\"resize_msglist\" "
2264 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2265 "<div class=\"fix_scrollbar_bug\">"
2266 "<table width=100%% border=3 cellspacing=0 "
2267 "bgcolor=\"#cccccc\" "
2268 "cellpadding=0><TR><TD> </td></tr></table>"
2272 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2276 * Bump these because although we're thinking in zero base, the user
2277 * is a drooling idiot and is thinking in one base.
2280 ++highest_displayed;
2283 * If we're not currently looking at ALL requested
2284 * messages, then display the selector bar
2287 /** begin bbview scroller */
2288 wprintf("<form name=\"msgomatic\">");
2289 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2291 wprintf("<select name=\"whichones\" size=\"1\" "
2292 "OnChange=\"location.href=msgomatic.whichones.options"
2293 "[selectedIndex].value\">\n");
2296 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2298 lo = b - maxmsgs + 2;
2300 wprintf("<option %s value="
2305 "%d-%d</option> \n",
2306 ((WC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2315 for (b=0; b<nummsgs; b = b + maxmsgs) {
2317 hi = b + maxmsgs + 1;
2318 if (hi > nummsgs) hi = nummsgs;
2319 wprintf("<option %s value="
2324 "%d-%d</option> \n",
2325 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2334 wprintf("<option value=\"%s?startmsg=%ld"
2335 "?maxmsgs=9999999?summary=%d\">"
2339 WC->msgarr[0], is_summary);
2341 wprintf("</select> ");
2342 wprintf(_("of %d messages."), nummsgs);
2344 /** forward/reverse */
2345 wprintf(" <select name=\"direction\" size=\"1\" "
2346 "OnChange=\"location.href=msgomatic.direction.options"
2347 "[selectedIndex].value\">\n"
2350 wprintf("<option %s value=\"%s?sortby=forward\">oldest to newest</option>\n",
2351 (bbs_reverse ? "" : "selected"),
2355 wprintf("<option %s value=\"%s?sortby=reverse\">newest to oldest</option>\n",
2356 (bbs_reverse ? "selected" : ""),
2360 wprintf("</select></form>\n");
2361 /** end bbview scroller */
2366 do_tasks_view(); /** Render the task list */
2370 do_calendar_view(); /** Render the calendar */
2373 if (is_addressbook) {
2374 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2377 /** Note: wDumpContent() will output one additional </div> tag. */
2379 if (addrbook != NULL) free(addrbook);
2381 /** free the summary */
2382 if (WC->summ != NULL) {
2391 * \brief Back end for post_message()
2392 * ... this is where the actual message gets transmitted to the server.
2394 void post_mime_to_server(void) {
2396 int is_multipart = 0;
2398 struct wc_attachment *att;
2400 size_t encoded_length;
2402 /** RFC2045 requires this, and some clients look for it... */
2403 serv_puts("MIME-Version: 1.0");
2405 /** If there are attachments, we have to do multipart/mixed */
2406 if (WC->first_attachment != NULL) {
2411 sprintf(boundary, "---Citadel-Multipart-%s-%04x%04x---",
2412 serv_info.serv_fqdn,
2417 /** Remember, serv_printf() appends an extra newline */
2418 serv_printf("Content-type: multipart/mixed; "
2419 "boundary=\"%s\"\n", boundary);
2420 serv_printf("This is a multipart message in MIME format.\n");
2421 serv_printf("--%s", boundary);
2424 serv_puts("Content-type: text/html; charset=utf-8");
2426 serv_puts("<html><body>\n"); /** Future templates go here */
2427 text_to_server(bstr("msgtext"), 0);
2428 serv_puts("</body></html>\n");
2433 /** Add in the attachments */
2434 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2436 encoded_length = ((att->length * 150) / 100);
2437 encoded = malloc(encoded_length);
2438 if (encoded == NULL) break;
2439 CtdlEncodeBase64(encoded, att->data, att->length);
2441 serv_printf("--%s", boundary);
2442 serv_printf("Content-type: %s", att->content_type);
2443 serv_printf("Content-disposition: attachment; "
2444 "filename=\"%s\"", att->filename);
2445 serv_puts("Content-transfer-encoding: base64");
2447 serv_write(encoded, strlen(encoded));
2452 serv_printf("--%s--", boundary);
2460 * \brief Post message (or don't post message)
2462 * Note regarding the "dont_post" variable:
2463 * A random value (actually, it's just a timestamp) is inserted as a hidden
2464 * field called "postseq" when the display_enter page is generated. This
2465 * value is checked when posting, using the static variable dont_post. If a
2466 * user attempts to post twice using the same dont_post value, the message is
2467 * discarded. This prevents the accidental double-saving of the same message
2468 * if the user happens to click the browser "back" button.
2470 void post_message(void)
2473 static long dont_post = (-1L);
2474 struct wc_attachment *att, *aptr;
2475 int is_anonymous = 0;
2477 if (!strcasecmp(bstr("is_anonymous"), "yes")) {
2481 if (WC->upload_length > 0) {
2483 /** There's an attachment. Save it to this struct... */
2484 att = malloc(sizeof(struct wc_attachment));
2485 memset(att, 0, sizeof(struct wc_attachment));
2486 att->length = WC->upload_length;
2487 strcpy(att->content_type, WC->upload_content_type);
2488 strcpy(att->filename, WC->upload_filename);
2491 /** And add it to the list. */
2492 if (WC->first_attachment == NULL) {
2493 WC->first_attachment = att;
2496 aptr = WC->first_attachment;
2497 while (aptr->next != NULL) aptr = aptr->next;
2502 * Mozilla sends a simple filename, which is what we want,
2503 * but Satan's Browser sends an entire pathname. Reduce
2504 * the path to just a filename if we need to.
2506 while (num_tokens(att->filename, '/') > 1) {
2507 remove_token(att->filename, 0, '/');
2509 while (num_tokens(att->filename, '\\') > 1) {
2510 remove_token(att->filename, 0, '\\');
2514 * Transfer control of this memory from the upload struct
2515 * to the attachment struct.
2517 att->data = WC->upload;
2518 WC->upload_length = 0;
2524 if (strlen(bstr("cancel_button")) > 0) {
2525 sprintf(WC->ImportantMessage,
2526 _("Cancelled. Message was not posted."));
2527 } else if (strlen(bstr("attach_button")) > 0) {
2530 } else if (atol(bstr("postseq")) == dont_post) {
2531 sprintf(WC->ImportantMessage,
2532 _("Automatically cancelled because you have already "
2533 "saved this message."));
2535 sprintf(buf, "ENT0 1|%s|%d|4|%s|||%s|%s|%s",
2544 serv_getln(buf, sizeof buf);
2545 if (buf[0] == '4') {
2546 post_mime_to_server();
2547 if ( (strlen(bstr("recp")) > 0)
2548 || (strlen(bstr("cc")) > 0)
2549 || (strlen(bstr("bcc")) > 0)
2551 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2554 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2556 dont_post = atol(bstr("postseq"));
2558 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2564 free_attachments(WC);
2567 * We may have been supplied with instructions regarding the location
2568 * to which we must return after posting. If found, go there.
2570 if (strlen(bstr("return_to")) > 0) {
2571 http_redirect(bstr("return_to"));
2574 * If we were editing a page in a wiki room, go to that page now.
2576 else if (strlen(bstr("wikipage")) > 0) {
2577 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
2581 * Otherwise, just go to the "read messages" loop.
2584 readloop("readnew");
2592 * \brief display the message entry screen
2594 void display_enter(void)
2599 struct wc_attachment *att;
2600 int recipient_required = 0;
2601 int recipient_bad = 0;
2603 int is_anonymous = 0;
2604 long existing_page = (-1L);
2606 if (strlen(bstr("force_room")) > 0) {
2607 gotoroom(bstr("force_room"));
2610 if (!strcasecmp(bstr("is_anonymous"), "yes")) {
2615 * Are we perhaps in an address book view? If so, then an "enter
2616 * message" command really means "add new entry."
2618 if (WC->wc_view == VIEW_ADDRESSBOOK) {
2619 do_edit_vcard(-1, "", "");
2623 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
2625 * Are we perhaps in a calendar view? If so, then an "enter
2626 * message" command really means "add new calendar item."
2628 if (WC->wc_view == VIEW_CALENDAR) {
2629 display_edit_event();
2634 * Are we perhaps in a tasks view? If so, then an "enter
2635 * message" command really means "add new task."
2637 if (WC->wc_view == VIEW_TASKS) {
2638 display_edit_task();
2644 * Otherwise proceed normally.
2645 * Do a custom room banner with no navbar...
2647 output_headers(1, 1, 2, 0, 0, 0);
2648 wprintf("<div id=\"banner\">\n");
2649 embed_room_banner(NULL, navbar_none);
2650 wprintf("</div>\n");
2651 wprintf("<div id=\"content\">\n"
2652 "<div class=\"fix_scrollbar_bug\">"
2653 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
2655 /** First test to see whether this is a room that requires recipients to be entered */
2656 serv_puts("ENT0 0");
2657 serv_getln(buf, sizeof buf);
2658 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
2659 recipient_required = 1;
2661 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2662 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2666 /** Now check our actual recipients if there are any */
2667 if (recipient_required) {
2668 sprintf(buf, "ENT0 0|%s|%d|0||||%s|%s|%s", bstr("recp"), is_anonymous,
2669 bstr("cc"), bstr("bcc"), bstr("wikipage"));
2671 serv_getln(buf, sizeof buf);
2673 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
2674 if (strlen(bstr("recp")) + strlen(bstr("cc")) + strlen(bstr("bcc")) > 0) {
2678 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2679 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2684 /** If we got this far, we can display the message entry screen. */
2687 fmt_date(buf, now, 0);
2688 strcat(&buf[strlen(buf)], _(" <I>from</I> "));
2689 stresc(&buf[strlen(buf)], WC->wc_fullname, 1, 1);
2691 /* Don't need this anymore, it's in the input box below
2692 if (strlen(bstr("recp")) > 0) {
2693 strcat(&buf[strlen(buf)], _(" <I>to</I> "));
2694 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
2698 strcat(&buf[strlen(buf)], _(" <I>in</I> "));
2699 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
2701 /** begin message entry screen */
2702 wprintf("<form enctype=\"multipart/form-data\" "
2703 "method=\"POST\" action=\"post\" "
2704 "name=\"enterform\""
2706 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2707 if (WC->wc_view == VIEW_WIKI) {
2708 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
2710 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
2712 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2713 wprintf("%s\n", buf); /** header bar */
2714 if (WC->room_flags & QR_ANONOPT) {
2716 "<input type=\"checkbox\" name=\"is_anonymous\" value=\"yes\" %s>",
2717 (is_anonymous ? "checked" : "")
2719 wprintf("Anonymous");
2721 wprintf("<br>\n"); /** header bar */
2723 wprintf("<table border=\"0\" width=\"100%%\">\n");
2724 if (recipient_required) {
2726 wprintf("<tr><td>");
2727 wprintf("<font size=-1>");
2731 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
2732 escputs(bstr("recp"));
2733 wprintf("\" size=50 maxlength=1000 />");
2734 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
2735 wprintf("</td><td></td></tr>\n");
2737 wprintf("<tr><td>");
2738 wprintf("<font size=-1>");
2742 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
2743 escputs(bstr("cc"));
2744 wprintf("\" size=50 maxlength=1000 />");
2745 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
2746 wprintf("</td><td></td></tr>\n");
2748 wprintf("<tr><td>");
2749 wprintf("<font size=-1>");
2753 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
2754 escputs(bstr("bcc"));
2755 wprintf("\" size=50 maxlength=1000 />");
2756 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
2757 wprintf("</td><td></td></tr>\n");
2759 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
2760 wprintf("<script type=\"text/javascript\"> \n"
2761 " activate_entmsg_autocompleters(); \n"
2766 wprintf("<tr><td>");
2767 wprintf("<font size=-1>");
2768 wprintf(_("Subject (optional):"));
2771 "<input type=\"text\" name=\"subject\" value=\"");
2772 escputs(bstr("subject"));
2773 wprintf("\" size=50 maxlength=70></td><td>\n");
2775 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2776 if (recipient_required) {
2777 wprintf(_("Send message"));
2779 wprintf(_("Post message"));
2782 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2783 wprintf("</td></tr></table>\n");
2785 wprintf("<center>");
2787 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
2789 /** If we're continuing from a previous edit, put our partially-composed message back... */
2790 msgescputs(bstr("msgtext"));
2792 /* If we're forwarding a message, insert it here... */
2793 if (atol(bstr("fwdquote")) > 0L) {
2794 wprintf("<br><div align=center><i>");
2795 wprintf(_("--- forwarded message ---"));
2796 wprintf("</i></div><br>");
2797 pullquote_message(atol(bstr("fwdquote")), 1, 1);
2800 /** If we're replying quoted, insert the quote here... */
2801 else if (atol(bstr("replyquote")) > 0L) {
2804 pullquote_message(atol(bstr("replyquote")), 0, 1);
2805 wprintf("</blockquote>\n\n");
2808 /** If we're editing a wiki page, insert the existing page here... */
2809 else if (WC->wc_view == VIEW_WIKI) {
2810 safestrncpy(buf, bstr("wikipage"), sizeof buf);
2811 str_wiki_index(buf);
2812 existing_page = locate_message_by_uid(buf);
2813 if (existing_page >= 0L) {
2814 pullquote_message(existing_page, 1, 0);
2818 /** Insert our signature if appropriate... */
2819 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
2820 get_preference("use_sig", buf, sizeof buf);
2821 if (!strcasecmp(buf, "yes")) {
2822 get_preference("signature", ebuf, sizeof ebuf);
2823 euid_unescapize(buf, ebuf);
2824 wprintf("<br>--<br>");
2825 for (i=0; i<strlen(buf); ++i) {
2826 if (buf[i] == '\n') {
2829 else if (buf[i] == '<') {
2832 else if (buf[i] == '>') {
2835 else if (buf[i] == '&') {
2838 else if (buf[i] == '\"') {
2841 else if (buf[i] == '\'') {
2844 else if (isprint(buf[i])) {
2845 wprintf("%c", buf[i]);
2851 wprintf("</textarea>");
2852 wprintf("</center><br />\n");
2855 * The following script embeds the TinyMCE richedit control, and automatically
2856 * transforms the textarea into a richedit textarea.
2859 "<script language=\"javascript\" type=\"text/javascript\" src=\"tiny_mce/tiny_mce.js\"></script>\n"
2860 "<script language=\"javascript\" type=\"text/javascript\">"
2862 " mode : \"textareas\", width : \"100%%\", browsers : \"msie,gecko\", "
2863 " theme : \"advanced\", plugins : \"iespell\", "
2864 " theme_advanced_buttons1 : \"bold, italic, underline, strikethrough, justifyleft, justifycenter, justifyright, justifyfull, bullist, numlist, cut, copy, paste, link, image, help, forecolor, iespell, code\", "
2865 " theme_advanced_buttons2 : \"\", "
2866 " theme_advanced_buttons3 : \"\" "
2872 /** Enumerate any attachments which are already in place... */
2873 wprintf("<img src=\"static/diskette_24x.gif\" border=0 "
2874 "align=middle height=16 width=16> ");
2875 wprintf(_("Attachments:"));
2877 wprintf("<select name=\"which_attachment\" size=1>");
2878 for (att = WC->first_attachment; att != NULL; att = att->next) {
2879 wprintf("<option value=\"");
2880 urlescputs(att->filename);
2882 escputs(att->filename);
2883 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
2884 wprintf("</option>\n");
2886 wprintf("</select>");
2888 /** Now offer the ability to attach additional files... */
2889 wprintf(" ");
2890 wprintf(_("Attach file:"));
2891 wprintf(" <input NAME=\"attachfile\" "
2892 "SIZE=16 TYPE=\"file\">\n "
2893 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
2895 /** Seth asked for these to be at the top *and* bottom... */
2896 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2897 if (recipient_required) {
2898 wprintf(_("Send message"));
2900 wprintf(_("Post message"));
2903 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2905 /** Make sure we only insert our signature once */
2906 if (strcmp(bstr("sig_inserted"), "yes")) {
2907 wprintf("<INPUT TYPE=\"hidden\" NAME=\"sig_inserted\" VALUE=\"yes\">\n");
2910 wprintf("</form>\n");
2912 wprintf("</td></tr></table></div>\n");
2913 DONE: wDumpContent(1);
2919 * \brief delete a message
2921 void delete_msg(void)
2926 msgid = atol(bstr("msgid"));
2928 output_headers(1, 1, 1, 0, 0, 0);
2930 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
2931 serv_printf("DELE %ld", msgid);
2933 else { /** Otherwise move it to Trash */
2934 serv_printf("MOVE %ld|_TRASH_|0", msgid);
2937 serv_getln(buf, sizeof buf);
2938 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2947 * \brief Confirm move of a message
2949 void confirm_move_msg(void)
2955 msgid = atol(bstr("msgid"));
2958 output_headers(1, 1, 2, 0, 0, 0);
2959 wprintf("<div id=\"banner\">\n");
2960 wprintf("<TABLE WIDTH=100%% BORDER=0><TR><TD>");
2961 wprintf("<SPAN CLASS=\"titlebar\">");
2962 wprintf(_("Confirm move of message"));
2963 wprintf("</SPAN>\n");
2964 wprintf("</TD></TR></TABLE>\n");
2965 wprintf("</div>\n<div id=\"content\">\n");
2967 wprintf("<CENTER>");
2969 wprintf(_("Move this message to:"));
2970 wprintf("<br />\n");
2972 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
2973 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
2975 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
2977 serv_getln(buf, sizeof buf);
2978 if (buf[0] == '1') {
2979 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2980 extract_token(targ, buf, 0, '|', sizeof targ);
2981 wprintf("<OPTION>");
2986 wprintf("</SELECT>\n");
2987 wprintf("<br />\n");
2989 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
2991 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
2992 wprintf("</form></CENTER>\n");
2994 wprintf("</CENTER>\n");
3000 * \brief move a message to another folder
3007 msgid = atol(bstr("msgid"));
3009 if (strlen(bstr("move_button")) > 0) {
3010 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3012 serv_getln(buf, sizeof buf);
3013 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3015 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3018 readloop("readnew");