5 * \defgroup MsgDisp Functions which deal with the fetching and displaying of messages.
6 * \ingroup WebcitDisplayItems
12 #include "webserver.h"
15 #define SUBJ_COL_WIDTH_PCT 50 /**< Mailbox view column width */
16 #define SENDER_COL_WIDTH_PCT 30 /**< Mailbox view column width */
17 #define DATE_PLUS_BUTTONS_WIDTH_PCT 20 /**< Mailbox view column width */
20 * Address book entry (keep it short and sweet, it's just a quickie lookup
21 * which we can use to get to the real meat and bones later)
24 char ab_name[64]; /**< name string */
25 long ab_msgnum; /**< message number of address book entry */
32 * \brief Handle subjects with RFC2047 encoding
34 * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=
35 * \param buf the stringbuffer to process
37 void utf8ify_rfc822_string(char *buf) {
43 iconv_t ic = (iconv_t)(-1) ;
44 char *ibuf; /**< Buffer of characters to be converted */
45 char *obuf; /**< Buffer for converted characters */
46 size_t ibuflen; /**< Length of input buffer */
47 size_t obuflen; /**< Length of output buffer */
48 char *isav; /**< Saved pointer to input buffer */
49 char *osav; /**< Saved pointer to output buffer */
52 while (start=strstr(buf, "=?"), end=strstr(buf, "?="),
53 ((start != NULL) && (end != NULL) && (end > start)) )
55 extract_token(charset, start, 1, '?', sizeof charset);
56 extract_token(encoding, start, 2, '?', sizeof encoding);
57 extract_token(istr, start, 3, '?', sizeof istr);
65 if (!strcasecmp(encoding, "B")) { /**< base64 */
66 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
68 else if (!strcasecmp(encoding, "Q")) { /**< quoted-printable */
69 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, strlen(istr));
72 strcpy(ibuf, istr); /**< huh? */
73 ibuflen = strlen(istr);
76 ic = iconv_open("UTF-8", charset);
77 if (ic != (iconv_t)(-1) ) {
80 obuf = (char *) malloc(obuflen);
82 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
83 osav[1024-obuflen] = 0;
88 remove_token(end, 0, '?');
89 remove_token(end, 0, '?');
90 remove_token(end, 0, '?');
91 remove_token(end, 0, '?');
94 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
103 remove_token(end, 0, '?');
104 remove_token(end, 0, '?');
105 remove_token(end, 0, '?');
106 remove_token(end, 0, '?');
107 strcpy(end, &end[1]);
109 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
116 * Since spammers will go to all sorts of absurd lengths to get their
117 * messages through, there are LOTS of corrupt headers out there.
118 * So, prevent a really badly formed RFC2047 header from throwing
119 * this function into an infinite loop.
122 if (passes > 20) return;
130 * \brief Look for URL's embedded in a buffer and make them linkable. We use a
131 * target window in order to keep the BBS session in its own window.
132 * \param buf the message buffer
147 for (pos = 0; pos < strlen(buf); ++pos) {
148 if (!strncasecmp(&buf[pos], "http://", 7))
150 if (!strncasecmp(&buf[pos], "ftp://", 6))
157 if ((start > 0) && (buf[start - 1] == '<'))
159 if ((start > 0) && (buf[start - 1] == '['))
161 if ((start > 0) && (buf[start - 1] == '('))
163 if ((start > 0) && (buf[start - 1] == '{'))
166 for (pos = strlen(buf); pos > start; --pos) {
167 if ((buf[pos] == ' ') || (buf[pos] == ench))
171 strncpy(urlbuf, &buf[start], end - start);
172 urlbuf[end - start] = 0;
174 strncpy(outbuf, buf, start);
175 sprintf(&outbuf[start], "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
176 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
177 strcat(outbuf, &buf[end]);
178 if ( strlen(outbuf) < 250 )
184 * \brief Turn a vCard "n" (name) field into something displayable.
185 * \param name the name field to convert
187 void vcard_n_prettyize(char *name)
192 original_name = strdup(name);
193 for (i=0; i<5; ++i) {
194 if (strlen(original_name) > 0) {
195 if (original_name[strlen(original_name)-1] == ' ') {
196 original_name[strlen(original_name)-1] = 0;
198 if (original_name[strlen(original_name)-1] == ';') {
199 original_name[strlen(original_name)-1] = 0;
204 for (i=0; i<strlen(original_name); ++i) {
205 if (original_name[i] == ';') {
209 name[strlen(name)+1] = 0;
210 name[strlen(name)] = original_name[i];
220 * \brief preparse a vcard name
221 * display_vcard() calls this after parsing the textual vCard into
222 * our 'struct vCard' data object.
223 * This gets called instead of display_parsed_vcard() if we are only looking
224 * to extract the person's name instead of displaying the card.
225 * \param v the vcard to retrieve the name from
226 * \param storename where to put the name at
228 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
231 strcpy(storename, "");
233 name = vcard_get_prop(v, "n", 1, 0, 0);
235 strcpy(storename, name);
236 /* vcard_n_prettyize(storename); */
244 * \brief html print a vcard
245 * display_vcard() calls this after parsing the textual vCard into
246 * our 'struct vCard' data object.
248 * Set 'full' to nonzero to display the full card, otherwise it will only
249 * show a summary line.
251 * This code is a bit ugly, so perhaps an explanation is due: we do this
252 * in two passes through the vCard fields. On the first pass, we process
253 * fields we understand, and then render them in a pretty fashion at the
254 * end. Then we make a second pass, outputting all the fields we don't
255 * understand in a simple two-column name/value format.
256 * \param v the vCard to display
257 * \param full display all items of the vcard?
259 void display_parsed_vcard(struct vCard *v, int full) {
265 char *thisname, *thisvalue;
266 char firsttoken[SIZ];
275 strcpy(fullname, "");
283 name = vcard_get_prop(v, "fn", 1, 0, 0);
287 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
288 strcpy(fullname, name);
289 vcard_n_prettyize(fullname);
299 wprintf("<div align=center><table bgcolor=#aaaaaa width=50%%>");
300 for (pass=1; pass<=2; ++pass) {
302 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
304 thisname = strdup(v->prop[i].name);
305 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
307 for (j=0; j<num_tokens(thisname, ';'); ++j) {
308 extract_token(buf, thisname, j, ';', sizeof buf);
309 if (!strcasecmp(buf, "encoding=quoted-printable")) {
311 remove_token(thisname, j, ';');
313 if (!strcasecmp(buf, "encoding=base64")) {
315 remove_token(thisname, j, ';');
320 thisvalue = malloc(strlen(v->prop[i].value) + 50);
321 j = CtdlDecodeQuotedPrintable(
322 thisvalue, v->prop[i].value,
323 strlen(v->prop[i].value) );
327 thisvalue = malloc(strlen(v->prop[i].value) + 50);
329 thisvalue, v->prop[i].value,
330 strlen(v->prop[i].value) );
333 thisvalue = strdup(v->prop[i].value);
336 /** Various fields we may encounter ***/
338 /** N is name, but only if there's no FN already there */
339 if (!strcasecmp(firsttoken, "n")) {
340 if (strlen(fullname) == 0) {
341 strcpy(fullname, thisvalue);
342 vcard_n_prettyize(fullname);
346 /** FN (full name) is a true 'display name' field */
347 else if (!strcasecmp(firsttoken, "fn")) {
348 strcpy(fullname, thisvalue);
352 else if (!strcasecmp(firsttoken, "title")) {
353 strcpy(title, thisvalue);
357 else if (!strcasecmp(firsttoken, "org")) {
358 strcpy(org, thisvalue);
361 else if (!strcasecmp(firsttoken, "email")) {
362 if (strlen(mailto) > 0) strcat(mailto, "<br />");
364 "<a href=\"display_enter"
365 "?force_room=_MAIL_?recp=");
367 urlesc(&mailto[strlen(mailto)], fullname);
368 urlesc(&mailto[strlen(mailto)], " <");
369 urlesc(&mailto[strlen(mailto)], thisvalue);
370 urlesc(&mailto[strlen(mailto)], ">");
372 strcat(mailto, "\">");
373 stresc(&mailto[strlen(mailto)], thisvalue, 1, 1);
374 strcat(mailto, "</A>");
376 else if (!strcasecmp(firsttoken, "tel")) {
377 if (strlen(phone) > 0) strcat(phone, "<br />");
378 strcat(phone, thisvalue);
379 for (j=0; j<num_tokens(thisname, ';'); ++j) {
380 extract_token(buf, thisname, j, ';', sizeof buf);
381 if (!strcasecmp(buf, "tel"))
383 else if (!strcasecmp(buf, "work"))
384 strcat(phone, _(" (work)"));
385 else if (!strcasecmp(buf, "home"))
386 strcat(phone, _(" (home)"));
387 else if (!strcasecmp(buf, "cell"))
388 strcat(phone, _(" (cell)"));
396 else if (!strcasecmp(firsttoken, "adr")) {
399 wprintf(_("Address:"));
400 wprintf("</TD><TD>");
401 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
402 extract_token(buf, thisvalue, j, ';', sizeof buf);
403 if (strlen(buf) > 0) {
405 if (j<3) wprintf("<br />");
409 wprintf("</TD></TR>\n");
412 else if (!strcasecmp(firsttoken, "version")) {
415 else if (!strcasecmp(firsttoken, "rev")) {
418 else if (!strcasecmp(firsttoken, "label")) {
423 /*** Don't show extra fields. They're ugly.
427 wprintf("</TD><TD>");
429 wprintf("</TD></TR>\n");
439 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
440 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
441 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
442 "<FONT SIZE=+1><B>");
444 wprintf("</B></FONT>");
445 if (strlen(title) > 0) {
446 wprintf("<div align=right>");
450 if (strlen(org) > 0) {
451 wprintf("<div align=right>");
455 wprintf("</TD></TR>\n");
457 if (strlen(phone) > 0) {
459 wprintf(_("Telephone:"));
460 wprintf("</td><td>%s</td></tr>\n", phone);
462 if (strlen(mailto) > 0) {
464 wprintf(_("E-mail:"));
465 wprintf("</td><td>%s</td></tr>\n", mailto);
471 wprintf("</table></div>\n");
477 * \brief Display a textual vCard
478 * (Converts to a vCard object and then calls the actual display function)
479 * Set 'full' to nonzero to display the whole card instead of a one-liner.
480 * Or, if "storename" is non-NULL, just store the person's name in that
481 * buffer instead of displaying the card at all.
482 * \param vcard_source the buffer containing the vcard text
483 * \param alpha what???
484 * \param full should we usse all lines?
485 * \param storename where to store???
487 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
493 v = vcard_load(vcard_source);
494 if (v == NULL) return;
496 name = vcard_get_prop(v, "n", 1, 0, 0);
502 if (storename != NULL) {
503 fetchname_parsed_vcard(v, storename);
505 else if ( (alpha == 0)
506 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
507 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
509 display_parsed_vcard(v, full);
517 * \brief I wanna SEE that message!
518 * \param msgnum the citadel number of the message to display
519 * \param printable_view are we doing a print view?
520 * \param section Optional for encapsulated message/rfc822 submessage)
522 void read_message(long msgnum, int printable_view, char *section) {
524 char mime_partnum[256];
525 char mime_filename[256];
526 char mime_content_type[256];
527 char mime_charset[256];
528 char mime_disposition[256];
531 char mime_submessages[256];
538 char reply_all[4096];
544 char vcard_partnum[256];
545 char cal_partnum[256];
546 char *part_source = NULL;
548 iconv_t ic = (iconv_t)(-1) ;
549 char *ibuf; /**< Buffer of characters to be converted */
550 char *obuf; /**< Buffer for converted characters */
551 size_t ibuflen; /**< Length of input buffer */
552 size_t obuflen; /**< Length of output buffer */
553 char *osav; /**< Saved pointer to output buffer */
559 strcpy(reply_to, "");
560 strcpy(reply_all, "");
561 strcpy(vcard_partnum, "");
562 strcpy(cal_partnum, "");
563 strcpy(mime_http, "");
564 strcpy(mime_content_type, "text/plain");
565 strcpy(mime_charset, "us-ascii");
566 strcpy(mime_submessages, "");
568 serv_printf("MSG4 %ld|%s", msgnum, section);
569 serv_getln(buf, sizeof buf);
572 wprintf(_("ERROR:"));
573 wprintf("</STRONG> %s<br />\n", &buf[4]);
577 /** begin everythingamundo table */
578 if (!printable_view) {
579 wprintf("<div class=\"fix_scrollbar_bug\">\n");
580 wprintf("<table width=100%% border=1 cellspacing=0 "
581 "cellpadding=0><TR><TD>\n");
584 /** begin message header table */
585 wprintf("<table width=100%% border=0 cellspacing=0 "
586 "cellpadding=1 bgcolor=\"#CCCCCC\"><tr><td>\n");
588 wprintf("<span class=\"message_header\">");
589 strcpy(m_subject, "");
592 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
593 if (!strcmp(buf, "000")) {
595 wprintf(_("unexpected end of message"));
596 wprintf("</i><br /><br />\n");
597 wprintf("</span>\n");
600 if (!strncasecmp(buf, "nhdr=yes", 8))
604 if (!strncasecmp(buf, "type=", 5))
605 format_type = atoi(&buf[5]);
606 if (!strncasecmp(buf, "from=", 5)) {
607 strcpy(from, &buf[5]);
609 wprintf("<a href=\"showuser?who=");
611 utf8ify_rfc822_string(from);
618 if (!strncasecmp(buf, "subj=", 5)) {
619 safestrncpy(m_subject, &buf[5], sizeof m_subject);
621 if (!strncasecmp(buf, "cccc=", 5)) {
622 safestrncpy(m_cc, &buf[5], sizeof m_cc);
623 if (strlen(reply_all) > 0) {
624 strcat(reply_all, ", ");
626 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
627 (sizeof reply_all - strlen(reply_all)) );
629 if ((!strncasecmp(buf, "hnod=", 5))
630 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
631 wprintf("(%s) ", &buf[5]);
633 if ((!strncasecmp(buf, "room=", 5))
634 && (strcasecmp(&buf[5], WC->wc_roomname))
635 && (strlen(&buf[5])>0) ) {
637 wprintf("%s> ", &buf[5]);
639 if (!strncasecmp(buf, "rfca=", 5)) {
640 strcpy(rfca, &buf[5]);
646 if (!strncasecmp(buf, "node=", 5)) {
647 strcpy(node, &buf[5]);
648 if ( ((WC->room_flags & QR_NETWORK)
649 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
650 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
653 wprintf("@%s ", &buf[5]);
656 if (!strncasecmp(buf, "rcpt=", 5)) {
658 if (strlen(reply_all) > 0) {
659 strcat(reply_all, ", ");
661 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
662 (sizeof reply_all - strlen(reply_all)) );
663 utf8ify_rfc822_string(&buf[5]);
667 if (!strncasecmp(buf, "time=", 5)) {
668 fmt_date(now, atol(&buf[5]), 0);
672 if (!strncasecmp(buf, "part=", 5)) {
673 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
674 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
675 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
676 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
677 mime_length = extract_int(&buf[5], 5);
679 if (!strcasecmp(mime_content_type, "message/rfc822")) {
680 if (strlen(mime_submessages) > 0) {
681 strcat(mime_submessages, "|");
683 strcat(mime_submessages, mime_partnum);
685 else if ((!strcasecmp(mime_disposition, "inline"))
686 && (!strncasecmp(mime_content_type, "image/", 6)) ){
687 snprintf(&mime_http[strlen(mime_http)],
688 (sizeof(mime_http) - strlen(mime_http) - 1),
689 "<img src=\"mimepart/%ld/%s/%s\">",
690 msgnum, mime_partnum, mime_filename);
692 else if ( (!strcasecmp(mime_disposition, "attachment"))
693 || (!strcasecmp(mime_disposition, "inline")) ) {
694 snprintf(&mime_http[strlen(mime_http)],
695 (sizeof(mime_http) - strlen(mime_http) - 1),
696 "<img src=\"static/diskette_24x.gif\" "
697 "border=0 align=middle>\n"
698 "%s (%s, %d bytes) [ "
699 "<a href=\"mimepart/%ld/%s/%s\""
700 "target=\"wc.%ld.%s\">%s</a>"
702 "<a href=\"mimepart_download/%ld/%s/%s\">%s</a>"
705 mime_content_type, mime_length,
706 msgnum, mime_partnum, mime_filename,
707 msgnum, mime_partnum,
709 msgnum, mime_partnum, mime_filename,
714 /** begin handler prep ***/
715 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
716 strcpy(vcard_partnum, mime_partnum);
719 if (!strcasecmp(mime_content_type, "text/calendar")) {
720 strcpy(cal_partnum, mime_partnum);
723 /** end handler prep ***/
729 /** Generate a reply-to address */
730 if (strlen(rfca) > 0) {
731 strcpy(reply_to, rfca);
734 if ( (strlen(node) > 0)
735 && (strcasecmp(node, serv_info.serv_nodename))
736 && (strcasecmp(node, serv_info.serv_humannode)) ) {
737 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
741 snprintf(reply_to, sizeof(reply_to), "%s", from);
751 utf8ify_rfc822_string(m_cc);
752 utf8ify_rfc822_string(m_subject);
754 if (strlen(m_cc) > 0) {
756 "<span class=\"message_subject\">");
762 if (strlen(m_subject) > 0) {
764 "<span class=\"message_subject\">");
765 wprintf(_("Subject:"));
772 /** start msg buttons */
773 if (!printable_view) {
774 wprintf("<td align=right><span class=\"msgbuttons\">\n");
777 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
778 wprintf("<a href=\"display_enter");
779 if (WC->is_mailbox) {
780 wprintf("?replyquote=%ld", msgnum);
783 urlescputs(reply_to);
784 if (strlen(m_subject) > 0) {
785 wprintf("?subject=");
786 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
787 urlescputs(m_subject);
789 wprintf("\">[%s]</a> ", _("Reply"));
793 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
794 if (!WC->is_mailbox) {
795 wprintf("<a href=\"display_enter");
796 wprintf("?replyquote=%ld", msgnum);
798 urlescputs(reply_to);
799 if (strlen(m_subject) > 0) {
800 wprintf("?subject=");
801 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
802 urlescputs(m_subject);
804 wprintf("\">[%s]</a> ", _("ReplyQuoted"));
809 if (WC->wc_view == VIEW_MAILBOX) {
810 wprintf("<a href=\"display_enter");
811 wprintf("?replyquote=%ld", msgnum);
813 urlescputs(reply_to);
815 urlescputs(reply_all);
816 if (strlen(m_subject) > 0) {
817 wprintf("?subject=");
818 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
819 urlescputs(m_subject);
821 wprintf("\">[%s]</a> ", _("ReplyAll"));
825 if (WC->wc_view == VIEW_MAILBOX) {
826 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
827 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
828 urlescputs(m_subject);
829 wprintf("\">[%s]</a> ", _("Forward"));
832 /** If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
833 if ( (WC->is_room_aide) || (WC->is_mailbox) ) {
835 wprintf("<a href=\"confirm_move_msg?msgid=%ld\">[%s]</a> ",
839 wprintf("<a href=\"delete_msg?msgid=%ld\" "
840 "onClick=\"return confirm('%s');\">"
841 "[%s]</a> ", msgnum, _("Delete this message?"), _("Delete")
846 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'); \" >"
847 "[%s]</a>", msgnum, msgnum, _("Headers"));
851 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'); \" >"
852 "[%s]</a>", msgnum, msgnum, _("Print"));
854 wprintf("</span></td>");
857 wprintf("</tr></table>\n");
860 wprintf("<table border=0 width=100%% bgcolor=\"#FFFFFF\" "
861 "cellpadding=1 cellspacing=0><tr><td>");
864 * Learn the content type
866 strcpy(mime_content_type, "text/plain");
867 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
868 if (!strcmp(buf, "000")) {
870 wprintf(_("unexpected end of message"));
871 wprintf("</i><br /><br />\n");
874 if (!strncasecmp(buf, "Content-type: ", 14)) {
875 safestrncpy(mime_content_type, &buf[14],
876 sizeof(mime_content_type));
877 for (i=0; i<strlen(mime_content_type); ++i) {
878 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
879 safestrncpy(mime_charset, &mime_content_type[i+8],
880 sizeof mime_charset);
883 for (i=0; i<strlen(mime_content_type); ++i) {
884 if (mime_content_type[i] == ';') {
885 mime_content_type[i] = 0;
891 /** Set up a character set conversion if we need to (and if we can) */
893 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
894 if ( (strcasecmp(mime_charset, "us-ascii"))
895 && (strcasecmp(mime_charset, "UTF-8"))
896 && (strcasecmp(mime_charset, ""))
898 ic = iconv_open("UTF-8", mime_charset);
899 if (ic == (iconv_t)(-1) ) {
900 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
901 __FILE__, __LINE__, mime_charset, strerror(errno));
906 /** Messages in legacy Citadel variformat get handled thusly... */
907 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
911 /** Boring old 80-column fixed format text gets handled this way... */
912 else if ( (!strcasecmp(mime_content_type, "text/plain"))
913 || (!strcasecmp(mime_content_type, "text")) ) {
914 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
915 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
916 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
919 if (ic != (iconv_t)(-1) ) {
921 ibuflen = strlen(ibuf);
923 obuf = (char *) malloc(obuflen);
925 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
926 osav[SIZ-obuflen] = 0;
927 safestrncpy(buf, osav, sizeof buf);
932 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
933 buf[strlen(buf) - 1] = 0;
935 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
936 wprintf("<blockquote>");
938 } else if ((bq == 1) &&
939 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
940 wprintf("</blockquote>");
946 wprintf("</tt><br />\n");
948 wprintf("</i><br />");
951 else /** HTML is fun, but we've got to strip it first */
952 if (!strcasecmp(mime_content_type, "text/html")) {
953 output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
956 /** Unknown weirdness */
958 wprintf(_("I don't know how to display %s"), mime_content_type);
959 wprintf("<br />\n", mime_content_type);
960 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
963 /** If there are attached submessages, display them now... */
964 if ( (strlen(mime_submessages) > 0) && (!section[0]) ) {
965 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
966 extract_token(buf, mime_submessages, i, '|', sizeof buf);
967 /** use printable_view to suppress buttons */
968 wprintf("<blockquote>");
969 read_message(msgnum, 1, buf);
970 wprintf("</blockquote>");
975 /** Afterwards, offer links to download attachments 'n' such */
976 if ( (strlen(mime_http) > 0) && (!section[0]) ) {
977 wprintf("%s", mime_http);
980 /** Handler for vCard parts */
981 if (strlen(vcard_partnum) > 0) {
982 part_source = load_mimepart(msgnum, vcard_partnum);
983 if (part_source != NULL) {
985 /** If it's my vCard I can edit it */
986 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
987 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
988 || (WC->wc_view == VIEW_ADDRESSBOOK)
990 wprintf("<a href=\"edit_vcard?"
991 "msgnum=%ld?partnum=%s\">",
992 msgnum, vcard_partnum);
993 wprintf("[%s]</a>", _("edit"));
996 /** In all cases, display the full card */
997 display_vcard(part_source, 0, 1, NULL);
1001 /** Handler for calendar parts */
1002 if (strlen(cal_partnum) > 0) {
1003 part_source = load_mimepart(msgnum, cal_partnum);
1004 if (part_source != NULL) {
1005 cal_process_attachment(part_source,
1006 msgnum, cal_partnum);
1016 wprintf("</td></tr></table>\n");
1018 /** end everythingamundo table */
1019 if (!printable_view) {
1020 wprintf("</td></tr></table>\n");
1021 wprintf("</div><br />\n");
1025 if (ic != (iconv_t)(-1) ) {
1034 * \brief Unadorned HTML output of an individual message, suitable
1035 * for placing in a hidden iframe, for printing, or whatever
1037 * \param msgnum_as_string Message number, as a string instead of as a long int
1039 void embed_message(char *msgnum_as_string) {
1042 msgnum = atol(msgnum_as_string);
1043 begin_ajax_response();
1044 read_message(msgnum, 0, "");
1045 end_ajax_response();
1050 * \brief Printable view of a message
1052 * \param msgnum_as_string Message number, as a string instead of as a long int
1054 void print_message(char *msgnum_as_string) {
1057 msgnum = atol(msgnum_as_string);
1058 output_headers(0, 0, 0, 0, 0, 0);
1060 wprintf("Content-type: text/html\r\n"
1062 "Connection: close\r\n",
1066 wprintf("\r\n\r\n<html>\n"
1067 "<head><title>Printable view</title></head>\n"
1068 "<body onLoad=\" window.print(); window.close(); \">\n"
1071 read_message(msgnum, 1, "");
1073 wprintf("\n</body></html>\n\n");
1080 * \brief Display a message's headers
1082 * \param msgnum_as_string Message number, as a string instead of as a long int
1084 void display_headers(char *msgnum_as_string) {
1088 msgnum = atol(msgnum_as_string);
1089 output_headers(0, 0, 0, 0, 0, 0);
1091 wprintf("Content-type: text/plain\r\n"
1093 "Connection: close\r\n",
1097 serv_printf("MSG2 %ld|3", msgnum);
1098 serv_getln(buf, sizeof buf);
1099 if (buf[0] == '1') {
1100 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1101 wprintf("%s\n", buf);
1111 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1112 * or 'reply quoted' operations.
1114 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1115 * in this function. Doing so would throw a JavaScript error in the
1116 * 'supplied text' argument to the editor.
1118 * \param msgnum Message number of the message we want to quote
1119 * \param forward_attachments Nonzero if we want attachments to be forwarded
1121 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1123 char mime_partnum[256];
1124 char mime_filename[256];
1125 char mime_content_type[256];
1126 char mime_charset[256];
1127 char mime_disposition[256];
1129 char mime_http[SIZ];
1130 char *attachments = NULL;
1131 int num_attachments = 0;
1132 struct wc_attachment *att, *aptr;
1133 char m_subject[256];
1139 int format_type = 0;
1144 iconv_t ic = (iconv_t)(-1) ;
1145 char *ibuf; /**< Buffer of characters to be converted */
1146 char *obuf; /**< Buffer for converted characters */
1147 size_t ibuflen; /**< Length of input buffer */
1148 size_t obuflen; /**< Length of output buffer */
1149 char *osav; /**< Saved pointer to output buffer */
1155 strcpy(reply_to, "");
1156 strcpy(mime_http, "");
1157 strcpy(mime_content_type, "text/plain");
1158 strcpy(mime_charset, "us-ascii");
1160 serv_printf("MSG4 %ld", msgnum);
1161 serv_getln(buf, sizeof buf);
1162 if (buf[0] != '1') {
1163 wprintf(_("ERROR:"));
1164 wprintf("%s<br />", &buf[4]);
1168 strcpy(m_subject, "");
1170 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1171 if (!strcmp(buf, "000")) {
1172 wprintf(_("unexpected end of message"));
1175 if (include_headers) {
1176 if (!strncasecmp(buf, "nhdr=yes", 8))
1180 if (!strncasecmp(buf, "type=", 5))
1181 format_type = atoi(&buf[5]);
1182 if (!strncasecmp(buf, "from=", 5)) {
1183 strcpy(from, &buf[5]);
1184 wprintf(_("from "));
1186 utf8ify_rfc822_string(from);
1190 if (!strncasecmp(buf, "subj=", 5)) {
1191 strcpy(m_subject, &buf[5]);
1193 if ((!strncasecmp(buf, "hnod=", 5))
1194 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1195 wprintf("(%s) ", &buf[5]);
1197 if ((!strncasecmp(buf, "room=", 5))
1198 && (strcasecmp(&buf[5], WC->wc_roomname))
1199 && (strlen(&buf[5])>0) ) {
1201 wprintf("%s> ", &buf[5]);
1203 if (!strncasecmp(buf, "rfca=", 5)) {
1204 strcpy(rfca, &buf[5]);
1210 if (!strncasecmp(buf, "node=", 5)) {
1211 strcpy(node, &buf[5]);
1212 if ( ((WC->room_flags & QR_NETWORK)
1213 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1214 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1215 && (strlen(rfca)==0)
1217 wprintf("@%s ", &buf[5]);
1220 if (!strncasecmp(buf, "rcpt=", 5)) {
1222 wprintf("%s ", &buf[5]);
1224 if (!strncasecmp(buf, "time=", 5)) {
1225 fmt_date(now, atol(&buf[5]), 0);
1226 wprintf("%s ", now);
1231 * Save attachment info for later. We can't start downloading them
1232 * yet because we're in the middle of a server transaction.
1234 if (!strncasecmp(buf, "part=", 5)) {
1236 attachments = realloc(attachments, (num_attachments * 1024));
1237 strcat(attachments, &buf[5]);
1238 strcat(attachments, "\n");
1243 if (include_headers) {
1247 utf8ify_rfc822_string(m_subject);
1249 if (strlen(m_subject) > 0) {
1250 wprintf(_("Subject:"));
1252 msgescputs(m_subject);
1263 * Learn the content type
1265 strcpy(mime_content_type, "text/plain");
1266 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1267 if (!strcmp(buf, "000")) {
1268 wprintf(_("unexpected end of message"));
1271 if (!strncasecmp(buf, "Content-type: ", 14)) {
1272 safestrncpy(mime_content_type, &buf[14],
1273 sizeof(mime_content_type));
1274 for (i=0; i<strlen(mime_content_type); ++i) {
1275 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1276 safestrncpy(mime_charset, &mime_content_type[i+8],
1277 sizeof mime_charset);
1280 for (i=0; i<strlen(mime_content_type); ++i) {
1281 if (mime_content_type[i] == ';') {
1282 mime_content_type[i] = 0;
1288 /** Set up a character set conversion if we need to (and if we can) */
1290 if ( (strcasecmp(mime_charset, "us-ascii"))
1291 && (strcasecmp(mime_charset, "UTF-8"))
1292 && (strcasecmp(mime_charset, ""))
1294 ic = iconv_open("UTF-8", mime_charset);
1295 if (ic == (iconv_t)(-1) ) {
1296 lprintf(5, "%s:%d iconv_open() failed: %s\n",
1297 __FILE__, __LINE__, strerror(errno));
1302 /** Messages in legacy Citadel variformat get handled thusly... */
1303 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1307 /* Boring old 80-column fixed format text gets handled this way... */
1308 else if (!strcasecmp(mime_content_type, "text/plain")) {
1309 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1310 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1311 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1314 if (ic != (iconv_t)(-1) ) {
1316 ibuflen = strlen(ibuf);
1318 obuf = (char *) malloc(obuflen);
1320 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1321 osav[SIZ-obuflen] = 0;
1322 safestrncpy(buf, osav, sizeof buf);
1327 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1328 buf[strlen(buf) - 1] = 0;
1330 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1331 wprintf("<blockquote>");
1333 } else if ((bq == 1) &&
1334 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1335 wprintf("</blockquote>");
1341 wprintf("</tt><br />");
1343 wprintf("</i><br />");
1346 /** HTML just gets escaped and stuffed back into the editor */
1347 else if (!strcasecmp(mime_content_type, "text/html")) {
1348 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1354 /** Unknown weirdness ... don't know how to handle this content type */
1356 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1360 /** end of body handler */
1363 * If there were attachments, we have to download them and insert them
1364 * into the attachment chain for the forwarded message we are composing.
1366 if ( (forward_attachments) && (num_attachments) ) {
1367 for (i=0; i<num_attachments; ++i) {
1368 extract_token(buf, attachments, i, '\n', sizeof buf);
1369 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1370 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1371 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1372 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1373 mime_length = extract_int(buf, 5);
1376 * tracing ... uncomment if necessary
1378 lprintf(9, "fwd filename: %s\n", mime_filename);
1379 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1380 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1381 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1382 lprintf(9, "fwd length : %d\n", mime_length);
1385 if ( (!strcasecmp(mime_disposition, "inline"))
1386 || (!strcasecmp(mime_disposition, "attachment")) ) {
1388 /* Create an attachment struct from this mime part... */
1389 att = malloc(sizeof(struct wc_attachment));
1390 memset(att, 0, sizeof(struct wc_attachment));
1391 att->length = mime_length;
1392 strcpy(att->content_type, mime_content_type);
1393 strcpy(att->filename, mime_filename);
1395 att->data = load_mimepart(msgnum, mime_partnum);
1397 /* And add it to the list. */
1398 if (WC->first_attachment == NULL) {
1399 WC->first_attachment = att;
1402 aptr = WC->first_attachment;
1403 while (aptr->next != NULL) aptr = aptr->next;
1413 if (ic != (iconv_t)(-1) ) {
1420 * \brief Display one row in the mailbox summary view
1422 * \param num The row number to be displayed
1424 void display_summarized(int num) {
1427 wprintf("<tr id=\"m%ld\" style=\"width:100%%;font-weight:%s;background-color:#ffffff\" "
1428 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1429 WC->summ[num].msgnum,
1430 (WC->summ[num].is_new ? "bold" : "normal"),
1431 WC->summ[num].msgnum
1434 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1435 escputs(WC->summ[num].subj);
1438 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1439 escputs(WC->summ[num].from);
1442 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1443 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1453 * \brief display the adressbook overview
1454 * \param msgnum the citadel message number
1455 * \param alpha what????
1457 void display_addressbook(long msgnum, char alpha) {
1459 char mime_partnum[SIZ];
1460 char mime_filename[SIZ];
1461 char mime_content_type[SIZ];
1462 char mime_disposition[SIZ];
1464 char vcard_partnum[SIZ];
1465 char *vcard_source = NULL;
1466 struct message_summary summ;
1468 memset(&summ, 0, sizeof(summ));
1469 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1471 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1473 serv_getln(buf, sizeof buf);
1474 if (buf[0] != '1') return;
1476 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1477 if (!strncasecmp(buf, "part=", 5)) {
1478 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1479 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1480 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1481 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1482 mime_length = extract_int(&buf[5], 5);
1484 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1485 strcpy(vcard_partnum, mime_partnum);
1491 if (strlen(vcard_partnum) > 0) {
1492 vcard_source = load_mimepart(msgnum, vcard_partnum);
1493 if (vcard_source != NULL) {
1495 /** Display the summary line */
1496 display_vcard(vcard_source, alpha, 0, NULL);
1498 /** If it's my vCard I can edit it */
1499 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1500 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1501 || (WC->wc_view == VIEW_ADDRESSBOOK)
1503 wprintf("<a href=\"edit_vcard?"
1504 "msgnum=%ld?partnum=%s\">",
1505 msgnum, vcard_partnum);
1506 wprintf("[%s]</a>", _("edit"));
1518 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1519 * \param namebuf name to analyze, reverse if nescessary
1521 void lastfirst_firstlast(char *namebuf) {
1522 char firstname[SIZ];
1526 if (namebuf == NULL) return;
1527 if (strchr(namebuf, ';') != NULL) return;
1529 i = num_tokens(namebuf, ' ');
1532 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1533 remove_token(namebuf, i-1, ' ');
1534 strcpy(firstname, namebuf);
1535 sprintf(namebuf, "%s; %s", lastname, firstname);
1539 * \brief fetch what??? name
1540 * \param msgnum the citadel message number
1541 * \param namebuf where to put the name in???
1543 void fetch_ab_name(long msgnum, char *namebuf) {
1545 char mime_partnum[SIZ];
1546 char mime_filename[SIZ];
1547 char mime_content_type[SIZ];
1548 char mime_disposition[SIZ];
1550 char vcard_partnum[SIZ];
1551 char *vcard_source = NULL;
1553 struct message_summary summ;
1555 if (namebuf == NULL) return;
1556 strcpy(namebuf, "");
1558 memset(&summ, 0, sizeof(summ));
1559 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1561 sprintf(buf, "MSG0 %ld|1", msgnum); /** ask for headers only */
1563 serv_getln(buf, sizeof buf);
1564 if (buf[0] != '1') return;
1566 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1567 if (!strncasecmp(buf, "part=", 5)) {
1568 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1569 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1570 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1571 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1572 mime_length = extract_int(&buf[5], 5);
1574 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1575 strcpy(vcard_partnum, mime_partnum);
1581 if (strlen(vcard_partnum) > 0) {
1582 vcard_source = load_mimepart(msgnum, vcard_partnum);
1583 if (vcard_source != NULL) {
1585 /* Grab the name off the card */
1586 display_vcard(vcard_source, 0, 0, namebuf);
1592 lastfirst_firstlast(namebuf);
1594 for (i=0; i<strlen(namebuf); ++i) {
1595 if (namebuf[i] != ';') return;
1597 strcpy(namebuf, _("(no name)"));
1603 * \brief Record compare function for sorting address book indices
1604 * \param ab1 adressbook one
1605 * \param ab2 adressbook two
1607 int abcmp(const void *ab1, const void *ab2) {
1609 (((const struct addrbookent *)ab1)->ab_name),
1610 (((const struct addrbookent *)ab2)->ab_name)
1616 * \brief Helper function for do_addrbook_view()
1617 * Converts a name into a three-letter tab label
1618 * \param tabbuf the tabbuffer to add name to
1619 * \param name the name to add to the tabbuffer
1621 void nametab(char *tabbuf, char *name) {
1622 stresc(tabbuf, name, 0, 0);
1623 tabbuf[0] = toupper(tabbuf[0]);
1624 tabbuf[1] = tolower(tabbuf[1]);
1625 tabbuf[2] = tolower(tabbuf[2]);
1631 * \brief Render the address book using info we gathered during the scan
1632 * \param addrbook the addressbook to render
1633 * \param num_ab the number of the addressbook
1635 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1639 static int NAMESPERPAGE = 60;
1643 char tabfirst_label[SIZ];
1645 char tablast_label[SIZ];
1648 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1649 wprintf(_("This address book is empty."));
1650 wprintf("</i></div>\n");
1655 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1658 num_pages = num_ab / NAMESPERPAGE;
1660 page = atoi(bstr("page"));
1663 for (i=0; i<=num_pages; ++i) {
1665 wprintf("<a href=\"readfwd?page=%d\">", i);
1670 tabfirst = i * NAMESPERPAGE;
1671 tablast = tabfirst + NAMESPERPAGE - 1;
1672 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1673 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1674 nametab(tablast_label, addrbook[tablast].ab_name);
1675 wprintf("[%s - %s]",
1676 tabfirst_label, tablast_label
1685 wprintf("<br />\n");
1687 wprintf("<table border=0 cellspacing=0 "
1688 "cellpadding=3 width=100%%>\n"
1691 for (i=0; i<num_ab; ++i) {
1693 if ((i / NAMESPERPAGE) == page) {
1695 if ((displayed % 4) == 0) {
1696 if (displayed > 0) {
1700 wprintf("<tr bgcolor=\"#%s\">",
1701 (bg ? "DDDDDD" : "FFFFFF")
1707 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
1708 addrbook[i].ab_msgnum);
1709 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1710 vcard_n_prettyize(addrbook[i].ab_name);
1711 escputs(addrbook[i].ab_name);
1712 wprintf("</a></td>\n");
1717 wprintf("</tr></table>\n");
1723 * \brief load message pointers from the server
1724 * \param servcmd the citadel command to send to the citserver
1725 * \param with_headers what headers???
1727 int load_msg_ptrs(char *servcmd, int with_headers)
1738 int num_summ_alloc = 0;
1740 if (WC->summ != NULL) {
1745 num_summ_alloc = 100;
1747 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1750 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1752 serv_getln(buf, sizeof buf);
1753 if (buf[0] != '1') {
1754 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1757 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1758 if (nummsgs < maxload) {
1759 WC->msgarr[nummsgs] = extract_long(buf, 0);
1760 datestamp = extract_long(buf, 1);
1761 extract_token(fullname, buf, 2, '|', sizeof fullname);
1762 extract_token(nodename, buf, 3, '|', sizeof nodename);
1763 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1764 extract_token(subject, buf, 5, '|', sizeof subject);
1768 if (nummsgs > num_summ_alloc) {
1769 num_summ_alloc *= 2;
1770 WC->summ = realloc(WC->summ,
1771 num_summ_alloc * sizeof(struct message_summary));
1775 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1776 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1777 safestrncpy(WC->summ[nummsgs-1].subj,
1778 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1779 if (strlen(fullname) > 0) {
1780 safestrncpy(WC->summ[nummsgs-1].from,
1781 fullname, sizeof WC->summ[nummsgs-1].from);
1783 if (strlen(subject) > 0) {
1784 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1785 sizeof WC->summ[nummsgs-1].subj);
1788 /** Handle subjects with RFC2047 encoding */
1789 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1791 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1792 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1795 if (strlen(nodename) > 0) {
1796 if ( ((WC->room_flags & QR_NETWORK)
1797 || ((strcasecmp(nodename, serv_info.serv_nodename)
1798 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1800 strcat(WC->summ[nummsgs-1].from, " @ ");
1801 strcat(WC->summ[nummsgs-1].from, nodename);
1805 WC->summ[nummsgs-1].date = datestamp;
1808 /** Handle senders with RFC2047 encoding */
1809 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1811 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1812 strcpy(&WC->summ[nummsgs-1].from[22], "...");
1821 * \brief qsort() compatible function to compare two longs in descending order.
1823 * \param s1 first number to compare
1824 * \param s2 second number to compare
1826 int longcmp_r(const void *s1, const void *s2) {
1833 if (l1 > l2) return(-1);
1834 if (l1 < l2) return(+1);
1840 * \brief qsort() compatible function to compare two message summary structs by ascending subject.
1842 * \param s1 first item to compare
1843 * \param s2 second item to compare
1845 int summcmp_subj(const void *s1, const void *s2) {
1846 struct message_summary *summ1;
1847 struct message_summary *summ2;
1849 summ1 = (struct message_summary *)s1;
1850 summ2 = (struct message_summary *)s2;
1851 return strcasecmp(summ1->subj, summ2->subj);
1855 * \brief qsort() compatible function to compare two message summary structs by descending subject.
1857 * \param s1 first item to compare
1858 * \param s2 second item to compare
1860 int summcmp_rsubj(const void *s1, const void *s2) {
1861 struct message_summary *summ1;
1862 struct message_summary *summ2;
1864 summ1 = (struct message_summary *)s1;
1865 summ2 = (struct message_summary *)s2;
1866 return strcasecmp(summ2->subj, summ1->subj);
1870 * \brief qsort() compatible function to compare two message summary structs by ascending sender.
1872 * \param s1 first item to compare
1873 * \param s2 second item to compare
1875 int summcmp_sender(const void *s1, const void *s2) {
1876 struct message_summary *summ1;
1877 struct message_summary *summ2;
1879 summ1 = (struct message_summary *)s1;
1880 summ2 = (struct message_summary *)s2;
1881 return strcasecmp(summ1->from, summ2->from);
1885 * \brief qsort() compatible function to compare two message summary structs by descending sender.
1887 * \param s1 first item to compare
1888 * \param s2 second item to compare
1890 int summcmp_rsender(const void *s1, const void *s2) {
1891 struct message_summary *summ1;
1892 struct message_summary *summ2;
1894 summ1 = (struct message_summary *)s1;
1895 summ2 = (struct message_summary *)s2;
1896 return strcasecmp(summ2->from, summ1->from);
1900 * \brief qsort() compatible function to compare two message summary structs by ascending date.
1902 * \param s1 first item to compare
1903 * \param s2 second item to compare
1905 int summcmp_date(const void *s1, const void *s2) {
1906 struct message_summary *summ1;
1907 struct message_summary *summ2;
1909 summ1 = (struct message_summary *)s1;
1910 summ2 = (struct message_summary *)s2;
1912 if (summ1->date < summ2->date) return -1;
1913 else if (summ1->date > summ2->date) return +1;
1918 * \brief qsort() compatible function to compare two message summary structs by descending date.
1920 * \param s1 first item to compare
1921 * \param s2 second item to compare
1923 int summcmp_rdate(const void *s1, const void *s2) {
1924 struct message_summary *summ1;
1925 struct message_summary *summ2;
1927 summ1 = (struct message_summary *)s1;
1928 summ2 = (struct message_summary *)s2;
1930 if (summ1->date < summ2->date) return +1;
1931 else if (summ1->date > summ2->date) return -1;
1938 * \brief command loop for reading messages
1940 * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
1942 void readloop(char *oper)
1951 long *displayed_msgs = NULL;
1952 int num_displayed = 0;
1954 int is_addressbook = 0;
1955 int is_singlecard = 0;
1956 int is_calendar = 0;
1961 int lowest_displayed = (-1);
1962 int highest_displayed = 0;
1963 struct addrbookent *addrbook = NULL;
1965 char *sortby = NULL;
1966 char sortpref_name[128];
1967 char sortpref_value[128];
1968 char *subjsort_button;
1969 char *sendsort_button;
1970 char *datesort_button;
1971 int bbs_reverse = 0;
1973 if (WC->wc_view == VIEW_WIKI) {
1974 sprintf(buf, "wiki?room=%s?page=home", WC->wc_roomname);
1979 startmsg = atol(bstr("startmsg"));
1980 maxmsgs = atoi(bstr("maxmsgs"));
1981 is_summary = atoi(bstr("summary"));
1982 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1984 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
1985 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
1987 sortby = bstr("sortby");
1988 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
1989 set_preference(sortpref_name, sortby, 1);
1991 if (strlen(sortby) == 0) sortby = sortpref_value;
1994 if (strlen(sortby) == 0) sortby = "rdate";
1996 /** message board sort */
1997 if (!strcasecmp(sortby, "reverse")) {
2004 output_headers(1, 1, 1, 0, 0, 0);
2007 * When in summary mode, always show ALL messages instead of just
2008 * new or old. Otherwise, show what the user asked for.
2010 if (!strcmp(oper, "readnew")) {
2011 strcpy(cmd, "MSGS NEW");
2013 else if (!strcmp(oper, "readold")) {
2014 strcpy(cmd, "MSGS OLD");
2017 strcpy(cmd, "MSGS ALL");
2020 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
2022 strcpy(cmd, "MSGS ALL");
2025 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2027 strcpy(cmd, "MSGS ALL");
2032 strcpy(cmd, "MSGS ALL|||1"); /**< fetch header summary */
2038 * Are we doing a summary view? If so, we need to know old messages
2039 * and new messages, so we can do that pretty boldface thing for the
2042 strcpy(old_msgs, "");
2045 serv_getln(buf, sizeof buf);
2046 if (buf[0] == '2') {
2047 strcpy(old_msgs, &buf[4]);
2051 is_singlecard = atoi(bstr("is_singlecard"));
2053 if ((WC->wc_view == VIEW_CALENDAR) ||
2054 (WC->wc_view == VIEW_CALBRIEF)){ /**< calendar */
2056 strcpy(cmd, "MSGS ALL");
2059 if (WC->wc_view == VIEW_TASKS) { /**< tasks */
2061 strcpy(cmd, "MSGS ALL");
2064 if (WC->wc_view == VIEW_NOTES) { /**< notes */
2066 strcpy(cmd, "MSGS ALL");
2070 nummsgs = load_msg_ptrs(cmd, is_summary);
2073 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2075 if (!strcmp(oper, "readnew")) {
2076 wprintf(_("No new messages."));
2077 } else if (!strcmp(oper, "readold")) {
2078 wprintf(_("No old messages."));
2080 wprintf(_("No messages here."));
2089 for (a = 0; a < nummsgs; ++a) {
2090 /** Are you a new message, or an old message? */
2092 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
2093 WC->summ[a].is_new = 0;
2096 WC->summ[a].is_new = 1;
2102 if (startmsg == 0L) {
2104 startmsg = WC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2107 startmsg = WC->msgarr[0];
2112 if (!strcasecmp(sortby, "subject")) {
2113 qsort(WC->summ, WC->num_summ,
2114 sizeof(struct message_summary), summcmp_subj);
2116 else if (!strcasecmp(sortby, "rsubject")) {
2117 qsort(WC->summ, WC->num_summ,
2118 sizeof(struct message_summary), summcmp_rsubj);
2120 else if (!strcasecmp(sortby, "sender")) {
2121 qsort(WC->summ, WC->num_summ,
2122 sizeof(struct message_summary), summcmp_sender);
2124 else if (!strcasecmp(sortby, "rsender")) {
2125 qsort(WC->summ, WC->num_summ,
2126 sizeof(struct message_summary), summcmp_rsender);
2128 else if (!strcasecmp(sortby, "date")) {
2129 qsort(WC->summ, WC->num_summ,
2130 sizeof(struct message_summary), summcmp_date);
2132 else if (!strcasecmp(sortby, "rdate")) {
2133 qsort(WC->summ, WC->num_summ,
2134 sizeof(struct message_summary), summcmp_rdate);
2138 if (!strcasecmp(sortby, "subject")) {
2139 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2141 else if (!strcasecmp(sortby, "rsubject")) {
2142 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2145 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2148 if (!strcasecmp(sortby, "sender")) {
2149 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2151 else if (!strcasecmp(sortby, "rsender")) {
2152 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2155 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2158 if (!strcasecmp(sortby, "date")) {
2159 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2161 else if (!strcasecmp(sortby, "rdate")) {
2162 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2165 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2169 wprintf("</div>\n"); /** end of 'content' div */
2171 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2172 " document.onkeydown = CtdlMsgListKeyPress; "
2173 " if (document.layers) { "
2174 " document.captureEvents(Event.KEYPRESS); "
2179 /** note that Date and Delete are now in the same column */
2180 wprintf("<div id=\"message_list_hdr\">"
2181 "<div class=\"fix_scrollbar_bug\">"
2182 "<table cellspacing=0 style=\"width:100%%\">"
2185 wprintf("<td width=%d%%><b><i>%s</i></b> %s</td>"
2186 "<td width=%d%%><b><i>%s</i></b> %s</td>"
2187 "<td width=%d%%><b><i>%s</i></b> %s"
2189 "<input type=\"submit\" name=\"delete_button\" style=\"font-size:6pt\" "
2190 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2196 _("Subject"), subjsort_button,
2197 SENDER_COL_WIDTH_PCT,
2198 _("Sender"), sendsort_button,
2199 DATE_PLUS_BUTTONS_WIDTH_PCT,
2200 _("Date"), datesort_button,
2203 wprintf("</table></div></div>\n");
2205 wprintf("<div id=\"message_list\">"
2207 "<div class=\"fix_scrollbar_bug\">\n"
2209 "<table class=\"mailbox_summary\" id=\"summary_headers\" rules=rows "
2210 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2215 wprintf("<div align=center>%s</div>\n", _("Click on any note to edit it."));
2216 wprintf("<div id=\"new_notes_here\"></div>\n");
2219 for (a = 0; a < nummsgs; ++a) {
2220 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2222 /** Display the message */
2224 display_summarized(a);
2226 else if (is_addressbook) {
2227 fetch_ab_name(WC->msgarr[a], buf);
2229 addrbook = realloc(addrbook,
2230 (sizeof(struct addrbookent) * num_ab) );
2231 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2232 sizeof(addrbook[num_ab-1].ab_name));
2233 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
2235 else if (is_calendar) {
2236 display_calendar(WC->msgarr[a]);
2238 else if (is_tasks) {
2239 display_task(WC->msgarr[a]);
2241 else if (is_notes) {
2242 display_note(WC->msgarr[a]);
2245 if (displayed_msgs == NULL) {
2246 displayed_msgs = malloc(sizeof(long) *
2247 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2249 displayed_msgs[num_displayed] = WC->msgarr[a];
2252 if (lowest_displayed < 0) lowest_displayed = a;
2253 highest_displayed = a;
2260 * Set the "is_bbview" variable if it appears that we are looking at
2261 * a classic bulletin board view.
2263 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2264 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2269 if (displayed_msgs != NULL) {
2271 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2274 /** if we do a split bbview in the future, begin messages div here */
2276 for (a=0; a<num_displayed; ++a) {
2277 read_message(displayed_msgs[a], 0, "");
2280 /** if we do a split bbview in the future, end messages div here */
2282 free(displayed_msgs);
2283 displayed_msgs = NULL;
2288 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2289 wprintf("</div>"); /**< end of 'message_list' div */
2291 /** Here's the grab-it-to-resize-the-message-list widget */
2292 wprintf("<div id=\"resize_msglist\" "
2293 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2294 "<div class=\"fix_scrollbar_bug\">"
2295 "<table width=100%% border=3 cellspacing=0 "
2296 "bgcolor=\"#cccccc\" "
2297 "cellpadding=0><TR><TD> </td></tr></table>"
2301 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2305 * Bump these because although we're thinking in zero base, the user
2306 * is a drooling idiot and is thinking in one base.
2309 ++highest_displayed;
2312 * If we're not currently looking at ALL requested
2313 * messages, then display the selector bar
2316 /** begin bbview scroller */
2317 wprintf("<form name=\"msgomatic\">");
2318 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2320 wprintf("<select name=\"whichones\" size=\"1\" "
2321 "OnChange=\"location.href=msgomatic.whichones.options"
2322 "[selectedIndex].value\">\n");
2325 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2327 lo = b - maxmsgs + 2;
2329 wprintf("<option %s value="
2334 "%d-%d</option> \n",
2335 ((WC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2344 for (b=0; b<nummsgs; b = b + maxmsgs) {
2346 hi = b + maxmsgs + 1;
2347 if (hi > nummsgs) hi = nummsgs;
2348 wprintf("<option %s value="
2353 "%d-%d</option> \n",
2354 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2363 wprintf("<option value=\"%s?startmsg=%ld"
2364 "?maxmsgs=9999999?summary=%d\">"
2368 WC->msgarr[0], is_summary);
2370 wprintf("</select> ");
2371 wprintf(_("of %d messages."), nummsgs);
2373 /** forward/reverse */
2374 wprintf(" <select name=\"direction\" size=\"1\" "
2375 "OnChange=\"location.href=msgomatic.direction.options"
2376 "[selectedIndex].value\">\n"
2379 wprintf("<option %s value=\"%s?sortby=forward\">oldest to newest</option>\n",
2380 (bbs_reverse ? "" : "selected"),
2384 wprintf("<option %s value=\"%s?sortby=reverse\">newest to oldest</option>\n",
2385 (bbs_reverse ? "selected" : ""),
2389 wprintf("</select></form>\n");
2390 /** end bbview scroller */
2395 do_tasks_view(); /** Render the task list */
2399 do_calendar_view(); /** Render the calendar */
2402 if (is_addressbook) {
2403 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2406 /** Note: wDumpContent() will output one additional </div> tag. */
2408 if (addrbook != NULL) free(addrbook);
2410 /** free the summary */
2411 if (WC->summ != NULL) {
2420 * \brief Back end for post_message()
2421 * ... this is where the actual message gets transmitted to the server.
2423 void post_mime_to_server(void) {
2425 int is_multipart = 0;
2427 struct wc_attachment *att;
2429 size_t encoded_length;
2431 /** RFC2045 requires this, and some clients look for it... */
2432 serv_puts("MIME-Version: 1.0");
2434 /** If there are attachments, we have to do multipart/mixed */
2435 if (WC->first_attachment != NULL) {
2440 sprintf(boundary, "=_Citadel_Multipart_%s_%04x%04x",
2441 serv_info.serv_fqdn,
2446 /** Remember, serv_printf() appends an extra newline */
2447 serv_printf("Content-type: multipart/mixed; "
2448 "boundary=\"%s\"\n", boundary);
2449 serv_printf("This is a multipart message in MIME format.\n");
2450 serv_printf("--%s", boundary);
2453 serv_puts("Content-type: text/html; charset=utf-8");
2454 serv_puts("Content-Transfer-Encoding: quoted-printable");
2456 serv_puts("<html><body>\r\n");
2457 text_to_server_qp(bstr("msgtext")); /** Transmit message in quoted-printable encoding */
2458 serv_puts("</body></html>\r\n");
2462 /** Add in the attachments */
2463 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2465 encoded_length = ((att->length * 150) / 100);
2466 encoded = malloc(encoded_length);
2467 if (encoded == NULL) break;
2468 CtdlEncodeBase64(encoded, att->data, att->length);
2470 serv_printf("--%s", boundary);
2471 serv_printf("Content-type: %s", att->content_type);
2472 serv_printf("Content-disposition: attachment; "
2473 "filename=\"%s\"", att->filename);
2474 serv_puts("Content-transfer-encoding: base64");
2476 serv_write(encoded, strlen(encoded));
2481 serv_printf("--%s--", boundary);
2489 * \brief Post message (or don't post message)
2491 * Note regarding the "dont_post" variable:
2492 * A random value (actually, it's just a timestamp) is inserted as a hidden
2493 * field called "postseq" when the display_enter page is generated. This
2494 * value is checked when posting, using the static variable dont_post. If a
2495 * user attempts to post twice using the same dont_post value, the message is
2496 * discarded. This prevents the accidental double-saving of the same message
2497 * if the user happens to click the browser "back" button.
2499 void post_message(void)
2502 static long dont_post = (-1L);
2503 struct wc_attachment *att, *aptr;
2504 int is_anonymous = 0;
2506 if (!strcasecmp(bstr("is_anonymous"), "yes")) {
2510 if (WC->upload_length > 0) {
2512 /** There's an attachment. Save it to this struct... */
2513 att = malloc(sizeof(struct wc_attachment));
2514 memset(att, 0, sizeof(struct wc_attachment));
2515 att->length = WC->upload_length;
2516 strcpy(att->content_type, WC->upload_content_type);
2517 strcpy(att->filename, WC->upload_filename);
2520 /** And add it to the list. */
2521 if (WC->first_attachment == NULL) {
2522 WC->first_attachment = att;
2525 aptr = WC->first_attachment;
2526 while (aptr->next != NULL) aptr = aptr->next;
2531 * Mozilla sends a simple filename, which is what we want,
2532 * but Satan's Browser sends an entire pathname. Reduce
2533 * the path to just a filename if we need to.
2535 while (num_tokens(att->filename, '/') > 1) {
2536 remove_token(att->filename, 0, '/');
2538 while (num_tokens(att->filename, '\\') > 1) {
2539 remove_token(att->filename, 0, '\\');
2543 * Transfer control of this memory from the upload struct
2544 * to the attachment struct.
2546 att->data = WC->upload;
2547 WC->upload_length = 0;
2553 if (strlen(bstr("cancel_button")) > 0) {
2554 sprintf(WC->ImportantMessage,
2555 _("Cancelled. Message was not posted."));
2556 } else if (strlen(bstr("attach_button")) > 0) {
2559 } else if (atol(bstr("postseq")) == dont_post) {
2560 sprintf(WC->ImportantMessage,
2561 _("Automatically cancelled because you have already "
2562 "saved this message."));
2564 sprintf(buf, "ENT0 1|%s|%d|4|%s|||%s|%s|%s",
2573 serv_getln(buf, sizeof buf);
2574 if (buf[0] == '4') {
2575 post_mime_to_server();
2576 if ( (strlen(bstr("recp")) > 0)
2577 || (strlen(bstr("cc")) > 0)
2578 || (strlen(bstr("bcc")) > 0)
2580 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2583 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2585 dont_post = atol(bstr("postseq"));
2587 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2593 free_attachments(WC);
2596 * We may have been supplied with instructions regarding the location
2597 * to which we must return after posting. If found, go there.
2599 if (strlen(bstr("return_to")) > 0) {
2600 http_redirect(bstr("return_to"));
2603 * If we were editing a page in a wiki room, go to that page now.
2605 else if (strlen(bstr("wikipage")) > 0) {
2606 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
2610 * Otherwise, just go to the "read messages" loop.
2613 readloop("readnew");
2621 * \brief display the message entry screen
2623 void display_enter(void)
2628 struct wc_attachment *att;
2629 int recipient_required = 0;
2630 int recipient_bad = 0;
2632 int is_anonymous = 0;
2633 long existing_page = (-1L);
2635 if (strlen(bstr("force_room")) > 0) {
2636 gotoroom(bstr("force_room"));
2639 if (!strcasecmp(bstr("is_anonymous"), "yes")) {
2644 * Are we perhaps in an address book view? If so, then an "enter
2645 * message" command really means "add new entry."
2647 if (WC->wc_view == VIEW_ADDRESSBOOK) {
2648 do_edit_vcard(-1, "", "");
2652 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
2654 * Are we perhaps in a calendar view? If so, then an "enter
2655 * message" command really means "add new calendar item."
2657 if ((WC->wc_view == VIEW_CALENDAR) ||
2658 (WC->wc_view == VIEW_CALBRIEF)){
2659 display_edit_event();
2664 * Are we perhaps in a tasks view? If so, then an "enter
2665 * message" command really means "add new task."
2667 if (WC->wc_view == VIEW_TASKS) {
2668 display_edit_task();
2674 * Otherwise proceed normally.
2675 * Do a custom room banner with no navbar...
2677 output_headers(1, 1, 2, 0, 0, 0);
2678 wprintf("<div id=\"banner\">\n");
2679 embed_room_banner(NULL, navbar_none);
2680 wprintf("</div>\n");
2681 wprintf("<div id=\"content\">\n"
2682 "<div class=\"fix_scrollbar_bug\">"
2683 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
2685 /** First test to see whether this is a room that requires recipients to be entered */
2686 serv_puts("ENT0 0");
2687 serv_getln(buf, sizeof buf);
2688 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
2689 recipient_required = 1;
2691 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2692 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2696 /** Now check our actual recipients if there are any */
2697 if (recipient_required) {
2698 sprintf(buf, "ENT0 0|%s|%d|0||||%s|%s|%s", bstr("recp"), is_anonymous,
2699 bstr("cc"), bstr("bcc"), bstr("wikipage"));
2701 serv_getln(buf, sizeof buf);
2703 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
2704 if (strlen(bstr("recp")) + strlen(bstr("cc")) + strlen(bstr("bcc")) > 0) {
2708 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2709 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2714 /** If we got this far, we can display the message entry screen. */
2717 fmt_date(buf, now, 0);
2718 strcat(&buf[strlen(buf)], _(" <I>from</I> "));
2719 stresc(&buf[strlen(buf)], WC->wc_fullname, 1, 1);
2721 /* Don't need this anymore, it's in the input box below
2722 if (strlen(bstr("recp")) > 0) {
2723 strcat(&buf[strlen(buf)], _(" <I>to</I> "));
2724 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
2728 strcat(&buf[strlen(buf)], _(" <I>in</I> "));
2729 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
2731 /** begin message entry screen */
2733 "enctype=\"multipart/form-data\" "
2735 "accept-charset=\"UTF-8\" "
2737 "name=\"enterform\""
2739 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2740 if (WC->wc_view == VIEW_WIKI) {
2741 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
2743 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
2745 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2746 wprintf("%s\n", buf); /** header bar */
2747 if (WC->room_flags & QR_ANONOPT) {
2749 "<input type=\"checkbox\" name=\"is_anonymous\" value=\"yes\" %s>",
2750 (is_anonymous ? "checked" : "")
2752 wprintf("Anonymous");
2754 wprintf("<br>\n"); /** header bar */
2756 wprintf("<table border=\"0\" width=\"100%%\">\n");
2757 if (recipient_required) {
2759 wprintf("<tr><td>");
2760 wprintf("<font size=-1>");
2764 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
2765 escputs(bstr("recp"));
2766 wprintf("\" size=50 maxlength=1000 />");
2767 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
2768 wprintf("</td><td></td></tr>\n");
2770 wprintf("<tr><td>");
2771 wprintf("<font size=-1>");
2775 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
2776 escputs(bstr("cc"));
2777 wprintf("\" size=50 maxlength=1000 />");
2778 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
2779 wprintf("</td><td></td></tr>\n");
2781 wprintf("<tr><td>");
2782 wprintf("<font size=-1>");
2786 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
2787 escputs(bstr("bcc"));
2788 wprintf("\" size=50 maxlength=1000 />");
2789 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
2790 wprintf("</td><td></td></tr>\n");
2792 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
2793 wprintf("<script type=\"text/javascript\"> \n"
2794 " activate_entmsg_autocompleters(); \n"
2799 wprintf("<tr><td>");
2800 wprintf("<font size=-1>");
2801 wprintf(_("Subject (optional):"));
2804 "<input type=\"text\" name=\"subject\" value=\"");
2805 escputs(bstr("subject"));
2806 wprintf("\" size=50 maxlength=70></td><td>\n");
2808 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2809 if (recipient_required) {
2810 wprintf(_("Send message"));
2812 wprintf(_("Post message"));
2815 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2816 wprintf("</td></tr></table>\n");
2818 wprintf("<center>");
2820 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
2822 /** If we're continuing from a previous edit, put our partially-composed message back... */
2823 msgescputs(bstr("msgtext"));
2825 /* If we're forwarding a message, insert it here... */
2826 if (atol(bstr("fwdquote")) > 0L) {
2827 wprintf("<br><div align=center><i>");
2828 wprintf(_("--- forwarded message ---"));
2829 wprintf("</i></div><br>");
2830 pullquote_message(atol(bstr("fwdquote")), 1, 1);
2833 /** If we're replying quoted, insert the quote here... */
2834 else if (atol(bstr("replyquote")) > 0L) {
2837 pullquote_message(atol(bstr("replyquote")), 0, 1);
2838 wprintf("</blockquote>\n\n");
2841 /** If we're editing a wiki page, insert the existing page here... */
2842 else if (WC->wc_view == VIEW_WIKI) {
2843 safestrncpy(buf, bstr("wikipage"), sizeof buf);
2844 str_wiki_index(buf);
2845 existing_page = locate_message_by_uid(buf);
2846 if (existing_page >= 0L) {
2847 pullquote_message(existing_page, 1, 0);
2851 /** Insert our signature if appropriate... */
2852 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
2853 get_preference("use_sig", buf, sizeof buf);
2854 if (!strcasecmp(buf, "yes")) {
2855 get_preference("signature", ebuf, sizeof ebuf);
2856 euid_unescapize(buf, ebuf);
2857 wprintf("<br>--<br>");
2858 for (i=0; i<strlen(buf); ++i) {
2859 if (buf[i] == '\n') {
2862 else if (buf[i] == '<') {
2865 else if (buf[i] == '>') {
2868 else if (buf[i] == '&') {
2871 else if (buf[i] == '\"') {
2874 else if (buf[i] == '\'') {
2877 else if (isprint(buf[i])) {
2878 wprintf("%c", buf[i]);
2884 wprintf("</textarea>");
2885 wprintf("</center><br />\n");
2888 * The following script embeds the TinyMCE richedit control, and automatically
2889 * transforms the textarea into a richedit textarea.
2892 "<script language=\"javascript\" type=\"text/javascript\" src=\"tiny_mce/tiny_mce.js\"></script>\n"
2893 "<script language=\"javascript\" type=\"text/javascript\">"
2895 " mode : \"textareas\", width : \"100%%\", browsers : \"msie,gecko\", "
2896 " theme : \"advanced\", plugins : \"iespell\", "
2897 " theme_advanced_buttons1 : \"bold, italic, underline, strikethrough, justifyleft, justifycenter, justifyright, justifyfull, bullist, numlist, cut, copy, paste, link, image, help, forecolor, iespell, code\", "
2898 " theme_advanced_buttons2 : \"\", "
2899 " theme_advanced_buttons3 : \"\" "
2905 /** Enumerate any attachments which are already in place... */
2906 wprintf("<img src=\"static/diskette_24x.gif\" border=0 "
2907 "align=middle height=16 width=16> ");
2908 wprintf(_("Attachments:"));
2910 wprintf("<select name=\"which_attachment\" size=1>");
2911 for (att = WC->first_attachment; att != NULL; att = att->next) {
2912 wprintf("<option value=\"");
2913 urlescputs(att->filename);
2915 escputs(att->filename);
2916 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
2917 wprintf("</option>\n");
2919 wprintf("</select>");
2921 /** Now offer the ability to attach additional files... */
2922 wprintf(" ");
2923 wprintf(_("Attach file:"));
2924 wprintf(" <input NAME=\"attachfile\" "
2925 "SIZE=16 TYPE=\"file\">\n "
2926 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
2928 /** Seth asked for these to be at the top *and* bottom... */
2929 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2930 if (recipient_required) {
2931 wprintf(_("Send message"));
2933 wprintf(_("Post message"));
2936 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2938 /** Make sure we only insert our signature once */
2939 if (strcmp(bstr("sig_inserted"), "yes")) {
2940 wprintf("<INPUT TYPE=\"hidden\" NAME=\"sig_inserted\" VALUE=\"yes\">\n");
2943 wprintf("</form>\n");
2945 wprintf("</td></tr></table></div>\n");
2946 DONE: wDumpContent(1);
2952 * \brief delete a message
2954 void delete_msg(void)
2959 msgid = atol(bstr("msgid"));
2961 output_headers(1, 1, 1, 0, 0, 0);
2963 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
2964 serv_printf("DELE %ld", msgid);
2966 else { /** Otherwise move it to Trash */
2967 serv_printf("MOVE %ld|_TRASH_|0", msgid);
2970 serv_getln(buf, sizeof buf);
2971 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2980 * \brief Confirm move of a message
2982 void confirm_move_msg(void)
2988 msgid = atol(bstr("msgid"));
2991 output_headers(1, 1, 2, 0, 0, 0);
2992 wprintf("<div id=\"banner\">\n");
2993 wprintf("<TABLE WIDTH=100%% BORDER=0><TR><TD>");
2994 wprintf("<SPAN CLASS=\"titlebar\">");
2995 wprintf(_("Confirm move of message"));
2996 wprintf("</SPAN>\n");
2997 wprintf("</TD></TR></TABLE>\n");
2998 wprintf("</div>\n<div id=\"content\">\n");
3000 wprintf("<CENTER>");
3002 wprintf(_("Move this message to:"));
3003 wprintf("<br />\n");
3005 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3006 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3008 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3010 serv_getln(buf, sizeof buf);
3011 if (buf[0] == '1') {
3012 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3013 extract_token(targ, buf, 0, '|', sizeof targ);
3014 wprintf("<OPTION>");
3019 wprintf("</SELECT>\n");
3020 wprintf("<br />\n");
3022 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3024 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3025 wprintf("</form></CENTER>\n");
3027 wprintf("</CENTER>\n");
3033 * \brief move a message to another folder
3040 msgid = atol(bstr("msgid"));
3042 if (strlen(bstr("move_button")) > 0) {
3043 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3045 serv_getln(buf, sizeof buf);
3046 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3048 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3051 readloop("readnew");