5 * \defgroup MsgDisp Functions which deal with the fetching and displaying of messages.
6 * \ingroup WebcitDisplayItems
12 #include "webserver.h"
15 #define SUBJ_COL_WIDTH_PCT 50 /**< Mailbox view column width */
16 #define SENDER_COL_WIDTH_PCT 30 /**< Mailbox view column width */
17 #define DATE_PLUS_BUTTONS_WIDTH_PCT 20 /**< Mailbox view column width */
20 * Address book entry (keep it short and sweet, it's just a quickie lookup
21 * which we can use to get to the real meat and bones later)
24 char ab_name[64]; /**< name string */
25 long ab_msgnum; /**< message number of address book entry */
33 * \brief Wrapper around iconv_open()
34 * Our version adds aliases for non-standard Microsoft charsets
35 * such as 'MS950', aliasing them to names like 'CP950'
37 * \param tocode Target encoding
38 * \param fromcode Source encoding
40 iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode)
42 iconv_t ic = (iconv_t)(-1) ;
43 ic = iconv_open(tocode, fromcode);
44 if (ic == (iconv_t)(-1) ) {
45 char alias_fromcode[64];
46 if ( (strlen(fromcode) == 5) && (!strncasecmp(fromcode, "MS", 2)) ) {
47 safestrncpy(alias_fromcode, fromcode, sizeof alias_fromcode);
48 alias_fromcode[0] = 'C';
49 alias_fromcode[1] = 'P';
50 ic = iconv_open(tocode, alias_fromcode);
58 * \brief Handle subjects with RFC2047 encoding
60 * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=
61 * \param buf the stringbuffer to process
63 void utf8ify_rfc822_string(char *buf) {
69 iconv_t ic = (iconv_t)(-1) ;
70 char *ibuf; /**< Buffer of characters to be converted */
71 char *obuf; /**< Buffer for converted characters */
72 size_t ibuflen; /**< Length of input buffer */
73 size_t obuflen; /**< Length of output buffer */
74 char *isav; /**< Saved pointer to input buffer */
75 char *osav; /**< Saved pointer to output buffer */
78 int illegal_non_rfc2047_encoding = 0;
80 /** Sometimes, badly formed messages contain strings which were simply
81 * written out directly in some foreign character set instead of
82 * using RFC2047 encoding. This is illegal but we will attempt to
83 * handle it anyway by converting from a user-specified default
84 * charset to UTF-8 if we see any nonprintable characters.
86 for (i=0; i<strlen(buf); ++i) {
87 if ((buf[i] < 32) || (buf[i] > 126)) {
88 illegal_non_rfc2047_encoding = 1;
91 if (illegal_non_rfc2047_encoding) {
92 char default_header_charset[128];
93 get_preference("default_header_charset", default_header_charset, sizeof default_header_charset);
94 if ( (strcasecmp(default_header_charset, "UTF-8")) && (strcasecmp(default_header_charset, "us-ascii")) ) {
95 ic = ctdl_iconv_open("UTF-8", default_header_charset);
96 if (ic != (iconv_t)(-1) ) {
99 safestrncpy(ibuf, buf, 1024);
100 ibuflen = strlen(ibuf);
102 obuf = (char *) malloc(obuflen);
104 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
105 osav[1024-obuflen] = 0;
114 /** Now we handle foreign character sets properly encoded
117 while (start=strstr(buf, "=?"), end=strstr(buf, "?="),
118 ((start != NULL) && (end != NULL) && (end > start)) )
120 extract_token(charset, start, 1, '?', sizeof charset);
121 extract_token(encoding, start, 2, '?', sizeof encoding);
122 extract_token(istr, start, 3, '?', sizeof istr);
126 if (!strcasecmp(encoding, "B")) { /**< base64 */
127 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
129 else if (!strcasecmp(encoding, "Q")) { /**< quoted-printable */
130 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, strlen(istr));
133 strcpy(ibuf, istr); /**< unknown encoding */
134 ibuflen = strlen(istr);
137 ic = ctdl_iconv_open("UTF-8", charset);
138 if (ic != (iconv_t)(-1) ) {
140 obuf = (char *) malloc(obuflen);
142 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
143 osav[1024-obuflen] = 0;
148 remove_token(end, 0, '?');
149 remove_token(end, 0, '?');
150 remove_token(end, 0, '?');
151 remove_token(end, 0, '?');
152 strcpy(end, &end[1]);
154 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
163 remove_token(end, 0, '?');
164 remove_token(end, 0, '?');
165 remove_token(end, 0, '?');
166 remove_token(end, 0, '?');
167 strcpy(end, &end[1]);
169 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
176 * Since spammers will go to all sorts of absurd lengths to get their
177 * messages through, there are LOTS of corrupt headers out there.
178 * So, prevent a really badly formed RFC2047 header from throwing
179 * this function into an infinite loop.
182 if (passes > 20) return;
192 * \brief RFC2047-encode a header field if necessary.
193 * If no non-ASCII characters are found, the string
194 * will be copied verbatim without encoding.
196 * \param target Target buffer.
197 * \param maxlen Maximum size of target buffer.
198 * \param source Source string to be encoded.
200 void rfc2047encode(char *target, int maxlen, char *source)
202 int need_to_encode = 0;
206 if (target == NULL) return;
208 for (i=0; i<strlen(source); ++i) {
209 if ((source[i] < 32) || (source[i] > 126)) {
214 if (!need_to_encode) {
215 safestrncpy(target, source, maxlen);
219 strcpy(target, "=?UTF-8?Q?");
220 for (i=0; i<strlen(source); ++i) {
221 ch = (unsigned char) source[i];
222 if ((ch < 32) || (ch > 126) || (ch == 61)) {
223 sprintf(&target[strlen(target)], "=%02X", ch);
226 sprintf(&target[strlen(target)], "%c", ch);
230 strcat(target, "?=");
237 * \brief Look for URL's embedded in a buffer and make them linkable. We use a
238 * target window in order to keep the BBS session in its own window.
239 * \param buf the message buffer
254 for (pos = 0; pos < strlen(buf); ++pos) {
255 if (!strncasecmp(&buf[pos], "http://", 7))
257 if (!strncasecmp(&buf[pos], "ftp://", 6))
264 if ((start > 0) && (buf[start - 1] == '<'))
266 if ((start > 0) && (buf[start - 1] == '['))
268 if ((start > 0) && (buf[start - 1] == '('))
270 if ((start > 0) && (buf[start - 1] == '{'))
273 for (pos = strlen(buf); pos > start; --pos) {
274 if ((buf[pos] == ' ') || (buf[pos] == ench))
278 strncpy(urlbuf, &buf[start], end - start);
279 urlbuf[end - start] = 0;
281 strncpy(outbuf, buf, start);
282 sprintf(&outbuf[start], "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
283 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
284 strcat(outbuf, &buf[end]);
285 if ( strlen(outbuf) < 250 )
291 * \brief Turn a vCard "n" (name) field into something displayable.
292 * \param name the name field to convert
294 void vcard_n_prettyize(char *name)
299 original_name = strdup(name);
300 for (i=0; i<5; ++i) {
301 if (strlen(original_name) > 0) {
302 if (original_name[strlen(original_name)-1] == ' ') {
303 original_name[strlen(original_name)-1] = 0;
305 if (original_name[strlen(original_name)-1] == ';') {
306 original_name[strlen(original_name)-1] = 0;
311 for (i=0; i<strlen(original_name); ++i) {
312 if (original_name[i] == ';') {
316 name[strlen(name)+1] = 0;
317 name[strlen(name)] = original_name[i];
327 * \brief preparse a vcard name
328 * display_vcard() calls this after parsing the textual vCard into
329 * our 'struct vCard' data object.
330 * This gets called instead of display_parsed_vcard() if we are only looking
331 * to extract the person's name instead of displaying the card.
332 * \param v the vcard to retrieve the name from
333 * \param storename where to put the name at
335 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
338 strcpy(storename, "");
340 name = vcard_get_prop(v, "n", 1, 0, 0);
342 strcpy(storename, name);
343 /* vcard_n_prettyize(storename); */
351 * \brief html print a vcard
352 * display_vcard() calls this after parsing the textual vCard into
353 * our 'struct vCard' data object.
355 * Set 'full' to nonzero to display the full card, otherwise it will only
356 * show a summary line.
358 * This code is a bit ugly, so perhaps an explanation is due: we do this
359 * in two passes through the vCard fields. On the first pass, we process
360 * fields we understand, and then render them in a pretty fashion at the
361 * end. Then we make a second pass, outputting all the fields we don't
362 * understand in a simple two-column name/value format.
363 * \param v the vCard to display
364 * \param full display all items of the vcard?
366 void display_parsed_vcard(struct vCard *v, int full) {
372 char *thisname, *thisvalue;
373 char firsttoken[SIZ];
382 strcpy(fullname, "");
390 name = vcard_get_prop(v, "fn", 1, 0, 0);
394 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
395 strcpy(fullname, name);
396 vcard_n_prettyize(fullname);
406 wprintf("<div align=center><table bgcolor=#aaaaaa width=50%%>");
407 for (pass=1; pass<=2; ++pass) {
409 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
411 thisname = strdup(v->prop[i].name);
412 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
414 for (j=0; j<num_tokens(thisname, ';'); ++j) {
415 extract_token(buf, thisname, j, ';', sizeof buf);
416 if (!strcasecmp(buf, "encoding=quoted-printable")) {
418 remove_token(thisname, j, ';');
420 if (!strcasecmp(buf, "encoding=base64")) {
422 remove_token(thisname, j, ';');
427 thisvalue = malloc(strlen(v->prop[i].value) + 50);
428 j = CtdlDecodeQuotedPrintable(
429 thisvalue, v->prop[i].value,
430 strlen(v->prop[i].value) );
434 thisvalue = malloc(strlen(v->prop[i].value) + 50);
436 thisvalue, v->prop[i].value,
437 strlen(v->prop[i].value) );
440 thisvalue = strdup(v->prop[i].value);
443 /** Various fields we may encounter ***/
445 /** N is name, but only if there's no FN already there */
446 if (!strcasecmp(firsttoken, "n")) {
447 if (strlen(fullname) == 0) {
448 strcpy(fullname, thisvalue);
449 vcard_n_prettyize(fullname);
453 /** FN (full name) is a true 'display name' field */
454 else if (!strcasecmp(firsttoken, "fn")) {
455 strcpy(fullname, thisvalue);
459 else if (!strcasecmp(firsttoken, "title")) {
460 strcpy(title, thisvalue);
464 else if (!strcasecmp(firsttoken, "org")) {
465 strcpy(org, thisvalue);
468 else if (!strcasecmp(firsttoken, "email")) {
469 if (strlen(mailto) > 0) strcat(mailto, "<br />");
471 "<a href=\"display_enter"
472 "?force_room=_MAIL_?recp=");
474 urlesc(&mailto[strlen(mailto)], fullname);
475 urlesc(&mailto[strlen(mailto)], " <");
476 urlesc(&mailto[strlen(mailto)], thisvalue);
477 urlesc(&mailto[strlen(mailto)], ">");
479 strcat(mailto, "\">");
480 stresc(&mailto[strlen(mailto)], thisvalue, 1, 1);
481 strcat(mailto, "</A>");
483 else if (!strcasecmp(firsttoken, "tel")) {
484 if (strlen(phone) > 0) strcat(phone, "<br />");
485 strcat(phone, thisvalue);
486 for (j=0; j<num_tokens(thisname, ';'); ++j) {
487 extract_token(buf, thisname, j, ';', sizeof buf);
488 if (!strcasecmp(buf, "tel"))
490 else if (!strcasecmp(buf, "work"))
491 strcat(phone, _(" (work)"));
492 else if (!strcasecmp(buf, "home"))
493 strcat(phone, _(" (home)"));
494 else if (!strcasecmp(buf, "cell"))
495 strcat(phone, _(" (cell)"));
503 else if (!strcasecmp(firsttoken, "adr")) {
506 wprintf(_("Address:"));
507 wprintf("</TD><TD>");
508 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
509 extract_token(buf, thisvalue, j, ';', sizeof buf);
510 if (strlen(buf) > 0) {
512 if (j<3) wprintf("<br />");
516 wprintf("</TD></TR>\n");
519 else if (!strcasecmp(firsttoken, "version")) {
522 else if (!strcasecmp(firsttoken, "rev")) {
525 else if (!strcasecmp(firsttoken, "label")) {
530 /*** Don't show extra fields. They're ugly.
534 wprintf("</TD><TD>");
536 wprintf("</TD></TR>\n");
546 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
547 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
548 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
549 "<FONT SIZE=+1><B>");
551 wprintf("</B></FONT>");
552 if (strlen(title) > 0) {
553 wprintf("<div align=right>");
557 if (strlen(org) > 0) {
558 wprintf("<div align=right>");
562 wprintf("</TD></TR>\n");
564 if (strlen(phone) > 0) {
566 wprintf(_("Telephone:"));
567 wprintf("</td><td>%s</td></tr>\n", phone);
569 if (strlen(mailto) > 0) {
571 wprintf(_("E-mail:"));
572 wprintf("</td><td>%s</td></tr>\n", mailto);
578 wprintf("</table></div>\n");
584 * \brief Display a textual vCard
585 * (Converts to a vCard object and then calls the actual display function)
586 * Set 'full' to nonzero to display the whole card instead of a one-liner.
587 * Or, if "storename" is non-NULL, just store the person's name in that
588 * buffer instead of displaying the card at all.
589 * \param vcard_source the buffer containing the vcard text
590 * \param alpha what???
591 * \param full should we usse all lines?
592 * \param storename where to store???
594 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
600 v = vcard_load(vcard_source);
601 if (v == NULL) return;
603 name = vcard_get_prop(v, "n", 1, 0, 0);
609 if (storename != NULL) {
610 fetchname_parsed_vcard(v, storename);
612 else if ( (alpha == 0)
613 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
614 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
616 display_parsed_vcard(v, full);
624 * \brief I wanna SEE that message!
625 * \param msgnum the citadel number of the message to display
626 * \param printable_view are we doing a print view?
627 * \param section Optional for encapsulated message/rfc822 submessage)
629 void read_message(long msgnum, int printable_view, char *section) {
631 char mime_partnum[256];
632 char mime_filename[256];
633 char mime_content_type[256];
634 char mime_charset[256];
635 char mime_disposition[256];
638 char mime_submessages[256];
645 char reply_all[4096];
651 char vcard_partnum[256];
652 char cal_partnum[256];
653 char *part_source = NULL;
655 iconv_t ic = (iconv_t)(-1) ;
656 char *ibuf; /**< Buffer of characters to be converted */
657 char *obuf; /**< Buffer for converted characters */
658 size_t ibuflen; /**< Length of input buffer */
659 size_t obuflen; /**< Length of output buffer */
660 char *osav; /**< Saved pointer to output buffer */
666 strcpy(reply_to, "");
667 strcpy(reply_all, "");
668 strcpy(vcard_partnum, "");
669 strcpy(cal_partnum, "");
670 strcpy(mime_http, "");
671 strcpy(mime_content_type, "text/plain");
672 strcpy(mime_charset, "us-ascii");
673 strcpy(mime_submessages, "");
675 serv_printf("MSG4 %ld|%s", msgnum, section);
676 serv_getln(buf, sizeof buf);
679 wprintf(_("ERROR:"));
680 wprintf("</STRONG> %s<br />\n", &buf[4]);
684 /** begin everythingamundo table */
685 if (!printable_view) {
686 wprintf("<div class=\"fix_scrollbar_bug\">\n");
687 wprintf("<table width=100%% border=1 cellspacing=0 "
688 "cellpadding=0><TR><TD>\n");
691 /** begin message header table */
692 wprintf("<table width=100%% border=0 cellspacing=0 "
693 "cellpadding=1 bgcolor=\"#CCCCCC\"><tr><td>\n");
695 wprintf("<span class=\"message_header\">");
696 strcpy(m_subject, "");
699 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
700 if (!strcmp(buf, "000")) {
702 wprintf(_("unexpected end of message"));
703 wprintf("</i><br /><br />\n");
704 wprintf("</span>\n");
707 if (!strncasecmp(buf, "nhdr=yes", 8))
711 if (!strncasecmp(buf, "type=", 5))
712 format_type = atoi(&buf[5]);
713 if (!strncasecmp(buf, "from=", 5)) {
714 strcpy(from, &buf[5]);
716 wprintf("<a href=\"showuser?who=");
718 utf8ify_rfc822_string(from);
725 if (!strncasecmp(buf, "subj=", 5)) {
726 safestrncpy(m_subject, &buf[5], sizeof m_subject);
728 if (!strncasecmp(buf, "cccc=", 5)) {
729 safestrncpy(m_cc, &buf[5], sizeof m_cc);
730 if (strlen(reply_all) > 0) {
731 strcat(reply_all, ", ");
733 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
734 (sizeof reply_all - strlen(reply_all)) );
736 if ((!strncasecmp(buf, "hnod=", 5))
737 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
738 wprintf("(%s) ", &buf[5]);
740 if ((!strncasecmp(buf, "room=", 5))
741 && (strcasecmp(&buf[5], WC->wc_roomname))
742 && (strlen(&buf[5])>0) ) {
744 wprintf("%s> ", &buf[5]);
746 if (!strncasecmp(buf, "rfca=", 5)) {
747 strcpy(rfca, &buf[5]);
753 if (!strncasecmp(buf, "node=", 5)) {
754 strcpy(node, &buf[5]);
755 if ( ((WC->room_flags & QR_NETWORK)
756 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
757 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
760 wprintf("@%s ", &buf[5]);
763 if (!strncasecmp(buf, "rcpt=", 5)) {
765 if (strlen(reply_all) > 0) {
766 strcat(reply_all, ", ");
768 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
769 (sizeof reply_all - strlen(reply_all)) );
771 utf8ify_rfc822_string(&buf[5]);
776 if (!strncasecmp(buf, "time=", 5)) {
777 fmt_date(now, atol(&buf[5]), 0);
781 if (!strncasecmp(buf, "part=", 5)) {
782 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
783 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
784 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
785 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
786 mime_length = extract_int(&buf[5], 5);
788 if (!strcasecmp(mime_content_type, "message/rfc822")) {
789 if (strlen(mime_submessages) > 0) {
790 strcat(mime_submessages, "|");
792 strcat(mime_submessages, mime_partnum);
794 else if ((!strcasecmp(mime_disposition, "inline"))
795 && (!strncasecmp(mime_content_type, "image/", 6)) ){
796 snprintf(&mime_http[strlen(mime_http)],
797 (sizeof(mime_http) - strlen(mime_http) - 1),
798 "<img src=\"mimepart/%ld/%s/%s\">",
799 msgnum, mime_partnum, mime_filename);
801 else if ( (!strcasecmp(mime_disposition, "attachment"))
802 || (!strcasecmp(mime_disposition, "inline")) ) {
803 snprintf(&mime_http[strlen(mime_http)],
804 (sizeof(mime_http) - strlen(mime_http) - 1),
805 "<img src=\"static/diskette_24x.gif\" "
806 "border=0 align=middle>\n"
807 "%s (%s, %d bytes) [ "
808 "<a href=\"mimepart/%ld/%s/%s\""
809 "target=\"wc.%ld.%s\">%s</a>"
811 "<a href=\"mimepart_download/%ld/%s/%s\">%s</a>"
814 mime_content_type, mime_length,
815 msgnum, mime_partnum, mime_filename,
816 msgnum, mime_partnum,
818 msgnum, mime_partnum, mime_filename,
823 /** begin handler prep ***/
824 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
825 strcpy(vcard_partnum, mime_partnum);
828 if (!strcasecmp(mime_content_type, "text/calendar")) {
829 strcpy(cal_partnum, mime_partnum);
832 /** end handler prep ***/
838 /** Generate a reply-to address */
839 if (strlen(rfca) > 0) {
840 strcpy(reply_to, rfca);
843 if ( (strlen(node) > 0)
844 && (strcasecmp(node, serv_info.serv_nodename))
845 && (strcasecmp(node, serv_info.serv_humannode)) ) {
846 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
850 snprintf(reply_to, sizeof(reply_to), "%s", from);
860 utf8ify_rfc822_string(m_cc);
861 utf8ify_rfc822_string(m_subject);
863 if (strlen(m_cc) > 0) {
865 "<span class=\"message_subject\">");
871 if (strlen(m_subject) > 0) {
873 "<span class=\"message_subject\">");
874 wprintf(_("Subject:"));
881 /** start msg buttons */
882 if (!printable_view) {
883 wprintf("<td align=right><span class=\"msgbuttons\">\n");
886 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
887 wprintf("<a href=\"display_enter");
888 if (WC->is_mailbox) {
889 wprintf("?replyquote=%ld", msgnum);
892 urlescputs(reply_to);
893 if (strlen(m_subject) > 0) {
894 wprintf("?subject=");
895 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
896 urlescputs(m_subject);
898 wprintf("\">[%s]</a> ", _("Reply"));
902 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
903 if (!WC->is_mailbox) {
904 wprintf("<a href=\"display_enter");
905 wprintf("?replyquote=%ld", msgnum);
907 urlescputs(reply_to);
908 if (strlen(m_subject) > 0) {
909 wprintf("?subject=");
910 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
911 urlescputs(m_subject);
913 wprintf("\">[%s]</a> ", _("ReplyQuoted"));
918 if (WC->wc_view == VIEW_MAILBOX) {
919 wprintf("<a href=\"display_enter");
920 wprintf("?replyquote=%ld", msgnum);
922 urlescputs(reply_to);
924 urlescputs(reply_all);
925 if (strlen(m_subject) > 0) {
926 wprintf("?subject=");
927 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
928 urlescputs(m_subject);
930 wprintf("\">[%s]</a> ", _("ReplyAll"));
934 if (WC->wc_view == VIEW_MAILBOX) {
935 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
936 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
937 urlescputs(m_subject);
938 wprintf("\">[%s]</a> ", _("Forward"));
941 /** If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
942 if ( (WC->is_room_aide) || (WC->is_mailbox) ) {
944 wprintf("<a href=\"confirm_move_msg?msgid=%ld\">[%s]</a> ",
948 wprintf("<a href=\"delete_msg?msgid=%ld\" "
949 "onClick=\"return confirm('%s');\">"
950 "[%s]</a> ", msgnum, _("Delete this message?"), _("Delete")
955 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'); \" >"
956 "[%s]</a>", msgnum, msgnum, _("Headers"));
960 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'); \" >"
961 "[%s]</a>", msgnum, msgnum, _("Print"));
963 wprintf("</span></td>");
966 wprintf("</tr></table>\n");
969 wprintf("<table border=0 width=100%% bgcolor=\"#FFFFFF\" "
970 "cellpadding=1 cellspacing=0><tr><td>");
973 * Learn the content type
975 strcpy(mime_content_type, "text/plain");
976 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
977 if (!strcmp(buf, "000")) {
979 wprintf(_("unexpected end of message"));
980 wprintf("</i><br /><br />\n");
983 if (!strncasecmp(buf, "Content-type: ", 14)) {
984 safestrncpy(mime_content_type, &buf[14],
985 sizeof(mime_content_type));
986 for (i=0; i<strlen(mime_content_type); ++i) {
987 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
988 safestrncpy(mime_charset, &mime_content_type[i+8],
989 sizeof mime_charset);
992 for (i=0; i<strlen(mime_content_type); ++i) {
993 if (mime_content_type[i] == ';') {
994 mime_content_type[i] = 0;
997 for (i=0; i<strlen(mime_charset); ++i) {
998 if (mime_charset[i] == ';') {
1005 /** Set up a character set conversion if we need to (and if we can) */
1007 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
1008 if ( (strcasecmp(mime_charset, "us-ascii"))
1009 && (strcasecmp(mime_charset, "UTF-8"))
1010 && (strcasecmp(mime_charset, ""))
1012 ic = ctdl_iconv_open("UTF-8", mime_charset);
1013 if (ic == (iconv_t)(-1) ) {
1014 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1015 __FILE__, __LINE__, mime_charset, strerror(errno));
1020 /** Messages in legacy Citadel variformat get handled thusly... */
1021 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1025 /** Boring old 80-column fixed format text gets handled this way... */
1026 else if ( (!strcasecmp(mime_content_type, "text/plain"))
1027 || (!strcasecmp(mime_content_type, "text")) ) {
1028 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1029 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1030 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1033 if (ic != (iconv_t)(-1) ) {
1035 ibuflen = strlen(ibuf);
1037 obuf = (char *) malloc(obuflen);
1039 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1040 osav[SIZ-obuflen] = 0;
1041 safestrncpy(buf, osav, sizeof buf);
1046 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1047 buf[strlen(buf) - 1] = 0;
1049 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1050 wprintf("<blockquote>");
1052 } else if ((bq == 1) &&
1053 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1054 wprintf("</blockquote>");
1060 wprintf("</tt><br />\n");
1062 wprintf("</i><br />");
1065 else /** HTML is fun, but we've got to strip it first */
1066 if (!strcasecmp(mime_content_type, "text/html")) {
1067 output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
1070 /** Unknown weirdness */
1072 wprintf(_("I don't know how to display %s"), mime_content_type);
1073 wprintf("<br />\n", mime_content_type);
1074 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1077 /** If there are attached submessages, display them now... */
1078 if ( (strlen(mime_submessages) > 0) && (!section[0]) ) {
1079 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1080 extract_token(buf, mime_submessages, i, '|', sizeof buf);
1081 /** use printable_view to suppress buttons */
1082 wprintf("<blockquote>");
1083 read_message(msgnum, 1, buf);
1084 wprintf("</blockquote>");
1089 /** Afterwards, offer links to download attachments 'n' such */
1090 if ( (strlen(mime_http) > 0) && (!section[0]) ) {
1091 wprintf("%s", mime_http);
1094 /** Handler for vCard parts */
1095 if (strlen(vcard_partnum) > 0) {
1096 part_source = load_mimepart(msgnum, vcard_partnum);
1097 if (part_source != NULL) {
1099 /** If it's my vCard I can edit it */
1100 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1101 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1102 || (WC->wc_view == VIEW_ADDRESSBOOK)
1104 wprintf("<a href=\"edit_vcard?"
1105 "msgnum=%ld?partnum=%s\">",
1106 msgnum, vcard_partnum);
1107 wprintf("[%s]</a>", _("edit"));
1110 /** In all cases, display the full card */
1111 display_vcard(part_source, 0, 1, NULL);
1115 /** Handler for calendar parts */
1116 if (strlen(cal_partnum) > 0) {
1117 part_source = load_mimepart(msgnum, cal_partnum);
1118 if (part_source != NULL) {
1119 cal_process_attachment(part_source,
1120 msgnum, cal_partnum);
1130 wprintf("</td></tr></table>\n");
1132 /** end everythingamundo table */
1133 if (!printable_view) {
1134 wprintf("</td></tr></table>\n");
1135 wprintf("</div><br />\n");
1139 if (ic != (iconv_t)(-1) ) {
1148 * \brief Unadorned HTML output of an individual message, suitable
1149 * for placing in a hidden iframe, for printing, or whatever
1151 * \param msgnum_as_string Message number, as a string instead of as a long int
1153 void embed_message(char *msgnum_as_string) {
1156 msgnum = atol(msgnum_as_string);
1157 begin_ajax_response();
1158 read_message(msgnum, 0, "");
1159 end_ajax_response();
1164 * \brief Printable view of a message
1166 * \param msgnum_as_string Message number, as a string instead of as a long int
1168 void print_message(char *msgnum_as_string) {
1171 msgnum = atol(msgnum_as_string);
1172 output_headers(0, 0, 0, 0, 0, 0);
1174 wprintf("Content-type: text/html\r\n"
1176 "Connection: close\r\n",
1180 wprintf("\r\n\r\n<html>\n"
1181 "<head><title>Printable view</title></head>\n"
1182 "<body onLoad=\" window.print(); window.close(); \">\n"
1185 read_message(msgnum, 1, "");
1187 wprintf("\n</body></html>\n\n");
1194 * \brief Display a message's headers
1196 * \param msgnum_as_string Message number, as a string instead of as a long int
1198 void display_headers(char *msgnum_as_string) {
1202 msgnum = atol(msgnum_as_string);
1203 output_headers(0, 0, 0, 0, 0, 0);
1205 wprintf("Content-type: text/plain\r\n"
1207 "Connection: close\r\n",
1211 serv_printf("MSG2 %ld|3", msgnum);
1212 serv_getln(buf, sizeof buf);
1213 if (buf[0] == '1') {
1214 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1215 wprintf("%s\n", buf);
1225 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1226 * or 'reply quoted' operations.
1228 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1229 * in this function. Doing so would throw a JavaScript error in the
1230 * 'supplied text' argument to the editor.
1232 * \param msgnum Message number of the message we want to quote
1233 * \param forward_attachments Nonzero if we want attachments to be forwarded
1235 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1237 char mime_partnum[256];
1238 char mime_filename[256];
1239 char mime_content_type[256];
1240 char mime_charset[256];
1241 char mime_disposition[256];
1243 char *attachments = NULL;
1245 int num_attachments = 0;
1246 struct wc_attachment *att, *aptr;
1247 char m_subject[256];
1253 int format_type = 0;
1258 iconv_t ic = (iconv_t)(-1) ;
1259 char *ibuf; /**< Buffer of characters to be converted */
1260 char *obuf; /**< Buffer for converted characters */
1261 size_t ibuflen; /**< Length of input buffer */
1262 size_t obuflen; /**< Length of output buffer */
1263 char *osav; /**< Saved pointer to output buffer */
1269 strcpy(reply_to, "");
1270 strcpy(mime_content_type, "text/plain");
1271 strcpy(mime_charset, "us-ascii");
1273 serv_printf("MSG4 %ld", msgnum);
1274 serv_getln(buf, sizeof buf);
1275 if (buf[0] != '1') {
1276 wprintf(_("ERROR:"));
1277 wprintf("%s<br />", &buf[4]);
1281 strcpy(m_subject, "");
1283 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1284 if (!strcmp(buf, "000")) {
1285 wprintf(_("unexpected end of message"));
1288 if (include_headers) {
1289 if (!strncasecmp(buf, "nhdr=yes", 8))
1293 if (!strncasecmp(buf, "type=", 5))
1294 format_type = atoi(&buf[5]);
1295 if (!strncasecmp(buf, "from=", 5)) {
1296 strcpy(from, &buf[5]);
1297 wprintf(_("from "));
1299 utf8ify_rfc822_string(from);
1303 if (!strncasecmp(buf, "subj=", 5)) {
1304 strcpy(m_subject, &buf[5]);
1306 if ((!strncasecmp(buf, "hnod=", 5))
1307 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1308 wprintf("(%s) ", &buf[5]);
1310 if ((!strncasecmp(buf, "room=", 5))
1311 && (strcasecmp(&buf[5], WC->wc_roomname))
1312 && (strlen(&buf[5])>0) ) {
1314 wprintf("%s> ", &buf[5]);
1316 if (!strncasecmp(buf, "rfca=", 5)) {
1317 strcpy(rfca, &buf[5]);
1323 if (!strncasecmp(buf, "node=", 5)) {
1324 strcpy(node, &buf[5]);
1325 if ( ((WC->room_flags & QR_NETWORK)
1326 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1327 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1328 && (strlen(rfca)==0)
1330 wprintf("@%s ", &buf[5]);
1333 if (!strncasecmp(buf, "rcpt=", 5)) {
1335 wprintf("%s ", &buf[5]);
1337 if (!strncasecmp(buf, "time=", 5)) {
1338 fmt_date(now, atol(&buf[5]), 0);
1339 wprintf("%s ", now);
1344 * Save attachment info for later. We can't start downloading them
1345 * yet because we're in the middle of a server transaction.
1347 if (!strncasecmp(buf, "part=", 5)) {
1348 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1351 sprintf(ptr, "%s%s\n",
1352 ((attachments != NULL) ? attachments : ""),
1357 lprintf(9, "attachments=<%s>\n", attachments);
1363 if (include_headers) {
1367 utf8ify_rfc822_string(m_subject);
1369 if (strlen(m_subject) > 0) {
1370 wprintf(_("Subject:"));
1372 msgescputs(m_subject);
1383 * Learn the content type
1385 strcpy(mime_content_type, "text/plain");
1386 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1387 if (!strcmp(buf, "000")) {
1388 wprintf(_("unexpected end of message"));
1391 if (!strncasecmp(buf, "Content-type: ", 14)) {
1392 safestrncpy(mime_content_type, &buf[14],
1393 sizeof(mime_content_type));
1394 for (i=0; i<strlen(mime_content_type); ++i) {
1395 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1396 safestrncpy(mime_charset, &mime_content_type[i+8],
1397 sizeof mime_charset);
1400 for (i=0; i<strlen(mime_content_type); ++i) {
1401 if (mime_content_type[i] == ';') {
1402 mime_content_type[i] = 0;
1405 for (i=0; i<strlen(mime_charset); ++i) {
1406 if (mime_charset[i] == ';') {
1407 mime_charset[i] = 0;
1413 /** Set up a character set conversion if we need to (and if we can) */
1415 if ( (strcasecmp(mime_charset, "us-ascii"))
1416 && (strcasecmp(mime_charset, "UTF-8"))
1417 && (strcasecmp(mime_charset, ""))
1419 ic = ctdl_iconv_open("UTF-8", mime_charset);
1420 if (ic == (iconv_t)(-1) ) {
1421 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1422 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1427 /** Messages in legacy Citadel variformat get handled thusly... */
1428 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1432 /* Boring old 80-column fixed format text gets handled this way... */
1433 else if (!strcasecmp(mime_content_type, "text/plain")) {
1434 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1435 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1436 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1439 if (ic != (iconv_t)(-1) ) {
1441 ibuflen = strlen(ibuf);
1443 obuf = (char *) malloc(obuflen);
1445 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1446 osav[SIZ-obuflen] = 0;
1447 safestrncpy(buf, osav, sizeof buf);
1452 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1453 buf[strlen(buf) - 1] = 0;
1455 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1456 wprintf("<blockquote>");
1458 } else if ((bq == 1) &&
1459 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1460 wprintf("</blockquote>");
1466 wprintf("</tt><br />");
1468 wprintf("</i><br />");
1471 /** HTML just gets escaped and stuffed back into the editor */
1472 else if (!strcasecmp(mime_content_type, "text/html")) {
1473 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1479 /** Unknown weirdness ... don't know how to handle this content type */
1481 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1485 /** end of body handler */
1488 * If there were attachments, we have to download them and insert them
1489 * into the attachment chain for the forwarded message we are composing.
1491 if ( (forward_attachments) && (num_attachments) ) {
1492 for (i=0; i<num_attachments; ++i) {
1493 extract_token(buf, attachments, i, '\n', sizeof buf);
1494 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1495 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1496 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1497 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1498 mime_length = extract_int(buf, 5);
1501 * tracing ... uncomment if necessary
1504 lprintf(9, "fwd filename: %s\n", mime_filename);
1505 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1506 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1507 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1508 lprintf(9, "fwd length : %d\n", mime_length);
1510 if ( (!strcasecmp(mime_disposition, "inline"))
1511 || (!strcasecmp(mime_disposition, "attachment")) ) {
1513 /* Create an attachment struct from this mime part... */
1514 att = malloc(sizeof(struct wc_attachment));
1515 memset(att, 0, sizeof(struct wc_attachment));
1516 att->length = mime_length;
1517 strcpy(att->content_type, mime_content_type);
1518 strcpy(att->filename, mime_filename);
1520 att->data = load_mimepart(msgnum, mime_partnum);
1522 /* And add it to the list. */
1523 if (WC->first_attachment == NULL) {
1524 WC->first_attachment = att;
1527 aptr = WC->first_attachment;
1528 while (aptr->next != NULL) aptr = aptr->next;
1537 if (ic != (iconv_t)(-1) ) {
1542 if (attachments != NULL) {
1548 * \brief Display one row in the mailbox summary view
1550 * \param num The row number to be displayed
1552 void display_summarized(int num) {
1555 wprintf("<tr id=\"m%ld\" style=\"width:100%%;font-weight:%s;background-color:#ffffff\" "
1556 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1557 WC->summ[num].msgnum,
1558 (WC->summ[num].is_new ? "bold" : "normal"),
1559 WC->summ[num].msgnum
1562 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1563 escputs(WC->summ[num].subj);
1566 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1567 escputs(WC->summ[num].from);
1570 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1571 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1581 * \brief display the adressbook overview
1582 * \param msgnum the citadel message number
1583 * \param alpha what????
1585 void display_addressbook(long msgnum, char alpha) {
1587 char mime_partnum[SIZ];
1588 char mime_filename[SIZ];
1589 char mime_content_type[SIZ];
1590 char mime_disposition[SIZ];
1592 char vcard_partnum[SIZ];
1593 char *vcard_source = NULL;
1594 struct message_summary summ;
1596 memset(&summ, 0, sizeof(summ));
1597 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1599 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1601 serv_getln(buf, sizeof buf);
1602 if (buf[0] != '1') return;
1604 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1605 if (!strncasecmp(buf, "part=", 5)) {
1606 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1607 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1608 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1609 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1610 mime_length = extract_int(&buf[5], 5);
1612 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1613 strcpy(vcard_partnum, mime_partnum);
1619 if (strlen(vcard_partnum) > 0) {
1620 vcard_source = load_mimepart(msgnum, vcard_partnum);
1621 if (vcard_source != NULL) {
1623 /** Display the summary line */
1624 display_vcard(vcard_source, alpha, 0, NULL);
1626 /** If it's my vCard I can edit it */
1627 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1628 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1629 || (WC->wc_view == VIEW_ADDRESSBOOK)
1631 wprintf("<a href=\"edit_vcard?"
1632 "msgnum=%ld?partnum=%s\">",
1633 msgnum, vcard_partnum);
1634 wprintf("[%s]</a>", _("edit"));
1646 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1647 * \param namebuf name to analyze, reverse if nescessary
1649 void lastfirst_firstlast(char *namebuf) {
1650 char firstname[SIZ];
1654 if (namebuf == NULL) return;
1655 if (strchr(namebuf, ';') != NULL) return;
1657 i = num_tokens(namebuf, ' ');
1660 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1661 remove_token(namebuf, i-1, ' ');
1662 strcpy(firstname, namebuf);
1663 sprintf(namebuf, "%s; %s", lastname, firstname);
1667 * \brief fetch what??? name
1668 * \param msgnum the citadel message number
1669 * \param namebuf where to put the name in???
1671 void fetch_ab_name(long msgnum, char *namebuf) {
1673 char mime_partnum[SIZ];
1674 char mime_filename[SIZ];
1675 char mime_content_type[SIZ];
1676 char mime_disposition[SIZ];
1678 char vcard_partnum[SIZ];
1679 char *vcard_source = NULL;
1681 struct message_summary summ;
1683 if (namebuf == NULL) return;
1684 strcpy(namebuf, "");
1686 memset(&summ, 0, sizeof(summ));
1687 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1689 sprintf(buf, "MSG0 %ld|1", msgnum); /** ask for headers only */
1691 serv_getln(buf, sizeof buf);
1692 if (buf[0] != '1') return;
1694 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1695 if (!strncasecmp(buf, "part=", 5)) {
1696 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1697 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1698 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1699 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1700 mime_length = extract_int(&buf[5], 5);
1702 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1703 strcpy(vcard_partnum, mime_partnum);
1709 if (strlen(vcard_partnum) > 0) {
1710 vcard_source = load_mimepart(msgnum, vcard_partnum);
1711 if (vcard_source != NULL) {
1713 /* Grab the name off the card */
1714 display_vcard(vcard_source, 0, 0, namebuf);
1720 lastfirst_firstlast(namebuf);
1722 for (i=0; i<strlen(namebuf); ++i) {
1723 if (namebuf[i] != ';') return;
1725 strcpy(namebuf, _("(no name)"));
1731 * \brief Record compare function for sorting address book indices
1732 * \param ab1 adressbook one
1733 * \param ab2 adressbook two
1735 int abcmp(const void *ab1, const void *ab2) {
1737 (((const struct addrbookent *)ab1)->ab_name),
1738 (((const struct addrbookent *)ab2)->ab_name)
1744 * \brief Helper function for do_addrbook_view()
1745 * Converts a name into a three-letter tab label
1746 * \param tabbuf the tabbuffer to add name to
1747 * \param name the name to add to the tabbuffer
1749 void nametab(char *tabbuf, char *name) {
1750 stresc(tabbuf, name, 0, 0);
1751 tabbuf[0] = toupper(tabbuf[0]);
1752 tabbuf[1] = tolower(tabbuf[1]);
1753 tabbuf[2] = tolower(tabbuf[2]);
1759 * \brief Render the address book using info we gathered during the scan
1760 * \param addrbook the addressbook to render
1761 * \param num_ab the number of the addressbook
1763 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1767 static int NAMESPERPAGE = 60;
1771 char tabfirst_label[SIZ];
1773 char tablast_label[SIZ];
1776 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1777 wprintf(_("This address book is empty."));
1778 wprintf("</i></div>\n");
1783 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1786 num_pages = num_ab / NAMESPERPAGE;
1788 page = atoi(bstr("page"));
1791 for (i=0; i<=num_pages; ++i) {
1793 wprintf("<a href=\"readfwd?page=%d\">", i);
1798 tabfirst = i * NAMESPERPAGE;
1799 tablast = tabfirst + NAMESPERPAGE - 1;
1800 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1801 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1802 nametab(tablast_label, addrbook[tablast].ab_name);
1803 wprintf("[%s - %s]",
1804 tabfirst_label, tablast_label
1813 wprintf("<br />\n");
1815 wprintf("<table border=0 cellspacing=0 "
1816 "cellpadding=3 width=100%%>\n"
1819 for (i=0; i<num_ab; ++i) {
1821 if ((i / NAMESPERPAGE) == page) {
1823 if ((displayed % 4) == 0) {
1824 if (displayed > 0) {
1828 wprintf("<tr bgcolor=\"#%s\">",
1829 (bg ? "DDDDDD" : "FFFFFF")
1835 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
1836 addrbook[i].ab_msgnum);
1837 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1838 vcard_n_prettyize(addrbook[i].ab_name);
1839 escputs(addrbook[i].ab_name);
1840 wprintf("</a></td>\n");
1845 wprintf("</tr></table>\n");
1851 * \brief load message pointers from the server
1852 * \param servcmd the citadel command to send to the citserver
1853 * \param with_headers what headers???
1855 int load_msg_ptrs(char *servcmd, int with_headers)
1866 int num_summ_alloc = 0;
1868 if (WC->summ != NULL) {
1873 num_summ_alloc = 100;
1875 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1878 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1880 serv_getln(buf, sizeof buf);
1881 if (buf[0] != '1') {
1884 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1885 if (nummsgs < maxload) {
1886 WC->msgarr[nummsgs] = extract_long(buf, 0);
1887 datestamp = extract_long(buf, 1);
1888 extract_token(fullname, buf, 2, '|', sizeof fullname);
1889 extract_token(nodename, buf, 3, '|', sizeof nodename);
1890 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1891 extract_token(subject, buf, 5, '|', sizeof subject);
1895 if (nummsgs > num_summ_alloc) {
1896 num_summ_alloc *= 2;
1897 WC->summ = realloc(WC->summ,
1898 num_summ_alloc * sizeof(struct message_summary));
1902 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1903 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1904 safestrncpy(WC->summ[nummsgs-1].subj,
1905 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1906 if (strlen(fullname) > 0) {
1907 safestrncpy(WC->summ[nummsgs-1].from,
1908 fullname, sizeof WC->summ[nummsgs-1].from);
1910 if (strlen(subject) > 0) {
1911 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1912 sizeof WC->summ[nummsgs-1].subj);
1915 /** Handle subjects with RFC2047 encoding */
1916 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1918 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1919 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1922 if (strlen(nodename) > 0) {
1923 if ( ((WC->room_flags & QR_NETWORK)
1924 || ((strcasecmp(nodename, serv_info.serv_nodename)
1925 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1927 strcat(WC->summ[nummsgs-1].from, " @ ");
1928 strcat(WC->summ[nummsgs-1].from, nodename);
1932 WC->summ[nummsgs-1].date = datestamp;
1935 /** Handle senders with RFC2047 encoding */
1936 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1938 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1939 strcpy(&WC->summ[nummsgs-1].from[22], "...");
1948 * \brief qsort() compatible function to compare two longs in descending order.
1950 * \param s1 first number to compare
1951 * \param s2 second number to compare
1953 int longcmp_r(const void *s1, const void *s2) {
1960 if (l1 > l2) return(-1);
1961 if (l1 < l2) return(+1);
1967 * \brief qsort() compatible function to compare two message summary structs by ascending subject.
1969 * \param s1 first item to compare
1970 * \param s2 second item to compare
1972 int summcmp_subj(const void *s1, const void *s2) {
1973 struct message_summary *summ1;
1974 struct message_summary *summ2;
1976 summ1 = (struct message_summary *)s1;
1977 summ2 = (struct message_summary *)s2;
1978 return strcasecmp(summ1->subj, summ2->subj);
1982 * \brief qsort() compatible function to compare two message summary structs by descending subject.
1984 * \param s1 first item to compare
1985 * \param s2 second item to compare
1987 int summcmp_rsubj(const void *s1, const void *s2) {
1988 struct message_summary *summ1;
1989 struct message_summary *summ2;
1991 summ1 = (struct message_summary *)s1;
1992 summ2 = (struct message_summary *)s2;
1993 return strcasecmp(summ2->subj, summ1->subj);
1997 * \brief qsort() compatible function to compare two message summary structs by ascending sender.
1999 * \param s1 first item to compare
2000 * \param s2 second item to compare
2002 int summcmp_sender(const void *s1, const void *s2) {
2003 struct message_summary *summ1;
2004 struct message_summary *summ2;
2006 summ1 = (struct message_summary *)s1;
2007 summ2 = (struct message_summary *)s2;
2008 return strcasecmp(summ1->from, summ2->from);
2012 * \brief qsort() compatible function to compare two message summary structs by descending sender.
2014 * \param s1 first item to compare
2015 * \param s2 second item to compare
2017 int summcmp_rsender(const void *s1, const void *s2) {
2018 struct message_summary *summ1;
2019 struct message_summary *summ2;
2021 summ1 = (struct message_summary *)s1;
2022 summ2 = (struct message_summary *)s2;
2023 return strcasecmp(summ2->from, summ1->from);
2027 * \brief qsort() compatible function to compare two message summary structs by ascending date.
2029 * \param s1 first item to compare
2030 * \param s2 second item to compare
2032 int summcmp_date(const void *s1, const void *s2) {
2033 struct message_summary *summ1;
2034 struct message_summary *summ2;
2036 summ1 = (struct message_summary *)s1;
2037 summ2 = (struct message_summary *)s2;
2039 if (summ1->date < summ2->date) return -1;
2040 else if (summ1->date > summ2->date) return +1;
2045 * \brief qsort() compatible function to compare two message summary structs by descending date.
2047 * \param s1 first item to compare
2048 * \param s2 second item to compare
2050 int summcmp_rdate(const void *s1, const void *s2) {
2051 struct message_summary *summ1;
2052 struct message_summary *summ2;
2054 summ1 = (struct message_summary *)s1;
2055 summ2 = (struct message_summary *)s2;
2057 if (summ1->date < summ2->date) return +1;
2058 else if (summ1->date > summ2->date) return -1;
2065 * \brief command loop for reading messages
2067 * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
2069 void readloop(char *oper)
2078 long *displayed_msgs = NULL;
2079 int num_displayed = 0;
2081 int is_addressbook = 0;
2082 int is_singlecard = 0;
2083 int is_calendar = 0;
2088 int lowest_displayed = (-1);
2089 int highest_displayed = 0;
2090 struct addrbookent *addrbook = NULL;
2092 char *sortby = NULL;
2093 char sortpref_name[128];
2094 char sortpref_value[128];
2095 char *subjsort_button;
2096 char *sendsort_button;
2097 char *datesort_button;
2098 int bbs_reverse = 0;
2100 if (WC->wc_view == VIEW_WIKI) {
2101 sprintf(buf, "wiki?room=%s?page=home", WC->wc_roomname);
2106 startmsg = atol(bstr("startmsg"));
2107 maxmsgs = atoi(bstr("maxmsgs"));
2108 is_summary = atoi(bstr("summary"));
2109 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2111 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
2112 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
2114 sortby = bstr("sortby");
2115 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
2116 set_preference(sortpref_name, sortby, 1);
2118 if (strlen(sortby) == 0) sortby = sortpref_value;
2121 if (strlen(sortby) == 0) sortby = "rdate";
2123 /** message board sort */
2124 if (!strcasecmp(sortby, "reverse")) {
2131 output_headers(1, 1, 1, 0, 0, 0);
2134 * When in summary mode, always show ALL messages instead of just
2135 * new or old. Otherwise, show what the user asked for.
2137 if (!strcmp(oper, "readnew")) {
2138 strcpy(cmd, "MSGS NEW");
2140 else if (!strcmp(oper, "readold")) {
2141 strcpy(cmd, "MSGS OLD");
2144 strcpy(cmd, "MSGS ALL");
2147 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
2149 strcpy(cmd, "MSGS ALL");
2152 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2154 strcpy(cmd, "MSGS ALL");
2159 strcpy(cmd, "MSGS ALL|||1"); /**< fetch header summary */
2165 * Are we doing a summary view? If so, we need to know old messages
2166 * and new messages, so we can do that pretty boldface thing for the
2169 strcpy(old_msgs, "");
2172 serv_getln(buf, sizeof buf);
2173 if (buf[0] == '2') {
2174 strcpy(old_msgs, &buf[4]);
2178 is_singlecard = atoi(bstr("is_singlecard"));
2180 if (WC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2182 strcpy(cmd, "MSGS ALL");
2185 if (WC->wc_default_view == VIEW_TASKS) { /**< tasks */
2187 strcpy(cmd, "MSGS ALL");
2190 if (WC->wc_default_view == VIEW_NOTES) { /**< notes */
2192 strcpy(cmd, "MSGS ALL");
2197 wprintf("<div align=center>%s</div>\n", _("Click on any note to edit it."));
2198 wprintf("<div id=\"new_notes_here\"></div>\n");
2201 nummsgs = load_msg_ptrs(cmd, is_summary);
2204 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2206 if (!strcmp(oper, "readnew")) {
2207 wprintf(_("No new messages."));
2208 } else if (!strcmp(oper, "readold")) {
2209 wprintf(_("No old messages."));
2211 wprintf(_("No messages here."));
2220 for (a = 0; a < nummsgs; ++a) {
2221 /** Are you a new message, or an old message? */
2223 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
2224 WC->summ[a].is_new = 0;
2227 WC->summ[a].is_new = 1;
2233 if (startmsg == 0L) {
2235 startmsg = WC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2238 startmsg = WC->msgarr[0];
2243 if (!strcasecmp(sortby, "subject")) {
2244 qsort(WC->summ, WC->num_summ,
2245 sizeof(struct message_summary), summcmp_subj);
2247 else if (!strcasecmp(sortby, "rsubject")) {
2248 qsort(WC->summ, WC->num_summ,
2249 sizeof(struct message_summary), summcmp_rsubj);
2251 else if (!strcasecmp(sortby, "sender")) {
2252 qsort(WC->summ, WC->num_summ,
2253 sizeof(struct message_summary), summcmp_sender);
2255 else if (!strcasecmp(sortby, "rsender")) {
2256 qsort(WC->summ, WC->num_summ,
2257 sizeof(struct message_summary), summcmp_rsender);
2259 else if (!strcasecmp(sortby, "date")) {
2260 qsort(WC->summ, WC->num_summ,
2261 sizeof(struct message_summary), summcmp_date);
2263 else if (!strcasecmp(sortby, "rdate")) {
2264 qsort(WC->summ, WC->num_summ,
2265 sizeof(struct message_summary), summcmp_rdate);
2269 if (!strcasecmp(sortby, "subject")) {
2270 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2272 else if (!strcasecmp(sortby, "rsubject")) {
2273 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2276 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2279 if (!strcasecmp(sortby, "sender")) {
2280 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2282 else if (!strcasecmp(sortby, "rsender")) {
2283 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2286 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2289 if (!strcasecmp(sortby, "date")) {
2290 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2292 else if (!strcasecmp(sortby, "rdate")) {
2293 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2296 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2300 wprintf("</div>\n"); /** end of 'content' div */
2302 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2303 " document.onkeydown = CtdlMsgListKeyPress; "
2304 " if (document.layers) { "
2305 " document.captureEvents(Event.KEYPRESS); "
2310 /** note that Date and Delete are now in the same column */
2311 wprintf("<div id=\"message_list_hdr\">"
2312 "<div class=\"fix_scrollbar_bug\">"
2313 "<table cellspacing=0 style=\"width:100%%\">"
2316 wprintf("<td width=%d%%><b><i>%s</i></b> %s</td>"
2317 "<td width=%d%%><b><i>%s</i></b> %s</td>"
2318 "<td width=%d%%><b><i>%s</i></b> %s"
2320 "<input type=\"submit\" name=\"delete_button\" style=\"font-size:6pt\" "
2321 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2327 _("Subject"), subjsort_button,
2328 SENDER_COL_WIDTH_PCT,
2329 _("Sender"), sendsort_button,
2330 DATE_PLUS_BUTTONS_WIDTH_PCT,
2331 _("Date"), datesort_button,
2334 wprintf("</table></div></div>\n");
2336 wprintf("<div id=\"message_list\">"
2338 "<div class=\"fix_scrollbar_bug\">\n"
2340 "<table class=\"mailbox_summary\" id=\"summary_headers\" rules=rows "
2341 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2345 for (a = 0; a < nummsgs; ++a) {
2346 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2348 /** Display the message */
2350 display_summarized(a);
2352 else if (is_addressbook) {
2353 fetch_ab_name(WC->msgarr[a], buf);
2355 addrbook = realloc(addrbook,
2356 (sizeof(struct addrbookent) * num_ab) );
2357 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2358 sizeof(addrbook[num_ab-1].ab_name));
2359 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
2361 else if (is_calendar) {
2362 display_calendar(WC->msgarr[a]);
2364 else if (is_tasks) {
2365 display_task(WC->msgarr[a]);
2367 else if (is_notes) {
2368 display_note(WC->msgarr[a]);
2371 if (displayed_msgs == NULL) {
2372 displayed_msgs = malloc(sizeof(long) *
2373 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2375 displayed_msgs[num_displayed] = WC->msgarr[a];
2378 if (lowest_displayed < 0) lowest_displayed = a;
2379 highest_displayed = a;
2386 * Set the "is_bbview" variable if it appears that we are looking at
2387 * a classic bulletin board view.
2389 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2390 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2395 if (displayed_msgs != NULL) {
2397 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2400 /** if we do a split bbview in the future, begin messages div here */
2402 for (a=0; a<num_displayed; ++a) {
2403 read_message(displayed_msgs[a], 0, "");
2406 /** if we do a split bbview in the future, end messages div here */
2408 free(displayed_msgs);
2409 displayed_msgs = NULL;
2414 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2415 wprintf("</div>"); /**< end of 'message_list' div */
2417 /** Here's the grab-it-to-resize-the-message-list widget */
2418 wprintf("<div id=\"resize_msglist\" "
2419 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2420 "<div class=\"fix_scrollbar_bug\">"
2421 "<table width=100%% border=3 cellspacing=0 "
2422 "bgcolor=\"#cccccc\" "
2423 "cellpadding=0><TR><TD> </td></tr></table>"
2427 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2431 * Bump these because although we're thinking in zero base, the user
2432 * is a drooling idiot and is thinking in one base.
2435 ++highest_displayed;
2438 * If we're not currently looking at ALL requested
2439 * messages, then display the selector bar
2442 /** begin bbview scroller */
2443 wprintf("<form name=\"msgomatic\">");
2444 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2446 wprintf("<select name=\"whichones\" size=\"1\" "
2447 "OnChange=\"location.href=msgomatic.whichones.options"
2448 "[selectedIndex].value\">\n");
2451 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2453 lo = b - maxmsgs + 2;
2455 wprintf("<option %s value="
2460 "%d-%d</option> \n",
2461 ((WC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2470 for (b=0; b<nummsgs; b = b + maxmsgs) {
2472 hi = b + maxmsgs + 1;
2473 if (hi > nummsgs) hi = nummsgs;
2474 wprintf("<option %s value="
2479 "%d-%d</option> \n",
2480 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2489 wprintf("<option value=\"%s?startmsg=%ld"
2490 "?maxmsgs=9999999?summary=%d\">"
2494 WC->msgarr[0], is_summary);
2496 wprintf("</select> ");
2497 wprintf(_("of %d messages."), nummsgs);
2499 /** forward/reverse */
2500 wprintf(" <select name=\"direction\" size=\"1\" "
2501 "OnChange=\"location.href=msgomatic.direction.options"
2502 "[selectedIndex].value\">\n"
2505 wprintf("<option %s value=\"%s?sortby=forward\">oldest to newest</option>\n",
2506 (bbs_reverse ? "" : "selected"),
2510 wprintf("<option %s value=\"%s?sortby=reverse\">newest to oldest</option>\n",
2511 (bbs_reverse ? "selected" : ""),
2515 wprintf("</select></form>\n");
2516 /** end bbview scroller */
2521 do_tasks_view(); /** Render the task list */
2525 do_calendar_view(); /** Render the calendar */
2528 if (is_addressbook) {
2529 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2532 /** Note: wDumpContent() will output one additional </div> tag. */
2534 if (addrbook != NULL) free(addrbook);
2536 /** free the summary */
2537 if (WC->summ != NULL) {
2546 * \brief Back end for post_message()
2547 * ... this is where the actual message gets transmitted to the server.
2549 void post_mime_to_server(void) {
2551 int is_multipart = 0;
2553 struct wc_attachment *att;
2555 size_t encoded_length;
2557 /** RFC2045 requires this, and some clients look for it... */
2558 serv_puts("MIME-Version: 1.0");
2560 /** If there are attachments, we have to do multipart/mixed */
2561 if (WC->first_attachment != NULL) {
2566 sprintf(boundary, "=_Citadel_Multipart_%s_%04x%04x",
2567 serv_info.serv_fqdn,
2572 /** Remember, serv_printf() appends an extra newline */
2573 serv_printf("Content-type: multipart/mixed; "
2574 "boundary=\"%s\"\n", boundary);
2575 serv_printf("This is a multipart message in MIME format.\n");
2576 serv_printf("--%s", boundary);
2579 serv_puts("Content-type: text/html; charset=utf-8");
2580 serv_puts("Content-Transfer-Encoding: quoted-printable");
2582 serv_puts("<html><body>\r\n");
2583 text_to_server_qp(bstr("msgtext")); /** Transmit message in quoted-printable encoding */
2584 serv_puts("</body></html>\r\n");
2588 /** Add in the attachments */
2589 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2591 encoded_length = ((att->length * 150) / 100);
2592 encoded = malloc(encoded_length);
2593 if (encoded == NULL) break;
2594 CtdlEncodeBase64(encoded, att->data, att->length);
2596 serv_printf("--%s", boundary);
2597 serv_printf("Content-type: %s", att->content_type);
2598 serv_printf("Content-disposition: attachment; "
2599 "filename=\"%s\"", att->filename);
2600 serv_puts("Content-transfer-encoding: base64");
2602 serv_write(encoded, strlen(encoded));
2607 serv_printf("--%s--", boundary);
2615 * \brief Post message (or don't post message)
2617 * Note regarding the "dont_post" variable:
2618 * A random value (actually, it's just a timestamp) is inserted as a hidden
2619 * field called "postseq" when the display_enter page is generated. This
2620 * value is checked when posting, using the static variable dont_post. If a
2621 * user attempts to post twice using the same dont_post value, the message is
2622 * discarded. This prevents the accidental double-saving of the same message
2623 * if the user happens to click the browser "back" button.
2625 void post_message(void)
2628 char encoded_subject[1024];
2629 static long dont_post = (-1L);
2630 struct wc_attachment *att, *aptr;
2631 int is_anonymous = 0;
2633 if (!strcasecmp(bstr("is_anonymous"), "yes")) {
2637 if (WC->upload_length > 0) {
2639 /** There's an attachment. Save it to this struct... */
2640 att = malloc(sizeof(struct wc_attachment));
2641 memset(att, 0, sizeof(struct wc_attachment));
2642 att->length = WC->upload_length;
2643 strcpy(att->content_type, WC->upload_content_type);
2644 strcpy(att->filename, WC->upload_filename);
2647 /** And add it to the list. */
2648 if (WC->first_attachment == NULL) {
2649 WC->first_attachment = att;
2652 aptr = WC->first_attachment;
2653 while (aptr->next != NULL) aptr = aptr->next;
2658 * Mozilla sends a simple filename, which is what we want,
2659 * but Satan's Browser sends an entire pathname. Reduce
2660 * the path to just a filename if we need to.
2662 while (num_tokens(att->filename, '/') > 1) {
2663 remove_token(att->filename, 0, '/');
2665 while (num_tokens(att->filename, '\\') > 1) {
2666 remove_token(att->filename, 0, '\\');
2670 * Transfer control of this memory from the upload struct
2671 * to the attachment struct.
2673 att->data = WC->upload;
2674 WC->upload_length = 0;
2680 if (strlen(bstr("cancel_button")) > 0) {
2681 sprintf(WC->ImportantMessage,
2682 _("Cancelled. Message was not posted."));
2683 } else if (strlen(bstr("attach_button")) > 0) {
2686 } else if (atol(bstr("postseq")) == dont_post) {
2687 sprintf(WC->ImportantMessage,
2688 _("Automatically cancelled because you have already "
2689 "saved this message."));
2691 rfc2047encode(encoded_subject, sizeof encoded_subject, bstr("subject"));
2692 sprintf(buf, "ENT0 1|%s|%d|4|%s|||%s|%s|%s",
2701 serv_getln(buf, sizeof buf);
2702 if (buf[0] == '4') {
2703 post_mime_to_server();
2704 if ( (strlen(bstr("recp")) > 0)
2705 || (strlen(bstr("cc")) > 0)
2706 || (strlen(bstr("bcc")) > 0)
2708 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2711 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2713 dont_post = atol(bstr("postseq"));
2715 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2721 free_attachments(WC);
2724 * We may have been supplied with instructions regarding the location
2725 * to which we must return after posting. If found, go there.
2727 if (strlen(bstr("return_to")) > 0) {
2728 http_redirect(bstr("return_to"));
2731 * If we were editing a page in a wiki room, go to that page now.
2733 else if (strlen(bstr("wikipage")) > 0) {
2734 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
2738 * Otherwise, just go to the "read messages" loop.
2741 readloop("readnew");
2749 * \brief display the message entry screen
2751 void display_enter(void)
2756 struct wc_attachment *att;
2757 int recipient_required = 0;
2758 int recipient_bad = 0;
2760 int is_anonymous = 0;
2761 long existing_page = (-1L);
2763 if (strlen(bstr("force_room")) > 0) {
2764 gotoroom(bstr("force_room"));
2767 if (!strcasecmp(bstr("is_anonymous"), "yes")) {
2772 * Are we perhaps in an address book view? If so, then an "enter
2773 * message" command really means "add new entry."
2775 if (WC->wc_default_view == VIEW_ADDRESSBOOK) {
2776 do_edit_vcard(-1, "", "");
2780 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
2782 * Are we perhaps in a calendar room? If so, then an "enter
2783 * message" command really means "add new calendar item."
2785 if (WC->wc_default_view == VIEW_CALENDAR) {
2786 display_edit_event();
2791 * Are we perhaps in a tasks view? If so, then an "enter
2792 * message" command really means "add new task."
2794 if (WC->wc_default_view == VIEW_TASKS) {
2795 display_edit_task();
2801 * Otherwise proceed normally.
2802 * Do a custom room banner with no navbar...
2804 output_headers(1, 1, 2, 0, 0, 0);
2805 wprintf("<div id=\"banner\">\n");
2806 embed_room_banner(NULL, navbar_none);
2807 wprintf("</div>\n");
2808 wprintf("<div id=\"content\">\n"
2809 "<div class=\"fix_scrollbar_bug\">"
2810 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
2812 /** First test to see whether this is a room that requires recipients to be entered */
2813 serv_puts("ENT0 0");
2814 serv_getln(buf, sizeof buf);
2815 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
2816 recipient_required = 1;
2818 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2819 wprintf("<em>%s</em><br />\n", &buf[4]);
2823 /** Now check our actual recipients if there are any */
2824 if (recipient_required) {
2825 sprintf(buf, "ENT0 0|%s|%d|0||||%s|%s|%s", bstr("recp"), is_anonymous,
2826 bstr("cc"), bstr("bcc"), bstr("wikipage"));
2828 serv_getln(buf, sizeof buf);
2830 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
2831 if (strlen(bstr("recp")) + strlen(bstr("cc")) + strlen(bstr("bcc")) > 0) {
2835 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2836 wprintf("<em>%s</em><br />\n", &buf[4]);
2841 /** If we got this far, we can display the message entry screen. */
2844 fmt_date(buf, now, 0);
2845 strcat(&buf[strlen(buf)], _(" <I>from</I> "));
2846 stresc(&buf[strlen(buf)], WC->wc_fullname, 1, 1);
2848 /* Don't need this anymore, it's in the input box below
2849 if (strlen(bstr("recp")) > 0) {
2850 strcat(&buf[strlen(buf)], _(" <I>to</I> "));
2851 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
2855 strcat(&buf[strlen(buf)], _(" <I>in</I> "));
2856 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
2858 /** begin message entry screen */
2860 "enctype=\"multipart/form-data\" "
2862 "accept-charset=\"UTF-8\" "
2864 "name=\"enterform\""
2866 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2867 if (WC->wc_view == VIEW_WIKI) {
2868 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
2870 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
2872 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2873 wprintf("%s\n", buf); /** header bar */
2874 if (WC->room_flags & QR_ANONOPT) {
2876 "<input type=\"checkbox\" name=\"is_anonymous\" value=\"yes\" %s>",
2877 (is_anonymous ? "checked" : "")
2879 wprintf("Anonymous");
2881 wprintf("<br>\n"); /** header bar */
2883 wprintf("<table border=\"0\" width=\"100%%\">\n");
2884 if (recipient_required) {
2886 wprintf("<tr><td>");
2887 wprintf("<font size=-1>");
2891 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
2892 escputs(bstr("recp"));
2893 wprintf("\" size=50 maxlength=1000 />");
2894 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
2895 wprintf("</td><td></td></tr>\n");
2897 wprintf("<tr><td>");
2898 wprintf("<font size=-1>");
2902 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
2903 escputs(bstr("cc"));
2904 wprintf("\" size=50 maxlength=1000 />");
2905 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
2906 wprintf("</td><td></td></tr>\n");
2908 wprintf("<tr><td>");
2909 wprintf("<font size=-1>");
2913 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
2914 escputs(bstr("bcc"));
2915 wprintf("\" size=50 maxlength=1000 />");
2916 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
2917 wprintf("</td><td></td></tr>\n");
2919 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
2920 wprintf("<script type=\"text/javascript\"> \n"
2921 " activate_entmsg_autocompleters(); \n"
2926 wprintf("<tr><td>");
2927 wprintf("<font size=-1>");
2928 wprintf(_("Subject (optional):"));
2931 "<input type=\"text\" name=\"subject\" value=\"");
2932 escputs(bstr("subject"));
2933 wprintf("\" size=50 maxlength=70></td><td>\n");
2935 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2936 if (recipient_required) {
2937 wprintf(_("Send message"));
2939 wprintf(_("Post message"));
2942 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2943 wprintf("</td></tr></table>\n");
2945 wprintf("<center>");
2947 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
2949 /** If we're continuing from a previous edit, put our partially-composed message back... */
2950 msgescputs(bstr("msgtext"));
2952 /* If we're forwarding a message, insert it here... */
2953 if (atol(bstr("fwdquote")) > 0L) {
2954 wprintf("<br><div align=center><i>");
2955 wprintf(_("--- forwarded message ---"));
2956 wprintf("</i></div><br>");
2957 pullquote_message(atol(bstr("fwdquote")), 1, 1);
2960 /** If we're replying quoted, insert the quote here... */
2961 else if (atol(bstr("replyquote")) > 0L) {
2964 pullquote_message(atol(bstr("replyquote")), 0, 1);
2965 wprintf("</blockquote><br>");
2968 /** If we're editing a wiki page, insert the existing page here... */
2969 else if (WC->wc_view == VIEW_WIKI) {
2970 safestrncpy(buf, bstr("wikipage"), sizeof buf);
2971 str_wiki_index(buf);
2972 existing_page = locate_message_by_uid(buf);
2973 if (existing_page >= 0L) {
2974 pullquote_message(existing_page, 1, 0);
2978 /** Insert our signature if appropriate... */
2979 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
2980 get_preference("use_sig", buf, sizeof buf);
2981 if (!strcasecmp(buf, "yes")) {
2982 get_preference("signature", ebuf, sizeof ebuf);
2983 euid_unescapize(buf, ebuf);
2984 wprintf("<br>--<br>");
2985 for (i=0; i<strlen(buf); ++i) {
2986 if (buf[i] == '\n') {
2989 else if (buf[i] == '<') {
2992 else if (buf[i] == '>') {
2995 else if (buf[i] == '&') {
2998 else if (buf[i] == '\"') {
3001 else if (buf[i] == '\'') {
3004 else if (isprint(buf[i])) {
3005 wprintf("%c", buf[i]);
3011 wprintf("</textarea>");
3012 wprintf("</center><br />\n");
3015 * The following script embeds the TinyMCE richedit control, and automatically
3016 * transforms the textarea into a richedit textarea.
3019 "<script language=\"javascript\" type=\"text/javascript\" src=\"tiny_mce/tiny_mce.js\"></script>\n"
3020 "<script language=\"javascript\" type=\"text/javascript\">"
3022 " mode : \"textareas\", width : \"100%%\", browsers : \"msie,gecko\", "
3023 " theme : \"advanced\", plugins : \"iespell\", "
3024 " theme_advanced_buttons1 : \"bold, italic, underline, strikethrough, justifyleft, justifycenter, justifyright, justifyfull, bullist, numlist, cut, copy, paste, link, image, help, forecolor, iespell, code\", "
3025 " theme_advanced_buttons2 : \"\", "
3026 " theme_advanced_buttons3 : \"\", "
3027 " content_css : \"static/webcit-tinymce.css\" "
3033 /** Enumerate any attachments which are already in place... */
3034 wprintf("<img src=\"static/diskette_24x.gif\" border=0 "
3035 "align=middle height=16 width=16> ");
3036 wprintf(_("Attachments:"));
3038 wprintf("<select name=\"which_attachment\" size=1>");
3039 for (att = WC->first_attachment; att != NULL; att = att->next) {
3040 wprintf("<option value=\"");
3041 urlescputs(att->filename);
3043 escputs(att->filename);
3044 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3045 wprintf("</option>\n");
3047 wprintf("</select>");
3049 /** Now offer the ability to attach additional files... */
3050 wprintf(" ");
3051 wprintf(_("Attach file:"));
3052 wprintf(" <input NAME=\"attachfile\" "
3053 "SIZE=16 TYPE=\"file\">\n "
3054 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3056 /** Seth asked for these to be at the top *and* bottom... */
3057 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3058 if (recipient_required) {
3059 wprintf(_("Send message"));
3061 wprintf(_("Post message"));
3064 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3066 /** Make sure we only insert our signature once */
3067 if (strcmp(bstr("sig_inserted"), "yes")) {
3068 wprintf("<INPUT TYPE=\"hidden\" NAME=\"sig_inserted\" VALUE=\"yes\">\n");
3071 wprintf("</form>\n");
3073 wprintf("</td></tr></table></div>\n");
3074 DONE: wDumpContent(1);
3080 * \brief delete a message
3082 void delete_msg(void)
3087 msgid = atol(bstr("msgid"));
3089 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3090 serv_printf("DELE %ld", msgid);
3092 else { /** Otherwise move it to Trash */
3093 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3096 serv_getln(buf, sizeof buf);
3097 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3099 readloop("readnew");
3104 * \brief move a message to another folder
3111 msgid = atol(bstr("msgid"));
3113 if (strlen(bstr("move_button")) > 0) {
3114 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3116 serv_getln(buf, sizeof buf);
3117 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3119 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3122 readloop("readnew");
3130 * \brief Confirm move of a message
3132 void confirm_move_msg(void)
3138 msgid = atol(bstr("msgid"));
3141 output_headers(1, 1, 2, 0, 0, 0);
3142 wprintf("<div id=\"banner\">\n");
3143 wprintf("<TABLE WIDTH=100%% BORDER=0><TR><TD>");
3144 wprintf("<SPAN CLASS=\"titlebar\">");
3145 wprintf(_("Confirm move of message"));
3146 wprintf("</SPAN>\n");
3147 wprintf("</TD></TR></TABLE>\n");
3148 wprintf("</div>\n<div id=\"content\">\n");
3150 wprintf("<CENTER>");
3152 wprintf(_("Move this message to:"));
3153 wprintf("<br />\n");
3155 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3156 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3158 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3160 serv_getln(buf, sizeof buf);
3161 if (buf[0] == '1') {
3162 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3163 extract_token(targ, buf, 0, '|', sizeof targ);
3164 wprintf("<OPTION>");
3169 wprintf("</SELECT>\n");
3170 wprintf("<br />\n");
3172 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3174 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3175 wprintf("</form></CENTER>\n");
3177 wprintf("</CENTER>\n");