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 */
33 * \brief Wrapper around iconv_open()
34 * Our version adds aliases for non-standard Microsoft charsets
35 * such as 'MS950', aliasing them to names like 'CP950'
37 * \param tocode Target encoding
38 * \param fromcode Source encoding
40 iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode)
42 iconv_t ic = (iconv_t)(-1) ;
43 ic = iconv_open(tocode, fromcode);
44 if (ic == (iconv_t)(-1) ) {
45 char alias_fromcode[64];
46 if ( (strlen(fromcode) == 5) && (!strncasecmp(fromcode, "MS", 2)) ) {
47 safestrncpy(alias_fromcode, fromcode, sizeof alias_fromcode);
48 alias_fromcode[0] = 'C';
49 alias_fromcode[1] = 'P';
50 ic = iconv_open(tocode, alias_fromcode);
58 * \brief Handle subjects with RFC2047 encoding
60 * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=
61 * \param buf the stringbuffer to process
63 void utf8ify_rfc822_string(char *buf) {
69 iconv_t ic = (iconv_t)(-1) ;
70 char *ibuf; /**< Buffer of characters to be converted */
71 char *obuf; /**< Buffer for converted characters */
72 size_t ibuflen; /**< Length of input buffer */
73 size_t obuflen; /**< Length of output buffer */
74 char *isav; /**< Saved pointer to input buffer */
75 char *osav; /**< Saved pointer to output buffer */
78 int illegal_non_rfc2047_encoding = 0;
80 /** Sometimes, badly formed messages contain strings which were simply
81 * written out directly in some foreign character set instead of
82 * using RFC2047 encoding. This is illegal but we will attempt to
83 * handle it anyway by converting from a user-specified default
84 * charset to UTF-8 if we see any nonprintable characters.
86 for (i=0; i<strlen(buf); ++i) {
87 if ((buf[i] < 32) || (buf[i] > 126)) {
88 illegal_non_rfc2047_encoding = 1;
91 if (illegal_non_rfc2047_encoding) {
92 char default_header_charset[128];
93 get_preference("default_header_charset", default_header_charset, sizeof default_header_charset);
94 if ( (strcasecmp(default_header_charset, "UTF-8")) && (strcasecmp(default_header_charset, "us-ascii")) ) {
95 ic = ctdl_iconv_open("UTF-8", default_header_charset);
96 if (ic != (iconv_t)(-1) ) {
99 safestrncpy(ibuf, buf, 1024);
100 ibuflen = strlen(ibuf);
102 obuf = (char *) malloc(obuflen);
104 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
105 osav[1024-obuflen] = 0;
114 /** Now we handle foreign character sets properly encoded
117 while (start=strstr(buf, "=?"), end=strstr(buf, "?="),
118 ((start != NULL) && (end != NULL) && (end > start)) )
120 extract_token(charset, start, 1, '?', sizeof charset);
121 extract_token(encoding, start, 2, '?', sizeof encoding);
122 extract_token(istr, start, 3, '?', sizeof istr);
126 if (!strcasecmp(encoding, "B")) { /**< base64 */
127 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
129 else if (!strcasecmp(encoding, "Q")) { /**< quoted-printable */
130 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, strlen(istr));
133 strcpy(ibuf, istr); /**< unknown encoding */
134 ibuflen = strlen(istr);
137 ic = ctdl_iconv_open("UTF-8", charset);
138 if (ic != (iconv_t)(-1) ) {
140 obuf = (char *) malloc(obuflen);
142 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
143 osav[1024-obuflen] = 0;
148 remove_token(end, 0, '?');
149 remove_token(end, 0, '?');
150 remove_token(end, 0, '?');
151 remove_token(end, 0, '?');
152 strcpy(end, &end[1]);
154 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
163 remove_token(end, 0, '?');
164 remove_token(end, 0, '?');
165 remove_token(end, 0, '?');
166 remove_token(end, 0, '?');
167 strcpy(end, &end[1]);
169 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
176 * Since spammers will go to all sorts of absurd lengths to get their
177 * messages through, there are LOTS of corrupt headers out there.
178 * So, prevent a really badly formed RFC2047 header from throwing
179 * this function into an infinite loop.
182 if (passes > 20) return;
190 * \brief Look for URL's embedded in a buffer and make them linkable. We use a
191 * target window in order to keep the BBS session in its own window.
192 * \param buf the message buffer
207 for (pos = 0; pos < strlen(buf); ++pos) {
208 if (!strncasecmp(&buf[pos], "http://", 7))
210 if (!strncasecmp(&buf[pos], "ftp://", 6))
217 if ((start > 0) && (buf[start - 1] == '<'))
219 if ((start > 0) && (buf[start - 1] == '['))
221 if ((start > 0) && (buf[start - 1] == '('))
223 if ((start > 0) && (buf[start - 1] == '{'))
226 for (pos = strlen(buf); pos > start; --pos) {
227 if ((buf[pos] == ' ') || (buf[pos] == ench))
231 strncpy(urlbuf, &buf[start], end - start);
232 urlbuf[end - start] = 0;
234 strncpy(outbuf, buf, start);
235 sprintf(&outbuf[start], "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
236 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
237 strcat(outbuf, &buf[end]);
238 if ( strlen(outbuf) < 250 )
244 * \brief Turn a vCard "n" (name) field into something displayable.
245 * \param name the name field to convert
247 void vcard_n_prettyize(char *name)
252 original_name = strdup(name);
253 for (i=0; i<5; ++i) {
254 if (strlen(original_name) > 0) {
255 if (original_name[strlen(original_name)-1] == ' ') {
256 original_name[strlen(original_name)-1] = 0;
258 if (original_name[strlen(original_name)-1] == ';') {
259 original_name[strlen(original_name)-1] = 0;
264 for (i=0; i<strlen(original_name); ++i) {
265 if (original_name[i] == ';') {
269 name[strlen(name)+1] = 0;
270 name[strlen(name)] = original_name[i];
280 * \brief preparse a vcard name
281 * display_vcard() calls this after parsing the textual vCard into
282 * our 'struct vCard' data object.
283 * This gets called instead of display_parsed_vcard() if we are only looking
284 * to extract the person's name instead of displaying the card.
285 * \param v the vcard to retrieve the name from
286 * \param storename where to put the name at
288 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
291 strcpy(storename, "");
293 name = vcard_get_prop(v, "n", 1, 0, 0);
295 strcpy(storename, name);
296 /* vcard_n_prettyize(storename); */
304 * \brief html print a vcard
305 * display_vcard() calls this after parsing the textual vCard into
306 * our 'struct vCard' data object.
308 * Set 'full' to nonzero to display the full card, otherwise it will only
309 * show a summary line.
311 * This code is a bit ugly, so perhaps an explanation is due: we do this
312 * in two passes through the vCard fields. On the first pass, we process
313 * fields we understand, and then render them in a pretty fashion at the
314 * end. Then we make a second pass, outputting all the fields we don't
315 * understand in a simple two-column name/value format.
316 * \param v the vCard to display
317 * \param full display all items of the vcard?
319 void display_parsed_vcard(struct vCard *v, int full) {
325 char *thisname, *thisvalue;
326 char firsttoken[SIZ];
335 strcpy(fullname, "");
343 name = vcard_get_prop(v, "fn", 1, 0, 0);
347 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
348 strcpy(fullname, name);
349 vcard_n_prettyize(fullname);
359 wprintf("<div align=center><table bgcolor=#aaaaaa width=50%%>");
360 for (pass=1; pass<=2; ++pass) {
362 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
364 thisname = strdup(v->prop[i].name);
365 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
367 for (j=0; j<num_tokens(thisname, ';'); ++j) {
368 extract_token(buf, thisname, j, ';', sizeof buf);
369 if (!strcasecmp(buf, "encoding=quoted-printable")) {
371 remove_token(thisname, j, ';');
373 if (!strcasecmp(buf, "encoding=base64")) {
375 remove_token(thisname, j, ';');
380 thisvalue = malloc(strlen(v->prop[i].value) + 50);
381 j = CtdlDecodeQuotedPrintable(
382 thisvalue, v->prop[i].value,
383 strlen(v->prop[i].value) );
387 thisvalue = malloc(strlen(v->prop[i].value) + 50);
389 thisvalue, v->prop[i].value,
390 strlen(v->prop[i].value) );
393 thisvalue = strdup(v->prop[i].value);
396 /** Various fields we may encounter ***/
398 /** N is name, but only if there's no FN already there */
399 if (!strcasecmp(firsttoken, "n")) {
400 if (strlen(fullname) == 0) {
401 strcpy(fullname, thisvalue);
402 vcard_n_prettyize(fullname);
406 /** FN (full name) is a true 'display name' field */
407 else if (!strcasecmp(firsttoken, "fn")) {
408 strcpy(fullname, thisvalue);
412 else if (!strcasecmp(firsttoken, "title")) {
413 strcpy(title, thisvalue);
417 else if (!strcasecmp(firsttoken, "org")) {
418 strcpy(org, thisvalue);
421 else if (!strcasecmp(firsttoken, "email")) {
422 if (strlen(mailto) > 0) strcat(mailto, "<br />");
424 "<a href=\"display_enter"
425 "?force_room=_MAIL_?recp=");
427 urlesc(&mailto[strlen(mailto)], fullname);
428 urlesc(&mailto[strlen(mailto)], " <");
429 urlesc(&mailto[strlen(mailto)], thisvalue);
430 urlesc(&mailto[strlen(mailto)], ">");
432 strcat(mailto, "\">");
433 stresc(&mailto[strlen(mailto)], thisvalue, 1, 1);
434 strcat(mailto, "</A>");
436 else if (!strcasecmp(firsttoken, "tel")) {
437 if (strlen(phone) > 0) strcat(phone, "<br />");
438 strcat(phone, thisvalue);
439 for (j=0; j<num_tokens(thisname, ';'); ++j) {
440 extract_token(buf, thisname, j, ';', sizeof buf);
441 if (!strcasecmp(buf, "tel"))
443 else if (!strcasecmp(buf, "work"))
444 strcat(phone, _(" (work)"));
445 else if (!strcasecmp(buf, "home"))
446 strcat(phone, _(" (home)"));
447 else if (!strcasecmp(buf, "cell"))
448 strcat(phone, _(" (cell)"));
456 else if (!strcasecmp(firsttoken, "adr")) {
459 wprintf(_("Address:"));
460 wprintf("</TD><TD>");
461 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
462 extract_token(buf, thisvalue, j, ';', sizeof buf);
463 if (strlen(buf) > 0) {
465 if (j<3) wprintf("<br />");
469 wprintf("</TD></TR>\n");
472 else if (!strcasecmp(firsttoken, "version")) {
475 else if (!strcasecmp(firsttoken, "rev")) {
478 else if (!strcasecmp(firsttoken, "label")) {
483 /*** Don't show extra fields. They're ugly.
487 wprintf("</TD><TD>");
489 wprintf("</TD></TR>\n");
499 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
500 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
501 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
502 "<FONT SIZE=+1><B>");
504 wprintf("</B></FONT>");
505 if (strlen(title) > 0) {
506 wprintf("<div align=right>");
510 if (strlen(org) > 0) {
511 wprintf("<div align=right>");
515 wprintf("</TD></TR>\n");
517 if (strlen(phone) > 0) {
519 wprintf(_("Telephone:"));
520 wprintf("</td><td>%s</td></tr>\n", phone);
522 if (strlen(mailto) > 0) {
524 wprintf(_("E-mail:"));
525 wprintf("</td><td>%s</td></tr>\n", mailto);
531 wprintf("</table></div>\n");
537 * \brief Display a textual vCard
538 * (Converts to a vCard object and then calls the actual display function)
539 * Set 'full' to nonzero to display the whole card instead of a one-liner.
540 * Or, if "storename" is non-NULL, just store the person's name in that
541 * buffer instead of displaying the card at all.
542 * \param vcard_source the buffer containing the vcard text
543 * \param alpha what???
544 * \param full should we usse all lines?
545 * \param storename where to store???
547 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
553 v = vcard_load(vcard_source);
554 if (v == NULL) return;
556 name = vcard_get_prop(v, "n", 1, 0, 0);
562 if (storename != NULL) {
563 fetchname_parsed_vcard(v, storename);
565 else if ( (alpha == 0)
566 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
567 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
569 display_parsed_vcard(v, full);
577 * \brief I wanna SEE that message!
578 * \param msgnum the citadel number of the message to display
579 * \param printable_view are we doing a print view?
580 * \param section Optional for encapsulated message/rfc822 submessage)
582 void read_message(long msgnum, int printable_view, char *section) {
584 char mime_partnum[256];
585 char mime_filename[256];
586 char mime_content_type[256];
587 char mime_charset[256];
588 char mime_disposition[256];
591 char mime_submessages[256];
598 char reply_all[4096];
604 char vcard_partnum[256];
605 char cal_partnum[256];
606 char *part_source = NULL;
608 iconv_t ic = (iconv_t)(-1) ;
609 char *ibuf; /**< Buffer of characters to be converted */
610 char *obuf; /**< Buffer for converted characters */
611 size_t ibuflen; /**< Length of input buffer */
612 size_t obuflen; /**< Length of output buffer */
613 char *osav; /**< Saved pointer to output buffer */
619 strcpy(reply_to, "");
620 strcpy(reply_all, "");
621 strcpy(vcard_partnum, "");
622 strcpy(cal_partnum, "");
623 strcpy(mime_http, "");
624 strcpy(mime_content_type, "text/plain");
625 strcpy(mime_charset, "us-ascii");
626 strcpy(mime_submessages, "");
628 serv_printf("MSG4 %ld|%s", msgnum, section);
629 serv_getln(buf, sizeof buf);
632 wprintf(_("ERROR:"));
633 wprintf("</STRONG> %s<br />\n", &buf[4]);
637 /** begin everythingamundo table */
638 if (!printable_view) {
639 wprintf("<div class=\"fix_scrollbar_bug\">\n");
640 wprintf("<table width=100%% border=1 cellspacing=0 "
641 "cellpadding=0><TR><TD>\n");
644 /** begin message header table */
645 wprintf("<table width=100%% border=0 cellspacing=0 "
646 "cellpadding=1 bgcolor=\"#CCCCCC\"><tr><td>\n");
648 wprintf("<span class=\"message_header\">");
649 strcpy(m_subject, "");
652 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
653 if (!strcmp(buf, "000")) {
655 wprintf(_("unexpected end of message"));
656 wprintf("</i><br /><br />\n");
657 wprintf("</span>\n");
660 if (!strncasecmp(buf, "nhdr=yes", 8))
664 if (!strncasecmp(buf, "type=", 5))
665 format_type = atoi(&buf[5]);
666 if (!strncasecmp(buf, "from=", 5)) {
667 strcpy(from, &buf[5]);
669 wprintf("<a href=\"showuser?who=");
671 utf8ify_rfc822_string(from);
678 if (!strncasecmp(buf, "subj=", 5)) {
679 safestrncpy(m_subject, &buf[5], sizeof m_subject);
681 if (!strncasecmp(buf, "cccc=", 5)) {
682 safestrncpy(m_cc, &buf[5], sizeof m_cc);
683 if (strlen(reply_all) > 0) {
684 strcat(reply_all, ", ");
686 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
687 (sizeof reply_all - strlen(reply_all)) );
689 if ((!strncasecmp(buf, "hnod=", 5))
690 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
691 wprintf("(%s) ", &buf[5]);
693 if ((!strncasecmp(buf, "room=", 5))
694 && (strcasecmp(&buf[5], WC->wc_roomname))
695 && (strlen(&buf[5])>0) ) {
697 wprintf("%s> ", &buf[5]);
699 if (!strncasecmp(buf, "rfca=", 5)) {
700 strcpy(rfca, &buf[5]);
706 if (!strncasecmp(buf, "node=", 5)) {
707 strcpy(node, &buf[5]);
708 if ( ((WC->room_flags & QR_NETWORK)
709 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
710 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
713 wprintf("@%s ", &buf[5]);
716 if (!strncasecmp(buf, "rcpt=", 5)) {
718 if (strlen(reply_all) > 0) {
719 strcat(reply_all, ", ");
721 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
722 (sizeof reply_all - strlen(reply_all)) );
724 utf8ify_rfc822_string(&buf[5]);
729 if (!strncasecmp(buf, "time=", 5)) {
730 fmt_date(now, atol(&buf[5]), 0);
734 if (!strncasecmp(buf, "part=", 5)) {
735 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
736 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
737 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
738 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
739 mime_length = extract_int(&buf[5], 5);
741 if (!strcasecmp(mime_content_type, "message/rfc822")) {
742 if (strlen(mime_submessages) > 0) {
743 strcat(mime_submessages, "|");
745 strcat(mime_submessages, mime_partnum);
747 else if ((!strcasecmp(mime_disposition, "inline"))
748 && (!strncasecmp(mime_content_type, "image/", 6)) ){
749 snprintf(&mime_http[strlen(mime_http)],
750 (sizeof(mime_http) - strlen(mime_http) - 1),
751 "<img src=\"mimepart/%ld/%s/%s\">",
752 msgnum, mime_partnum, mime_filename);
754 else if ( (!strcasecmp(mime_disposition, "attachment"))
755 || (!strcasecmp(mime_disposition, "inline")) ) {
756 snprintf(&mime_http[strlen(mime_http)],
757 (sizeof(mime_http) - strlen(mime_http) - 1),
758 "<img src=\"static/diskette_24x.gif\" "
759 "border=0 align=middle>\n"
760 "%s (%s, %d bytes) [ "
761 "<a href=\"mimepart/%ld/%s/%s\""
762 "target=\"wc.%ld.%s\">%s</a>"
764 "<a href=\"mimepart_download/%ld/%s/%s\">%s</a>"
767 mime_content_type, mime_length,
768 msgnum, mime_partnum, mime_filename,
769 msgnum, mime_partnum,
771 msgnum, mime_partnum, mime_filename,
776 /** begin handler prep ***/
777 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
778 strcpy(vcard_partnum, mime_partnum);
781 if (!strcasecmp(mime_content_type, "text/calendar")) {
782 strcpy(cal_partnum, mime_partnum);
785 /** end handler prep ***/
791 /** Generate a reply-to address */
792 if (strlen(rfca) > 0) {
793 strcpy(reply_to, rfca);
796 if ( (strlen(node) > 0)
797 && (strcasecmp(node, serv_info.serv_nodename))
798 && (strcasecmp(node, serv_info.serv_humannode)) ) {
799 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
803 snprintf(reply_to, sizeof(reply_to), "%s", from);
813 utf8ify_rfc822_string(m_cc);
814 utf8ify_rfc822_string(m_subject);
816 if (strlen(m_cc) > 0) {
818 "<span class=\"message_subject\">");
824 if (strlen(m_subject) > 0) {
826 "<span class=\"message_subject\">");
827 wprintf(_("Subject:"));
834 /** start msg buttons */
835 if (!printable_view) {
836 wprintf("<td align=right><span class=\"msgbuttons\">\n");
839 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
840 wprintf("<a href=\"display_enter");
841 if (WC->is_mailbox) {
842 wprintf("?replyquote=%ld", msgnum);
845 urlescputs(reply_to);
846 if (strlen(m_subject) > 0) {
847 wprintf("?subject=");
848 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
849 urlescputs(m_subject);
851 wprintf("\">[%s]</a> ", _("Reply"));
855 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
856 if (!WC->is_mailbox) {
857 wprintf("<a href=\"display_enter");
858 wprintf("?replyquote=%ld", msgnum);
860 urlescputs(reply_to);
861 if (strlen(m_subject) > 0) {
862 wprintf("?subject=");
863 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
864 urlescputs(m_subject);
866 wprintf("\">[%s]</a> ", _("ReplyQuoted"));
871 if (WC->wc_view == VIEW_MAILBOX) {
872 wprintf("<a href=\"display_enter");
873 wprintf("?replyquote=%ld", msgnum);
875 urlescputs(reply_to);
877 urlescputs(reply_all);
878 if (strlen(m_subject) > 0) {
879 wprintf("?subject=");
880 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
881 urlescputs(m_subject);
883 wprintf("\">[%s]</a> ", _("ReplyAll"));
887 if (WC->wc_view == VIEW_MAILBOX) {
888 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
889 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
890 urlescputs(m_subject);
891 wprintf("\">[%s]</a> ", _("Forward"));
894 /** If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
895 if ( (WC->is_room_aide) || (WC->is_mailbox) ) {
897 wprintf("<a href=\"confirm_move_msg?msgid=%ld\">[%s]</a> ",
901 wprintf("<a href=\"delete_msg?msgid=%ld\" "
902 "onClick=\"return confirm('%s');\">"
903 "[%s]</a> ", msgnum, _("Delete this message?"), _("Delete")
908 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'); \" >"
909 "[%s]</a>", msgnum, msgnum, _("Headers"));
913 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'); \" >"
914 "[%s]</a>", msgnum, msgnum, _("Print"));
916 wprintf("</span></td>");
919 wprintf("</tr></table>\n");
922 wprintf("<table border=0 width=100%% bgcolor=\"#FFFFFF\" "
923 "cellpadding=1 cellspacing=0><tr><td>");
926 * Learn the content type
928 strcpy(mime_content_type, "text/plain");
929 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
930 if (!strcmp(buf, "000")) {
932 wprintf(_("unexpected end of message"));
933 wprintf("</i><br /><br />\n");
936 if (!strncasecmp(buf, "Content-type: ", 14)) {
937 safestrncpy(mime_content_type, &buf[14],
938 sizeof(mime_content_type));
939 for (i=0; i<strlen(mime_content_type); ++i) {
940 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
941 safestrncpy(mime_charset, &mime_content_type[i+8],
942 sizeof mime_charset);
945 for (i=0; i<strlen(mime_content_type); ++i) {
946 if (mime_content_type[i] == ';') {
947 mime_content_type[i] = 0;
950 for (i=0; i<strlen(mime_charset); ++i) {
951 if (mime_charset[i] == ';') {
958 /** Set up a character set conversion if we need to (and if we can) */
960 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
961 if ( (strcasecmp(mime_charset, "us-ascii"))
962 && (strcasecmp(mime_charset, "UTF-8"))
963 && (strcasecmp(mime_charset, ""))
965 ic = ctdl_iconv_open("UTF-8", mime_charset);
966 if (ic == (iconv_t)(-1) ) {
967 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
968 __FILE__, __LINE__, mime_charset, strerror(errno));
973 /** Messages in legacy Citadel variformat get handled thusly... */
974 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
978 /** Boring old 80-column fixed format text gets handled this way... */
979 else if ( (!strcasecmp(mime_content_type, "text/plain"))
980 || (!strcasecmp(mime_content_type, "text")) ) {
981 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
982 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
983 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
986 if (ic != (iconv_t)(-1) ) {
988 ibuflen = strlen(ibuf);
990 obuf = (char *) malloc(obuflen);
992 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
993 osav[SIZ-obuflen] = 0;
994 safestrncpy(buf, osav, sizeof buf);
999 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1000 buf[strlen(buf) - 1] = 0;
1002 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1003 wprintf("<blockquote>");
1005 } else if ((bq == 1) &&
1006 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1007 wprintf("</blockquote>");
1013 wprintf("</tt><br />\n");
1015 wprintf("</i><br />");
1018 else /** HTML is fun, but we've got to strip it first */
1019 if (!strcasecmp(mime_content_type, "text/html")) {
1020 output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
1023 /** Unknown weirdness */
1025 wprintf(_("I don't know how to display %s"), mime_content_type);
1026 wprintf("<br />\n", mime_content_type);
1027 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1030 /** If there are attached submessages, display them now... */
1031 if ( (strlen(mime_submessages) > 0) && (!section[0]) ) {
1032 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1033 extract_token(buf, mime_submessages, i, '|', sizeof buf);
1034 /** use printable_view to suppress buttons */
1035 wprintf("<blockquote>");
1036 read_message(msgnum, 1, buf);
1037 wprintf("</blockquote>");
1042 /** Afterwards, offer links to download attachments 'n' such */
1043 if ( (strlen(mime_http) > 0) && (!section[0]) ) {
1044 wprintf("%s", mime_http);
1047 /** Handler for vCard parts */
1048 if (strlen(vcard_partnum) > 0) {
1049 part_source = load_mimepart(msgnum, vcard_partnum);
1050 if (part_source != NULL) {
1052 /** If it's my vCard I can edit it */
1053 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1054 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1055 || (WC->wc_view == VIEW_ADDRESSBOOK)
1057 wprintf("<a href=\"edit_vcard?"
1058 "msgnum=%ld?partnum=%s\">",
1059 msgnum, vcard_partnum);
1060 wprintf("[%s]</a>", _("edit"));
1063 /** In all cases, display the full card */
1064 display_vcard(part_source, 0, 1, NULL);
1068 /** Handler for calendar parts */
1069 if (strlen(cal_partnum) > 0) {
1070 part_source = load_mimepart(msgnum, cal_partnum);
1071 if (part_source != NULL) {
1072 cal_process_attachment(part_source,
1073 msgnum, cal_partnum);
1083 wprintf("</td></tr></table>\n");
1085 /** end everythingamundo table */
1086 if (!printable_view) {
1087 wprintf("</td></tr></table>\n");
1088 wprintf("</div><br />\n");
1092 if (ic != (iconv_t)(-1) ) {
1101 * \brief Unadorned HTML output of an individual message, suitable
1102 * for placing in a hidden iframe, for printing, or whatever
1104 * \param msgnum_as_string Message number, as a string instead of as a long int
1106 void embed_message(char *msgnum_as_string) {
1109 msgnum = atol(msgnum_as_string);
1110 begin_ajax_response();
1111 read_message(msgnum, 0, "");
1112 end_ajax_response();
1117 * \brief Printable view of a message
1119 * \param msgnum_as_string Message number, as a string instead of as a long int
1121 void print_message(char *msgnum_as_string) {
1124 msgnum = atol(msgnum_as_string);
1125 output_headers(0, 0, 0, 0, 0, 0);
1127 wprintf("Content-type: text/html\r\n"
1129 "Connection: close\r\n",
1133 wprintf("\r\n\r\n<html>\n"
1134 "<head><title>Printable view</title></head>\n"
1135 "<body onLoad=\" window.print(); window.close(); \">\n"
1138 read_message(msgnum, 1, "");
1140 wprintf("\n</body></html>\n\n");
1147 * \brief Display a message's headers
1149 * \param msgnum_as_string Message number, as a string instead of as a long int
1151 void display_headers(char *msgnum_as_string) {
1155 msgnum = atol(msgnum_as_string);
1156 output_headers(0, 0, 0, 0, 0, 0);
1158 wprintf("Content-type: text/plain\r\n"
1160 "Connection: close\r\n",
1164 serv_printf("MSG2 %ld|3", msgnum);
1165 serv_getln(buf, sizeof buf);
1166 if (buf[0] == '1') {
1167 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1168 wprintf("%s\n", buf);
1178 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1179 * or 'reply quoted' operations.
1181 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1182 * in this function. Doing so would throw a JavaScript error in the
1183 * 'supplied text' argument to the editor.
1185 * \param msgnum Message number of the message we want to quote
1186 * \param forward_attachments Nonzero if we want attachments to be forwarded
1188 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1190 char mime_partnum[256];
1191 char mime_filename[256];
1192 char mime_content_type[256];
1193 char mime_charset[256];
1194 char mime_disposition[256];
1196 char *attachments = NULL;
1198 int num_attachments = 0;
1199 struct wc_attachment *att, *aptr;
1200 char m_subject[256];
1206 int format_type = 0;
1211 iconv_t ic = (iconv_t)(-1) ;
1212 char *ibuf; /**< Buffer of characters to be converted */
1213 char *obuf; /**< Buffer for converted characters */
1214 size_t ibuflen; /**< Length of input buffer */
1215 size_t obuflen; /**< Length of output buffer */
1216 char *osav; /**< Saved pointer to output buffer */
1222 strcpy(reply_to, "");
1223 strcpy(mime_content_type, "text/plain");
1224 strcpy(mime_charset, "us-ascii");
1226 serv_printf("MSG4 %ld", msgnum);
1227 serv_getln(buf, sizeof buf);
1228 if (buf[0] != '1') {
1229 wprintf(_("ERROR:"));
1230 wprintf("%s<br />", &buf[4]);
1234 strcpy(m_subject, "");
1236 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1237 if (!strcmp(buf, "000")) {
1238 wprintf(_("unexpected end of message"));
1241 if (include_headers) {
1242 if (!strncasecmp(buf, "nhdr=yes", 8))
1246 if (!strncasecmp(buf, "type=", 5))
1247 format_type = atoi(&buf[5]);
1248 if (!strncasecmp(buf, "from=", 5)) {
1249 strcpy(from, &buf[5]);
1250 wprintf(_("from "));
1252 utf8ify_rfc822_string(from);
1256 if (!strncasecmp(buf, "subj=", 5)) {
1257 strcpy(m_subject, &buf[5]);
1259 if ((!strncasecmp(buf, "hnod=", 5))
1260 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1261 wprintf("(%s) ", &buf[5]);
1263 if ((!strncasecmp(buf, "room=", 5))
1264 && (strcasecmp(&buf[5], WC->wc_roomname))
1265 && (strlen(&buf[5])>0) ) {
1267 wprintf("%s> ", &buf[5]);
1269 if (!strncasecmp(buf, "rfca=", 5)) {
1270 strcpy(rfca, &buf[5]);
1276 if (!strncasecmp(buf, "node=", 5)) {
1277 strcpy(node, &buf[5]);
1278 if ( ((WC->room_flags & QR_NETWORK)
1279 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1280 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1281 && (strlen(rfca)==0)
1283 wprintf("@%s ", &buf[5]);
1286 if (!strncasecmp(buf, "rcpt=", 5)) {
1288 wprintf("%s ", &buf[5]);
1290 if (!strncasecmp(buf, "time=", 5)) {
1291 fmt_date(now, atol(&buf[5]), 0);
1292 wprintf("%s ", now);
1297 * Save attachment info for later. We can't start downloading them
1298 * yet because we're in the middle of a server transaction.
1300 if (!strncasecmp(buf, "part=", 5)) {
1301 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1304 sprintf(ptr, "%s%s\n",
1305 ((attachments != NULL) ? attachments : ""),
1310 lprintf(9, "attachments=<%s>\n", attachments);
1316 if (include_headers) {
1320 utf8ify_rfc822_string(m_subject);
1322 if (strlen(m_subject) > 0) {
1323 wprintf(_("Subject:"));
1325 msgescputs(m_subject);
1336 * Learn the content type
1338 strcpy(mime_content_type, "text/plain");
1339 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1340 if (!strcmp(buf, "000")) {
1341 wprintf(_("unexpected end of message"));
1344 if (!strncasecmp(buf, "Content-type: ", 14)) {
1345 safestrncpy(mime_content_type, &buf[14],
1346 sizeof(mime_content_type));
1347 for (i=0; i<strlen(mime_content_type); ++i) {
1348 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1349 safestrncpy(mime_charset, &mime_content_type[i+8],
1350 sizeof mime_charset);
1353 for (i=0; i<strlen(mime_content_type); ++i) {
1354 if (mime_content_type[i] == ';') {
1355 mime_content_type[i] = 0;
1358 for (i=0; i<strlen(mime_charset); ++i) {
1359 if (mime_charset[i] == ';') {
1360 mime_charset[i] = 0;
1366 /** Set up a character set conversion if we need to (and if we can) */
1368 if ( (strcasecmp(mime_charset, "us-ascii"))
1369 && (strcasecmp(mime_charset, "UTF-8"))
1370 && (strcasecmp(mime_charset, ""))
1372 ic = ctdl_iconv_open("UTF-8", mime_charset);
1373 if (ic == (iconv_t)(-1) ) {
1374 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1375 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1380 /** Messages in legacy Citadel variformat get handled thusly... */
1381 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1385 /* Boring old 80-column fixed format text gets handled this way... */
1386 else if (!strcasecmp(mime_content_type, "text/plain")) {
1387 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1388 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1389 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1392 if (ic != (iconv_t)(-1) ) {
1394 ibuflen = strlen(ibuf);
1396 obuf = (char *) malloc(obuflen);
1398 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1399 osav[SIZ-obuflen] = 0;
1400 safestrncpy(buf, osav, sizeof buf);
1405 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1406 buf[strlen(buf) - 1] = 0;
1408 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1409 wprintf("<blockquote>");
1411 } else if ((bq == 1) &&
1412 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1413 wprintf("</blockquote>");
1419 wprintf("</tt><br />");
1421 wprintf("</i><br />");
1424 /** HTML just gets escaped and stuffed back into the editor */
1425 else if (!strcasecmp(mime_content_type, "text/html")) {
1426 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1432 /** Unknown weirdness ... don't know how to handle this content type */
1434 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1438 /** end of body handler */
1441 * If there were attachments, we have to download them and insert them
1442 * into the attachment chain for the forwarded message we are composing.
1444 if ( (forward_attachments) && (num_attachments) ) {
1445 for (i=0; i<num_attachments; ++i) {
1446 extract_token(buf, attachments, i, '\n', sizeof buf);
1447 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1448 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1449 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1450 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1451 mime_length = extract_int(buf, 5);
1454 * tracing ... uncomment if necessary
1457 lprintf(9, "fwd filename: %s\n", mime_filename);
1458 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1459 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1460 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1461 lprintf(9, "fwd length : %d\n", mime_length);
1463 if ( (!strcasecmp(mime_disposition, "inline"))
1464 || (!strcasecmp(mime_disposition, "attachment")) ) {
1466 /* Create an attachment struct from this mime part... */
1467 att = malloc(sizeof(struct wc_attachment));
1468 memset(att, 0, sizeof(struct wc_attachment));
1469 att->length = mime_length;
1470 strcpy(att->content_type, mime_content_type);
1471 strcpy(att->filename, mime_filename);
1473 att->data = load_mimepart(msgnum, mime_partnum);
1475 /* And add it to the list. */
1476 if (WC->first_attachment == NULL) {
1477 WC->first_attachment = att;
1480 aptr = WC->first_attachment;
1481 while (aptr->next != NULL) aptr = aptr->next;
1490 if (ic != (iconv_t)(-1) ) {
1495 if (attachments != NULL) {
1501 * \brief Display one row in the mailbox summary view
1503 * \param num The row number to be displayed
1505 void display_summarized(int num) {
1508 wprintf("<tr id=\"m%ld\" style=\"width:100%%;font-weight:%s;background-color:#ffffff\" "
1509 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1510 WC->summ[num].msgnum,
1511 (WC->summ[num].is_new ? "bold" : "normal"),
1512 WC->summ[num].msgnum
1515 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1516 escputs(WC->summ[num].subj);
1519 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1520 escputs(WC->summ[num].from);
1523 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1524 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1534 * \brief display the adressbook overview
1535 * \param msgnum the citadel message number
1536 * \param alpha what????
1538 void display_addressbook(long msgnum, char alpha) {
1540 char mime_partnum[SIZ];
1541 char mime_filename[SIZ];
1542 char mime_content_type[SIZ];
1543 char mime_disposition[SIZ];
1545 char vcard_partnum[SIZ];
1546 char *vcard_source = NULL;
1547 struct message_summary summ;
1549 memset(&summ, 0, sizeof(summ));
1550 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1552 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1554 serv_getln(buf, sizeof buf);
1555 if (buf[0] != '1') return;
1557 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1558 if (!strncasecmp(buf, "part=", 5)) {
1559 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1560 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1561 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1562 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1563 mime_length = extract_int(&buf[5], 5);
1565 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1566 strcpy(vcard_partnum, mime_partnum);
1572 if (strlen(vcard_partnum) > 0) {
1573 vcard_source = load_mimepart(msgnum, vcard_partnum);
1574 if (vcard_source != NULL) {
1576 /** Display the summary line */
1577 display_vcard(vcard_source, alpha, 0, NULL);
1579 /** If it's my vCard I can edit it */
1580 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1581 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1582 || (WC->wc_view == VIEW_ADDRESSBOOK)
1584 wprintf("<a href=\"edit_vcard?"
1585 "msgnum=%ld?partnum=%s\">",
1586 msgnum, vcard_partnum);
1587 wprintf("[%s]</a>", _("edit"));
1599 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1600 * \param namebuf name to analyze, reverse if nescessary
1602 void lastfirst_firstlast(char *namebuf) {
1603 char firstname[SIZ];
1607 if (namebuf == NULL) return;
1608 if (strchr(namebuf, ';') != NULL) return;
1610 i = num_tokens(namebuf, ' ');
1613 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1614 remove_token(namebuf, i-1, ' ');
1615 strcpy(firstname, namebuf);
1616 sprintf(namebuf, "%s; %s", lastname, firstname);
1620 * \brief fetch what??? name
1621 * \param msgnum the citadel message number
1622 * \param namebuf where to put the name in???
1624 void fetch_ab_name(long msgnum, char *namebuf) {
1626 char mime_partnum[SIZ];
1627 char mime_filename[SIZ];
1628 char mime_content_type[SIZ];
1629 char mime_disposition[SIZ];
1631 char vcard_partnum[SIZ];
1632 char *vcard_source = NULL;
1634 struct message_summary summ;
1636 if (namebuf == NULL) return;
1637 strcpy(namebuf, "");
1639 memset(&summ, 0, sizeof(summ));
1640 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1642 sprintf(buf, "MSG0 %ld|1", msgnum); /** ask for headers only */
1644 serv_getln(buf, sizeof buf);
1645 if (buf[0] != '1') return;
1647 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1648 if (!strncasecmp(buf, "part=", 5)) {
1649 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1650 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1651 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1652 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1653 mime_length = extract_int(&buf[5], 5);
1655 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1656 strcpy(vcard_partnum, mime_partnum);
1662 if (strlen(vcard_partnum) > 0) {
1663 vcard_source = load_mimepart(msgnum, vcard_partnum);
1664 if (vcard_source != NULL) {
1666 /* Grab the name off the card */
1667 display_vcard(vcard_source, 0, 0, namebuf);
1673 lastfirst_firstlast(namebuf);
1675 for (i=0; i<strlen(namebuf); ++i) {
1676 if (namebuf[i] != ';') return;
1678 strcpy(namebuf, _("(no name)"));
1684 * \brief Record compare function for sorting address book indices
1685 * \param ab1 adressbook one
1686 * \param ab2 adressbook two
1688 int abcmp(const void *ab1, const void *ab2) {
1690 (((const struct addrbookent *)ab1)->ab_name),
1691 (((const struct addrbookent *)ab2)->ab_name)
1697 * \brief Helper function for do_addrbook_view()
1698 * Converts a name into a three-letter tab label
1699 * \param tabbuf the tabbuffer to add name to
1700 * \param name the name to add to the tabbuffer
1702 void nametab(char *tabbuf, char *name) {
1703 stresc(tabbuf, name, 0, 0);
1704 tabbuf[0] = toupper(tabbuf[0]);
1705 tabbuf[1] = tolower(tabbuf[1]);
1706 tabbuf[2] = tolower(tabbuf[2]);
1712 * \brief Render the address book using info we gathered during the scan
1713 * \param addrbook the addressbook to render
1714 * \param num_ab the number of the addressbook
1716 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1720 static int NAMESPERPAGE = 60;
1724 char tabfirst_label[SIZ];
1726 char tablast_label[SIZ];
1729 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1730 wprintf(_("This address book is empty."));
1731 wprintf("</i></div>\n");
1736 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1739 num_pages = num_ab / NAMESPERPAGE;
1741 page = atoi(bstr("page"));
1744 for (i=0; i<=num_pages; ++i) {
1746 wprintf("<a href=\"readfwd?page=%d\">", i);
1751 tabfirst = i * NAMESPERPAGE;
1752 tablast = tabfirst + NAMESPERPAGE - 1;
1753 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1754 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1755 nametab(tablast_label, addrbook[tablast].ab_name);
1756 wprintf("[%s - %s]",
1757 tabfirst_label, tablast_label
1766 wprintf("<br />\n");
1768 wprintf("<table border=0 cellspacing=0 "
1769 "cellpadding=3 width=100%%>\n"
1772 for (i=0; i<num_ab; ++i) {
1774 if ((i / NAMESPERPAGE) == page) {
1776 if ((displayed % 4) == 0) {
1777 if (displayed > 0) {
1781 wprintf("<tr bgcolor=\"#%s\">",
1782 (bg ? "DDDDDD" : "FFFFFF")
1788 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
1789 addrbook[i].ab_msgnum);
1790 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1791 vcard_n_prettyize(addrbook[i].ab_name);
1792 escputs(addrbook[i].ab_name);
1793 wprintf("</a></td>\n");
1798 wprintf("</tr></table>\n");
1804 * \brief load message pointers from the server
1805 * \param servcmd the citadel command to send to the citserver
1806 * \param with_headers what headers???
1808 int load_msg_ptrs(char *servcmd, int with_headers)
1819 int num_summ_alloc = 0;
1821 if (WC->summ != NULL) {
1826 num_summ_alloc = 100;
1828 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1831 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1833 serv_getln(buf, sizeof buf);
1834 if (buf[0] != '1') {
1835 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1838 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1839 if (nummsgs < maxload) {
1840 WC->msgarr[nummsgs] = extract_long(buf, 0);
1841 datestamp = extract_long(buf, 1);
1842 extract_token(fullname, buf, 2, '|', sizeof fullname);
1843 extract_token(nodename, buf, 3, '|', sizeof nodename);
1844 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1845 extract_token(subject, buf, 5, '|', sizeof subject);
1849 if (nummsgs > num_summ_alloc) {
1850 num_summ_alloc *= 2;
1851 WC->summ = realloc(WC->summ,
1852 num_summ_alloc * sizeof(struct message_summary));
1856 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1857 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1858 safestrncpy(WC->summ[nummsgs-1].subj,
1859 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1860 if (strlen(fullname) > 0) {
1861 safestrncpy(WC->summ[nummsgs-1].from,
1862 fullname, sizeof WC->summ[nummsgs-1].from);
1864 if (strlen(subject) > 0) {
1865 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1866 sizeof WC->summ[nummsgs-1].subj);
1869 /** Handle subjects with RFC2047 encoding */
1870 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1872 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1873 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1876 if (strlen(nodename) > 0) {
1877 if ( ((WC->room_flags & QR_NETWORK)
1878 || ((strcasecmp(nodename, serv_info.serv_nodename)
1879 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1881 strcat(WC->summ[nummsgs-1].from, " @ ");
1882 strcat(WC->summ[nummsgs-1].from, nodename);
1886 WC->summ[nummsgs-1].date = datestamp;
1889 /** Handle senders with RFC2047 encoding */
1890 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1892 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1893 strcpy(&WC->summ[nummsgs-1].from[22], "...");
1902 * \brief qsort() compatible function to compare two longs in descending order.
1904 * \param s1 first number to compare
1905 * \param s2 second number to compare
1907 int longcmp_r(const void *s1, const void *s2) {
1914 if (l1 > l2) return(-1);
1915 if (l1 < l2) return(+1);
1921 * \brief qsort() compatible function to compare two message summary structs by ascending subject.
1923 * \param s1 first item to compare
1924 * \param s2 second item to compare
1926 int summcmp_subj(const void *s1, const void *s2) {
1927 struct message_summary *summ1;
1928 struct message_summary *summ2;
1930 summ1 = (struct message_summary *)s1;
1931 summ2 = (struct message_summary *)s2;
1932 return strcasecmp(summ1->subj, summ2->subj);
1936 * \brief qsort() compatible function to compare two message summary structs by descending subject.
1938 * \param s1 first item to compare
1939 * \param s2 second item to compare
1941 int summcmp_rsubj(const void *s1, const void *s2) {
1942 struct message_summary *summ1;
1943 struct message_summary *summ2;
1945 summ1 = (struct message_summary *)s1;
1946 summ2 = (struct message_summary *)s2;
1947 return strcasecmp(summ2->subj, summ1->subj);
1951 * \brief qsort() compatible function to compare two message summary structs by ascending sender.
1953 * \param s1 first item to compare
1954 * \param s2 second item to compare
1956 int summcmp_sender(const void *s1, const void *s2) {
1957 struct message_summary *summ1;
1958 struct message_summary *summ2;
1960 summ1 = (struct message_summary *)s1;
1961 summ2 = (struct message_summary *)s2;
1962 return strcasecmp(summ1->from, summ2->from);
1966 * \brief qsort() compatible function to compare two message summary structs by descending sender.
1968 * \param s1 first item to compare
1969 * \param s2 second item to compare
1971 int summcmp_rsender(const void *s1, const void *s2) {
1972 struct message_summary *summ1;
1973 struct message_summary *summ2;
1975 summ1 = (struct message_summary *)s1;
1976 summ2 = (struct message_summary *)s2;
1977 return strcasecmp(summ2->from, summ1->from);
1981 * \brief qsort() compatible function to compare two message summary structs by ascending date.
1983 * \param s1 first item to compare
1984 * \param s2 second item to compare
1986 int summcmp_date(const void *s1, const void *s2) {
1987 struct message_summary *summ1;
1988 struct message_summary *summ2;
1990 summ1 = (struct message_summary *)s1;
1991 summ2 = (struct message_summary *)s2;
1993 if (summ1->date < summ2->date) return -1;
1994 else if (summ1->date > summ2->date) return +1;
1999 * \brief qsort() compatible function to compare two message summary structs by descending date.
2001 * \param s1 first item to compare
2002 * \param s2 second item to compare
2004 int summcmp_rdate(const void *s1, const void *s2) {
2005 struct message_summary *summ1;
2006 struct message_summary *summ2;
2008 summ1 = (struct message_summary *)s1;
2009 summ2 = (struct message_summary *)s2;
2011 if (summ1->date < summ2->date) return +1;
2012 else if (summ1->date > summ2->date) return -1;
2019 * \brief command loop for reading messages
2021 * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
2023 void readloop(char *oper)
2032 long *displayed_msgs = NULL;
2033 int num_displayed = 0;
2035 int is_addressbook = 0;
2036 int is_singlecard = 0;
2037 int is_calendar = 0;
2042 int lowest_displayed = (-1);
2043 int highest_displayed = 0;
2044 struct addrbookent *addrbook = NULL;
2046 char *sortby = NULL;
2047 char sortpref_name[128];
2048 char sortpref_value[128];
2049 char *subjsort_button;
2050 char *sendsort_button;
2051 char *datesort_button;
2052 int bbs_reverse = 0;
2054 if (WC->wc_view == VIEW_WIKI) {
2055 sprintf(buf, "wiki?room=%s?page=home", WC->wc_roomname);
2060 startmsg = atol(bstr("startmsg"));
2061 maxmsgs = atoi(bstr("maxmsgs"));
2062 is_summary = atoi(bstr("summary"));
2063 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2065 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
2066 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
2068 sortby = bstr("sortby");
2069 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
2070 set_preference(sortpref_name, sortby, 1);
2072 if (strlen(sortby) == 0) sortby = sortpref_value;
2075 if (strlen(sortby) == 0) sortby = "rdate";
2077 /** message board sort */
2078 if (!strcasecmp(sortby, "reverse")) {
2085 output_headers(1, 1, 1, 0, 0, 0);
2088 * When in summary mode, always show ALL messages instead of just
2089 * new or old. Otherwise, show what the user asked for.
2091 if (!strcmp(oper, "readnew")) {
2092 strcpy(cmd, "MSGS NEW");
2094 else if (!strcmp(oper, "readold")) {
2095 strcpy(cmd, "MSGS OLD");
2098 strcpy(cmd, "MSGS ALL");
2101 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
2103 strcpy(cmd, "MSGS ALL");
2106 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2108 strcpy(cmd, "MSGS ALL");
2113 strcpy(cmd, "MSGS ALL|||1"); /**< fetch header summary */
2119 * Are we doing a summary view? If so, we need to know old messages
2120 * and new messages, so we can do that pretty boldface thing for the
2123 strcpy(old_msgs, "");
2126 serv_getln(buf, sizeof buf);
2127 if (buf[0] == '2') {
2128 strcpy(old_msgs, &buf[4]);
2132 is_singlecard = atoi(bstr("is_singlecard"));
2134 if (WC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2136 strcpy(cmd, "MSGS ALL");
2139 if (WC->wc_default_view == VIEW_TASKS) { /**< tasks */
2141 strcpy(cmd, "MSGS ALL");
2144 if (WC->wc_default_view == VIEW_NOTES) { /**< notes */
2146 strcpy(cmd, "MSGS ALL");
2150 nummsgs = load_msg_ptrs(cmd, is_summary);
2153 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2155 if (!strcmp(oper, "readnew")) {
2156 wprintf(_("No new messages."));
2157 } else if (!strcmp(oper, "readold")) {
2158 wprintf(_("No old messages."));
2160 wprintf(_("No messages here."));
2169 for (a = 0; a < nummsgs; ++a) {
2170 /** Are you a new message, or an old message? */
2172 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
2173 WC->summ[a].is_new = 0;
2176 WC->summ[a].is_new = 1;
2182 if (startmsg == 0L) {
2184 startmsg = WC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2187 startmsg = WC->msgarr[0];
2192 if (!strcasecmp(sortby, "subject")) {
2193 qsort(WC->summ, WC->num_summ,
2194 sizeof(struct message_summary), summcmp_subj);
2196 else if (!strcasecmp(sortby, "rsubject")) {
2197 qsort(WC->summ, WC->num_summ,
2198 sizeof(struct message_summary), summcmp_rsubj);
2200 else if (!strcasecmp(sortby, "sender")) {
2201 qsort(WC->summ, WC->num_summ,
2202 sizeof(struct message_summary), summcmp_sender);
2204 else if (!strcasecmp(sortby, "rsender")) {
2205 qsort(WC->summ, WC->num_summ,
2206 sizeof(struct message_summary), summcmp_rsender);
2208 else if (!strcasecmp(sortby, "date")) {
2209 qsort(WC->summ, WC->num_summ,
2210 sizeof(struct message_summary), summcmp_date);
2212 else if (!strcasecmp(sortby, "rdate")) {
2213 qsort(WC->summ, WC->num_summ,
2214 sizeof(struct message_summary), summcmp_rdate);
2218 if (!strcasecmp(sortby, "subject")) {
2219 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2221 else if (!strcasecmp(sortby, "rsubject")) {
2222 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2225 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2228 if (!strcasecmp(sortby, "sender")) {
2229 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2231 else if (!strcasecmp(sortby, "rsender")) {
2232 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2235 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2238 if (!strcasecmp(sortby, "date")) {
2239 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2241 else if (!strcasecmp(sortby, "rdate")) {
2242 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2245 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2249 wprintf("</div>\n"); /** end of 'content' div */
2251 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2252 " document.onkeydown = CtdlMsgListKeyPress; "
2253 " if (document.layers) { "
2254 " document.captureEvents(Event.KEYPRESS); "
2259 /** note that Date and Delete are now in the same column */
2260 wprintf("<div id=\"message_list_hdr\">"
2261 "<div class=\"fix_scrollbar_bug\">"
2262 "<table cellspacing=0 style=\"width:100%%\">"
2265 wprintf("<td width=%d%%><b><i>%s</i></b> %s</td>"
2266 "<td width=%d%%><b><i>%s</i></b> %s</td>"
2267 "<td width=%d%%><b><i>%s</i></b> %s"
2269 "<input type=\"submit\" name=\"delete_button\" style=\"font-size:6pt\" "
2270 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2276 _("Subject"), subjsort_button,
2277 SENDER_COL_WIDTH_PCT,
2278 _("Sender"), sendsort_button,
2279 DATE_PLUS_BUTTONS_WIDTH_PCT,
2280 _("Date"), datesort_button,
2283 wprintf("</table></div></div>\n");
2285 wprintf("<div id=\"message_list\">"
2287 "<div class=\"fix_scrollbar_bug\">\n"
2289 "<table class=\"mailbox_summary\" id=\"summary_headers\" rules=rows "
2290 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2295 wprintf("<div align=center>%s</div>\n", _("Click on any note to edit it."));
2296 wprintf("<div id=\"new_notes_here\"></div>\n");
2299 for (a = 0; a < nummsgs; ++a) {
2300 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2302 /** Display the message */
2304 display_summarized(a);
2306 else if (is_addressbook) {
2307 fetch_ab_name(WC->msgarr[a], buf);
2309 addrbook = realloc(addrbook,
2310 (sizeof(struct addrbookent) * num_ab) );
2311 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2312 sizeof(addrbook[num_ab-1].ab_name));
2313 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
2315 else if (is_calendar) {
2316 display_calendar(WC->msgarr[a]);
2318 else if (is_tasks) {
2319 display_task(WC->msgarr[a]);
2321 else if (is_notes) {
2322 display_note(WC->msgarr[a]);
2325 if (displayed_msgs == NULL) {
2326 displayed_msgs = malloc(sizeof(long) *
2327 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2329 displayed_msgs[num_displayed] = WC->msgarr[a];
2332 if (lowest_displayed < 0) lowest_displayed = a;
2333 highest_displayed = a;
2340 * Set the "is_bbview" variable if it appears that we are looking at
2341 * a classic bulletin board view.
2343 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2344 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2349 if (displayed_msgs != NULL) {
2351 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2354 /** if we do a split bbview in the future, begin messages div here */
2356 for (a=0; a<num_displayed; ++a) {
2357 read_message(displayed_msgs[a], 0, "");
2360 /** if we do a split bbview in the future, end messages div here */
2362 free(displayed_msgs);
2363 displayed_msgs = NULL;
2368 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2369 wprintf("</div>"); /**< end of 'message_list' div */
2371 /** Here's the grab-it-to-resize-the-message-list widget */
2372 wprintf("<div id=\"resize_msglist\" "
2373 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2374 "<div class=\"fix_scrollbar_bug\">"
2375 "<table width=100%% border=3 cellspacing=0 "
2376 "bgcolor=\"#cccccc\" "
2377 "cellpadding=0><TR><TD> </td></tr></table>"
2381 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2385 * Bump these because although we're thinking in zero base, the user
2386 * is a drooling idiot and is thinking in one base.
2389 ++highest_displayed;
2392 * If we're not currently looking at ALL requested
2393 * messages, then display the selector bar
2396 /** begin bbview scroller */
2397 wprintf("<form name=\"msgomatic\">");
2398 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2400 wprintf("<select name=\"whichones\" size=\"1\" "
2401 "OnChange=\"location.href=msgomatic.whichones.options"
2402 "[selectedIndex].value\">\n");
2405 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2407 lo = b - maxmsgs + 2;
2409 wprintf("<option %s value="
2414 "%d-%d</option> \n",
2415 ((WC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2424 for (b=0; b<nummsgs; b = b + maxmsgs) {
2426 hi = b + maxmsgs + 1;
2427 if (hi > nummsgs) hi = nummsgs;
2428 wprintf("<option %s value="
2433 "%d-%d</option> \n",
2434 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2443 wprintf("<option value=\"%s?startmsg=%ld"
2444 "?maxmsgs=9999999?summary=%d\">"
2448 WC->msgarr[0], is_summary);
2450 wprintf("</select> ");
2451 wprintf(_("of %d messages."), nummsgs);
2453 /** forward/reverse */
2454 wprintf(" <select name=\"direction\" size=\"1\" "
2455 "OnChange=\"location.href=msgomatic.direction.options"
2456 "[selectedIndex].value\">\n"
2459 wprintf("<option %s value=\"%s?sortby=forward\">oldest to newest</option>\n",
2460 (bbs_reverse ? "" : "selected"),
2464 wprintf("<option %s value=\"%s?sortby=reverse\">newest to oldest</option>\n",
2465 (bbs_reverse ? "selected" : ""),
2469 wprintf("</select></form>\n");
2470 /** end bbview scroller */
2475 do_tasks_view(); /** Render the task list */
2479 do_calendar_view(); /** Render the calendar */
2482 if (is_addressbook) {
2483 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2486 /** Note: wDumpContent() will output one additional </div> tag. */
2488 if (addrbook != NULL) free(addrbook);
2490 /** free the summary */
2491 if (WC->summ != NULL) {
2500 * \brief Back end for post_message()
2501 * ... this is where the actual message gets transmitted to the server.
2503 void post_mime_to_server(void) {
2505 int is_multipart = 0;
2507 struct wc_attachment *att;
2509 size_t encoded_length;
2511 /** RFC2045 requires this, and some clients look for it... */
2512 serv_puts("MIME-Version: 1.0");
2514 /** If there are attachments, we have to do multipart/mixed */
2515 if (WC->first_attachment != NULL) {
2520 sprintf(boundary, "=_Citadel_Multipart_%s_%04x%04x",
2521 serv_info.serv_fqdn,
2526 /** Remember, serv_printf() appends an extra newline */
2527 serv_printf("Content-type: multipart/mixed; "
2528 "boundary=\"%s\"\n", boundary);
2529 serv_printf("This is a multipart message in MIME format.\n");
2530 serv_printf("--%s", boundary);
2533 serv_puts("Content-type: text/html; charset=utf-8");
2534 serv_puts("Content-Transfer-Encoding: quoted-printable");
2536 serv_puts("<html><body>\r\n");
2537 text_to_server_qp(bstr("msgtext")); /** Transmit message in quoted-printable encoding */
2538 serv_puts("</body></html>\r\n");
2542 /** Add in the attachments */
2543 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2545 encoded_length = ((att->length * 150) / 100);
2546 encoded = malloc(encoded_length);
2547 if (encoded == NULL) break;
2548 CtdlEncodeBase64(encoded, att->data, att->length);
2550 serv_printf("--%s", boundary);
2551 serv_printf("Content-type: %s", att->content_type);
2552 serv_printf("Content-disposition: attachment; "
2553 "filename=\"%s\"", att->filename);
2554 serv_puts("Content-transfer-encoding: base64");
2556 serv_write(encoded, strlen(encoded));
2561 serv_printf("--%s--", boundary);
2569 * \brief Post message (or don't post message)
2571 * Note regarding the "dont_post" variable:
2572 * A random value (actually, it's just a timestamp) is inserted as a hidden
2573 * field called "postseq" when the display_enter page is generated. This
2574 * value is checked when posting, using the static variable dont_post. If a
2575 * user attempts to post twice using the same dont_post value, the message is
2576 * discarded. This prevents the accidental double-saving of the same message
2577 * if the user happens to click the browser "back" button.
2579 void post_message(void)
2582 static long dont_post = (-1L);
2583 struct wc_attachment *att, *aptr;
2584 int is_anonymous = 0;
2586 if (!strcasecmp(bstr("is_anonymous"), "yes")) {
2590 if (WC->upload_length > 0) {
2592 /** There's an attachment. Save it to this struct... */
2593 att = malloc(sizeof(struct wc_attachment));
2594 memset(att, 0, sizeof(struct wc_attachment));
2595 att->length = WC->upload_length;
2596 strcpy(att->content_type, WC->upload_content_type);
2597 strcpy(att->filename, WC->upload_filename);
2600 /** And add it to the list. */
2601 if (WC->first_attachment == NULL) {
2602 WC->first_attachment = att;
2605 aptr = WC->first_attachment;
2606 while (aptr->next != NULL) aptr = aptr->next;
2611 * Mozilla sends a simple filename, which is what we want,
2612 * but Satan's Browser sends an entire pathname. Reduce
2613 * the path to just a filename if we need to.
2615 while (num_tokens(att->filename, '/') > 1) {
2616 remove_token(att->filename, 0, '/');
2618 while (num_tokens(att->filename, '\\') > 1) {
2619 remove_token(att->filename, 0, '\\');
2623 * Transfer control of this memory from the upload struct
2624 * to the attachment struct.
2626 att->data = WC->upload;
2627 WC->upload_length = 0;
2633 if (strlen(bstr("cancel_button")) > 0) {
2634 sprintf(WC->ImportantMessage,
2635 _("Cancelled. Message was not posted."));
2636 } else if (strlen(bstr("attach_button")) > 0) {
2639 } else if (atol(bstr("postseq")) == dont_post) {
2640 sprintf(WC->ImportantMessage,
2641 _("Automatically cancelled because you have already "
2642 "saved this message."));
2644 sprintf(buf, "ENT0 1|%s|%d|4|%s|||%s|%s|%s",
2653 serv_getln(buf, sizeof buf);
2654 if (buf[0] == '4') {
2655 post_mime_to_server();
2656 if ( (strlen(bstr("recp")) > 0)
2657 || (strlen(bstr("cc")) > 0)
2658 || (strlen(bstr("bcc")) > 0)
2660 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2663 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2665 dont_post = atol(bstr("postseq"));
2667 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2673 free_attachments(WC);
2676 * We may have been supplied with instructions regarding the location
2677 * to which we must return after posting. If found, go there.
2679 if (strlen(bstr("return_to")) > 0) {
2680 http_redirect(bstr("return_to"));
2683 * If we were editing a page in a wiki room, go to that page now.
2685 else if (strlen(bstr("wikipage")) > 0) {
2686 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
2690 * Otherwise, just go to the "read messages" loop.
2693 readloop("readnew");
2701 * \brief display the message entry screen
2703 void display_enter(void)
2708 struct wc_attachment *att;
2709 int recipient_required = 0;
2710 int recipient_bad = 0;
2712 int is_anonymous = 0;
2713 long existing_page = (-1L);
2715 if (strlen(bstr("force_room")) > 0) {
2716 gotoroom(bstr("force_room"));
2719 if (!strcasecmp(bstr("is_anonymous"), "yes")) {
2724 * Are we perhaps in an address book view? If so, then an "enter
2725 * message" command really means "add new entry."
2727 if (WC->wc_default_view == VIEW_ADDRESSBOOK) {
2728 do_edit_vcard(-1, "", "");
2732 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
2734 * Are we perhaps in a calendar room? If so, then an "enter
2735 * message" command really means "add new calendar item."
2737 if (WC->wc_default_view == VIEW_CALENDAR) {
2738 display_edit_event();
2743 * Are we perhaps in a tasks view? If so, then an "enter
2744 * message" command really means "add new task."
2746 if (WC->wc_default_view == VIEW_TASKS) {
2747 display_edit_task();
2753 * Otherwise proceed normally.
2754 * Do a custom room banner with no navbar...
2756 output_headers(1, 1, 2, 0, 0, 0);
2757 wprintf("<div id=\"banner\">\n");
2758 embed_room_banner(NULL, navbar_none);
2759 wprintf("</div>\n");
2760 wprintf("<div id=\"content\">\n"
2761 "<div class=\"fix_scrollbar_bug\">"
2762 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
2764 /** First test to see whether this is a room that requires recipients to be entered */
2765 serv_puts("ENT0 0");
2766 serv_getln(buf, sizeof buf);
2767 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
2768 recipient_required = 1;
2770 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2771 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2775 /** Now check our actual recipients if there are any */
2776 if (recipient_required) {
2777 sprintf(buf, "ENT0 0|%s|%d|0||||%s|%s|%s", bstr("recp"), is_anonymous,
2778 bstr("cc"), bstr("bcc"), bstr("wikipage"));
2780 serv_getln(buf, sizeof buf);
2782 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
2783 if (strlen(bstr("recp")) + strlen(bstr("cc")) + strlen(bstr("bcc")) > 0) {
2787 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2788 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2793 /** If we got this far, we can display the message entry screen. */
2796 fmt_date(buf, now, 0);
2797 strcat(&buf[strlen(buf)], _(" <I>from</I> "));
2798 stresc(&buf[strlen(buf)], WC->wc_fullname, 1, 1);
2800 /* Don't need this anymore, it's in the input box below
2801 if (strlen(bstr("recp")) > 0) {
2802 strcat(&buf[strlen(buf)], _(" <I>to</I> "));
2803 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
2807 strcat(&buf[strlen(buf)], _(" <I>in</I> "));
2808 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
2810 /** begin message entry screen */
2812 "enctype=\"multipart/form-data\" "
2814 "accept-charset=\"UTF-8\" "
2816 "name=\"enterform\""
2818 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2819 if (WC->wc_view == VIEW_WIKI) {
2820 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
2822 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
2824 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2825 wprintf("%s\n", buf); /** header bar */
2826 if (WC->room_flags & QR_ANONOPT) {
2828 "<input type=\"checkbox\" name=\"is_anonymous\" value=\"yes\" %s>",
2829 (is_anonymous ? "checked" : "")
2831 wprintf("Anonymous");
2833 wprintf("<br>\n"); /** header bar */
2835 wprintf("<table border=\"0\" width=\"100%%\">\n");
2836 if (recipient_required) {
2838 wprintf("<tr><td>");
2839 wprintf("<font size=-1>");
2843 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
2844 escputs(bstr("recp"));
2845 wprintf("\" size=50 maxlength=1000 />");
2846 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
2847 wprintf("</td><td></td></tr>\n");
2849 wprintf("<tr><td>");
2850 wprintf("<font size=-1>");
2854 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
2855 escputs(bstr("cc"));
2856 wprintf("\" size=50 maxlength=1000 />");
2857 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
2858 wprintf("</td><td></td></tr>\n");
2860 wprintf("<tr><td>");
2861 wprintf("<font size=-1>");
2865 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
2866 escputs(bstr("bcc"));
2867 wprintf("\" size=50 maxlength=1000 />");
2868 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
2869 wprintf("</td><td></td></tr>\n");
2871 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
2872 wprintf("<script type=\"text/javascript\"> \n"
2873 " activate_entmsg_autocompleters(); \n"
2878 wprintf("<tr><td>");
2879 wprintf("<font size=-1>");
2880 wprintf(_("Subject (optional):"));
2883 "<input type=\"text\" name=\"subject\" value=\"");
2884 escputs(bstr("subject"));
2885 wprintf("\" size=50 maxlength=70></td><td>\n");
2887 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2888 if (recipient_required) {
2889 wprintf(_("Send message"));
2891 wprintf(_("Post message"));
2894 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2895 wprintf("</td></tr></table>\n");
2897 wprintf("<center>");
2899 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
2901 /** If we're continuing from a previous edit, put our partially-composed message back... */
2902 msgescputs(bstr("msgtext"));
2904 /* If we're forwarding a message, insert it here... */
2905 if (atol(bstr("fwdquote")) > 0L) {
2906 wprintf("<br><div align=center><i>");
2907 wprintf(_("--- forwarded message ---"));
2908 wprintf("</i></div><br>");
2909 pullquote_message(atol(bstr("fwdquote")), 1, 1);
2912 /** If we're replying quoted, insert the quote here... */
2913 else if (atol(bstr("replyquote")) > 0L) {
2916 pullquote_message(atol(bstr("replyquote")), 0, 1);
2917 wprintf("</blockquote>\n\n");
2920 /** If we're editing a wiki page, insert the existing page here... */
2921 else if (WC->wc_view == VIEW_WIKI) {
2922 safestrncpy(buf, bstr("wikipage"), sizeof buf);
2923 str_wiki_index(buf);
2924 existing_page = locate_message_by_uid(buf);
2925 if (existing_page >= 0L) {
2926 pullquote_message(existing_page, 1, 0);
2930 /** Insert our signature if appropriate... */
2931 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
2932 get_preference("use_sig", buf, sizeof buf);
2933 if (!strcasecmp(buf, "yes")) {
2934 get_preference("signature", ebuf, sizeof ebuf);
2935 euid_unescapize(buf, ebuf);
2936 wprintf("<br>--<br>");
2937 for (i=0; i<strlen(buf); ++i) {
2938 if (buf[i] == '\n') {
2941 else if (buf[i] == '<') {
2944 else if (buf[i] == '>') {
2947 else if (buf[i] == '&') {
2950 else if (buf[i] == '\"') {
2953 else if (buf[i] == '\'') {
2956 else if (isprint(buf[i])) {
2957 wprintf("%c", buf[i]);
2963 wprintf("</textarea>");
2964 wprintf("</center><br />\n");
2967 * The following script embeds the TinyMCE richedit control, and automatically
2968 * transforms the textarea into a richedit textarea.
2971 "<script language=\"javascript\" type=\"text/javascript\" src=\"tiny_mce/tiny_mce.js\"></script>\n"
2972 "<script language=\"javascript\" type=\"text/javascript\">"
2974 " mode : \"textareas\", width : \"100%%\", browsers : \"msie,gecko\", "
2975 " theme : \"advanced\", plugins : \"iespell\", "
2976 " theme_advanced_buttons1 : \"bold, italic, underline, strikethrough, justifyleft, justifycenter, justifyright, justifyfull, bullist, numlist, cut, copy, paste, link, image, help, forecolor, iespell, code\", "
2977 " theme_advanced_buttons2 : \"\", "
2978 " theme_advanced_buttons3 : \"\" "
2984 /** Enumerate any attachments which are already in place... */
2985 wprintf("<img src=\"static/diskette_24x.gif\" border=0 "
2986 "align=middle height=16 width=16> ");
2987 wprintf(_("Attachments:"));
2989 wprintf("<select name=\"which_attachment\" size=1>");
2990 for (att = WC->first_attachment; att != NULL; att = att->next) {
2991 wprintf("<option value=\"");
2992 urlescputs(att->filename);
2994 escputs(att->filename);
2995 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
2996 wprintf("</option>\n");
2998 wprintf("</select>");
3000 /** Now offer the ability to attach additional files... */
3001 wprintf(" ");
3002 wprintf(_("Attach file:"));
3003 wprintf(" <input NAME=\"attachfile\" "
3004 "SIZE=16 TYPE=\"file\">\n "
3005 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3007 /** Seth asked for these to be at the top *and* bottom... */
3008 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3009 if (recipient_required) {
3010 wprintf(_("Send message"));
3012 wprintf(_("Post message"));
3015 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3017 /** Make sure we only insert our signature once */
3018 if (strcmp(bstr("sig_inserted"), "yes")) {
3019 wprintf("<INPUT TYPE=\"hidden\" NAME=\"sig_inserted\" VALUE=\"yes\">\n");
3022 wprintf("</form>\n");
3024 wprintf("</td></tr></table></div>\n");
3025 DONE: wDumpContent(1);
3031 * \brief delete a message
3033 void delete_msg(void)
3038 msgid = atol(bstr("msgid"));
3040 output_headers(1, 1, 1, 0, 0, 0);
3042 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3043 serv_printf("DELE %ld", msgid);
3045 else { /** Otherwise move it to Trash */
3046 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3049 serv_getln(buf, sizeof buf);
3050 wprintf("<EM>%s</EM><br />\n", &buf[4]);
3059 * \brief Confirm move of a message
3061 void confirm_move_msg(void)
3067 msgid = atol(bstr("msgid"));
3070 output_headers(1, 1, 2, 0, 0, 0);
3071 wprintf("<div id=\"banner\">\n");
3072 wprintf("<TABLE WIDTH=100%% BORDER=0><TR><TD>");
3073 wprintf("<SPAN CLASS=\"titlebar\">");
3074 wprintf(_("Confirm move of message"));
3075 wprintf("</SPAN>\n");
3076 wprintf("</TD></TR></TABLE>\n");
3077 wprintf("</div>\n<div id=\"content\">\n");
3079 wprintf("<CENTER>");
3081 wprintf(_("Move this message to:"));
3082 wprintf("<br />\n");
3084 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3085 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3087 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3089 serv_getln(buf, sizeof buf);
3090 if (buf[0] == '1') {
3091 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3092 extract_token(targ, buf, 0, '|', sizeof targ);
3093 wprintf("<OPTION>");
3098 wprintf("</SELECT>\n");
3099 wprintf("<br />\n");
3101 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3103 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3104 wprintf("</form></CENTER>\n");
3106 wprintf("</CENTER>\n");
3112 * \brief move a message to another folder
3119 msgid = atol(bstr("msgid"));
3121 if (strlen(bstr("move_button")) > 0) {
3122 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3124 serv_getln(buf, sizeof buf);
3125 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3127 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3130 readloop("readnew");