5 * \defgroup MsgDisp Functions which deal with the fetching and displaying of messages.
6 * \ingroup WebcitDisplayItems
11 #include "webserver.h"
14 #define SUBJ_COL_WIDTH_PCT 50 /**< Mailbox view column width */
15 #define SENDER_COL_WIDTH_PCT 30 /**< Mailbox view column width */
16 #define DATE_PLUS_BUTTONS_WIDTH_PCT 20 /**< Mailbox view column width */
19 * Address book entry (keep it short and sweet, it's just a quickie lookup
20 * which we can use to get to the real meat and bones later)
23 char ab_name[64]; /**< name string */
24 long ab_msgnum; /**< message number of address book entry */
32 * \brief Wrapper around iconv_open()
33 * Our version adds aliases for non-standard Microsoft charsets
34 * such as 'MS950', aliasing them to names like 'CP950'
36 * \param tocode Target encoding
37 * \param fromcode Source encoding
39 iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode)
41 iconv_t ic = (iconv_t)(-1) ;
42 ic = iconv_open(tocode, fromcode);
43 if (ic == (iconv_t)(-1) ) {
44 char alias_fromcode[64];
45 if ( (strlen(fromcode) == 5) && (!strncasecmp(fromcode, "MS", 2)) ) {
46 safestrncpy(alias_fromcode, fromcode, sizeof alias_fromcode);
47 alias_fromcode[0] = 'C';
48 alias_fromcode[1] = 'P';
49 ic = iconv_open(tocode, alias_fromcode);
57 * \brief Handle subjects with RFC2047 encoding
59 * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=
60 * \param buf the stringbuffer to process
62 void utf8ify_rfc822_string(char *buf) {
63 char *start, *end, *next, *nextend, *ptr;
68 iconv_t ic = (iconv_t)(-1) ;
69 char *ibuf; /**< Buffer of characters to be converted */
70 char *obuf; /**< Buffer for converted characters */
71 size_t ibuflen; /**< Length of input buffer */
72 size_t obuflen; /**< Length of output buffer */
73 char *isav; /**< Saved pointer to input buffer */
74 char *osav; /**< Saved pointer to output buffer */
77 int illegal_non_rfc2047_encoding = 0;
79 /** Sometimes, badly formed messages contain strings which were simply
80 * written out directly in some foreign character set instead of
81 * using RFC2047 encoding. This is illegal but we will attempt to
82 * handle it anyway by converting from a user-specified default
83 * charset to UTF-8 if we see any nonprintable characters.
86 for (i=0; i<len; ++i) {
87 if ((buf[i] < 32) || (buf[i] > 126)) {
88 illegal_non_rfc2047_encoding = 1;
89 i = len; ///< take a shortcut, it won't be more than one.
92 if (illegal_non_rfc2047_encoding) {
93 char default_header_charset[128];
94 get_preference("default_header_charset", default_header_charset, sizeof default_header_charset);
95 if ( (strcasecmp(default_header_charset, "UTF-8")) && (strcasecmp(default_header_charset, "us-ascii")) ) {
96 ic = ctdl_iconv_open("UTF-8", default_header_charset);
97 if (ic != (iconv_t)(-1) ) {
100 safestrncpy(ibuf, buf, 1024);
101 ibuflen = strlen(ibuf);
103 obuf = (char *) malloc(obuflen);
105 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
106 osav[1024-obuflen] = 0;
115 /* pre evaluate the first pair */
116 nextend = end = NULL;
118 start = strstr(buf, "=?");
120 end = strstr(start, "?=");
122 while ((start != NULL) && (end != NULL))
124 next = strstr(end, "=?");
126 nextend = strstr(next, "?=");
130 /* did we find two partitions */
131 if ((next != NULL) &&
135 while ((ptr < next) &&
141 /* did we find a gab just filled with blanks? */
146 len - (next - start));
148 /* now terminate the gab at the end */
149 delta = (next - end) - 2;
153 /* move next to its new location. */
158 /* our next-pair is our new first pair now. */
163 /** Now we handle foreign character sets properly encoded
166 while (start=strstr(buf, "=?"), end=strstr(buf, "?="),
167 ((start != NULL) && (end != NULL) && (end > start)) )
169 extract_token(charset, start, 1, '?', sizeof charset);
170 extract_token(encoding, start, 2, '?', sizeof encoding);
171 extract_token(istr, start, 3, '?', sizeof istr);
175 if (!strcasecmp(encoding, "B")) { /**< base64 */
176 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
178 else if (!strcasecmp(encoding, "Q")) { /**< quoted-printable */
186 if (istr[pos] == '_') istr[pos] = ' ';
190 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, len);
193 strcpy(ibuf, istr); /**< unknown encoding */
194 ibuflen = strlen(istr);
197 ic = ctdl_iconv_open("UTF-8", charset);
198 if (ic != (iconv_t)(-1) ) {
200 obuf = (char *) malloc(obuflen);
202 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
203 osav[1024-obuflen] = 0;
208 remove_token(end, 0, '?');
209 remove_token(end, 0, '?');
210 remove_token(end, 0, '?');
211 remove_token(end, 0, '?');
212 strcpy(end, &end[1]);
214 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
223 remove_token(end, 0, '?');
224 remove_token(end, 0, '?');
225 remove_token(end, 0, '?');
226 remove_token(end, 0, '?');
227 strcpy(end, &end[1]);
229 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
236 * Since spammers will go to all sorts of absurd lengths to get their
237 * messages through, there are LOTS of corrupt headers out there.
238 * So, prevent a really badly formed RFC2047 header from throwing
239 * this function into an infinite loop.
242 if (passes > 20) return;
252 * \brief RFC2047-encode a header field if necessary.
253 * If no non-ASCII characters are found, the string
254 * will be copied verbatim without encoding.
256 * \param target Target buffer.
257 * \param maxlen Maximum size of target buffer.
258 * \param source Source string to be encoded.
260 void webcit_rfc2047encode(char *target, int maxlen, char *source)
262 int need_to_encode = 0;
266 if (target == NULL) return;
267 len = strlen(source);
268 for (i=0; i<len; ++i) {
269 if ((source[i] < 32) || (source[i] > 126)) {
271 i = len; ///< shortcut. won't become more than 1
275 if (!need_to_encode) {
276 safestrncpy(target, source, maxlen);
280 strcpy(target, "=?UTF-8?Q?");
281 for (i=0; i<len; ++i) {
282 ch = (unsigned char) source[i];
283 if ((ch < 32) || (ch > 126) || (ch == 61)) {
284 sprintf(&target[strlen(target)], "=%02X", ch);
287 sprintf(&target[strlen(target)], "%c", ch);
291 strcat(target, "?=");
298 * \brief Look for URL's embedded in a buffer and make them linkable. We use a
299 * target window in order to keep the BBS session in its own window.
300 * \param buf the message buffer
305 char *start, *end, *pos;
312 for (pos = buf; (pos < end) && (start == NULL); ++pos) {
313 if (!strncasecmp(pos, "http://", 7))
315 if (!strncasecmp(pos, "ftp://", 6))
322 for (pos = buf+len; pos > start; --pos) {
323 if ( (!isprint(*pos))
342 strncpy(urlbuf, start, end - start);
343 urlbuf[end - start] = '\0';
346 strncpy(outbuf, buf, start - buf );
347 sprintf(&outbuf[start-buf], "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
348 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
350 if ( strlen(outbuf) < 250 )
356 * \brief Turn a vCard "n" (name) field into something displayable.
357 * \param name the name field to convert
359 void vcard_n_prettyize(char *name)
364 original_name = strdup(name);
365 len = strlen(original_name);
366 for (i=0; i<5; ++i) {
368 if (original_name[len-1] == ' ') {
369 original_name[--len] = 0;
371 if (original_name[len-1] == ';') {
372 original_name[--len] = 0;
378 for (i=0; i<len; ++i) {
379 if (original_name[i] == ';') {
384 name[j++] = original_name[i];
395 * \brief preparse a vcard name
396 * display_vcard() calls this after parsing the textual vCard into
397 * our 'struct vCard' data object.
398 * This gets called instead of display_parsed_vcard() if we are only looking
399 * to extract the person's name instead of displaying the card.
400 * \param v the vcard to retrieve the name from
401 * \param storename where to put the name at
403 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
406 strcpy(storename, "");
408 name = vcard_get_prop(v, "n", 1, 0, 0);
410 strcpy(storename, name);
411 /* vcard_n_prettyize(storename); */
419 * \brief html print a vcard
420 * display_vcard() calls this after parsing the textual vCard into
421 * our 'struct vCard' data object.
423 * Set 'full' to nonzero to display the full card, otherwise it will only
424 * show a summary line.
426 * This code is a bit ugly, so perhaps an explanation is due: we do this
427 * in two passes through the vCard fields. On the first pass, we process
428 * fields we understand, and then render them in a pretty fashion at the
429 * end. Then we make a second pass, outputting all the fields we don't
430 * understand in a simple two-column name/value format.
431 * \param v the vCard to display
432 * \param full display all items of the vcard?
434 void display_parsed_vcard(struct vCard *v, int full) {
440 char *thisname, *thisvalue;
441 char firsttoken[SIZ];
450 strcpy(fullname, "");
458 name = vcard_get_prop(v, "fn", 1, 0, 0);
462 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
463 strcpy(fullname, name);
464 vcard_n_prettyize(fullname);
474 wprintf("<div align=center>"
475 "<table bgcolor=#aaaaaa width=50%%>");
476 for (pass=1; pass<=2; ++pass) {
478 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
480 thisname = strdup(v->prop[i].name);
481 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
483 for (j=0; j<num_tokens(thisname, ';'); ++j) {
484 extract_token(buf, thisname, j, ';', sizeof buf);
485 if (!strcasecmp(buf, "encoding=quoted-printable")) {
487 remove_token(thisname, j, ';');
489 if (!strcasecmp(buf, "encoding=base64")) {
491 remove_token(thisname, j, ';');
495 len = strlen(v->prop[i].value);
498 // %ff can become 6 bytes in utf8
499 thisvalue = malloc(len * 2 + 3);
500 j = CtdlDecodeQuotedPrintable(
501 thisvalue, v->prop[i].value,
506 // ff will become one byte..
507 thisvalue = malloc(len + 50);
509 thisvalue, v->prop[i].value,
510 strlen(v->prop[i].value) );
513 thisvalue = strdup(v->prop[i].value);
516 /** Various fields we may encounter ***/
518 /** N is name, but only if there's no FN already there */
519 if (!strcasecmp(firsttoken, "n")) {
520 if (IsEmptyStr(fullname)) {
521 strcpy(fullname, thisvalue);
522 vcard_n_prettyize(fullname);
526 /** FN (full name) is a true 'display name' field */
527 else if (!strcasecmp(firsttoken, "fn")) {
528 strcpy(fullname, thisvalue);
532 else if (!strcasecmp(firsttoken, "title")) {
533 strcpy(title, thisvalue);
537 else if (!strcasecmp(firsttoken, "org")) {
538 strcpy(org, thisvalue);
541 else if (!strcasecmp(firsttoken, "email")) {
543 if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
545 "<a href=\"display_enter"
546 "?force_room=_MAIL_?recp=");
548 len = strlen(mailto);
549 urlesc(&mailto[len], SIZ - len, fullname);
550 len = strlen(mailto);
551 urlesc(&mailto[len], SIZ - len, " <");
552 len = strlen(mailto);
553 urlesc(&mailto[len], SIZ - len, thisvalue);
554 len = strlen(mailto);
555 urlesc(&mailto[len], SIZ - len, ">");
557 strcat(mailto, "\">");
558 len = strlen(mailto);
559 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
560 strcat(mailto, "</A>");
562 else if (!strcasecmp(firsttoken, "tel")) {
563 if (!IsEmptyStr(phone)) strcat(phone, "<br />");
564 strcat(phone, thisvalue);
565 for (j=0; j<num_tokens(thisname, ';'); ++j) {
566 extract_token(buf, thisname, j, ';', sizeof buf);
567 if (!strcasecmp(buf, "tel"))
569 else if (!strcasecmp(buf, "work"))
570 strcat(phone, _(" (work)"));
571 else if (!strcasecmp(buf, "home"))
572 strcat(phone, _(" (home)"));
573 else if (!strcasecmp(buf, "cell"))
574 strcat(phone, _(" (cell)"));
582 else if (!strcasecmp(firsttoken, "adr")) {
585 wprintf(_("Address:"));
586 wprintf("</TD><TD>");
587 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
588 extract_token(buf, thisvalue, j, ';', sizeof buf);
589 if (!IsEmptyStr(buf)) {
591 if (j<3) wprintf("<br />");
595 wprintf("</TD></TR>\n");
598 else if (!strcasecmp(firsttoken, "version")) {
601 else if (!strcasecmp(firsttoken, "rev")) {
604 else if (!strcasecmp(firsttoken, "label")) {
609 /*** Don't show extra fields. They're ugly.
613 wprintf("</TD><TD>");
615 wprintf("</TD></TR>\n");
625 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
626 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
627 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
628 "<FONT SIZE=+1><B>");
630 wprintf("</B></FONT>");
631 if (!IsEmptyStr(title)) {
632 wprintf("<div align=right>");
636 if (!IsEmptyStr(org)) {
637 wprintf("<div align=right>");
641 wprintf("</TD></TR>\n");
643 if (!IsEmptyStr(phone)) {
645 wprintf(_("Telephone:"));
646 wprintf("</td><td>%s</td></tr>\n", phone);
648 if (!IsEmptyStr(mailto)) {
650 wprintf(_("E-mail:"));
651 wprintf("</td><td>%s</td></tr>\n", mailto);
657 wprintf("</table></div>\n");
663 * \brief Display a textual vCard
664 * (Converts to a vCard object and then calls the actual display function)
665 * Set 'full' to nonzero to display the whole card instead of a one-liner.
666 * Or, if "storename" is non-NULL, just store the person's name in that
667 * buffer instead of displaying the card at all.
668 * \param vcard_source the buffer containing the vcard text
669 * \param alpha what???
670 * \param full should we usse all lines?
671 * \param storename where to store???
673 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
679 v = vcard_load(vcard_source);
680 if (v == NULL) return;
682 name = vcard_get_prop(v, "n", 1, 0, 0);
688 if (storename != NULL) {
689 fetchname_parsed_vcard(v, storename);
691 else if ( (alpha == 0)
692 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
693 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
695 display_parsed_vcard(v, full);
709 * I wanna SEE that message!
711 * msgnum Message number to display
712 * printable_view Nonzero to display a printable view
713 * section Optional for encapsulated message/rfc822 submessage
715 void read_message(long msgnum, int printable_view, char *section) {
717 char mime_partnum[256] = "";
718 char mime_name[256] = "";
719 char mime_filename[256] = "";
720 char escaped_mime_filename[256] = "";
721 char mime_content_type[256] = "";
722 char mime_charset[256] = "";
723 char mime_disposition[256] = "";
725 struct attach_link *attach_links = NULL;
726 int num_attach_links = 0;
727 char mime_submessages[256] = "";
728 char m_subject[256] = "";
729 char m_cc[1024] = "";
733 char reply_to[512] = "";
734 char reply_all[4096] = "";
740 char vcard_partnum[256] = "";
741 char cal_partnum[256] = "";
742 char *part_source = NULL;
743 char msg4_partnum[32] = "";
745 iconv_t ic = (iconv_t)(-1) ;
746 char *ibuf; /**< Buffer of characters to be converted */
747 char *obuf; /**< Buffer for converted characters */
748 size_t ibuflen; /**< Length of input buffer */
749 size_t obuflen; /**< Length of output buffer */
750 char *osav; /**< Saved pointer to output buffer */
753 strcpy(mime_content_type, "text/plain");
754 strcpy(mime_charset, "us-ascii");
755 strcpy(mime_submessages, "");
757 serv_printf("MSG4 %ld|%s", msgnum, section);
758 serv_getln(buf, sizeof buf);
761 wprintf(_("ERROR:"));
762 wprintf("</strong> %s<br />\n", &buf[4]);
766 /** begin everythingamundo table */
767 if (!printable_view) {
768 wprintf("<div class=\"fix_scrollbar_bug message\" ");
769 wprintf("onMouseOver=document.getElementById(\"msg%ld\").style.visibility=\"visible\" ", msgnum);
770 wprintf("onMouseOut=document.getElementById(\"msg%ld\").style.visibility=\"hidden\" >", msgnum);
773 /** begin message header table */
774 wprintf("<div class=\"message_header\">");
776 strcpy(m_subject, "");
779 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
780 if (!strcmp(buf, "000")) {
782 wprintf(_("unexpected end of message"));
783 wprintf(" (1)</i><br /><br />\n");
787 if (!strncasecmp(buf, "nhdr=yes", 8))
791 if (!strncasecmp(buf, "type=", 5))
792 format_type = atoi(&buf[5]);
793 if (!strncasecmp(buf, "from=", 5)) {
794 strcpy(from, &buf[5]);
796 wprintf("<a href=\"showuser?who=");
798 utf8ify_rfc822_string(from);
805 if (!strncasecmp(buf, "subj=", 5)) {
806 safestrncpy(m_subject, &buf[5], sizeof m_subject);
808 if (!strncasecmp(buf, "cccc=", 5)) {
810 safestrncpy(m_cc, &buf[5], sizeof m_cc);
811 if (!IsEmptyStr(reply_all)) {
812 strcat(reply_all, ", ");
814 len = strlen(reply_all);
815 safestrncpy(&reply_all[len], &buf[5],
816 (sizeof reply_all - len) );
818 if ((!strncasecmp(buf, "hnod=", 5))
819 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
820 wprintf("(%s) ", &buf[5]);
822 if ((!strncasecmp(buf, "room=", 5))
823 && (strcasecmp(&buf[5], WC->wc_roomname))
824 && (!IsEmptyStr(&buf[5])) ) {
826 wprintf("%s> ", &buf[5]);
828 if (!strncasecmp(buf, "rfca=", 5)) {
829 strcpy(rfca, &buf[5]);
835 if (!strncasecmp(buf, "node=", 5)) {
836 strcpy(node, &buf[5]);
837 if ( ((WC->room_flags & QR_NETWORK)
838 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
839 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
840 && (IsEmptyStr(rfca))
842 wprintf("@%s ", &buf[5]);
845 if (!strncasecmp(buf, "rcpt=", 5)) {
848 if (!IsEmptyStr(reply_all)) {
849 strcat(reply_all, ", ");
851 len = strlen(reply_all);
852 safestrncpy(&reply_all[len], &buf[5],
853 (sizeof reply_all - len) );
855 utf8ify_rfc822_string(&buf[5]);
860 if (!strncasecmp(buf, "time=", 5)) {
861 webcit_fmt_date(now, atol(&buf[5]), 0);
867 if (!strncasecmp(buf, "part=", 5)) {
868 extract_token(mime_name, &buf[5], 0, '|', sizeof mime_filename);
869 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
870 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
871 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
872 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
873 mime_length = extract_int(&buf[5], 5);
876 striplt(mime_filename);
877 if ( (IsEmptyStr(mime_filename)) && (!IsEmptyStr(mime_name)) ) {
878 strcpy(mime_filename, mime_name);
881 if (!strcasecmp(mime_content_type, "message/rfc822")) {
882 if (!IsEmptyStr(mime_submessages)) {
883 strcat(mime_submessages, "|");
885 strcat(mime_submessages, mime_partnum);
887 else if ((!strcasecmp(mime_disposition, "inline"))
888 && (!strncasecmp(mime_content_type, "image/", 6)) ){
890 attach_links = realloc(attach_links,
891 (num_attach_links*sizeof(struct attach_link)));
892 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
893 snprintf(attach_links[num_attach_links-1].html, 1024,
894 "<img src=\"mimepart/%ld/%s/%s\">",
895 msgnum, mime_partnum, mime_filename);
897 else if ( ( (!strcasecmp(mime_disposition, "attachment"))
898 || (!strcasecmp(mime_disposition, "inline"))
899 || (!strcasecmp(mime_disposition, ""))
900 ) && (!IsEmptyStr(mime_content_type))
903 attach_links = realloc(attach_links,
904 (num_attach_links*sizeof(struct attach_link)));
905 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
906 urlesc(escaped_mime_filename, 265, mime_filename);
907 snprintf(attach_links[num_attach_links-1].html, 1024,
908 "<img src=\"static/diskette_24x.gif\" "
909 "border=0 align=middle>\n"
910 "%s (%s, %d bytes) [ "
911 "<a href=\"mimepart/%ld/%s/%s\""
912 "target=\"wc.%ld.%s\">%s</a>"
914 "<a href=\"mimepart_download/%ld/%s/%s\">%s</a>"
917 mime_content_type, mime_length,
918 msgnum, mime_partnum, escaped_mime_filename,
919 msgnum, mime_partnum,
921 msgnum, mime_partnum, escaped_mime_filename,
926 /** begin handler prep ***/
927 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
928 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
929 strcpy(vcard_partnum, mime_partnum);
932 if ( (!strcasecmp(mime_content_type, "text/calendar"))
933 || (!strcasecmp(mime_content_type, "application/ics")) ) {
934 strcpy(cal_partnum, mime_partnum);
937 /** end handler prep ***/
943 /** Generate a reply-to address */
944 if (!IsEmptyStr(rfca)) {
945 if (!IsEmptyStr(from)) {
946 snprintf(reply_to, sizeof(reply_to), "%s <%s>", from, rfca);
949 strcpy(reply_to, rfca);
953 if ((!IsEmptyStr(node))
954 && (strcasecmp(node, serv_info.serv_nodename))
955 && (strcasecmp(node, serv_info.serv_humannode)) ) {
956 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
960 snprintf(reply_to, sizeof(reply_to), "%s", from);
969 utf8ify_rfc822_string(m_cc);
970 utf8ify_rfc822_string(m_subject);
973 /** start msg buttons */
975 if (!printable_view) {
976 wprintf("<p id=\"msg%ld\" class=\"msgbuttons\" >\n",msgnum);
979 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
980 wprintf("<a href=\"display_enter");
981 if (WC->is_mailbox) {
982 wprintf("?replyquote=%ld", msgnum);
985 urlescputs(reply_to);
986 if (!IsEmptyStr(m_subject)) {
987 wprintf("?subject=");
988 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
989 urlescputs(m_subject);
991 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Reply"));
995 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
996 if (!WC->is_mailbox) {
997 wprintf("<a href=\"display_enter");
998 wprintf("?replyquote=%ld", msgnum);
1000 urlescputs(reply_to);
1001 if (!IsEmptyStr(m_subject)) {
1002 wprintf("?subject=");
1003 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
1004 urlescputs(m_subject);
1006 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyQuoted"));
1011 if (WC->wc_view == VIEW_MAILBOX) {
1012 wprintf("<a href=\"display_enter");
1013 wprintf("?replyquote=%ld", msgnum);
1015 urlescputs(reply_to);
1017 urlescputs(reply_all);
1018 if (!IsEmptyStr(m_subject)) {
1019 wprintf("?subject=");
1020 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
1021 urlescputs(m_subject);
1023 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyAll"));
1027 if (WC->wc_view == VIEW_MAILBOX) {
1028 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
1029 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
1030 urlescputs(m_subject);
1031 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Forward"));
1034 /** If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
1035 if ( (WC->is_room_aide) || (WC->is_mailbox) || (WC->room_flags2 & QR2_COLLABDEL) ) {
1037 wprintf("<a href=\"confirm_move_msg?msgid=%ld\"><span>[</span>%s<span>]</span></a> ",
1041 wprintf("<a href=\"delete_msg?msgid=%ld\" "
1042 "onClick=\"return confirm('%s');\">"
1043 "<span>[</span>%s<span>]</span> "
1044 "</a> ", msgnum, _("Delete this message?"), _("Delete")
1049 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'); \" >"
1050 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Headers"));
1054 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'); \" >"
1055 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Print"));
1061 if (!IsEmptyStr(m_cc)) {
1068 if (!IsEmptyStr(m_subject)) {
1069 wprintf("<p class=\"message_subject\">");
1070 wprintf(_("Subject:"));
1079 wprintf("<div class=\"message_content\">");
1082 * Learn the content type
1084 strcpy(mime_content_type, "text/plain");
1085 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1086 if (!strcmp(buf, "000")) {
1087 /* This is not necessarily an error condition. See bug #226. */
1090 if (!strncasecmp(buf, "X-Citadel-MSG4-Partnum:", 23)) {
1091 safestrncpy(msg4_partnum, &buf[23], sizeof(msg4_partnum));
1092 striplt(msg4_partnum);
1094 if (!strncasecmp(buf, "Content-type:", 13)) {
1096 safestrncpy(mime_content_type, &buf[13], sizeof(mime_content_type));
1097 striplt(mime_content_type);
1098 len = strlen(mime_content_type);
1099 for (i=0; i<len; ++i) {
1100 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1101 safestrncpy(mime_charset, &mime_content_type[i+8],
1102 sizeof mime_charset);
1105 for (i=0; i<len; ++i) {
1106 if (mime_content_type[i] == ';') {
1107 mime_content_type[i] = 0;
1111 len = strlen(mime_charset);
1112 for (i=0; i<len; ++i) {
1113 if (mime_charset[i] == ';') {
1114 mime_charset[i] = 0;
1121 /** Set up a character set conversion if we need to (and if we can) */
1123 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
1124 if ( (strcasecmp(mime_charset, "us-ascii"))
1125 && (strcasecmp(mime_charset, "UTF-8"))
1126 && (strcasecmp(mime_charset, ""))
1128 ic = ctdl_iconv_open("UTF-8", mime_charset);
1129 if (ic == (iconv_t)(-1) ) {
1130 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1131 __FILE__, __LINE__, mime_charset, strerror(errno));
1136 /** Messages in legacy Citadel variformat get handled thusly... */
1137 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1141 /** Boring old 80-column fixed format text gets handled this way... */
1142 else if ( (!strcasecmp(mime_content_type, "text/plain"))
1143 || (!strcasecmp(mime_content_type, "text")) ) {
1145 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1148 if ((len > 0) && buf[len-1] == '\n') buf[--len] = 0;
1149 if ((len > 0) && buf[len-1] == '\r') buf[--len] = 0;
1152 if (ic != (iconv_t)(-1) ) {
1154 ibuflen = strlen(ibuf);
1156 obuf = (char *) malloc(obuflen);
1158 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1159 osav[SIZ-obuflen] = 0;
1160 safestrncpy(buf, osav, sizeof buf);
1166 while ((!IsEmptyStr(buf)) && (isspace(buf[len-1])))
1169 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1170 wprintf("<blockquote>");
1172 } else if ((bq == 1) &&
1173 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1174 wprintf("</blockquote>");
1180 wprintf("</tt><br />\n");
1182 wprintf("</i><br />");
1185 else /** HTML is fun, but we've got to strip it first */
1186 if (!strcasecmp(mime_content_type, "text/html")) {
1187 output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
1190 /** Unknown weirdness */
1192 wprintf(_("I don't know how to display %s"), mime_content_type);
1193 wprintf("<br />\n", mime_content_type);
1194 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1197 ENDBODY: /* If there are attached submessages, display them now... */
1199 if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
1200 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1201 extract_token(buf, mime_submessages, i, '|', sizeof buf);
1202 /** use printable_view to suppress buttons */
1203 wprintf("<blockquote>");
1204 read_message(msgnum, 1, buf);
1205 wprintf("</blockquote>");
1210 /** Afterwards, offer links to download attachments 'n' such */
1211 if ( (num_attach_links > 0) && (!section[0]) ) {
1212 for (i=0; i<num_attach_links; ++i) {
1213 if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
1214 wprintf("%s", attach_links[i].html);
1219 /** Handler for vCard parts */
1220 if (!IsEmptyStr(vcard_partnum)) {
1221 part_source = load_mimepart(msgnum, vcard_partnum);
1222 if (part_source != NULL) {
1224 /** If it's my vCard I can edit it */
1225 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1226 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1227 || (WC->wc_view == VIEW_ADDRESSBOOK)
1229 wprintf("<a href=\"edit_vcard?"
1230 "msgnum=%ld?partnum=%s\">",
1231 msgnum, vcard_partnum);
1232 wprintf("[%s]</a>", _("edit"));
1235 /** In all cases, display the full card */
1236 display_vcard(part_source, 0, 1, NULL);
1240 /** Handler for calendar parts */
1241 if (!IsEmptyStr(cal_partnum)) {
1242 part_source = load_mimepart(msgnum, cal_partnum);
1243 if (part_source != NULL) {
1244 cal_process_attachment(part_source,
1245 msgnum, cal_partnum);
1254 wprintf("</div>\n");
1256 /** end everythingamundo table */
1257 if (!printable_view) {
1258 wprintf("</div>\n");
1261 if (num_attach_links > 0) {
1266 if (ic != (iconv_t)(-1) ) {
1275 * \brief Unadorned HTML output of an individual message, suitable
1276 * for placing in a hidden iframe, for printing, or whatever
1278 * \param msgnum_as_string Message number, as a string instead of as a long int
1280 void embed_message(char *msgnum_as_string) {
1283 msgnum = atol(msgnum_as_string);
1284 begin_ajax_response();
1285 read_message(msgnum, 0, "");
1286 end_ajax_response();
1291 * \brief Printable view of a message
1293 * \param msgnum_as_string Message number, as a string instead of as a long int
1295 void print_message(char *msgnum_as_string) {
1298 msgnum = atol(msgnum_as_string);
1299 output_headers(0, 0, 0, 0, 0, 0);
1301 wprintf("Content-type: text/html\r\n"
1303 "Connection: close\r\n",
1307 wprintf("\r\n\r\n<html>\n"
1308 "<head><title>Printable view</title></head>\n"
1309 "<body onLoad=\" window.print(); window.close(); \">\n"
1312 read_message(msgnum, 1, "");
1314 wprintf("\n</body></html>\n\n");
1321 * \brief Display a message's headers
1323 * \param msgnum_as_string Message number, as a string instead of as a long int
1325 void display_headers(char *msgnum_as_string) {
1329 msgnum = atol(msgnum_as_string);
1330 output_headers(0, 0, 0, 0, 0, 0);
1332 wprintf("Content-type: text/plain\r\n"
1334 "Connection: close\r\n",
1338 serv_printf("MSG2 %ld|3", msgnum);
1339 serv_getln(buf, sizeof buf);
1340 if (buf[0] == '1') {
1341 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1342 wprintf("%s\n", buf);
1352 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1353 * or 'reply quoted' operations.
1355 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1356 * in this function. Doing so would throw a JavaScript error in the
1357 * 'supplied text' argument to the editor.
1359 * \param msgnum Message number of the message we want to quote
1360 * \param forward_attachments Nonzero if we want attachments to be forwarded
1362 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1364 char mime_partnum[256];
1365 char mime_filename[256];
1366 char mime_content_type[256];
1367 char mime_charset[256];
1368 char mime_disposition[256];
1370 char *attachments = NULL;
1372 int num_attachments = 0;
1373 struct wc_attachment *att, *aptr;
1374 char m_subject[256];
1381 int format_type = 0;
1386 iconv_t ic = (iconv_t)(-1) ;
1387 char *ibuf; /**< Buffer of characters to be converted */
1388 char *obuf; /**< Buffer for converted characters */
1389 size_t ibuflen; /**< Length of input buffer */
1390 size_t obuflen; /**< Length of output buffer */
1391 char *osav; /**< Saved pointer to output buffer */
1397 strcpy(reply_to, "");
1398 strcpy(mime_content_type, "text/plain");
1399 strcpy(mime_charset, "us-ascii");
1401 serv_printf("MSG4 %ld", msgnum);
1402 serv_getln(buf, sizeof buf);
1403 if (buf[0] != '1') {
1404 wprintf(_("ERROR:"));
1405 wprintf("%s<br />", &buf[4]);
1409 strcpy(m_subject, "");
1411 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1412 if (!strcmp(buf, "000")) {
1413 wprintf("%s (3)", _("unexpected end of message"));
1416 if (include_headers) {
1417 if (!strncasecmp(buf, "nhdr=yes", 8))
1421 if (!strncasecmp(buf, "type=", 5))
1422 format_type = atoi(&buf[5]);
1423 if (!strncasecmp(buf, "from=", 5)) {
1424 strcpy(from, &buf[5]);
1425 wprintf(_("from "));
1427 utf8ify_rfc822_string(from);
1431 if (!strncasecmp(buf, "subj=", 5)) {
1432 strcpy(m_subject, &buf[5]);
1434 if ((!strncasecmp(buf, "hnod=", 5))
1435 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1436 wprintf("(%s) ", &buf[5]);
1438 if ((!strncasecmp(buf, "room=", 5))
1439 && (strcasecmp(&buf[5], WC->wc_roomname))
1440 && (!IsEmptyStr(&buf[5])) ) {
1442 wprintf("%s> ", &buf[5]);
1444 if (!strncasecmp(buf, "rfca=", 5)) {
1445 strcpy(rfca, &buf[5]);
1451 if (!strncasecmp(buf, "node=", 5)) {
1452 strcpy(node, &buf[5]);
1453 if ( ((WC->room_flags & QR_NETWORK)
1454 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1455 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1456 && (IsEmptyStr(rfca))
1458 wprintf("@%s ", &buf[5]);
1461 if (!strncasecmp(buf, "rcpt=", 5)) {
1463 strcpy(to, &buf[5]);
1465 utf8ify_rfc822_string(to);
1469 if (!strncasecmp(buf, "time=", 5)) {
1470 webcit_fmt_date(now, atol(&buf[5]), 0);
1471 wprintf("%s ", now);
1476 * Save attachment info for later. We can't start downloading them
1477 * yet because we're in the middle of a server transaction.
1479 if (!strncasecmp(buf, "part=", 5)) {
1480 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1483 sprintf(ptr, "%s%s\n",
1484 ((attachments != NULL) ? attachments : ""),
1489 lprintf(9, "attachments=<%s>\n", attachments);
1495 if (include_headers) {
1499 utf8ify_rfc822_string(m_subject);
1501 if (!IsEmptyStr(m_subject)) {
1502 wprintf(_("Subject:"));
1504 msgescputs(m_subject);
1515 * Learn the content type
1517 strcpy(mime_content_type, "text/plain");
1518 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1519 if (!strcmp(buf, "000")) {
1520 wprintf("%s (4)", _("unexpected end of message"));
1523 if (!strncasecmp(buf, "Content-type: ", 14)) {
1525 safestrncpy(mime_content_type, &buf[14],
1526 sizeof(mime_content_type));
1527 for (i=0; i<strlen(mime_content_type); ++i) {
1528 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1529 safestrncpy(mime_charset, &mime_content_type[i+8],
1530 sizeof mime_charset);
1533 len = strlen(mime_content_type);
1534 for (i=0; i<len; ++i) {
1535 if (mime_content_type[i] == ';') {
1536 mime_content_type[i] = 0;
1540 len = strlen(mime_charset);
1541 for (i=0; i<len; ++i) {
1542 if (mime_charset[i] == ';') {
1543 mime_charset[i] = 0;
1550 /** Set up a character set conversion if we need to (and if we can) */
1552 if ( (strcasecmp(mime_charset, "us-ascii"))
1553 && (strcasecmp(mime_charset, "UTF-8"))
1554 && (strcasecmp(mime_charset, ""))
1556 ic = ctdl_iconv_open("UTF-8", mime_charset);
1557 if (ic == (iconv_t)(-1) ) {
1558 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1559 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1564 /** Messages in legacy Citadel variformat get handled thusly... */
1565 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1569 /* Boring old 80-column fixed format text gets handled this way... */
1570 else if (!strcasecmp(mime_content_type, "text/plain")) {
1571 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1574 if (buf[len-1] == '\n') buf[--len] = 0;
1575 if (buf[len-1] == '\r') buf[--len] = 0;
1578 if (ic != (iconv_t)(-1) ) {
1582 obuf = (char *) malloc(obuflen);
1584 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1585 osav[SIZ-obuflen] = 0;
1586 safestrncpy(buf, osav, sizeof buf);
1592 while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
1595 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1596 wprintf("<blockquote>");
1598 } else if ((bq == 1) &&
1599 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1600 wprintf("</blockquote>");
1606 wprintf("</tt><br />");
1608 wprintf("</i><br />");
1611 /** HTML just gets escaped and stuffed back into the editor */
1612 else if (!strcasecmp(mime_content_type, "text/html")) {
1613 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1619 /** Unknown weirdness ... don't know how to handle this content type */
1621 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1625 /** end of body handler */
1628 * If there were attachments, we have to download them and insert them
1629 * into the attachment chain for the forwarded message we are composing.
1631 if ( (forward_attachments) && (num_attachments) ) {
1632 for (i=0; i<num_attachments; ++i) {
1633 extract_token(buf, attachments, i, '\n', sizeof buf);
1634 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1635 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1636 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1637 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1638 mime_length = extract_int(buf, 5);
1641 * tracing ... uncomment if necessary
1644 lprintf(9, "fwd filename: %s\n", mime_filename);
1645 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1646 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1647 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1648 lprintf(9, "fwd length : %d\n", mime_length);
1650 if ( (!strcasecmp(mime_disposition, "inline"))
1651 || (!strcasecmp(mime_disposition, "attachment")) ) {
1653 /* Create an attachment struct from this mime part... */
1654 att = malloc(sizeof(struct wc_attachment));
1655 memset(att, 0, sizeof(struct wc_attachment));
1656 att->length = mime_length;
1657 strcpy(att->content_type, mime_content_type);
1658 strcpy(att->filename, mime_filename);
1660 att->data = load_mimepart(msgnum, mime_partnum);
1662 /* And add it to the list. */
1663 if (WC->first_attachment == NULL) {
1664 WC->first_attachment = att;
1667 aptr = WC->first_attachment;
1668 while (aptr->next != NULL) aptr = aptr->next;
1677 if (ic != (iconv_t)(-1) ) {
1682 if (attachments != NULL) {
1688 * \brief Display one row in the mailbox summary view
1690 * \param num The row number to be displayed
1692 void display_summarized(int num) {
1695 wprintf("<tr id=\"m%ld\" style=\"font-weight:%s;\" "
1696 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1697 WC->summ[num].msgnum,
1698 (WC->summ[num].is_new ? "bold" : "normal"),
1699 WC->summ[num].msgnum
1702 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1704 escputs(WC->summ[num].subj);//////////////////////////////////TODO: QP DECODE
1707 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1708 escputs(WC->summ[num].from);
1711 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1712 webcit_fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1722 * \brief display the adressbook overview
1723 * \param msgnum the citadel message number
1724 * \param alpha what????
1726 void display_addressbook(long msgnum, char alpha) {
1728 char mime_partnum[SIZ];
1729 char mime_filename[SIZ];
1730 char mime_content_type[SIZ];
1731 char mime_disposition[SIZ];
1733 char vcard_partnum[SIZ];
1734 char *vcard_source = NULL;
1735 struct message_summary summ;
1737 memset(&summ, 0, sizeof(summ));
1738 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1740 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1742 serv_getln(buf, sizeof buf);
1743 if (buf[0] != '1') return;
1745 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1746 if (!strncasecmp(buf, "part=", 5)) {
1747 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1748 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1749 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1750 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1751 mime_length = extract_int(&buf[5], 5);
1753 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1754 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1755 strcpy(vcard_partnum, mime_partnum);
1761 if (!IsEmptyStr(vcard_partnum)) {
1762 vcard_source = load_mimepart(msgnum, vcard_partnum);
1763 if (vcard_source != NULL) {
1765 /** Display the summary line */
1766 display_vcard(vcard_source, alpha, 0, NULL);
1768 /** If it's my vCard I can edit it */
1769 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1770 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1771 || (WC->wc_view == VIEW_ADDRESSBOOK)
1773 wprintf("<a href=\"edit_vcard?"
1774 "msgnum=%ld?partnum=%s\">",
1775 msgnum, vcard_partnum);
1776 wprintf("[%s]</a>", _("edit"));
1788 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1789 * \param namebuf name to analyze, reverse if nescessary
1791 void lastfirst_firstlast(char *namebuf) {
1792 char firstname[SIZ];
1796 if (namebuf == NULL) return;
1797 if (strchr(namebuf, ';') != NULL) return;
1799 i = num_tokens(namebuf, ' ');
1802 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1803 remove_token(namebuf, i-1, ' ');
1804 strcpy(firstname, namebuf);
1805 sprintf(namebuf, "%s; %s", lastname, firstname);
1809 * \brief fetch what??? name
1810 * \param msgnum the citadel message number
1811 * \param namebuf where to put the name in???
1813 void fetch_ab_name(long msgnum, char *namebuf) {
1815 char mime_partnum[SIZ];
1816 char mime_filename[SIZ];
1817 char mime_content_type[SIZ];
1818 char mime_disposition[SIZ];
1820 char vcard_partnum[SIZ];
1821 char *vcard_source = NULL;
1823 struct message_summary summ;
1825 if (namebuf == NULL) return;
1826 strcpy(namebuf, "");
1828 memset(&summ, 0, sizeof(summ));
1829 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1831 sprintf(buf, "MSG0 %ld|0", msgnum); /** unfortunately we need the mime info now */
1833 serv_getln(buf, sizeof buf);
1834 if (buf[0] != '1') return;
1836 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1837 if (!strncasecmp(buf, "part=", 5)) {
1838 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1839 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1840 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1841 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1842 mime_length = extract_int(&buf[5], 5);
1844 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1845 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1846 strcpy(vcard_partnum, mime_partnum);
1852 if (!IsEmptyStr(vcard_partnum)) {
1853 vcard_source = load_mimepart(msgnum, vcard_partnum);
1854 if (vcard_source != NULL) {
1856 /* Grab the name off the card */
1857 display_vcard(vcard_source, 0, 0, namebuf);
1863 lastfirst_firstlast(namebuf);
1865 len = strlen(namebuf);
1866 for (i=0; i<len; ++i) {
1867 if (namebuf[i] != ';') return;
1869 strcpy(namebuf, _("(no name)"));
1875 * \brief Record compare function for sorting address book indices
1876 * \param ab1 adressbook one
1877 * \param ab2 adressbook two
1879 int abcmp(const void *ab1, const void *ab2) {
1881 (((const struct addrbookent *)ab1)->ab_name),
1882 (((const struct addrbookent *)ab2)->ab_name)
1888 * \brief Helper function for do_addrbook_view()
1889 * Converts a name into a three-letter tab label
1890 * \param tabbuf the tabbuffer to add name to
1891 * \param name the name to add to the tabbuffer
1893 void nametab(char *tabbuf, long len, char *name) {
1894 stresc(tabbuf, len, name, 0, 0);
1895 tabbuf[0] = toupper(tabbuf[0]);
1896 tabbuf[1] = tolower(tabbuf[1]);
1897 tabbuf[2] = tolower(tabbuf[2]);
1903 * \brief Render the address book using info we gathered during the scan
1904 * \param addrbook the addressbook to render
1905 * \param num_ab the number of the addressbook
1907 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1911 static int NAMESPERPAGE = 60;
1914 char tabfirst_label[64];
1916 char tablast_label[64];
1917 char this_tablabel[64];
1922 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1923 wprintf(_("This address book is empty."));
1924 wprintf("</i></div>\n");
1929 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1932 num_pages = (num_ab / NAMESPERPAGE) + 1;
1934 tablabels = malloc(num_pages * sizeof (char *));
1935 if (tablabels == NULL) {
1936 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1937 wprintf(_("An internal error has occurred."));
1938 wprintf("</i></div>\n");
1942 for (i=0; i<num_pages; ++i) {
1943 tabfirst = i * NAMESPERPAGE;
1944 tablast = tabfirst + NAMESPERPAGE - 1;
1945 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1946 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
1947 nametab(tablast_label, 64, addrbook[tablast].ab_name);
1948 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
1949 tablabels[i] = strdup(this_tablabel);
1952 tabbed_dialog(num_pages, tablabels);
1955 for (i=0; i<num_ab; ++i) {
1957 if ((i / NAMESPERPAGE) != page) { /* New tab */
1958 page = (i / NAMESPERPAGE);
1960 wprintf("</tr></table>\n");
1961 end_tab(page-1, num_pages);
1963 begin_tab(page, num_pages);
1964 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
1968 if ((displayed % 4) == 0) {
1969 if (displayed > 0) {
1973 wprintf("<tr bgcolor=\"#%s\">",
1974 (bg ? "DDDDDD" : "FFFFFF")
1980 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
1981 addrbook[i].ab_msgnum);
1982 wprintf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
1983 vcard_n_prettyize(addrbook[i].ab_name);
1984 escputs(addrbook[i].ab_name);
1985 wprintf("</a></td>\n");
1989 wprintf("</tr></table>\n");
1990 end_tab((num_pages-1), num_pages);
1992 for (i=0; i<num_pages; ++i) {
2001 * \brief load message pointers from the server
2002 * \param servcmd the citadel command to send to the citserver
2003 * \param with_headers what headers???
2005 int load_msg_ptrs(char *servcmd, int with_headers)
2016 int num_summ_alloc = 0;
2018 if (WC->summ != NULL) {
2023 num_summ_alloc = 100;
2025 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
2028 maxload = sizeof(WC->msgarr) / sizeof(long) ;
2030 serv_getln(buf, sizeof buf);
2031 if (buf[0] != '1') {
2034 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2035 if (nummsgs < maxload) {
2036 WC->msgarr[nummsgs] = extract_long(buf, 0);
2037 datestamp = extract_long(buf, 1);
2038 extract_token(fullname, buf, 2, '|', sizeof fullname);
2039 extract_token(nodename, buf, 3, '|', sizeof nodename);
2040 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
2041 extract_token(subject, buf, 5, '|', sizeof subject);
2045 if (nummsgs > num_summ_alloc) {
2046 num_summ_alloc *= 2;
2047 WC->summ = realloc(WC->summ,
2048 num_summ_alloc * sizeof(struct message_summary));
2052 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
2053 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
2054 safestrncpy(WC->summ[nummsgs-1].subj,
2055 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
2056 if (!IsEmptyStr(fullname)) {
2058 /** Handle senders with RFC2047 encoding */
2059 utf8ify_rfc822_string(fullname);
2061 safestrncpy(WC->summ[nummsgs-1].from,
2062 fullname, sizeof WC->summ[nummsgs-1].from);
2064 if (!IsEmptyStr(subject)) {
2066 /** Handle subjects with RFC2047 encoding */
2067 utf8ify_rfc822_string(subject);
2069 safestrncpy(WC->summ[nummsgs-1].subj, subject,
2070 sizeof WC->summ[nummsgs-1].subj);
2072 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
2073 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
2076 if (!IsEmptyStr(nodename)) {
2077 if ( ((WC->room_flags & QR_NETWORK)
2078 || ((strcasecmp(nodename, serv_info.serv_nodename)
2079 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
2081 strcat(WC->summ[nummsgs-1].from, " @ ");
2082 strcat(WC->summ[nummsgs-1].from, nodename);
2086 WC->summ[nummsgs-1].date = datestamp;
2089 /** Handle senders with RFC2047 encoding */
2090 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
2092 if (strlen(WC->summ[nummsgs-1].from) > 25) {
2093 strcpy(&WC->summ[nummsgs-1].from[22], "...");
2102 * \brief qsort() compatible function to compare two longs in descending order.
2104 * \param s1 first number to compare
2105 * \param s2 second number to compare
2107 int longcmp_r(const void *s1, const void *s2) {
2114 if (l1 > l2) return(-1);
2115 if (l1 < l2) return(+1);
2121 * \brief qsort() compatible function to compare two message summary structs by ascending subject.
2123 * \param s1 first item to compare
2124 * \param s2 second item to compare
2126 int summcmp_subj(const void *s1, const void *s2) {
2127 struct message_summary *summ1;
2128 struct message_summary *summ2;
2130 summ1 = (struct message_summary *)s1;
2131 summ2 = (struct message_summary *)s2;
2132 return strcasecmp(summ1->subj, summ2->subj);
2136 * \brief qsort() compatible function to compare two message summary structs by descending subject.
2138 * \param s1 first item to compare
2139 * \param s2 second item to compare
2141 int summcmp_rsubj(const void *s1, const void *s2) {
2142 struct message_summary *summ1;
2143 struct message_summary *summ2;
2145 summ1 = (struct message_summary *)s1;
2146 summ2 = (struct message_summary *)s2;
2147 return strcasecmp(summ2->subj, summ1->subj);
2151 * \brief qsort() compatible function to compare two message summary structs by ascending sender.
2153 * \param s1 first item to compare
2154 * \param s2 second item to compare
2156 int summcmp_sender(const void *s1, const void *s2) {
2157 struct message_summary *summ1;
2158 struct message_summary *summ2;
2160 summ1 = (struct message_summary *)s1;
2161 summ2 = (struct message_summary *)s2;
2162 return strcasecmp(summ1->from, summ2->from);
2166 * \brief qsort() compatible function to compare two message summary structs by descending sender.
2168 * \param s1 first item to compare
2169 * \param s2 second item to compare
2171 int summcmp_rsender(const void *s1, const void *s2) {
2172 struct message_summary *summ1;
2173 struct message_summary *summ2;
2175 summ1 = (struct message_summary *)s1;
2176 summ2 = (struct message_summary *)s2;
2177 return strcasecmp(summ2->from, summ1->from);
2181 * \brief qsort() compatible function to compare two message summary structs by ascending date.
2183 * \param s1 first item to compare
2184 * \param s2 second item to compare
2186 int summcmp_date(const void *s1, const void *s2) {
2187 struct message_summary *summ1;
2188 struct message_summary *summ2;
2190 summ1 = (struct message_summary *)s1;
2191 summ2 = (struct message_summary *)s2;
2193 if (summ1->date < summ2->date) return -1;
2194 else if (summ1->date > summ2->date) return +1;
2199 * \brief qsort() compatible function to compare two message summary structs by descending date.
2201 * \param s1 first item to compare
2202 * \param s2 second item to compare
2204 int summcmp_rdate(const void *s1, const void *s2) {
2205 struct message_summary *summ1;
2206 struct message_summary *summ2;
2208 summ1 = (struct message_summary *)s1;
2209 summ2 = (struct message_summary *)s2;
2211 if (summ1->date < summ2->date) return +1;
2212 else if (summ1->date > summ2->date) return -1;
2219 * \brief command loop for reading messages
2221 * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
2223 void readloop(char *oper)
2232 long *displayed_msgs = NULL;
2233 int num_displayed = 0;
2235 int is_addressbook = 0;
2236 int is_singlecard = 0;
2237 int is_calendar = 0;
2242 int lowest_displayed = (-1);
2243 int highest_displayed = 0;
2244 struct addrbookent *addrbook = NULL;
2246 char *sortby = NULL;
2247 char sortpref_name[128];
2248 char sortpref_value[128];
2249 char *subjsort_button;
2250 char *sendsort_button;
2251 char *datesort_button;
2252 int bbs_reverse = 0;
2253 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
2255 if (WCC->wc_view == VIEW_WIKI) {
2256 sprintf(buf, "wiki?room=%s?page=home", WCC->wc_roomname);
2261 startmsg = atol(bstr("startmsg"));
2262 maxmsgs = atoi(bstr("maxmsgs"));
2263 is_summary = atoi(bstr("is_summary"));
2264 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2266 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WCC->wc_roomname);
2267 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
2269 sortby = bstr("sortby");
2270 if ( (!IsEmptyStr(sortby)) && (strcasecmp(sortby, sortpref_value)) ) {
2271 set_preference(sortpref_name, sortby, 1);
2273 if (IsEmptyStr(sortby)) sortby = sortpref_value;
2276 if (IsEmptyStr(sortby)) sortby = "rdate";
2278 /** message board sort */
2279 if (!strcasecmp(sortby, "reverse")) {
2286 output_headers(1, 1, 1, 0, 0, 0);
2289 * When in summary mode, always show ALL messages instead of just
2290 * new or old. Otherwise, show what the user asked for.
2292 if (!strcmp(oper, "readnew")) {
2293 strcpy(cmd, "MSGS NEW");
2295 else if (!strcmp(oper, "readold")) {
2296 strcpy(cmd, "MSGS OLD");
2298 else if (!strcmp(oper, "do_search")) {
2299 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2302 strcpy(cmd, "MSGS ALL");
2305 if ((WCC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
2307 if (!strcmp(oper, "do_search")) {
2308 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2311 strcpy(cmd, "MSGS ALL");
2315 if ((WCC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2317 if (!strcmp(oper, "do_search")) {
2318 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2321 strcpy(cmd, "MSGS ALL");
2326 if (is_summary) { /**< fetch header summary */
2327 snprintf(cmd, sizeof cmd, "MSGS %s|%s||1",
2328 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2329 (!strcmp(oper, "do_search") ? bstr("query") : "")
2336 * Are we doing a summary view? If so, we need to know old messages
2337 * and new messages, so we can do that pretty boldface thing for the
2340 strcpy(old_msgs, "");
2343 serv_getln(buf, sizeof buf);
2344 if (buf[0] == '2') {
2345 strcpy(old_msgs, &buf[4]);
2349 is_singlecard = atoi(bstr("is_singlecard"));
2351 if (WCC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2353 strcpy(cmd, "MSGS ALL");
2356 if (WCC->wc_default_view == VIEW_TASKS) { /**< tasks */
2358 strcpy(cmd, "MSGS ALL");
2361 if (WCC->wc_default_view == VIEW_NOTES) { /**< notes */
2363 strcpy(cmd, "MSGS ALL");
2368 wprintf("<div align=center>%s</div>\n", _("Click on any note to edit it."));
2369 wprintf("<div id=\"new_notes_here\"></div>\n");
2372 nummsgs = load_msg_ptrs(cmd, is_summary);
2375 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2376 wprintf("<div align=\"center\"><br /><em>");
2377 if (!strcmp(oper, "readnew")) {
2378 wprintf(_("No new messages."));
2379 } else if (!strcmp(oper, "readold")) {
2380 wprintf(_("No old messages."));
2382 wprintf(_("No messages here."));
2384 wprintf("</em><br /></div>\n");
2391 for (a = 0; a < nummsgs; ++a) {
2392 /** Are you a new message, or an old message? */
2394 if (is_msg_in_mset(old_msgs, WCC->msgarr[a])) {
2395 WCC->summ[a].is_new = 0;
2398 WCC->summ[a].is_new = 1;
2404 if (startmsg == 0L) {
2406 startmsg = WCC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2409 startmsg = WCC->msgarr[0];
2414 if (!strcasecmp(sortby, "subject")) {
2415 qsort(WCC->summ, WCC->num_summ,
2416 sizeof(struct message_summary), summcmp_subj);
2418 else if (!strcasecmp(sortby, "rsubject")) {
2419 qsort(WCC->summ, WCC->num_summ,
2420 sizeof(struct message_summary), summcmp_rsubj);
2422 else if (!strcasecmp(sortby, "sender")) {
2423 qsort(WCC->summ, WCC->num_summ,
2424 sizeof(struct message_summary), summcmp_sender);
2426 else if (!strcasecmp(sortby, "rsender")) {
2427 qsort(WCC->summ, WCC->num_summ,
2428 sizeof(struct message_summary), summcmp_rsender);
2430 else if (!strcasecmp(sortby, "date")) {
2431 qsort(WCC->summ, WCC->num_summ,
2432 sizeof(struct message_summary), summcmp_date);
2434 else if (!strcasecmp(sortby, "rdate")) {
2435 qsort(WCC->summ, WCC->num_summ,
2436 sizeof(struct message_summary), summcmp_rdate);
2440 if (!strcasecmp(sortby, "subject")) {
2441 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2443 else if (!strcasecmp(sortby, "rsubject")) {
2444 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2447 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2450 if (!strcasecmp(sortby, "sender")) {
2451 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2453 else if (!strcasecmp(sortby, "rsender")) {
2454 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2457 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2460 if (!strcasecmp(sortby, "date")) {
2461 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2463 else if (!strcasecmp(sortby, "rdate")) {
2464 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2467 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2472 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2473 " document.onkeydown = CtdlMsgListKeyPress; "
2474 " if (document.layers) { "
2475 " document.captureEvents(Event.KEYPRESS); "
2480 /** note that Date and Delete are now in the same column */
2481 wprintf("<div id=\"message_list_hdr\">"
2482 "<div class=\"fix_scrollbar_bug\">"
2483 "<table cellspacing=0 style=\"width:100%%\">"
2486 wprintf("<th width=%d%%>%s %s</th>"
2487 "<th width=%d%%>%s %s</th>"
2488 "<th width=%d%%>%s %s"
2490 "<input type=\"submit\" name=\"delete_button\" id=\"delbutton\" "
2491 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2497 _("Subject"), subjsort_button,
2498 SENDER_COL_WIDTH_PCT,
2499 _("Sender"), sendsort_button,
2500 DATE_PLUS_BUTTONS_WIDTH_PCT,
2501 _("Date"), datesort_button,
2504 wprintf("</table></div></div>\n");
2506 wprintf("<div id=\"message_list\">"
2508 "<div class=\"fix_scrollbar_bug\">\n"
2510 "<table class=\"mailbox_summary\" id=\"summary_headers\" "
2511 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2517 * Set the "is_bbview" variable if it appears that we are looking at
2518 * a classic bulletin board view.
2520 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2521 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2526 * If we're not currently looking at ALL requested
2527 * messages, then display the selector bar
2530 /** begin bbview scroller */
2531 wprintf("<form name=\"msgomatictop\" class=\"selector_top\" > \n <p>");
2532 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2534 wprintf("<select name=\"whichones\" size=\"1\" "
2535 "OnChange=\"location.href=msgomatictop.whichones.options"
2536 "[selectedIndex].value\">\n");
2539 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2541 lo = b - maxmsgs + 2;
2543 wprintf("<option %s value="
2548 "%d-%d</option> \n",
2549 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2558 for (b=0; b<nummsgs; b = b + maxmsgs) {
2560 hi = b + maxmsgs + 1;
2561 if (hi > nummsgs) hi = nummsgs;
2562 wprintf("<option %s value="
2567 "%d-%d</option> \n",
2568 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2577 wprintf("<option value=\"%s?startmsg=%ld"
2578 "?maxmsgs=9999999?is_summary=%d\">",
2580 WCC->msgarr[0], is_summary);
2582 wprintf("</option>");
2583 wprintf("</select> ");
2584 wprintf(_("of %d messages."), nummsgs);
2586 /** forward/reverse */
2587 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2588 "OnChange=\"location.href='%s?sortby=forward'\"",
2589 (bbs_reverse ? "" : "checked"),
2593 wprintf(_("oldest to newest"));
2594 wprintf(" ");
2596 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2597 "OnChange=\"location.href='%s?sortby=reverse'\"",
2598 (bbs_reverse ? "checked" : ""),
2602 wprintf(_("newest to oldest"));
2605 wprintf("</p></form>\n");
2606 /** end bbview scroller */
2611 wprintf ("<script src=\"/static/dragdrop.js\" type=\"text/javascript\"></script>\n");
2616 for (a = 0; a < nummsgs; ++a) {
2617 if ((WCC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2619 /** Display the message */
2621 display_summarized(a);
2623 else if (is_addressbook) {
2624 fetch_ab_name(WCC->msgarr[a], buf);
2626 addrbook = realloc(addrbook,
2627 (sizeof(struct addrbookent) * num_ab) );
2628 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2629 sizeof(addrbook[num_ab-1].ab_name));
2630 addrbook[num_ab-1].ab_msgnum = WCC->msgarr[a];
2632 else if (is_calendar) {
2633 display_calendar(WCC->msgarr[a]);
2635 else if (is_tasks) {
2636 display_task(WCC->msgarr[a]);
2638 else if (is_notes) {
2639 display_note(WCC->msgarr[a]);
2642 if (displayed_msgs == NULL) {
2643 displayed_msgs = malloc(sizeof(long) *
2644 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2646 displayed_msgs[num_displayed] = WCC->msgarr[a];
2649 if (lowest_displayed < 0) lowest_displayed = a;
2650 highest_displayed = a;
2657 if (displayed_msgs != NULL) {
2659 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2662 /** if we do a split bbview in the future, begin messages div here */
2664 for (a=0; a<num_displayed; ++a) {
2665 read_message(displayed_msgs[a], 0, "");
2668 /** if we do a split bbview in the future, end messages div here */
2670 free(displayed_msgs);
2671 displayed_msgs = NULL;
2676 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2677 wprintf("</div>"); /**< end of 'message_list' div */
2679 /** Here's the grab-it-to-resize-the-message-list widget */
2680 wprintf("<div id=\"resize_msglist\" "
2681 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2682 "<div class=\"fix_scrollbar_bug\"> <hr>"
2686 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2690 * Bump these because although we're thinking in zero base, the user
2691 * is a drooling idiot and is thinking in one base.
2694 ++highest_displayed;
2697 * If we're not currently looking at ALL requested
2698 * messages, then display the selector bar
2701 /** begin bbview scroller */
2702 wprintf("<form name=\"msgomatic\" class=\"selector_bottom\" > \n <p>");
2703 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2705 wprintf("<select name=\"whichones\" size=\"1\" "
2706 "OnChange=\"location.href=msgomatic.whichones.options"
2707 "[selectedIndex].value\">\n");
2710 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2712 lo = b - maxmsgs + 2;
2714 wprintf("<option %s value="
2719 "%d-%d</option> \n",
2720 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2729 for (b=0; b<nummsgs; b = b + maxmsgs) {
2731 hi = b + maxmsgs + 1;
2732 if (hi > nummsgs) hi = nummsgs;
2733 wprintf("<option %s value="
2738 "%d-%d</option> \n",
2739 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2748 wprintf("<option value=\"%s?startmsg=%ld"
2749 "?maxmsgs=9999999?is_summary=%d\">",
2751 WCC->msgarr[0], is_summary);
2753 wprintf("</option>");
2754 wprintf("</select> ");
2755 wprintf(_("of %d messages."), nummsgs);
2757 /** forward/reverse */
2758 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2759 "OnChange=\"location.href='%s?sortby=forward'\"",
2760 (bbs_reverse ? "" : "checked"),
2764 wprintf(_("oldest to newest"));
2765 wprintf(" ");
2766 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2767 "OnChange=\"location.href='%s?sortby=reverse'\"",
2768 (bbs_reverse ? "checked" : ""),
2772 wprintf(_("newest to oldest"));
2775 wprintf("</p></form>\n");
2776 /** end bbview scroller */
2781 // wprintf ("</div>\n");
2782 wprintf ("<div id=\"wastebin\" align=middle>Drop notes here to remove them.</div>\n");
2783 wprintf ("<script type=\"text/javascript\">\n");
2784 // wprintf ("//<![CDATA[\n");
2785 wprintf ("Droppables.add(\"wastebin\",\n");
2787 wprintf ("\t\taccept:'notes',\n");
2788 wprintf ("\t\tonDrop:function(element)\n");
2789 wprintf ("\t\t{\n");
2790 wprintf ("\t\t\tElement.hide(element);\n");
2791 wprintf ("\t\t\tnew Ajax.Updater('notes', 'delnote',\n");
2792 wprintf ("\t\t\t{\n");
2793 wprintf ("\t\t\t\tasynchronous:true,\n");
2794 wprintf ("\t\t\t\tevalScripts:true,\n");
2795 wprintf ("\t\t\t\tonComplete:function(request)\n");
2796 wprintf ("\t\t\t\t{\n");
2797 wprintf ("\t\t\t\t\tElement.hide('indicator')\n");
2798 wprintf ("\t\t\t\t},\n");
2799 wprintf ("\t\t\t\tonLoading:function(request)\n");
2800 wprintf ("\t\t\t\t{\n");
2801 wprintf ("\t\t\t\t\tElement.show('indicator')\n");
2802 wprintf ("\t\t\t\t},\n");
2803 wprintf ("\t\t\t\tparameters:'id=' + encodeURIComponent(element.id)\n");
2804 wprintf ("\t\t\t})\n");
2805 wprintf ("\t\t}\n");
2807 // wprintf ("//]]>\n");
2808 wprintf ("</script>\n");
2815 do_tasks_view(); /** Render the task list */
2819 do_calendar_view(); /** Render the calendar */
2822 if (is_addressbook) {
2823 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2826 /** Note: wDumpContent() will output one additional </div> tag. */
2827 wprintf("</div>\n"); /** end of 'content' div */
2830 /** free the summary */
2831 if (WCC->summ != NULL) {
2836 if (addrbook != NULL) free(addrbook);
2841 * \brief Back end for post_message()
2842 * ... this is where the actual message gets transmitted to the server.
2844 void post_mime_to_server(void) {
2846 int is_multipart = 0;
2848 struct wc_attachment *att;
2850 size_t encoded_length;
2851 size_t encoded_strlen;
2853 /** RFC2045 requires this, and some clients look for it... */
2854 serv_puts("MIME-Version: 1.0");
2855 serv_puts("X-Mailer: " PACKAGE_STRING);
2857 /** If there are attachments, we have to do multipart/mixed */
2858 if (WC->first_attachment != NULL) {
2863 sprintf(boundary, "Citadel--Multipart--%s--%04x--%04x",
2864 serv_info.serv_fqdn,
2869 /** Remember, serv_printf() appends an extra newline */
2870 serv_printf("Content-type: multipart/mixed; "
2871 "boundary=\"%s\"\n", boundary);
2872 serv_printf("This is a multipart message in MIME format.\n");
2873 serv_printf("--%s", boundary);
2876 serv_puts("Content-type: text/html; charset=utf-8");
2877 serv_puts("Content-Transfer-Encoding: quoted-printable");
2879 serv_puts("<html><body>\r\n");
2880 text_to_server_qp(bstr("msgtext")); /** Transmit message in quoted-printable encoding */
2881 serv_puts("</body></html>\r\n");
2885 /** Add in the attachments */
2886 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2888 encoded_length = ((att->length * 150) / 100);
2889 encoded = malloc(encoded_length);
2890 if (encoded == NULL) break;
2891 encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1);
2893 serv_printf("--%s", boundary);
2894 serv_printf("Content-type: %s", att->content_type);
2895 serv_printf("Content-disposition: attachment; "
2896 "filename=\"%s\"", att->filename);
2897 serv_puts("Content-transfer-encoding: base64");
2899 serv_write(encoded, encoded_strlen);
2904 serv_printf("--%s--", boundary);
2912 * \brief Post message (or don't post message)
2914 * Note regarding the "dont_post" variable:
2915 * A random value (actually, it's just a timestamp) is inserted as a hidden
2916 * field called "postseq" when the display_enter page is generated. This
2917 * value is checked when posting, using the static variable dont_post. If a
2918 * user attempts to post twice using the same dont_post value, the message is
2919 * discarded. This prevents the accidental double-saving of the same message
2920 * if the user happens to click the browser "back" button.
2922 void post_message(void)
2925 char encoded_subject[1024];
2926 static long dont_post = (-1L);
2927 struct wc_attachment *att, *aptr;
2928 int is_anonymous = 0;
2931 if (!IsEmptyStr(bstr("force_room"))) {
2932 gotoroom(bstr("force_room"));
2935 display_name = bstr("display_name");
2936 if (!strcmp(display_name, "__ANONYMOUS__")) {
2941 if (WC->upload_length > 0) {
2943 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WC->upload_length);
2944 /** There's an attachment. Save it to this struct... */
2945 att = malloc(sizeof(struct wc_attachment));
2946 memset(att, 0, sizeof(struct wc_attachment));
2947 att->length = WC->upload_length;
2948 strcpy(att->content_type, WC->upload_content_type);
2949 strcpy(att->filename, WC->upload_filename);
2952 /** And add it to the list. */
2953 if (WC->first_attachment == NULL) {
2954 WC->first_attachment = att;
2957 aptr = WC->first_attachment;
2958 while (aptr->next != NULL) aptr = aptr->next;
2963 * Mozilla sends a simple filename, which is what we want,
2964 * but Satan's Browser sends an entire pathname. Reduce
2965 * the path to just a filename if we need to.
2967 while (num_tokens(att->filename, '/') > 1) {
2968 remove_token(att->filename, 0, '/');
2970 while (num_tokens(att->filename, '\\') > 1) {
2971 remove_token(att->filename, 0, '\\');
2975 * Transfer control of this memory from the upload struct
2976 * to the attachment struct.
2978 att->data = WC->upload;
2979 WC->upload_length = 0;
2985 if (!IsEmptyStr(bstr("cancel_button"))) {
2986 sprintf(WC->ImportantMessage,
2987 _("Cancelled. Message was not posted."));
2988 } else if (!IsEmptyStr(bstr("attach_button"))) {
2991 } else if (atol(bstr("postseq")) == dont_post) {
2992 sprintf(WC->ImportantMessage,
2993 _("Automatically cancelled because you have already "
2994 "saved this message."));
2996 webcit_rfc2047encode(encoded_subject, sizeof encoded_subject, bstr("subject"));
2997 sprintf(buf, "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s",
3005 bstr("my_email_addr")
3008 serv_getln(buf, sizeof buf);
3009 if (buf[0] == '4') {
3010 post_mime_to_server();
3011 if ( (!IsEmptyStr(bstr("recp")))
3012 || (!IsEmptyStr(bstr("cc" )))
3013 || (!IsEmptyStr(bstr("bcc" )))
3015 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
3018 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
3020 dont_post = atol(bstr("postseq"));
3022 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
3023 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3029 free_attachments(WC);
3032 * We may have been supplied with instructions regarding the location
3033 * to which we must return after posting. If found, go there.
3035 if (!IsEmptyStr(bstr("return_to"))) {
3036 http_redirect(bstr("return_to"));
3039 * If we were editing a page in a wiki room, go to that page now.
3041 else if (!IsEmptyStr(bstr("wikipage"))) {
3042 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
3046 * Otherwise, just go to the "read messages" loop.
3049 readloop("readnew");
3057 * \brief display the message entry screen
3059 void display_enter(void)
3065 struct wc_attachment *att;
3066 int recipient_required = 0;
3067 int subject_required = 0;
3068 int recipient_bad = 0;
3070 int is_anonymous = 0;
3071 long existing_page = (-1L);
3075 if (!IsEmptyStr(bstr("force_room"))) {
3076 gotoroom(bstr("force_room"));
3079 display_name = bstr("display_name");
3080 if (!strcmp(display_name, "__ANONYMOUS__")) {
3085 /** First test to see whether this is a room that requires recipients to be entered */
3086 serv_puts("ENT0 0");
3087 serv_getln(buf, sizeof buf);
3089 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
3090 recipient_required = 1;
3092 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3093 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3094 readloop("readnew");
3098 /* Is the server strongly recommending that the user enter a message subject? */
3099 if ((buf[3] != '\0') && (buf[4] != '\0')) {
3100 subject_required = extract_int(&buf[4], 1);
3104 * Are we perhaps in an address book view? If so, then an "enter
3105 * message" command really means "add new entry."
3107 if (WC->wc_default_view == VIEW_ADDRESSBOOK) {
3108 do_edit_vcard(-1, "", "", WC->wc_roomname);
3112 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
3114 * Are we perhaps in a calendar room? If so, then an "enter
3115 * message" command really means "add new calendar item."
3117 if (WC->wc_default_view == VIEW_CALENDAR) {
3118 display_edit_event();
3123 * Are we perhaps in a tasks view? If so, then an "enter
3124 * message" command really means "add new task."
3126 if (WC->wc_default_view == VIEW_TASKS) {
3127 display_edit_task();
3133 * Otherwise proceed normally.
3134 * Do a custom room banner with no navbar...
3136 output_headers(1, 1, 2, 0, 0, 0);
3137 wprintf("<div id=\"banner\">\n");
3138 embed_room_banner(NULL, navbar_none);
3139 wprintf("</div>\n");
3140 wprintf("<div id=\"content\">\n"
3141 "<div class=\"fix_scrollbar_bug message \">");
3143 /** Now check our actual recipients if there are any */
3144 if (recipient_required) {
3145 sprintf(buf, "ENT0 0|%s|%d|0||%s||%s|%s|%s",
3149 bstr("cc"), bstr("bcc"), bstr("wikipage"));
3151 serv_getln(buf, sizeof buf);
3153 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
3154 if (!IsEmptyStr(bstr("recp")) &&
3155 !IsEmptyStr(bstr("cc" )) &&
3156 !IsEmptyStr(bstr("bcc" ))) {
3160 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3161 wprintf("<em>%s</em><br />\n", &buf[4]);
3166 /** If we got this far, we can display the message entry screen. */
3168 /** begin message entry screen */
3170 "enctype=\"multipart/form-data\" "
3172 "accept-charset=\"UTF-8\" "
3174 "name=\"enterform\""
3176 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
3177 if (WC->wc_view == VIEW_WIKI) {
3178 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
3180 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
3181 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
3182 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
3183 escputs(WC->wc_roomname);
3186 /** submit or cancel buttons */
3187 wprintf("<p class=\"send_edit_msg\">");
3188 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3189 if (recipient_required) {
3190 wprintf(_("Send message"));
3192 wprintf(_("Post message"));
3195 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3200 wprintf("<img src=\"static/newmess3_24x.gif\" class=\"imgedit\">");
3201 wprintf(" "); /** header bar */
3202 webcit_fmt_date(buf, now, 0);
3204 wprintf("\n"); /** header bar */
3206 wprintf("<table width=\"100%%\" class=\"edit_msg_table\">");
3208 wprintf("<th><label for=\"from_id\" > ");
3209 wprintf(_(" <I>from</I> "));
3210 wprintf("</label></th>");
3212 wprintf("<td colspan=\"2\">");
3214 /* Allow the user to select any of his valid screen names */
3216 wprintf("<select name=\"display_name\" size=1 id=\"from_id\">\n");
3219 serv_getln(buf, sizeof buf);
3220 if (buf[0] == '1') {
3221 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3222 wprintf("<option %s value=\"",
3223 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
3228 wprintf("</option>\n");
3232 if (WC->room_flags & QR_ANONOPT) {
3233 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
3234 ((!strcasecmp(bstr("__ANONYMOUS__"), WC->wc_fullname)) ? "selected" : ""),
3239 wprintf("</select>\n");
3241 /* If this is an email (not a post), allow the user to select any of his
3242 * valid email addresses.
3244 if (recipient_required) {
3246 serv_getln(buf, sizeof buf);
3247 if (buf[0] == '1') {
3248 wprintf("<select name=\"my_email_addr\" size=1>\n");
3249 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3250 wprintf("<option value=\"");
3254 wprintf("></option>\n");
3256 wprintf("</select>\n");
3260 wprintf(_(" <I>in</I> "));
3261 escputs(WC->wc_roomname);
3263 wprintf("</td></tr>");
3265 if (recipient_required) {
3269 wprintf("<tr><th><label for=\"recp_id\"> ");
3271 wprintf("</label></th>"
3272 "<td><input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
3273 ccraw = bstr("recp");
3274 len = strlen(ccraw);
3275 copy = (char*) malloc(len * 2 + 1);
3276 memcpy(copy, ccraw, len + 1);
3278 utf8ify_rfc822_string(copy);
3282 wprintf("\" size=45 maxlength=1000 />");
3283 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
3284 wprintf("</td><td rowspan=\"3\" align=\"left\" valign=\"top\">");
3286 /** Pop open an address book -- begin **/
3288 "<a href=\"javascript:PopOpenAddressBook('recp_id|%s|cc_id|%s|bcc_id|%s');\" "
3290 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
3292 _("To:"), _("CC:"), _("BCC:"),
3293 _("Contacts"), _("Contacts")
3295 /** Pop open an address book -- end **/
3297 wprintf("</td></tr>");
3299 wprintf("<tr><th><label for=\"cc_id\"> ");
3301 wprintf("</label></th>"
3302 "<td><input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
3304 len = strlen(ccraw);
3305 copy = (char*) malloc(len * 2 + 1);
3306 memcpy(copy, ccraw, len + 1);
3308 utf8ify_rfc822_string(copy);
3312 wprintf("\" size=45 maxlength=1000 />");
3313 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
3314 wprintf("</td></tr>");
3316 wprintf("<tr><th><label for=\"bcc_id\"> ");
3318 wprintf("</label></th>"
3319 "<td><input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
3320 ccraw = bstr("bcc");
3321 len = strlen(ccraw);
3322 copy = (char*) malloc(len * 2 + 1);
3323 memcpy(copy, ccraw, len + 1);
3325 utf8ify_rfc822_string(copy);
3329 wprintf("\" size=45 maxlength=1000 />");
3330 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
3331 wprintf("</td></tr>");
3333 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
3334 wprintf("<script type=\"text/javascript\"> \n"
3335 " activate_entmsg_autocompleters(); \n"
3341 wprintf("<tr><th><label for=\"subject_id\" > ");
3342 if (recipient_required || subject_required) {
3343 wprintf(_("Subject:"));
3346 wprintf(_("Subject (optional):"));
3348 wprintf("</label></th>"
3349 "<td colspan=\"2\">"
3350 "<input type=\"text\" name=\"subject\" id=\"subject_id\" value=\"");
3351 escputs(bstr("subject"));
3352 wprintf("\" size=45 maxlength=70>\n");
3353 wprintf("</td></tr>");
3355 wprintf("<tr><td colspan=\"3\">\n");
3357 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
3359 /** If we're continuing from a previous edit, put our partially-composed message back... */
3360 msgescputs(bstr("msgtext"));
3362 /* If we're forwarding a message, insert it here... */
3363 if (atol(bstr("fwdquote")) > 0L) {
3364 wprintf("<br><div align=center><i>");
3365 wprintf(_("--- forwarded message ---"));
3366 wprintf("</i></div><br>");
3367 pullquote_message(atol(bstr("fwdquote")), 1, 1);
3370 /** If we're replying quoted, insert the quote here... */
3371 else if (atol(bstr("replyquote")) > 0L) {
3374 pullquote_message(atol(bstr("replyquote")), 0, 1);
3375 wprintf("</blockquote><br>");
3378 /** If we're editing a wiki page, insert the existing page here... */
3379 else if (WC->wc_view == VIEW_WIKI) {
3380 safestrncpy(buf, bstr("wikipage"), sizeof buf);
3381 str_wiki_index(buf);
3382 existing_page = locate_message_by_uid(buf);
3383 if (existing_page >= 0L) {
3384 pullquote_message(existing_page, 1, 0);
3388 /** Insert our signature if appropriate... */
3389 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
3390 get_preference("use_sig", buf, sizeof buf);
3391 if (!strcasecmp(buf, "yes")) {
3393 get_preference("signature", ebuf, sizeof ebuf);
3394 euid_unescapize(buf, ebuf);
3395 wprintf("<br>--<br>");
3397 for (i=0; i<len; ++i) {
3398 if (buf[i] == '\n') {
3401 else if (buf[i] == '<') {
3404 else if (buf[i] == '>') {
3407 else if (buf[i] == '&') {
3410 else if (buf[i] == '\"') {
3413 else if (buf[i] == '\'') {
3416 else if (isprint(buf[i])) {
3417 wprintf("%c", buf[i]);
3423 wprintf("</textarea>\n");
3425 /** Make sure we only insert our signature once */
3426 /** We don't care if it was there or not before, it needs to be there now. */
3427 wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
3430 * The following template embeds the TinyMCE richedit control, and automatically
3431 * transforms the textarea into a richedit textarea.
3433 do_template("richedit");
3435 /** Enumerate any attachments which are already in place... */
3436 wprintf("<div class=\"attachment buttons\"><img src=\"static/diskette_24x.gif\" class=\"imgedit\" > ");
3437 wprintf(_("Attachments:"));
3439 wprintf("<select name=\"which_attachment\" size=1>");
3440 for (att = WC->first_attachment; att != NULL; att = att->next) {
3441 wprintf("<option value=\"");
3442 urlescputs(att->filename);
3444 escputs(att->filename);
3445 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3446 wprintf("</option>\n");
3448 wprintf("</select>");
3450 /** Now offer the ability to attach additional files... */
3451 wprintf(" ");
3452 wprintf(_("Attach file:"));
3453 wprintf(" <input name=\"attachfile\" class=\"attachfile\" "
3454 "size=16 type=\"file\">\n "
3455 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3456 wprintf("</div>"); /* End of "attachment buttons" div */
3459 wprintf("</td></tr></table>");
3461 wprintf("</form>\n");
3462 wprintf("</div>\n"); /* end of "fix_scrollbar_bug" div */
3464 /* NOTE: address_book_popup() will close the "content" div. Don't close it here. */
3465 DONE: address_book_popup();
3471 * \brief delete a message
3473 void delete_msg(void)
3478 msgid = atol(bstr("msgid"));
3480 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3481 serv_printf("DELE %ld", msgid);
3483 else { /** Otherwise move it to Trash */
3484 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3487 serv_getln(buf, sizeof buf);
3488 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3490 readloop("readnew");
3495 * \brief move a message to another folder
3502 msgid = atol(bstr("msgid"));
3504 if (!IsEmptyStr(bstr("move_button"))) {
3505 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3507 serv_getln(buf, sizeof buf);
3508 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3510 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3513 readloop("readnew");
3521 * \brief Confirm move of a message
3523 void confirm_move_msg(void)
3529 msgid = atol(bstr("msgid"));
3532 output_headers(1, 1, 2, 0, 0, 0);
3533 wprintf("<div id=\"banner\">\n");
3535 wprintf(_("Confirm move of message"));
3537 wprintf("</div>\n");
3539 wprintf("<div id=\"content\" class=\"service\">\n");
3541 wprintf("<CENTER>");
3543 wprintf(_("Move this message to:"));
3544 wprintf("<br />\n");
3546 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3547 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
3548 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3550 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3552 serv_getln(buf, sizeof buf);
3553 if (buf[0] == '1') {
3554 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3555 extract_token(targ, buf, 0, '|', sizeof targ);
3556 wprintf("<OPTION>");
3561 wprintf("</SELECT>\n");
3562 wprintf("<br />\n");
3564 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3566 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3567 wprintf("</form></CENTER>\n");
3569 wprintf("</CENTER>\n");