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.
87 for (i=0; i<len; ++i) {
88 if ((buf[i] < 32) || (buf[i] > 126)) {
89 illegal_non_rfc2047_encoding = 1;
90 i = len; ///< take a shortcut, it won't be more than one.
93 if (illegal_non_rfc2047_encoding) {
94 char default_header_charset[128];
95 get_preference("default_header_charset", default_header_charset, sizeof default_header_charset);
96 if ( (strcasecmp(default_header_charset, "UTF-8")) && (strcasecmp(default_header_charset, "us-ascii")) ) {
97 ic = ctdl_iconv_open("UTF-8", default_header_charset);
98 if (ic != (iconv_t)(-1) ) {
101 safestrncpy(ibuf, buf, 1024);
102 ibuflen = strlen(ibuf);
104 obuf = (char *) malloc(obuflen);
106 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
107 osav[1024-obuflen] = 0;
116 /** Now we handle foreign character sets properly encoded
119 while (start=strstr(buf, "=?"), end=strstr(buf, "?="),
120 ((start != NULL) && (end != NULL) && (end > start)) )
122 extract_token(charset, start, 1, '?', sizeof charset);
123 extract_token(encoding, start, 2, '?', sizeof encoding);
124 extract_token(istr, start, 3, '?', sizeof istr);
128 if (!strcasecmp(encoding, "B")) { /**< base64 */
129 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
131 else if (!strcasecmp(encoding, "Q")) { /**< quoted-printable */
139 if (istr[pos] == '_') istr[pos] = ' ';
143 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, len);
146 strcpy(ibuf, istr); /**< unknown encoding */
147 ibuflen = strlen(istr);
150 ic = ctdl_iconv_open("UTF-8", charset);
151 if (ic != (iconv_t)(-1) ) {
153 obuf = (char *) malloc(obuflen);
155 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
156 osav[1024-obuflen] = 0;
161 remove_token(end, 0, '?');
162 remove_token(end, 0, '?');
163 remove_token(end, 0, '?');
164 remove_token(end, 0, '?');
165 strcpy(end, &end[1]);
167 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
176 remove_token(end, 0, '?');
177 remove_token(end, 0, '?');
178 remove_token(end, 0, '?');
179 remove_token(end, 0, '?');
180 strcpy(end, &end[1]);
182 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
189 * Since spammers will go to all sorts of absurd lengths to get their
190 * messages through, there are LOTS of corrupt headers out there.
191 * So, prevent a really badly formed RFC2047 header from throwing
192 * this function into an infinite loop.
195 if (passes > 20) return;
205 * \brief RFC2047-encode a header field if necessary.
206 * If no non-ASCII characters are found, the string
207 * will be copied verbatim without encoding.
209 * \param target Target buffer.
210 * \param maxlen Maximum size of target buffer.
211 * \param source Source string to be encoded.
213 void rfc2047encode(char *target, int maxlen, char *source)
215 int need_to_encode = 0;
219 if (target == NULL) return;
220 len = strlen(source);
221 for (i=0; i<len; ++i) {
222 if ((source[i] < 32) || (source[i] > 126)) {
224 i = len; ///< shortcut. won't become more than 1
228 if (!need_to_encode) {
229 safestrncpy(target, source, maxlen);
233 strcpy(target, "=?UTF-8?Q?");
234 for (i=0; i<len; ++i) {
235 ch = (unsigned char) source[i];
236 if ((ch < 32) || (ch > 126) || (ch == 61)) {
237 sprintf(&target[strlen(target)], "=%02X", ch);
240 sprintf(&target[strlen(target)], "%c", ch);
244 strcat(target, "?=");
251 * \brief Look for URL's embedded in a buffer and make them linkable. We use a
252 * target window in order to keep the BBS session in its own window.
253 * \param buf the message buffer
258 char *start, *end, *pos;
265 for (pos = buf; (pos < end) && (start == NULL); ++pos) {
266 if (!strncasecmp(pos, "http://", 7))
268 if (!strncasecmp(pos, "ftp://", 6))
275 for (pos = buf+len; pos > start; --pos) {
276 if ( (!isprint(*pos))
295 strncpy(urlbuf, start, end - start);
296 urlbuf[end - start] = '\0';
299 strncpy(outbuf, buf, start - buf );
300 sprintf(&outbuf[start-buf], "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
301 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
303 if ( strlen(outbuf) < 250 )
309 * \brief Turn a vCard "n" (name) field into something displayable.
310 * \param name the name field to convert
312 void vcard_n_prettyize(char *name)
317 original_name = strdup(name);
318 len = strlen(original_name);
319 for (i=0; i<5; ++i) {
321 if (original_name[len-1] == ' ') {
322 original_name[--len] = 0;
324 if (original_name[len-1] == ';') {
325 original_name[--len] = 0;
331 for (i=0; i<len; ++i) {
332 if (original_name[i] == ';') {
337 name[j++] = original_name[i];
348 * \brief preparse a vcard name
349 * display_vcard() calls this after parsing the textual vCard into
350 * our 'struct vCard' data object.
351 * This gets called instead of display_parsed_vcard() if we are only looking
352 * to extract the person's name instead of displaying the card.
353 * \param v the vcard to retrieve the name from
354 * \param storename where to put the name at
356 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
359 strcpy(storename, "");
361 name = vcard_get_prop(v, "n", 1, 0, 0);
363 strcpy(storename, name);
364 /* vcard_n_prettyize(storename); */
372 * \brief html print a vcard
373 * display_vcard() calls this after parsing the textual vCard into
374 * our 'struct vCard' data object.
376 * Set 'full' to nonzero to display the full card, otherwise it will only
377 * show a summary line.
379 * This code is a bit ugly, so perhaps an explanation is due: we do this
380 * in two passes through the vCard fields. On the first pass, we process
381 * fields we understand, and then render them in a pretty fashion at the
382 * end. Then we make a second pass, outputting all the fields we don't
383 * understand in a simple two-column name/value format.
384 * \param v the vCard to display
385 * \param full display all items of the vcard?
387 void display_parsed_vcard(struct vCard *v, int full) {
393 char *thisname, *thisvalue;
394 char firsttoken[SIZ];
403 strcpy(fullname, "");
411 name = vcard_get_prop(v, "fn", 1, 0, 0);
415 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
416 strcpy(fullname, name);
417 vcard_n_prettyize(fullname);
427 wprintf("<div align=center>"
428 "<table bgcolor=#aaaaaa width=50%%>");
429 for (pass=1; pass<=2; ++pass) {
431 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
433 thisname = strdup(v->prop[i].name);
434 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
436 for (j=0; j<num_tokens(thisname, ';'); ++j) {
437 extract_token(buf, thisname, j, ';', sizeof buf);
438 if (!strcasecmp(buf, "encoding=quoted-printable")) {
440 remove_token(thisname, j, ';');
442 if (!strcasecmp(buf, "encoding=base64")) {
444 remove_token(thisname, j, ';');
448 len = strlen(v->prop[i].value);
451 // %ff can become 6 bytes in utf8
452 thisvalue = malloc(len * 2 + 3);
453 j = CtdlDecodeQuotedPrintable(
454 thisvalue, v->prop[i].value,
459 // ff will become one byte..
460 thisvalue = malloc(len + 50);
462 thisvalue, v->prop[i].value,
463 strlen(v->prop[i].value) );
466 thisvalue = strdup(v->prop[i].value);
469 /** Various fields we may encounter ***/
471 /** N is name, but only if there's no FN already there */
472 if (!strcasecmp(firsttoken, "n")) {
473 if (IsEmptyStr(fullname)) {
474 strcpy(fullname, thisvalue);
475 vcard_n_prettyize(fullname);
479 /** FN (full name) is a true 'display name' field */
480 else if (!strcasecmp(firsttoken, "fn")) {
481 strcpy(fullname, thisvalue);
485 else if (!strcasecmp(firsttoken, "title")) {
486 strcpy(title, thisvalue);
490 else if (!strcasecmp(firsttoken, "org")) {
491 strcpy(org, thisvalue);
494 else if (!strcasecmp(firsttoken, "email")) {
495 if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
498 "<a href=\"display_enter"
499 "?force_room=_MAIL_?recp=");
501 urlesc(&mailto[strlen(mailto)], fullname);
502 urlesc(&mailto[strlen(mailto)], " <");
503 urlesc(&mailto[strlen(mailto)], thisvalue);
504 urlesc(&mailto[strlen(mailto)], ">");
506 strcat(mailto, "\">");
507 len = strlen(mailto);
508 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
509 strcat(mailto, "</A>");
511 else if (!strcasecmp(firsttoken, "tel")) {
512 if (!IsEmptyStr(phone)) strcat(phone, "<br />");
513 strcat(phone, thisvalue);
514 for (j=0; j<num_tokens(thisname, ';'); ++j) {
515 extract_token(buf, thisname, j, ';', sizeof buf);
516 if (!strcasecmp(buf, "tel"))
518 else if (!strcasecmp(buf, "work"))
519 strcat(phone, _(" (work)"));
520 else if (!strcasecmp(buf, "home"))
521 strcat(phone, _(" (home)"));
522 else if (!strcasecmp(buf, "cell"))
523 strcat(phone, _(" (cell)"));
531 else if (!strcasecmp(firsttoken, "adr")) {
534 wprintf(_("Address:"));
535 wprintf("</TD><TD>");
536 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
537 extract_token(buf, thisvalue, j, ';', sizeof buf);
538 if (!IsEmptyStr(buf)) {
540 if (j<3) wprintf("<br />");
544 wprintf("</TD></TR>\n");
547 else if (!strcasecmp(firsttoken, "version")) {
550 else if (!strcasecmp(firsttoken, "rev")) {
553 else if (!strcasecmp(firsttoken, "label")) {
558 /*** Don't show extra fields. They're ugly.
562 wprintf("</TD><TD>");
564 wprintf("</TD></TR>\n");
574 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
575 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
576 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
577 "<FONT SIZE=+1><B>");
579 wprintf("</B></FONT>");
580 if (!IsEmptyStr(title)) {
581 wprintf("<div align=right>");
585 if (!IsEmptyStr(org)) {
586 wprintf("<div align=right>");
590 wprintf("</TD></TR>\n");
592 if (!IsEmptyStr(phone)) {
594 wprintf(_("Telephone:"));
595 wprintf("</td><td>%s</td></tr>\n", phone);
597 if (!IsEmptyStr(mailto)) {
599 wprintf(_("E-mail:"));
600 wprintf("</td><td>%s</td></tr>\n", mailto);
606 wprintf("</table></div>\n");
612 * \brief Display a textual vCard
613 * (Converts to a vCard object and then calls the actual display function)
614 * Set 'full' to nonzero to display the whole card instead of a one-liner.
615 * Or, if "storename" is non-NULL, just store the person's name in that
616 * buffer instead of displaying the card at all.
617 * \param vcard_source the buffer containing the vcard text
618 * \param alpha what???
619 * \param full should we usse all lines?
620 * \param storename where to store???
622 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
628 v = vcard_load(vcard_source);
629 if (v == NULL) return;
631 name = vcard_get_prop(v, "n", 1, 0, 0);
637 if (storename != NULL) {
638 fetchname_parsed_vcard(v, storename);
640 else if ( (alpha == 0)
641 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
642 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
644 display_parsed_vcard(v, full);
658 * \brief I wanna SEE that message!
659 * \param msgnum the citadel number of the message to display
660 * \param printable_view are we doing a print view?
661 * \param section Optional for encapsulated message/rfc822 submessage)
663 void read_message(long msgnum, int printable_view, char *section) {
665 char mime_partnum[256];
667 char mime_filename[256];
668 char escaped_mime_filename[256];
669 char mime_content_type[256];
670 char mime_charset[256];
671 char mime_disposition[256];
673 struct attach_link *attach_links = NULL;
674 int num_attach_links = 0;
675 char mime_submessages[256];
682 char reply_all[4096];
688 char vcard_partnum[256];
689 char cal_partnum[256];
690 char *part_source = NULL;
691 char msg4_partnum[32];
693 iconv_t ic = (iconv_t)(-1) ;
694 char *ibuf; /**< Buffer of characters to be converted */
695 char *obuf; /**< Buffer for converted characters */
696 size_t ibuflen; /**< Length of input buffer */
697 size_t obuflen; /**< Length of output buffer */
698 char *osav; /**< Saved pointer to output buffer */
704 strcpy(reply_to, "");
705 strcpy(reply_all, "");
706 strcpy(vcard_partnum, "");
707 strcpy(cal_partnum, "");
708 strcpy(mime_content_type, "text/plain");
709 strcpy(mime_charset, "us-ascii");
710 strcpy(mime_submessages, "");
712 serv_printf("MSG4 %ld|%s", msgnum, section);
713 serv_getln(buf, sizeof buf);
716 wprintf(_("ERROR:"));
717 wprintf("</strong> %s<br />\n", &buf[4]);
721 /** begin everythingamundo table */
722 if (!printable_view) {
723 wprintf("<div class=\"fix_scrollbar_bug message\" ");
724 wprintf("onMouseOver=document.getElementById(\"msg%ld\").style.visibility=\"visible\" ", msgnum);
725 wprintf("onMouseOut=document.getElementById(\"msg%ld\").style.visibility=\"hidden\" >", msgnum);
728 /** begin message header table */
729 wprintf("<div class=\"message_header\">");
731 strcpy(m_subject, "");
734 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
735 if (!strcmp(buf, "000")) {
737 wprintf(_("unexpected end of message"));
738 wprintf(" (1)</i><br /><br />\n");
742 if (!strncasecmp(buf, "nhdr=yes", 8))
746 if (!strncasecmp(buf, "type=", 5))
747 format_type = atoi(&buf[5]);
748 if (!strncasecmp(buf, "from=", 5)) {
749 strcpy(from, &buf[5]);
751 wprintf("<a href=\"showuser?who=");
753 utf8ify_rfc822_string(from);
760 if (!strncasecmp(buf, "subj=", 5)) {
761 safestrncpy(m_subject, &buf[5], sizeof m_subject);
763 if (!strncasecmp(buf, "cccc=", 5)) {
765 safestrncpy(m_cc, &buf[5], sizeof m_cc);
766 if (!IsEmptyStr(reply_all)) {
767 strcat(reply_all, ", ");
769 len = strlen(reply_all);
770 safestrncpy(&reply_all[len], &buf[5],
771 (sizeof reply_all - len) );
773 if ((!strncasecmp(buf, "hnod=", 5))
774 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
775 wprintf("(%s) ", &buf[5]);
777 if ((!strncasecmp(buf, "room=", 5))
778 && (strcasecmp(&buf[5], WC->wc_roomname))
779 && (!IsEmptyStr(&buf[5])) ) {
781 wprintf("%s> ", &buf[5]);
783 if (!strncasecmp(buf, "rfca=", 5)) {
784 strcpy(rfca, &buf[5]);
790 if (!strncasecmp(buf, "node=", 5)) {
791 strcpy(node, &buf[5]);
792 if ( ((WC->room_flags & QR_NETWORK)
793 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
794 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
795 && (IsEmptyStr(rfca))
797 wprintf("@%s ", &buf[5]);
800 if (!strncasecmp(buf, "rcpt=", 5)) {
803 if (!IsEmptyStr(reply_all)) {
804 strcat(reply_all, ", ");
806 len = strlen(reply_all);
807 safestrncpy(&reply_all[len], &buf[5],
808 (sizeof reply_all - len) );
810 utf8ify_rfc822_string(&buf[5]);
815 if (!strncasecmp(buf, "time=", 5)) {
816 fmt_date(now, atol(&buf[5]), 0);
822 if (!strncasecmp(buf, "part=", 5)) {
823 extract_token(mime_name, &buf[5], 0, '|', sizeof mime_filename);
824 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
825 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
826 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
827 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
828 mime_length = extract_int(&buf[5], 5);
831 striplt(mime_filename);
832 if ( (IsEmptyStr(mime_filename)) && (!IsEmptyStr(mime_name)) ) {
833 strcpy(mime_filename, mime_name);
836 if (!strcasecmp(mime_content_type, "message/rfc822")) {
837 if (!IsEmptyStr(mime_submessages)) {
838 strcat(mime_submessages, "|");
840 strcat(mime_submessages, mime_partnum);
842 else if ((!strcasecmp(mime_disposition, "inline"))
843 && (!strncasecmp(mime_content_type, "image/", 6)) ){
845 attach_links = realloc(attach_links,
846 (num_attach_links*sizeof(struct attach_link)));
847 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
848 snprintf(attach_links[num_attach_links-1].html, 1024,
849 "<img src=\"mimepart/%ld/%s/%s\">",
850 msgnum, mime_partnum, mime_filename);
852 else if ( ( (!strcasecmp(mime_disposition, "attachment"))
853 || (!strcasecmp(mime_disposition, "inline"))
854 || (!strcasecmp(mime_disposition, ""))
855 ) && (!IsEmptyStr(mime_content_type))
858 attach_links = realloc(attach_links,
859 (num_attach_links*sizeof(struct attach_link)));
860 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
861 urlesc(escaped_mime_filename, mime_filename);
862 snprintf(attach_links[num_attach_links-1].html, 1024,
863 "<img src=\"static/diskette_24x.gif\" "
864 "border=0 align=middle>\n"
865 "%s (%s, %d bytes) [ "
866 "<a href=\"mimepart/%ld/%s/%s\""
867 "target=\"wc.%ld.%s\">%s</a>"
869 "<a href=\"mimepart_download/%ld/%s/%s\">%s</a>"
872 mime_content_type, mime_length,
873 msgnum, mime_partnum, escaped_mime_filename,
874 msgnum, mime_partnum,
876 msgnum, mime_partnum, escaped_mime_filename,
881 /** begin handler prep ***/
882 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
883 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
884 strcpy(vcard_partnum, mime_partnum);
887 if (!strcasecmp(mime_content_type, "text/calendar")) {
888 strcpy(cal_partnum, mime_partnum);
891 /** end handler prep ***/
897 /** Generate a reply-to address */
898 if (!IsEmptyStr(rfca)) {
899 if (!IsEmptyStr(from)) {
900 snprintf(reply_to, sizeof(reply_to), "%s <%s>", from, rfca);
903 strcpy(reply_to, rfca);
907 if ((!IsEmptyStr(node))
908 && (strcasecmp(node, serv_info.serv_nodename))
909 && (strcasecmp(node, serv_info.serv_humannode)) ) {
910 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
914 snprintf(reply_to, sizeof(reply_to), "%s", from);
923 utf8ify_rfc822_string(m_cc);
924 utf8ify_rfc822_string(m_subject);
927 /** start msg buttons */
929 if (!printable_view) {
930 wprintf("<p id=\"msg%ld\" class=\"msgbuttons\" >\n",msgnum);
933 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
934 wprintf("<a href=\"display_enter");
935 if (WC->is_mailbox) {
936 wprintf("?replyquote=%ld", msgnum);
939 urlescputs(reply_to);
940 if (!IsEmptyStr(m_subject)) {
941 wprintf("?subject=");
942 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
943 urlescputs(m_subject);
945 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Reply"));
949 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
950 if (!WC->is_mailbox) {
951 wprintf("<a href=\"display_enter");
952 wprintf("?replyquote=%ld", msgnum);
954 urlescputs(reply_to);
955 if (!IsEmptyStr(m_subject)) {
956 wprintf("?subject=");
957 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
958 urlescputs(m_subject);
960 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyQuoted"));
965 if (WC->wc_view == VIEW_MAILBOX) {
966 wprintf("<a href=\"display_enter");
967 wprintf("?replyquote=%ld", msgnum);
969 urlescputs(reply_to);
971 urlescputs(reply_all);
972 if (!IsEmptyStr(m_subject)) {
973 wprintf("?subject=");
974 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
975 urlescputs(m_subject);
977 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyAll"));
981 if (WC->wc_view == VIEW_MAILBOX) {
982 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
983 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
984 urlescputs(m_subject);
985 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Forward"));
988 /** If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
989 if ( (WC->is_room_aide) || (WC->is_mailbox) || (WC->room_flags2 & QR2_COLLABDEL) ) {
991 wprintf("<a href=\"confirm_move_msg?msgid=%ld\"><span>[</span>%s<span>]</span></a> ",
995 wprintf("<a href=\"delete_msg?msgid=%ld\" "
996 "onClick=\"return confirm('%s');\">"
997 "<span>[</span>%s<span>]</span> "
998 "</a> ", msgnum, _("Delete this message?"), _("Delete")
1003 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'); \" >"
1004 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Headers"));
1008 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'); \" >"
1009 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Print"));
1015 if (!IsEmptyStr(m_cc)) {
1022 if (!IsEmptyStr(m_subject)) {
1023 wprintf("<p class=\"message_subject\">");
1024 wprintf(_("Subject:"));
1033 wprintf("<div class=\"message_content\">");
1036 * Learn the content type
1038 strcpy(mime_content_type, "text/plain");
1039 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1040 if (!strcmp(buf, "000")) {
1042 wprintf(_("unexpected end of message"));
1043 wprintf(" (2)</i><br /><br />\n");
1046 if (!strncasecmp(buf, "X-Citadel-MSG4-Partnum:", 23)) {
1047 safestrncpy(msg4_partnum, &buf[23], sizeof(msg4_partnum));
1048 striplt(msg4_partnum);
1050 if (!strncasecmp(buf, "Content-type:", 13)) {
1052 safestrncpy(mime_content_type, &buf[13], sizeof(mime_content_type));
1053 striplt(mime_content_type);
1054 len = strlen(mime_content_type);
1055 for (i=0; i<len; ++i) {
1056 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1057 safestrncpy(mime_charset, &mime_content_type[i+8],
1058 sizeof mime_charset);
1061 for (i=0; i<len; ++i) {
1062 if (mime_content_type[i] == ';') {
1063 mime_content_type[i] = 0;
1067 len = strlen(mime_charset);
1068 for (i=0; i<len; ++i) {
1069 if (mime_charset[i] == ';') {
1070 mime_charset[i] = 0;
1077 /** Set up a character set conversion if we need to (and if we can) */
1079 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
1080 if ( (strcasecmp(mime_charset, "us-ascii"))
1081 && (strcasecmp(mime_charset, "UTF-8"))
1082 && (strcasecmp(mime_charset, ""))
1084 ic = ctdl_iconv_open("UTF-8", mime_charset);
1085 if (ic == (iconv_t)(-1) ) {
1086 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1087 __FILE__, __LINE__, mime_charset, strerror(errno));
1092 /** Messages in legacy Citadel variformat get handled thusly... */
1093 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1097 /** Boring old 80-column fixed format text gets handled this way... */
1098 else if ( (!strcasecmp(mime_content_type, "text/plain"))
1099 || (!strcasecmp(mime_content_type, "text")) ) {
1101 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1104 if ((len > 0) && buf[len-1] == '\n') buf[--len] = 0;
1105 if ((len > 0) && buf[len-1] == '\r') buf[--len] = 0;
1108 if (ic != (iconv_t)(-1) ) {
1110 ibuflen = strlen(ibuf);
1112 obuf = (char *) malloc(obuflen);
1114 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1115 osav[SIZ-obuflen] = 0;
1116 safestrncpy(buf, osav, sizeof buf);
1122 while ((!IsEmptyStr(buf)) && (isspace(buf[len-1])))
1125 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1126 wprintf("<blockquote>");
1128 } else if ((bq == 1) &&
1129 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1130 wprintf("</blockquote>");
1136 wprintf("</tt><br />\n");
1138 wprintf("</i><br />");
1141 else /** HTML is fun, but we've got to strip it first */
1142 if (!strcasecmp(mime_content_type, "text/html")) {
1143 output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
1146 /** Unknown weirdness */
1148 wprintf(_("I don't know how to display %s"), mime_content_type);
1149 wprintf("<br />\n", mime_content_type);
1150 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1153 /** If there are attached submessages, display them now... */
1154 if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
1155 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1156 extract_token(buf, mime_submessages, i, '|', sizeof buf);
1157 /** use printable_view to suppress buttons */
1158 wprintf("<blockquote>");
1159 read_message(msgnum, 1, buf);
1160 wprintf("</blockquote>");
1165 /** Afterwards, offer links to download attachments 'n' such */
1166 if ( (num_attach_links > 0) && (!section[0]) ) {
1167 for (i=0; i<num_attach_links; ++i) {
1168 if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
1169 wprintf("%s", attach_links[i].html);
1174 /** Handler for vCard parts */
1175 if (!IsEmptyStr(vcard_partnum)) {
1176 part_source = load_mimepart(msgnum, vcard_partnum);
1177 if (part_source != NULL) {
1179 /** If it's my vCard I can edit it */
1180 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1181 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1182 || (WC->wc_view == VIEW_ADDRESSBOOK)
1184 wprintf("<a href=\"edit_vcard?"
1185 "msgnum=%ld?partnum=%s\">",
1186 msgnum, vcard_partnum);
1187 wprintf("[%s]</a>", _("edit"));
1190 /** In all cases, display the full card */
1191 display_vcard(part_source, 0, 1, NULL);
1195 /** Handler for calendar parts */
1196 if (!IsEmptyStr(cal_partnum)) {
1197 part_source = load_mimepart(msgnum, cal_partnum);
1198 if (part_source != NULL) {
1199 cal_process_attachment(part_source,
1200 msgnum, cal_partnum);
1210 wprintf("</div>\n");
1212 /** end everythingamundo table */
1213 if (!printable_view) {
1214 wprintf("</div>\n");
1217 if (num_attach_links > 0) {
1222 if (ic != (iconv_t)(-1) ) {
1231 * \brief Unadorned HTML output of an individual message, suitable
1232 * for placing in a hidden iframe, for printing, or whatever
1234 * \param msgnum_as_string Message number, as a string instead of as a long int
1236 void embed_message(char *msgnum_as_string) {
1239 msgnum = atol(msgnum_as_string);
1240 begin_ajax_response();
1241 read_message(msgnum, 0, "");
1242 end_ajax_response();
1247 * \brief Printable view of a message
1249 * \param msgnum_as_string Message number, as a string instead of as a long int
1251 void print_message(char *msgnum_as_string) {
1254 msgnum = atol(msgnum_as_string);
1255 output_headers(0, 0, 0, 0, 0, 0);
1257 wprintf("Content-type: text/html\r\n"
1259 "Connection: close\r\n",
1263 wprintf("\r\n\r\n<html>\n"
1264 "<head><title>Printable view</title></head>\n"
1265 "<body onLoad=\" window.print(); window.close(); \">\n"
1268 read_message(msgnum, 1, "");
1270 wprintf("\n</body></html>\n\n");
1277 * \brief Display a message's headers
1279 * \param msgnum_as_string Message number, as a string instead of as a long int
1281 void display_headers(char *msgnum_as_string) {
1285 msgnum = atol(msgnum_as_string);
1286 output_headers(0, 0, 0, 0, 0, 0);
1288 wprintf("Content-type: text/plain\r\n"
1290 "Connection: close\r\n",
1294 serv_printf("MSG2 %ld|3", msgnum);
1295 serv_getln(buf, sizeof buf);
1296 if (buf[0] == '1') {
1297 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1298 wprintf("%s\n", buf);
1308 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1309 * or 'reply quoted' operations.
1311 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1312 * in this function. Doing so would throw a JavaScript error in the
1313 * 'supplied text' argument to the editor.
1315 * \param msgnum Message number of the message we want to quote
1316 * \param forward_attachments Nonzero if we want attachments to be forwarded
1318 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1320 char mime_partnum[256];
1321 char mime_filename[256];
1322 char mime_content_type[256];
1323 char mime_charset[256];
1324 char mime_disposition[256];
1326 char *attachments = NULL;
1328 int num_attachments = 0;
1329 struct wc_attachment *att, *aptr;
1330 char m_subject[256];
1336 int format_type = 0;
1341 iconv_t ic = (iconv_t)(-1) ;
1342 char *ibuf; /**< Buffer of characters to be converted */
1343 char *obuf; /**< Buffer for converted characters */
1344 size_t ibuflen; /**< Length of input buffer */
1345 size_t obuflen; /**< Length of output buffer */
1346 char *osav; /**< Saved pointer to output buffer */
1352 strcpy(reply_to, "");
1353 strcpy(mime_content_type, "text/plain");
1354 strcpy(mime_charset, "us-ascii");
1356 serv_printf("MSG4 %ld", msgnum);
1357 serv_getln(buf, sizeof buf);
1358 if (buf[0] != '1') {
1359 wprintf(_("ERROR:"));
1360 wprintf("%s<br />", &buf[4]);
1364 strcpy(m_subject, "");
1366 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1367 if (!strcmp(buf, "000")) {
1368 wprintf("%s (3)", _("unexpected end of message"));
1371 if (include_headers) {
1372 if (!strncasecmp(buf, "nhdr=yes", 8))
1376 if (!strncasecmp(buf, "type=", 5))
1377 format_type = atoi(&buf[5]);
1378 if (!strncasecmp(buf, "from=", 5)) {
1379 strcpy(from, &buf[5]);
1380 wprintf(_("from "));
1382 utf8ify_rfc822_string(from);
1386 if (!strncasecmp(buf, "subj=", 5)) {
1387 strcpy(m_subject, &buf[5]);
1389 if ((!strncasecmp(buf, "hnod=", 5))
1390 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1391 wprintf("(%s) ", &buf[5]);
1393 if ((!strncasecmp(buf, "room=", 5))
1394 && (strcasecmp(&buf[5], WC->wc_roomname))
1395 && (!IsEmptyStr(&buf[5])) ) {
1397 wprintf("%s> ", &buf[5]);
1399 if (!strncasecmp(buf, "rfca=", 5)) {
1400 strcpy(rfca, &buf[5]);
1406 if (!strncasecmp(buf, "node=", 5)) {
1407 strcpy(node, &buf[5]);
1408 if ( ((WC->room_flags & QR_NETWORK)
1409 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1410 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1411 && (IsEmptyStr(rfca))
1413 wprintf("@%s ", &buf[5]);
1416 if (!strncasecmp(buf, "rcpt=", 5)) {
1418 wprintf("%s ", &buf[5]);
1420 if (!strncasecmp(buf, "time=", 5)) {
1421 fmt_date(now, atol(&buf[5]), 0);
1422 wprintf("%s ", now);
1427 * Save attachment info for later. We can't start downloading them
1428 * yet because we're in the middle of a server transaction.
1430 if (!strncasecmp(buf, "part=", 5)) {
1431 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1434 sprintf(ptr, "%s%s\n",
1435 ((attachments != NULL) ? attachments : ""),
1440 lprintf(9, "attachments=<%s>\n", attachments);
1446 if (include_headers) {
1450 utf8ify_rfc822_string(m_subject);
1452 if (!IsEmptyStr(m_subject)) {
1453 wprintf(_("Subject:"));
1455 msgescputs(m_subject);
1466 * Learn the content type
1468 strcpy(mime_content_type, "text/plain");
1469 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1470 if (!strcmp(buf, "000")) {
1471 wprintf("%s (4)", _("unexpected end of message"));
1474 if (!strncasecmp(buf, "Content-type: ", 14)) {
1476 safestrncpy(mime_content_type, &buf[14],
1477 sizeof(mime_content_type));
1478 for (i=0; i<strlen(mime_content_type); ++i) {
1479 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1480 safestrncpy(mime_charset, &mime_content_type[i+8],
1481 sizeof mime_charset);
1484 len = strlen(mime_content_type);
1485 for (i=0; i<len; ++i) {
1486 if (mime_content_type[i] == ';') {
1487 mime_content_type[i] = 0;
1491 len = strlen(mime_charset);
1492 for (i=0; i<len; ++i) {
1493 if (mime_charset[i] == ';') {
1494 mime_charset[i] = 0;
1501 /** Set up a character set conversion if we need to (and if we can) */
1503 if ( (strcasecmp(mime_charset, "us-ascii"))
1504 && (strcasecmp(mime_charset, "UTF-8"))
1505 && (strcasecmp(mime_charset, ""))
1507 ic = ctdl_iconv_open("UTF-8", mime_charset);
1508 if (ic == (iconv_t)(-1) ) {
1509 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1510 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1515 /** Messages in legacy Citadel variformat get handled thusly... */
1516 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1520 /* Boring old 80-column fixed format text gets handled this way... */
1521 else if (!strcasecmp(mime_content_type, "text/plain")) {
1522 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1525 if (buf[len-1] == '\n') buf[--len] = 0;
1526 if (buf[len-1] == '\r') buf[--len] = 0;
1529 if (ic != (iconv_t)(-1) ) {
1533 obuf = (char *) malloc(obuflen);
1535 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1536 osav[SIZ-obuflen] = 0;
1537 safestrncpy(buf, osav, sizeof buf);
1543 while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
1546 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1547 wprintf("<blockquote>");
1549 } else if ((bq == 1) &&
1550 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1551 wprintf("</blockquote>");
1557 wprintf("</tt><br />");
1559 wprintf("</i><br />");
1562 /** HTML just gets escaped and stuffed back into the editor */
1563 else if (!strcasecmp(mime_content_type, "text/html")) {
1564 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1570 /** Unknown weirdness ... don't know how to handle this content type */
1572 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1576 /** end of body handler */
1579 * If there were attachments, we have to download them and insert them
1580 * into the attachment chain for the forwarded message we are composing.
1582 if ( (forward_attachments) && (num_attachments) ) {
1583 for (i=0; i<num_attachments; ++i) {
1584 extract_token(buf, attachments, i, '\n', sizeof buf);
1585 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1586 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1587 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1588 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1589 mime_length = extract_int(buf, 5);
1592 * tracing ... uncomment if necessary
1595 lprintf(9, "fwd filename: %s\n", mime_filename);
1596 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1597 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1598 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1599 lprintf(9, "fwd length : %d\n", mime_length);
1601 if ( (!strcasecmp(mime_disposition, "inline"))
1602 || (!strcasecmp(mime_disposition, "attachment")) ) {
1604 /* Create an attachment struct from this mime part... */
1605 att = malloc(sizeof(struct wc_attachment));
1606 memset(att, 0, sizeof(struct wc_attachment));
1607 att->length = mime_length;
1608 strcpy(att->content_type, mime_content_type);
1609 strcpy(att->filename, mime_filename);
1611 att->data = load_mimepart(msgnum, mime_partnum);
1613 /* And add it to the list. */
1614 if (WC->first_attachment == NULL) {
1615 WC->first_attachment = att;
1618 aptr = WC->first_attachment;
1619 while (aptr->next != NULL) aptr = aptr->next;
1628 if (ic != (iconv_t)(-1) ) {
1633 if (attachments != NULL) {
1639 * \brief Display one row in the mailbox summary view
1641 * \param num The row number to be displayed
1643 void display_summarized(int num) {
1646 wprintf("<tr id=\"m%ld\" style=\"font-weight:%s;\" "
1647 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1648 WC->summ[num].msgnum,
1649 (WC->summ[num].is_new ? "bold" : "normal"),
1650 WC->summ[num].msgnum
1653 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1654 escputs(WC->summ[num].subj);
1657 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1658 escputs(WC->summ[num].from);
1661 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1662 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1672 * \brief display the adressbook overview
1673 * \param msgnum the citadel message number
1674 * \param alpha what????
1676 void display_addressbook(long msgnum, char alpha) {
1678 char mime_partnum[SIZ];
1679 char mime_filename[SIZ];
1680 char mime_content_type[SIZ];
1681 char mime_disposition[SIZ];
1683 char vcard_partnum[SIZ];
1684 char *vcard_source = NULL;
1685 struct message_summary summ;
1687 memset(&summ, 0, sizeof(summ));
1688 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1690 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1692 serv_getln(buf, sizeof buf);
1693 if (buf[0] != '1') return;
1695 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1696 if (!strncasecmp(buf, "part=", 5)) {
1697 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1698 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1699 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1700 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1701 mime_length = extract_int(&buf[5], 5);
1703 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1704 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1705 strcpy(vcard_partnum, mime_partnum);
1711 if (!IsEmptyStr(vcard_partnum)) {
1712 vcard_source = load_mimepart(msgnum, vcard_partnum);
1713 if (vcard_source != NULL) {
1715 /** Display the summary line */
1716 display_vcard(vcard_source, alpha, 0, NULL);
1718 /** If it's my vCard I can edit it */
1719 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1720 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1721 || (WC->wc_view == VIEW_ADDRESSBOOK)
1723 wprintf("<a href=\"edit_vcard?"
1724 "msgnum=%ld?partnum=%s\">",
1725 msgnum, vcard_partnum);
1726 wprintf("[%s]</a>", _("edit"));
1738 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1739 * \param namebuf name to analyze, reverse if nescessary
1741 void lastfirst_firstlast(char *namebuf) {
1742 char firstname[SIZ];
1746 if (namebuf == NULL) return;
1747 if (strchr(namebuf, ';') != NULL) return;
1749 i = num_tokens(namebuf, ' ');
1752 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1753 remove_token(namebuf, i-1, ' ');
1754 strcpy(firstname, namebuf);
1755 sprintf(namebuf, "%s; %s", lastname, firstname);
1759 * \brief fetch what??? name
1760 * \param msgnum the citadel message number
1761 * \param namebuf where to put the name in???
1763 void fetch_ab_name(long msgnum, char *namebuf) {
1765 char mime_partnum[SIZ];
1766 char mime_filename[SIZ];
1767 char mime_content_type[SIZ];
1768 char mime_disposition[SIZ];
1770 char vcard_partnum[SIZ];
1771 char *vcard_source = NULL;
1773 struct message_summary summ;
1775 if (namebuf == NULL) return;
1776 strcpy(namebuf, "");
1778 memset(&summ, 0, sizeof(summ));
1779 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1781 sprintf(buf, "MSG0 %ld|0", msgnum); /** unfortunately we need the mime info now */
1783 serv_getln(buf, sizeof buf);
1784 if (buf[0] != '1') return;
1786 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1787 if (!strncasecmp(buf, "part=", 5)) {
1788 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1789 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1790 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1791 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1792 mime_length = extract_int(&buf[5], 5);
1794 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1795 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1796 strcpy(vcard_partnum, mime_partnum);
1802 if (!IsEmptyStr(vcard_partnum)) {
1803 vcard_source = load_mimepart(msgnum, vcard_partnum);
1804 if (vcard_source != NULL) {
1806 /* Grab the name off the card */
1807 display_vcard(vcard_source, 0, 0, namebuf);
1813 lastfirst_firstlast(namebuf);
1815 len = strlen(namebuf);
1816 for (i=0; i<len; ++i) {
1817 if (namebuf[i] != ';') return;
1819 strcpy(namebuf, _("(no name)"));
1825 * \brief Record compare function for sorting address book indices
1826 * \param ab1 adressbook one
1827 * \param ab2 adressbook two
1829 int abcmp(const void *ab1, const void *ab2) {
1831 (((const struct addrbookent *)ab1)->ab_name),
1832 (((const struct addrbookent *)ab2)->ab_name)
1838 * \brief Helper function for do_addrbook_view()
1839 * Converts a name into a three-letter tab label
1840 * \param tabbuf the tabbuffer to add name to
1841 * \param name the name to add to the tabbuffer
1843 void nametab(char *tabbuf, long len, char *name) {
1844 stresc(tabbuf, len, name, 0, 0);
1845 tabbuf[0] = toupper(tabbuf[0]);
1846 tabbuf[1] = tolower(tabbuf[1]);
1847 tabbuf[2] = tolower(tabbuf[2]);
1853 * \brief Render the address book using info we gathered during the scan
1854 * \param addrbook the addressbook to render
1855 * \param num_ab the number of the addressbook
1857 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1861 static int NAMESPERPAGE = 60;
1864 char tabfirst_label[64];
1866 char tablast_label[64];
1867 char this_tablabel[64];
1872 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1873 wprintf(_("This address book is empty."));
1874 wprintf("</i></div>\n");
1879 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1882 num_pages = (num_ab / NAMESPERPAGE) + 1;
1884 tablabels = malloc(num_pages * sizeof (char *));
1885 if (tablabels == NULL) {
1886 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1887 wprintf(_("An internal error has occurred."));
1888 wprintf("</i></div>\n");
1892 for (i=0; i<num_pages; ++i) {
1893 tabfirst = i * NAMESPERPAGE;
1894 tablast = tabfirst + NAMESPERPAGE - 1;
1895 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1896 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
1897 nametab(tablast_label, 64, addrbook[tablast].ab_name);
1898 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
1899 tablabels[i] = strdup(this_tablabel);
1902 tabbed_dialog(num_pages, tablabels);
1905 for (i=0; i<num_ab; ++i) {
1907 if ((i / NAMESPERPAGE) != page) { /* New tab */
1908 page = (i / NAMESPERPAGE);
1910 wprintf("</tr></table>\n");
1911 end_tab(page-1, num_pages);
1913 begin_tab(page, num_pages);
1914 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
1918 if ((displayed % 4) == 0) {
1919 if (displayed > 0) {
1923 wprintf("<tr bgcolor=\"#%s\">",
1924 (bg ? "DDDDDD" : "FFFFFF")
1930 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
1931 addrbook[i].ab_msgnum);
1932 wprintf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
1933 vcard_n_prettyize(addrbook[i].ab_name);
1934 escputs(addrbook[i].ab_name);
1935 wprintf("</a></td>\n");
1939 wprintf("</tr></table>\n");
1940 end_tab((num_pages-1), num_pages);
1942 for (i=0; i<num_pages; ++i) {
1951 * \brief load message pointers from the server
1952 * \param servcmd the citadel command to send to the citserver
1953 * \param with_headers what headers???
1955 int load_msg_ptrs(char *servcmd, int with_headers)
1966 int num_summ_alloc = 0;
1968 if (WC->summ != NULL) {
1973 num_summ_alloc = 100;
1975 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1978 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1980 serv_getln(buf, sizeof buf);
1981 if (buf[0] != '1') {
1984 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1985 if (nummsgs < maxload) {
1986 WC->msgarr[nummsgs] = extract_long(buf, 0);
1987 datestamp = extract_long(buf, 1);
1988 extract_token(fullname, buf, 2, '|', sizeof fullname);
1989 extract_token(nodename, buf, 3, '|', sizeof nodename);
1990 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1991 extract_token(subject, buf, 5, '|', sizeof subject);
1995 if (nummsgs > num_summ_alloc) {
1996 num_summ_alloc *= 2;
1997 WC->summ = realloc(WC->summ,
1998 num_summ_alloc * sizeof(struct message_summary));
2002 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
2003 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
2004 safestrncpy(WC->summ[nummsgs-1].subj,
2005 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
2006 if (!IsEmptyStr(fullname)) {
2007 safestrncpy(WC->summ[nummsgs-1].from,
2008 fullname, sizeof WC->summ[nummsgs-1].from);
2010 if (!IsEmptyStr(subject)) {
2011 safestrncpy(WC->summ[nummsgs-1].subj, subject,
2012 sizeof WC->summ[nummsgs-1].subj);
2015 /** Handle subjects with RFC2047 encoding */
2016 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
2018 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
2019 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
2022 if (!IsEmptyStr(nodename)) {
2023 if ( ((WC->room_flags & QR_NETWORK)
2024 || ((strcasecmp(nodename, serv_info.serv_nodename)
2025 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
2027 strcat(WC->summ[nummsgs-1].from, " @ ");
2028 strcat(WC->summ[nummsgs-1].from, nodename);
2032 WC->summ[nummsgs-1].date = datestamp;
2035 /** Handle senders with RFC2047 encoding */
2036 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
2038 if (strlen(WC->summ[nummsgs-1].from) > 25) {
2039 strcpy(&WC->summ[nummsgs-1].from[22], "...");
2048 * \brief qsort() compatible function to compare two longs in descending order.
2050 * \param s1 first number to compare
2051 * \param s2 second number to compare
2053 int longcmp_r(const void *s1, const void *s2) {
2060 if (l1 > l2) return(-1);
2061 if (l1 < l2) return(+1);
2067 * \brief qsort() compatible function to compare two message summary structs by ascending subject.
2069 * \param s1 first item to compare
2070 * \param s2 second item to compare
2072 int summcmp_subj(const void *s1, const void *s2) {
2073 struct message_summary *summ1;
2074 struct message_summary *summ2;
2076 summ1 = (struct message_summary *)s1;
2077 summ2 = (struct message_summary *)s2;
2078 return strcasecmp(summ1->subj, summ2->subj);
2082 * \brief qsort() compatible function to compare two message summary structs by descending subject.
2084 * \param s1 first item to compare
2085 * \param s2 second item to compare
2087 int summcmp_rsubj(const void *s1, const void *s2) {
2088 struct message_summary *summ1;
2089 struct message_summary *summ2;
2091 summ1 = (struct message_summary *)s1;
2092 summ2 = (struct message_summary *)s2;
2093 return strcasecmp(summ2->subj, summ1->subj);
2097 * \brief qsort() compatible function to compare two message summary structs by ascending sender.
2099 * \param s1 first item to compare
2100 * \param s2 second item to compare
2102 int summcmp_sender(const void *s1, const void *s2) {
2103 struct message_summary *summ1;
2104 struct message_summary *summ2;
2106 summ1 = (struct message_summary *)s1;
2107 summ2 = (struct message_summary *)s2;
2108 return strcasecmp(summ1->from, summ2->from);
2112 * \brief qsort() compatible function to compare two message summary structs by descending sender.
2114 * \param s1 first item to compare
2115 * \param s2 second item to compare
2117 int summcmp_rsender(const void *s1, const void *s2) {
2118 struct message_summary *summ1;
2119 struct message_summary *summ2;
2121 summ1 = (struct message_summary *)s1;
2122 summ2 = (struct message_summary *)s2;
2123 return strcasecmp(summ2->from, summ1->from);
2127 * \brief qsort() compatible function to compare two message summary structs by ascending date.
2129 * \param s1 first item to compare
2130 * \param s2 second item to compare
2132 int summcmp_date(const void *s1, const void *s2) {
2133 struct message_summary *summ1;
2134 struct message_summary *summ2;
2136 summ1 = (struct message_summary *)s1;
2137 summ2 = (struct message_summary *)s2;
2139 if (summ1->date < summ2->date) return -1;
2140 else if (summ1->date > summ2->date) return +1;
2145 * \brief qsort() compatible function to compare two message summary structs by descending date.
2147 * \param s1 first item to compare
2148 * \param s2 second item to compare
2150 int summcmp_rdate(const void *s1, const void *s2) {
2151 struct message_summary *summ1;
2152 struct message_summary *summ2;
2154 summ1 = (struct message_summary *)s1;
2155 summ2 = (struct message_summary *)s2;
2157 if (summ1->date < summ2->date) return +1;
2158 else if (summ1->date > summ2->date) return -1;
2165 * \brief command loop for reading messages
2167 * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
2169 void readloop(char *oper)
2178 long *displayed_msgs = NULL;
2179 int num_displayed = 0;
2181 int is_addressbook = 0;
2182 int is_singlecard = 0;
2183 int is_calendar = 0;
2188 int lowest_displayed = (-1);
2189 int highest_displayed = 0;
2190 struct addrbookent *addrbook = NULL;
2192 char *sortby = NULL;
2193 char sortpref_name[128];
2194 char sortpref_value[128];
2195 char *subjsort_button;
2196 char *sendsort_button;
2197 char *datesort_button;
2198 int bbs_reverse = 0;
2199 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
2201 if (WCC->wc_view == VIEW_WIKI) {
2202 sprintf(buf, "wiki?room=%s?page=home", WCC->wc_roomname);
2207 startmsg = atol(bstr("startmsg"));
2208 maxmsgs = atoi(bstr("maxmsgs"));
2209 is_summary = atoi(bstr("is_summary"));
2210 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2212 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WCC->wc_roomname);
2213 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
2215 sortby = bstr("sortby");
2216 if ( (!IsEmptyStr(sortby)) && (strcasecmp(sortby, sortpref_value)) ) {
2217 set_preference(sortpref_name, sortby, 1);
2219 if (IsEmptyStr(sortby)) sortby = sortpref_value;
2222 if (IsEmptyStr(sortby)) sortby = "rdate";
2224 /** message board sort */
2225 if (!strcasecmp(sortby, "reverse")) {
2232 output_headers(1, 1, 1, 0, 0, 0);
2235 * When in summary mode, always show ALL messages instead of just
2236 * new or old. Otherwise, show what the user asked for.
2238 if (!strcmp(oper, "readnew")) {
2239 strcpy(cmd, "MSGS NEW");
2241 else if (!strcmp(oper, "readold")) {
2242 strcpy(cmd, "MSGS OLD");
2244 else if (!strcmp(oper, "do_search")) {
2245 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2248 strcpy(cmd, "MSGS ALL");
2251 if ((WCC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
2253 if (!strcmp(oper, "do_search")) {
2254 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2257 strcpy(cmd, "MSGS ALL");
2261 if ((WCC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2263 if (!strcmp(oper, "do_search")) {
2264 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2267 strcpy(cmd, "MSGS ALL");
2272 if (is_summary) { /**< fetch header summary */
2273 snprintf(cmd, sizeof cmd, "MSGS %s|%s||1",
2274 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2275 (!strcmp(oper, "do_search") ? bstr("query") : "")
2282 * Are we doing a summary view? If so, we need to know old messages
2283 * and new messages, so we can do that pretty boldface thing for the
2286 strcpy(old_msgs, "");
2289 serv_getln(buf, sizeof buf);
2290 if (buf[0] == '2') {
2291 strcpy(old_msgs, &buf[4]);
2295 is_singlecard = atoi(bstr("is_singlecard"));
2297 if (WCC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2299 strcpy(cmd, "MSGS ALL");
2302 if (WCC->wc_default_view == VIEW_TASKS) { /**< tasks */
2304 strcpy(cmd, "MSGS ALL");
2307 if (WCC->wc_default_view == VIEW_NOTES) { /**< notes */
2309 strcpy(cmd, "MSGS ALL");
2314 wprintf("<div align=center>%s</div>\n", _("Click on any note to edit it."));
2315 wprintf("<div id=\"new_notes_here\"></div>\n");
2318 nummsgs = load_msg_ptrs(cmd, is_summary);
2321 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2322 wprintf("<div align=\"center\"><br /><em>");
2323 if (!strcmp(oper, "readnew")) {
2324 wprintf(_("No new messages."));
2325 } else if (!strcmp(oper, "readold")) {
2326 wprintf(_("No old messages."));
2328 wprintf(_("No messages here."));
2330 wprintf("</em><br /></div>\n");
2337 for (a = 0; a < nummsgs; ++a) {
2338 /** Are you a new message, or an old message? */
2340 if (is_msg_in_mset(old_msgs, WCC->msgarr[a])) {
2341 WCC->summ[a].is_new = 0;
2344 WCC->summ[a].is_new = 1;
2350 if (startmsg == 0L) {
2352 startmsg = WCC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2355 startmsg = WCC->msgarr[0];
2360 if (!strcasecmp(sortby, "subject")) {
2361 qsort(WCC->summ, WCC->num_summ,
2362 sizeof(struct message_summary), summcmp_subj);
2364 else if (!strcasecmp(sortby, "rsubject")) {
2365 qsort(WCC->summ, WCC->num_summ,
2366 sizeof(struct message_summary), summcmp_rsubj);
2368 else if (!strcasecmp(sortby, "sender")) {
2369 qsort(WCC->summ, WCC->num_summ,
2370 sizeof(struct message_summary), summcmp_sender);
2372 else if (!strcasecmp(sortby, "rsender")) {
2373 qsort(WCC->summ, WCC->num_summ,
2374 sizeof(struct message_summary), summcmp_rsender);
2376 else if (!strcasecmp(sortby, "date")) {
2377 qsort(WCC->summ, WCC->num_summ,
2378 sizeof(struct message_summary), summcmp_date);
2380 else if (!strcasecmp(sortby, "rdate")) {
2381 qsort(WCC->summ, WCC->num_summ,
2382 sizeof(struct message_summary), summcmp_rdate);
2386 if (!strcasecmp(sortby, "subject")) {
2387 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2389 else if (!strcasecmp(sortby, "rsubject")) {
2390 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2393 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2396 if (!strcasecmp(sortby, "sender")) {
2397 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2399 else if (!strcasecmp(sortby, "rsender")) {
2400 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2403 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2406 if (!strcasecmp(sortby, "date")) {
2407 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2409 else if (!strcasecmp(sortby, "rdate")) {
2410 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2413 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2418 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2419 " document.onkeydown = CtdlMsgListKeyPress; "
2420 " if (document.layers) { "
2421 " document.captureEvents(Event.KEYPRESS); "
2426 /** note that Date and Delete are now in the same column */
2427 wprintf("<div id=\"message_list_hdr\">"
2428 "<div class=\"fix_scrollbar_bug\">"
2429 "<table cellspacing=0 style=\"width:100%%\">"
2432 wprintf("<th width=%d%%>%s %s</th>"
2433 "<th width=%d%%>%s %s</th>"
2434 "<th width=%d%%>%s %s"
2436 "<input type=\"submit\" name=\"delete_button\" id=\"delbutton\" "
2437 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2443 _("Subject"), subjsort_button,
2444 SENDER_COL_WIDTH_PCT,
2445 _("Sender"), sendsort_button,
2446 DATE_PLUS_BUTTONS_WIDTH_PCT,
2447 _("Date"), datesort_button,
2450 wprintf("</table></div></div>\n");
2452 wprintf("<div id=\"message_list\">"
2454 "<div class=\"fix_scrollbar_bug\">\n"
2456 "<table class=\"mailbox_summary\" id=\"summary_headers\" "
2457 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2463 * Set the "is_bbview" variable if it appears that we are looking at
2464 * a classic bulletin board view.
2466 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2467 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2472 * If we're not currently looking at ALL requested
2473 * messages, then display the selector bar
2476 /** begin bbview scroller */
2477 wprintf("<form name=\"msgomatictop\" class=\"selector_top\" >");
2478 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2480 wprintf("<select name=\"whichones\" size=\"1\" "
2481 "OnChange=\"location.href=msgomatictop.whichones.options"
2482 "[selectedIndex].value\">\n");
2485 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2487 lo = b - maxmsgs + 2;
2489 wprintf("<option %s value="
2494 "%d-%d</option> \n",
2495 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2504 for (b=0; b<nummsgs; b = b + maxmsgs) {
2506 hi = b + maxmsgs + 1;
2507 if (hi > nummsgs) hi = nummsgs;
2508 wprintf("<option %s value="
2513 "%d-%d</option> \n",
2514 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2523 wprintf("<option value=\"%s?startmsg=%ld"
2524 "?maxmsgs=9999999?is_summary=%d\">",
2526 WCC->msgarr[0], is_summary);
2528 wprintf("</option>");
2529 wprintf("</select> ");
2530 wprintf(_("of %d messages."), nummsgs);
2532 /** forward/reverse */
2533 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2534 "OnChange=\"location.href='%s?sortby=forward'\"",
2535 (bbs_reverse ? "" : "checked"),
2539 wprintf(_("oldest to newest"));
2540 wprintf(" ");
2542 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2543 "OnChange=\"location.href='%s?sortby=reverse'\"",
2544 (bbs_reverse ? "checked" : ""),
2548 wprintf(_("newest to oldest"));
2551 wprintf("</select></form>\n");
2552 /** end bbview scroller */
2557 for (a = 0; a < nummsgs; ++a) {
2558 if ((WCC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2560 /** Display the message */
2562 display_summarized(a);
2564 else if (is_addressbook) {
2565 fetch_ab_name(WCC->msgarr[a], buf);
2567 addrbook = realloc(addrbook,
2568 (sizeof(struct addrbookent) * num_ab) );
2569 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2570 sizeof(addrbook[num_ab-1].ab_name));
2571 addrbook[num_ab-1].ab_msgnum = WCC->msgarr[a];
2573 else if (is_calendar) {
2574 display_calendar(WCC->msgarr[a]);
2576 else if (is_tasks) {
2577 display_task(WCC->msgarr[a]);
2579 else if (is_notes) {
2580 display_note(WCC->msgarr[a]);
2583 if (displayed_msgs == NULL) {
2584 displayed_msgs = malloc(sizeof(long) *
2585 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2587 displayed_msgs[num_displayed] = WCC->msgarr[a];
2590 if (lowest_displayed < 0) lowest_displayed = a;
2591 highest_displayed = a;
2599 if (displayed_msgs != NULL) {
2601 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2604 /** if we do a split bbview in the future, begin messages div here */
2606 for (a=0; a<num_displayed; ++a) {
2607 read_message(displayed_msgs[a], 0, "");
2610 /** if we do a split bbview in the future, end messages div here */
2612 free(displayed_msgs);
2613 displayed_msgs = NULL;
2618 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2619 wprintf("</div>"); /**< end of 'message_list' div */
2621 /** Here's the grab-it-to-resize-the-message-list widget */
2622 wprintf("<div id=\"resize_msglist\" "
2623 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2624 "<div class=\"fix_scrollbar_bug\"> <hr>"
2628 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2632 * Bump these because although we're thinking in zero base, the user
2633 * is a drooling idiot and is thinking in one base.
2636 ++highest_displayed;
2639 * If we're not currently looking at ALL requested
2640 * messages, then display the selector bar
2643 /** begin bbview scroller */
2644 wprintf("<form name=\"msgomatic\" class=\"selector_bottom\" >");
2645 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2647 wprintf("<select name=\"whichones\" size=\"1\" "
2648 "OnChange=\"location.href=msgomatic.whichones.options"
2649 "[selectedIndex].value\">\n");
2652 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2654 lo = b - maxmsgs + 2;
2656 wprintf("<option %s value="
2661 "%d-%d</option> \n",
2662 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2671 for (b=0; b<nummsgs; b = b + maxmsgs) {
2673 hi = b + maxmsgs + 1;
2674 if (hi > nummsgs) hi = nummsgs;
2675 wprintf("<option %s value="
2680 "%d-%d</option> \n",
2681 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2690 wprintf("<option value=\"%s?startmsg=%ld"
2691 "?maxmsgs=9999999?is_summary=%d\">",
2693 WCC->msgarr[0], is_summary);
2695 wprintf("</option>");
2696 wprintf("</select> ");
2697 wprintf(_("of %d messages."), nummsgs);
2699 /** forward/reverse */
2700 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2701 "OnChange=\"location.href='%s?sortby=forward'\"",
2702 (bbs_reverse ? "" : "checked"),
2706 wprintf(_("oldest to newest"));
2707 wprintf(" ");
2708 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2709 "OnChange=\"location.href='%s?sortby=reverse'\"",
2710 (bbs_reverse ? "checked" : ""),
2714 wprintf(_("newest to oldest"));
2717 wprintf("</form>\n");
2718 /** end bbview scroller */
2723 do_tasks_view(); /** Render the task list */
2727 do_calendar_view(); /** Render the calendar */
2730 if (is_addressbook) {
2731 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2734 /** Note: wDumpContent() will output one additional </div> tag. */
2735 wprintf("</div>\n"); /** end of 'content' div */
2738 /** free the summary */
2739 if (WCC->summ != NULL) {
2744 if (addrbook != NULL) free(addrbook);
2749 * \brief Back end for post_message()
2750 * ... this is where the actual message gets transmitted to the server.
2752 void post_mime_to_server(void) {
2754 int is_multipart = 0;
2756 struct wc_attachment *att;
2758 size_t encoded_length;
2759 size_t encoded_strlen;
2761 /** RFC2045 requires this, and some clients look for it... */
2762 serv_puts("MIME-Version: 1.0");
2763 serv_puts("X-Mailer: " PACKAGE_STRING);
2765 /** If there are attachments, we have to do multipart/mixed */
2766 if (WC->first_attachment != NULL) {
2771 sprintf(boundary, "Citadel--Multipart--%s--%04x--%04x",
2772 serv_info.serv_fqdn,
2777 /** Remember, serv_printf() appends an extra newline */
2778 serv_printf("Content-type: multipart/mixed; "
2779 "boundary=\"%s\"\n", boundary);
2780 serv_printf("This is a multipart message in MIME format.\n");
2781 serv_printf("--%s", boundary);
2784 serv_puts("Content-type: text/html; charset=utf-8");
2785 serv_puts("Content-Transfer-Encoding: quoted-printable");
2787 serv_puts("<html><body>\r\n");
2788 text_to_server_qp(bstr("msgtext")); /** Transmit message in quoted-printable encoding */
2789 serv_puts("</body></html>\r\n");
2793 /** Add in the attachments */
2794 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2796 encoded_length = ((att->length * 150) / 100);
2797 encoded = malloc(encoded_length);
2798 if (encoded == NULL) break;
2799 encoded_strlen = CtdlEncodeBase64(&encoded, att->data, att->length, &encoded_length, 1);
2801 serv_printf("--%s", boundary);
2802 serv_printf("Content-type: %s", att->content_type);
2803 serv_printf("Content-disposition: attachment; "
2804 "filename=\"%s\"", att->filename);
2805 serv_puts("Content-transfer-encoding: base64");
2807 serv_write(encoded, encoded_strlen);
2812 serv_printf("--%s--", boundary);
2820 * \brief Post message (or don't post message)
2822 * Note regarding the "dont_post" variable:
2823 * A random value (actually, it's just a timestamp) is inserted as a hidden
2824 * field called "postseq" when the display_enter page is generated. This
2825 * value is checked when posting, using the static variable dont_post. If a
2826 * user attempts to post twice using the same dont_post value, the message is
2827 * discarded. This prevents the accidental double-saving of the same message
2828 * if the user happens to click the browser "back" button.
2830 void post_message(void)
2833 char encoded_subject[1024];
2834 static long dont_post = (-1L);
2835 struct wc_attachment *att, *aptr;
2836 int is_anonymous = 0;
2839 display_name = bstr("display_name");
2840 if (!strcmp(display_name, "__ANONYMOUS__")) {
2845 if (WC->upload_length > 0) {
2847 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WC->upload_length);
2848 /** There's an attachment. Save it to this struct... */
2849 att = malloc(sizeof(struct wc_attachment));
2850 memset(att, 0, sizeof(struct wc_attachment));
2851 att->length = WC->upload_length;
2852 strcpy(att->content_type, WC->upload_content_type);
2853 strcpy(att->filename, WC->upload_filename);
2856 /** And add it to the list. */
2857 if (WC->first_attachment == NULL) {
2858 WC->first_attachment = att;
2861 aptr = WC->first_attachment;
2862 while (aptr->next != NULL) aptr = aptr->next;
2867 * Mozilla sends a simple filename, which is what we want,
2868 * but Satan's Browser sends an entire pathname. Reduce
2869 * the path to just a filename if we need to.
2871 while (num_tokens(att->filename, '/') > 1) {
2872 remove_token(att->filename, 0, '/');
2874 while (num_tokens(att->filename, '\\') > 1) {
2875 remove_token(att->filename, 0, '\\');
2879 * Transfer control of this memory from the upload struct
2880 * to the attachment struct.
2882 att->data = WC->upload;
2883 WC->upload_length = 0;
2889 if (!IsEmptyStr(bstr("cancel_button"))) {
2890 sprintf(WC->ImportantMessage,
2891 _("Cancelled. Message was not posted."));
2892 } else if (!IsEmptyStr(bstr("attach_button"))) {
2895 } else if (atol(bstr("postseq")) == dont_post) {
2896 sprintf(WC->ImportantMessage,
2897 _("Automatically cancelled because you have already "
2898 "saved this message."));
2900 rfc2047encode(encoded_subject, sizeof encoded_subject, bstr("subject"));
2901 sprintf(buf, "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s",
2909 bstr("my_email_addr")
2912 serv_getln(buf, sizeof buf);
2913 if (buf[0] == '4') {
2914 post_mime_to_server();
2915 if ( (!IsEmptyStr(bstr("recp")))
2916 || (!IsEmptyStr(bstr("cc" )))
2917 || (!IsEmptyStr(bstr("bcc" )))
2919 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2922 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2924 dont_post = atol(bstr("postseq"));
2926 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
2927 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2933 free_attachments(WC);
2936 * We may have been supplied with instructions regarding the location
2937 * to which we must return after posting. If found, go there.
2939 if (!IsEmptyStr(bstr("return_to"))) {
2940 http_redirect(bstr("return_to"));
2943 * If we were editing a page in a wiki room, go to that page now.
2945 else if (!IsEmptyStr(bstr("wikipage"))) {
2946 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
2950 * Otherwise, just go to the "read messages" loop.
2953 readloop("readnew");
2961 * \brief display the message entry screen
2963 void display_enter(void)
2969 struct wc_attachment *att;
2970 int recipient_required = 0;
2971 int subject_required = 0;
2972 int recipient_bad = 0;
2974 int is_anonymous = 0;
2975 long existing_page = (-1L);
2979 if (!IsEmptyStr(bstr("force_room"))) {
2980 gotoroom(bstr("force_room"));
2983 display_name = bstr("display_name");
2984 if (!strcmp(display_name, "__ANONYMOUS__")) {
2989 /** First test to see whether this is a room that requires recipients to be entered */
2990 serv_puts("ENT0 0");
2991 serv_getln(buf, sizeof buf);
2993 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
2994 recipient_required = 1;
2996 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2997 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2998 readloop("readnew");
3002 /* Is the server strongly recommending that the user enter a message subject? */
3003 if ((buf[3] != '\0') && (buf[4] != '\0')) {
3004 subject_required = extract_int(&buf[4], 1);
3008 * Are we perhaps in an address book view? If so, then an "enter
3009 * message" command really means "add new entry."
3011 if (WC->wc_default_view == VIEW_ADDRESSBOOK) {
3012 do_edit_vcard(-1, "", "", WC->wc_roomname);
3016 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
3018 * Are we perhaps in a calendar room? If so, then an "enter
3019 * message" command really means "add new calendar item."
3021 if (WC->wc_default_view == VIEW_CALENDAR) {
3022 display_edit_event();
3027 * Are we perhaps in a tasks view? If so, then an "enter
3028 * message" command really means "add new task."
3030 if (WC->wc_default_view == VIEW_TASKS) {
3031 display_edit_task();
3037 * Otherwise proceed normally.
3038 * Do a custom room banner with no navbar...
3040 output_headers(1, 1, 2, 0, 0, 0);
3041 wprintf("<div id=\"banner\">\n");
3042 embed_room_banner(NULL, navbar_none);
3043 wprintf("</div>\n");
3044 wprintf("<div id=\"content\">\n"
3045 "<div class=\"fix_scrollbar_bug message \">");
3047 /** Now check our actual recipients if there are any */
3048 if (recipient_required) {
3049 sprintf(buf, "ENT0 0|%s|%d|0||%s||%s|%s|%s",
3053 bstr("cc"), bstr("bcc"), bstr("wikipage"));
3055 serv_getln(buf, sizeof buf);
3057 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
3058 if (!IsEmptyStr(bstr("recp")) &&
3059 !IsEmptyStr(bstr("cc" )) &&
3060 !IsEmptyStr(bstr("bcc" ))) {
3064 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3065 wprintf("<em>%s</em><br />\n", &buf[4]);
3070 /** If we got this far, we can display the message entry screen. */
3072 /** begin message entry screen */
3074 "enctype=\"multipart/form-data\" "
3076 "accept-charset=\"UTF-8\" "
3078 "name=\"enterform\""
3080 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
3081 if (WC->wc_view == VIEW_WIKI) {
3082 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
3084 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
3085 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
3087 /** submit or cancel buttons */
3088 wprintf("<p class=\"send_edit_msg\">");
3089 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3090 if (recipient_required) {
3091 wprintf(_("Send message"));
3093 wprintf(_("Post message"));
3096 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3101 wprintf("<img src=\"static/newmess3_24x.gif\" class=\"imgedit\">");
3102 wprintf(" "); /** header bar */
3103 fmt_date(buf, now, 0);
3105 wprintf("\n"); /** header bar */
3107 wprintf("<table width=\"100%%\" class=\"edit_msg_table\">");
3109 wprintf("<th><label for=\"from_id\" > ");
3110 wprintf(_(" <I>from</I> "));
3111 wprintf("</label></th>");
3113 wprintf("<td colspan=\"2\">");
3115 /* Allow the user to select any of his valid screen names */
3117 wprintf("<select name=\"display_name\" size=1 id=\"from_id\">\n");
3120 serv_getln(buf, sizeof buf);
3121 if (buf[0] == '1') {
3122 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3123 wprintf("<option %s value=\"",
3124 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
3129 wprintf("</option>\n");
3133 if (WC->room_flags & QR_ANONOPT) {
3134 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
3135 ((!strcasecmp(bstr("__ANONYMOUS__"), WC->wc_fullname)) ? "selected" : ""),
3140 wprintf("</select>\n");
3142 /* If this is an email (not a post), allow the user to select any of his
3143 * valid email addresses.
3145 if (recipient_required) {
3147 serv_getln(buf, sizeof buf);
3148 if (buf[0] == '1') {
3149 wprintf("<select name=\"my_email_addr\" size=1>\n");
3150 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3151 wprintf("<option value=\"");
3155 wprintf("></option>\n");
3157 wprintf("</select>\n");
3161 wprintf(_(" <I>in</I> "));
3162 escputs(WC->wc_roomname);
3164 wprintf("</td></tr>");
3166 if (recipient_required) {
3168 wprintf("<tr><th><label for=\"recp_id\"> ");
3170 wprintf("</label></th>"
3171 "<td><input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
3172 escputs(bstr("recp"));
3173 wprintf("\" size=45 maxlength=1000 />");
3174 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
3175 wprintf("</td><td rowspan=\"3\" align=\"left\" valign=\"top\"");
3177 /** Pop open an address book -- begin **/
3179 "<a href=\"javascript:PopOpenAddressBook('recp_id|%s|cc_id|%s|bcc_id|%s');\" "
3181 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
3183 _("To:"), _("CC:"), _("BCC:"),
3184 _("Contacts"), _("Contacts")
3186 /** Pop open an address book -- end **/
3188 wprintf("</td></tr>");
3190 wprintf("<tr><th><label for=\"cc_id\"> ");
3192 wprintf("</label></th>"
3193 "<td><input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
3194 escputs(bstr("cc"));
3195 wprintf("\" size=45 maxlength=1000 />");
3196 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
3197 wprintf("</td></tr>");
3199 wprintf("<tr><th><label for=\"bcc_id\"> ");
3201 wprintf("</label></th>"
3202 "<td><input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
3203 escputs(bstr("bcc"));
3204 wprintf("\" size=45 maxlength=1000 />");
3205 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
3206 wprintf("</td></tr>");
3208 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
3209 wprintf("<script type=\"text/javascript\"> \n"
3210 " activate_entmsg_autocompleters(); \n"
3216 wprintf("<tr><th><label for=\"subject_id\" > ");
3217 if (recipient_required || subject_required) {
3218 wprintf(_("Subject:"));
3221 wprintf(_("Subject (optional):"));
3223 wprintf("</label></th>"
3224 "<td colspan=\"2\">"
3225 "<input type=\"text\" name=\"subject\" id=\"subject_id\" value=\" ");
3226 escputs(bstr("subject"));
3227 wprintf("\" size=45 maxlength=70>\n");
3228 wprintf("</td></tr>");
3230 wprintf("<tr><td colspan=\"3\"\n");
3232 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
3234 /** If we're continuing from a previous edit, put our partially-composed message back... */
3235 msgescputs(bstr("msgtext"));
3237 /* If we're forwarding a message, insert it here... */
3238 if (atol(bstr("fwdquote")) > 0L) {
3239 wprintf("<br><div align=center><i>");
3240 wprintf(_("--- forwarded message ---"));
3241 wprintf("</i></div><br>");
3242 pullquote_message(atol(bstr("fwdquote")), 1, 1);
3245 /** If we're replying quoted, insert the quote here... */
3246 else if (atol(bstr("replyquote")) > 0L) {
3249 pullquote_message(atol(bstr("replyquote")), 0, 1);
3250 wprintf("</blockquote><br>");
3253 /** If we're editing a wiki page, insert the existing page here... */
3254 else if (WC->wc_view == VIEW_WIKI) {
3255 safestrncpy(buf, bstr("wikipage"), sizeof buf);
3256 str_wiki_index(buf);
3257 existing_page = locate_message_by_uid(buf);
3258 if (existing_page >= 0L) {
3259 pullquote_message(existing_page, 1, 0);
3263 /** Insert our signature if appropriate... */
3264 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
3265 get_preference("use_sig", buf, sizeof buf);
3266 if (!strcasecmp(buf, "yes")) {
3268 get_preference("signature", ebuf, sizeof ebuf);
3269 euid_unescapize(buf, ebuf);
3270 wprintf("<br>--<br>");
3272 for (i=0; i<len; ++i) {
3273 if (buf[i] == '\n') {
3276 else if (buf[i] == '<') {
3279 else if (buf[i] == '>') {
3282 else if (buf[i] == '&') {
3285 else if (buf[i] == '\"') {
3288 else if (buf[i] == '\'') {
3291 else if (isprint(buf[i])) {
3292 wprintf("%c", buf[i]);
3298 wprintf("</textarea>");
3301 * The following template embeds the TinyMCE richedit control, and automatically
3302 * transforms the textarea into a richedit textarea.
3304 do_template("richedit");
3306 /** Enumerate any attachments which are already in place... */
3307 wprintf("<div class=\"attachment buttons\"><img src=\"static/diskette_24x.gif\" class=\"imgedit\" > ");
3308 wprintf(_("Attachments:"));
3310 wprintf("<select name=\"which_attachment\" size=1>");
3311 for (att = WC->first_attachment; att != NULL; att = att->next) {
3312 wprintf("<option value=\"");
3313 urlescputs(att->filename);
3315 escputs(att->filename);
3316 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3317 wprintf("</option>\n");
3319 wprintf("</select>");
3321 /** Now offer the ability to attach additional files... */
3322 wprintf(" ");
3323 wprintf(_("Attach file:"));
3324 wprintf(" <input name=\"attachfile\" class=\"attachfile\" "
3325 "size=16 type=\"file\">\n "
3326 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3330 /** Make sure we only insert our signature once */
3331 if (strcmp(bstr("sig_inserted"), "yes")) {
3332 wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
3335 wprintf("</td></tr></table>");
3337 wprintf("</form>\n");
3338 wprintf("</div></div>\n");
3340 DONE: address_book_popup();
3346 * \brief delete a message
3348 void delete_msg(void)
3353 msgid = atol(bstr("msgid"));
3355 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3356 serv_printf("DELE %ld", msgid);
3358 else { /** Otherwise move it to Trash */
3359 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3362 serv_getln(buf, sizeof buf);
3363 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3365 readloop("readnew");
3370 * \brief move a message to another folder
3377 msgid = atol(bstr("msgid"));
3379 if (!IsEmptyStr(bstr("move_button"))) {
3380 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3382 serv_getln(buf, sizeof buf);
3383 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3385 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3388 readloop("readnew");
3396 * \brief Confirm move of a message
3398 void confirm_move_msg(void)
3404 msgid = atol(bstr("msgid"));
3407 output_headers(1, 1, 2, 0, 0, 0);
3408 wprintf("<div id=\"banner\">\n");
3410 wprintf(_("Confirm move of message"));
3412 wprintf("</div>\n");
3414 wprintf("<div id=\"content\" class=\"service\">\n");
3416 wprintf("<CENTER>");
3418 wprintf(_("Move this message to:"));
3419 wprintf("<br />\n");
3421 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3422 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
3423 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3425 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3427 serv_getln(buf, sizeof buf);
3428 if (buf[0] == '1') {
3429 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3430 extract_token(targ, buf, 0, '|', sizeof targ);
3431 wprintf("<OPTION>");
3436 wprintf("</SELECT>\n");
3437 wprintf("<br />\n");
3439 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3441 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3442 wprintf("</form></CENTER>\n");
3444 wprintf("</CENTER>\n");