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 || (!strcasecmp(mime_disposition, ""))
816 snprintf(&mime_http[strlen(mime_http)],
817 (sizeof(mime_http) - strlen(mime_http) - 1),
818 "<img src=\"static/diskette_24x.gif\" "
819 "border=0 align=middle>\n"
820 "%s (%s, %d bytes) [ "
821 "<a href=\"mimepart/%ld/%s/%s\""
822 "target=\"wc.%ld.%s\">%s</a>"
824 "<a href=\"mimepart_download/%ld/%s/%s\">%s</a>"
827 mime_content_type, mime_length,
828 msgnum, mime_partnum, mime_filename,
829 msgnum, mime_partnum,
831 msgnum, mime_partnum, mime_filename,
836 /** begin handler prep ***/
837 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
838 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
839 strcpy(vcard_partnum, mime_partnum);
842 if (!strcasecmp(mime_content_type, "text/calendar")) {
843 strcpy(cal_partnum, mime_partnum);
846 /** end handler prep ***/
852 /** Generate a reply-to address */
853 if (strlen(rfca) > 0) {
854 if (strlen(from) > 0) {
855 snprintf(reply_to, sizeof(reply_to), "%s <%s>", from, rfca);
858 strcpy(reply_to, rfca);
862 if ( (strlen(node) > 0)
863 && (strcasecmp(node, serv_info.serv_nodename))
864 && (strcasecmp(node, serv_info.serv_humannode)) ) {
865 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
869 snprintf(reply_to, sizeof(reply_to), "%s", from);
879 utf8ify_rfc822_string(m_cc);
880 utf8ify_rfc822_string(m_subject);
882 if (strlen(m_cc) > 0) {
884 "<span class=\"message_subject\">");
890 if (strlen(m_subject) > 0) {
892 "<span class=\"message_subject\">");
893 wprintf(_("Subject:"));
900 /** start msg buttons */
901 if (!printable_view) {
902 wprintf("<td align=right><span class=\"msgbuttons\">\n");
905 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
906 wprintf("<a href=\"display_enter");
907 if (WC->is_mailbox) {
908 wprintf("?replyquote=%ld", msgnum);
911 urlescputs(reply_to);
912 if (strlen(m_subject) > 0) {
913 wprintf("?subject=");
914 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
915 urlescputs(m_subject);
917 wprintf("\">[%s]</a> ", _("Reply"));
921 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
922 if (!WC->is_mailbox) {
923 wprintf("<a href=\"display_enter");
924 wprintf("?replyquote=%ld", msgnum);
926 urlescputs(reply_to);
927 if (strlen(m_subject) > 0) {
928 wprintf("?subject=");
929 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
930 urlescputs(m_subject);
932 wprintf("\">[%s]</a> ", _("ReplyQuoted"));
937 if (WC->wc_view == VIEW_MAILBOX) {
938 wprintf("<a href=\"display_enter");
939 wprintf("?replyquote=%ld", msgnum);
941 urlescputs(reply_to);
943 urlescputs(reply_all);
944 if (strlen(m_subject) > 0) {
945 wprintf("?subject=");
946 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
947 urlescputs(m_subject);
949 wprintf("\">[%s]</a> ", _("ReplyAll"));
953 if (WC->wc_view == VIEW_MAILBOX) {
954 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
955 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
956 urlescputs(m_subject);
957 wprintf("\">[%s]</a> ", _("Forward"));
960 /** If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
961 if ( (WC->is_room_aide) || (WC->is_mailbox) ) {
963 wprintf("<a href=\"confirm_move_msg?msgid=%ld\">[%s]</a> ",
967 wprintf("<a href=\"delete_msg?msgid=%ld\" "
968 "onClick=\"return confirm('%s');\">"
969 "[%s]</a> ", msgnum, _("Delete this message?"), _("Delete")
974 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'); \" >"
975 "[%s]</a>", msgnum, msgnum, _("Headers"));
979 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'); \" >"
980 "[%s]</a>", msgnum, msgnum, _("Print"));
982 wprintf("</span></td>");
985 wprintf("</tr></table>\n");
988 wprintf("<table class=\"messages_background\" "
989 "cellpadding=1 cellspacing=0><tr><td>");
992 * Learn the content type
994 strcpy(mime_content_type, "text/plain");
995 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
996 if (!strcmp(buf, "000")) {
998 wprintf(_("unexpected end of message"));
999 wprintf("</i><br /><br />\n");
1002 if (!strncasecmp(buf, "Content-type: ", 14)) {
1003 safestrncpy(mime_content_type, &buf[14],
1004 sizeof(mime_content_type));
1005 for (i=0; i<strlen(mime_content_type); ++i) {
1006 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1007 safestrncpy(mime_charset, &mime_content_type[i+8],
1008 sizeof mime_charset);
1011 for (i=0; i<strlen(mime_content_type); ++i) {
1012 if (mime_content_type[i] == ';') {
1013 mime_content_type[i] = 0;
1016 for (i=0; i<strlen(mime_charset); ++i) {
1017 if (mime_charset[i] == ';') {
1018 mime_charset[i] = 0;
1024 /** Set up a character set conversion if we need to (and if we can) */
1026 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
1027 if ( (strcasecmp(mime_charset, "us-ascii"))
1028 && (strcasecmp(mime_charset, "UTF-8"))
1029 && (strcasecmp(mime_charset, ""))
1031 ic = ctdl_iconv_open("UTF-8", mime_charset);
1032 if (ic == (iconv_t)(-1) ) {
1033 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1034 __FILE__, __LINE__, mime_charset, strerror(errno));
1039 /** Messages in legacy Citadel variformat get handled thusly... */
1040 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1044 /** Boring old 80-column fixed format text gets handled this way... */
1045 else if ( (!strcasecmp(mime_content_type, "text/plain"))
1046 || (!strcasecmp(mime_content_type, "text")) ) {
1047 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1048 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1049 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1052 if (ic != (iconv_t)(-1) ) {
1054 ibuflen = strlen(ibuf);
1056 obuf = (char *) malloc(obuflen);
1058 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1059 osav[SIZ-obuflen] = 0;
1060 safestrncpy(buf, osav, sizeof buf);
1065 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1066 buf[strlen(buf) - 1] = 0;
1068 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1069 wprintf("<blockquote>");
1071 } else if ((bq == 1) &&
1072 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1073 wprintf("</blockquote>");
1079 wprintf("</tt><br />\n");
1081 wprintf("</i><br />");
1084 else /** HTML is fun, but we've got to strip it first */
1085 if (!strcasecmp(mime_content_type, "text/html")) {
1086 output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
1089 /** Unknown weirdness */
1091 wprintf(_("I don't know how to display %s"), mime_content_type);
1092 wprintf("<br />\n", mime_content_type);
1093 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1096 /** If there are attached submessages, display them now... */
1097 if ( (strlen(mime_submessages) > 0) && (!section[0]) ) {
1098 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1099 extract_token(buf, mime_submessages, i, '|', sizeof buf);
1100 /** use printable_view to suppress buttons */
1101 wprintf("<blockquote>");
1102 read_message(msgnum, 1, buf);
1103 wprintf("</blockquote>");
1108 /** Afterwards, offer links to download attachments 'n' such */
1109 if ( (strlen(mime_http) > 0) && (!section[0]) ) {
1110 wprintf("%s", mime_http);
1113 /** Handler for vCard parts */
1114 if (strlen(vcard_partnum) > 0) {
1115 part_source = load_mimepart(msgnum, vcard_partnum);
1116 if (part_source != NULL) {
1118 /** If it's my vCard I can edit it */
1119 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1120 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1121 || (WC->wc_view == VIEW_ADDRESSBOOK)
1123 wprintf("<a href=\"edit_vcard?"
1124 "msgnum=%ld?partnum=%s\">",
1125 msgnum, vcard_partnum);
1126 wprintf("[%s]</a>", _("edit"));
1129 /** In all cases, display the full card */
1130 display_vcard(part_source, 0, 1, NULL);
1134 /** Handler for calendar parts */
1135 if (strlen(cal_partnum) > 0) {
1136 part_source = load_mimepart(msgnum, cal_partnum);
1137 if (part_source != NULL) {
1138 cal_process_attachment(part_source,
1139 msgnum, cal_partnum);
1149 wprintf("</td></tr></table>\n");
1151 /** end everythingamundo table */
1152 if (!printable_view) {
1153 wprintf("</td></tr></table>\n");
1154 wprintf("</div><br />\n");
1158 if (ic != (iconv_t)(-1) ) {
1167 * \brief Unadorned HTML output of an individual message, suitable
1168 * for placing in a hidden iframe, for printing, or whatever
1170 * \param msgnum_as_string Message number, as a string instead of as a long int
1172 void embed_message(char *msgnum_as_string) {
1175 msgnum = atol(msgnum_as_string);
1176 begin_ajax_response();
1177 read_message(msgnum, 0, "");
1178 end_ajax_response();
1183 * \brief Printable view of a message
1185 * \param msgnum_as_string Message number, as a string instead of as a long int
1187 void print_message(char *msgnum_as_string) {
1190 msgnum = atol(msgnum_as_string);
1191 output_headers(0, 0, 0, 0, 0, 0);
1193 wprintf("Content-type: text/html\r\n"
1195 "Connection: close\r\n",
1199 wprintf("\r\n\r\n<html>\n"
1200 "<head><title>Printable view</title></head>\n"
1201 "<body onLoad=\" window.print(); window.close(); \">\n"
1204 read_message(msgnum, 1, "");
1206 wprintf("\n</body></html>\n\n");
1213 * \brief Display a message's headers
1215 * \param msgnum_as_string Message number, as a string instead of as a long int
1217 void display_headers(char *msgnum_as_string) {
1221 msgnum = atol(msgnum_as_string);
1222 output_headers(0, 0, 0, 0, 0, 0);
1224 wprintf("Content-type: text/plain\r\n"
1226 "Connection: close\r\n",
1230 serv_printf("MSG2 %ld|3", msgnum);
1231 serv_getln(buf, sizeof buf);
1232 if (buf[0] == '1') {
1233 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1234 wprintf("%s\n", buf);
1244 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1245 * or 'reply quoted' operations.
1247 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1248 * in this function. Doing so would throw a JavaScript error in the
1249 * 'supplied text' argument to the editor.
1251 * \param msgnum Message number of the message we want to quote
1252 * \param forward_attachments Nonzero if we want attachments to be forwarded
1254 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1256 char mime_partnum[256];
1257 char mime_filename[256];
1258 char mime_content_type[256];
1259 char mime_charset[256];
1260 char mime_disposition[256];
1262 char *attachments = NULL;
1264 int num_attachments = 0;
1265 struct wc_attachment *att, *aptr;
1266 char m_subject[256];
1272 int format_type = 0;
1277 iconv_t ic = (iconv_t)(-1) ;
1278 char *ibuf; /**< Buffer of characters to be converted */
1279 char *obuf; /**< Buffer for converted characters */
1280 size_t ibuflen; /**< Length of input buffer */
1281 size_t obuflen; /**< Length of output buffer */
1282 char *osav; /**< Saved pointer to output buffer */
1288 strcpy(reply_to, "");
1289 strcpy(mime_content_type, "text/plain");
1290 strcpy(mime_charset, "us-ascii");
1292 serv_printf("MSG4 %ld", msgnum);
1293 serv_getln(buf, sizeof buf);
1294 if (buf[0] != '1') {
1295 wprintf(_("ERROR:"));
1296 wprintf("%s<br />", &buf[4]);
1300 strcpy(m_subject, "");
1302 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1303 if (!strcmp(buf, "000")) {
1304 wprintf(_("unexpected end of message"));
1307 if (include_headers) {
1308 if (!strncasecmp(buf, "nhdr=yes", 8))
1312 if (!strncasecmp(buf, "type=", 5))
1313 format_type = atoi(&buf[5]);
1314 if (!strncasecmp(buf, "from=", 5)) {
1315 strcpy(from, &buf[5]);
1316 wprintf(_("from "));
1318 utf8ify_rfc822_string(from);
1322 if (!strncasecmp(buf, "subj=", 5)) {
1323 strcpy(m_subject, &buf[5]);
1325 if ((!strncasecmp(buf, "hnod=", 5))
1326 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1327 wprintf("(%s) ", &buf[5]);
1329 if ((!strncasecmp(buf, "room=", 5))
1330 && (strcasecmp(&buf[5], WC->wc_roomname))
1331 && (strlen(&buf[5])>0) ) {
1333 wprintf("%s> ", &buf[5]);
1335 if (!strncasecmp(buf, "rfca=", 5)) {
1336 strcpy(rfca, &buf[5]);
1342 if (!strncasecmp(buf, "node=", 5)) {
1343 strcpy(node, &buf[5]);
1344 if ( ((WC->room_flags & QR_NETWORK)
1345 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1346 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1347 && (strlen(rfca)==0)
1349 wprintf("@%s ", &buf[5]);
1352 if (!strncasecmp(buf, "rcpt=", 5)) {
1354 wprintf("%s ", &buf[5]);
1356 if (!strncasecmp(buf, "time=", 5)) {
1357 fmt_date(now, atol(&buf[5]), 0);
1358 wprintf("%s ", now);
1363 * Save attachment info for later. We can't start downloading them
1364 * yet because we're in the middle of a server transaction.
1366 if (!strncasecmp(buf, "part=", 5)) {
1367 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1370 sprintf(ptr, "%s%s\n",
1371 ((attachments != NULL) ? attachments : ""),
1376 lprintf(9, "attachments=<%s>\n", attachments);
1382 if (include_headers) {
1386 utf8ify_rfc822_string(m_subject);
1388 if (strlen(m_subject) > 0) {
1389 wprintf(_("Subject:"));
1391 msgescputs(m_subject);
1402 * Learn the content type
1404 strcpy(mime_content_type, "text/plain");
1405 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1406 if (!strcmp(buf, "000")) {
1407 wprintf(_("unexpected end of message"));
1410 if (!strncasecmp(buf, "Content-type: ", 14)) {
1411 safestrncpy(mime_content_type, &buf[14],
1412 sizeof(mime_content_type));
1413 for (i=0; i<strlen(mime_content_type); ++i) {
1414 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1415 safestrncpy(mime_charset, &mime_content_type[i+8],
1416 sizeof mime_charset);
1419 for (i=0; i<strlen(mime_content_type); ++i) {
1420 if (mime_content_type[i] == ';') {
1421 mime_content_type[i] = 0;
1424 for (i=0; i<strlen(mime_charset); ++i) {
1425 if (mime_charset[i] == ';') {
1426 mime_charset[i] = 0;
1432 /** Set up a character set conversion if we need to (and if we can) */
1434 if ( (strcasecmp(mime_charset, "us-ascii"))
1435 && (strcasecmp(mime_charset, "UTF-8"))
1436 && (strcasecmp(mime_charset, ""))
1438 ic = ctdl_iconv_open("UTF-8", mime_charset);
1439 if (ic == (iconv_t)(-1) ) {
1440 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1441 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1446 /** Messages in legacy Citadel variformat get handled thusly... */
1447 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1451 /* Boring old 80-column fixed format text gets handled this way... */
1452 else if (!strcasecmp(mime_content_type, "text/plain")) {
1453 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1454 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1455 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1458 if (ic != (iconv_t)(-1) ) {
1460 ibuflen = strlen(ibuf);
1462 obuf = (char *) malloc(obuflen);
1464 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1465 osav[SIZ-obuflen] = 0;
1466 safestrncpy(buf, osav, sizeof buf);
1471 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1472 buf[strlen(buf) - 1] = 0;
1474 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1475 wprintf("<blockquote>");
1477 } else if ((bq == 1) &&
1478 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1479 wprintf("</blockquote>");
1485 wprintf("</tt><br />");
1487 wprintf("</i><br />");
1490 /** HTML just gets escaped and stuffed back into the editor */
1491 else if (!strcasecmp(mime_content_type, "text/html")) {
1492 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1498 /** Unknown weirdness ... don't know how to handle this content type */
1500 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1504 /** end of body handler */
1507 * If there were attachments, we have to download them and insert them
1508 * into the attachment chain for the forwarded message we are composing.
1510 if ( (forward_attachments) && (num_attachments) ) {
1511 for (i=0; i<num_attachments; ++i) {
1512 extract_token(buf, attachments, i, '\n', sizeof buf);
1513 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1514 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1515 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1516 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1517 mime_length = extract_int(buf, 5);
1520 * tracing ... uncomment if necessary
1523 lprintf(9, "fwd filename: %s\n", mime_filename);
1524 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1525 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1526 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1527 lprintf(9, "fwd length : %d\n", mime_length);
1529 if ( (!strcasecmp(mime_disposition, "inline"))
1530 || (!strcasecmp(mime_disposition, "attachment")) ) {
1532 /* Create an attachment struct from this mime part... */
1533 att = malloc(sizeof(struct wc_attachment));
1534 memset(att, 0, sizeof(struct wc_attachment));
1535 att->length = mime_length;
1536 strcpy(att->content_type, mime_content_type);
1537 strcpy(att->filename, mime_filename);
1539 att->data = load_mimepart(msgnum, mime_partnum);
1541 /* And add it to the list. */
1542 if (WC->first_attachment == NULL) {
1543 WC->first_attachment = att;
1546 aptr = WC->first_attachment;
1547 while (aptr->next != NULL) aptr = aptr->next;
1556 if (ic != (iconv_t)(-1) ) {
1561 if (attachments != NULL) {
1567 * \brief Display one row in the mailbox summary view
1569 * \param num The row number to be displayed
1571 void display_summarized(int num) {
1574 wprintf("<tr id=\"m%ld\" style=\"width:100%%;font-weight:%s;background-color:#ffffff\" "
1575 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1576 WC->summ[num].msgnum,
1577 (WC->summ[num].is_new ? "bold" : "normal"),
1578 WC->summ[num].msgnum
1581 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1582 escputs(WC->summ[num].subj);
1585 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1586 escputs(WC->summ[num].from);
1589 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1590 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1600 * \brief display the adressbook overview
1601 * \param msgnum the citadel message number
1602 * \param alpha what????
1604 void display_addressbook(long msgnum, char alpha) {
1606 char mime_partnum[SIZ];
1607 char mime_filename[SIZ];
1608 char mime_content_type[SIZ];
1609 char mime_disposition[SIZ];
1611 char vcard_partnum[SIZ];
1612 char *vcard_source = NULL;
1613 struct message_summary summ;
1615 memset(&summ, 0, sizeof(summ));
1616 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1618 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1620 serv_getln(buf, sizeof buf);
1621 if (buf[0] != '1') return;
1623 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1624 if (!strncasecmp(buf, "part=", 5)) {
1625 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1626 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1627 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1628 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1629 mime_length = extract_int(&buf[5], 5);
1631 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1632 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1633 strcpy(vcard_partnum, mime_partnum);
1639 if (strlen(vcard_partnum) > 0) {
1640 vcard_source = load_mimepart(msgnum, vcard_partnum);
1641 if (vcard_source != NULL) {
1643 /** Display the summary line */
1644 display_vcard(vcard_source, alpha, 0, NULL);
1646 /** If it's my vCard I can edit it */
1647 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1648 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1649 || (WC->wc_view == VIEW_ADDRESSBOOK)
1651 wprintf("<a href=\"edit_vcard?"
1652 "msgnum=%ld?partnum=%s\">",
1653 msgnum, vcard_partnum);
1654 wprintf("[%s]</a>", _("edit"));
1666 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1667 * \param namebuf name to analyze, reverse if nescessary
1669 void lastfirst_firstlast(char *namebuf) {
1670 char firstname[SIZ];
1674 if (namebuf == NULL) return;
1675 if (strchr(namebuf, ';') != NULL) return;
1677 i = num_tokens(namebuf, ' ');
1680 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1681 remove_token(namebuf, i-1, ' ');
1682 strcpy(firstname, namebuf);
1683 sprintf(namebuf, "%s; %s", lastname, firstname);
1687 * \brief fetch what??? name
1688 * \param msgnum the citadel message number
1689 * \param namebuf where to put the name in???
1691 void fetch_ab_name(long msgnum, char *namebuf) {
1693 char mime_partnum[SIZ];
1694 char mime_filename[SIZ];
1695 char mime_content_type[SIZ];
1696 char mime_disposition[SIZ];
1698 char vcard_partnum[SIZ];
1699 char *vcard_source = NULL;
1701 struct message_summary summ;
1703 if (namebuf == NULL) return;
1704 strcpy(namebuf, "");
1706 memset(&summ, 0, sizeof(summ));
1707 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1709 sprintf(buf, "MSG0 %ld|0", msgnum); /** unfortunately we need the mime info now */
1711 serv_getln(buf, sizeof buf);
1712 if (buf[0] != '1') return;
1714 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1715 if (!strncasecmp(buf, "part=", 5)) {
1716 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1717 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1718 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1719 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1720 mime_length = extract_int(&buf[5], 5);
1722 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1723 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1724 strcpy(vcard_partnum, mime_partnum);
1730 if (strlen(vcard_partnum) > 0) {
1731 vcard_source = load_mimepart(msgnum, vcard_partnum);
1732 if (vcard_source != NULL) {
1734 /* Grab the name off the card */
1735 display_vcard(vcard_source, 0, 0, namebuf);
1741 lastfirst_firstlast(namebuf);
1743 for (i=0; i<strlen(namebuf); ++i) {
1744 if (namebuf[i] != ';') return;
1746 strcpy(namebuf, _("(no name)"));
1752 * \brief Record compare function for sorting address book indices
1753 * \param ab1 adressbook one
1754 * \param ab2 adressbook two
1756 int abcmp(const void *ab1, const void *ab2) {
1758 (((const struct addrbookent *)ab1)->ab_name),
1759 (((const struct addrbookent *)ab2)->ab_name)
1765 * \brief Helper function for do_addrbook_view()
1766 * Converts a name into a three-letter tab label
1767 * \param tabbuf the tabbuffer to add name to
1768 * \param name the name to add to the tabbuffer
1770 void nametab(char *tabbuf, char *name) {
1771 stresc(tabbuf, name, 0, 0);
1772 tabbuf[0] = toupper(tabbuf[0]);
1773 tabbuf[1] = tolower(tabbuf[1]);
1774 tabbuf[2] = tolower(tabbuf[2]);
1780 * \brief Render the address book using info we gathered during the scan
1781 * \param addrbook the addressbook to render
1782 * \param num_ab the number of the addressbook
1784 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1788 static int NAMESPERPAGE = 60;
1792 char tabfirst_label[SIZ];
1794 char tablast_label[SIZ];
1797 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1798 wprintf(_("This address book is empty."));
1799 wprintf("</i></div>\n");
1804 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1807 num_pages = num_ab / NAMESPERPAGE;
1809 page = atoi(bstr("page"));
1812 for (i=0; i<=num_pages; ++i) {
1814 wprintf("<a href=\"readfwd?page=%d\">", i);
1819 tabfirst = i * NAMESPERPAGE;
1820 tablast = tabfirst + NAMESPERPAGE - 1;
1821 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1822 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1823 nametab(tablast_label, addrbook[tablast].ab_name);
1824 wprintf("[%s - %s]",
1825 tabfirst_label, tablast_label
1834 wprintf("<br />\n");
1836 wprintf("<table border=0 cellspacing=0 "
1837 "cellpadding=3 width=100%%>\n"
1840 for (i=0; i<num_ab; ++i) {
1842 if ((i / NAMESPERPAGE) == page) {
1844 if ((displayed % 4) == 0) {
1845 if (displayed > 0) {
1849 wprintf("<tr bgcolor=\"#%s\">",
1850 (bg ? "DDDDDD" : "FFFFFF")
1856 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
1857 addrbook[i].ab_msgnum);
1858 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1859 vcard_n_prettyize(addrbook[i].ab_name);
1860 escputs(addrbook[i].ab_name);
1861 wprintf("</a></td>\n");
1866 wprintf("</tr></table>\n");
1872 * \brief load message pointers from the server
1873 * \param servcmd the citadel command to send to the citserver
1874 * \param with_headers what headers???
1876 int load_msg_ptrs(char *servcmd, int with_headers)
1887 int num_summ_alloc = 0;
1889 if (WC->summ != NULL) {
1894 num_summ_alloc = 100;
1896 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1899 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1901 serv_getln(buf, sizeof buf);
1902 if (buf[0] != '1') {
1905 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1906 if (nummsgs < maxload) {
1907 WC->msgarr[nummsgs] = extract_long(buf, 0);
1908 datestamp = extract_long(buf, 1);
1909 extract_token(fullname, buf, 2, '|', sizeof fullname);
1910 extract_token(nodename, buf, 3, '|', sizeof nodename);
1911 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1912 extract_token(subject, buf, 5, '|', sizeof subject);
1916 if (nummsgs > num_summ_alloc) {
1917 num_summ_alloc *= 2;
1918 WC->summ = realloc(WC->summ,
1919 num_summ_alloc * sizeof(struct message_summary));
1923 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1924 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1925 safestrncpy(WC->summ[nummsgs-1].subj,
1926 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1927 if (strlen(fullname) > 0) {
1928 safestrncpy(WC->summ[nummsgs-1].from,
1929 fullname, sizeof WC->summ[nummsgs-1].from);
1931 if (strlen(subject) > 0) {
1932 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1933 sizeof WC->summ[nummsgs-1].subj);
1936 /** Handle subjects with RFC2047 encoding */
1937 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1939 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1940 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1943 if (strlen(nodename) > 0) {
1944 if ( ((WC->room_flags & QR_NETWORK)
1945 || ((strcasecmp(nodename, serv_info.serv_nodename)
1946 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1948 strcat(WC->summ[nummsgs-1].from, " @ ");
1949 strcat(WC->summ[nummsgs-1].from, nodename);
1953 WC->summ[nummsgs-1].date = datestamp;
1956 /** Handle senders with RFC2047 encoding */
1957 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1959 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1960 strcpy(&WC->summ[nummsgs-1].from[22], "...");
1969 * \brief qsort() compatible function to compare two longs in descending order.
1971 * \param s1 first number to compare
1972 * \param s2 second number to compare
1974 int longcmp_r(const void *s1, const void *s2) {
1981 if (l1 > l2) return(-1);
1982 if (l1 < l2) return(+1);
1988 * \brief qsort() compatible function to compare two message summary structs by ascending subject.
1990 * \param s1 first item to compare
1991 * \param s2 second item to compare
1993 int summcmp_subj(const void *s1, const void *s2) {
1994 struct message_summary *summ1;
1995 struct message_summary *summ2;
1997 summ1 = (struct message_summary *)s1;
1998 summ2 = (struct message_summary *)s2;
1999 return strcasecmp(summ1->subj, summ2->subj);
2003 * \brief qsort() compatible function to compare two message summary structs by descending subject.
2005 * \param s1 first item to compare
2006 * \param s2 second item to compare
2008 int summcmp_rsubj(const void *s1, const void *s2) {
2009 struct message_summary *summ1;
2010 struct message_summary *summ2;
2012 summ1 = (struct message_summary *)s1;
2013 summ2 = (struct message_summary *)s2;
2014 return strcasecmp(summ2->subj, summ1->subj);
2018 * \brief qsort() compatible function to compare two message summary structs by ascending sender.
2020 * \param s1 first item to compare
2021 * \param s2 second item to compare
2023 int summcmp_sender(const void *s1, const void *s2) {
2024 struct message_summary *summ1;
2025 struct message_summary *summ2;
2027 summ1 = (struct message_summary *)s1;
2028 summ2 = (struct message_summary *)s2;
2029 return strcasecmp(summ1->from, summ2->from);
2033 * \brief qsort() compatible function to compare two message summary structs by descending sender.
2035 * \param s1 first item to compare
2036 * \param s2 second item to compare
2038 int summcmp_rsender(const void *s1, const void *s2) {
2039 struct message_summary *summ1;
2040 struct message_summary *summ2;
2042 summ1 = (struct message_summary *)s1;
2043 summ2 = (struct message_summary *)s2;
2044 return strcasecmp(summ2->from, summ1->from);
2048 * \brief qsort() compatible function to compare two message summary structs by ascending date.
2050 * \param s1 first item to compare
2051 * \param s2 second item to compare
2053 int summcmp_date(const void *s1, const void *s2) {
2054 struct message_summary *summ1;
2055 struct message_summary *summ2;
2057 summ1 = (struct message_summary *)s1;
2058 summ2 = (struct message_summary *)s2;
2060 if (summ1->date < summ2->date) return -1;
2061 else if (summ1->date > summ2->date) return +1;
2066 * \brief qsort() compatible function to compare two message summary structs by descending date.
2068 * \param s1 first item to compare
2069 * \param s2 second item to compare
2071 int summcmp_rdate(const void *s1, const void *s2) {
2072 struct message_summary *summ1;
2073 struct message_summary *summ2;
2075 summ1 = (struct message_summary *)s1;
2076 summ2 = (struct message_summary *)s2;
2078 if (summ1->date < summ2->date) return +1;
2079 else if (summ1->date > summ2->date) return -1;
2086 * \brief command loop for reading messages
2088 * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
2090 void readloop(char *oper)
2099 long *displayed_msgs = NULL;
2100 int num_displayed = 0;
2102 int is_addressbook = 0;
2103 int is_singlecard = 0;
2104 int is_calendar = 0;
2109 int lowest_displayed = (-1);
2110 int highest_displayed = 0;
2111 struct addrbookent *addrbook = NULL;
2113 char *sortby = NULL;
2114 char sortpref_name[128];
2115 char sortpref_value[128];
2116 char *subjsort_button;
2117 char *sendsort_button;
2118 char *datesort_button;
2119 int bbs_reverse = 0;
2121 if (WC->wc_view == VIEW_WIKI) {
2122 sprintf(buf, "wiki?room=%s?page=home", WC->wc_roomname);
2127 startmsg = atol(bstr("startmsg"));
2128 maxmsgs = atoi(bstr("maxmsgs"));
2129 is_summary = atoi(bstr("summary"));
2130 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2132 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
2133 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
2135 sortby = bstr("sortby");
2136 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
2137 set_preference(sortpref_name, sortby, 1);
2139 if (strlen(sortby) == 0) sortby = sortpref_value;
2142 if (strlen(sortby) == 0) sortby = "rdate";
2144 /** message board sort */
2145 if (!strcasecmp(sortby, "reverse")) {
2152 output_headers(1, 1, 1, 0, 0, 0);
2155 * When in summary mode, always show ALL messages instead of just
2156 * new or old. Otherwise, show what the user asked for.
2158 if (!strcmp(oper, "readnew")) {
2159 strcpy(cmd, "MSGS NEW");
2161 else if (!strcmp(oper, "readold")) {
2162 strcpy(cmd, "MSGS OLD");
2164 else if (!strcmp(oper, "do_search")) {
2165 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2168 strcpy(cmd, "MSGS ALL");
2171 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
2173 if (!strcmp(oper, "do_search")) {
2174 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2177 strcpy(cmd, "MSGS ALL");
2181 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2183 if (!strcmp(oper, "do_search")) {
2184 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2187 strcpy(cmd, "MSGS ALL");
2192 if (is_summary) { /**< fetch header summary */
2193 snprintf(cmd, sizeof cmd, "MSGS %s|%s||1",
2194 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2195 (!strcmp(oper, "do_search") ? bstr("query") : "")
2202 * Are we doing a summary view? If so, we need to know old messages
2203 * and new messages, so we can do that pretty boldface thing for the
2206 strcpy(old_msgs, "");
2209 serv_getln(buf, sizeof buf);
2210 if (buf[0] == '2') {
2211 strcpy(old_msgs, &buf[4]);
2215 is_singlecard = atoi(bstr("is_singlecard"));
2217 if (WC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2219 strcpy(cmd, "MSGS ALL");
2222 if (WC->wc_default_view == VIEW_TASKS) { /**< tasks */
2224 strcpy(cmd, "MSGS ALL");
2227 if (WC->wc_default_view == VIEW_NOTES) { /**< notes */
2229 strcpy(cmd, "MSGS ALL");
2234 wprintf("<div align=center>%s</div>\n", _("Click on any note to edit it."));
2235 wprintf("<div id=\"new_notes_here\"></div>\n");
2238 nummsgs = load_msg_ptrs(cmd, is_summary);
2241 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2242 wprintf("<div align=\"center\"><br /><em>");
2243 if (!strcmp(oper, "readnew")) {
2244 wprintf(_("No new messages."));
2245 } else if (!strcmp(oper, "readold")) {
2246 wprintf(_("No old messages."));
2248 wprintf(_("No messages here."));
2250 wprintf("</em><br /></div>\n");
2257 for (a = 0; a < nummsgs; ++a) {
2258 /** Are you a new message, or an old message? */
2260 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
2261 WC->summ[a].is_new = 0;
2264 WC->summ[a].is_new = 1;
2270 if (startmsg == 0L) {
2272 startmsg = WC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2275 startmsg = WC->msgarr[0];
2280 if (!strcasecmp(sortby, "subject")) {
2281 qsort(WC->summ, WC->num_summ,
2282 sizeof(struct message_summary), summcmp_subj);
2284 else if (!strcasecmp(sortby, "rsubject")) {
2285 qsort(WC->summ, WC->num_summ,
2286 sizeof(struct message_summary), summcmp_rsubj);
2288 else if (!strcasecmp(sortby, "sender")) {
2289 qsort(WC->summ, WC->num_summ,
2290 sizeof(struct message_summary), summcmp_sender);
2292 else if (!strcasecmp(sortby, "rsender")) {
2293 qsort(WC->summ, WC->num_summ,
2294 sizeof(struct message_summary), summcmp_rsender);
2296 else if (!strcasecmp(sortby, "date")) {
2297 qsort(WC->summ, WC->num_summ,
2298 sizeof(struct message_summary), summcmp_date);
2300 else if (!strcasecmp(sortby, "rdate")) {
2301 qsort(WC->summ, WC->num_summ,
2302 sizeof(struct message_summary), summcmp_rdate);
2306 if (!strcasecmp(sortby, "subject")) {
2307 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2309 else if (!strcasecmp(sortby, "rsubject")) {
2310 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2313 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2316 if (!strcasecmp(sortby, "sender")) {
2317 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2319 else if (!strcasecmp(sortby, "rsender")) {
2320 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2323 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2326 if (!strcasecmp(sortby, "date")) {
2327 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2329 else if (!strcasecmp(sortby, "rdate")) {
2330 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2333 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2337 wprintf("</div>\n"); /** end of 'content' div */
2339 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2340 " document.onkeydown = CtdlMsgListKeyPress; "
2341 " if (document.layers) { "
2342 " document.captureEvents(Event.KEYPRESS); "
2347 /** note that Date and Delete are now in the same column */
2348 wprintf("<div id=\"message_list_hdr\">"
2349 "<div class=\"fix_scrollbar_bug\">"
2350 "<table cellspacing=0 style=\"width:100%%\">"
2353 wprintf("<td width=%d%%><b><i>%s</i></b> %s</td>"
2354 "<td width=%d%%><b><i>%s</i></b> %s</td>"
2355 "<td width=%d%%><b><i>%s</i></b> %s"
2357 "<input type=\"submit\" name=\"delete_button\" style=\"font-size:6pt\" "
2358 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2364 _("Subject"), subjsort_button,
2365 SENDER_COL_WIDTH_PCT,
2366 _("Sender"), sendsort_button,
2367 DATE_PLUS_BUTTONS_WIDTH_PCT,
2368 _("Date"), datesort_button,
2371 wprintf("</table></div></div>\n");
2373 wprintf("<div id=\"message_list\">"
2375 "<div class=\"fix_scrollbar_bug\">\n"
2377 "<table class=\"mailbox_summary\" id=\"summary_headers\" rules=rows "
2378 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2382 for (a = 0; a < nummsgs; ++a) {
2383 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2385 /** Display the message */
2387 display_summarized(a);
2389 else if (is_addressbook) {
2390 fetch_ab_name(WC->msgarr[a], buf);
2392 addrbook = realloc(addrbook,
2393 (sizeof(struct addrbookent) * num_ab) );
2394 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2395 sizeof(addrbook[num_ab-1].ab_name));
2396 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
2398 else if (is_calendar) {
2399 display_calendar(WC->msgarr[a]);
2401 else if (is_tasks) {
2402 display_task(WC->msgarr[a]);
2404 else if (is_notes) {
2405 display_note(WC->msgarr[a]);
2408 if (displayed_msgs == NULL) {
2409 displayed_msgs = malloc(sizeof(long) *
2410 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2412 displayed_msgs[num_displayed] = WC->msgarr[a];
2415 if (lowest_displayed < 0) lowest_displayed = a;
2416 highest_displayed = a;
2423 * Set the "is_bbview" variable if it appears that we are looking at
2424 * a classic bulletin board view.
2426 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2427 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2432 if (displayed_msgs != NULL) {
2434 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2437 /** if we do a split bbview in the future, begin messages div here */
2439 for (a=0; a<num_displayed; ++a) {
2440 read_message(displayed_msgs[a], 0, "");
2443 /** if we do a split bbview in the future, end messages div here */
2445 free(displayed_msgs);
2446 displayed_msgs = NULL;
2451 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2452 wprintf("</div>"); /**< end of 'message_list' div */
2454 /** Here's the grab-it-to-resize-the-message-list widget */
2455 wprintf("<div id=\"resize_msglist\" "
2456 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2457 "<div class=\"fix_scrollbar_bug\">"
2458 "<table width=100%% border=3 cellspacing=0 "
2459 "bgcolor=\"#cccccc\" "
2460 "cellpadding=0><TR><TD> </td></tr></table>"
2464 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2468 * Bump these because although we're thinking in zero base, the user
2469 * is a drooling idiot and is thinking in one base.
2472 ++highest_displayed;
2475 * If we're not currently looking at ALL requested
2476 * messages, then display the selector bar
2479 /** begin bbview scroller */
2480 wprintf("<form name=\"msgomatic\">");
2481 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2483 wprintf("<select name=\"whichones\" size=\"1\" "
2484 "OnChange=\"location.href=msgomatic.whichones.options"
2485 "[selectedIndex].value\">\n");
2488 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2490 lo = b - maxmsgs + 2;
2492 wprintf("<option %s value="
2497 "%d-%d</option> \n",
2498 ((WC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2507 for (b=0; b<nummsgs; b = b + maxmsgs) {
2509 hi = b + maxmsgs + 1;
2510 if (hi > nummsgs) hi = nummsgs;
2511 wprintf("<option %s value="
2516 "%d-%d</option> \n",
2517 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2526 wprintf("<option value=\"%s?startmsg=%ld"
2527 "?maxmsgs=9999999?summary=%d\">"
2531 WC->msgarr[0], is_summary);
2533 wprintf("</select> ");
2534 wprintf(_("of %d messages."), nummsgs);
2536 /** forward/reverse */
2537 wprintf(" <select name=\"direction\" size=\"1\" "
2538 "OnChange=\"location.href=msgomatic.direction.options"
2539 "[selectedIndex].value\">\n"
2542 wprintf("<option %s value=\"%s?sortby=forward\">oldest to newest</option>\n",
2543 (bbs_reverse ? "" : "selected"),
2547 wprintf("<option %s value=\"%s?sortby=reverse\">newest to oldest</option>\n",
2548 (bbs_reverse ? "selected" : ""),
2552 wprintf("</select></form>\n");
2553 /** end bbview scroller */
2558 do_tasks_view(); /** Render the task list */
2562 do_calendar_view(); /** Render the calendar */
2565 if (is_addressbook) {
2566 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2569 /** Note: wDumpContent() will output one additional </div> tag. */
2571 if (addrbook != NULL) free(addrbook);
2573 /** free the summary */
2574 if (WC->summ != NULL) {
2583 * \brief Back end for post_message()
2584 * ... this is where the actual message gets transmitted to the server.
2586 void post_mime_to_server(void) {
2588 int is_multipart = 0;
2590 struct wc_attachment *att;
2592 size_t encoded_length;
2594 /** RFC2045 requires this, and some clients look for it... */
2595 serv_puts("MIME-Version: 1.0");
2596 serv_puts("X-Mailer: " SERVER);
2598 /** If there are attachments, we have to do multipart/mixed */
2599 if (WC->first_attachment != NULL) {
2604 sprintf(boundary, "Citadel--Multipart--%s--%04x--%04x",
2605 serv_info.serv_fqdn,
2610 /** Remember, serv_printf() appends an extra newline */
2611 serv_printf("Content-type: multipart/mixed; "
2612 "boundary=\"%s\"\n", boundary);
2613 serv_printf("This is a multipart message in MIME format.\n");
2614 serv_printf("--%s", boundary);
2617 serv_puts("Content-type: text/html; charset=utf-8");
2618 serv_puts("Content-Transfer-Encoding: quoted-printable");
2620 serv_puts("<html><body>\r\n");
2621 text_to_server_qp(bstr("msgtext")); /** Transmit message in quoted-printable encoding */
2622 serv_puts("</body></html>\r\n");
2626 /** Add in the attachments */
2627 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2629 encoded_length = ((att->length * 150) / 100);
2630 encoded = malloc(encoded_length);
2631 if (encoded == NULL) break;
2632 CtdlEncodeBase64(encoded, att->data, att->length, 1);
2634 serv_printf("--%s", boundary);
2635 serv_printf("Content-type: %s", att->content_type);
2636 serv_printf("Content-disposition: attachment; "
2637 "filename=\"%s\"", att->filename);
2638 serv_puts("Content-transfer-encoding: base64");
2640 serv_write(encoded, strlen(encoded));
2645 serv_printf("--%s--", boundary);
2653 * \brief Post message (or don't post message)
2655 * Note regarding the "dont_post" variable:
2656 * A random value (actually, it's just a timestamp) is inserted as a hidden
2657 * field called "postseq" when the display_enter page is generated. This
2658 * value is checked when posting, using the static variable dont_post. If a
2659 * user attempts to post twice using the same dont_post value, the message is
2660 * discarded. This prevents the accidental double-saving of the same message
2661 * if the user happens to click the browser "back" button.
2663 void post_message(void)
2666 char encoded_subject[1024];
2667 static long dont_post = (-1L);
2668 struct wc_attachment *att, *aptr;
2669 int is_anonymous = 0;
2672 display_name = bstr("display_name");
2673 if (!strcmp(display_name, "__ANONYMOUS__")) {
2678 if (WC->upload_length > 0) {
2680 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WC->upload_length);
2681 /** There's an attachment. Save it to this struct... */
2682 att = malloc(sizeof(struct wc_attachment));
2683 memset(att, 0, sizeof(struct wc_attachment));
2684 att->length = WC->upload_length;
2685 strcpy(att->content_type, WC->upload_content_type);
2686 strcpy(att->filename, WC->upload_filename);
2689 /** And add it to the list. */
2690 if (WC->first_attachment == NULL) {
2691 WC->first_attachment = att;
2694 aptr = WC->first_attachment;
2695 while (aptr->next != NULL) aptr = aptr->next;
2700 * Mozilla sends a simple filename, which is what we want,
2701 * but Satan's Browser sends an entire pathname. Reduce
2702 * the path to just a filename if we need to.
2704 while (num_tokens(att->filename, '/') > 1) {
2705 remove_token(att->filename, 0, '/');
2707 while (num_tokens(att->filename, '\\') > 1) {
2708 remove_token(att->filename, 0, '\\');
2712 * Transfer control of this memory from the upload struct
2713 * to the attachment struct.
2715 att->data = WC->upload;
2716 WC->upload_length = 0;
2722 if (strlen(bstr("cancel_button")) > 0) {
2723 sprintf(WC->ImportantMessage,
2724 _("Cancelled. Message was not posted."));
2725 } else if (strlen(bstr("attach_button")) > 0) {
2728 } else if (atol(bstr("postseq")) == dont_post) {
2729 sprintf(WC->ImportantMessage,
2730 _("Automatically cancelled because you have already "
2731 "saved this message."));
2733 rfc2047encode(encoded_subject, sizeof encoded_subject, bstr("subject"));
2734 sprintf(buf, "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s",
2742 bstr("my_email_addr")
2745 serv_getln(buf, sizeof buf);
2746 if (buf[0] == '4') {
2747 post_mime_to_server();
2748 if ( (strlen(bstr("recp")) > 0)
2749 || (strlen(bstr("cc")) > 0)
2750 || (strlen(bstr("bcc")) > 0)
2752 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2755 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2757 dont_post = atol(bstr("postseq"));
2759 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
2760 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2766 free_attachments(WC);
2769 * We may have been supplied with instructions regarding the location
2770 * to which we must return after posting. If found, go there.
2772 if (strlen(bstr("return_to")) > 0) {
2773 http_redirect(bstr("return_to"));
2776 * If we were editing a page in a wiki room, go to that page now.
2778 else if (strlen(bstr("wikipage")) > 0) {
2779 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
2783 * Otherwise, just go to the "read messages" loop.
2786 readloop("readnew");
2794 * \brief display the message entry screen
2796 void display_enter(void)
2802 struct wc_attachment *att;
2803 int recipient_required = 0;
2804 int recipient_bad = 0;
2806 int is_anonymous = 0;
2807 long existing_page = (-1L);
2811 if (strlen(bstr("force_room")) > 0) {
2812 gotoroom(bstr("force_room"));
2815 display_name = bstr("display_name");
2816 if (!strcmp(display_name, "__ANONYMOUS__")) {
2821 /** First test to see whether this is a room that requires recipients to be entered */
2822 serv_puts("ENT0 0");
2823 serv_getln(buf, sizeof buf);
2824 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
2825 recipient_required = 1;
2827 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2828 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2829 readloop("readnew");
2834 * Are we perhaps in an address book view? If so, then an "enter
2835 * message" command really means "add new entry."
2837 if (WC->wc_default_view == VIEW_ADDRESSBOOK) {
2838 do_edit_vcard(-1, "", "");
2842 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
2844 * Are we perhaps in a calendar room? If so, then an "enter
2845 * message" command really means "add new calendar item."
2847 if (WC->wc_default_view == VIEW_CALENDAR) {
2848 display_edit_event();
2853 * Are we perhaps in a tasks view? If so, then an "enter
2854 * message" command really means "add new task."
2856 if (WC->wc_default_view == VIEW_TASKS) {
2857 display_edit_task();
2863 * Otherwise proceed normally.
2864 * Do a custom room banner with no navbar...
2866 output_headers(1, 1, 2, 0, 0, 0);
2867 wprintf("<div id=\"banner\">\n");
2868 embed_room_banner(NULL, navbar_none);
2869 wprintf("</div>\n");
2870 wprintf("<div id=\"content\">\n"
2871 "<div class=\"fix_scrollbar_bug\">"
2872 "<table class=\"messages_background\"><tr><td>");
2874 /** Now check our actual recipients if there are any */
2875 if (recipient_required) {
2876 sprintf(buf, "ENT0 0|%s|%d|0||%s||%s|%s|%s",
2880 bstr("cc"), bstr("bcc"), bstr("wikipage"));
2882 serv_getln(buf, sizeof buf);
2884 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
2885 if (strlen(bstr("recp")) + strlen(bstr("cc")) + strlen(bstr("bcc")) > 0) {
2889 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2890 wprintf("<em>%s</em><br />\n", &buf[4]);
2895 /** If we got this far, we can display the message entry screen. */
2897 /** begin message entry screen */
2899 "enctype=\"multipart/form-data\" "
2901 "accept-charset=\"UTF-8\" "
2903 "name=\"enterform\""
2905 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2906 if (WC->wc_view == VIEW_WIKI) {
2907 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
2909 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
2913 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2914 fmt_date(buf, now, 0);
2915 wprintf("%s ", buf);
2917 wprintf(_(" <I>from</I> "));
2919 /* Allow the user to select any of his valid screen names */
2921 wprintf("<select name=\"display_name\" size=1>\n");
2924 serv_getln(buf, sizeof buf);
2925 if (buf[0] == '1') {
2926 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2927 wprintf("<option %s value=\"",
2928 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
2933 wprintf("</option>\n");
2937 if (WC->room_flags & QR_ANONOPT) {
2938 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
2939 ((!strcasecmp(bstr("__ANONYMOUS__"), WC->wc_fullname)) ? "selected" : ""),
2944 wprintf("</select>\n");
2946 /* If this is an email (not a post), allow the user to select any of his
2947 * valid email addresses.
2949 if (recipient_required) {
2951 serv_getln(buf, sizeof buf);
2952 if (buf[0] == '1') {
2953 wprintf("<select name=\"my_email_addr\" size=1>\n");
2954 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2955 wprintf("<option value=\"");
2959 wprintf("></option>\n");
2961 wprintf("</select>\n");
2965 wprintf(_(" <I>in</I> "));
2966 escputs(WC->wc_roomname);
2967 wprintf("<br>\n"); /** header bar */
2969 wprintf("<table border=\"0\" width=\"100%%\">\n");
2970 if (recipient_required) {
2972 wprintf("<tr><td>");
2973 wprintf("<font size=-1>");
2977 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
2978 escputs(bstr("recp"));
2979 wprintf("\" size=50 maxlength=1000 />");
2980 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
2981 wprintf("</td><td></td></tr>\n");
2983 wprintf("<tr><td>");
2984 wprintf("<font size=-1>");
2988 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
2989 escputs(bstr("cc"));
2990 wprintf("\" size=50 maxlength=1000 />");
2991 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
2992 wprintf("</td><td></td></tr>\n");
2994 wprintf("<tr><td>");
2995 wprintf("<font size=-1>");
2999 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
3000 escputs(bstr("bcc"));
3001 wprintf("\" size=50 maxlength=1000 />");
3002 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
3003 wprintf("</td><td></td></tr>\n");
3005 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
3006 wprintf("<script type=\"text/javascript\"> \n"
3007 " activate_entmsg_autocompleters(); \n"
3012 wprintf("<tr><td>");
3013 wprintf("<font size=-1>");
3014 wprintf(_("Subject (optional):"));
3017 "<input type=\"text\" name=\"subject\" value=\"");
3018 escputs(bstr("subject"));
3019 wprintf("\" size=50 maxlength=70></td><td>\n");
3021 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3022 if (recipient_required) {
3023 wprintf(_("Send message"));
3025 wprintf(_("Post message"));
3028 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3029 wprintf("</td></tr></table>\n");
3031 wprintf("<center>");
3033 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
3035 /** If we're continuing from a previous edit, put our partially-composed message back... */
3036 msgescputs(bstr("msgtext"));
3038 /* If we're forwarding a message, insert it here... */
3039 if (atol(bstr("fwdquote")) > 0L) {
3040 wprintf("<br><div align=center><i>");
3041 wprintf(_("--- forwarded message ---"));
3042 wprintf("</i></div><br>");
3043 pullquote_message(atol(bstr("fwdquote")), 1, 1);
3046 /** If we're replying quoted, insert the quote here... */
3047 else if (atol(bstr("replyquote")) > 0L) {
3050 pullquote_message(atol(bstr("replyquote")), 0, 1);
3051 wprintf("</blockquote><br>");
3054 /** If we're editing a wiki page, insert the existing page here... */
3055 else if (WC->wc_view == VIEW_WIKI) {
3056 safestrncpy(buf, bstr("wikipage"), sizeof buf);
3057 str_wiki_index(buf);
3058 existing_page = locate_message_by_uid(buf);
3059 if (existing_page >= 0L) {
3060 pullquote_message(existing_page, 1, 0);
3064 /** Insert our signature if appropriate... */
3065 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
3066 get_preference("use_sig", buf, sizeof buf);
3067 if (!strcasecmp(buf, "yes")) {
3068 get_preference("signature", ebuf, sizeof ebuf);
3069 euid_unescapize(buf, ebuf);
3070 wprintf("<br>--<br>");
3071 for (i=0; i<strlen(buf); ++i) {
3072 if (buf[i] == '\n') {
3075 else if (buf[i] == '<') {
3078 else if (buf[i] == '>') {
3081 else if (buf[i] == '&') {
3084 else if (buf[i] == '\"') {
3087 else if (buf[i] == '\'') {
3090 else if (isprint(buf[i])) {
3091 wprintf("%c", buf[i]);
3097 wprintf("</textarea>");
3098 wprintf("</center><br />\n");
3101 * The following script embeds the TinyMCE richedit control, and automatically
3102 * transforms the textarea into a richedit textarea.
3105 "<script language=\"javascript\" type=\"text/javascript\" src=\"tiny_mce/tiny_mce.js\"></script>\n"
3106 "<script language=\"javascript\" type=\"text/javascript\">"
3108 " mode : \"textareas\", width : \"100%%\", browsers : \"msie,gecko\", "
3109 " theme : \"advanced\", plugins : \"iespell\", "
3110 " theme_advanced_buttons1 : \"bold, italic, underline, strikethrough, justifyleft, justifycenter, justifyright, justifyfull, bullist, numlist, cut, copy, paste, link, image, help, forecolor, iespell, code\", "
3111 " theme_advanced_buttons2 : \"\", "
3112 " theme_advanced_buttons3 : \"\", "
3113 " content_css : \"static/webcit-tinymce.css\" "
3119 /** Enumerate any attachments which are already in place... */
3120 wprintf("<img src=\"static/diskette_24x.gif\" border=0 "
3121 "align=middle height=16 width=16> ");
3122 wprintf(_("Attachments:"));
3124 wprintf("<select name=\"which_attachment\" size=1>");
3125 for (att = WC->first_attachment; att != NULL; att = att->next) {
3126 wprintf("<option value=\"");
3127 urlescputs(att->filename);
3129 escputs(att->filename);
3130 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3131 wprintf("</option>\n");
3133 wprintf("</select>");
3135 /** Now offer the ability to attach additional files... */
3136 wprintf(" ");
3137 wprintf(_("Attach file:"));
3138 wprintf(" <input NAME=\"attachfile\" "
3139 "SIZE=16 TYPE=\"file\">\n "
3140 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3142 /** Seth asked for these to be at the top *and* bottom... */
3143 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3144 if (recipient_required) {
3145 wprintf(_("Send message"));
3147 wprintf(_("Post message"));
3150 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3152 /** Make sure we only insert our signature once */
3153 if (strcmp(bstr("sig_inserted"), "yes")) {
3154 wprintf("<INPUT TYPE=\"hidden\" NAME=\"sig_inserted\" VALUE=\"yes\">\n");
3157 wprintf("</form>\n");
3159 wprintf("</td></tr></table></div>\n");
3160 DONE: wDumpContent(1);
3166 * \brief delete a message
3168 void delete_msg(void)
3173 msgid = atol(bstr("msgid"));
3175 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3176 serv_printf("DELE %ld", msgid);
3178 else { /** Otherwise move it to Trash */
3179 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3182 serv_getln(buf, sizeof buf);
3183 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3185 readloop("readnew");
3190 * \brief move a message to another folder
3197 msgid = atol(bstr("msgid"));
3199 if (strlen(bstr("move_button")) > 0) {
3200 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3202 serv_getln(buf, sizeof buf);
3203 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3205 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3208 readloop("readnew");
3216 * \brief Confirm move of a message
3218 void confirm_move_msg(void)
3224 msgid = atol(bstr("msgid"));
3227 output_headers(1, 1, 2, 0, 0, 0);
3228 wprintf("<div id=\"banner\">\n");
3229 wprintf("<TABLE WIDTH=100%% BORDER=0><TR><TD>");
3230 wprintf("<SPAN CLASS=\"titlebar\">");
3231 wprintf(_("Confirm move of message"));
3232 wprintf("</SPAN>\n");
3233 wprintf("</TD></TR></TABLE>\n");
3234 wprintf("</div>\n<div id=\"content\">\n");
3236 wprintf("<CENTER>");
3238 wprintf(_("Move this message to:"));
3239 wprintf("<br />\n");
3241 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3242 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3244 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3246 serv_getln(buf, sizeof buf);
3247 if (buf[0] == '1') {
3248 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3249 extract_token(targ, buf, 0, '|', sizeof targ);
3250 wprintf("<OPTION>");
3255 wprintf("</SELECT>\n");
3256 wprintf("<br />\n");
3258 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3260 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3261 wprintf("</form></CENTER>\n");
3263 wprintf("</CENTER>\n");