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 />");
497 "<a href=\"display_enter"
498 "?force_room=_MAIL_?recp=");
500 urlesc(&mailto[strlen(mailto)], fullname);
501 urlesc(&mailto[strlen(mailto)], " <");
502 urlesc(&mailto[strlen(mailto)], thisvalue);
503 urlesc(&mailto[strlen(mailto)], ">");
505 strcat(mailto, "\">");
506 stresc(&mailto[strlen(mailto)], thisvalue, 1, 1);
507 strcat(mailto, "</A>");
509 else if (!strcasecmp(firsttoken, "tel")) {
510 if (!IsEmptyStr(phone)) strcat(phone, "<br />");
511 strcat(phone, thisvalue);
512 for (j=0; j<num_tokens(thisname, ';'); ++j) {
513 extract_token(buf, thisname, j, ';', sizeof buf);
514 if (!strcasecmp(buf, "tel"))
516 else if (!strcasecmp(buf, "work"))
517 strcat(phone, _(" (work)"));
518 else if (!strcasecmp(buf, "home"))
519 strcat(phone, _(" (home)"));
520 else if (!strcasecmp(buf, "cell"))
521 strcat(phone, _(" (cell)"));
529 else if (!strcasecmp(firsttoken, "adr")) {
532 wprintf(_("Address:"));
533 wprintf("</TD><TD>");
534 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
535 extract_token(buf, thisvalue, j, ';', sizeof buf);
536 if (!IsEmptyStr(buf)) {
538 if (j<3) wprintf("<br />");
542 wprintf("</TD></TR>\n");
545 else if (!strcasecmp(firsttoken, "version")) {
548 else if (!strcasecmp(firsttoken, "rev")) {
551 else if (!strcasecmp(firsttoken, "label")) {
556 /*** Don't show extra fields. They're ugly.
560 wprintf("</TD><TD>");
562 wprintf("</TD></TR>\n");
572 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
573 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
574 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
575 "<FONT SIZE=+1><B>");
577 wprintf("</B></FONT>");
578 if (!IsEmptyStr(title)) {
579 wprintf("<div align=right>");
583 if (!IsEmptyStr(org)) {
584 wprintf("<div align=right>");
588 wprintf("</TD></TR>\n");
590 if (!IsEmptyStr(phone)) {
592 wprintf(_("Telephone:"));
593 wprintf("</td><td>%s</td></tr>\n", phone);
595 if (!IsEmptyStr(mailto)) {
597 wprintf(_("E-mail:"));
598 wprintf("</td><td>%s</td></tr>\n", mailto);
604 wprintf("</table></div>\n");
610 * \brief Display a textual vCard
611 * (Converts to a vCard object and then calls the actual display function)
612 * Set 'full' to nonzero to display the whole card instead of a one-liner.
613 * Or, if "storename" is non-NULL, just store the person's name in that
614 * buffer instead of displaying the card at all.
615 * \param vcard_source the buffer containing the vcard text
616 * \param alpha what???
617 * \param full should we usse all lines?
618 * \param storename where to store???
620 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
626 v = vcard_load(vcard_source);
627 if (v == NULL) return;
629 name = vcard_get_prop(v, "n", 1, 0, 0);
635 if (storename != NULL) {
636 fetchname_parsed_vcard(v, storename);
638 else if ( (alpha == 0)
639 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
640 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
642 display_parsed_vcard(v, full);
656 * \brief I wanna SEE that message!
657 * \param msgnum the citadel number of the message to display
658 * \param printable_view are we doing a print view?
659 * \param section Optional for encapsulated message/rfc822 submessage)
661 void read_message(long msgnum, int printable_view, char *section) {
663 char mime_partnum[256];
665 char mime_filename[256];
666 char mime_content_type[256];
667 char mime_charset[256];
668 char mime_disposition[256];
670 struct attach_link *attach_links = NULL;
671 int num_attach_links = 0;
672 char mime_submessages[256];
679 char reply_all[4096];
685 char vcard_partnum[256];
686 char cal_partnum[256];
687 char *part_source = NULL;
688 char msg4_partnum[32];
690 iconv_t ic = (iconv_t)(-1) ;
691 char *ibuf; /**< Buffer of characters to be converted */
692 char *obuf; /**< Buffer for converted characters */
693 size_t ibuflen; /**< Length of input buffer */
694 size_t obuflen; /**< Length of output buffer */
695 char *osav; /**< Saved pointer to output buffer */
701 strcpy(reply_to, "");
702 strcpy(reply_all, "");
703 strcpy(vcard_partnum, "");
704 strcpy(cal_partnum, "");
705 strcpy(mime_content_type, "text/plain");
706 strcpy(mime_charset, "us-ascii");
707 strcpy(mime_submessages, "");
709 serv_printf("MSG4 %ld|%s", msgnum, section);
710 serv_getln(buf, sizeof buf);
713 wprintf(_("ERROR:"));
714 wprintf("</strong> %s<br />\n", &buf[4]);
718 /** begin everythingamundo table */
719 if (!printable_view) {
720 wprintf("<div class=\"fix_scrollbar_bug message\" ");
721 wprintf("onMouseOver=document.getElementById(\"msg%ld\").style.visibility=\"visible\" ", msgnum);
722 wprintf("onMouseOut=document.getElementById(\"msg%ld\").style.visibility=\"hidden\" >", msgnum);
725 /** begin message header table */
726 wprintf("<div class=\"message_header\">");
728 strcpy(m_subject, "");
731 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
732 if (!strcmp(buf, "000")) {
734 wprintf(_("unexpected end of message"));
735 wprintf(" (1)</i><br /><br />\n");
739 if (!strncasecmp(buf, "nhdr=yes", 8))
743 if (!strncasecmp(buf, "type=", 5))
744 format_type = atoi(&buf[5]);
745 if (!strncasecmp(buf, "from=", 5)) {
746 strcpy(from, &buf[5]);
748 wprintf("<a href=\"showuser?who=");
750 utf8ify_rfc822_string(from);
757 if (!strncasecmp(buf, "subj=", 5)) {
758 safestrncpy(m_subject, &buf[5], sizeof m_subject);
760 if (!strncasecmp(buf, "cccc=", 5)) {
762 safestrncpy(m_cc, &buf[5], sizeof m_cc);
763 if (!IsEmptyStr(reply_all)) {
764 strcat(reply_all, ", ");
766 len = strlen(reply_all);
767 safestrncpy(&reply_all[len], &buf[5],
768 (sizeof reply_all - len) );
770 if ((!strncasecmp(buf, "hnod=", 5))
771 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
772 wprintf("(%s) ", &buf[5]);
774 if ((!strncasecmp(buf, "room=", 5))
775 && (strcasecmp(&buf[5], WC->wc_roomname))
776 && (!IsEmptyStr(&buf[5])) ) {
778 wprintf("%s> ", &buf[5]);
780 if (!strncasecmp(buf, "rfca=", 5)) {
781 strcpy(rfca, &buf[5]);
787 if (!strncasecmp(buf, "node=", 5)) {
788 strcpy(node, &buf[5]);
789 if ( ((WC->room_flags & QR_NETWORK)
790 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
791 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
792 && (IsEmptyStr(rfca))
794 wprintf("@%s ", &buf[5]);
797 if (!strncasecmp(buf, "rcpt=", 5)) {
800 if (!IsEmptyStr(reply_all)) {
801 strcat(reply_all, ", ");
803 len = strlen(reply_all);
804 safestrncpy(&reply_all[len], &buf[5],
805 (sizeof reply_all - len) );
807 utf8ify_rfc822_string(&buf[5]);
812 if (!strncasecmp(buf, "time=", 5)) {
813 fmt_date(now, atol(&buf[5]), 0);
819 if (!strncasecmp(buf, "part=", 5)) {
820 extract_token(mime_name, &buf[5], 0, '|', sizeof mime_filename);
821 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
822 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
823 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
824 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
825 mime_length = extract_int(&buf[5], 5);
828 striplt(mime_filename);
829 if ( (IsEmptyStr(mime_filename)) && (!IsEmptyStr(mime_name)) ) {
830 strcpy(mime_filename, mime_name);
833 if (!strcasecmp(mime_content_type, "message/rfc822")) {
834 if (!IsEmptyStr(mime_submessages)) {
835 strcat(mime_submessages, "|");
837 strcat(mime_submessages, mime_partnum);
839 else if ((!strcasecmp(mime_disposition, "inline"))
840 && (!strncasecmp(mime_content_type, "image/", 6)) ){
842 attach_links = realloc(attach_links,
843 (num_attach_links*sizeof(struct attach_link)));
844 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
845 snprintf(attach_links[num_attach_links-1].html, 1024,
846 "<img src=\"mimepart/%ld/%s/%s\">",
847 msgnum, mime_partnum, mime_filename);
849 else if ( ( (!strcasecmp(mime_disposition, "attachment"))
850 || (!strcasecmp(mime_disposition, "inline"))
851 || (!strcasecmp(mime_disposition, ""))
852 ) && (!IsEmptyStr(mime_content_type))
855 attach_links = realloc(attach_links,
856 (num_attach_links*sizeof(struct attach_link)));
857 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
858 snprintf(attach_links[num_attach_links-1].html, 1024,
859 "<img src=\"static/diskette_24x.gif\" "
860 "border=0 align=middle>\n"
861 "%s (%s, %d bytes) [ "
862 "<a href=\"mimepart/%ld/%s/%s\""
863 "target=\"wc.%ld.%s\">%s</a>"
865 "<a href=\"mimepart_download/%ld/%s/%s\">%s</a>"
868 mime_content_type, mime_length,
869 msgnum, mime_partnum, mime_filename,
870 msgnum, mime_partnum,
872 msgnum, mime_partnum, mime_filename,
877 /** begin handler prep ***/
878 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
879 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
880 strcpy(vcard_partnum, mime_partnum);
883 if (!strcasecmp(mime_content_type, "text/calendar")) {
884 strcpy(cal_partnum, mime_partnum);
887 /** end handler prep ***/
893 /** Generate a reply-to address */
894 if (!IsEmptyStr(rfca)) {
895 if (!IsEmptyStr(from)) {
896 snprintf(reply_to, sizeof(reply_to), "%s <%s>", from, rfca);
899 strcpy(reply_to, rfca);
903 if ((!IsEmptyStr(node))
904 && (strcasecmp(node, serv_info.serv_nodename))
905 && (strcasecmp(node, serv_info.serv_humannode)) ) {
906 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
910 snprintf(reply_to, sizeof(reply_to), "%s", from);
919 utf8ify_rfc822_string(m_cc);
920 utf8ify_rfc822_string(m_subject);
923 /** start msg buttons */
925 if (!printable_view) {
926 wprintf("<p id=\"msg%ld\" class=\"msgbuttons\" >\n",msgnum);
929 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
930 wprintf("<a href=\"display_enter");
931 if (WC->is_mailbox) {
932 wprintf("?replyquote=%ld", msgnum);
935 urlescputs(reply_to);
936 if (!IsEmptyStr(m_subject)) {
937 wprintf("?subject=");
938 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
939 urlescputs(m_subject);
941 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Reply"));
945 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
946 if (!WC->is_mailbox) {
947 wprintf("<a href=\"display_enter");
948 wprintf("?replyquote=%ld", msgnum);
950 urlescputs(reply_to);
951 if (!IsEmptyStr(m_subject)) {
952 wprintf("?subject=");
953 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
954 urlescputs(m_subject);
956 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyQuoted"));
961 if (WC->wc_view == VIEW_MAILBOX) {
962 wprintf("<a href=\"display_enter");
963 wprintf("?replyquote=%ld", msgnum);
965 urlescputs(reply_to);
967 urlescputs(reply_all);
968 if (!IsEmptyStr(m_subject)) {
969 wprintf("?subject=");
970 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
971 urlescputs(m_subject);
973 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyAll"));
977 if (WC->wc_view == VIEW_MAILBOX) {
978 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
979 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
980 urlescputs(m_subject);
981 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Forward"));
984 /** If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
985 if ( (WC->is_room_aide) || (WC->is_mailbox) || (WC->room_flags2 & QR2_COLLABDEL) ) {
987 wprintf("<a href=\"confirm_move_msg?msgid=%ld\"><span>[</span>%s<span>]</span></a> ",
991 wprintf("<a href=\"delete_msg?msgid=%ld\" "
992 "onClick=\"return confirm('%s');\">"
993 "<span>[</span>%s<span>]</span> "
994 "</a> ", msgnum, _("Delete this message?"), _("Delete")
999 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'); \" >"
1000 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Headers"));
1004 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'); \" >"
1005 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Print"));
1011 if (!IsEmptyStr(m_cc)) {
1018 if (!IsEmptyStr(m_subject)) {
1019 wprintf("<p class=\"message_subject\">");
1020 wprintf(_("Subject:"));
1029 wprintf("<div class=\"message_content\">");
1032 * Learn the content type
1034 strcpy(mime_content_type, "text/plain");
1035 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1036 if (!strcmp(buf, "000")) {
1038 wprintf(_("unexpected end of message"));
1039 wprintf(" (2)</i><br /><br />\n");
1042 if (!strncasecmp(buf, "X-Citadel-MSG4-Partnum:", 23)) {
1043 safestrncpy(msg4_partnum, &buf[23], sizeof(msg4_partnum));
1044 striplt(msg4_partnum);
1046 if (!strncasecmp(buf, "Content-type:", 13)) {
1048 safestrncpy(mime_content_type, &buf[13], sizeof(mime_content_type));
1049 striplt(mime_content_type);
1050 len = strlen(mime_content_type);
1051 for (i=0; i<len; ++i) {
1052 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1053 safestrncpy(mime_charset, &mime_content_type[i+8],
1054 sizeof mime_charset);
1057 for (i=0; i<len; ++i) {
1058 if (mime_content_type[i] == ';') {
1059 mime_content_type[i] = 0;
1063 len = strlen(mime_charset);
1064 for (i=0; i<len; ++i) {
1065 if (mime_charset[i] == ';') {
1066 mime_charset[i] = 0;
1073 /** Set up a character set conversion if we need to (and if we can) */
1075 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
1076 if ( (strcasecmp(mime_charset, "us-ascii"))
1077 && (strcasecmp(mime_charset, "UTF-8"))
1078 && (strcasecmp(mime_charset, ""))
1080 ic = ctdl_iconv_open("UTF-8", mime_charset);
1081 if (ic == (iconv_t)(-1) ) {
1082 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1083 __FILE__, __LINE__, mime_charset, strerror(errno));
1088 /** Messages in legacy Citadel variformat get handled thusly... */
1089 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1093 /** Boring old 80-column fixed format text gets handled this way... */
1094 else if ( (!strcasecmp(mime_content_type, "text/plain"))
1095 || (!strcasecmp(mime_content_type, "text")) ) {
1097 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1100 if ((len > 0) && buf[len-1] == '\n') buf[--len] = 0;
1101 if ((len > 0) && buf[len-1] == '\r') buf[--len] = 0;
1104 if (ic != (iconv_t)(-1) ) {
1106 ibuflen = strlen(ibuf);
1108 obuf = (char *) malloc(obuflen);
1110 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1111 osav[SIZ-obuflen] = 0;
1112 safestrncpy(buf, osav, sizeof buf);
1118 while ((!IsEmptyStr(buf)) && (isspace(buf[len-1])))
1121 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1122 wprintf("<blockquote>");
1124 } else if ((bq == 1) &&
1125 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1126 wprintf("</blockquote>");
1132 wprintf("</tt><br />\n");
1134 wprintf("</i><br />");
1137 else /** HTML is fun, but we've got to strip it first */
1138 if (!strcasecmp(mime_content_type, "text/html")) {
1139 output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
1142 /** Unknown weirdness */
1144 wprintf(_("I don't know how to display %s"), mime_content_type);
1145 wprintf("<br />\n", mime_content_type);
1146 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1149 /** If there are attached submessages, display them now... */
1150 if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
1151 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1152 extract_token(buf, mime_submessages, i, '|', sizeof buf);
1153 /** use printable_view to suppress buttons */
1154 wprintf("<blockquote>");
1155 read_message(msgnum, 1, buf);
1156 wprintf("</blockquote>");
1161 /** Afterwards, offer links to download attachments 'n' such */
1162 if ( (num_attach_links > 0) && (!section[0]) ) {
1163 for (i=0; i<num_attach_links; ++i) {
1164 if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
1165 wprintf("%s", attach_links[i].html);
1170 /** Handler for vCard parts */
1171 if (!IsEmptyStr(vcard_partnum)) {
1172 part_source = load_mimepart(msgnum, vcard_partnum);
1173 if (part_source != NULL) {
1175 /** If it's my vCard I can edit it */
1176 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1177 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1178 || (WC->wc_view == VIEW_ADDRESSBOOK)
1180 wprintf("<a href=\"edit_vcard?"
1181 "msgnum=%ld?partnum=%s\">",
1182 msgnum, vcard_partnum);
1183 wprintf("[%s]</a>", _("edit"));
1186 /** In all cases, display the full card */
1187 display_vcard(part_source, 0, 1, NULL);
1191 /** Handler for calendar parts */
1192 if (!IsEmptyStr(cal_partnum)) {
1193 part_source = load_mimepart(msgnum, cal_partnum);
1194 if (part_source != NULL) {
1195 cal_process_attachment(part_source,
1196 msgnum, cal_partnum);
1206 wprintf("</div>\n");
1208 /** end everythingamundo table */
1209 if (!printable_view) {
1210 wprintf("</div>\n");
1213 if (num_attach_links > 0) {
1218 if (ic != (iconv_t)(-1) ) {
1227 * \brief Unadorned HTML output of an individual message, suitable
1228 * for placing in a hidden iframe, for printing, or whatever
1230 * \param msgnum_as_string Message number, as a string instead of as a long int
1232 void embed_message(char *msgnum_as_string) {
1235 msgnum = atol(msgnum_as_string);
1236 begin_ajax_response();
1237 read_message(msgnum, 0, "");
1238 end_ajax_response();
1243 * \brief Printable view of a message
1245 * \param msgnum_as_string Message number, as a string instead of as a long int
1247 void print_message(char *msgnum_as_string) {
1250 msgnum = atol(msgnum_as_string);
1251 output_headers(0, 0, 0, 0, 0, 0);
1253 wprintf("Content-type: text/html\r\n"
1255 "Connection: close\r\n",
1259 wprintf("\r\n\r\n<html>\n"
1260 "<head><title>Printable view</title></head>\n"
1261 "<body onLoad=\" window.print(); window.close(); \">\n"
1264 read_message(msgnum, 1, "");
1266 wprintf("\n</body></html>\n\n");
1273 * \brief Display a message's headers
1275 * \param msgnum_as_string Message number, as a string instead of as a long int
1277 void display_headers(char *msgnum_as_string) {
1281 msgnum = atol(msgnum_as_string);
1282 output_headers(0, 0, 0, 0, 0, 0);
1284 wprintf("Content-type: text/plain\r\n"
1286 "Connection: close\r\n",
1290 serv_printf("MSG2 %ld|3", msgnum);
1291 serv_getln(buf, sizeof buf);
1292 if (buf[0] == '1') {
1293 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1294 wprintf("%s\n", buf);
1304 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1305 * or 'reply quoted' operations.
1307 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1308 * in this function. Doing so would throw a JavaScript error in the
1309 * 'supplied text' argument to the editor.
1311 * \param msgnum Message number of the message we want to quote
1312 * \param forward_attachments Nonzero if we want attachments to be forwarded
1314 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1316 char mime_partnum[256];
1317 char mime_filename[256];
1318 char mime_content_type[256];
1319 char mime_charset[256];
1320 char mime_disposition[256];
1322 char *attachments = NULL;
1324 int num_attachments = 0;
1325 struct wc_attachment *att, *aptr;
1326 char m_subject[256];
1332 int format_type = 0;
1337 iconv_t ic = (iconv_t)(-1) ;
1338 char *ibuf; /**< Buffer of characters to be converted */
1339 char *obuf; /**< Buffer for converted characters */
1340 size_t ibuflen; /**< Length of input buffer */
1341 size_t obuflen; /**< Length of output buffer */
1342 char *osav; /**< Saved pointer to output buffer */
1348 strcpy(reply_to, "");
1349 strcpy(mime_content_type, "text/plain");
1350 strcpy(mime_charset, "us-ascii");
1352 serv_printf("MSG4 %ld", msgnum);
1353 serv_getln(buf, sizeof buf);
1354 if (buf[0] != '1') {
1355 wprintf(_("ERROR:"));
1356 wprintf("%s<br />", &buf[4]);
1360 strcpy(m_subject, "");
1362 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1363 if (!strcmp(buf, "000")) {
1364 wprintf("%s (3)", _("unexpected end of message"));
1367 if (include_headers) {
1368 if (!strncasecmp(buf, "nhdr=yes", 8))
1372 if (!strncasecmp(buf, "type=", 5))
1373 format_type = atoi(&buf[5]);
1374 if (!strncasecmp(buf, "from=", 5)) {
1375 strcpy(from, &buf[5]);
1376 wprintf(_("from "));
1378 utf8ify_rfc822_string(from);
1382 if (!strncasecmp(buf, "subj=", 5)) {
1383 strcpy(m_subject, &buf[5]);
1385 if ((!strncasecmp(buf, "hnod=", 5))
1386 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1387 wprintf("(%s) ", &buf[5]);
1389 if ((!strncasecmp(buf, "room=", 5))
1390 && (strcasecmp(&buf[5], WC->wc_roomname))
1391 && (!IsEmptyStr(&buf[5])) ) {
1393 wprintf("%s> ", &buf[5]);
1395 if (!strncasecmp(buf, "rfca=", 5)) {
1396 strcpy(rfca, &buf[5]);
1402 if (!strncasecmp(buf, "node=", 5)) {
1403 strcpy(node, &buf[5]);
1404 if ( ((WC->room_flags & QR_NETWORK)
1405 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1406 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1407 && (IsEmptyStr(rfca))
1409 wprintf("@%s ", &buf[5]);
1412 if (!strncasecmp(buf, "rcpt=", 5)) {
1414 wprintf("%s ", &buf[5]);
1416 if (!strncasecmp(buf, "time=", 5)) {
1417 fmt_date(now, atol(&buf[5]), 0);
1418 wprintf("%s ", now);
1423 * Save attachment info for later. We can't start downloading them
1424 * yet because we're in the middle of a server transaction.
1426 if (!strncasecmp(buf, "part=", 5)) {
1427 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1430 sprintf(ptr, "%s%s\n",
1431 ((attachments != NULL) ? attachments : ""),
1436 lprintf(9, "attachments=<%s>\n", attachments);
1442 if (include_headers) {
1446 utf8ify_rfc822_string(m_subject);
1448 if (!IsEmptyStr(m_subject)) {
1449 wprintf(_("Subject:"));
1451 msgescputs(m_subject);
1462 * Learn the content type
1464 strcpy(mime_content_type, "text/plain");
1465 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1466 if (!strcmp(buf, "000")) {
1467 wprintf("%s (4)", _("unexpected end of message"));
1470 if (!strncasecmp(buf, "Content-type: ", 14)) {
1472 safestrncpy(mime_content_type, &buf[14],
1473 sizeof(mime_content_type));
1474 for (i=0; i<strlen(mime_content_type); ++i) {
1475 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1476 safestrncpy(mime_charset, &mime_content_type[i+8],
1477 sizeof mime_charset);
1480 len = strlen(mime_content_type);
1481 for (i=0; i<len; ++i) {
1482 if (mime_content_type[i] == ';') {
1483 mime_content_type[i] = 0;
1487 len = strlen(mime_charset);
1488 for (i=0; i<len; ++i) {
1489 if (mime_charset[i] == ';') {
1490 mime_charset[i] = 0;
1497 /** Set up a character set conversion if we need to (and if we can) */
1499 if ( (strcasecmp(mime_charset, "us-ascii"))
1500 && (strcasecmp(mime_charset, "UTF-8"))
1501 && (strcasecmp(mime_charset, ""))
1503 ic = ctdl_iconv_open("UTF-8", mime_charset);
1504 if (ic == (iconv_t)(-1) ) {
1505 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1506 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1511 /** Messages in legacy Citadel variformat get handled thusly... */
1512 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1516 /* Boring old 80-column fixed format text gets handled this way... */
1517 else if (!strcasecmp(mime_content_type, "text/plain")) {
1518 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1521 if (buf[len-1] == '\n') buf[--len] = 0;
1522 if (buf[len-1] == '\r') buf[--len] = 0;
1525 if (ic != (iconv_t)(-1) ) {
1529 obuf = (char *) malloc(obuflen);
1531 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1532 osav[SIZ-obuflen] = 0;
1533 safestrncpy(buf, osav, sizeof buf);
1539 while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
1542 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1543 wprintf("<blockquote>");
1545 } else if ((bq == 1) &&
1546 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1547 wprintf("</blockquote>");
1553 wprintf("</tt><br />");
1555 wprintf("</i><br />");
1558 /** HTML just gets escaped and stuffed back into the editor */
1559 else if (!strcasecmp(mime_content_type, "text/html")) {
1560 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1566 /** Unknown weirdness ... don't know how to handle this content type */
1568 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1572 /** end of body handler */
1575 * If there were attachments, we have to download them and insert them
1576 * into the attachment chain for the forwarded message we are composing.
1578 if ( (forward_attachments) && (num_attachments) ) {
1579 for (i=0; i<num_attachments; ++i) {
1580 extract_token(buf, attachments, i, '\n', sizeof buf);
1581 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1582 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1583 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1584 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1585 mime_length = extract_int(buf, 5);
1588 * tracing ... uncomment if necessary
1591 lprintf(9, "fwd filename: %s\n", mime_filename);
1592 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1593 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1594 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1595 lprintf(9, "fwd length : %d\n", mime_length);
1597 if ( (!strcasecmp(mime_disposition, "inline"))
1598 || (!strcasecmp(mime_disposition, "attachment")) ) {
1600 /* Create an attachment struct from this mime part... */
1601 att = malloc(sizeof(struct wc_attachment));
1602 memset(att, 0, sizeof(struct wc_attachment));
1603 att->length = mime_length;
1604 strcpy(att->content_type, mime_content_type);
1605 strcpy(att->filename, mime_filename);
1607 att->data = load_mimepart(msgnum, mime_partnum);
1609 /* And add it to the list. */
1610 if (WC->first_attachment == NULL) {
1611 WC->first_attachment = att;
1614 aptr = WC->first_attachment;
1615 while (aptr->next != NULL) aptr = aptr->next;
1624 if (ic != (iconv_t)(-1) ) {
1629 if (attachments != NULL) {
1635 * \brief Display one row in the mailbox summary view
1637 * \param num The row number to be displayed
1639 void display_summarized(int num) {
1642 wprintf("<tr id=\"m%ld\" style=\"font-weight:%s;\" "
1643 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1644 WC->summ[num].msgnum,
1645 (WC->summ[num].is_new ? "bold" : "normal"),
1646 WC->summ[num].msgnum
1649 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1650 escputs(WC->summ[num].subj);
1653 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1654 escputs(WC->summ[num].from);
1657 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1658 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1668 * \brief display the adressbook overview
1669 * \param msgnum the citadel message number
1670 * \param alpha what????
1672 void display_addressbook(long msgnum, char alpha) {
1674 char mime_partnum[SIZ];
1675 char mime_filename[SIZ];
1676 char mime_content_type[SIZ];
1677 char mime_disposition[SIZ];
1679 char vcard_partnum[SIZ];
1680 char *vcard_source = NULL;
1681 struct message_summary summ;
1683 memset(&summ, 0, sizeof(summ));
1684 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1686 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1688 serv_getln(buf, sizeof buf);
1689 if (buf[0] != '1') return;
1691 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1692 if (!strncasecmp(buf, "part=", 5)) {
1693 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1694 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1695 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1696 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1697 mime_length = extract_int(&buf[5], 5);
1699 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1700 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1701 strcpy(vcard_partnum, mime_partnum);
1707 if (!IsEmptyStr(vcard_partnum)) {
1708 vcard_source = load_mimepart(msgnum, vcard_partnum);
1709 if (vcard_source != NULL) {
1711 /** Display the summary line */
1712 display_vcard(vcard_source, alpha, 0, NULL);
1714 /** If it's my vCard I can edit it */
1715 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1716 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1717 || (WC->wc_view == VIEW_ADDRESSBOOK)
1719 wprintf("<a href=\"edit_vcard?"
1720 "msgnum=%ld?partnum=%s\">",
1721 msgnum, vcard_partnum);
1722 wprintf("[%s]</a>", _("edit"));
1734 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1735 * \param namebuf name to analyze, reverse if nescessary
1737 void lastfirst_firstlast(char *namebuf) {
1738 char firstname[SIZ];
1742 if (namebuf == NULL) return;
1743 if (strchr(namebuf, ';') != NULL) return;
1745 i = num_tokens(namebuf, ' ');
1748 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1749 remove_token(namebuf, i-1, ' ');
1750 strcpy(firstname, namebuf);
1751 sprintf(namebuf, "%s; %s", lastname, firstname);
1755 * \brief fetch what??? name
1756 * \param msgnum the citadel message number
1757 * \param namebuf where to put the name in???
1759 void fetch_ab_name(long msgnum, char *namebuf) {
1761 char mime_partnum[SIZ];
1762 char mime_filename[SIZ];
1763 char mime_content_type[SIZ];
1764 char mime_disposition[SIZ];
1766 char vcard_partnum[SIZ];
1767 char *vcard_source = NULL;
1769 struct message_summary summ;
1771 if (namebuf == NULL) return;
1772 strcpy(namebuf, "");
1774 memset(&summ, 0, sizeof(summ));
1775 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1777 sprintf(buf, "MSG0 %ld|0", msgnum); /** unfortunately we need the mime info now */
1779 serv_getln(buf, sizeof buf);
1780 if (buf[0] != '1') return;
1782 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1783 if (!strncasecmp(buf, "part=", 5)) {
1784 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1785 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1786 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1787 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1788 mime_length = extract_int(&buf[5], 5);
1790 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1791 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1792 strcpy(vcard_partnum, mime_partnum);
1798 if (!IsEmptyStr(vcard_partnum)) {
1799 vcard_source = load_mimepart(msgnum, vcard_partnum);
1800 if (vcard_source != NULL) {
1802 /* Grab the name off the card */
1803 display_vcard(vcard_source, 0, 0, namebuf);
1809 lastfirst_firstlast(namebuf);
1811 len = strlen(namebuf);
1812 for (i=0; i<len; ++i) {
1813 if (namebuf[i] != ';') return;
1815 strcpy(namebuf, _("(no name)"));
1821 * \brief Record compare function for sorting address book indices
1822 * \param ab1 adressbook one
1823 * \param ab2 adressbook two
1825 int abcmp(const void *ab1, const void *ab2) {
1827 (((const struct addrbookent *)ab1)->ab_name),
1828 (((const struct addrbookent *)ab2)->ab_name)
1834 * \brief Helper function for do_addrbook_view()
1835 * Converts a name into a three-letter tab label
1836 * \param tabbuf the tabbuffer to add name to
1837 * \param name the name to add to the tabbuffer
1839 void nametab(char *tabbuf, char *name) {
1840 stresc(tabbuf, name, 0, 0);
1841 tabbuf[0] = toupper(tabbuf[0]);
1842 tabbuf[1] = tolower(tabbuf[1]);
1843 tabbuf[2] = tolower(tabbuf[2]);
1849 * \brief Render the address book using info we gathered during the scan
1850 * \param addrbook the addressbook to render
1851 * \param num_ab the number of the addressbook
1853 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1857 static int NAMESPERPAGE = 60;
1860 char tabfirst_label[64];
1862 char tablast_label[64];
1863 char this_tablabel[64];
1868 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1869 wprintf(_("This address book is empty."));
1870 wprintf("</i></div>\n");
1875 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1878 num_pages = (num_ab / NAMESPERPAGE) + 1;
1880 tablabels = malloc(num_pages * sizeof (char *));
1881 if (tablabels == NULL) {
1882 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1883 wprintf(_("An internal error has occurred."));
1884 wprintf("</i></div>\n");
1888 for (i=0; i<num_pages; ++i) {
1889 tabfirst = i * NAMESPERPAGE;
1890 tablast = tabfirst + NAMESPERPAGE - 1;
1891 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1892 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1893 nametab(tablast_label, addrbook[tablast].ab_name);
1894 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
1895 tablabels[i] = strdup(this_tablabel);
1898 tabbed_dialog(num_pages, tablabels);
1901 for (i=0; i<num_ab; ++i) {
1903 if ((i / NAMESPERPAGE) != page) { /* New tab */
1904 page = (i / NAMESPERPAGE);
1906 wprintf("</tr></table>\n");
1907 end_tab(page-1, num_pages);
1909 begin_tab(page, num_pages);
1910 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
1914 if ((displayed % 4) == 0) {
1915 if (displayed > 0) {
1919 wprintf("<tr bgcolor=\"#%s\">",
1920 (bg ? "DDDDDD" : "FFFFFF")
1926 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
1927 addrbook[i].ab_msgnum);
1928 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1929 vcard_n_prettyize(addrbook[i].ab_name);
1930 escputs(addrbook[i].ab_name);
1931 wprintf("</a></td>\n");
1935 wprintf("</tr></table>\n");
1936 end_tab((num_pages-1), num_pages);
1938 for (i=0; i<num_pages; ++i) {
1947 * \brief load message pointers from the server
1948 * \param servcmd the citadel command to send to the citserver
1949 * \param with_headers what headers???
1951 int load_msg_ptrs(char *servcmd, int with_headers)
1962 int num_summ_alloc = 0;
1964 if (WC->summ != NULL) {
1969 num_summ_alloc = 100;
1971 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1974 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1976 serv_getln(buf, sizeof buf);
1977 if (buf[0] != '1') {
1980 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1981 if (nummsgs < maxload) {
1982 WC->msgarr[nummsgs] = extract_long(buf, 0);
1983 datestamp = extract_long(buf, 1);
1984 extract_token(fullname, buf, 2, '|', sizeof fullname);
1985 extract_token(nodename, buf, 3, '|', sizeof nodename);
1986 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1987 extract_token(subject, buf, 5, '|', sizeof subject);
1991 if (nummsgs > num_summ_alloc) {
1992 num_summ_alloc *= 2;
1993 WC->summ = realloc(WC->summ,
1994 num_summ_alloc * sizeof(struct message_summary));
1998 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1999 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
2000 safestrncpy(WC->summ[nummsgs-1].subj,
2001 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
2002 if (!IsEmptyStr(fullname)) {
2003 safestrncpy(WC->summ[nummsgs-1].from,
2004 fullname, sizeof WC->summ[nummsgs-1].from);
2006 if (!IsEmptyStr(subject)) {
2007 safestrncpy(WC->summ[nummsgs-1].subj, subject,
2008 sizeof WC->summ[nummsgs-1].subj);
2011 /** Handle subjects with RFC2047 encoding */
2012 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
2014 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
2015 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
2018 if (!IsEmptyStr(nodename)) {
2019 if ( ((WC->room_flags & QR_NETWORK)
2020 || ((strcasecmp(nodename, serv_info.serv_nodename)
2021 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
2023 strcat(WC->summ[nummsgs-1].from, " @ ");
2024 strcat(WC->summ[nummsgs-1].from, nodename);
2028 WC->summ[nummsgs-1].date = datestamp;
2031 /** Handle senders with RFC2047 encoding */
2032 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
2034 if (strlen(WC->summ[nummsgs-1].from) > 25) {
2035 strcpy(&WC->summ[nummsgs-1].from[22], "...");
2044 * \brief qsort() compatible function to compare two longs in descending order.
2046 * \param s1 first number to compare
2047 * \param s2 second number to compare
2049 int longcmp_r(const void *s1, const void *s2) {
2056 if (l1 > l2) return(-1);
2057 if (l1 < l2) return(+1);
2063 * \brief qsort() compatible function to compare two message summary structs by ascending subject.
2065 * \param s1 first item to compare
2066 * \param s2 second item to compare
2068 int summcmp_subj(const void *s1, const void *s2) {
2069 struct message_summary *summ1;
2070 struct message_summary *summ2;
2072 summ1 = (struct message_summary *)s1;
2073 summ2 = (struct message_summary *)s2;
2074 return strcasecmp(summ1->subj, summ2->subj);
2078 * \brief qsort() compatible function to compare two message summary structs by descending subject.
2080 * \param s1 first item to compare
2081 * \param s2 second item to compare
2083 int summcmp_rsubj(const void *s1, const void *s2) {
2084 struct message_summary *summ1;
2085 struct message_summary *summ2;
2087 summ1 = (struct message_summary *)s1;
2088 summ2 = (struct message_summary *)s2;
2089 return strcasecmp(summ2->subj, summ1->subj);
2093 * \brief qsort() compatible function to compare two message summary structs by ascending sender.
2095 * \param s1 first item to compare
2096 * \param s2 second item to compare
2098 int summcmp_sender(const void *s1, const void *s2) {
2099 struct message_summary *summ1;
2100 struct message_summary *summ2;
2102 summ1 = (struct message_summary *)s1;
2103 summ2 = (struct message_summary *)s2;
2104 return strcasecmp(summ1->from, summ2->from);
2108 * \brief qsort() compatible function to compare two message summary structs by descending sender.
2110 * \param s1 first item to compare
2111 * \param s2 second item to compare
2113 int summcmp_rsender(const void *s1, const void *s2) {
2114 struct message_summary *summ1;
2115 struct message_summary *summ2;
2117 summ1 = (struct message_summary *)s1;
2118 summ2 = (struct message_summary *)s2;
2119 return strcasecmp(summ2->from, summ1->from);
2123 * \brief qsort() compatible function to compare two message summary structs by ascending date.
2125 * \param s1 first item to compare
2126 * \param s2 second item to compare
2128 int summcmp_date(const void *s1, const void *s2) {
2129 struct message_summary *summ1;
2130 struct message_summary *summ2;
2132 summ1 = (struct message_summary *)s1;
2133 summ2 = (struct message_summary *)s2;
2135 if (summ1->date < summ2->date) return -1;
2136 else if (summ1->date > summ2->date) return +1;
2141 * \brief qsort() compatible function to compare two message summary structs by descending date.
2143 * \param s1 first item to compare
2144 * \param s2 second item to compare
2146 int summcmp_rdate(const void *s1, const void *s2) {
2147 struct message_summary *summ1;
2148 struct message_summary *summ2;
2150 summ1 = (struct message_summary *)s1;
2151 summ2 = (struct message_summary *)s2;
2153 if (summ1->date < summ2->date) return +1;
2154 else if (summ1->date > summ2->date) return -1;
2161 * \brief command loop for reading messages
2163 * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
2165 void readloop(char *oper)
2174 long *displayed_msgs = NULL;
2175 int num_displayed = 0;
2177 int is_addressbook = 0;
2178 int is_singlecard = 0;
2179 int is_calendar = 0;
2184 int lowest_displayed = (-1);
2185 int highest_displayed = 0;
2186 struct addrbookent *addrbook = NULL;
2188 char *sortby = NULL;
2189 char sortpref_name[128];
2190 char sortpref_value[128];
2191 char *subjsort_button;
2192 char *sendsort_button;
2193 char *datesort_button;
2194 int bbs_reverse = 0;
2196 if (WC->wc_view == VIEW_WIKI) {
2197 sprintf(buf, "wiki?room=%s?page=home", WC->wc_roomname);
2202 startmsg = atol(bstr("startmsg"));
2203 maxmsgs = atoi(bstr("maxmsgs"));
2204 is_summary = atoi(bstr("summary"));
2205 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2207 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
2208 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
2210 sortby = bstr("sortby");
2211 if ( (!IsEmptyStr(sortby)) && (strcasecmp(sortby, sortpref_value)) ) {
2212 set_preference(sortpref_name, sortby, 1);
2214 if (IsEmptyStr(sortby)) sortby = sortpref_value;
2217 if (IsEmptyStr(sortby)) sortby = "rdate";
2219 /** message board sort */
2220 if (!strcasecmp(sortby, "reverse")) {
2227 output_headers(1, 1, 1, 0, 0, 0);
2230 * When in summary mode, always show ALL messages instead of just
2231 * new or old. Otherwise, show what the user asked for.
2233 if (!strcmp(oper, "readnew")) {
2234 strcpy(cmd, "MSGS NEW");
2236 else if (!strcmp(oper, "readold")) {
2237 strcpy(cmd, "MSGS OLD");
2239 else if (!strcmp(oper, "do_search")) {
2240 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2243 strcpy(cmd, "MSGS ALL");
2246 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
2248 if (!strcmp(oper, "do_search")) {
2249 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2252 strcpy(cmd, "MSGS ALL");
2256 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2258 if (!strcmp(oper, "do_search")) {
2259 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2262 strcpy(cmd, "MSGS ALL");
2267 if (is_summary) { /**< fetch header summary */
2268 snprintf(cmd, sizeof cmd, "MSGS %s|%s||1",
2269 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2270 (!strcmp(oper, "do_search") ? bstr("query") : "")
2277 * Are we doing a summary view? If so, we need to know old messages
2278 * and new messages, so we can do that pretty boldface thing for the
2281 strcpy(old_msgs, "");
2284 serv_getln(buf, sizeof buf);
2285 if (buf[0] == '2') {
2286 strcpy(old_msgs, &buf[4]);
2290 is_singlecard = atoi(bstr("is_singlecard"));
2292 if (WC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2294 strcpy(cmd, "MSGS ALL");
2297 if (WC->wc_default_view == VIEW_TASKS) { /**< tasks */
2299 strcpy(cmd, "MSGS ALL");
2302 if (WC->wc_default_view == VIEW_NOTES) { /**< notes */
2304 strcpy(cmd, "MSGS ALL");
2309 wprintf("<div align=center>%s</div>\n", _("Click on any note to edit it."));
2310 wprintf("<div id=\"new_notes_here\"></div>\n");
2313 nummsgs = load_msg_ptrs(cmd, is_summary);
2316 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2317 wprintf("<div align=\"center\"><br /><em>");
2318 if (!strcmp(oper, "readnew")) {
2319 wprintf(_("No new messages."));
2320 } else if (!strcmp(oper, "readold")) {
2321 wprintf(_("No old messages."));
2323 wprintf(_("No messages here."));
2325 wprintf("</em><br /></div>\n");
2332 for (a = 0; a < nummsgs; ++a) {
2333 /** Are you a new message, or an old message? */
2335 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
2336 WC->summ[a].is_new = 0;
2339 WC->summ[a].is_new = 1;
2345 if (startmsg == 0L) {
2347 startmsg = WC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2350 startmsg = WC->msgarr[0];
2355 if (!strcasecmp(sortby, "subject")) {
2356 qsort(WC->summ, WC->num_summ,
2357 sizeof(struct message_summary), summcmp_subj);
2359 else if (!strcasecmp(sortby, "rsubject")) {
2360 qsort(WC->summ, WC->num_summ,
2361 sizeof(struct message_summary), summcmp_rsubj);
2363 else if (!strcasecmp(sortby, "sender")) {
2364 qsort(WC->summ, WC->num_summ,
2365 sizeof(struct message_summary), summcmp_sender);
2367 else if (!strcasecmp(sortby, "rsender")) {
2368 qsort(WC->summ, WC->num_summ,
2369 sizeof(struct message_summary), summcmp_rsender);
2371 else if (!strcasecmp(sortby, "date")) {
2372 qsort(WC->summ, WC->num_summ,
2373 sizeof(struct message_summary), summcmp_date);
2375 else if (!strcasecmp(sortby, "rdate")) {
2376 qsort(WC->summ, WC->num_summ,
2377 sizeof(struct message_summary), summcmp_rdate);
2381 if (!strcasecmp(sortby, "subject")) {
2382 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2384 else if (!strcasecmp(sortby, "rsubject")) {
2385 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2388 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2391 if (!strcasecmp(sortby, "sender")) {
2392 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2394 else if (!strcasecmp(sortby, "rsender")) {
2395 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2398 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2401 if (!strcasecmp(sortby, "date")) {
2402 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2404 else if (!strcasecmp(sortby, "rdate")) {
2405 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2408 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2413 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2414 " document.onkeydown = CtdlMsgListKeyPress; "
2415 " if (document.layers) { "
2416 " document.captureEvents(Event.KEYPRESS); "
2421 /** note that Date and Delete are now in the same column */
2422 wprintf("<div id=\"message_list_hdr\">"
2423 "<div class=\"fix_scrollbar_bug\">"
2424 "<table cellspacing=0 style=\"width:100%%\">"
2427 wprintf("<th width=%d%%>%s %s</th>"
2428 "<th width=%d%%>%s %s</th>"
2429 "<th width=%d%%>%s %s"
2431 "<input type=\"submit\" name=\"delete_button\" id=\"delbutton\" "
2432 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2438 _("Subject"), subjsort_button,
2439 SENDER_COL_WIDTH_PCT,
2440 _("Sender"), sendsort_button,
2441 DATE_PLUS_BUTTONS_WIDTH_PCT,
2442 _("Date"), datesort_button,
2445 wprintf("</table></div></div>\n");
2447 wprintf("<div id=\"message_list\">"
2449 "<div class=\"fix_scrollbar_bug\">\n"
2451 "<table class=\"mailbox_summary\" id=\"summary_headers\" "
2452 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2458 * Set the "is_bbview" variable if it appears that we are looking at
2459 * a classic bulletin board view.
2461 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2462 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2467 * If we're not currently looking at ALL requested
2468 * messages, then display the selector bar
2471 /** begin bbview scroller */
2472 wprintf("<form name=\"msgomatictop\" class=\"selector_top\" >");
2473 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2475 wprintf("<select name=\"whichones\" size=\"1\" "
2476 "OnChange=\"location.href=msgomatictop.whichones.options"
2477 "[selectedIndex].value\">\n");
2480 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2482 lo = b - maxmsgs + 2;
2484 wprintf("<option %s value="
2489 "%d-%d</option> \n",
2490 ((WC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2499 for (b=0; b<nummsgs; b = b + maxmsgs) {
2501 hi = b + maxmsgs + 1;
2502 if (hi > nummsgs) hi = nummsgs;
2503 wprintf("<option %s value="
2508 "%d-%d</option> \n",
2509 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2518 wprintf("<option value=\"%s?startmsg=%ld"
2519 "?maxmsgs=9999999?summary=%d\">",
2521 WC->msgarr[0], is_summary);
2523 wprintf("</option>");
2524 wprintf("</select> ");
2525 wprintf(_("of %d messages."), nummsgs);
2527 /** forward/reverse */
2528 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2529 "OnChange=\"location.href='%s?sortby=forward'\"",
2530 (bbs_reverse ? "" : "checked"),
2534 wprintf(_("oldest to newest"));
2535 wprintf(" ");
2537 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2538 "OnChange=\"location.href='%s?sortby=reverse'\"",
2539 (bbs_reverse ? "checked" : ""),
2543 wprintf(_("newest to oldest"));
2546 wprintf("</select></form>\n");
2547 /** end bbview scroller */
2552 for (a = 0; a < nummsgs; ++a) {
2553 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2555 /** Display the message */
2557 display_summarized(a);
2559 else if (is_addressbook) {
2560 fetch_ab_name(WC->msgarr[a], buf);
2562 addrbook = realloc(addrbook,
2563 (sizeof(struct addrbookent) * num_ab) );
2564 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2565 sizeof(addrbook[num_ab-1].ab_name));
2566 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
2568 else if (is_calendar) {
2569 display_calendar(WC->msgarr[a]);
2571 else if (is_tasks) {
2572 display_task(WC->msgarr[a]);
2574 else if (is_notes) {
2575 display_note(WC->msgarr[a]);
2578 if (displayed_msgs == NULL) {
2579 displayed_msgs = malloc(sizeof(long) *
2580 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2582 displayed_msgs[num_displayed] = WC->msgarr[a];
2585 if (lowest_displayed < 0) lowest_displayed = a;
2586 highest_displayed = a;
2594 if (displayed_msgs != NULL) {
2596 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2599 /** if we do a split bbview in the future, begin messages div here */
2601 for (a=0; a<num_displayed; ++a) {
2602 read_message(displayed_msgs[a], 0, "");
2605 /** if we do a split bbview in the future, end messages div here */
2607 free(displayed_msgs);
2608 displayed_msgs = NULL;
2613 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2614 wprintf("</div>"); /**< end of 'message_list' div */
2616 /** Here's the grab-it-to-resize-the-message-list widget */
2617 wprintf("<div id=\"resize_msglist\" "
2618 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2619 "<div class=\"fix_scrollbar_bug\"> <hr>"
2623 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2627 * Bump these because although we're thinking in zero base, the user
2628 * is a drooling idiot and is thinking in one base.
2631 ++highest_displayed;
2634 * If we're not currently looking at ALL requested
2635 * messages, then display the selector bar
2638 /** begin bbview scroller */
2639 wprintf("<form name=\"msgomatic\" class=\"selector_bottom\" >");
2640 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2642 wprintf("<select name=\"whichones\" size=\"1\" "
2643 "OnChange=\"location.href=msgomatic.whichones.options"
2644 "[selectedIndex].value\">\n");
2647 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2649 lo = b - maxmsgs + 2;
2651 wprintf("<option %s value="
2656 "%d-%d</option> \n",
2657 ((WC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2666 for (b=0; b<nummsgs; b = b + maxmsgs) {
2668 hi = b + maxmsgs + 1;
2669 if (hi > nummsgs) hi = nummsgs;
2670 wprintf("<option %s value="
2675 "%d-%d</option> \n",
2676 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2685 wprintf("<option value=\"%s?startmsg=%ld"
2686 "?maxmsgs=9999999?summary=%d\">",
2688 WC->msgarr[0], is_summary);
2690 wprintf("</option>");
2691 wprintf("</select> ");
2692 wprintf(_("of %d messages."), nummsgs);
2694 /** forward/reverse */
2695 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2696 "OnChange=\"location.href='%s?sortby=forward'\"",
2697 (bbs_reverse ? "" : "checked"),
2701 wprintf(_("oldest to newest"));
2702 wprintf(" ");
2703 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2704 "OnChange=\"location.href='%s?sortby=reverse'\"",
2705 (bbs_reverse ? "checked" : ""),
2709 wprintf(_("newest to oldest"));
2712 wprintf("</form>\n");
2713 /** end bbview scroller */
2718 do_tasks_view(); /** Render the task list */
2722 do_calendar_view(); /** Render the calendar */
2725 if (is_addressbook) {
2726 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2729 /** Note: wDumpContent() will output one additional </div> tag. */
2730 wprintf("</div>\n"); /** end of 'content' div */
2733 /** free the summary */
2734 if (WC->summ != NULL) {
2739 if (addrbook != NULL) free(addrbook);
2744 * \brief Back end for post_message()
2745 * ... this is where the actual message gets transmitted to the server.
2747 void post_mime_to_server(void) {
2749 int is_multipart = 0;
2751 struct wc_attachment *att;
2753 size_t encoded_length;
2755 /** RFC2045 requires this, and some clients look for it... */
2756 serv_puts("MIME-Version: 1.0");
2757 serv_puts("X-Mailer: " SERVER);
2759 /** If there are attachments, we have to do multipart/mixed */
2760 if (WC->first_attachment != NULL) {
2765 sprintf(boundary, "Citadel--Multipart--%s--%04x--%04x",
2766 serv_info.serv_fqdn,
2771 /** Remember, serv_printf() appends an extra newline */
2772 serv_printf("Content-type: multipart/mixed; "
2773 "boundary=\"%s\"\n", boundary);
2774 serv_printf("This is a multipart message in MIME format.\n");
2775 serv_printf("--%s", boundary);
2778 serv_puts("Content-type: text/html; charset=utf-8");
2779 serv_puts("Content-Transfer-Encoding: quoted-printable");
2781 serv_puts("<html><body>\r\n");
2782 text_to_server_qp(bstr("msgtext")); /** Transmit message in quoted-printable encoding */
2783 serv_puts("</body></html>\r\n");
2787 /** Add in the attachments */
2788 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2790 encoded_length = ((att->length * 150) / 100);
2791 encoded = malloc(encoded_length);
2792 if (encoded == NULL) break;
2793 CtdlEncodeBase64(encoded, att->data, att->length, 1);
2795 serv_printf("--%s", boundary);
2796 serv_printf("Content-type: %s", att->content_type);
2797 serv_printf("Content-disposition: attachment; "
2798 "filename=\"%s\"", att->filename);
2799 serv_puts("Content-transfer-encoding: base64");
2801 serv_write(encoded, strlen(encoded));
2806 serv_printf("--%s--", boundary);
2814 * \brief Post message (or don't post message)
2816 * Note regarding the "dont_post" variable:
2817 * A random value (actually, it's just a timestamp) is inserted as a hidden
2818 * field called "postseq" when the display_enter page is generated. This
2819 * value is checked when posting, using the static variable dont_post. If a
2820 * user attempts to post twice using the same dont_post value, the message is
2821 * discarded. This prevents the accidental double-saving of the same message
2822 * if the user happens to click the browser "back" button.
2824 void post_message(void)
2827 char encoded_subject[1024];
2828 static long dont_post = (-1L);
2829 struct wc_attachment *att, *aptr;
2830 int is_anonymous = 0;
2833 display_name = bstr("display_name");
2834 if (!strcmp(display_name, "__ANONYMOUS__")) {
2839 if (WC->upload_length > 0) {
2841 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WC->upload_length);
2842 /** There's an attachment. Save it to this struct... */
2843 att = malloc(sizeof(struct wc_attachment));
2844 memset(att, 0, sizeof(struct wc_attachment));
2845 att->length = WC->upload_length;
2846 strcpy(att->content_type, WC->upload_content_type);
2847 strcpy(att->filename, WC->upload_filename);
2850 /** And add it to the list. */
2851 if (WC->first_attachment == NULL) {
2852 WC->first_attachment = att;
2855 aptr = WC->first_attachment;
2856 while (aptr->next != NULL) aptr = aptr->next;
2861 * Mozilla sends a simple filename, which is what we want,
2862 * but Satan's Browser sends an entire pathname. Reduce
2863 * the path to just a filename if we need to.
2865 while (num_tokens(att->filename, '/') > 1) {
2866 remove_token(att->filename, 0, '/');
2868 while (num_tokens(att->filename, '\\') > 1) {
2869 remove_token(att->filename, 0, '\\');
2873 * Transfer control of this memory from the upload struct
2874 * to the attachment struct.
2876 att->data = WC->upload;
2877 WC->upload_length = 0;
2883 if (!IsEmptyStr(bstr("cancel_button"))) {
2884 sprintf(WC->ImportantMessage,
2885 _("Cancelled. Message was not posted."));
2886 } else if (!IsEmptyStr(bstr("attach_button"))) {
2889 } else if (atol(bstr("postseq")) == dont_post) {
2890 sprintf(WC->ImportantMessage,
2891 _("Automatically cancelled because you have already "
2892 "saved this message."));
2894 rfc2047encode(encoded_subject, sizeof encoded_subject, bstr("subject"));
2895 sprintf(buf, "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s",
2903 bstr("my_email_addr")
2906 serv_getln(buf, sizeof buf);
2907 if (buf[0] == '4') {
2908 post_mime_to_server();
2909 if ( (!IsEmptyStr(bstr("recp")))
2910 || (!IsEmptyStr(bstr("cc" )))
2911 || (!IsEmptyStr(bstr("bcc" )))
2913 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2916 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2918 dont_post = atol(bstr("postseq"));
2920 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
2921 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2927 free_attachments(WC);
2930 * We may have been supplied with instructions regarding the location
2931 * to which we must return after posting. If found, go there.
2933 if (!IsEmptyStr(bstr("return_to"))) {
2934 http_redirect(bstr("return_to"));
2937 * If we were editing a page in a wiki room, go to that page now.
2939 else if (!IsEmptyStr(bstr("wikipage"))) {
2940 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
2944 * Otherwise, just go to the "read messages" loop.
2947 readloop("readnew");
2955 * \brief display the message entry screen
2957 void display_enter(void)
2963 struct wc_attachment *att;
2964 int recipient_required = 0;
2965 int subject_required = 0;
2966 int recipient_bad = 0;
2968 int is_anonymous = 0;
2969 long existing_page = (-1L);
2973 if (!IsEmptyStr(bstr("force_room"))) {
2974 gotoroom(bstr("force_room"));
2977 display_name = bstr("display_name");
2978 if (!strcmp(display_name, "__ANONYMOUS__")) {
2983 /** First test to see whether this is a room that requires recipients to be entered */
2984 serv_puts("ENT0 0");
2985 serv_getln(buf, sizeof buf);
2987 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
2988 recipient_required = 1;
2990 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2991 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2992 readloop("readnew");
2996 /* Is the server strongly recommending that the user enter a message subject? */
2997 if ((buf[3] != '\0') && (buf[4] != '\0')) {
2998 subject_required = extract_int(&buf[4], 1);
3002 * Are we perhaps in an address book view? If so, then an "enter
3003 * message" command really means "add new entry."
3005 if (WC->wc_default_view == VIEW_ADDRESSBOOK) {
3006 do_edit_vcard(-1, "", "");
3010 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
3012 * Are we perhaps in a calendar room? If so, then an "enter
3013 * message" command really means "add new calendar item."
3015 if (WC->wc_default_view == VIEW_CALENDAR) {
3016 display_edit_event();
3021 * Are we perhaps in a tasks view? If so, then an "enter
3022 * message" command really means "add new task."
3024 if (WC->wc_default_view == VIEW_TASKS) {
3025 display_edit_task();
3031 * Otherwise proceed normally.
3032 * Do a custom room banner with no navbar...
3034 output_headers(1, 1, 2, 0, 0, 0);
3035 wprintf("<div id=\"banner\">\n");
3036 embed_room_banner(NULL, navbar_none);
3037 wprintf("</div>\n");
3038 wprintf("<div id=\"content\">\n"
3039 "<div class=\"fix_scrollbar_bug message \">");
3041 /** Now check our actual recipients if there are any */
3042 if (recipient_required) {
3043 sprintf(buf, "ENT0 0|%s|%d|0||%s||%s|%s|%s",
3047 bstr("cc"), bstr("bcc"), bstr("wikipage"));
3049 serv_getln(buf, sizeof buf);
3051 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
3052 if (!IsEmptyStr(bstr("recp")) &&
3053 !IsEmptyStr(bstr("cc" )) &&
3054 !IsEmptyStr(bstr("bcc" ))) {
3058 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3059 wprintf("<em>%s</em><br />\n", &buf[4]);
3064 /** If we got this far, we can display the message entry screen. */
3066 /** begin message entry screen */
3068 "enctype=\"multipart/form-data\" "
3070 "accept-charset=\"UTF-8\" "
3072 "name=\"enterform\""
3074 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
3075 if (WC->wc_view == VIEW_WIKI) {
3076 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
3078 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
3079 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
3081 /** submit or cancel buttons */
3082 wprintf("<p class=\"send_edit_msg\">");
3083 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3084 if (recipient_required) {
3085 wprintf(_("Send message"));
3087 wprintf(_("Post message"));
3090 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3095 wprintf("<img src=\"static/newmess3_24x.gif\" class=\"imgedit\">");
3096 wprintf(" "); /** header bar */
3097 fmt_date(buf, now, 0);
3099 wprintf("\n"); /** header bar */
3102 wprintf("<label for=\"from_id\" > ");
3103 wprintf(_(" <I>from</I> "));
3104 wprintf("</label>");
3106 /* Allow the user to select any of his valid screen names */
3108 wprintf("<select name=\"display_name\" size=1 id=\"from_id\">\n");
3111 serv_getln(buf, sizeof buf);
3112 if (buf[0] == '1') {
3113 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3114 wprintf("<option %s value=\"",
3115 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
3120 wprintf("</option>\n");
3124 if (WC->room_flags & QR_ANONOPT) {
3125 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
3126 ((!strcasecmp(bstr("__ANONYMOUS__"), WC->wc_fullname)) ? "selected" : ""),
3131 wprintf("</select>\n");
3133 /* If this is an email (not a post), allow the user to select any of his
3134 * valid email addresses.
3136 if (recipient_required) {
3138 serv_getln(buf, sizeof buf);
3139 if (buf[0] == '1') {
3140 wprintf("<select name=\"my_email_addr\" size=1>\n");
3141 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3142 wprintf("<option value=\"");
3146 wprintf("></option>\n");
3148 wprintf("</select>\n");
3152 wprintf(_(" <I>in</I> "));
3153 escputs(WC->wc_roomname);
3156 if (recipient_required) {
3158 wprintf("<div style=\"float: left;\"><label for=\"recp_id\"> ");
3161 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
3162 escputs(bstr("recp"));
3163 wprintf("\" size=45 maxlength=1000 />");
3164 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
3167 wprintf("<br/><label for=\"cc_id\"> ");
3170 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
3171 escputs(bstr("cc"));
3172 wprintf("\" size=45 maxlength=1000 />");
3173 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
3174 wprintf("<br/><label for=\"bcc_id\"> ");
3177 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
3178 escputs(bstr("bcc"));
3179 wprintf("\" size=45 maxlength=1000 />");
3180 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
3182 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
3183 wprintf("<script type=\"text/javascript\"> \n"
3184 " activate_entmsg_autocompleters(); \n"
3189 /** Pop open an address book -- begin **/
3191 "<a href=\"javascript:PopOpenAddressBook('recp_id|%s|cc_id|%s|bcc_id|%s');\" "
3193 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
3195 _("To:"), _("CC:"), _("BCC:"),
3196 _("Contacts"), _("Contacts")
3198 /** Pop open an address book -- end **/
3201 wprintf("<div style=\"clear: both;\"><label for=\"subject_id\" > ");
3202 if (recipient_required || subject_required) {
3203 wprintf(_("Subject:"));
3206 wprintf(_("Subject (optional):"));
3209 "<input type=\"text\" name=\"subject\" id=\"subject_id\" value=\" ");
3210 escputs(bstr("subject"));
3211 wprintf("\" size=45 maxlength=70>\n");
3213 wprintf("</div>\n");
3215 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
3217 /** If we're continuing from a previous edit, put our partially-composed message back... */
3218 msgescputs(bstr("msgtext"));
3220 /* If we're forwarding a message, insert it here... */
3221 if (atol(bstr("fwdquote")) > 0L) {
3222 wprintf("<br><div align=center><i>");
3223 wprintf(_("--- forwarded message ---"));
3224 wprintf("</i></div><br>");
3225 pullquote_message(atol(bstr("fwdquote")), 1, 1);
3228 /** If we're replying quoted, insert the quote here... */
3229 else if (atol(bstr("replyquote")) > 0L) {
3232 pullquote_message(atol(bstr("replyquote")), 0, 1);
3233 wprintf("</blockquote><br>");
3236 /** If we're editing a wiki page, insert the existing page here... */
3237 else if (WC->wc_view == VIEW_WIKI) {
3238 safestrncpy(buf, bstr("wikipage"), sizeof buf);
3239 str_wiki_index(buf);
3240 existing_page = locate_message_by_uid(buf);
3241 if (existing_page >= 0L) {
3242 pullquote_message(existing_page, 1, 0);
3246 /** Insert our signature if appropriate... */
3247 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
3248 get_preference("use_sig", buf, sizeof buf);
3249 if (!strcasecmp(buf, "yes")) {
3251 get_preference("signature", ebuf, sizeof ebuf);
3252 euid_unescapize(buf, ebuf);
3253 wprintf("<br>--<br>");
3255 for (i=0; i<len; ++i) {
3256 if (buf[i] == '\n') {
3259 else if (buf[i] == '<') {
3262 else if (buf[i] == '>') {
3265 else if (buf[i] == '&') {
3268 else if (buf[i] == '\"') {
3271 else if (buf[i] == '\'') {
3274 else if (isprint(buf[i])) {
3275 wprintf("%c", buf[i]);
3281 wprintf("</textarea>");
3284 * The following template embeds the TinyMCE richedit control, and automatically
3285 * transforms the textarea into a richedit textarea.
3287 do_template("richedit");
3289 /** Enumerate any attachments which are already in place... */
3290 wprintf("<div class=\"attachment buttons\"><img src=\"static/diskette_24x.gif\" class=\"imgedit\" > ");
3291 wprintf(_("Attachments:"));
3293 wprintf("<select name=\"which_attachment\" size=1>");
3294 for (att = WC->first_attachment; att != NULL; att = att->next) {
3295 wprintf("<option value=\"");
3296 urlescputs(att->filename);
3298 escputs(att->filename);
3299 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3300 wprintf("</option>\n");
3302 wprintf("</select>");
3304 /** Now offer the ability to attach additional files... */
3305 wprintf(" ");
3306 wprintf(_("Attach file:"));
3307 wprintf(" <input name=\"attachfile\" class=\"attachfile\" "
3308 "size=16 type=\"file\">\n "
3309 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3313 /** Make sure we only insert our signature once */
3314 if (strcmp(bstr("sig_inserted"), "yes")) {
3315 wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
3318 wprintf("</form>\n");
3319 wprintf("</div></div>\n");
3321 DONE: address_book_popup();
3327 * \brief delete a message
3329 void delete_msg(void)
3334 msgid = atol(bstr("msgid"));
3336 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3337 serv_printf("DELE %ld", msgid);
3339 else { /** Otherwise move it to Trash */
3340 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3343 serv_getln(buf, sizeof buf);
3344 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3346 readloop("readnew");
3351 * \brief move a message to another folder
3358 msgid = atol(bstr("msgid"));
3360 if (!IsEmptyStr(bstr("move_button"))) {
3361 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3363 serv_getln(buf, sizeof buf);
3364 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3366 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3369 readloop("readnew");
3377 * \brief Confirm move of a message
3379 void confirm_move_msg(void)
3385 msgid = atol(bstr("msgid"));
3388 output_headers(1, 1, 2, 0, 0, 0);
3389 wprintf("<div id=\"banner\">\n");
3391 wprintf(_("Confirm move of message"));
3393 wprintf("</div>\n");
3395 wprintf("<div id=\"content\" class=\"service\">\n");
3397 wprintf("<CENTER>");
3399 wprintf(_("Move this message to:"));
3400 wprintf("<br />\n");
3402 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3403 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
3404 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3406 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3408 serv_getln(buf, sizeof buf);
3409 if (buf[0] == '1') {
3410 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3411 extract_token(targ, buf, 0, '|', sizeof targ);
3412 wprintf("<OPTION>");
3417 wprintf("</SELECT>\n");
3418 wprintf("<br />\n");
3420 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3422 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3423 wprintf("</form></CENTER>\n");
3425 wprintf("</CENTER>\n");