5 * \defgroup MsgDisp Functions which deal with the fetching and displaying of messages.
6 * \ingroup WebcitDisplayItems
12 #include "webserver.h"
15 #define SUBJ_COL_WIDTH_PCT 50 /**< Mailbox view column width */
16 #define SENDER_COL_WIDTH_PCT 30 /**< Mailbox view column width */
17 #define DATE_PLUS_BUTTONS_WIDTH_PCT 20 /**< Mailbox view column width */
20 * Address book entry (keep it short and sweet, it's just a quickie lookup
21 * which we can use to get to the real meat and bones later)
24 char ab_name[64]; /**< name string */
25 long ab_msgnum; /**< message number of address book entry */
33 * \brief Wrapper around iconv_open()
34 * Our version adds aliases for non-standard Microsoft charsets
35 * such as 'MS950', aliasing them to names like 'CP950'
37 * \param tocode Target encoding
38 * \param fromcode Source encoding
40 iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode)
42 iconv_t ic = (iconv_t)(-1) ;
43 ic = iconv_open(tocode, fromcode);
44 if (ic == (iconv_t)(-1) ) {
45 char alias_fromcode[64];
46 if ( (strlen(fromcode) == 5) && (!strncasecmp(fromcode, "MS", 2)) ) {
47 safestrncpy(alias_fromcode, fromcode, sizeof alias_fromcode);
48 alias_fromcode[0] = 'C';
49 alias_fromcode[1] = 'P';
50 ic = iconv_open(tocode, alias_fromcode);
58 * \brief Handle subjects with RFC2047 encoding
60 * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=
61 * \param buf the stringbuffer to process
63 void utf8ify_rfc822_string(char *buf) {
69 iconv_t ic = (iconv_t)(-1) ;
70 char *ibuf; /**< Buffer of characters to be converted */
71 char *obuf; /**< Buffer for converted characters */
72 size_t ibuflen; /**< Length of input buffer */
73 size_t obuflen; /**< Length of output buffer */
74 char *isav; /**< Saved pointer to input buffer */
75 char *osav; /**< Saved pointer to output buffer */
78 int illegal_non_rfc2047_encoding = 0;
80 /** Sometimes, badly formed messages contain strings which were simply
81 * written out directly in some foreign character set instead of
82 * using RFC2047 encoding. This is illegal but we will attempt to
83 * handle it anyway by converting from a user-specified default
84 * charset to UTF-8 if we see any nonprintable characters.
86 for (i=0; i<strlen(buf); ++i) {
87 if ((buf[i] < 32) || (buf[i] > 126)) {
88 illegal_non_rfc2047_encoding = 1;
91 if (illegal_non_rfc2047_encoding) {
92 char default_header_charset[128];
93 get_preference("default_header_charset", default_header_charset, sizeof default_header_charset);
94 if ( (strcasecmp(default_header_charset, "UTF-8")) && (strcasecmp(default_header_charset, "us-ascii")) ) {
95 ic = ctdl_iconv_open("UTF-8", default_header_charset);
96 if (ic != (iconv_t)(-1) ) {
99 safestrncpy(ibuf, buf, 1024);
100 ibuflen = strlen(ibuf);
102 obuf = (char *) malloc(obuflen);
104 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
105 osav[1024-obuflen] = 0;
114 /** Now we handle foreign character sets properly encoded
117 while (start=strstr(buf, "=?"), end=strstr(buf, "?="),
118 ((start != NULL) && (end != NULL) && (end > start)) )
120 extract_token(charset, start, 1, '?', sizeof charset);
121 extract_token(encoding, start, 2, '?', sizeof encoding);
122 extract_token(istr, start, 3, '?', sizeof istr);
126 if (!strcasecmp(encoding, "B")) { /**< base64 */
127 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
129 else if (!strcasecmp(encoding, "Q")) { /**< quoted-printable */
137 if (istr[pos] == '_') istr[pos] = ' ';
141 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, len);
144 strcpy(ibuf, istr); /**< unknown encoding */
145 ibuflen = strlen(istr);
148 ic = ctdl_iconv_open("UTF-8", charset);
149 if (ic != (iconv_t)(-1) ) {
151 obuf = (char *) malloc(obuflen);
153 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
154 osav[1024-obuflen] = 0;
159 remove_token(end, 0, '?');
160 remove_token(end, 0, '?');
161 remove_token(end, 0, '?');
162 remove_token(end, 0, '?');
163 strcpy(end, &end[1]);
165 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
174 remove_token(end, 0, '?');
175 remove_token(end, 0, '?');
176 remove_token(end, 0, '?');
177 remove_token(end, 0, '?');
178 strcpy(end, &end[1]);
180 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
187 * Since spammers will go to all sorts of absurd lengths to get their
188 * messages through, there are LOTS of corrupt headers out there.
189 * So, prevent a really badly formed RFC2047 header from throwing
190 * this function into an infinite loop.
193 if (passes > 20) return;
203 * \brief RFC2047-encode a header field if necessary.
204 * If no non-ASCII characters are found, the string
205 * will be copied verbatim without encoding.
207 * \param target Target buffer.
208 * \param maxlen Maximum size of target buffer.
209 * \param source Source string to be encoded.
211 void rfc2047encode(char *target, int maxlen, char *source)
213 int need_to_encode = 0;
217 if (target == NULL) return;
219 for (i=0; i<strlen(source); ++i) {
220 if ((source[i] < 32) || (source[i] > 126)) {
225 if (!need_to_encode) {
226 safestrncpy(target, source, maxlen);
230 strcpy(target, "=?UTF-8?Q?");
231 for (i=0; i<strlen(source); ++i) {
232 ch = (unsigned char) source[i];
233 if ((ch < 32) || (ch > 126) || (ch == 61)) {
234 sprintf(&target[strlen(target)], "=%02X", ch);
237 sprintf(&target[strlen(target)], "%c", ch);
241 strcat(target, "?=");
248 * \brief Look for URL's embedded in a buffer and make them linkable. We use a
249 * target window in order to keep the BBS session in its own window.
250 * \param buf the message buffer
262 for (pos = 0; pos < strlen(buf); ++pos) {
263 if (!strncasecmp(&buf[pos], "http://", 7))
265 if (!strncasecmp(&buf[pos], "ftp://", 6))
272 for (pos = strlen(buf); pos > start; --pos) {
273 if ( (!isprint(buf[pos]))
274 || (isspace(buf[pos]))
278 || (buf[pos] == '\\')
292 strncpy(urlbuf, &buf[start], end - start);
293 urlbuf[end - start] = 0;
295 strncpy(outbuf, buf, start);
296 sprintf(&outbuf[start], "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
297 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
298 strcat(outbuf, &buf[end]);
299 if ( strlen(outbuf) < 250 )
305 * \brief Turn a vCard "n" (name) field into something displayable.
306 * \param name the name field to convert
308 void vcard_n_prettyize(char *name)
313 original_name = strdup(name);
314 for (i=0; i<5; ++i) {
315 if (strlen(original_name) > 0) {
316 if (original_name[strlen(original_name)-1] == ' ') {
317 original_name[strlen(original_name)-1] = 0;
319 if (original_name[strlen(original_name)-1] == ';') {
320 original_name[strlen(original_name)-1] = 0;
325 for (i=0; i<strlen(original_name); ++i) {
326 if (original_name[i] == ';') {
330 name[strlen(name)+1] = 0;
331 name[strlen(name)] = original_name[i];
341 * \brief preparse a vcard name
342 * display_vcard() calls this after parsing the textual vCard into
343 * our 'struct vCard' data object.
344 * This gets called instead of display_parsed_vcard() if we are only looking
345 * to extract the person's name instead of displaying the card.
346 * \param v the vcard to retrieve the name from
347 * \param storename where to put the name at
349 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
352 strcpy(storename, "");
354 name = vcard_get_prop(v, "n", 1, 0, 0);
356 strcpy(storename, name);
357 /* vcard_n_prettyize(storename); */
365 * \brief html print a vcard
366 * display_vcard() calls this after parsing the textual vCard into
367 * our 'struct vCard' data object.
369 * Set 'full' to nonzero to display the full card, otherwise it will only
370 * show a summary line.
372 * This code is a bit ugly, so perhaps an explanation is due: we do this
373 * in two passes through the vCard fields. On the first pass, we process
374 * fields we understand, and then render them in a pretty fashion at the
375 * end. Then we make a second pass, outputting all the fields we don't
376 * understand in a simple two-column name/value format.
377 * \param v the vCard to display
378 * \param full display all items of the vcard?
380 void display_parsed_vcard(struct vCard *v, int full) {
386 char *thisname, *thisvalue;
387 char firsttoken[SIZ];
396 strcpy(fullname, "");
404 name = vcard_get_prop(v, "fn", 1, 0, 0);
408 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
409 strcpy(fullname, name);
410 vcard_n_prettyize(fullname);
420 wprintf("<div align=center><table bgcolor=#aaaaaa width=50%%>");
421 for (pass=1; pass<=2; ++pass) {
423 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
425 thisname = strdup(v->prop[i].name);
426 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
428 for (j=0; j<num_tokens(thisname, ';'); ++j) {
429 extract_token(buf, thisname, j, ';', sizeof buf);
430 if (!strcasecmp(buf, "encoding=quoted-printable")) {
432 remove_token(thisname, j, ';');
434 if (!strcasecmp(buf, "encoding=base64")) {
436 remove_token(thisname, j, ';');
441 thisvalue = malloc(strlen(v->prop[i].value) + 50);
442 j = CtdlDecodeQuotedPrintable(
443 thisvalue, v->prop[i].value,
444 strlen(v->prop[i].value) );
448 thisvalue = malloc(strlen(v->prop[i].value) + 50);
450 thisvalue, v->prop[i].value,
451 strlen(v->prop[i].value) );
454 thisvalue = strdup(v->prop[i].value);
457 /** Various fields we may encounter ***/
459 /** N is name, but only if there's no FN already there */
460 if (!strcasecmp(firsttoken, "n")) {
461 if (strlen(fullname) == 0) {
462 strcpy(fullname, thisvalue);
463 vcard_n_prettyize(fullname);
467 /** FN (full name) is a true 'display name' field */
468 else if (!strcasecmp(firsttoken, "fn")) {
469 strcpy(fullname, thisvalue);
473 else if (!strcasecmp(firsttoken, "title")) {
474 strcpy(title, thisvalue);
478 else if (!strcasecmp(firsttoken, "org")) {
479 strcpy(org, thisvalue);
482 else if (!strcasecmp(firsttoken, "email")) {
483 if (strlen(mailto) > 0) strcat(mailto, "<br />");
485 "<a href=\"display_enter"
486 "?force_room=_MAIL_?recp=");
488 urlesc(&mailto[strlen(mailto)], fullname);
489 urlesc(&mailto[strlen(mailto)], " <");
490 urlesc(&mailto[strlen(mailto)], thisvalue);
491 urlesc(&mailto[strlen(mailto)], ">");
493 strcat(mailto, "\">");
494 stresc(&mailto[strlen(mailto)], thisvalue, 1, 1);
495 strcat(mailto, "</A>");
497 else if (!strcasecmp(firsttoken, "tel")) {
498 if (strlen(phone) > 0) strcat(phone, "<br />");
499 strcat(phone, thisvalue);
500 for (j=0; j<num_tokens(thisname, ';'); ++j) {
501 extract_token(buf, thisname, j, ';', sizeof buf);
502 if (!strcasecmp(buf, "tel"))
504 else if (!strcasecmp(buf, "work"))
505 strcat(phone, _(" (work)"));
506 else if (!strcasecmp(buf, "home"))
507 strcat(phone, _(" (home)"));
508 else if (!strcasecmp(buf, "cell"))
509 strcat(phone, _(" (cell)"));
517 else if (!strcasecmp(firsttoken, "adr")) {
520 wprintf(_("Address:"));
521 wprintf("</TD><TD>");
522 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
523 extract_token(buf, thisvalue, j, ';', sizeof buf);
524 if (strlen(buf) > 0) {
526 if (j<3) wprintf("<br />");
530 wprintf("</TD></TR>\n");
533 else if (!strcasecmp(firsttoken, "version")) {
536 else if (!strcasecmp(firsttoken, "rev")) {
539 else if (!strcasecmp(firsttoken, "label")) {
544 /*** Don't show extra fields. They're ugly.
548 wprintf("</TD><TD>");
550 wprintf("</TD></TR>\n");
560 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
561 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
562 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
563 "<FONT SIZE=+1><B>");
565 wprintf("</B></FONT>");
566 if (strlen(title) > 0) {
567 wprintf("<div align=right>");
571 if (strlen(org) > 0) {
572 wprintf("<div align=right>");
576 wprintf("</TD></TR>\n");
578 if (strlen(phone) > 0) {
580 wprintf(_("Telephone:"));
581 wprintf("</td><td>%s</td></tr>\n", phone);
583 if (strlen(mailto) > 0) {
585 wprintf(_("E-mail:"));
586 wprintf("</td><td>%s</td></tr>\n", mailto);
592 wprintf("</table></div>\n");
598 * \brief Display a textual vCard
599 * (Converts to a vCard object and then calls the actual display function)
600 * Set 'full' to nonzero to display the whole card instead of a one-liner.
601 * Or, if "storename" is non-NULL, just store the person's name in that
602 * buffer instead of displaying the card at all.
603 * \param vcard_source the buffer containing the vcard text
604 * \param alpha what???
605 * \param full should we usse all lines?
606 * \param storename where to store???
608 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
614 v = vcard_load(vcard_source);
615 if (v == NULL) return;
617 name = vcard_get_prop(v, "n", 1, 0, 0);
623 if (storename != NULL) {
624 fetchname_parsed_vcard(v, storename);
626 else if ( (alpha == 0)
627 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
628 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
630 display_parsed_vcard(v, full);
644 * \brief I wanna SEE that message!
645 * \param msgnum the citadel number of the message to display
646 * \param printable_view are we doing a print view?
647 * \param section Optional for encapsulated message/rfc822 submessage)
649 void read_message(long msgnum, int printable_view, char *section) {
651 char mime_partnum[256];
653 char mime_filename[256];
654 char mime_content_type[256];
655 char mime_charset[256];
656 char mime_disposition[256];
658 struct attach_link *attach_links = NULL;
659 int num_attach_links = 0;
660 char mime_submessages[256];
667 char reply_all[4096];
673 char vcard_partnum[256];
674 char cal_partnum[256];
675 char *part_source = NULL;
676 char msg4_partnum[32];
678 iconv_t ic = (iconv_t)(-1) ;
679 char *ibuf; /**< Buffer of characters to be converted */
680 char *obuf; /**< Buffer for converted characters */
681 size_t ibuflen; /**< Length of input buffer */
682 size_t obuflen; /**< Length of output buffer */
683 char *osav; /**< Saved pointer to output buffer */
689 strcpy(reply_to, "");
690 strcpy(reply_all, "");
691 strcpy(vcard_partnum, "");
692 strcpy(cal_partnum, "");
693 strcpy(mime_content_type, "text/plain");
694 strcpy(mime_charset, "us-ascii");
695 strcpy(mime_submessages, "");
697 serv_printf("MSG4 %ld|%s", msgnum, section);
698 serv_getln(buf, sizeof buf);
701 wprintf(_("ERROR:"));
702 wprintf("</strong> %s<br />\n", &buf[4]);
706 /** begin everythingamundo table */
707 if (!printable_view) {
708 wprintf("<div class=\"fix_scrollbar_bug message\" ");
709 wprintf("onMouseOver=document.getElementById(\"msg%ld\").style.visibility=\"visible\" ", msgnum);
710 wprintf("onMouseOut=document.getElementById(\"msg%ld\").style.visibility=\"hidden\" >", msgnum);
713 /** begin message header table */
714 wprintf("<div class=\"message_header\">");
715 strcpy(m_subject, "");
718 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
719 if (!strcmp(buf, "000")) {
721 wprintf(_("unexpected end of message"));
722 wprintf(" (1)</i><br /><br />\n");
726 if (!strncasecmp(buf, "nhdr=yes", 8))
730 if (!strncasecmp(buf, "type=", 5))
731 format_type = atoi(&buf[5]);
732 if (!strncasecmp(buf, "from=", 5)) {
733 strcpy(from, &buf[5]);
735 wprintf("<a href=\"showuser?who=");
737 utf8ify_rfc822_string(from);
744 if (!strncasecmp(buf, "subj=", 5)) {
745 safestrncpy(m_subject, &buf[5], sizeof m_subject);
747 if (!strncasecmp(buf, "cccc=", 5)) {
748 safestrncpy(m_cc, &buf[5], sizeof m_cc);
749 if (strlen(reply_all) > 0) {
750 strcat(reply_all, ", ");
752 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
753 (sizeof reply_all - strlen(reply_all)) );
755 if ((!strncasecmp(buf, "hnod=", 5))
756 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
757 wprintf("(%s) ", &buf[5]);
759 if ((!strncasecmp(buf, "room=", 5))
760 && (strcasecmp(&buf[5], WC->wc_roomname))
761 && (strlen(&buf[5])>0) ) {
763 wprintf("%s> ", &buf[5]);
765 if (!strncasecmp(buf, "rfca=", 5)) {
766 strcpy(rfca, &buf[5]);
772 if (!strncasecmp(buf, "node=", 5)) {
773 strcpy(node, &buf[5]);
774 if ( ((WC->room_flags & QR_NETWORK)
775 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
776 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
779 wprintf("@%s ", &buf[5]);
782 if (!strncasecmp(buf, "rcpt=", 5)) {
784 if (strlen(reply_all) > 0) {
785 strcat(reply_all, ", ");
787 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
788 (sizeof reply_all - strlen(reply_all)) );
790 utf8ify_rfc822_string(&buf[5]);
795 if (!strncasecmp(buf, "time=", 5)) {
796 fmt_date(now, atol(&buf[5]), 0);
800 if (!strncasecmp(buf, "part=", 5)) {
801 extract_token(mime_name, &buf[5], 0, '|', sizeof mime_filename);
802 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
803 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
804 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
805 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
806 mime_length = extract_int(&buf[5], 5);
809 striplt(mime_filename);
810 if ( (strlen(mime_filename) == 0) && (strlen(mime_name) > 0) ) {
811 strcpy(mime_filename, mime_name);
814 if (!strcasecmp(mime_content_type, "message/rfc822")) {
815 if (strlen(mime_submessages) > 0) {
816 strcat(mime_submessages, "|");
818 strcat(mime_submessages, mime_partnum);
820 else if ((!strcasecmp(mime_disposition, "inline"))
821 && (!strncasecmp(mime_content_type, "image/", 6)) ){
823 attach_links = realloc(attach_links,
824 (num_attach_links*sizeof(struct attach_link)));
825 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
826 snprintf(attach_links[num_attach_links-1].html, 1024,
827 "<img src=\"mimepart/%ld/%s/%s\">",
828 msgnum, mime_partnum, mime_filename);
830 else if ( ( (!strcasecmp(mime_disposition, "attachment"))
831 || (!strcasecmp(mime_disposition, "inline"))
832 || (!strcasecmp(mime_disposition, ""))
833 ) && (strlen(mime_content_type) > 0)
836 attach_links = realloc(attach_links,
837 (num_attach_links*sizeof(struct attach_link)));
838 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
839 snprintf(attach_links[num_attach_links-1].html, 1024,
840 "<img src=\"static/diskette_24x.gif\" "
841 "border=0 align=middle>\n"
842 "%s (%s, %d bytes) [ "
843 "<a href=\"mimepart/%ld/%s/%s\""
844 "target=\"wc.%ld.%s\">%s</a>"
846 "<a href=\"mimepart_download/%ld/%s/%s\">%s</a>"
849 mime_content_type, mime_length,
850 msgnum, mime_partnum, mime_filename,
851 msgnum, mime_partnum,
853 msgnum, mime_partnum, mime_filename,
858 /** begin handler prep ***/
859 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
860 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
861 strcpy(vcard_partnum, mime_partnum);
864 if (!strcasecmp(mime_content_type, "text/calendar")) {
865 strcpy(cal_partnum, mime_partnum);
868 /** end handler prep ***/
874 /** Generate a reply-to address */
875 if (strlen(rfca) > 0) {
876 if (strlen(from) > 0) {
877 snprintf(reply_to, sizeof(reply_to), "%s <%s>", from, rfca);
880 strcpy(reply_to, rfca);
884 if ( (strlen(node) > 0)
885 && (strcasecmp(node, serv_info.serv_nodename))
886 && (strcasecmp(node, serv_info.serv_humannode)) ) {
887 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
891 snprintf(reply_to, sizeof(reply_to), "%s", from);
902 utf8ify_rfc822_string(m_cc);
903 utf8ify_rfc822_string(m_subject);
905 if (strlen(m_cc) > 0) {
906 wprintf("<div class=\"message_subject\">");
912 if (strlen(m_subject) > 0) {
913 wprintf("<div class=\"message_subject\">");
914 wprintf(_("Subject:"));
921 /** start msg buttons */
922 if (!printable_view) {
923 wprintf("<div id=\"msg%ld\" class=\"msgbuttons\" >\n",msgnum);
926 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
927 wprintf("<a href=\"display_enter");
928 if (WC->is_mailbox) {
929 wprintf("?replyquote=%ld", msgnum);
932 urlescputs(reply_to);
933 if (strlen(m_subject) > 0) {
934 wprintf("?subject=");
935 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
936 urlescputs(m_subject);
938 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Reply"));
942 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
943 if (!WC->is_mailbox) {
944 wprintf("<a href=\"display_enter");
945 wprintf("?replyquote=%ld", msgnum);
947 urlescputs(reply_to);
948 if (strlen(m_subject) > 0) {
949 wprintf("?subject=");
950 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
951 urlescputs(m_subject);
953 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyQuoted"));
958 if (WC->wc_view == VIEW_MAILBOX) {
959 wprintf("<a href=\"display_enter");
960 wprintf("?replyquote=%ld", msgnum);
962 urlescputs(reply_to);
964 urlescputs(reply_all);
965 if (strlen(m_subject) > 0) {
966 wprintf("?subject=");
967 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
968 urlescputs(m_subject);
970 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyAll"));
974 if (WC->wc_view == VIEW_MAILBOX) {
975 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
976 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
977 urlescputs(m_subject);
978 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Forward"));
981 /** If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
982 if ( (WC->is_room_aide) || (WC->is_mailbox) || (WC->room_flags2 & QR2_COLLABDEL) ) {
984 wprintf("<a href=\"confirm_move_msg?msgid=%ld\"><span>[</span>%s<span>]</span></a> ",
988 wprintf("<a href=\"delete_msg?msgid=%ld\" "
989 "onClick=\"return confirm('%s');\">"
990 "<span>[</span>%s<span>]</span> "
991 "</a> ", msgnum, _("Delete this message?"), _("Delete")
996 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'); \" >"
997 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Headers"));
1001 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'); \" >"
1002 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Print"));
1011 wprintf("<div class=\"message_content\" ");
1014 * Learn the content type
1016 strcpy(mime_content_type, "text/plain");
1017 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1018 if (!strcmp(buf, "000")) {
1020 wprintf(_("unexpected end of message"));
1021 wprintf(" (2)</i><br /><br />\n");
1024 if (!strncasecmp(buf, "X-Citadel-MSG4-Partnum:", 23)) {
1025 safestrncpy(msg4_partnum, &buf[23], sizeof(msg4_partnum));
1026 striplt(msg4_partnum);
1028 if (!strncasecmp(buf, "Content-type:", 13)) {
1029 safestrncpy(mime_content_type, &buf[13], sizeof(mime_content_type));
1030 striplt(mime_content_type);
1031 for (i=0; i<strlen(mime_content_type); ++i) {
1032 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1033 safestrncpy(mime_charset, &mime_content_type[i+8],
1034 sizeof mime_charset);
1037 for (i=0; i<strlen(mime_content_type); ++i) {
1038 if (mime_content_type[i] == ';') {
1039 mime_content_type[i] = 0;
1042 for (i=0; i<strlen(mime_charset); ++i) {
1043 if (mime_charset[i] == ';') {
1044 mime_charset[i] = 0;
1050 /** Set up a character set conversion if we need to (and if we can) */
1052 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
1053 if ( (strcasecmp(mime_charset, "us-ascii"))
1054 && (strcasecmp(mime_charset, "UTF-8"))
1055 && (strcasecmp(mime_charset, ""))
1057 ic = ctdl_iconv_open("UTF-8", mime_charset);
1058 if (ic == (iconv_t)(-1) ) {
1059 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1060 __FILE__, __LINE__, mime_charset, strerror(errno));
1065 /** Messages in legacy Citadel variformat get handled thusly... */
1066 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1070 /** Boring old 80-column fixed format text gets handled this way... */
1071 else if ( (!strcasecmp(mime_content_type, "text/plain"))
1072 || (!strcasecmp(mime_content_type, "text")) ) {
1073 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1074 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1075 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1078 if (ic != (iconv_t)(-1) ) {
1080 ibuflen = strlen(ibuf);
1082 obuf = (char *) malloc(obuflen);
1084 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1085 osav[SIZ-obuflen] = 0;
1086 safestrncpy(buf, osav, sizeof buf);
1091 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1092 buf[strlen(buf) - 1] = 0;
1094 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1095 wprintf("<blockquote>");
1097 } else if ((bq == 1) &&
1098 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1099 wprintf("</blockquote>");
1105 wprintf("</tt><br />\n");
1107 wprintf("</i><br />");
1110 else /** HTML is fun, but we've got to strip it first */
1111 if (!strcasecmp(mime_content_type, "text/html")) {
1112 output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
1115 /** Unknown weirdness */
1117 wprintf(_("I don't know how to display %s"), mime_content_type);
1118 wprintf("<br />\n", mime_content_type);
1119 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1122 /** If there are attached submessages, display them now... */
1123 if ( (strlen(mime_submessages) > 0) && (!section[0]) ) {
1124 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1125 extract_token(buf, mime_submessages, i, '|', sizeof buf);
1126 /** use printable_view to suppress buttons */
1127 wprintf("<blockquote>");
1128 read_message(msgnum, 1, buf);
1129 wprintf("</blockquote>");
1134 /** Afterwards, offer links to download attachments 'n' such */
1135 if ( (num_attach_links > 0) && (!section[0]) ) {
1136 for (i=0; i<num_attach_links; ++i) {
1137 if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
1138 wprintf("%s", attach_links[i].html);
1143 /** Handler for vCard parts */
1144 if (strlen(vcard_partnum) > 0) {
1145 part_source = load_mimepart(msgnum, vcard_partnum);
1146 if (part_source != NULL) {
1148 /** If it's my vCard I can edit it */
1149 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1150 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1151 || (WC->wc_view == VIEW_ADDRESSBOOK)
1153 wprintf("<a href=\"edit_vcard?"
1154 "msgnum=%ld?partnum=%s\">",
1155 msgnum, vcard_partnum);
1156 wprintf("[%s]</a>", _("edit"));
1159 /** In all cases, display the full card */
1160 display_vcard(part_source, 0, 1, NULL);
1164 /** Handler for calendar parts */
1165 if (strlen(cal_partnum) > 0) {
1166 part_source = load_mimepart(msgnum, cal_partnum);
1167 if (part_source != NULL) {
1168 cal_process_attachment(part_source,
1169 msgnum, cal_partnum);
1179 wprintf("</div>\n");
1181 /** end everythingamundo table */
1182 if (!printable_view) {
1183 wprintf("</div>\n");
1186 if (num_attach_links > 0) {
1191 if (ic != (iconv_t)(-1) ) {
1200 * \brief Unadorned HTML output of an individual message, suitable
1201 * for placing in a hidden iframe, for printing, or whatever
1203 * \param msgnum_as_string Message number, as a string instead of as a long int
1205 void embed_message(char *msgnum_as_string) {
1208 msgnum = atol(msgnum_as_string);
1209 begin_ajax_response();
1210 read_message(msgnum, 0, "");
1211 end_ajax_response();
1216 * \brief Printable view of a message
1218 * \param msgnum_as_string Message number, as a string instead of as a long int
1220 void print_message(char *msgnum_as_string) {
1223 msgnum = atol(msgnum_as_string);
1224 output_headers(0, 0, 0, 0, 0, 0);
1226 wprintf("Content-type: text/html\r\n"
1228 "Connection: close\r\n",
1232 wprintf("\r\n\r\n<html>\n"
1233 "<head><title>Printable view</title></head>\n"
1234 "<body onLoad=\" window.print(); window.close(); \">\n"
1237 read_message(msgnum, 1, "");
1239 wprintf("\n</body></html>\n\n");
1246 * \brief Display a message's headers
1248 * \param msgnum_as_string Message number, as a string instead of as a long int
1250 void display_headers(char *msgnum_as_string) {
1254 msgnum = atol(msgnum_as_string);
1255 output_headers(0, 0, 0, 0, 0, 0);
1257 wprintf("Content-type: text/plain\r\n"
1259 "Connection: close\r\n",
1263 serv_printf("MSG2 %ld|3", msgnum);
1264 serv_getln(buf, sizeof buf);
1265 if (buf[0] == '1') {
1266 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1267 wprintf("%s\n", buf);
1277 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1278 * or 'reply quoted' operations.
1280 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1281 * in this function. Doing so would throw a JavaScript error in the
1282 * 'supplied text' argument to the editor.
1284 * \param msgnum Message number of the message we want to quote
1285 * \param forward_attachments Nonzero if we want attachments to be forwarded
1287 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1289 char mime_partnum[256];
1290 char mime_filename[256];
1291 char mime_content_type[256];
1292 char mime_charset[256];
1293 char mime_disposition[256];
1295 char *attachments = NULL;
1297 int num_attachments = 0;
1298 struct wc_attachment *att, *aptr;
1299 char m_subject[256];
1305 int format_type = 0;
1310 iconv_t ic = (iconv_t)(-1) ;
1311 char *ibuf; /**< Buffer of characters to be converted */
1312 char *obuf; /**< Buffer for converted characters */
1313 size_t ibuflen; /**< Length of input buffer */
1314 size_t obuflen; /**< Length of output buffer */
1315 char *osav; /**< Saved pointer to output buffer */
1321 strcpy(reply_to, "");
1322 strcpy(mime_content_type, "text/plain");
1323 strcpy(mime_charset, "us-ascii");
1325 serv_printf("MSG4 %ld", msgnum);
1326 serv_getln(buf, sizeof buf);
1327 if (buf[0] != '1') {
1328 wprintf(_("ERROR:"));
1329 wprintf("%s<br />", &buf[4]);
1333 strcpy(m_subject, "");
1335 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1336 if (!strcmp(buf, "000")) {
1337 wprintf("%s (3)", _("unexpected end of message"));
1340 if (include_headers) {
1341 if (!strncasecmp(buf, "nhdr=yes", 8))
1345 if (!strncasecmp(buf, "type=", 5))
1346 format_type = atoi(&buf[5]);
1347 if (!strncasecmp(buf, "from=", 5)) {
1348 strcpy(from, &buf[5]);
1349 wprintf(_("from "));
1351 utf8ify_rfc822_string(from);
1355 if (!strncasecmp(buf, "subj=", 5)) {
1356 strcpy(m_subject, &buf[5]);
1358 if ((!strncasecmp(buf, "hnod=", 5))
1359 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1360 wprintf("(%s) ", &buf[5]);
1362 if ((!strncasecmp(buf, "room=", 5))
1363 && (strcasecmp(&buf[5], WC->wc_roomname))
1364 && (strlen(&buf[5])>0) ) {
1366 wprintf("%s> ", &buf[5]);
1368 if (!strncasecmp(buf, "rfca=", 5)) {
1369 strcpy(rfca, &buf[5]);
1375 if (!strncasecmp(buf, "node=", 5)) {
1376 strcpy(node, &buf[5]);
1377 if ( ((WC->room_flags & QR_NETWORK)
1378 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1379 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1380 && (strlen(rfca)==0)
1382 wprintf("@%s ", &buf[5]);
1385 if (!strncasecmp(buf, "rcpt=", 5)) {
1387 wprintf("%s ", &buf[5]);
1389 if (!strncasecmp(buf, "time=", 5)) {
1390 fmt_date(now, atol(&buf[5]), 0);
1391 wprintf("%s ", now);
1396 * Save attachment info for later. We can't start downloading them
1397 * yet because we're in the middle of a server transaction.
1399 if (!strncasecmp(buf, "part=", 5)) {
1400 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1403 sprintf(ptr, "%s%s\n",
1404 ((attachments != NULL) ? attachments : ""),
1409 lprintf(9, "attachments=<%s>\n", attachments);
1415 if (include_headers) {
1419 utf8ify_rfc822_string(m_subject);
1421 if (strlen(m_subject) > 0) {
1422 wprintf(_("Subject:"));
1424 msgescputs(m_subject);
1435 * Learn the content type
1437 strcpy(mime_content_type, "text/plain");
1438 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1439 if (!strcmp(buf, "000")) {
1440 wprintf("%s (4)", _("unexpected end of message"));
1443 if (!strncasecmp(buf, "Content-type: ", 14)) {
1444 safestrncpy(mime_content_type, &buf[14],
1445 sizeof(mime_content_type));
1446 for (i=0; i<strlen(mime_content_type); ++i) {
1447 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1448 safestrncpy(mime_charset, &mime_content_type[i+8],
1449 sizeof mime_charset);
1452 for (i=0; i<strlen(mime_content_type); ++i) {
1453 if (mime_content_type[i] == ';') {
1454 mime_content_type[i] = 0;
1457 for (i=0; i<strlen(mime_charset); ++i) {
1458 if (mime_charset[i] == ';') {
1459 mime_charset[i] = 0;
1465 /** Set up a character set conversion if we need to (and if we can) */
1467 if ( (strcasecmp(mime_charset, "us-ascii"))
1468 && (strcasecmp(mime_charset, "UTF-8"))
1469 && (strcasecmp(mime_charset, ""))
1471 ic = ctdl_iconv_open("UTF-8", mime_charset);
1472 if (ic == (iconv_t)(-1) ) {
1473 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1474 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1479 /** Messages in legacy Citadel variformat get handled thusly... */
1480 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1484 /* Boring old 80-column fixed format text gets handled this way... */
1485 else if (!strcasecmp(mime_content_type, "text/plain")) {
1486 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1487 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1488 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1491 if (ic != (iconv_t)(-1) ) {
1493 ibuflen = strlen(ibuf);
1495 obuf = (char *) malloc(obuflen);
1497 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1498 osav[SIZ-obuflen] = 0;
1499 safestrncpy(buf, osav, sizeof buf);
1504 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1505 buf[strlen(buf) - 1] = 0;
1507 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1508 wprintf("<blockquote>");
1510 } else if ((bq == 1) &&
1511 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1512 wprintf("</blockquote>");
1518 wprintf("</tt><br />");
1520 wprintf("</i><br />");
1523 /** HTML just gets escaped and stuffed back into the editor */
1524 else if (!strcasecmp(mime_content_type, "text/html")) {
1525 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1531 /** Unknown weirdness ... don't know how to handle this content type */
1533 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1537 /** end of body handler */
1540 * If there were attachments, we have to download them and insert them
1541 * into the attachment chain for the forwarded message we are composing.
1543 if ( (forward_attachments) && (num_attachments) ) {
1544 for (i=0; i<num_attachments; ++i) {
1545 extract_token(buf, attachments, i, '\n', sizeof buf);
1546 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1547 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1548 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1549 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1550 mime_length = extract_int(buf, 5);
1553 * tracing ... uncomment if necessary
1556 lprintf(9, "fwd filename: %s\n", mime_filename);
1557 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1558 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1559 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1560 lprintf(9, "fwd length : %d\n", mime_length);
1562 if ( (!strcasecmp(mime_disposition, "inline"))
1563 || (!strcasecmp(mime_disposition, "attachment")) ) {
1565 /* Create an attachment struct from this mime part... */
1566 att = malloc(sizeof(struct wc_attachment));
1567 memset(att, 0, sizeof(struct wc_attachment));
1568 att->length = mime_length;
1569 strcpy(att->content_type, mime_content_type);
1570 strcpy(att->filename, mime_filename);
1572 att->data = load_mimepart(msgnum, mime_partnum);
1574 /* And add it to the list. */
1575 if (WC->first_attachment == NULL) {
1576 WC->first_attachment = att;
1579 aptr = WC->first_attachment;
1580 while (aptr->next != NULL) aptr = aptr->next;
1589 if (ic != (iconv_t)(-1) ) {
1594 if (attachments != NULL) {
1600 * \brief Display one row in the mailbox summary view
1602 * \param num The row number to be displayed
1604 void display_summarized(int num) {
1607 wprintf("<tr id=\"m%ld\" style=\"font-weight:%s;\" "
1608 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1609 WC->summ[num].msgnum,
1610 (WC->summ[num].is_new ? "bold" : "normal"),
1611 WC->summ[num].msgnum
1614 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1615 escputs(WC->summ[num].subj);
1618 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1619 escputs(WC->summ[num].from);
1622 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1623 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1633 * \brief display the adressbook overview
1634 * \param msgnum the citadel message number
1635 * \param alpha what????
1637 void display_addressbook(long msgnum, char alpha) {
1639 char mime_partnum[SIZ];
1640 char mime_filename[SIZ];
1641 char mime_content_type[SIZ];
1642 char mime_disposition[SIZ];
1644 char vcard_partnum[SIZ];
1645 char *vcard_source = NULL;
1646 struct message_summary summ;
1648 memset(&summ, 0, sizeof(summ));
1649 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1651 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1653 serv_getln(buf, sizeof buf);
1654 if (buf[0] != '1') return;
1656 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1657 if (!strncasecmp(buf, "part=", 5)) {
1658 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1659 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1660 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1661 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1662 mime_length = extract_int(&buf[5], 5);
1664 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1665 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1666 strcpy(vcard_partnum, mime_partnum);
1672 if (strlen(vcard_partnum) > 0) {
1673 vcard_source = load_mimepart(msgnum, vcard_partnum);
1674 if (vcard_source != NULL) {
1676 /** Display the summary line */
1677 display_vcard(vcard_source, alpha, 0, NULL);
1679 /** If it's my vCard I can edit it */
1680 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1681 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1682 || (WC->wc_view == VIEW_ADDRESSBOOK)
1684 wprintf("<a href=\"edit_vcard?"
1685 "msgnum=%ld?partnum=%s\">",
1686 msgnum, vcard_partnum);
1687 wprintf("[%s]</a>", _("edit"));
1699 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1700 * \param namebuf name to analyze, reverse if nescessary
1702 void lastfirst_firstlast(char *namebuf) {
1703 char firstname[SIZ];
1707 if (namebuf == NULL) return;
1708 if (strchr(namebuf, ';') != NULL) return;
1710 i = num_tokens(namebuf, ' ');
1713 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1714 remove_token(namebuf, i-1, ' ');
1715 strcpy(firstname, namebuf);
1716 sprintf(namebuf, "%s; %s", lastname, firstname);
1720 * \brief fetch what??? name
1721 * \param msgnum the citadel message number
1722 * \param namebuf where to put the name in???
1724 void fetch_ab_name(long msgnum, char *namebuf) {
1726 char mime_partnum[SIZ];
1727 char mime_filename[SIZ];
1728 char mime_content_type[SIZ];
1729 char mime_disposition[SIZ];
1731 char vcard_partnum[SIZ];
1732 char *vcard_source = NULL;
1734 struct message_summary summ;
1736 if (namebuf == NULL) return;
1737 strcpy(namebuf, "");
1739 memset(&summ, 0, sizeof(summ));
1740 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1742 sprintf(buf, "MSG0 %ld|0", msgnum); /** unfortunately we need the mime info now */
1744 serv_getln(buf, sizeof buf);
1745 if (buf[0] != '1') return;
1747 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1748 if (!strncasecmp(buf, "part=", 5)) {
1749 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1750 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1751 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1752 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1753 mime_length = extract_int(&buf[5], 5);
1755 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1756 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1757 strcpy(vcard_partnum, mime_partnum);
1763 if (strlen(vcard_partnum) > 0) {
1764 vcard_source = load_mimepart(msgnum, vcard_partnum);
1765 if (vcard_source != NULL) {
1767 /* Grab the name off the card */
1768 display_vcard(vcard_source, 0, 0, namebuf);
1774 lastfirst_firstlast(namebuf);
1776 for (i=0; i<strlen(namebuf); ++i) {
1777 if (namebuf[i] != ';') return;
1779 strcpy(namebuf, _("(no name)"));
1785 * \brief Record compare function for sorting address book indices
1786 * \param ab1 adressbook one
1787 * \param ab2 adressbook two
1789 int abcmp(const void *ab1, const void *ab2) {
1791 (((const struct addrbookent *)ab1)->ab_name),
1792 (((const struct addrbookent *)ab2)->ab_name)
1798 * \brief Helper function for do_addrbook_view()
1799 * Converts a name into a three-letter tab label
1800 * \param tabbuf the tabbuffer to add name to
1801 * \param name the name to add to the tabbuffer
1803 void nametab(char *tabbuf, char *name) {
1804 stresc(tabbuf, name, 0, 0);
1805 tabbuf[0] = toupper(tabbuf[0]);
1806 tabbuf[1] = tolower(tabbuf[1]);
1807 tabbuf[2] = tolower(tabbuf[2]);
1813 * \brief Render the address book using info we gathered during the scan
1814 * \param addrbook the addressbook to render
1815 * \param num_ab the number of the addressbook
1817 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1821 static int NAMESPERPAGE = 60;
1824 char tabfirst_label[64];
1826 char tablast_label[64];
1827 char this_tablabel[64];
1832 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1833 wprintf(_("This address book is empty."));
1834 wprintf("</i></div>\n");
1839 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1842 num_pages = (num_ab / NAMESPERPAGE) + 1;
1844 tablabels = malloc(num_pages * sizeof (char *));
1845 if (tablabels == NULL) {
1846 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1847 wprintf(_("An internal error has occurred."));
1848 wprintf("</i></div>\n");
1852 for (i=0; i<num_pages; ++i) {
1853 tabfirst = i * NAMESPERPAGE;
1854 tablast = tabfirst + NAMESPERPAGE - 1;
1855 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1856 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1857 nametab(tablast_label, addrbook[tablast].ab_name);
1858 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
1859 tablabels[i] = strdup(this_tablabel);
1862 tabbed_dialog(num_pages, tablabels);
1865 for (i=0; i<num_ab; ++i) {
1867 if ((i / NAMESPERPAGE) != page) { /* New tab */
1868 page = (i / NAMESPERPAGE);
1870 wprintf("</tr></table>\n");
1871 end_tab(page-1, num_pages);
1873 begin_tab(page, num_pages);
1874 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
1878 if ((displayed % 4) == 0) {
1879 if (displayed > 0) {
1883 wprintf("<tr bgcolor=\"#%s\">",
1884 (bg ? "DDDDDD" : "FFFFFF")
1890 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
1891 addrbook[i].ab_msgnum);
1892 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1893 vcard_n_prettyize(addrbook[i].ab_name);
1894 escputs(addrbook[i].ab_name);
1895 wprintf("</a></td>\n");
1899 wprintf("</tr></table>\n");
1900 end_tab((num_pages-1), num_pages);
1902 for (i=0; i<num_pages; ++i) {
1911 * \brief load message pointers from the server
1912 * \param servcmd the citadel command to send to the citserver
1913 * \param with_headers what headers???
1915 int load_msg_ptrs(char *servcmd, int with_headers)
1926 int num_summ_alloc = 0;
1928 if (WC->summ != NULL) {
1933 num_summ_alloc = 100;
1935 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1938 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1940 serv_getln(buf, sizeof buf);
1941 if (buf[0] != '1') {
1944 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1945 if (nummsgs < maxload) {
1946 WC->msgarr[nummsgs] = extract_long(buf, 0);
1947 datestamp = extract_long(buf, 1);
1948 extract_token(fullname, buf, 2, '|', sizeof fullname);
1949 extract_token(nodename, buf, 3, '|', sizeof nodename);
1950 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1951 extract_token(subject, buf, 5, '|', sizeof subject);
1955 if (nummsgs > num_summ_alloc) {
1956 num_summ_alloc *= 2;
1957 WC->summ = realloc(WC->summ,
1958 num_summ_alloc * sizeof(struct message_summary));
1962 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1963 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1964 safestrncpy(WC->summ[nummsgs-1].subj,
1965 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1966 if (strlen(fullname) > 0) {
1967 safestrncpy(WC->summ[nummsgs-1].from,
1968 fullname, sizeof WC->summ[nummsgs-1].from);
1970 if (strlen(subject) > 0) {
1971 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1972 sizeof WC->summ[nummsgs-1].subj);
1975 /** Handle subjects with RFC2047 encoding */
1976 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1978 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1979 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1982 if (strlen(nodename) > 0) {
1983 if ( ((WC->room_flags & QR_NETWORK)
1984 || ((strcasecmp(nodename, serv_info.serv_nodename)
1985 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1987 strcat(WC->summ[nummsgs-1].from, " @ ");
1988 strcat(WC->summ[nummsgs-1].from, nodename);
1992 WC->summ[nummsgs-1].date = datestamp;
1995 /** Handle senders with RFC2047 encoding */
1996 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1998 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1999 strcpy(&WC->summ[nummsgs-1].from[22], "...");
2008 * \brief qsort() compatible function to compare two longs in descending order.
2010 * \param s1 first number to compare
2011 * \param s2 second number to compare
2013 int longcmp_r(const void *s1, const void *s2) {
2020 if (l1 > l2) return(-1);
2021 if (l1 < l2) return(+1);
2027 * \brief qsort() compatible function to compare two message summary structs by ascending subject.
2029 * \param s1 first item to compare
2030 * \param s2 second item to compare
2032 int summcmp_subj(const void *s1, const void *s2) {
2033 struct message_summary *summ1;
2034 struct message_summary *summ2;
2036 summ1 = (struct message_summary *)s1;
2037 summ2 = (struct message_summary *)s2;
2038 return strcasecmp(summ1->subj, summ2->subj);
2042 * \brief qsort() compatible function to compare two message summary structs by descending subject.
2044 * \param s1 first item to compare
2045 * \param s2 second item to compare
2047 int summcmp_rsubj(const void *s1, const void *s2) {
2048 struct message_summary *summ1;
2049 struct message_summary *summ2;
2051 summ1 = (struct message_summary *)s1;
2052 summ2 = (struct message_summary *)s2;
2053 return strcasecmp(summ2->subj, summ1->subj);
2057 * \brief qsort() compatible function to compare two message summary structs by ascending sender.
2059 * \param s1 first item to compare
2060 * \param s2 second item to compare
2062 int summcmp_sender(const void *s1, const void *s2) {
2063 struct message_summary *summ1;
2064 struct message_summary *summ2;
2066 summ1 = (struct message_summary *)s1;
2067 summ2 = (struct message_summary *)s2;
2068 return strcasecmp(summ1->from, summ2->from);
2072 * \brief qsort() compatible function to compare two message summary structs by descending sender.
2074 * \param s1 first item to compare
2075 * \param s2 second item to compare
2077 int summcmp_rsender(const void *s1, const void *s2) {
2078 struct message_summary *summ1;
2079 struct message_summary *summ2;
2081 summ1 = (struct message_summary *)s1;
2082 summ2 = (struct message_summary *)s2;
2083 return strcasecmp(summ2->from, summ1->from);
2087 * \brief qsort() compatible function to compare two message summary structs by ascending date.
2089 * \param s1 first item to compare
2090 * \param s2 second item to compare
2092 int summcmp_date(const void *s1, const void *s2) {
2093 struct message_summary *summ1;
2094 struct message_summary *summ2;
2096 summ1 = (struct message_summary *)s1;
2097 summ2 = (struct message_summary *)s2;
2099 if (summ1->date < summ2->date) return -1;
2100 else if (summ1->date > summ2->date) return +1;
2105 * \brief qsort() compatible function to compare two message summary structs by descending date.
2107 * \param s1 first item to compare
2108 * \param s2 second item to compare
2110 int summcmp_rdate(const void *s1, const void *s2) {
2111 struct message_summary *summ1;
2112 struct message_summary *summ2;
2114 summ1 = (struct message_summary *)s1;
2115 summ2 = (struct message_summary *)s2;
2117 if (summ1->date < summ2->date) return +1;
2118 else if (summ1->date > summ2->date) return -1;
2125 * \brief command loop for reading messages
2127 * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
2129 void readloop(char *oper)
2138 long *displayed_msgs = NULL;
2139 int num_displayed = 0;
2141 int is_addressbook = 0;
2142 int is_singlecard = 0;
2143 int is_calendar = 0;
2148 int lowest_displayed = (-1);
2149 int highest_displayed = 0;
2150 struct addrbookent *addrbook = NULL;
2152 char *sortby = NULL;
2153 char sortpref_name[128];
2154 char sortpref_value[128];
2155 char *subjsort_button;
2156 char *sendsort_button;
2157 char *datesort_button;
2158 int bbs_reverse = 0;
2160 if (WC->wc_view == VIEW_WIKI) {
2161 sprintf(buf, "wiki?room=%s?page=home", WC->wc_roomname);
2166 startmsg = atol(bstr("startmsg"));
2167 maxmsgs = atoi(bstr("maxmsgs"));
2168 is_summary = atoi(bstr("summary"));
2169 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2171 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
2172 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
2174 sortby = bstr("sortby");
2175 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
2176 set_preference(sortpref_name, sortby, 1);
2178 if (strlen(sortby) == 0) sortby = sortpref_value;
2181 if (strlen(sortby) == 0) sortby = "rdate";
2183 /** message board sort */
2184 if (!strcasecmp(sortby, "reverse")) {
2191 output_headers(1, 1, 1, 0, 0, 0);
2194 * When in summary mode, always show ALL messages instead of just
2195 * new or old. Otherwise, show what the user asked for.
2197 if (!strcmp(oper, "readnew")) {
2198 strcpy(cmd, "MSGS NEW");
2200 else if (!strcmp(oper, "readold")) {
2201 strcpy(cmd, "MSGS OLD");
2203 else if (!strcmp(oper, "do_search")) {
2204 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2207 strcpy(cmd, "MSGS ALL");
2210 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
2212 if (!strcmp(oper, "do_search")) {
2213 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2216 strcpy(cmd, "MSGS ALL");
2220 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2222 if (!strcmp(oper, "do_search")) {
2223 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2226 strcpy(cmd, "MSGS ALL");
2231 if (is_summary) { /**< fetch header summary */
2232 snprintf(cmd, sizeof cmd, "MSGS %s|%s||1",
2233 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2234 (!strcmp(oper, "do_search") ? bstr("query") : "")
2241 * Are we doing a summary view? If so, we need to know old messages
2242 * and new messages, so we can do that pretty boldface thing for the
2245 strcpy(old_msgs, "");
2248 serv_getln(buf, sizeof buf);
2249 if (buf[0] == '2') {
2250 strcpy(old_msgs, &buf[4]);
2254 is_singlecard = atoi(bstr("is_singlecard"));
2256 if (WC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2258 strcpy(cmd, "MSGS ALL");
2261 if (WC->wc_default_view == VIEW_TASKS) { /**< tasks */
2263 strcpy(cmd, "MSGS ALL");
2266 if (WC->wc_default_view == VIEW_NOTES) { /**< notes */
2268 strcpy(cmd, "MSGS ALL");
2273 wprintf("<div align=center>%s</div>\n", _("Click on any note to edit it."));
2274 wprintf("<div id=\"new_notes_here\"></div>\n");
2277 nummsgs = load_msg_ptrs(cmd, is_summary);
2280 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2281 wprintf("<div align=\"center\"><br /><em>");
2282 if (!strcmp(oper, "readnew")) {
2283 wprintf(_("No new messages."));
2284 } else if (!strcmp(oper, "readold")) {
2285 wprintf(_("No old messages."));
2287 wprintf(_("No messages here."));
2289 wprintf("</em><br /></div>\n");
2296 for (a = 0; a < nummsgs; ++a) {
2297 /** Are you a new message, or an old message? */
2299 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
2300 WC->summ[a].is_new = 0;
2303 WC->summ[a].is_new = 1;
2309 if (startmsg == 0L) {
2311 startmsg = WC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2314 startmsg = WC->msgarr[0];
2319 if (!strcasecmp(sortby, "subject")) {
2320 qsort(WC->summ, WC->num_summ,
2321 sizeof(struct message_summary), summcmp_subj);
2323 else if (!strcasecmp(sortby, "rsubject")) {
2324 qsort(WC->summ, WC->num_summ,
2325 sizeof(struct message_summary), summcmp_rsubj);
2327 else if (!strcasecmp(sortby, "sender")) {
2328 qsort(WC->summ, WC->num_summ,
2329 sizeof(struct message_summary), summcmp_sender);
2331 else if (!strcasecmp(sortby, "rsender")) {
2332 qsort(WC->summ, WC->num_summ,
2333 sizeof(struct message_summary), summcmp_rsender);
2335 else if (!strcasecmp(sortby, "date")) {
2336 qsort(WC->summ, WC->num_summ,
2337 sizeof(struct message_summary), summcmp_date);
2339 else if (!strcasecmp(sortby, "rdate")) {
2340 qsort(WC->summ, WC->num_summ,
2341 sizeof(struct message_summary), summcmp_rdate);
2345 if (!strcasecmp(sortby, "subject")) {
2346 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2348 else if (!strcasecmp(sortby, "rsubject")) {
2349 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2352 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2355 if (!strcasecmp(sortby, "sender")) {
2356 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2358 else if (!strcasecmp(sortby, "rsender")) {
2359 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2362 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2365 if (!strcasecmp(sortby, "date")) {
2366 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2368 else if (!strcasecmp(sortby, "rdate")) {
2369 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2372 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2376 wprintf("</div>\n"); /** end of 'content' div */
2378 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2379 " document.onkeydown = CtdlMsgListKeyPress; "
2380 " if (document.layers) { "
2381 " document.captureEvents(Event.KEYPRESS); "
2386 /** note that Date and Delete are now in the same column */
2387 wprintf("<div id=\"message_list_hdr\">"
2388 "<div class=\"fix_scrollbar_bug\">"
2389 "<table cellspacing=0 style=\"width:100%%\">"
2392 wprintf("<th width=%d%%>%s %s</th>"
2393 "<th width=%d%%>%s %s</th>"
2394 "<th width=%d%%>%s %s"
2396 "<input type=\"submit\" name=\"delete_button\" id=\"delbutton\" "
2397 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2403 _("Subject"), subjsort_button,
2404 SENDER_COL_WIDTH_PCT,
2405 _("Sender"), sendsort_button,
2406 DATE_PLUS_BUTTONS_WIDTH_PCT,
2407 _("Date"), datesort_button,
2410 wprintf("</table></div></div>\n");
2412 wprintf("<div id=\"message_list\">"
2414 "<div class=\"fix_scrollbar_bug\">\n"
2416 "<table class=\"mailbox_summary\" id=\"summary_headers\" "
2417 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2421 for (a = 0; a < nummsgs; ++a) {
2422 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2424 /** Display the message */
2426 display_summarized(a);
2428 else if (is_addressbook) {
2429 fetch_ab_name(WC->msgarr[a], buf);
2431 addrbook = realloc(addrbook,
2432 (sizeof(struct addrbookent) * num_ab) );
2433 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2434 sizeof(addrbook[num_ab-1].ab_name));
2435 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
2437 else if (is_calendar) {
2438 display_calendar(WC->msgarr[a]);
2440 else if (is_tasks) {
2441 display_task(WC->msgarr[a]);
2443 else if (is_notes) {
2444 display_note(WC->msgarr[a]);
2447 if (displayed_msgs == NULL) {
2448 displayed_msgs = malloc(sizeof(long) *
2449 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2451 displayed_msgs[num_displayed] = WC->msgarr[a];
2454 if (lowest_displayed < 0) lowest_displayed = a;
2455 highest_displayed = a;
2462 * Set the "is_bbview" variable if it appears that we are looking at
2463 * a classic bulletin board view.
2465 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2466 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2471 if (displayed_msgs != NULL) {
2473 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2476 /** if we do a split bbview in the future, begin messages div here */
2478 for (a=0; a<num_displayed; ++a) {
2479 read_message(displayed_msgs[a], 0, "");
2482 /** if we do a split bbview in the future, end messages div here */
2484 free(displayed_msgs);
2485 displayed_msgs = NULL;
2490 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2491 wprintf("</div>"); /**< end of 'message_list' div */
2493 /** Here's the grab-it-to-resize-the-message-list widget */
2494 wprintf("<div id=\"resize_msglist\" "
2495 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2496 "<div class=\"fix_scrollbar_bug\"> <hr>"
2500 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2504 * Bump these because although we're thinking in zero base, the user
2505 * is a drooling idiot and is thinking in one base.
2508 ++highest_displayed;
2511 * If we're not currently looking at ALL requested
2512 * messages, then display the selector bar
2515 /** begin bbview scroller */
2516 wprintf("<form name=\"msgomatic\">");
2517 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2519 wprintf("<select name=\"whichones\" size=\"1\" "
2520 "OnChange=\"location.href=msgomatic.whichones.options"
2521 "[selectedIndex].value\">\n");
2524 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2526 lo = b - maxmsgs + 2;
2528 wprintf("<option %s value="
2533 "%d-%d</option> \n",
2534 ((WC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2543 for (b=0; b<nummsgs; b = b + maxmsgs) {
2545 hi = b + maxmsgs + 1;
2546 if (hi > nummsgs) hi = nummsgs;
2547 wprintf("<option %s value="
2552 "%d-%d</option> \n",
2553 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2562 wprintf("<option value=\"%s?startmsg=%ld"
2563 "?maxmsgs=9999999?summary=%d\">"
2567 WC->msgarr[0], is_summary);
2569 wprintf("</select> ");
2570 wprintf(_("of %d messages."), nummsgs);
2572 /** forward/reverse */
2573 wprintf(" <select name=\"direction\" size=\"1\" "
2574 "OnChange=\"location.href=msgomatic.direction.options"
2575 "[selectedIndex].value\">\n"
2578 wprintf("<option %s value=\"%s?sortby=forward\">oldest to newest</option>\n",
2579 (bbs_reverse ? "" : "selected"),
2583 wprintf("<option %s value=\"%s?sortby=reverse\">newest to oldest</option>\n",
2584 (bbs_reverse ? "selected" : ""),
2588 wprintf("</select></form>\n");
2589 /** end bbview scroller */
2594 do_tasks_view(); /** Render the task list */
2598 do_calendar_view(); /** Render the calendar */
2601 if (is_addressbook) {
2602 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2605 /** Note: wDumpContent() will output one additional </div> tag. */
2607 if (addrbook != NULL) free(addrbook);
2609 /** free the summary */
2610 if (WC->summ != NULL) {
2619 * \brief Back end for post_message()
2620 * ... this is where the actual message gets transmitted to the server.
2622 void post_mime_to_server(void) {
2624 int is_multipart = 0;
2626 struct wc_attachment *att;
2628 size_t encoded_length;
2630 /** RFC2045 requires this, and some clients look for it... */
2631 serv_puts("MIME-Version: 1.0");
2632 serv_puts("X-Mailer: " SERVER);
2634 /** If there are attachments, we have to do multipart/mixed */
2635 if (WC->first_attachment != NULL) {
2640 sprintf(boundary, "Citadel--Multipart--%s--%04x--%04x",
2641 serv_info.serv_fqdn,
2646 /** Remember, serv_printf() appends an extra newline */
2647 serv_printf("Content-type: multipart/mixed; "
2648 "boundary=\"%s\"\n", boundary);
2649 serv_printf("This is a multipart message in MIME format.\n");
2650 serv_printf("--%s", boundary);
2653 serv_puts("Content-type: text/html; charset=utf-8");
2654 serv_puts("Content-Transfer-Encoding: quoted-printable");
2656 serv_puts("<html><body>\r\n");
2657 text_to_server_qp(bstr("msgtext")); /** Transmit message in quoted-printable encoding */
2658 serv_puts("</body></html>\r\n");
2662 /** Add in the attachments */
2663 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2665 encoded_length = ((att->length * 150) / 100);
2666 encoded = malloc(encoded_length);
2667 if (encoded == NULL) break;
2668 CtdlEncodeBase64(encoded, att->data, att->length, 1);
2670 serv_printf("--%s", boundary);
2671 serv_printf("Content-type: %s", att->content_type);
2672 serv_printf("Content-disposition: attachment; "
2673 "filename=\"%s\"", att->filename);
2674 serv_puts("Content-transfer-encoding: base64");
2676 serv_write(encoded, strlen(encoded));
2681 serv_printf("--%s--", boundary);
2689 * \brief Post message (or don't post message)
2691 * Note regarding the "dont_post" variable:
2692 * A random value (actually, it's just a timestamp) is inserted as a hidden
2693 * field called "postseq" when the display_enter page is generated. This
2694 * value is checked when posting, using the static variable dont_post. If a
2695 * user attempts to post twice using the same dont_post value, the message is
2696 * discarded. This prevents the accidental double-saving of the same message
2697 * if the user happens to click the browser "back" button.
2699 void post_message(void)
2702 char encoded_subject[1024];
2703 static long dont_post = (-1L);
2704 struct wc_attachment *att, *aptr;
2705 int is_anonymous = 0;
2708 display_name = bstr("display_name");
2709 if (!strcmp(display_name, "__ANONYMOUS__")) {
2714 if (WC->upload_length > 0) {
2716 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WC->upload_length);
2717 /** There's an attachment. Save it to this struct... */
2718 att = malloc(sizeof(struct wc_attachment));
2719 memset(att, 0, sizeof(struct wc_attachment));
2720 att->length = WC->upload_length;
2721 strcpy(att->content_type, WC->upload_content_type);
2722 strcpy(att->filename, WC->upload_filename);
2725 /** And add it to the list. */
2726 if (WC->first_attachment == NULL) {
2727 WC->first_attachment = att;
2730 aptr = WC->first_attachment;
2731 while (aptr->next != NULL) aptr = aptr->next;
2736 * Mozilla sends a simple filename, which is what we want,
2737 * but Satan's Browser sends an entire pathname. Reduce
2738 * the path to just a filename if we need to.
2740 while (num_tokens(att->filename, '/') > 1) {
2741 remove_token(att->filename, 0, '/');
2743 while (num_tokens(att->filename, '\\') > 1) {
2744 remove_token(att->filename, 0, '\\');
2748 * Transfer control of this memory from the upload struct
2749 * to the attachment struct.
2751 att->data = WC->upload;
2752 WC->upload_length = 0;
2758 if (strlen(bstr("cancel_button")) > 0) {
2759 sprintf(WC->ImportantMessage,
2760 _("Cancelled. Message was not posted."));
2761 } else if (strlen(bstr("attach_button")) > 0) {
2764 } else if (atol(bstr("postseq")) == dont_post) {
2765 sprintf(WC->ImportantMessage,
2766 _("Automatically cancelled because you have already "
2767 "saved this message."));
2769 rfc2047encode(encoded_subject, sizeof encoded_subject, bstr("subject"));
2770 sprintf(buf, "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s",
2778 bstr("my_email_addr")
2781 serv_getln(buf, sizeof buf);
2782 if (buf[0] == '4') {
2783 post_mime_to_server();
2784 if ( (strlen(bstr("recp")) > 0)
2785 || (strlen(bstr("cc")) > 0)
2786 || (strlen(bstr("bcc")) > 0)
2788 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2791 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2793 dont_post = atol(bstr("postseq"));
2795 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
2796 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2802 free_attachments(WC);
2805 * We may have been supplied with instructions regarding the location
2806 * to which we must return after posting. If found, go there.
2808 if (strlen(bstr("return_to")) > 0) {
2809 http_redirect(bstr("return_to"));
2812 * If we were editing a page in a wiki room, go to that page now.
2814 else if (strlen(bstr("wikipage")) > 0) {
2815 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
2819 * Otherwise, just go to the "read messages" loop.
2822 readloop("readnew");
2830 * \brief display the message entry screen
2832 void display_enter(void)
2838 struct wc_attachment *att;
2839 int recipient_required = 0;
2840 int recipient_bad = 0;
2842 int is_anonymous = 0;
2843 long existing_page = (-1L);
2847 if (strlen(bstr("force_room")) > 0) {
2848 gotoroom(bstr("force_room"));
2851 display_name = bstr("display_name");
2852 if (!strcmp(display_name, "__ANONYMOUS__")) {
2857 /** First test to see whether this is a room that requires recipients to be entered */
2858 serv_puts("ENT0 0");
2859 serv_getln(buf, sizeof buf);
2860 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
2861 recipient_required = 1;
2863 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2864 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2865 readloop("readnew");
2870 * Are we perhaps in an address book view? If so, then an "enter
2871 * message" command really means "add new entry."
2873 if (WC->wc_default_view == VIEW_ADDRESSBOOK) {
2874 do_edit_vcard(-1, "", "");
2878 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
2880 * Are we perhaps in a calendar room? If so, then an "enter
2881 * message" command really means "add new calendar item."
2883 if (WC->wc_default_view == VIEW_CALENDAR) {
2884 display_edit_event();
2889 * Are we perhaps in a tasks view? If so, then an "enter
2890 * message" command really means "add new task."
2892 if (WC->wc_default_view == VIEW_TASKS) {
2893 display_edit_task();
2899 * Otherwise proceed normally.
2900 * Do a custom room banner with no navbar...
2902 output_headers(1, 1, 2, 0, 0, 0);
2903 wprintf("<div id=\"banner\">\n");
2904 embed_room_banner(NULL, navbar_none);
2905 wprintf("</div>\n");
2906 wprintf("<div id=\"content\">\n"
2907 "<div class=\"fix_scrollbar_bug message \">");
2909 /** Now check our actual recipients if there are any */
2910 if (recipient_required) {
2911 sprintf(buf, "ENT0 0|%s|%d|0||%s||%s|%s|%s",
2915 bstr("cc"), bstr("bcc"), bstr("wikipage"));
2917 serv_getln(buf, sizeof buf);
2919 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
2920 if (strlen(bstr("recp")) + strlen(bstr("cc")) + strlen(bstr("bcc")) > 0) {
2924 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2925 wprintf("<em>%s</em><br />\n", &buf[4]);
2930 /** If we got this far, we can display the message entry screen. */
2932 /** begin message entry screen */
2934 "enctype=\"multipart/form-data\" "
2936 "accept-charset=\"UTF-8\" "
2938 "name=\"enterform\""
2940 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2941 if (WC->wc_view == VIEW_WIKI) {
2942 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
2944 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
2948 wprintf("<img src=\"static/newmess3_24x.gif\" class=\"imgedit\">");
2949 wprintf(" "); /** header bar */
2950 fmt_date(buf, now, 0);
2952 wprintf("\n"); /** header bar */
2955 wprintf("<label for=\"from_id\" > ");
2956 wprintf(_(" <I>from</I> "));
2957 wprintf("</label>");
2959 /* Allow the user to select any of his valid screen names */
2961 wprintf("<select name=\"display_name\" size=1 id=\"from_id\">\n");
2964 serv_getln(buf, sizeof buf);
2965 if (buf[0] == '1') {
2966 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2967 wprintf("<option %s value=\"",
2968 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
2973 wprintf("</option>\n");
2977 if (WC->room_flags & QR_ANONOPT) {
2978 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
2979 ((!strcasecmp(bstr("__ANONYMOUS__"), WC->wc_fullname)) ? "selected" : ""),
2984 wprintf("</select>\n");
2986 /* If this is an email (not a post), allow the user to select any of his
2987 * valid email addresses.
2989 if (recipient_required) {
2991 serv_getln(buf, sizeof buf);
2992 if (buf[0] == '1') {
2993 wprintf("<select name=\"my_email_addr\" size=1>\n");
2994 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2995 wprintf("<option value=\"");
2999 wprintf("></option>\n");
3001 wprintf("</select>\n");
3005 wprintf(_(" <I>in</I> "));
3006 escputs(WC->wc_roomname);
3009 if (recipient_required) {
3011 wprintf("<div style=\"float: left;\"><label for=\"recp_id\"> ");
3014 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
3015 escputs(bstr("recp"));
3016 wprintf("\" size=45 maxlength=1000 />");
3017 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
3020 wprintf("<br/><label for=\"cc_id\"> ");
3023 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
3024 escputs(bstr("cc"));
3025 wprintf("\" size=45 maxlength=1000 />");
3026 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
3027 wprintf("<br/><label for=\"bcc_id\"> ");
3030 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
3031 escputs(bstr("bcc"));
3032 wprintf("\" size=45 maxlength=1000 />");
3033 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
3035 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
3036 wprintf("<script type=\"text/javascript\"> \n"
3037 " activate_entmsg_autocompleters(); \n"
3042 /** Pop open an address book -- begin **/
3044 "<a href=\"javascript:PopOpenAddressBook('recp_id|%s|cc_id|%s|bcc_id|%s');\" "
3046 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
3048 _("To:"), _("CC:"), _("BCC:"),
3049 _("Contacts"), _("Contacts")
3051 /** Pop open an address book -- end **/
3054 wprintf("<div style=\"clear: both;\"><label for=\"subject_id\" > ");
3055 if (recipient_required) {
3056 wprintf(_("Subject:"));
3059 wprintf(_("Subject (optional):"));
3062 "<input type=\"text\" name=\"subject\" id=\"subject_id\" value=\" ");
3063 escputs(bstr("subject"));
3064 wprintf("\" size=45 maxlength=70>\n");
3066 wprintf("</div>\n");
3068 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
3070 /** If we're continuing from a previous edit, put our partially-composed message back... */
3071 msgescputs(bstr("msgtext"));
3073 /* If we're forwarding a message, insert it here... */
3074 if (atol(bstr("fwdquote")) > 0L) {
3075 wprintf("<br><div align=center><i>");
3076 wprintf(_("--- forwarded message ---"));
3077 wprintf("</i></div><br>");
3078 pullquote_message(atol(bstr("fwdquote")), 1, 1);
3081 /** If we're replying quoted, insert the quote here... */
3082 else if (atol(bstr("replyquote")) > 0L) {
3085 pullquote_message(atol(bstr("replyquote")), 0, 1);
3086 wprintf("</blockquote><br>");
3089 /** If we're editing a wiki page, insert the existing page here... */
3090 else if (WC->wc_view == VIEW_WIKI) {
3091 safestrncpy(buf, bstr("wikipage"), sizeof buf);
3092 str_wiki_index(buf);
3093 existing_page = locate_message_by_uid(buf);
3094 if (existing_page >= 0L) {
3095 pullquote_message(existing_page, 1, 0);
3099 /** Insert our signature if appropriate... */
3100 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
3101 get_preference("use_sig", buf, sizeof buf);
3102 if (!strcasecmp(buf, "yes")) {
3103 get_preference("signature", ebuf, sizeof ebuf);
3104 euid_unescapize(buf, ebuf);
3105 wprintf("<br>--<br>");
3106 for (i=0; i<strlen(buf); ++i) {
3107 if (buf[i] == '\n') {
3110 else if (buf[i] == '<') {
3113 else if (buf[i] == '>') {
3116 else if (buf[i] == '&') {
3119 else if (buf[i] == '\"') {
3122 else if (buf[i] == '\'') {
3125 else if (isprint(buf[i])) {
3126 wprintf("%c", buf[i]);
3132 wprintf("</textarea>");
3135 * The following script embeds the TinyMCE richedit control, and automatically
3136 * transforms the textarea into a richedit textarea.
3139 "<script language=\"javascript\" type=\"text/javascript\" src=\"tiny_mce/tiny_mce.js\"></script>\n"
3140 "<script language=\"javascript\" type=\"text/javascript\">"
3142 " mode : \"textareas\", width : \"100%%\", browsers : \"msie,gecko\", "
3143 " theme : \"advanced\", plugins : \"iespell\", "
3144 " theme_advanced_buttons1 : \"bold, italic, underline, strikethrough, justifyleft, justifycenter, justifyright, justifyfull, bullist, numlist, cut, copy, paste, link, image, help, forecolor, iespell, code\", "
3145 " theme_advanced_buttons2 : \"\", "
3146 " theme_advanced_buttons3 : \"\", "
3147 " content_css : \"static/webcit-tinymce.css\" "
3152 /** Enumerate any attachments which are already in place... */
3153 wprintf("<div style=\"float: left; \"><img src=\"static/diskette_24x.gif\" border=0 ");
3154 wprintf(_("Attachments:"));
3156 wprintf("<select name=\"which_attachment\" size=1>");
3157 for (att = WC->first_attachment; att != NULL; att = att->next) {
3158 wprintf("<option value=\"");
3159 urlescputs(att->filename);
3161 escputs(att->filename);
3162 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3163 wprintf("</option>\n");
3165 wprintf("</select><br />");
3167 /** Now offer the ability to attach additional files... */
3168 wprintf(" ");
3169 wprintf(_("Attach file:"));
3170 wprintf(" <input name=\"attachfile\" "
3171 "size=16 type=\"file\">\n "
3172 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3175 /** Seth asked for these to be at the top *and* bottom... (removed) */
3176 wprintf("<div class=\"send_edit_msg\">");
3177 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3178 if (recipient_required) {
3179 wprintf(_("Send message"));
3181 wprintf(_("Post message"));
3184 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3188 /** Make sure we only insert our signature once */
3189 if (strcmp(bstr("sig_inserted"), "yes")) {
3190 wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
3193 wprintf("</form>\n");
3194 wprintf("</div></div>\n");
3196 DONE: address_book_popup();
3202 * \brief delete a message
3204 void delete_msg(void)
3209 msgid = atol(bstr("msgid"));
3211 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3212 serv_printf("DELE %ld", msgid);
3214 else { /** Otherwise move it to Trash */
3215 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3218 serv_getln(buf, sizeof buf);
3219 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3221 readloop("readnew");
3226 * \brief move a message to another folder
3233 msgid = atol(bstr("msgid"));
3235 if (strlen(bstr("move_button")) > 0) {
3236 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3238 serv_getln(buf, sizeof buf);
3239 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3241 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3244 readloop("readnew");
3252 * \brief Confirm move of a message
3254 void confirm_move_msg(void)
3260 msgid = atol(bstr("msgid"));
3263 output_headers(1, 1, 2, 0, 0, 0);
3264 wprintf("<div id=\"banner\">\n");
3265 wprintf("<TABLE WIDTH=100%% BORDER=0><TR><TD>");
3266 wprintf("<SPAN CLASS=\"titlebar\">");
3267 wprintf(_("Confirm move of message"));
3268 wprintf("</SPAN>\n");
3269 wprintf("</TD></TR></TABLE>\n");
3270 wprintf("</div>\n<div id=\"content\">\n");
3272 wprintf("<CENTER>");
3274 wprintf(_("Move this message to:"));
3275 wprintf("<br />\n");
3277 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3278 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3280 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3282 serv_getln(buf, sizeof buf);
3283 if (buf[0] == '1') {
3284 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3285 extract_token(targ, buf, 0, '|', sizeof targ);
3286 wprintf("<OPTION>");
3291 wprintf("</SELECT>\n");
3292 wprintf("<br />\n");
3294 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3296 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3297 wprintf("</form></CENTER>\n");
3299 wprintf("</CENTER>\n");