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 */
137 if (istr[pos] == '_') istr[pos] = ' ';
141 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, len);
144 strcpy(ibuf, istr); /**< unknown encoding */
145 ibuflen = strlen(istr);
148 ic = ctdl_iconv_open("UTF-8", charset);
149 if (ic != (iconv_t)(-1) ) {
151 obuf = (char *) malloc(obuflen);
153 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
154 osav[1024-obuflen] = 0;
159 remove_token(end, 0, '?');
160 remove_token(end, 0, '?');
161 remove_token(end, 0, '?');
162 remove_token(end, 0, '?');
163 strcpy(end, &end[1]);
165 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
174 remove_token(end, 0, '?');
175 remove_token(end, 0, '?');
176 remove_token(end, 0, '?');
177 remove_token(end, 0, '?');
178 strcpy(end, &end[1]);
180 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
187 * Since spammers will go to all sorts of absurd lengths to get their
188 * messages through, there are LOTS of corrupt headers out there.
189 * So, prevent a really badly formed RFC2047 header from throwing
190 * this function into an infinite loop.
193 if (passes > 20) return;
203 * \brief RFC2047-encode a header field if necessary.
204 * If no non-ASCII characters are found, the string
205 * will be copied verbatim without encoding.
207 * \param target Target buffer.
208 * \param maxlen Maximum size of target buffer.
209 * \param source Source string to be encoded.
211 void rfc2047encode(char *target, int maxlen, char *source)
213 int need_to_encode = 0;
217 if (target == NULL) return;
219 for (i=0; i<strlen(source); ++i) {
220 if ((source[i] < 32) || (source[i] > 126)) {
225 if (!need_to_encode) {
226 safestrncpy(target, source, maxlen);
230 strcpy(target, "=?UTF-8?Q?");
231 for (i=0; i<strlen(source); ++i) {
232 ch = (unsigned char) source[i];
233 if ((ch < 32) || (ch > 126) || (ch == 61)) {
234 sprintf(&target[strlen(target)], "=%02X", ch);
237 sprintf(&target[strlen(target)], "%c", ch);
241 strcat(target, "?=");
248 * \brief Look for URL's embedded in a buffer and make them linkable. We use a
249 * target window in order to keep the BBS session in its own window.
250 * \param buf the message buffer
265 for (pos = 0; pos < strlen(buf); ++pos) {
266 if (!strncasecmp(&buf[pos], "http://", 7))
268 if (!strncasecmp(&buf[pos], "ftp://", 6))
275 if ((start > 0) && (buf[start - 1] == '<'))
277 if ((start > 0) && (buf[start - 1] == '['))
279 if ((start > 0) && (buf[start - 1] == '('))
281 if ((start > 0) && (buf[start - 1] == '{'))
284 for (pos = strlen(buf); pos > start; --pos) {
285 if ((buf[pos] == ' ') || (buf[pos] == ench))
289 strncpy(urlbuf, &buf[start], end - start);
290 urlbuf[end - start] = 0;
292 strncpy(outbuf, buf, start);
293 sprintf(&outbuf[start], "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
294 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
295 strcat(outbuf, &buf[end]);
296 if ( strlen(outbuf) < 250 )
302 * \brief Turn a vCard "n" (name) field into something displayable.
303 * \param name the name field to convert
305 void vcard_n_prettyize(char *name)
310 original_name = strdup(name);
311 for (i=0; i<5; ++i) {
312 if (strlen(original_name) > 0) {
313 if (original_name[strlen(original_name)-1] == ' ') {
314 original_name[strlen(original_name)-1] = 0;
316 if (original_name[strlen(original_name)-1] == ';') {
317 original_name[strlen(original_name)-1] = 0;
322 for (i=0; i<strlen(original_name); ++i) {
323 if (original_name[i] == ';') {
327 name[strlen(name)+1] = 0;
328 name[strlen(name)] = original_name[i];
338 * \brief preparse a vcard name
339 * display_vcard() calls this after parsing the textual vCard into
340 * our 'struct vCard' data object.
341 * This gets called instead of display_parsed_vcard() if we are only looking
342 * to extract the person's name instead of displaying the card.
343 * \param v the vcard to retrieve the name from
344 * \param storename where to put the name at
346 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
349 strcpy(storename, "");
351 name = vcard_get_prop(v, "n", 1, 0, 0);
353 strcpy(storename, name);
354 /* vcard_n_prettyize(storename); */
362 * \brief html print a vcard
363 * display_vcard() calls this after parsing the textual vCard into
364 * our 'struct vCard' data object.
366 * Set 'full' to nonzero to display the full card, otherwise it will only
367 * show a summary line.
369 * This code is a bit ugly, so perhaps an explanation is due: we do this
370 * in two passes through the vCard fields. On the first pass, we process
371 * fields we understand, and then render them in a pretty fashion at the
372 * end. Then we make a second pass, outputting all the fields we don't
373 * understand in a simple two-column name/value format.
374 * \param v the vCard to display
375 * \param full display all items of the vcard?
377 void display_parsed_vcard(struct vCard *v, int full) {
383 char *thisname, *thisvalue;
384 char firsttoken[SIZ];
393 strcpy(fullname, "");
401 name = vcard_get_prop(v, "fn", 1, 0, 0);
405 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
406 strcpy(fullname, name);
407 vcard_n_prettyize(fullname);
417 wprintf("<div align=center><table bgcolor=#aaaaaa width=50%%>");
418 for (pass=1; pass<=2; ++pass) {
420 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
422 thisname = strdup(v->prop[i].name);
423 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
425 for (j=0; j<num_tokens(thisname, ';'); ++j) {
426 extract_token(buf, thisname, j, ';', sizeof buf);
427 if (!strcasecmp(buf, "encoding=quoted-printable")) {
429 remove_token(thisname, j, ';');
431 if (!strcasecmp(buf, "encoding=base64")) {
433 remove_token(thisname, j, ';');
438 thisvalue = malloc(strlen(v->prop[i].value) + 50);
439 j = CtdlDecodeQuotedPrintable(
440 thisvalue, v->prop[i].value,
441 strlen(v->prop[i].value) );
445 thisvalue = malloc(strlen(v->prop[i].value) + 50);
447 thisvalue, v->prop[i].value,
448 strlen(v->prop[i].value) );
451 thisvalue = strdup(v->prop[i].value);
454 /** Various fields we may encounter ***/
456 /** N is name, but only if there's no FN already there */
457 if (!strcasecmp(firsttoken, "n")) {
458 if (strlen(fullname) == 0) {
459 strcpy(fullname, thisvalue);
460 vcard_n_prettyize(fullname);
464 /** FN (full name) is a true 'display name' field */
465 else if (!strcasecmp(firsttoken, "fn")) {
466 strcpy(fullname, thisvalue);
470 else if (!strcasecmp(firsttoken, "title")) {
471 strcpy(title, thisvalue);
475 else if (!strcasecmp(firsttoken, "org")) {
476 strcpy(org, thisvalue);
479 else if (!strcasecmp(firsttoken, "email")) {
480 if (strlen(mailto) > 0) strcat(mailto, "<br />");
482 "<a href=\"display_enter"
483 "?force_room=_MAIL_?recp=");
485 urlesc(&mailto[strlen(mailto)], fullname);
486 urlesc(&mailto[strlen(mailto)], " <");
487 urlesc(&mailto[strlen(mailto)], thisvalue);
488 urlesc(&mailto[strlen(mailto)], ">");
490 strcat(mailto, "\">");
491 stresc(&mailto[strlen(mailto)], thisvalue, 1, 1);
492 strcat(mailto, "</A>");
494 else if (!strcasecmp(firsttoken, "tel")) {
495 if (strlen(phone) > 0) strcat(phone, "<br />");
496 strcat(phone, thisvalue);
497 for (j=0; j<num_tokens(thisname, ';'); ++j) {
498 extract_token(buf, thisname, j, ';', sizeof buf);
499 if (!strcasecmp(buf, "tel"))
501 else if (!strcasecmp(buf, "work"))
502 strcat(phone, _(" (work)"));
503 else if (!strcasecmp(buf, "home"))
504 strcat(phone, _(" (home)"));
505 else if (!strcasecmp(buf, "cell"))
506 strcat(phone, _(" (cell)"));
514 else if (!strcasecmp(firsttoken, "adr")) {
517 wprintf(_("Address:"));
518 wprintf("</TD><TD>");
519 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
520 extract_token(buf, thisvalue, j, ';', sizeof buf);
521 if (strlen(buf) > 0) {
523 if (j<3) wprintf("<br />");
527 wprintf("</TD></TR>\n");
530 else if (!strcasecmp(firsttoken, "version")) {
533 else if (!strcasecmp(firsttoken, "rev")) {
536 else if (!strcasecmp(firsttoken, "label")) {
541 /*** Don't show extra fields. They're ugly.
545 wprintf("</TD><TD>");
547 wprintf("</TD></TR>\n");
557 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
558 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
559 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
560 "<FONT SIZE=+1><B>");
562 wprintf("</B></FONT>");
563 if (strlen(title) > 0) {
564 wprintf("<div align=right>");
568 if (strlen(org) > 0) {
569 wprintf("<div align=right>");
573 wprintf("</TD></TR>\n");
575 if (strlen(phone) > 0) {
577 wprintf(_("Telephone:"));
578 wprintf("</td><td>%s</td></tr>\n", phone);
580 if (strlen(mailto) > 0) {
582 wprintf(_("E-mail:"));
583 wprintf("</td><td>%s</td></tr>\n", mailto);
589 wprintf("</table></div>\n");
595 * \brief Display a textual vCard
596 * (Converts to a vCard object and then calls the actual display function)
597 * Set 'full' to nonzero to display the whole card instead of a one-liner.
598 * Or, if "storename" is non-NULL, just store the person's name in that
599 * buffer instead of displaying the card at all.
600 * \param vcard_source the buffer containing the vcard text
601 * \param alpha what???
602 * \param full should we usse all lines?
603 * \param storename where to store???
605 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
611 v = vcard_load(vcard_source);
612 if (v == NULL) return;
614 name = vcard_get_prop(v, "n", 1, 0, 0);
620 if (storename != NULL) {
621 fetchname_parsed_vcard(v, storename);
623 else if ( (alpha == 0)
624 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
625 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
627 display_parsed_vcard(v, full);
635 * \brief I wanna SEE that message!
636 * \param msgnum the citadel number of the message to display
637 * \param printable_view are we doing a print view?
638 * \param section Optional for encapsulated message/rfc822 submessage)
640 void read_message(long msgnum, int printable_view, char *section) {
642 char mime_partnum[256];
643 char mime_filename[256];
644 char mime_content_type[256];
645 char mime_charset[256];
646 char mime_disposition[256];
649 char mime_submessages[256];
656 char reply_all[4096];
662 char vcard_partnum[256];
663 char cal_partnum[256];
664 char *part_source = NULL;
666 iconv_t ic = (iconv_t)(-1) ;
667 char *ibuf; /**< Buffer of characters to be converted */
668 char *obuf; /**< Buffer for converted characters */
669 size_t ibuflen; /**< Length of input buffer */
670 size_t obuflen; /**< Length of output buffer */
671 char *osav; /**< Saved pointer to output buffer */
677 strcpy(reply_to, "");
678 strcpy(reply_all, "");
679 strcpy(vcard_partnum, "");
680 strcpy(cal_partnum, "");
681 strcpy(mime_http, "");
682 strcpy(mime_content_type, "text/plain");
683 strcpy(mime_charset, "us-ascii");
684 strcpy(mime_submessages, "");
686 serv_printf("MSG4 %ld|%s", msgnum, section);
687 serv_getln(buf, sizeof buf);
690 wprintf(_("ERROR:"));
691 wprintf("</STRONG> %s<br />\n", &buf[4]);
695 /** begin everythingamundo table */
696 if (!printable_view) {
697 wprintf("<div class=\"fix_scrollbar_bug\">\n");
698 wprintf("<table width=100%% border=1 cellspacing=0 "
699 "cellpadding=0><TR><TD>\n");
702 /** begin message header table */
703 wprintf("<table width=100%% border=0 cellspacing=0 "
704 "cellpadding=1 bgcolor=\"#CCCCCC\"><tr><td>\n");
706 wprintf("<span class=\"message_header\">");
707 strcpy(m_subject, "");
710 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
711 if (!strcmp(buf, "000")) {
713 wprintf(_("unexpected end of message"));
714 wprintf("</i><br /><br />\n");
715 wprintf("</span>\n");
718 if (!strncasecmp(buf, "nhdr=yes", 8))
722 if (!strncasecmp(buf, "type=", 5))
723 format_type = atoi(&buf[5]);
724 if (!strncasecmp(buf, "from=", 5)) {
725 strcpy(from, &buf[5]);
727 wprintf("<a href=\"showuser?who=");
729 utf8ify_rfc822_string(from);
736 if (!strncasecmp(buf, "subj=", 5)) {
737 safestrncpy(m_subject, &buf[5], sizeof m_subject);
739 if (!strncasecmp(buf, "cccc=", 5)) {
740 safestrncpy(m_cc, &buf[5], sizeof m_cc);
741 if (strlen(reply_all) > 0) {
742 strcat(reply_all, ", ");
744 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
745 (sizeof reply_all - strlen(reply_all)) );
747 if ((!strncasecmp(buf, "hnod=", 5))
748 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
749 wprintf("(%s) ", &buf[5]);
751 if ((!strncasecmp(buf, "room=", 5))
752 && (strcasecmp(&buf[5], WC->wc_roomname))
753 && (strlen(&buf[5])>0) ) {
755 wprintf("%s> ", &buf[5]);
757 if (!strncasecmp(buf, "rfca=", 5)) {
758 strcpy(rfca, &buf[5]);
764 if (!strncasecmp(buf, "node=", 5)) {
765 strcpy(node, &buf[5]);
766 if ( ((WC->room_flags & QR_NETWORK)
767 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
768 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
771 wprintf("@%s ", &buf[5]);
774 if (!strncasecmp(buf, "rcpt=", 5)) {
776 if (strlen(reply_all) > 0) {
777 strcat(reply_all, ", ");
779 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
780 (sizeof reply_all - strlen(reply_all)) );
782 utf8ify_rfc822_string(&buf[5]);
787 if (!strncasecmp(buf, "time=", 5)) {
788 fmt_date(now, atol(&buf[5]), 0);
792 if (!strncasecmp(buf, "part=", 5)) {
793 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
794 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
795 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
796 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
797 mime_length = extract_int(&buf[5], 5);
799 if (!strcasecmp(mime_content_type, "message/rfc822")) {
800 if (strlen(mime_submessages) > 0) {
801 strcat(mime_submessages, "|");
803 strcat(mime_submessages, mime_partnum);
805 else if ((!strcasecmp(mime_disposition, "inline"))
806 && (!strncasecmp(mime_content_type, "image/", 6)) ){
807 snprintf(&mime_http[strlen(mime_http)],
808 (sizeof(mime_http) - strlen(mime_http) - 1),
809 "<img src=\"mimepart/%ld/%s/%s\">",
810 msgnum, mime_partnum, mime_filename);
812 else if ( (!strcasecmp(mime_disposition, "attachment"))
813 || (!strcasecmp(mime_disposition, "inline")) ) {
814 snprintf(&mime_http[strlen(mime_http)],
815 (sizeof(mime_http) - strlen(mime_http) - 1),
816 "<img src=\"static/diskette_24x.gif\" "
817 "border=0 align=middle>\n"
818 "%s (%s, %d bytes) [ "
819 "<a href=\"mimepart/%ld/%s/%s\""
820 "target=\"wc.%ld.%s\">%s</a>"
822 "<a href=\"mimepart_download/%ld/%s/%s\">%s</a>"
825 mime_content_type, mime_length,
826 msgnum, mime_partnum, mime_filename,
827 msgnum, mime_partnum,
829 msgnum, mime_partnum, mime_filename,
834 /** begin handler prep ***/
835 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
836 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
837 strcpy(vcard_partnum, mime_partnum);
840 if (!strcasecmp(mime_content_type, "text/calendar")) {
841 strcpy(cal_partnum, mime_partnum);
844 /** end handler prep ***/
850 /** Generate a reply-to address */
851 if (strlen(rfca) > 0) {
852 strcpy(reply_to, rfca);
855 if ( (strlen(node) > 0)
856 && (strcasecmp(node, serv_info.serv_nodename))
857 && (strcasecmp(node, serv_info.serv_humannode)) ) {
858 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
862 snprintf(reply_to, sizeof(reply_to), "%s", from);
872 utf8ify_rfc822_string(m_cc);
873 utf8ify_rfc822_string(m_subject);
875 if (strlen(m_cc) > 0) {
877 "<span class=\"message_subject\">");
883 if (strlen(m_subject) > 0) {
885 "<span class=\"message_subject\">");
886 wprintf(_("Subject:"));
893 /** start msg buttons */
894 if (!printable_view) {
895 wprintf("<td align=right><span class=\"msgbuttons\">\n");
898 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
899 wprintf("<a href=\"display_enter");
900 if (WC->is_mailbox) {
901 wprintf("?replyquote=%ld", msgnum);
904 urlescputs(reply_to);
905 if (strlen(m_subject) > 0) {
906 wprintf("?subject=");
907 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
908 urlescputs(m_subject);
910 wprintf("\">[%s]</a> ", _("Reply"));
914 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
915 if (!WC->is_mailbox) {
916 wprintf("<a href=\"display_enter");
917 wprintf("?replyquote=%ld", msgnum);
919 urlescputs(reply_to);
920 if (strlen(m_subject) > 0) {
921 wprintf("?subject=");
922 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
923 urlescputs(m_subject);
925 wprintf("\">[%s]</a> ", _("ReplyQuoted"));
930 if (WC->wc_view == VIEW_MAILBOX) {
931 wprintf("<a href=\"display_enter");
932 wprintf("?replyquote=%ld", msgnum);
934 urlescputs(reply_to);
936 urlescputs(reply_all);
937 if (strlen(m_subject) > 0) {
938 wprintf("?subject=");
939 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
940 urlescputs(m_subject);
942 wprintf("\">[%s]</a> ", _("ReplyAll"));
946 if (WC->wc_view == VIEW_MAILBOX) {
947 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
948 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
949 urlescputs(m_subject);
950 wprintf("\">[%s]</a> ", _("Forward"));
953 /** If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
954 if ( (WC->is_room_aide) || (WC->is_mailbox) ) {
956 wprintf("<a href=\"confirm_move_msg?msgid=%ld\">[%s]</a> ",
960 wprintf("<a href=\"delete_msg?msgid=%ld\" "
961 "onClick=\"return confirm('%s');\">"
962 "[%s]</a> ", msgnum, _("Delete this message?"), _("Delete")
967 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'); \" >"
968 "[%s]</a>", msgnum, msgnum, _("Headers"));
972 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'); \" >"
973 "[%s]</a>", msgnum, msgnum, _("Print"));
975 wprintf("</span></td>");
978 wprintf("</tr></table>\n");
981 wprintf("<table class=\"messages_background\" "
982 "cellpadding=1 cellspacing=0><tr><td>");
985 * Learn the content type
987 strcpy(mime_content_type, "text/plain");
988 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
989 if (!strcmp(buf, "000")) {
991 wprintf(_("unexpected end of message"));
992 wprintf("</i><br /><br />\n");
995 if (!strncasecmp(buf, "Content-type: ", 14)) {
996 safestrncpy(mime_content_type, &buf[14],
997 sizeof(mime_content_type));
998 for (i=0; i<strlen(mime_content_type); ++i) {
999 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1000 safestrncpy(mime_charset, &mime_content_type[i+8],
1001 sizeof mime_charset);
1004 for (i=0; i<strlen(mime_content_type); ++i) {
1005 if (mime_content_type[i] == ';') {
1006 mime_content_type[i] = 0;
1009 for (i=0; i<strlen(mime_charset); ++i) {
1010 if (mime_charset[i] == ';') {
1011 mime_charset[i] = 0;
1017 /** Set up a character set conversion if we need to (and if we can) */
1019 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
1020 if ( (strcasecmp(mime_charset, "us-ascii"))
1021 && (strcasecmp(mime_charset, "UTF-8"))
1022 && (strcasecmp(mime_charset, ""))
1024 ic = ctdl_iconv_open("UTF-8", mime_charset);
1025 if (ic == (iconv_t)(-1) ) {
1026 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1027 __FILE__, __LINE__, mime_charset, strerror(errno));
1032 /** Messages in legacy Citadel variformat get handled thusly... */
1033 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1037 /** Boring old 80-column fixed format text gets handled this way... */
1038 else if ( (!strcasecmp(mime_content_type, "text/plain"))
1039 || (!strcasecmp(mime_content_type, "text")) ) {
1040 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1041 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1042 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1045 if (ic != (iconv_t)(-1) ) {
1047 ibuflen = strlen(ibuf);
1049 obuf = (char *) malloc(obuflen);
1051 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1052 osav[SIZ-obuflen] = 0;
1053 safestrncpy(buf, osav, sizeof buf);
1058 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1059 buf[strlen(buf) - 1] = 0;
1061 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1062 wprintf("<blockquote>");
1064 } else if ((bq == 1) &&
1065 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1066 wprintf("</blockquote>");
1072 wprintf("</tt><br />\n");
1074 wprintf("</i><br />");
1077 else /** HTML is fun, but we've got to strip it first */
1078 if (!strcasecmp(mime_content_type, "text/html")) {
1079 output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
1082 /** Unknown weirdness */
1084 wprintf(_("I don't know how to display %s"), mime_content_type);
1085 wprintf("<br />\n", mime_content_type);
1086 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1089 /** If there are attached submessages, display them now... */
1090 if ( (strlen(mime_submessages) > 0) && (!section[0]) ) {
1091 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1092 extract_token(buf, mime_submessages, i, '|', sizeof buf);
1093 /** use printable_view to suppress buttons */
1094 wprintf("<blockquote>");
1095 read_message(msgnum, 1, buf);
1096 wprintf("</blockquote>");
1101 /** Afterwards, offer links to download attachments 'n' such */
1102 if ( (strlen(mime_http) > 0) && (!section[0]) ) {
1103 wprintf("%s", mime_http);
1106 /** Handler for vCard parts */
1107 if (strlen(vcard_partnum) > 0) {
1108 part_source = load_mimepart(msgnum, vcard_partnum);
1109 if (part_source != NULL) {
1111 /** If it's my vCard I can edit it */
1112 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1113 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1114 || (WC->wc_view == VIEW_ADDRESSBOOK)
1116 wprintf("<a href=\"edit_vcard?"
1117 "msgnum=%ld?partnum=%s\">",
1118 msgnum, vcard_partnum);
1119 wprintf("[%s]</a>", _("edit"));
1122 /** In all cases, display the full card */
1123 display_vcard(part_source, 0, 1, NULL);
1127 /** Handler for calendar parts */
1128 if (strlen(cal_partnum) > 0) {
1129 part_source = load_mimepart(msgnum, cal_partnum);
1130 if (part_source != NULL) {
1131 cal_process_attachment(part_source,
1132 msgnum, cal_partnum);
1142 wprintf("</td></tr></table>\n");
1144 /** end everythingamundo table */
1145 if (!printable_view) {
1146 wprintf("</td></tr></table>\n");
1147 wprintf("</div><br />\n");
1151 if (ic != (iconv_t)(-1) ) {
1160 * \brief Unadorned HTML output of an individual message, suitable
1161 * for placing in a hidden iframe, for printing, or whatever
1163 * \param msgnum_as_string Message number, as a string instead of as a long int
1165 void embed_message(char *msgnum_as_string) {
1168 msgnum = atol(msgnum_as_string);
1169 begin_ajax_response();
1170 read_message(msgnum, 0, "");
1171 end_ajax_response();
1176 * \brief Printable view of a message
1178 * \param msgnum_as_string Message number, as a string instead of as a long int
1180 void print_message(char *msgnum_as_string) {
1183 msgnum = atol(msgnum_as_string);
1184 output_headers(0, 0, 0, 0, 0, 0);
1186 wprintf("Content-type: text/html\r\n"
1188 "Connection: close\r\n",
1192 wprintf("\r\n\r\n<html>\n"
1193 "<head><title>Printable view</title></head>\n"
1194 "<body onLoad=\" window.print(); window.close(); \">\n"
1197 read_message(msgnum, 1, "");
1199 wprintf("\n</body></html>\n\n");
1206 * \brief Display a message's headers
1208 * \param msgnum_as_string Message number, as a string instead of as a long int
1210 void display_headers(char *msgnum_as_string) {
1214 msgnum = atol(msgnum_as_string);
1215 output_headers(0, 0, 0, 0, 0, 0);
1217 wprintf("Content-type: text/plain\r\n"
1219 "Connection: close\r\n",
1223 serv_printf("MSG2 %ld|3", msgnum);
1224 serv_getln(buf, sizeof buf);
1225 if (buf[0] == '1') {
1226 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1227 wprintf("%s\n", buf);
1237 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1238 * or 'reply quoted' operations.
1240 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1241 * in this function. Doing so would throw a JavaScript error in the
1242 * 'supplied text' argument to the editor.
1244 * \param msgnum Message number of the message we want to quote
1245 * \param forward_attachments Nonzero if we want attachments to be forwarded
1247 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1249 char mime_partnum[256];
1250 char mime_filename[256];
1251 char mime_content_type[256];
1252 char mime_charset[256];
1253 char mime_disposition[256];
1255 char *attachments = NULL;
1257 int num_attachments = 0;
1258 struct wc_attachment *att, *aptr;
1259 char m_subject[256];
1265 int format_type = 0;
1270 iconv_t ic = (iconv_t)(-1) ;
1271 char *ibuf; /**< Buffer of characters to be converted */
1272 char *obuf; /**< Buffer for converted characters */
1273 size_t ibuflen; /**< Length of input buffer */
1274 size_t obuflen; /**< Length of output buffer */
1275 char *osav; /**< Saved pointer to output buffer */
1281 strcpy(reply_to, "");
1282 strcpy(mime_content_type, "text/plain");
1283 strcpy(mime_charset, "us-ascii");
1285 serv_printf("MSG4 %ld", msgnum);
1286 serv_getln(buf, sizeof buf);
1287 if (buf[0] != '1') {
1288 wprintf(_("ERROR:"));
1289 wprintf("%s<br />", &buf[4]);
1293 strcpy(m_subject, "");
1295 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1296 if (!strcmp(buf, "000")) {
1297 wprintf(_("unexpected end of message"));
1300 if (include_headers) {
1301 if (!strncasecmp(buf, "nhdr=yes", 8))
1305 if (!strncasecmp(buf, "type=", 5))
1306 format_type = atoi(&buf[5]);
1307 if (!strncasecmp(buf, "from=", 5)) {
1308 strcpy(from, &buf[5]);
1309 wprintf(_("from "));
1311 utf8ify_rfc822_string(from);
1315 if (!strncasecmp(buf, "subj=", 5)) {
1316 strcpy(m_subject, &buf[5]);
1318 if ((!strncasecmp(buf, "hnod=", 5))
1319 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1320 wprintf("(%s) ", &buf[5]);
1322 if ((!strncasecmp(buf, "room=", 5))
1323 && (strcasecmp(&buf[5], WC->wc_roomname))
1324 && (strlen(&buf[5])>0) ) {
1326 wprintf("%s> ", &buf[5]);
1328 if (!strncasecmp(buf, "rfca=", 5)) {
1329 strcpy(rfca, &buf[5]);
1335 if (!strncasecmp(buf, "node=", 5)) {
1336 strcpy(node, &buf[5]);
1337 if ( ((WC->room_flags & QR_NETWORK)
1338 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1339 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1340 && (strlen(rfca)==0)
1342 wprintf("@%s ", &buf[5]);
1345 if (!strncasecmp(buf, "rcpt=", 5)) {
1347 wprintf("%s ", &buf[5]);
1349 if (!strncasecmp(buf, "time=", 5)) {
1350 fmt_date(now, atol(&buf[5]), 0);
1351 wprintf("%s ", now);
1356 * Save attachment info for later. We can't start downloading them
1357 * yet because we're in the middle of a server transaction.
1359 if (!strncasecmp(buf, "part=", 5)) {
1360 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1363 sprintf(ptr, "%s%s\n",
1364 ((attachments != NULL) ? attachments : ""),
1369 lprintf(9, "attachments=<%s>\n", attachments);
1375 if (include_headers) {
1379 utf8ify_rfc822_string(m_subject);
1381 if (strlen(m_subject) > 0) {
1382 wprintf(_("Subject:"));
1384 msgescputs(m_subject);
1395 * Learn the content type
1397 strcpy(mime_content_type, "text/plain");
1398 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1399 if (!strcmp(buf, "000")) {
1400 wprintf(_("unexpected end of message"));
1403 if (!strncasecmp(buf, "Content-type: ", 14)) {
1404 safestrncpy(mime_content_type, &buf[14],
1405 sizeof(mime_content_type));
1406 for (i=0; i<strlen(mime_content_type); ++i) {
1407 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1408 safestrncpy(mime_charset, &mime_content_type[i+8],
1409 sizeof mime_charset);
1412 for (i=0; i<strlen(mime_content_type); ++i) {
1413 if (mime_content_type[i] == ';') {
1414 mime_content_type[i] = 0;
1417 for (i=0; i<strlen(mime_charset); ++i) {
1418 if (mime_charset[i] == ';') {
1419 mime_charset[i] = 0;
1425 /** Set up a character set conversion if we need to (and if we can) */
1427 if ( (strcasecmp(mime_charset, "us-ascii"))
1428 && (strcasecmp(mime_charset, "UTF-8"))
1429 && (strcasecmp(mime_charset, ""))
1431 ic = ctdl_iconv_open("UTF-8", mime_charset);
1432 if (ic == (iconv_t)(-1) ) {
1433 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1434 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1439 /** Messages in legacy Citadel variformat get handled thusly... */
1440 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1444 /* Boring old 80-column fixed format text gets handled this way... */
1445 else if (!strcasecmp(mime_content_type, "text/plain")) {
1446 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1447 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1448 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1451 if (ic != (iconv_t)(-1) ) {
1453 ibuflen = strlen(ibuf);
1455 obuf = (char *) malloc(obuflen);
1457 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1458 osav[SIZ-obuflen] = 0;
1459 safestrncpy(buf, osav, sizeof buf);
1464 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1465 buf[strlen(buf) - 1] = 0;
1467 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1468 wprintf("<blockquote>");
1470 } else if ((bq == 1) &&
1471 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1472 wprintf("</blockquote>");
1478 wprintf("</tt><br />");
1480 wprintf("</i><br />");
1483 /** HTML just gets escaped and stuffed back into the editor */
1484 else if (!strcasecmp(mime_content_type, "text/html")) {
1485 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1491 /** Unknown weirdness ... don't know how to handle this content type */
1493 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1497 /** end of body handler */
1500 * If there were attachments, we have to download them and insert them
1501 * into the attachment chain for the forwarded message we are composing.
1503 if ( (forward_attachments) && (num_attachments) ) {
1504 for (i=0; i<num_attachments; ++i) {
1505 extract_token(buf, attachments, i, '\n', sizeof buf);
1506 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1507 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1508 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1509 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1510 mime_length = extract_int(buf, 5);
1513 * tracing ... uncomment if necessary
1516 lprintf(9, "fwd filename: %s\n", mime_filename);
1517 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1518 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1519 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1520 lprintf(9, "fwd length : %d\n", mime_length);
1522 if ( (!strcasecmp(mime_disposition, "inline"))
1523 || (!strcasecmp(mime_disposition, "attachment")) ) {
1525 /* Create an attachment struct from this mime part... */
1526 att = malloc(sizeof(struct wc_attachment));
1527 memset(att, 0, sizeof(struct wc_attachment));
1528 att->length = mime_length;
1529 strcpy(att->content_type, mime_content_type);
1530 strcpy(att->filename, mime_filename);
1532 att->data = load_mimepart(msgnum, mime_partnum);
1534 /* And add it to the list. */
1535 if (WC->first_attachment == NULL) {
1536 WC->first_attachment = att;
1539 aptr = WC->first_attachment;
1540 while (aptr->next != NULL) aptr = aptr->next;
1549 if (ic != (iconv_t)(-1) ) {
1554 if (attachments != NULL) {
1560 * \brief Display one row in the mailbox summary view
1562 * \param num The row number to be displayed
1564 void display_summarized(int num) {
1567 wprintf("<tr id=\"m%ld\" style=\"width:100%%;font-weight:%s;background-color:#ffffff\" "
1568 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1569 WC->summ[num].msgnum,
1570 (WC->summ[num].is_new ? "bold" : "normal"),
1571 WC->summ[num].msgnum
1574 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1575 escputs(WC->summ[num].subj);
1578 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1579 escputs(WC->summ[num].from);
1582 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1583 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1593 * \brief display the adressbook overview
1594 * \param msgnum the citadel message number
1595 * \param alpha what????
1597 void display_addressbook(long msgnum, char alpha) {
1599 char mime_partnum[SIZ];
1600 char mime_filename[SIZ];
1601 char mime_content_type[SIZ];
1602 char mime_disposition[SIZ];
1604 char vcard_partnum[SIZ];
1605 char *vcard_source = NULL;
1606 struct message_summary summ;
1608 memset(&summ, 0, sizeof(summ));
1609 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1611 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1613 serv_getln(buf, sizeof buf);
1614 if (buf[0] != '1') return;
1616 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1617 if (!strncasecmp(buf, "part=", 5)) {
1618 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1619 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1620 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1621 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1622 mime_length = extract_int(&buf[5], 5);
1624 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1625 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1626 strcpy(vcard_partnum, mime_partnum);
1632 if (strlen(vcard_partnum) > 0) {
1633 vcard_source = load_mimepart(msgnum, vcard_partnum);
1634 if (vcard_source != NULL) {
1636 /** Display the summary line */
1637 display_vcard(vcard_source, alpha, 0, NULL);
1639 /** If it's my vCard I can edit it */
1640 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1641 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1642 || (WC->wc_view == VIEW_ADDRESSBOOK)
1644 wprintf("<a href=\"edit_vcard?"
1645 "msgnum=%ld?partnum=%s\">",
1646 msgnum, vcard_partnum);
1647 wprintf("[%s]</a>", _("edit"));
1659 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1660 * \param namebuf name to analyze, reverse if nescessary
1662 void lastfirst_firstlast(char *namebuf) {
1663 char firstname[SIZ];
1667 if (namebuf == NULL) return;
1668 if (strchr(namebuf, ';') != NULL) return;
1670 i = num_tokens(namebuf, ' ');
1673 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1674 remove_token(namebuf, i-1, ' ');
1675 strcpy(firstname, namebuf);
1676 sprintf(namebuf, "%s; %s", lastname, firstname);
1680 * \brief fetch what??? name
1681 * \param msgnum the citadel message number
1682 * \param namebuf where to put the name in???
1684 void fetch_ab_name(long msgnum, char *namebuf) {
1686 char mime_partnum[SIZ];
1687 char mime_filename[SIZ];
1688 char mime_content_type[SIZ];
1689 char mime_disposition[SIZ];
1691 char vcard_partnum[SIZ];
1692 char *vcard_source = NULL;
1694 struct message_summary summ;
1696 if (namebuf == NULL) return;
1697 strcpy(namebuf, "");
1699 memset(&summ, 0, sizeof(summ));
1700 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1702 sprintf(buf, "MSG0 %ld|0", msgnum); /** unfortunately we need the mime info now */
1704 serv_getln(buf, sizeof buf);
1705 if (buf[0] != '1') return;
1707 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1708 if (!strncasecmp(buf, "part=", 5)) {
1709 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1710 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1711 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1712 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1713 mime_length = extract_int(&buf[5], 5);
1715 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1716 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1717 strcpy(vcard_partnum, mime_partnum);
1723 if (strlen(vcard_partnum) > 0) {
1724 vcard_source = load_mimepart(msgnum, vcard_partnum);
1725 if (vcard_source != NULL) {
1727 /* Grab the name off the card */
1728 display_vcard(vcard_source, 0, 0, namebuf);
1734 lastfirst_firstlast(namebuf);
1736 for (i=0; i<strlen(namebuf); ++i) {
1737 if (namebuf[i] != ';') return;
1739 strcpy(namebuf, _("(no name)"));
1745 * \brief Record compare function for sorting address book indices
1746 * \param ab1 adressbook one
1747 * \param ab2 adressbook two
1749 int abcmp(const void *ab1, const void *ab2) {
1751 (((const struct addrbookent *)ab1)->ab_name),
1752 (((const struct addrbookent *)ab2)->ab_name)
1758 * \brief Helper function for do_addrbook_view()
1759 * Converts a name into a three-letter tab label
1760 * \param tabbuf the tabbuffer to add name to
1761 * \param name the name to add to the tabbuffer
1763 void nametab(char *tabbuf, char *name) {
1764 stresc(tabbuf, name, 0, 0);
1765 tabbuf[0] = toupper(tabbuf[0]);
1766 tabbuf[1] = tolower(tabbuf[1]);
1767 tabbuf[2] = tolower(tabbuf[2]);
1773 * \brief Render the address book using info we gathered during the scan
1774 * \param addrbook the addressbook to render
1775 * \param num_ab the number of the addressbook
1777 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1781 static int NAMESPERPAGE = 60;
1785 char tabfirst_label[SIZ];
1787 char tablast_label[SIZ];
1790 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1791 wprintf(_("This address book is empty."));
1792 wprintf("</i></div>\n");
1797 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1800 num_pages = num_ab / NAMESPERPAGE;
1802 page = atoi(bstr("page"));
1805 for (i=0; i<=num_pages; ++i) {
1807 wprintf("<a href=\"readfwd?page=%d\">", i);
1812 tabfirst = i * NAMESPERPAGE;
1813 tablast = tabfirst + NAMESPERPAGE - 1;
1814 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1815 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1816 nametab(tablast_label, addrbook[tablast].ab_name);
1817 wprintf("[%s - %s]",
1818 tabfirst_label, tablast_label
1827 wprintf("<br />\n");
1829 wprintf("<table border=0 cellspacing=0 "
1830 "cellpadding=3 width=100%%>\n"
1833 for (i=0; i<num_ab; ++i) {
1835 if ((i / NAMESPERPAGE) == page) {
1837 if ((displayed % 4) == 0) {
1838 if (displayed > 0) {
1842 wprintf("<tr bgcolor=\"#%s\">",
1843 (bg ? "DDDDDD" : "FFFFFF")
1849 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
1850 addrbook[i].ab_msgnum);
1851 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1852 vcard_n_prettyize(addrbook[i].ab_name);
1853 escputs(addrbook[i].ab_name);
1854 wprintf("</a></td>\n");
1859 wprintf("</tr></table>\n");
1865 * \brief load message pointers from the server
1866 * \param servcmd the citadel command to send to the citserver
1867 * \param with_headers what headers???
1869 int load_msg_ptrs(char *servcmd, int with_headers)
1880 int num_summ_alloc = 0;
1882 if (WC->summ != NULL) {
1887 num_summ_alloc = 100;
1889 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1892 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1894 serv_getln(buf, sizeof buf);
1895 if (buf[0] != '1') {
1898 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1899 if (nummsgs < maxload) {
1900 WC->msgarr[nummsgs] = extract_long(buf, 0);
1901 datestamp = extract_long(buf, 1);
1902 extract_token(fullname, buf, 2, '|', sizeof fullname);
1903 extract_token(nodename, buf, 3, '|', sizeof nodename);
1904 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1905 extract_token(subject, buf, 5, '|', sizeof subject);
1909 if (nummsgs > num_summ_alloc) {
1910 num_summ_alloc *= 2;
1911 WC->summ = realloc(WC->summ,
1912 num_summ_alloc * sizeof(struct message_summary));
1916 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1917 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1918 safestrncpy(WC->summ[nummsgs-1].subj,
1919 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1920 if (strlen(fullname) > 0) {
1921 safestrncpy(WC->summ[nummsgs-1].from,
1922 fullname, sizeof WC->summ[nummsgs-1].from);
1924 if (strlen(subject) > 0) {
1925 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1926 sizeof WC->summ[nummsgs-1].subj);
1929 /** Handle subjects with RFC2047 encoding */
1930 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1932 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1933 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1936 if (strlen(nodename) > 0) {
1937 if ( ((WC->room_flags & QR_NETWORK)
1938 || ((strcasecmp(nodename, serv_info.serv_nodename)
1939 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1941 strcat(WC->summ[nummsgs-1].from, " @ ");
1942 strcat(WC->summ[nummsgs-1].from, nodename);
1946 WC->summ[nummsgs-1].date = datestamp;
1949 /** Handle senders with RFC2047 encoding */
1950 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1952 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1953 strcpy(&WC->summ[nummsgs-1].from[22], "...");
1962 * \brief qsort() compatible function to compare two longs in descending order.
1964 * \param s1 first number to compare
1965 * \param s2 second number to compare
1967 int longcmp_r(const void *s1, const void *s2) {
1974 if (l1 > l2) return(-1);
1975 if (l1 < l2) return(+1);
1981 * \brief qsort() compatible function to compare two message summary structs by ascending subject.
1983 * \param s1 first item to compare
1984 * \param s2 second item to compare
1986 int summcmp_subj(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;
1992 return strcasecmp(summ1->subj, summ2->subj);
1996 * \brief qsort() compatible function to compare two message summary structs by descending subject.
1998 * \param s1 first item to compare
1999 * \param s2 second item to compare
2001 int summcmp_rsubj(const void *s1, const void *s2) {
2002 struct message_summary *summ1;
2003 struct message_summary *summ2;
2005 summ1 = (struct message_summary *)s1;
2006 summ2 = (struct message_summary *)s2;
2007 return strcasecmp(summ2->subj, summ1->subj);
2011 * \brief qsort() compatible function to compare two message summary structs by ascending sender.
2013 * \param s1 first item to compare
2014 * \param s2 second item to compare
2016 int summcmp_sender(const void *s1, const void *s2) {
2017 struct message_summary *summ1;
2018 struct message_summary *summ2;
2020 summ1 = (struct message_summary *)s1;
2021 summ2 = (struct message_summary *)s2;
2022 return strcasecmp(summ1->from, summ2->from);
2026 * \brief qsort() compatible function to compare two message summary structs by descending sender.
2028 * \param s1 first item to compare
2029 * \param s2 second item to compare
2031 int summcmp_rsender(const void *s1, const void *s2) {
2032 struct message_summary *summ1;
2033 struct message_summary *summ2;
2035 summ1 = (struct message_summary *)s1;
2036 summ2 = (struct message_summary *)s2;
2037 return strcasecmp(summ2->from, summ1->from);
2041 * \brief qsort() compatible function to compare two message summary structs by ascending date.
2043 * \param s1 first item to compare
2044 * \param s2 second item to compare
2046 int summcmp_date(const void *s1, const void *s2) {
2047 struct message_summary *summ1;
2048 struct message_summary *summ2;
2050 summ1 = (struct message_summary *)s1;
2051 summ2 = (struct message_summary *)s2;
2053 if (summ1->date < summ2->date) return -1;
2054 else if (summ1->date > summ2->date) return +1;
2059 * \brief qsort() compatible function to compare two message summary structs by descending date.
2061 * \param s1 first item to compare
2062 * \param s2 second item to compare
2064 int summcmp_rdate(const void *s1, const void *s2) {
2065 struct message_summary *summ1;
2066 struct message_summary *summ2;
2068 summ1 = (struct message_summary *)s1;
2069 summ2 = (struct message_summary *)s2;
2071 if (summ1->date < summ2->date) return +1;
2072 else if (summ1->date > summ2->date) return -1;
2079 * \brief command loop for reading messages
2081 * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
2083 void readloop(char *oper)
2092 long *displayed_msgs = NULL;
2093 int num_displayed = 0;
2095 int is_addressbook = 0;
2096 int is_singlecard = 0;
2097 int is_calendar = 0;
2102 int lowest_displayed = (-1);
2103 int highest_displayed = 0;
2104 struct addrbookent *addrbook = NULL;
2106 char *sortby = NULL;
2107 char sortpref_name[128];
2108 char sortpref_value[128];
2109 char *subjsort_button;
2110 char *sendsort_button;
2111 char *datesort_button;
2112 int bbs_reverse = 0;
2114 if (WC->wc_view == VIEW_WIKI) {
2115 sprintf(buf, "wiki?room=%s?page=home", WC->wc_roomname);
2120 startmsg = atol(bstr("startmsg"));
2121 maxmsgs = atoi(bstr("maxmsgs"));
2122 is_summary = atoi(bstr("summary"));
2123 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2125 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
2126 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
2128 sortby = bstr("sortby");
2129 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
2130 set_preference(sortpref_name, sortby, 1);
2132 if (strlen(sortby) == 0) sortby = sortpref_value;
2135 if (strlen(sortby) == 0) sortby = "rdate";
2137 /** message board sort */
2138 if (!strcasecmp(sortby, "reverse")) {
2145 output_headers(1, 1, 1, 0, 0, 0);
2148 * When in summary mode, always show ALL messages instead of just
2149 * new or old. Otherwise, show what the user asked for.
2151 if (!strcmp(oper, "readnew")) {
2152 strcpy(cmd, "MSGS NEW");
2154 else if (!strcmp(oper, "readold")) {
2155 strcpy(cmd, "MSGS OLD");
2157 else if (!strcmp(oper, "do_search")) {
2158 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2161 strcpy(cmd, "MSGS ALL");
2164 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
2166 if (!strcmp(oper, "do_search")) {
2167 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2170 strcpy(cmd, "MSGS ALL");
2174 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2176 if (!strcmp(oper, "do_search")) {
2177 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2180 strcpy(cmd, "MSGS ALL");
2185 if (is_summary) { /**< fetch header summary */
2186 snprintf(cmd, sizeof cmd, "MSGS %s|%s||1",
2187 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2188 (!strcmp(oper, "do_search") ? bstr("query") : "")
2195 * Are we doing a summary view? If so, we need to know old messages
2196 * and new messages, so we can do that pretty boldface thing for the
2199 strcpy(old_msgs, "");
2202 serv_getln(buf, sizeof buf);
2203 if (buf[0] == '2') {
2204 strcpy(old_msgs, &buf[4]);
2208 is_singlecard = atoi(bstr("is_singlecard"));
2210 if (WC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2212 strcpy(cmd, "MSGS ALL");
2215 if (WC->wc_default_view == VIEW_TASKS) { /**< tasks */
2217 strcpy(cmd, "MSGS ALL");
2220 if (WC->wc_default_view == VIEW_NOTES) { /**< notes */
2222 strcpy(cmd, "MSGS ALL");
2227 wprintf("<div align=center>%s</div>\n", _("Click on any note to edit it."));
2228 wprintf("<div id=\"new_notes_here\"></div>\n");
2231 nummsgs = load_msg_ptrs(cmd, is_summary);
2234 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2235 wprintf("<div align=\"center\"><br /><em>");
2236 if (!strcmp(oper, "readnew")) {
2237 wprintf(_("No new messages."));
2238 } else if (!strcmp(oper, "readold")) {
2239 wprintf(_("No old messages."));
2241 wprintf(_("No messages here."));
2243 wprintf("</em><br /></div>\n");
2250 for (a = 0; a < nummsgs; ++a) {
2251 /** Are you a new message, or an old message? */
2253 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
2254 WC->summ[a].is_new = 0;
2257 WC->summ[a].is_new = 1;
2263 if (startmsg == 0L) {
2265 startmsg = WC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2268 startmsg = WC->msgarr[0];
2273 if (!strcasecmp(sortby, "subject")) {
2274 qsort(WC->summ, WC->num_summ,
2275 sizeof(struct message_summary), summcmp_subj);
2277 else if (!strcasecmp(sortby, "rsubject")) {
2278 qsort(WC->summ, WC->num_summ,
2279 sizeof(struct message_summary), summcmp_rsubj);
2281 else if (!strcasecmp(sortby, "sender")) {
2282 qsort(WC->summ, WC->num_summ,
2283 sizeof(struct message_summary), summcmp_sender);
2285 else if (!strcasecmp(sortby, "rsender")) {
2286 qsort(WC->summ, WC->num_summ,
2287 sizeof(struct message_summary), summcmp_rsender);
2289 else if (!strcasecmp(sortby, "date")) {
2290 qsort(WC->summ, WC->num_summ,
2291 sizeof(struct message_summary), summcmp_date);
2293 else if (!strcasecmp(sortby, "rdate")) {
2294 qsort(WC->summ, WC->num_summ,
2295 sizeof(struct message_summary), summcmp_rdate);
2299 if (!strcasecmp(sortby, "subject")) {
2300 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2302 else if (!strcasecmp(sortby, "rsubject")) {
2303 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2306 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2309 if (!strcasecmp(sortby, "sender")) {
2310 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2312 else if (!strcasecmp(sortby, "rsender")) {
2313 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2316 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2319 if (!strcasecmp(sortby, "date")) {
2320 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2322 else if (!strcasecmp(sortby, "rdate")) {
2323 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2326 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2330 wprintf("</div>\n"); /** end of 'content' div */
2332 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2333 " document.onkeydown = CtdlMsgListKeyPress; "
2334 " if (document.layers) { "
2335 " document.captureEvents(Event.KEYPRESS); "
2340 /** note that Date and Delete are now in the same column */
2341 wprintf("<div id=\"message_list_hdr\">"
2342 "<div class=\"fix_scrollbar_bug\">"
2343 "<table cellspacing=0 style=\"width:100%%\">"
2346 wprintf("<td width=%d%%><b><i>%s</i></b> %s</td>"
2347 "<td width=%d%%><b><i>%s</i></b> %s</td>"
2348 "<td width=%d%%><b><i>%s</i></b> %s"
2350 "<input type=\"submit\" name=\"delete_button\" style=\"font-size:6pt\" "
2351 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2357 _("Subject"), subjsort_button,
2358 SENDER_COL_WIDTH_PCT,
2359 _("Sender"), sendsort_button,
2360 DATE_PLUS_BUTTONS_WIDTH_PCT,
2361 _("Date"), datesort_button,
2364 wprintf("</table></div></div>\n");
2366 wprintf("<div id=\"message_list\">"
2368 "<div class=\"fix_scrollbar_bug\">\n"
2370 "<table class=\"mailbox_summary\" id=\"summary_headers\" rules=rows "
2371 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2375 for (a = 0; a < nummsgs; ++a) {
2376 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2378 /** Display the message */
2380 display_summarized(a);
2382 else if (is_addressbook) {
2383 fetch_ab_name(WC->msgarr[a], buf);
2385 addrbook = realloc(addrbook,
2386 (sizeof(struct addrbookent) * num_ab) );
2387 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2388 sizeof(addrbook[num_ab-1].ab_name));
2389 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
2391 else if (is_calendar) {
2392 display_calendar(WC->msgarr[a]);
2394 else if (is_tasks) {
2395 display_task(WC->msgarr[a]);
2397 else if (is_notes) {
2398 display_note(WC->msgarr[a]);
2401 if (displayed_msgs == NULL) {
2402 displayed_msgs = malloc(sizeof(long) *
2403 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2405 displayed_msgs[num_displayed] = WC->msgarr[a];
2408 if (lowest_displayed < 0) lowest_displayed = a;
2409 highest_displayed = a;
2416 * Set the "is_bbview" variable if it appears that we are looking at
2417 * a classic bulletin board view.
2419 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2420 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2425 if (displayed_msgs != NULL) {
2427 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2430 /** if we do a split bbview in the future, begin messages div here */
2432 for (a=0; a<num_displayed; ++a) {
2433 read_message(displayed_msgs[a], 0, "");
2436 /** if we do a split bbview in the future, end messages div here */
2438 free(displayed_msgs);
2439 displayed_msgs = NULL;
2444 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2445 wprintf("</div>"); /**< end of 'message_list' div */
2447 /** Here's the grab-it-to-resize-the-message-list widget */
2448 wprintf("<div id=\"resize_msglist\" "
2449 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2450 "<div class=\"fix_scrollbar_bug\">"
2451 "<table width=100%% border=3 cellspacing=0 "
2452 "bgcolor=\"#cccccc\" "
2453 "cellpadding=0><TR><TD> </td></tr></table>"
2457 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2461 * Bump these because although we're thinking in zero base, the user
2462 * is a drooling idiot and is thinking in one base.
2465 ++highest_displayed;
2468 * If we're not currently looking at ALL requested
2469 * messages, then display the selector bar
2472 /** begin bbview scroller */
2473 wprintf("<form name=\"msgomatic\">");
2474 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2476 wprintf("<select name=\"whichones\" size=\"1\" "
2477 "OnChange=\"location.href=msgomatic.whichones.options"
2478 "[selectedIndex].value\">\n");
2481 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2483 lo = b - maxmsgs + 2;
2485 wprintf("<option %s value="
2490 "%d-%d</option> \n",
2491 ((WC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2500 for (b=0; b<nummsgs; b = b + maxmsgs) {
2502 hi = b + maxmsgs + 1;
2503 if (hi > nummsgs) hi = nummsgs;
2504 wprintf("<option %s value="
2509 "%d-%d</option> \n",
2510 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2519 wprintf("<option value=\"%s?startmsg=%ld"
2520 "?maxmsgs=9999999?summary=%d\">"
2524 WC->msgarr[0], is_summary);
2526 wprintf("</select> ");
2527 wprintf(_("of %d messages."), nummsgs);
2529 /** forward/reverse */
2530 wprintf(" <select name=\"direction\" size=\"1\" "
2531 "OnChange=\"location.href=msgomatic.direction.options"
2532 "[selectedIndex].value\">\n"
2535 wprintf("<option %s value=\"%s?sortby=forward\">oldest to newest</option>\n",
2536 (bbs_reverse ? "" : "selected"),
2540 wprintf("<option %s value=\"%s?sortby=reverse\">newest to oldest</option>\n",
2541 (bbs_reverse ? "selected" : ""),
2545 wprintf("</select></form>\n");
2546 /** end bbview scroller */
2551 do_tasks_view(); /** Render the task list */
2555 do_calendar_view(); /** Render the calendar */
2558 if (is_addressbook) {
2559 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2562 /** Note: wDumpContent() will output one additional </div> tag. */
2564 if (addrbook != NULL) free(addrbook);
2566 /** free the summary */
2567 if (WC->summ != NULL) {
2576 * \brief Back end for post_message()
2577 * ... this is where the actual message gets transmitted to the server.
2579 void post_mime_to_server(void) {
2581 int is_multipart = 0;
2583 struct wc_attachment *att;
2585 size_t encoded_length;
2587 /** RFC2045 requires this, and some clients look for it... */
2588 serv_puts("MIME-Version: 1.0");
2589 serv_puts("X-Mailer: " SERVER);
2591 /** If there are attachments, we have to do multipart/mixed */
2592 if (WC->first_attachment != NULL) {
2597 sprintf(boundary, "Citadel--Multipart--%s--%04x--%04x",
2598 serv_info.serv_fqdn,
2603 /** Remember, serv_printf() appends an extra newline */
2604 serv_printf("Content-type: multipart/mixed; "
2605 "boundary=\"%s\"\n", boundary);
2606 serv_printf("This is a multipart message in MIME format.\n");
2607 serv_printf("--%s", boundary);
2610 serv_puts("Content-type: text/html; charset=utf-8");
2611 serv_puts("Content-Transfer-Encoding: quoted-printable");
2613 serv_puts("<html><body>\r\n");
2614 text_to_server_qp(bstr("msgtext")); /** Transmit message in quoted-printable encoding */
2615 serv_puts("</body></html>\r\n");
2619 /** Add in the attachments */
2620 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2622 encoded_length = ((att->length * 150) / 100);
2623 encoded = malloc(encoded_length);
2624 if (encoded == NULL) break;
2625 CtdlEncodeBase64(encoded, att->data, att->length, 1);
2627 serv_printf("--%s", boundary);
2628 serv_printf("Content-type: %s", att->content_type);
2629 serv_printf("Content-disposition: attachment; "
2630 "filename=\"%s\"", att->filename);
2631 serv_puts("Content-transfer-encoding: base64");
2633 serv_write(encoded, strlen(encoded));
2638 serv_printf("--%s--", boundary);
2646 * \brief Post message (or don't post message)
2648 * Note regarding the "dont_post" variable:
2649 * A random value (actually, it's just a timestamp) is inserted as a hidden
2650 * field called "postseq" when the display_enter page is generated. This
2651 * value is checked when posting, using the static variable dont_post. If a
2652 * user attempts to post twice using the same dont_post value, the message is
2653 * discarded. This prevents the accidental double-saving of the same message
2654 * if the user happens to click the browser "back" button.
2656 void post_message(void)
2659 char encoded_subject[1024];
2660 static long dont_post = (-1L);
2661 struct wc_attachment *att, *aptr;
2662 int is_anonymous = 0;
2665 display_name = bstr("display_name");
2666 if (!strcmp(display_name, "__ANONYMOUS__")) {
2671 if (WC->upload_length > 0) {
2673 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WC->upload_length);
2674 /** There's an attachment. Save it to this struct... */
2675 att = malloc(sizeof(struct wc_attachment));
2676 memset(att, 0, sizeof(struct wc_attachment));
2677 att->length = WC->upload_length;
2678 strcpy(att->content_type, WC->upload_content_type);
2679 strcpy(att->filename, WC->upload_filename);
2682 /** And add it to the list. */
2683 if (WC->first_attachment == NULL) {
2684 WC->first_attachment = att;
2687 aptr = WC->first_attachment;
2688 while (aptr->next != NULL) aptr = aptr->next;
2693 * Mozilla sends a simple filename, which is what we want,
2694 * but Satan's Browser sends an entire pathname. Reduce
2695 * the path to just a filename if we need to.
2697 while (num_tokens(att->filename, '/') > 1) {
2698 remove_token(att->filename, 0, '/');
2700 while (num_tokens(att->filename, '\\') > 1) {
2701 remove_token(att->filename, 0, '\\');
2705 * Transfer control of this memory from the upload struct
2706 * to the attachment struct.
2708 att->data = WC->upload;
2709 WC->upload_length = 0;
2715 if (strlen(bstr("cancel_button")) > 0) {
2716 lprintf(9, "%s:%d: cancel button was pressed\n", __FILE__, __LINE__);
2717 sprintf(WC->ImportantMessage,
2718 _("Cancelled. Message was not posted."));
2719 } else if (strlen(bstr("attach_button")) > 0) {
2720 lprintf(9, "%s:%d: attach button was pressed\n", __FILE__, __LINE__);
2723 } else if (atol(bstr("postseq")) == dont_post) {
2724 lprintf(9, "%s:%d: postseq does not match\n", __FILE__, __LINE__);
2725 sprintf(WC->ImportantMessage,
2726 _("Automatically cancelled because you have already "
2727 "saved this message."));
2729 rfc2047encode(encoded_subject, sizeof encoded_subject, bstr("subject"));
2730 sprintf(buf, "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s",
2740 serv_getln(buf, sizeof buf);
2741 if (buf[0] == '4') {
2742 post_mime_to_server();
2743 if ( (strlen(bstr("recp")) > 0)
2744 || (strlen(bstr("cc")) > 0)
2745 || (strlen(bstr("bcc")) > 0)
2747 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2750 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2752 dont_post = atol(bstr("postseq"));
2754 lprintf(9, "%s:%d: server post error\n", __FILE__, __LINE__);
2755 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2761 free_attachments(WC);
2764 * We may have been supplied with instructions regarding the location
2765 * to which we must return after posting. If found, go there.
2767 if (strlen(bstr("return_to")) > 0) {
2768 http_redirect(bstr("return_to"));
2771 * If we were editing a page in a wiki room, go to that page now.
2773 else if (strlen(bstr("wikipage")) > 0) {
2774 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
2778 * Otherwise, just go to the "read messages" loop.
2781 readloop("readnew");
2789 * \brief display the message entry screen
2791 void display_enter(void)
2797 struct wc_attachment *att;
2798 int recipient_required = 0;
2799 int recipient_bad = 0;
2801 int is_anonymous = 0;
2802 long existing_page = (-1L);
2806 if (strlen(bstr("force_room")) > 0) {
2807 gotoroom(bstr("force_room"));
2810 display_name = bstr("display_name");
2811 if (!strcmp(display_name, "__ANONYMOUS__")) {
2816 /** First test to see whether this is a room that requires recipients to be entered */
2817 serv_puts("ENT0 0");
2818 serv_getln(buf, sizeof buf);
2819 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
2820 recipient_required = 1;
2822 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2823 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2824 readloop("readnew");
2829 * Are we perhaps in an address book view? If so, then an "enter
2830 * message" command really means "add new entry."
2832 if (WC->wc_default_view == VIEW_ADDRESSBOOK) {
2833 do_edit_vcard(-1, "", "");
2837 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
2839 * Are we perhaps in a calendar room? If so, then an "enter
2840 * message" command really means "add new calendar item."
2842 if (WC->wc_default_view == VIEW_CALENDAR) {
2843 display_edit_event();
2848 * Are we perhaps in a tasks view? If so, then an "enter
2849 * message" command really means "add new task."
2851 if (WC->wc_default_view == VIEW_TASKS) {
2852 display_edit_task();
2858 * Otherwise proceed normally.
2859 * Do a custom room banner with no navbar...
2861 output_headers(1, 1, 2, 0, 0, 0);
2862 wprintf("<div id=\"banner\">\n");
2863 embed_room_banner(NULL, navbar_none);
2864 wprintf("</div>\n");
2865 wprintf("<div id=\"content\">\n"
2866 "<div class=\"fix_scrollbar_bug\">"
2867 "<table class=\"messages_background\"><tr><td>");
2869 /** Now check our actual recipients if there are any */
2870 if (recipient_required) {
2871 sprintf(buf, "ENT0 0|%s|%d|0||%s||%s|%s|%s",
2875 bstr("cc"), bstr("bcc"), bstr("wikipage"));
2877 serv_getln(buf, sizeof buf);
2879 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
2880 if (strlen(bstr("recp")) + strlen(bstr("cc")) + strlen(bstr("bcc")) > 0) {
2884 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2885 wprintf("<em>%s</em><br />\n", &buf[4]);
2890 /** If we got this far, we can display the message entry screen. */
2892 /** begin message entry screen */
2894 "enctype=\"multipart/form-data\" "
2896 "accept-charset=\"UTF-8\" "
2898 "name=\"enterform\""
2900 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2901 if (WC->wc_view == VIEW_WIKI) {
2902 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
2904 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
2908 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2909 fmt_date(buf, now, 0);
2910 wprintf("%s ", buf);
2912 wprintf(_(" <I>from</I> "));
2914 wprintf("<select name=\"display_name\" size=1>\n");
2917 serv_getln(buf, sizeof buf);
2918 if (buf[0] == '1') {
2919 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2920 wprintf("<option %s value=\"",
2921 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
2926 wprintf("</option>\n");
2930 if (WC->room_flags & QR_ANONOPT) {
2931 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
2932 ((!strcasecmp(bstr("__ANONYMOUS__"), WC->wc_fullname)) ? "selected" : ""),
2937 wprintf("</select>\n");
2939 wprintf(_(" <I>in</I> "));
2940 escputs(WC->wc_roomname);
2941 wprintf("<br>\n"); /** header bar */
2943 wprintf("<table border=\"0\" width=\"100%%\">\n");
2944 if (recipient_required) {
2946 wprintf("<tr><td>");
2947 wprintf("<font size=-1>");
2951 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
2952 escputs(bstr("recp"));
2953 wprintf("\" size=50 maxlength=1000 />");
2954 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
2955 wprintf("</td><td></td></tr>\n");
2957 wprintf("<tr><td>");
2958 wprintf("<font size=-1>");
2962 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
2963 escputs(bstr("cc"));
2964 wprintf("\" size=50 maxlength=1000 />");
2965 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
2966 wprintf("</td><td></td></tr>\n");
2968 wprintf("<tr><td>");
2969 wprintf("<font size=-1>");
2973 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
2974 escputs(bstr("bcc"));
2975 wprintf("\" size=50 maxlength=1000 />");
2976 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
2977 wprintf("</td><td></td></tr>\n");
2979 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
2980 wprintf("<script type=\"text/javascript\"> \n"
2981 " activate_entmsg_autocompleters(); \n"
2986 wprintf("<tr><td>");
2987 wprintf("<font size=-1>");
2988 wprintf(_("Subject (optional):"));
2991 "<input type=\"text\" name=\"subject\" value=\"");
2992 escputs(bstr("subject"));
2993 wprintf("\" size=50 maxlength=70></td><td>\n");
2995 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2996 if (recipient_required) {
2997 wprintf(_("Send message"));
2999 wprintf(_("Post message"));
3002 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3003 wprintf("</td></tr></table>\n");
3005 wprintf("<center>");
3007 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
3009 /** If we're continuing from a previous edit, put our partially-composed message back... */
3010 msgescputs(bstr("msgtext"));
3012 /* If we're forwarding a message, insert it here... */
3013 if (atol(bstr("fwdquote")) > 0L) {
3014 wprintf("<br><div align=center><i>");
3015 wprintf(_("--- forwarded message ---"));
3016 wprintf("</i></div><br>");
3017 pullquote_message(atol(bstr("fwdquote")), 1, 1);
3020 /** If we're replying quoted, insert the quote here... */
3021 else if (atol(bstr("replyquote")) > 0L) {
3024 pullquote_message(atol(bstr("replyquote")), 0, 1);
3025 wprintf("</blockquote><br>");
3028 /** If we're editing a wiki page, insert the existing page here... */
3029 else if (WC->wc_view == VIEW_WIKI) {
3030 safestrncpy(buf, bstr("wikipage"), sizeof buf);
3031 str_wiki_index(buf);
3032 existing_page = locate_message_by_uid(buf);
3033 if (existing_page >= 0L) {
3034 pullquote_message(existing_page, 1, 0);
3038 /** Insert our signature if appropriate... */
3039 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
3040 get_preference("use_sig", buf, sizeof buf);
3041 if (!strcasecmp(buf, "yes")) {
3042 get_preference("signature", ebuf, sizeof ebuf);
3043 euid_unescapize(buf, ebuf);
3044 wprintf("<br>--<br>");
3045 for (i=0; i<strlen(buf); ++i) {
3046 if (buf[i] == '\n') {
3049 else if (buf[i] == '<') {
3052 else if (buf[i] == '>') {
3055 else if (buf[i] == '&') {
3058 else if (buf[i] == '\"') {
3061 else if (buf[i] == '\'') {
3064 else if (isprint(buf[i])) {
3065 wprintf("%c", buf[i]);
3071 wprintf("</textarea>");
3072 wprintf("</center><br />\n");
3075 * The following script embeds the TinyMCE richedit control, and automatically
3076 * transforms the textarea into a richedit textarea.
3079 "<script language=\"javascript\" type=\"text/javascript\" src=\"tiny_mce/tiny_mce.js\"></script>\n"
3080 "<script language=\"javascript\" type=\"text/javascript\">"
3082 " mode : \"textareas\", width : \"100%%\", browsers : \"msie,gecko\", "
3083 " theme : \"advanced\", plugins : \"iespell\", "
3084 " theme_advanced_buttons1 : \"bold, italic, underline, strikethrough, justifyleft, justifycenter, justifyright, justifyfull, bullist, numlist, cut, copy, paste, link, image, help, forecolor, iespell, code\", "
3085 " theme_advanced_buttons2 : \"\", "
3086 " theme_advanced_buttons3 : \"\", "
3087 " content_css : \"static/webcit-tinymce.css\" "
3093 /** Enumerate any attachments which are already in place... */
3094 wprintf("<img src=\"static/diskette_24x.gif\" border=0 "
3095 "align=middle height=16 width=16> ");
3096 wprintf(_("Attachments:"));
3098 wprintf("<select name=\"which_attachment\" size=1>");
3099 for (att = WC->first_attachment; att != NULL; att = att->next) {
3100 wprintf("<option value=\"");
3101 urlescputs(att->filename);
3103 escputs(att->filename);
3104 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3105 wprintf("</option>\n");
3107 wprintf("</select>");
3109 /** Now offer the ability to attach additional files... */
3110 wprintf(" ");
3111 wprintf(_("Attach file:"));
3112 wprintf(" <input NAME=\"attachfile\" "
3113 "SIZE=16 TYPE=\"file\">\n "
3114 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3116 /** Seth asked for these to be at the top *and* bottom... */
3117 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3118 if (recipient_required) {
3119 wprintf(_("Send message"));
3121 wprintf(_("Post message"));
3124 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3126 /** Make sure we only insert our signature once */
3127 if (strcmp(bstr("sig_inserted"), "yes")) {
3128 wprintf("<INPUT TYPE=\"hidden\" NAME=\"sig_inserted\" VALUE=\"yes\">\n");
3131 wprintf("</form>\n");
3133 wprintf("</td></tr></table></div>\n");
3134 DONE: wDumpContent(1);
3140 * \brief delete a message
3142 void delete_msg(void)
3147 msgid = atol(bstr("msgid"));
3149 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3150 serv_printf("DELE %ld", msgid);
3152 else { /** Otherwise move it to Trash */
3153 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3156 serv_getln(buf, sizeof buf);
3157 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3159 readloop("readnew");
3164 * \brief move a message to another folder
3171 msgid = atol(bstr("msgid"));
3173 if (strlen(bstr("move_button")) > 0) {
3174 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3176 serv_getln(buf, sizeof buf);
3177 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3179 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3182 readloop("readnew");
3190 * \brief Confirm move of a message
3192 void confirm_move_msg(void)
3198 msgid = atol(bstr("msgid"));
3201 output_headers(1, 1, 2, 0, 0, 0);
3202 wprintf("<div id=\"banner\">\n");
3203 wprintf("<TABLE WIDTH=100%% BORDER=0><TR><TD>");
3204 wprintf("<SPAN CLASS=\"titlebar\">");
3205 wprintf(_("Confirm move of message"));
3206 wprintf("</SPAN>\n");
3207 wprintf("</TD></TR></TABLE>\n");
3208 wprintf("</div>\n<div id=\"content\">\n");
3210 wprintf("<CENTER>");
3212 wprintf(_("Move this message to:"));
3213 wprintf("<br />\n");
3215 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3216 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3218 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3220 serv_getln(buf, sizeof buf);
3221 if (buf[0] == '1') {
3222 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3223 extract_token(targ, buf, 0, '|', sizeof targ);
3224 wprintf("<OPTION>");
3229 wprintf("</SELECT>\n");
3230 wprintf("<br />\n");
3232 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3234 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3235 wprintf("</form></CENTER>\n");
3237 wprintf("</CENTER>\n");