5 * \defgroup MsgDisp Functions which deal with the fetching and displaying of messages.
6 * \ingroup WebcitDisplayItems
11 #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) {
64 char *start, *end, *next, *nextend, *ptr;
69 iconv_t ic = (iconv_t)(-1) ;
70 char *ibuf; /**< Buffer of characters to be converted */
71 char *obuf; /**< Buffer for converted characters */
72 size_t ibuflen; /**< Length of input buffer */
73 size_t obuflen; /**< Length of output buffer */
74 char *isav; /**< Saved pointer to input buffer */
75 char *osav; /**< Saved pointer to output buffer */
78 int illegal_non_rfc2047_encoding = 0;
80 /** Sometimes, badly formed messages contain strings which were simply
81 * written out directly in some foreign character set instead of
82 * using RFC2047 encoding. This is illegal but we will attempt to
83 * handle it anyway by converting from a user-specified default
84 * charset to UTF-8 if we see any nonprintable characters.
87 for (i=0; i<len; ++i) {
88 if ((buf[i] < 32) || (buf[i] > 126)) {
89 illegal_non_rfc2047_encoding = 1;
90 i = len; ///< take a shortcut, it won't be more than one.
93 if (illegal_non_rfc2047_encoding) {
94 char default_header_charset[128];
95 get_preference("default_header_charset", default_header_charset, sizeof default_header_charset);
96 if ( (strcasecmp(default_header_charset, "UTF-8")) && (strcasecmp(default_header_charset, "us-ascii")) ) {
97 ic = ctdl_iconv_open("UTF-8", default_header_charset);
98 if (ic != (iconv_t)(-1) ) {
101 safestrncpy(ibuf, buf, 1024);
102 ibuflen = strlen(ibuf);
104 obuf = (char *) malloc(obuflen);
106 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
107 osav[1024-obuflen] = 0;
116 /* pre evaluate the first pair */
117 nextend = end = NULL;
119 start = strstr(buf, "=?");
121 end = strstr(start, "?=");
123 while ((start != NULL) && (end != NULL))
125 next = strstr(end, "=?");
127 nextend = strstr(next, "?=");
131 /* did we find two partitions */
132 if ((next != NULL) &&
136 while ((ptr < next) &&
142 /* did we find a gab just filled with blanks? */
147 len - (next - start));
149 /* now terminate the gab at the end */
150 delta = (next - end) - 2;
154 /* move next to its new location. */
159 /* our next-pair is our new first pair now. */
164 /** Now we handle foreign character sets properly encoded
167 while (start=strstr(buf, "=?"), end=strstr(buf, "?="),
168 ((start != NULL) && (end != NULL) && (end > start)) )
170 extract_token(charset, start, 1, '?', sizeof charset);
171 extract_token(encoding, start, 2, '?', sizeof encoding);
172 extract_token(istr, start, 3, '?', sizeof istr);
176 if (!strcasecmp(encoding, "B")) { /**< base64 */
177 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
179 else if (!strcasecmp(encoding, "Q")) { /**< quoted-printable */
187 if (istr[pos] == '_') istr[pos] = ' ';
191 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, len);
194 strcpy(ibuf, istr); /**< unknown encoding */
195 ibuflen = strlen(istr);
198 ic = ctdl_iconv_open("UTF-8", charset);
199 if (ic != (iconv_t)(-1) ) {
201 obuf = (char *) malloc(obuflen);
203 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
204 osav[1024-obuflen] = 0;
209 remove_token(end, 0, '?');
210 remove_token(end, 0, '?');
211 remove_token(end, 0, '?');
212 remove_token(end, 0, '?');
213 strcpy(end, &end[1]);
215 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
224 remove_token(end, 0, '?');
225 remove_token(end, 0, '?');
226 remove_token(end, 0, '?');
227 remove_token(end, 0, '?');
228 strcpy(end, &end[1]);
230 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
237 * Since spammers will go to all sorts of absurd lengths to get their
238 * messages through, there are LOTS of corrupt headers out there.
239 * So, prevent a really badly formed RFC2047 header from throwing
240 * this function into an infinite loop.
243 if (passes > 20) return;
253 * \brief RFC2047-encode a header field if necessary.
254 * If no non-ASCII characters are found, the string
255 * will be copied verbatim without encoding.
257 * \param target Target buffer.
258 * \param maxlen Maximum size of target buffer.
259 * \param source Source string to be encoded.
261 void webcit_rfc2047encode(char *target, int maxlen, char *source)
263 int need_to_encode = 0;
267 if (target == NULL) return;
268 len = strlen(source);
269 for (i=0; i<len; ++i) {
270 if ((source[i] < 32) || (source[i] > 126)) {
272 i = len; ///< shortcut. won't become more than 1
276 if (!need_to_encode) {
277 safestrncpy(target, source, maxlen);
281 strcpy(target, "=?UTF-8?Q?");
282 for (i=0; i<len; ++i) {
283 ch = (unsigned char) source[i];
284 if ((ch < 32) || (ch > 126) || (ch == 61)) {
285 sprintf(&target[strlen(target)], "=%02X", ch);
288 sprintf(&target[strlen(target)], "%c", ch);
292 strcat(target, "?=");
299 * \brief Look for URL's embedded in a buffer and make them linkable. We use a
300 * target window in order to keep the BBS session in its own window.
301 * \param buf the message buffer
306 char *start, *end, *pos;
313 for (pos = buf; (pos < end) && (start == NULL); ++pos) {
314 if (!strncasecmp(pos, "http://", 7))
316 if (!strncasecmp(pos, "ftp://", 6))
323 for (pos = buf+len; pos > start; --pos) {
324 if ( (!isprint(*pos))
343 strncpy(urlbuf, start, end - start);
344 urlbuf[end - start] = '\0';
347 strncpy(outbuf, buf, start - buf );
348 sprintf(&outbuf[start-buf], "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
349 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
351 if ( strlen(outbuf) < 250 )
357 * \brief Turn a vCard "n" (name) field into something displayable.
358 * \param name the name field to convert
360 void vcard_n_prettyize(char *name)
365 original_name = strdup(name);
366 len = strlen(original_name);
367 for (i=0; i<5; ++i) {
369 if (original_name[len-1] == ' ') {
370 original_name[--len] = 0;
372 if (original_name[len-1] == ';') {
373 original_name[--len] = 0;
379 for (i=0; i<len; ++i) {
380 if (original_name[i] == ';') {
385 name[j++] = original_name[i];
396 * \brief preparse a vcard name
397 * display_vcard() calls this after parsing the textual vCard into
398 * our 'struct vCard' data object.
399 * This gets called instead of display_parsed_vcard() if we are only looking
400 * to extract the person's name instead of displaying the card.
401 * \param v the vcard to retrieve the name from
402 * \param storename where to put the name at
404 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
407 strcpy(storename, "");
409 name = vcard_get_prop(v, "n", 1, 0, 0);
411 strcpy(storename, name);
412 /* vcard_n_prettyize(storename); */
420 * \brief html print a vcard
421 * display_vcard() calls this after parsing the textual vCard into
422 * our 'struct vCard' data object.
424 * Set 'full' to nonzero to display the full card, otherwise it will only
425 * show a summary line.
427 * This code is a bit ugly, so perhaps an explanation is due: we do this
428 * in two passes through the vCard fields. On the first pass, we process
429 * fields we understand, and then render them in a pretty fashion at the
430 * end. Then we make a second pass, outputting all the fields we don't
431 * understand in a simple two-column name/value format.
432 * \param v the vCard to display
433 * \param full display all items of the vcard?
435 void display_parsed_vcard(struct vCard *v, int full) {
441 char *thisname, *thisvalue;
442 char firsttoken[SIZ];
451 strcpy(fullname, "");
459 name = vcard_get_prop(v, "fn", 1, 0, 0);
463 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
464 strcpy(fullname, name);
465 vcard_n_prettyize(fullname);
475 wprintf("<div align=center>"
476 "<table bgcolor=#aaaaaa width=50%%>");
477 for (pass=1; pass<=2; ++pass) {
479 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
481 thisname = strdup(v->prop[i].name);
482 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
484 for (j=0; j<num_tokens(thisname, ';'); ++j) {
485 extract_token(buf, thisname, j, ';', sizeof buf);
486 if (!strcasecmp(buf, "encoding=quoted-printable")) {
488 remove_token(thisname, j, ';');
490 if (!strcasecmp(buf, "encoding=base64")) {
492 remove_token(thisname, j, ';');
496 len = strlen(v->prop[i].value);
497 /* if we have some untagged QP, detect it here. */
498 if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
500 utf8ify_rfc822_string(v->prop[i].value);
504 // %ff can become 6 bytes in utf8
505 thisvalue = malloc(len * 2 + 3);
506 j = CtdlDecodeQuotedPrintable(
507 thisvalue, v->prop[i].value,
512 // ff will become one byte..
513 thisvalue = malloc(len + 50);
515 thisvalue, v->prop[i].value,
516 strlen(v->prop[i].value) );
519 thisvalue = strdup(v->prop[i].value);
522 /** Various fields we may encounter ***/
524 /** N is name, but only if there's no FN already there */
525 if (!strcasecmp(firsttoken, "n")) {
526 if (IsEmptyStr(fullname)) {
527 strcpy(fullname, thisvalue);
528 vcard_n_prettyize(fullname);
532 /** FN (full name) is a true 'display name' field */
533 else if (!strcasecmp(firsttoken, "fn")) {
534 strcpy(fullname, thisvalue);
538 else if (!strcasecmp(firsttoken, "title")) {
539 strcpy(title, thisvalue);
543 else if (!strcasecmp(firsttoken, "org")) {
544 strcpy(org, thisvalue);
547 else if (!strcasecmp(firsttoken, "email")) {
549 if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
551 "<a href=\"display_enter"
552 "?force_room=_MAIL_?recp=");
554 len = strlen(mailto);
555 urlesc(&mailto[len], SIZ - len, fullname);
556 len = strlen(mailto);
557 urlesc(&mailto[len], SIZ - len, " <");
558 len = strlen(mailto);
559 urlesc(&mailto[len], SIZ - len, thisvalue);
560 len = strlen(mailto);
561 urlesc(&mailto[len], SIZ - len, ">");
563 strcat(mailto, "\">");
564 len = strlen(mailto);
565 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
566 strcat(mailto, "</A>");
568 else if (!strcasecmp(firsttoken, "tel")) {
569 if (!IsEmptyStr(phone)) strcat(phone, "<br />");
570 strcat(phone, thisvalue);
571 for (j=0; j<num_tokens(thisname, ';'); ++j) {
572 extract_token(buf, thisname, j, ';', sizeof buf);
573 if (!strcasecmp(buf, "tel"))
575 else if (!strcasecmp(buf, "work"))
576 strcat(phone, _(" (work)"));
577 else if (!strcasecmp(buf, "home"))
578 strcat(phone, _(" (home)"));
579 else if (!strcasecmp(buf, "cell"))
580 strcat(phone, _(" (cell)"));
588 else if (!strcasecmp(firsttoken, "adr")) {
591 wprintf(_("Address:"));
592 wprintf("</TD><TD>");
593 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
594 extract_token(buf, thisvalue, j, ';', sizeof buf);
595 if (!IsEmptyStr(buf)) {
597 if (j<3) wprintf("<br />");
601 wprintf("</TD></TR>\n");
604 else if (!strcasecmp(firsttoken, "version")) {
607 else if (!strcasecmp(firsttoken, "rev")) {
610 else if (!strcasecmp(firsttoken, "label")) {
615 /*** Don't show extra fields. They're ugly.
619 wprintf("</TD><TD>");
621 wprintf("</TD></TR>\n");
631 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
632 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
633 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
634 "<FONT SIZE=+1><B>");
636 wprintf("</B></FONT>");
637 if (!IsEmptyStr(title)) {
638 wprintf("<div align=right>");
642 if (!IsEmptyStr(org)) {
643 wprintf("<div align=right>");
647 wprintf("</TD></TR>\n");
649 if (!IsEmptyStr(phone)) {
651 wprintf(_("Telephone:"));
652 wprintf("</td><td>%s</td></tr>\n", phone);
654 if (!IsEmptyStr(mailto)) {
656 wprintf(_("E-mail:"));
657 wprintf("</td><td>%s</td></tr>\n", mailto);
663 wprintf("</table></div>\n");
669 * \brief Display a textual vCard
670 * (Converts to a vCard object and then calls the actual display function)
671 * Set 'full' to nonzero to display the whole card instead of a one-liner.
672 * Or, if "storename" is non-NULL, just store the person's name in that
673 * buffer instead of displaying the card at all.
674 * \param vcard_source the buffer containing the vcard text
675 * \param alpha what???
676 * \param full should we usse all lines?
677 * \param storename where to store???
679 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
685 v = vcard_load(vcard_source);
686 if (v == NULL) return;
688 name = vcard_get_prop(v, "n", 1, 0, 0);
691 utf8ify_rfc822_string(name);
697 if (storename != NULL) {
698 fetchname_parsed_vcard(v, storename);
700 else if ( (alpha == 0)
701 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
702 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
704 display_parsed_vcard(v, full);
718 * I wanna SEE that message!
720 * msgnum Message number to display
721 * printable_view Nonzero to display a printable view
722 * section Optional for encapsulated message/rfc822 submessage
724 void read_message(long msgnum, int printable_view, char *section) {
726 char mime_partnum[256] = "";
727 char mime_name[256] = "";
728 char mime_filename[256] = "";
729 char escaped_mime_filename[256] = "";
730 char mime_content_type[256] = "";
731 char mime_charset[256] = "";
732 char mime_disposition[256] = "";
734 struct attach_link *attach_links = NULL;
735 int num_attach_links = 0;
736 char mime_submessages[256] = "";
737 char m_subject[256] = "";
738 char m_cc[1024] = "";
742 char reply_to[512] = "";
743 char reply_all[4096] = "";
749 char vcard_partnum[256] = "";
750 char cal_partnum[256] = "";
751 char *part_source = NULL;
752 char msg4_partnum[32] = "";
754 iconv_t ic = (iconv_t)(-1) ;
755 char *ibuf; /**< Buffer of characters to be converted */
756 char *obuf; /**< Buffer for converted characters */
757 size_t ibuflen; /**< Length of input buffer */
758 size_t obuflen; /**< Length of output buffer */
759 char *osav; /**< Saved pointer to output buffer */
762 strcpy(mime_content_type, "text/plain");
763 strcpy(mime_charset, "us-ascii");
764 strcpy(mime_submessages, "");
766 serv_printf("MSG4 %ld|%s", msgnum, section);
767 serv_getln(buf, sizeof buf);
770 wprintf(_("ERROR:"));
771 wprintf("</strong> %s<br />\n", &buf[4]);
775 /** begin everythingamundo table */
776 if (!printable_view) {
777 wprintf("<div class=\"fix_scrollbar_bug message\" ");
778 wprintf("onMouseOver=document.getElementById(\"msg%ld\").style.visibility=\"visible\" ", msgnum);
779 wprintf("onMouseOut=document.getElementById(\"msg%ld\").style.visibility=\"hidden\" >", msgnum);
782 /** begin message header table */
783 wprintf("<div class=\"message_header\">");
785 strcpy(m_subject, "");
788 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
789 if (!strcmp(buf, "000")) {
791 wprintf(_("unexpected end of message"));
792 wprintf(" (1)</i><br /><br />\n");
796 if (!strncasecmp(buf, "nhdr=yes", 8))
800 if (!strncasecmp(buf, "type=", 5))
801 format_type = atoi(&buf[5]);
802 if (!strncasecmp(buf, "from=", 5)) {
803 strcpy(from, &buf[5]);
805 wprintf("<a href=\"showuser?who=");
807 utf8ify_rfc822_string(from);
814 if (!strncasecmp(buf, "subj=", 5)) {
815 safestrncpy(m_subject, &buf[5], sizeof m_subject);
817 if (!strncasecmp(buf, "cccc=", 5)) {
819 safestrncpy(m_cc, &buf[5], sizeof m_cc);
820 if (!IsEmptyStr(reply_all)) {
821 strcat(reply_all, ", ");
823 len = strlen(reply_all);
824 safestrncpy(&reply_all[len], &buf[5],
825 (sizeof reply_all - len) );
827 if ((!strncasecmp(buf, "hnod=", 5))
828 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
829 wprintf("(%s) ", &buf[5]);
831 if ((!strncasecmp(buf, "room=", 5))
832 && (strcasecmp(&buf[5], WC->wc_roomname))
833 && (!IsEmptyStr(&buf[5])) ) {
835 wprintf("%s> ", &buf[5]);
837 if (!strncasecmp(buf, "rfca=", 5)) {
838 strcpy(rfca, &buf[5]);
844 if (!strncasecmp(buf, "node=", 5)) {
845 strcpy(node, &buf[5]);
846 if ( ((WC->room_flags & QR_NETWORK)
847 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
848 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
849 && (IsEmptyStr(rfca))
851 wprintf("@%s ", &buf[5]);
854 if (!strncasecmp(buf, "rcpt=", 5)) {
857 if (!IsEmptyStr(reply_all)) {
858 strcat(reply_all, ", ");
860 len = strlen(reply_all);
861 safestrncpy(&reply_all[len], &buf[5],
862 (sizeof reply_all - len) );
864 utf8ify_rfc822_string(&buf[5]);
869 if (!strncasecmp(buf, "time=", 5)) {
870 webcit_fmt_date(now, atol(&buf[5]), 0);
876 if (!strncasecmp(buf, "part=", 5)) {
877 extract_token(mime_name, &buf[5], 0, '|', sizeof mime_filename);
878 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
879 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
880 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
881 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
882 mime_length = extract_int(&buf[5], 5);
885 striplt(mime_filename);
886 if ( (IsEmptyStr(mime_filename)) && (!IsEmptyStr(mime_name)) ) {
887 strcpy(mime_filename, mime_name);
890 if (!strcasecmp(mime_content_type, "message/rfc822")) {
891 if (!IsEmptyStr(mime_submessages)) {
892 strcat(mime_submessages, "|");
894 strcat(mime_submessages, mime_partnum);
896 else if ((!strcasecmp(mime_disposition, "inline"))
897 && (!strncasecmp(mime_content_type, "image/", 6)) ){
899 attach_links = realloc(attach_links,
900 (num_attach_links*sizeof(struct attach_link)));
901 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
902 snprintf(attach_links[num_attach_links-1].html, 1024,
903 "<img src=\"mimepart/%ld/%s/%s\">",
904 msgnum, mime_partnum, mime_filename);
906 else if ( ( (!strcasecmp(mime_disposition, "attachment"))
907 || (!strcasecmp(mime_disposition, "inline"))
908 || (!strcasecmp(mime_disposition, ""))
909 ) && (!IsEmptyStr(mime_content_type))
912 attach_links = realloc(attach_links,
913 (num_attach_links*sizeof(struct attach_link)));
914 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
915 urlesc(escaped_mime_filename, 265, mime_filename);
916 snprintf(attach_links[num_attach_links-1].html, 1024,
917 "<img src=\"static/diskette_24x.gif\" "
918 "border=0 align=middle>\n"
919 "%s (%s, %d bytes) [ "
920 "<a href=\"mimepart/%ld/%s/%s\""
921 "target=\"wc.%ld.%s\">%s</a>"
923 "<a href=\"mimepart_download/%ld/%s/%s\">%s</a>"
926 mime_content_type, mime_length,
927 msgnum, mime_partnum, escaped_mime_filename,
928 msgnum, mime_partnum,
930 msgnum, mime_partnum, escaped_mime_filename,
935 /** begin handler prep ***/
936 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
937 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
938 strcpy(vcard_partnum, mime_partnum);
941 if ( (!strcasecmp(mime_content_type, "text/calendar"))
942 || (!strcasecmp(mime_content_type, "application/ics")) ) {
943 strcpy(cal_partnum, mime_partnum);
946 /** end handler prep ***/
952 /** Generate a reply-to address */
953 if (!IsEmptyStr(rfca)) {
954 if (!IsEmptyStr(from)) {
955 snprintf(reply_to, sizeof(reply_to), "%s <%s>", from, rfca);
958 strcpy(reply_to, rfca);
962 if ((!IsEmptyStr(node))
963 && (strcasecmp(node, serv_info.serv_nodename))
964 && (strcasecmp(node, serv_info.serv_humannode)) ) {
965 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
969 snprintf(reply_to, sizeof(reply_to), "%s", from);
978 utf8ify_rfc822_string(m_cc);
979 utf8ify_rfc822_string(m_subject);
982 /** start msg buttons */
984 if (!printable_view) {
985 wprintf("<p id=\"msg%ld\" class=\"msgbuttons\" >\n",msgnum);
988 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
989 wprintf("<a href=\"display_enter");
990 if (WC->is_mailbox) {
991 wprintf("?replyquote=%ld", msgnum);
994 urlescputs(reply_to);
995 if (!IsEmptyStr(m_subject)) {
996 wprintf("?subject=");
997 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
998 urlescputs(m_subject);
1000 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Reply"));
1004 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
1005 if (!WC->is_mailbox) {
1006 wprintf("<a href=\"display_enter");
1007 wprintf("?replyquote=%ld", msgnum);
1009 urlescputs(reply_to);
1010 if (!IsEmptyStr(m_subject)) {
1011 wprintf("?subject=");
1012 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
1013 urlescputs(m_subject);
1015 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyQuoted"));
1020 if (WC->wc_view == VIEW_MAILBOX) {
1021 wprintf("<a href=\"display_enter");
1022 wprintf("?replyquote=%ld", msgnum);
1024 urlescputs(reply_to);
1026 urlescputs(reply_all);
1027 if (!IsEmptyStr(m_subject)) {
1028 wprintf("?subject=");
1029 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
1030 urlescputs(m_subject);
1032 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyAll"));
1036 if (WC->wc_view == VIEW_MAILBOX) {
1037 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
1038 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
1039 urlescputs(m_subject);
1040 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Forward"));
1043 /** If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
1044 if ( (WC->is_room_aide) || (WC->is_mailbox) || (WC->room_flags2 & QR2_COLLABDEL) ) {
1046 wprintf("<a href=\"confirm_move_msg?msgid=%ld\"><span>[</span>%s<span>]</span></a> ",
1050 wprintf("<a href=\"delete_msg?msgid=%ld\" "
1051 "onClick=\"return confirm('%s');\">"
1052 "<span>[</span>%s<span>]</span> "
1053 "</a> ", msgnum, _("Delete this message?"), _("Delete")
1058 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'); \" >"
1059 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Headers"));
1063 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'); \" >"
1064 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Print"));
1070 if (!IsEmptyStr(m_cc)) {
1077 if (!IsEmptyStr(m_subject)) {
1078 wprintf("<p class=\"message_subject\">");
1079 wprintf(_("Subject:"));
1088 wprintf("<div class=\"message_content\">");
1091 * Learn the content type
1093 strcpy(mime_content_type, "text/plain");
1094 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1095 if (!strcmp(buf, "000")) {
1096 /* This is not necessarily an error condition. See bug #226. */
1099 if (!strncasecmp(buf, "X-Citadel-MSG4-Partnum:", 23)) {
1100 safestrncpy(msg4_partnum, &buf[23], sizeof(msg4_partnum));
1101 striplt(msg4_partnum);
1103 if (!strncasecmp(buf, "Content-type:", 13)) {
1105 safestrncpy(mime_content_type, &buf[13], sizeof(mime_content_type));
1106 striplt(mime_content_type);
1107 len = strlen(mime_content_type);
1108 for (i=0; i<len; ++i) {
1109 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1110 safestrncpy(mime_charset, &mime_content_type[i+8],
1111 sizeof mime_charset);
1114 for (i=0; i<len; ++i) {
1115 if (mime_content_type[i] == ';') {
1116 mime_content_type[i] = 0;
1120 len = strlen(mime_charset);
1121 for (i=0; i<len; ++i) {
1122 if (mime_charset[i] == ';') {
1123 mime_charset[i] = 0;
1130 /** Set up a character set conversion if we need to (and if we can) */
1132 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
1133 if ( (strcasecmp(mime_charset, "us-ascii"))
1134 && (strcasecmp(mime_charset, "UTF-8"))
1135 && (strcasecmp(mime_charset, ""))
1137 ic = ctdl_iconv_open("UTF-8", mime_charset);
1138 if (ic == (iconv_t)(-1) ) {
1139 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1140 __FILE__, __LINE__, mime_charset, strerror(errno));
1145 /** Messages in legacy Citadel variformat get handled thusly... */
1146 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1150 /** Boring old 80-column fixed format text gets handled this way... */
1151 else if ( (!strcasecmp(mime_content_type, "text/plain"))
1152 || (!strcasecmp(mime_content_type, "text")) ) {
1154 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1157 if ((len > 0) && buf[len-1] == '\n') buf[--len] = 0;
1158 if ((len > 0) && buf[len-1] == '\r') buf[--len] = 0;
1161 if (ic != (iconv_t)(-1) ) {
1163 ibuflen = strlen(ibuf);
1165 obuf = (char *) malloc(obuflen);
1167 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1168 osav[SIZ-obuflen] = 0;
1169 safestrncpy(buf, osav, sizeof buf);
1175 while ((!IsEmptyStr(buf)) && (isspace(buf[len-1])))
1178 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1179 wprintf("<blockquote>");
1181 } else if ((bq == 1) &&
1182 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1183 wprintf("</blockquote>");
1189 wprintf("</tt><br />\n");
1191 wprintf("</i><br />");
1194 else /** HTML is fun, but we've got to strip it first */
1195 if (!strcasecmp(mime_content_type, "text/html")) {
1196 output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
1199 /** Unknown weirdness */
1201 wprintf(_("I don't know how to display %s"), mime_content_type);
1202 wprintf("<br />\n", mime_content_type);
1203 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1206 ENDBODY: /* If there are attached submessages, display them now... */
1208 if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
1209 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1210 extract_token(buf, mime_submessages, i, '|', sizeof buf);
1211 /** use printable_view to suppress buttons */
1212 wprintf("<blockquote>");
1213 read_message(msgnum, 1, buf);
1214 wprintf("</blockquote>");
1219 /** Afterwards, offer links to download attachments 'n' such */
1220 if ( (num_attach_links > 0) && (!section[0]) ) {
1221 for (i=0; i<num_attach_links; ++i) {
1222 if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
1223 wprintf("%s", attach_links[i].html);
1228 /** Handler for vCard parts */
1229 if (!IsEmptyStr(vcard_partnum)) {
1230 part_source = load_mimepart(msgnum, vcard_partnum);
1231 if (part_source != NULL) {
1233 /** If it's my vCard I can edit it */
1234 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1235 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1236 || (WC->wc_view == VIEW_ADDRESSBOOK)
1238 wprintf("<a href=\"edit_vcard?"
1239 "msgnum=%ld?partnum=%s\">",
1240 msgnum, vcard_partnum);
1241 wprintf("[%s]</a>", _("edit"));
1244 /** In all cases, display the full card */
1245 display_vcard(part_source, 0, 1, NULL);
1249 /** Handler for calendar parts */
1250 if (!IsEmptyStr(cal_partnum)) {
1251 part_source = load_mimepart(msgnum, cal_partnum);
1252 if (part_source != NULL) {
1253 cal_process_attachment(part_source,
1254 msgnum, cal_partnum);
1263 wprintf("</div>\n");
1265 /** end everythingamundo table */
1266 if (!printable_view) {
1267 wprintf("</div>\n");
1270 if (num_attach_links > 0) {
1275 if (ic != (iconv_t)(-1) ) {
1284 * \brief Unadorned HTML output of an individual message, suitable
1285 * for placing in a hidden iframe, for printing, or whatever
1287 * \param msgnum_as_string Message number, as a string instead of as a long int
1289 void embed_message(char *msgnum_as_string) {
1292 msgnum = atol(msgnum_as_string);
1293 begin_ajax_response();
1294 read_message(msgnum, 0, "");
1295 end_ajax_response();
1300 * \brief Printable view of a message
1302 * \param msgnum_as_string Message number, as a string instead of as a long int
1304 void print_message(char *msgnum_as_string) {
1307 msgnum = atol(msgnum_as_string);
1308 output_headers(0, 0, 0, 0, 0, 0);
1310 wprintf("Content-type: text/html\r\n"
1312 "Connection: close\r\n",
1316 wprintf("\r\n\r\n<html>\n"
1317 "<head><title>Printable view</title></head>\n"
1318 "<body onLoad=\" window.print(); window.close(); \">\n"
1321 read_message(msgnum, 1, "");
1323 wprintf("\n</body></html>\n\n");
1330 * \brief Display a message's headers
1332 * \param msgnum_as_string Message number, as a string instead of as a long int
1334 void display_headers(char *msgnum_as_string) {
1338 msgnum = atol(msgnum_as_string);
1339 output_headers(0, 0, 0, 0, 0, 0);
1341 wprintf("Content-type: text/plain\r\n"
1343 "Connection: close\r\n",
1347 serv_printf("MSG2 %ld|3", msgnum);
1348 serv_getln(buf, sizeof buf);
1349 if (buf[0] == '1') {
1350 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1351 wprintf("%s\n", buf);
1361 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1362 * or 'reply quoted' operations.
1364 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1365 * in this function. Doing so would throw a JavaScript error in the
1366 * 'supplied text' argument to the editor.
1368 * \param msgnum Message number of the message we want to quote
1369 * \param forward_attachments Nonzero if we want attachments to be forwarded
1371 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1373 char mime_partnum[256];
1374 char mime_filename[256];
1375 char mime_content_type[256];
1376 char mime_charset[256];
1377 char mime_disposition[256];
1379 char *attachments = NULL;
1381 int num_attachments = 0;
1382 struct wc_attachment *att, *aptr;
1383 char m_subject[256];
1390 int format_type = 0;
1395 iconv_t ic = (iconv_t)(-1) ;
1396 char *ibuf; /**< Buffer of characters to be converted */
1397 char *obuf; /**< Buffer for converted characters */
1398 size_t ibuflen; /**< Length of input buffer */
1399 size_t obuflen; /**< Length of output buffer */
1400 char *osav; /**< Saved pointer to output buffer */
1406 strcpy(reply_to, "");
1407 strcpy(mime_content_type, "text/plain");
1408 strcpy(mime_charset, "us-ascii");
1410 serv_printf("MSG4 %ld", msgnum);
1411 serv_getln(buf, sizeof buf);
1412 if (buf[0] != '1') {
1413 wprintf(_("ERROR:"));
1414 wprintf("%s<br />", &buf[4]);
1418 strcpy(m_subject, "");
1420 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1421 if (!strcmp(buf, "000")) {
1422 wprintf("%s (3)", _("unexpected end of message"));
1425 if (include_headers) {
1426 if (!strncasecmp(buf, "nhdr=yes", 8))
1430 if (!strncasecmp(buf, "type=", 5))
1431 format_type = atoi(&buf[5]);
1432 if (!strncasecmp(buf, "from=", 5)) {
1433 strcpy(from, &buf[5]);
1434 wprintf(_("from "));
1436 utf8ify_rfc822_string(from);
1440 if (!strncasecmp(buf, "subj=", 5)) {
1441 strcpy(m_subject, &buf[5]);
1443 if ((!strncasecmp(buf, "hnod=", 5))
1444 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1445 wprintf("(%s) ", &buf[5]);
1447 if ((!strncasecmp(buf, "room=", 5))
1448 && (strcasecmp(&buf[5], WC->wc_roomname))
1449 && (!IsEmptyStr(&buf[5])) ) {
1451 wprintf("%s> ", &buf[5]);
1453 if (!strncasecmp(buf, "rfca=", 5)) {
1454 strcpy(rfca, &buf[5]);
1460 if (!strncasecmp(buf, "node=", 5)) {
1461 strcpy(node, &buf[5]);
1462 if ( ((WC->room_flags & QR_NETWORK)
1463 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1464 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1465 && (IsEmptyStr(rfca))
1467 wprintf("@%s ", &buf[5]);
1470 if (!strncasecmp(buf, "rcpt=", 5)) {
1472 strcpy(to, &buf[5]);
1474 utf8ify_rfc822_string(to);
1478 if (!strncasecmp(buf, "time=", 5)) {
1479 webcit_fmt_date(now, atol(&buf[5]), 0);
1480 wprintf("%s ", now);
1485 * Save attachment info for later. We can't start downloading them
1486 * yet because we're in the middle of a server transaction.
1488 if (!strncasecmp(buf, "part=", 5)) {
1489 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1492 sprintf(ptr, "%s%s\n",
1493 ((attachments != NULL) ? attachments : ""),
1498 lprintf(9, "attachments=<%s>\n", attachments);
1504 if (include_headers) {
1508 utf8ify_rfc822_string(m_subject);
1510 if (!IsEmptyStr(m_subject)) {
1511 wprintf(_("Subject:"));
1513 msgescputs(m_subject);
1524 * Learn the content type
1526 strcpy(mime_content_type, "text/plain");
1527 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1528 if (!strcmp(buf, "000")) {
1529 wprintf("%s (4)", _("unexpected end of message"));
1532 if (!strncasecmp(buf, "Content-type: ", 14)) {
1534 safestrncpy(mime_content_type, &buf[14],
1535 sizeof(mime_content_type));
1536 for (i=0; i<strlen(mime_content_type); ++i) {
1537 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1538 safestrncpy(mime_charset, &mime_content_type[i+8],
1539 sizeof mime_charset);
1542 len = strlen(mime_content_type);
1543 for (i=0; i<len; ++i) {
1544 if (mime_content_type[i] == ';') {
1545 mime_content_type[i] = 0;
1549 len = strlen(mime_charset);
1550 for (i=0; i<len; ++i) {
1551 if (mime_charset[i] == ';') {
1552 mime_charset[i] = 0;
1559 /** Set up a character set conversion if we need to (and if we can) */
1561 if ( (strcasecmp(mime_charset, "us-ascii"))
1562 && (strcasecmp(mime_charset, "UTF-8"))
1563 && (strcasecmp(mime_charset, ""))
1565 ic = ctdl_iconv_open("UTF-8", mime_charset);
1566 if (ic == (iconv_t)(-1) ) {
1567 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1568 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1573 /** Messages in legacy Citadel variformat get handled thusly... */
1574 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1578 /* Boring old 80-column fixed format text gets handled this way... */
1579 else if (!strcasecmp(mime_content_type, "text/plain")) {
1580 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1583 if (buf[len-1] == '\n') buf[--len] = 0;
1584 if (buf[len-1] == '\r') buf[--len] = 0;
1587 if (ic != (iconv_t)(-1) ) {
1591 obuf = (char *) malloc(obuflen);
1593 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1594 osav[SIZ-obuflen] = 0;
1595 safestrncpy(buf, osav, sizeof buf);
1601 while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
1604 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1605 wprintf("<blockquote>");
1607 } else if ((bq == 1) &&
1608 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1609 wprintf("</blockquote>");
1615 wprintf("</tt><br />");
1617 wprintf("</i><br />");
1620 /** HTML just gets escaped and stuffed back into the editor */
1621 else if (!strcasecmp(mime_content_type, "text/html")) {
1622 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1628 /** Unknown weirdness ... don't know how to handle this content type */
1630 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1634 /** end of body handler */
1637 * If there were attachments, we have to download them and insert them
1638 * into the attachment chain for the forwarded message we are composing.
1640 if ( (forward_attachments) && (num_attachments) ) {
1641 for (i=0; i<num_attachments; ++i) {
1642 extract_token(buf, attachments, i, '\n', sizeof buf);
1643 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1644 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1645 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1646 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1647 mime_length = extract_int(buf, 5);
1650 * tracing ... uncomment if necessary
1653 lprintf(9, "fwd filename: %s\n", mime_filename);
1654 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1655 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1656 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1657 lprintf(9, "fwd length : %d\n", mime_length);
1659 if ( (!strcasecmp(mime_disposition, "inline"))
1660 || (!strcasecmp(mime_disposition, "attachment")) ) {
1662 /* Create an attachment struct from this mime part... */
1663 att = malloc(sizeof(struct wc_attachment));
1664 memset(att, 0, sizeof(struct wc_attachment));
1665 att->length = mime_length;
1666 strcpy(att->content_type, mime_content_type);
1667 strcpy(att->filename, mime_filename);
1669 att->data = load_mimepart(msgnum, mime_partnum);
1671 /* And add it to the list. */
1672 if (WC->first_attachment == NULL) {
1673 WC->first_attachment = att;
1676 aptr = WC->first_attachment;
1677 while (aptr->next != NULL) aptr = aptr->next;
1686 if (ic != (iconv_t)(-1) ) {
1691 if (attachments != NULL) {
1697 * \brief Display one row in the mailbox summary view
1699 * \param num The row number to be displayed
1701 void display_summarized(int num) {
1704 wprintf("<tr id=\"m%ld\" style=\"font-weight:%s;\" "
1705 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1706 WC->summ[num].msgnum,
1707 (WC->summ[num].is_new ? "bold" : "normal"),
1708 WC->summ[num].msgnum
1711 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1713 escputs(WC->summ[num].subj);//////////////////////////////////TODO: QP DECODE
1716 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1717 escputs(WC->summ[num].from);
1720 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1721 webcit_fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1731 * \brief display the adressbook overview
1732 * \param msgnum the citadel message number
1733 * \param alpha what????
1735 void display_addressbook(long msgnum, char alpha) {
1737 char mime_partnum[SIZ];
1738 char mime_filename[SIZ];
1739 char mime_content_type[SIZ];
1740 char mime_disposition[SIZ];
1742 char vcard_partnum[SIZ];
1743 char *vcard_source = NULL;
1744 struct message_summary summ;
1746 memset(&summ, 0, sizeof(summ));
1747 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1749 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1751 serv_getln(buf, sizeof buf);
1752 if (buf[0] != '1') return;
1754 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1755 if (!strncasecmp(buf, "part=", 5)) {
1756 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1757 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1758 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1759 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1760 mime_length = extract_int(&buf[5], 5);
1762 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1763 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1764 strcpy(vcard_partnum, mime_partnum);
1770 if (!IsEmptyStr(vcard_partnum)) {
1771 vcard_source = load_mimepart(msgnum, vcard_partnum);
1772 if (vcard_source != NULL) {
1774 /** Display the summary line */
1775 display_vcard(vcard_source, alpha, 0, NULL);
1777 /** If it's my vCard I can edit it */
1778 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1779 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1780 || (WC->wc_view == VIEW_ADDRESSBOOK)
1782 wprintf("<a href=\"edit_vcard?"
1783 "msgnum=%ld?partnum=%s\">",
1784 msgnum, vcard_partnum);
1785 wprintf("[%s]</a>", _("edit"));
1797 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1798 * \param namebuf name to analyze, reverse if nescessary
1800 void lastfirst_firstlast(char *namebuf) {
1801 char firstname[SIZ];
1805 if (namebuf == NULL) return;
1806 if (strchr(namebuf, ';') != NULL) return;
1808 i = num_tokens(namebuf, ' ');
1811 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1812 remove_token(namebuf, i-1, ' ');
1813 strcpy(firstname, namebuf);
1814 sprintf(namebuf, "%s; %s", lastname, firstname);
1818 * \brief fetch what??? name
1819 * \param msgnum the citadel message number
1820 * \param namebuf where to put the name in???
1822 void fetch_ab_name(long msgnum, char *namebuf) {
1824 char mime_partnum[SIZ];
1825 char mime_filename[SIZ];
1826 char mime_content_type[SIZ];
1827 char mime_disposition[SIZ];
1829 char vcard_partnum[SIZ];
1830 char *vcard_source = NULL;
1832 struct message_summary summ;
1834 if (namebuf == NULL) return;
1835 strcpy(namebuf, "");
1837 memset(&summ, 0, sizeof(summ));
1838 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1840 sprintf(buf, "MSG0 %ld|0", msgnum); /** unfortunately we need the mime info now */
1842 serv_getln(buf, sizeof buf);
1843 if (buf[0] != '1') return;
1845 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1846 if (!strncasecmp(buf, "part=", 5)) {
1847 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1848 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1849 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1850 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1851 mime_length = extract_int(&buf[5], 5);
1853 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1854 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1855 strcpy(vcard_partnum, mime_partnum);
1861 if (!IsEmptyStr(vcard_partnum)) {
1862 vcard_source = load_mimepart(msgnum, vcard_partnum);
1863 if (vcard_source != NULL) {
1865 /* Grab the name off the card */
1866 display_vcard(vcard_source, 0, 0, namebuf);
1872 lastfirst_firstlast(namebuf);
1874 len = strlen(namebuf);
1875 for (i=0; i<len; ++i) {
1876 if (namebuf[i] != ';') return;
1878 strcpy(namebuf, _("(no name)"));
1884 * \brief Record compare function for sorting address book indices
1885 * \param ab1 adressbook one
1886 * \param ab2 adressbook two
1888 int abcmp(const void *ab1, const void *ab2) {
1890 (((const struct addrbookent *)ab1)->ab_name),
1891 (((const struct addrbookent *)ab2)->ab_name)
1897 * \brief Helper function for do_addrbook_view()
1898 * Converts a name into a three-letter tab label
1899 * \param tabbuf the tabbuffer to add name to
1900 * \param name the name to add to the tabbuffer
1902 void nametab(char *tabbuf, long len, char *name) {
1903 stresc(tabbuf, len, name, 0, 0);
1904 tabbuf[0] = toupper(tabbuf[0]);
1905 tabbuf[1] = tolower(tabbuf[1]);
1906 tabbuf[2] = tolower(tabbuf[2]);
1912 * \brief Render the address book using info we gathered during the scan
1913 * \param addrbook the addressbook to render
1914 * \param num_ab the number of the addressbook
1916 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1920 static int NAMESPERPAGE = 60;
1923 char tabfirst_label[64];
1925 char tablast_label[64];
1926 char this_tablabel[64];
1931 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1932 wprintf(_("This address book is empty."));
1933 wprintf("</i></div>\n");
1938 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1941 num_pages = (num_ab / NAMESPERPAGE) + 1;
1943 tablabels = malloc(num_pages * sizeof (char *));
1944 if (tablabels == NULL) {
1945 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1946 wprintf(_("An internal error has occurred."));
1947 wprintf("</i></div>\n");
1951 for (i=0; i<num_pages; ++i) {
1952 tabfirst = i * NAMESPERPAGE;
1953 tablast = tabfirst + NAMESPERPAGE - 1;
1954 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1955 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
1956 nametab(tablast_label, 64, addrbook[tablast].ab_name);
1957 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
1958 tablabels[i] = strdup(this_tablabel);
1961 tabbed_dialog(num_pages, tablabels);
1964 for (i=0; i<num_ab; ++i) {
1966 if ((i / NAMESPERPAGE) != page) { /* New tab */
1967 page = (i / NAMESPERPAGE);
1969 wprintf("</tr></table>\n");
1970 end_tab(page-1, num_pages);
1972 begin_tab(page, num_pages);
1973 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
1977 if ((displayed % 4) == 0) {
1978 if (displayed > 0) {
1982 wprintf("<tr bgcolor=\"#%s\">",
1983 (bg ? "DDDDDD" : "FFFFFF")
1989 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
1990 addrbook[i].ab_msgnum);
1991 wprintf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
1992 vcard_n_prettyize(addrbook[i].ab_name);
1993 escputs(addrbook[i].ab_name);
1994 wprintf("</a></td>\n");
1998 wprintf("</tr></table>\n");
1999 end_tab((num_pages-1), num_pages);
2001 for (i=0; i<num_pages; ++i) {
2010 * \brief load message pointers from the server
2011 * \param servcmd the citadel command to send to the citserver
2012 * \param with_headers what headers???
2014 int load_msg_ptrs(char *servcmd, int with_headers)
2025 int num_summ_alloc = 0;
2027 if (WC->summ != NULL) {
2032 num_summ_alloc = 100;
2034 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
2037 maxload = sizeof(WC->msgarr) / sizeof(long) ;
2039 serv_getln(buf, sizeof buf);
2040 if (buf[0] != '1') {
2043 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2044 if (nummsgs < maxload) {
2045 WC->msgarr[nummsgs] = extract_long(buf, 0);
2046 datestamp = extract_long(buf, 1);
2047 extract_token(fullname, buf, 2, '|', sizeof fullname);
2048 extract_token(nodename, buf, 3, '|', sizeof nodename);
2049 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
2050 extract_token(subject, buf, 5, '|', sizeof subject);
2054 if (nummsgs > num_summ_alloc) {
2055 num_summ_alloc *= 2;
2056 WC->summ = realloc(WC->summ,
2057 num_summ_alloc * sizeof(struct message_summary));
2061 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
2062 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
2063 safestrncpy(WC->summ[nummsgs-1].subj,
2064 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
2065 if (!IsEmptyStr(fullname)) {
2067 /** Handle senders with RFC2047 encoding */
2068 utf8ify_rfc822_string(fullname);
2070 safestrncpy(WC->summ[nummsgs-1].from,
2071 fullname, sizeof WC->summ[nummsgs-1].from);
2073 if (!IsEmptyStr(subject)) {
2075 /** Handle subjects with RFC2047 encoding */
2076 utf8ify_rfc822_string(subject);
2078 safestrncpy(WC->summ[nummsgs-1].subj, subject,
2079 sizeof WC->summ[nummsgs-1].subj);
2081 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
2082 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
2085 if (!IsEmptyStr(nodename)) {
2086 if ( ((WC->room_flags & QR_NETWORK)
2087 || ((strcasecmp(nodename, serv_info.serv_nodename)
2088 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
2090 strcat(WC->summ[nummsgs-1].from, " @ ");
2091 strcat(WC->summ[nummsgs-1].from, nodename);
2095 WC->summ[nummsgs-1].date = datestamp;
2098 /** Handle senders with RFC2047 encoding */
2099 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
2101 if (strlen(WC->summ[nummsgs-1].from) > 25) {
2102 strcpy(&WC->summ[nummsgs-1].from[22], "...");
2111 * \brief qsort() compatible function to compare two longs in descending order.
2113 * \param s1 first number to compare
2114 * \param s2 second number to compare
2116 int longcmp_r(const void *s1, const void *s2) {
2123 if (l1 > l2) return(-1);
2124 if (l1 < l2) return(+1);
2130 * \brief qsort() compatible function to compare two message summary structs by ascending subject.
2132 * \param s1 first item to compare
2133 * \param s2 second item to compare
2135 int summcmp_subj(const void *s1, const void *s2) {
2136 struct message_summary *summ1;
2137 struct message_summary *summ2;
2139 summ1 = (struct message_summary *)s1;
2140 summ2 = (struct message_summary *)s2;
2141 return strcasecmp(summ1->subj, summ2->subj);
2145 * \brief qsort() compatible function to compare two message summary structs by descending subject.
2147 * \param s1 first item to compare
2148 * \param s2 second item to compare
2150 int summcmp_rsubj(const void *s1, const void *s2) {
2151 struct message_summary *summ1;
2152 struct message_summary *summ2;
2154 summ1 = (struct message_summary *)s1;
2155 summ2 = (struct message_summary *)s2;
2156 return strcasecmp(summ2->subj, summ1->subj);
2160 * \brief qsort() compatible function to compare two message summary structs by ascending sender.
2162 * \param s1 first item to compare
2163 * \param s2 second item to compare
2165 int summcmp_sender(const void *s1, const void *s2) {
2166 struct message_summary *summ1;
2167 struct message_summary *summ2;
2169 summ1 = (struct message_summary *)s1;
2170 summ2 = (struct message_summary *)s2;
2171 return strcasecmp(summ1->from, summ2->from);
2175 * \brief qsort() compatible function to compare two message summary structs by descending sender.
2177 * \param s1 first item to compare
2178 * \param s2 second item to compare
2180 int summcmp_rsender(const void *s1, const void *s2) {
2181 struct message_summary *summ1;
2182 struct message_summary *summ2;
2184 summ1 = (struct message_summary *)s1;
2185 summ2 = (struct message_summary *)s2;
2186 return strcasecmp(summ2->from, summ1->from);
2190 * \brief qsort() compatible function to compare two message summary structs by ascending date.
2192 * \param s1 first item to compare
2193 * \param s2 second item to compare
2195 int summcmp_date(const void *s1, const void *s2) {
2196 struct message_summary *summ1;
2197 struct message_summary *summ2;
2199 summ1 = (struct message_summary *)s1;
2200 summ2 = (struct message_summary *)s2;
2202 if (summ1->date < summ2->date) return -1;
2203 else if (summ1->date > summ2->date) return +1;
2208 * \brief qsort() compatible function to compare two message summary structs by descending date.
2210 * \param s1 first item to compare
2211 * \param s2 second item to compare
2213 int summcmp_rdate(const void *s1, const void *s2) {
2214 struct message_summary *summ1;
2215 struct message_summary *summ2;
2217 summ1 = (struct message_summary *)s1;
2218 summ2 = (struct message_summary *)s2;
2220 if (summ1->date < summ2->date) return +1;
2221 else if (summ1->date > summ2->date) return -1;
2228 * \brief command loop for reading messages
2230 * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
2232 void readloop(char *oper)
2241 long *displayed_msgs = NULL;
2242 int num_displayed = 0;
2244 int is_addressbook = 0;
2245 int is_singlecard = 0;
2246 int is_calendar = 0;
2251 int lowest_displayed = (-1);
2252 int highest_displayed = 0;
2253 struct addrbookent *addrbook = NULL;
2255 char *sortby = NULL;
2256 char sortpref_name[128];
2257 char sortpref_value[128];
2258 char *subjsort_button;
2259 char *sendsort_button;
2260 char *datesort_button;
2261 int bbs_reverse = 0;
2262 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
2264 if (WCC->wc_view == VIEW_WIKI) {
2265 sprintf(buf, "wiki?room=%s?page=home", WCC->wc_roomname);
2270 startmsg = atol(bstr("startmsg"));
2271 maxmsgs = atoi(bstr("maxmsgs"));
2272 is_summary = atoi(bstr("is_summary"));
2273 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2275 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WCC->wc_roomname);
2276 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
2278 sortby = bstr("sortby");
2279 if ( (!IsEmptyStr(sortby)) && (strcasecmp(sortby, sortpref_value)) ) {
2280 set_preference(sortpref_name, sortby, 1);
2282 if (IsEmptyStr(sortby)) sortby = sortpref_value;
2285 if (IsEmptyStr(sortby)) sortby = "rdate";
2287 /** message board sort */
2288 if (!strcasecmp(sortby, "reverse")) {
2295 output_headers(1, 1, 1, 0, 0, 0);
2298 * When in summary mode, always show ALL messages instead of just
2299 * new or old. Otherwise, show what the user asked for.
2301 if (!strcmp(oper, "readnew")) {
2302 strcpy(cmd, "MSGS NEW");
2304 else if (!strcmp(oper, "readold")) {
2305 strcpy(cmd, "MSGS OLD");
2307 else if (!strcmp(oper, "do_search")) {
2308 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2311 strcpy(cmd, "MSGS ALL");
2314 if ((WCC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
2316 if (!strcmp(oper, "do_search")) {
2317 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2320 strcpy(cmd, "MSGS ALL");
2324 if ((WCC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2326 if (!strcmp(oper, "do_search")) {
2327 sprintf(cmd, "MSGS SEARCH|%s", bstr("query"));
2330 strcpy(cmd, "MSGS ALL");
2335 if (is_summary) { /**< fetch header summary */
2336 snprintf(cmd, sizeof cmd, "MSGS %s|%s||1",
2337 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2338 (!strcmp(oper, "do_search") ? bstr("query") : "")
2345 * Are we doing a summary view? If so, we need to know old messages
2346 * and new messages, so we can do that pretty boldface thing for the
2349 strcpy(old_msgs, "");
2350 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR)){
2352 serv_getln(buf, sizeof buf);
2353 if (buf[0] == '2') {
2354 strcpy(old_msgs, &buf[4]);
2358 is_singlecard = atoi(bstr("is_singlecard"));
2360 if (WCC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2362 strcpy(cmd, "MSGS ALL|||1");
2365 if (WCC->wc_default_view == VIEW_TASKS) { /**< tasks */
2367 strcpy(cmd, "MSGS ALL");
2370 if (WCC->wc_default_view == VIEW_NOTES) { /**< notes */
2372 strcpy(cmd, "MSGS ALL");
2377 wprintf("<div align=center>%s</div>\n", _("Click on any note to edit it."));
2378 wprintf("<div id=\"new_notes_here\"></div>\n");
2381 nummsgs = load_msg_ptrs(cmd, is_summary);
2384 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2385 wprintf("<div align=\"center\"><br /><em>");
2386 if (!strcmp(oper, "readnew")) {
2387 wprintf(_("No new messages."));
2388 } else if (!strcmp(oper, "readold")) {
2389 wprintf(_("No old messages."));
2391 wprintf(_("No messages here."));
2393 wprintf("</em><br /></div>\n");
2399 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR)){
2400 for (a = 0; a < nummsgs; ++a) {
2401 /** Are you a new message, or an old message? */
2403 if (is_msg_in_mset(old_msgs, WCC->msgarr[a])) {
2404 WCC->summ[a].is_new = 0;
2407 WCC->summ[a].is_new = 1;
2413 if (startmsg == 0L) {
2415 startmsg = WCC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2418 startmsg = WCC->msgarr[0];
2423 if (!strcasecmp(sortby, "subject")) {
2424 qsort(WCC->summ, WCC->num_summ,
2425 sizeof(struct message_summary), summcmp_subj);
2427 else if (!strcasecmp(sortby, "rsubject")) {
2428 qsort(WCC->summ, WCC->num_summ,
2429 sizeof(struct message_summary), summcmp_rsubj);
2431 else if (!strcasecmp(sortby, "sender")) {
2432 qsort(WCC->summ, WCC->num_summ,
2433 sizeof(struct message_summary), summcmp_sender);
2435 else if (!strcasecmp(sortby, "rsender")) {
2436 qsort(WCC->summ, WCC->num_summ,
2437 sizeof(struct message_summary), summcmp_rsender);
2439 else if (!strcasecmp(sortby, "date")) {
2440 qsort(WCC->summ, WCC->num_summ,
2441 sizeof(struct message_summary), summcmp_date);
2443 else if (!strcasecmp(sortby, "rdate")) {
2444 qsort(WCC->summ, WCC->num_summ,
2445 sizeof(struct message_summary), summcmp_rdate);
2449 if (!strcasecmp(sortby, "subject")) {
2450 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2452 else if (!strcasecmp(sortby, "rsubject")) {
2453 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2456 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2459 if (!strcasecmp(sortby, "sender")) {
2460 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2462 else if (!strcasecmp(sortby, "rsender")) {
2463 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2466 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2469 if (!strcasecmp(sortby, "date")) {
2470 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2472 else if (!strcasecmp(sortby, "rdate")) {
2473 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2476 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2481 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2482 " document.onkeydown = CtdlMsgListKeyPress; "
2483 " if (document.layers) { "
2484 " document.captureEvents(Event.KEYPRESS); "
2489 /** note that Date and Delete are now in the same column */
2490 wprintf("<div id=\"message_list_hdr\">"
2491 "<div class=\"fix_scrollbar_bug\">"
2492 "<table cellspacing=0 style=\"width:100%%\">"
2495 wprintf("<th width=%d%%>%s %s</th>"
2496 "<th width=%d%%>%s %s</th>"
2497 "<th width=%d%%>%s %s"
2499 "<input type=\"submit\" name=\"delete_button\" id=\"delbutton\" "
2500 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2506 _("Subject"), subjsort_button,
2507 SENDER_COL_WIDTH_PCT,
2508 _("Sender"), sendsort_button,
2509 DATE_PLUS_BUTTONS_WIDTH_PCT,
2510 _("Date"), datesort_button,
2513 wprintf("</table></div></div>\n");
2515 wprintf("<div id=\"message_list\">"
2517 "<div class=\"fix_scrollbar_bug\">\n"
2519 "<table class=\"mailbox_summary\" id=\"summary_headers\" "
2520 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2526 * Set the "is_bbview" variable if it appears that we are looking at
2527 * a classic bulletin board view.
2529 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2530 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2535 * If we're not currently looking at ALL requested
2536 * messages, then display the selector bar
2539 /** begin bbview scroller */
2540 wprintf("<form name=\"msgomatictop\" class=\"selector_top\" > \n <p>");
2541 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2543 wprintf("<select name=\"whichones\" size=\"1\" "
2544 "OnChange=\"location.href=msgomatictop.whichones.options"
2545 "[selectedIndex].value\">\n");
2548 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2550 lo = b - maxmsgs + 2;
2552 wprintf("<option %s value="
2557 "%d-%d</option> \n",
2558 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2567 for (b=0; b<nummsgs; b = b + maxmsgs) {
2569 hi = b + maxmsgs + 1;
2570 if (hi > nummsgs) hi = nummsgs;
2571 wprintf("<option %s value="
2576 "%d-%d</option> \n",
2577 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2586 wprintf("<option value=\"%s?startmsg=%ld"
2587 "?maxmsgs=9999999?is_summary=%d\">",
2589 WCC->msgarr[0], is_summary);
2591 wprintf("</option>");
2592 wprintf("</select> ");
2593 wprintf(_("of %d messages."), nummsgs);
2595 /** forward/reverse */
2596 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2597 "OnChange=\"location.href='%s?sortby=forward'\"",
2598 (bbs_reverse ? "" : "checked"),
2602 wprintf(_("oldest to newest"));
2603 wprintf(" ");
2605 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2606 "OnChange=\"location.href='%s?sortby=reverse'\"",
2607 (bbs_reverse ? "checked" : ""),
2611 wprintf(_("newest to oldest"));
2614 wprintf("</p></form>\n");
2615 /** end bbview scroller */
2620 wprintf ("<script src=\"/static/dragdrop.js\" type=\"text/javascript\"></script>\n");
2625 for (a = 0; a < nummsgs; ++a) {
2626 if ((WCC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2628 /** Display the message */
2630 display_summarized(a);
2632 else if (is_addressbook) {
2633 fetch_ab_name(WCC->msgarr[a], buf);
2635 addrbook = realloc(addrbook,
2636 (sizeof(struct addrbookent) * num_ab) );
2637 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2638 sizeof(addrbook[num_ab-1].ab_name));
2639 addrbook[num_ab-1].ab_msgnum = WCC->msgarr[a];
2641 else if (is_calendar) {
2642 display_calendar(WCC->msgarr[a], WCC->summ[a].is_new);
2644 else if (is_tasks) {
2645 display_task(WCC->msgarr[a], WCC->summ[a].is_new);
2647 else if (is_notes) {
2648 display_note(WCC->msgarr[a], WCC->summ[a].is_new);
2651 if (displayed_msgs == NULL) {
2652 displayed_msgs = malloc(sizeof(long) *
2653 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2655 displayed_msgs[num_displayed] = WCC->msgarr[a];
2658 if (lowest_displayed < 0) lowest_displayed = a;
2659 highest_displayed = a;
2666 if (displayed_msgs != NULL) {
2668 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2671 /** if we do a split bbview in the future, begin messages div here */
2673 for (a=0; a<num_displayed; ++a) {
2674 read_message(displayed_msgs[a], 0, "");
2677 /** if we do a split bbview in the future, end messages div here */
2679 free(displayed_msgs);
2680 displayed_msgs = NULL;
2685 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2686 wprintf("</div>"); /**< end of 'message_list' div */
2688 /** Here's the grab-it-to-resize-the-message-list widget */
2689 wprintf("<div id=\"resize_msglist\" "
2690 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2691 "<div class=\"fix_scrollbar_bug\"> <hr>"
2695 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2699 * Bump these because although we're thinking in zero base, the user
2700 * is a drooling idiot and is thinking in one base.
2703 ++highest_displayed;
2706 * If we're not currently looking at ALL requested
2707 * messages, then display the selector bar
2710 /** begin bbview scroller */
2711 wprintf("<form name=\"msgomatic\" class=\"selector_bottom\" > \n <p>");
2712 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2714 wprintf("<select name=\"whichones\" size=\"1\" "
2715 "OnChange=\"location.href=msgomatic.whichones.options"
2716 "[selectedIndex].value\">\n");
2719 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2721 lo = b - maxmsgs + 2;
2723 wprintf("<option %s value="
2728 "%d-%d</option> \n",
2729 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2738 for (b=0; b<nummsgs; b = b + maxmsgs) {
2740 hi = b + maxmsgs + 1;
2741 if (hi > nummsgs) hi = nummsgs;
2742 wprintf("<option %s value="
2747 "%d-%d</option> \n",
2748 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2757 wprintf("<option value=\"%s?startmsg=%ld"
2758 "?maxmsgs=9999999?is_summary=%d\">",
2760 WCC->msgarr[0], is_summary);
2762 wprintf("</option>");
2763 wprintf("</select> ");
2764 wprintf(_("of %d messages."), nummsgs);
2766 /** forward/reverse */
2767 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2768 "OnChange=\"location.href='%s?sortby=forward'\"",
2769 (bbs_reverse ? "" : "checked"),
2773 wprintf(_("oldest to newest"));
2774 wprintf(" ");
2775 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2776 "OnChange=\"location.href='%s?sortby=reverse'\"",
2777 (bbs_reverse ? "checked" : ""),
2781 wprintf(_("newest to oldest"));
2784 wprintf("</p></form>\n");
2785 /** end bbview scroller */
2790 // wprintf ("</div>\n");
2791 wprintf ("<div id=\"wastebin\" align=middle>Drop notes here to remove them.</div>\n");
2792 wprintf ("<script type=\"text/javascript\">\n");
2793 // wprintf ("//<![CDATA[\n");
2794 wprintf ("Droppables.add(\"wastebin\",\n");
2796 wprintf ("\t\taccept:'notes',\n");
2797 wprintf ("\t\tonDrop:function(element)\n");
2798 wprintf ("\t\t{\n");
2799 wprintf ("\t\t\tElement.hide(element);\n");
2800 wprintf ("\t\t\tnew Ajax.Updater('notes', 'delnote',\n");
2801 wprintf ("\t\t\t{\n");
2802 wprintf ("\t\t\t\tasynchronous:true,\n");
2803 wprintf ("\t\t\t\tevalScripts:true,\n");
2804 wprintf ("\t\t\t\tonComplete:function(request)\n");
2805 wprintf ("\t\t\t\t{\n");
2806 wprintf ("\t\t\t\t\tElement.hide('indicator')\n");
2807 wprintf ("\t\t\t\t},\n");
2808 wprintf ("\t\t\t\tonLoading:function(request)\n");
2809 wprintf ("\t\t\t\t{\n");
2810 wprintf ("\t\t\t\t\tElement.show('indicator')\n");
2811 wprintf ("\t\t\t\t},\n");
2812 wprintf ("\t\t\t\tparameters:'id=' + encodeURIComponent(element.id)\n");
2813 wprintf ("\t\t\t})\n");
2814 wprintf ("\t\t}\n");
2816 // wprintf ("//]]>\n");
2817 wprintf ("</script>\n");
2824 do_tasks_view(); /** Render the task list */
2828 do_calendar_view(); /** Render the calendar */
2831 if (is_addressbook) {
2832 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2835 /** Note: wDumpContent() will output one additional </div> tag. */
2836 wprintf("</div>\n"); /** end of 'content' div */
2839 /** free the summary */
2840 if (WCC->summ != NULL) {
2845 if (addrbook != NULL) free(addrbook);
2850 * \brief Back end for post_message()
2851 * ... this is where the actual message gets transmitted to the server.
2853 void post_mime_to_server(void) {
2855 int is_multipart = 0;
2857 struct wc_attachment *att;
2860 size_t encoded_length;
2861 size_t encoded_strlen;
2863 /** RFC2045 requires this, and some clients look for it... */
2864 serv_puts("MIME-Version: 1.0");
2865 serv_puts("X-Mailer: " PACKAGE_STRING);
2867 /** If there are attachments, we have to do multipart/mixed */
2868 if (WC->first_attachment != NULL) {
2872 // if (is_multipart) {
2873 sprintf(boundary, "Citadel--Multipart--%s--%04x--%04x",
2874 serv_info.serv_fqdn,
2879 /** Remember, serv_printf() appends an extra newline */
2881 serv_printf("Content-type: multipart/mixed; "
2882 "boundary=\"%s\"\n", boundary);
2884 serv_printf("Content-type: multipart/alternative; "
2885 "boundary=\"%s\"\n", boundary);
2886 serv_printf("This is a multipart message in MIME format.\n");
2887 serv_printf("--%s", boundary);
2890 serv_puts("Content-type: text/html; charset=utf-8");
2891 serv_puts("Content-Transfer-Encoding: quoted-printable");
2893 serv_puts("<html><body>\r\n");
2894 text_to_server_qp(bstr("msgtext")); /** Transmit message in quoted-printable encoding */
2895 serv_puts("</body></html>\r\n");
2897 serv_puts("Content-type: text/plain; charset=utf-8");
2898 serv_puts("Content-Transfer-Encoding: quoted-printable");
2901 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
2902 text_to_server_qp(txtmail); /** Transmit message in quoted-printable encoding */
2905 serv_printf("--%s", boundary);
2909 /** Add in the attachments */
2910 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2912 encoded_length = ((att->length * 150) / 100);
2913 encoded = malloc(encoded_length);
2914 if (encoded == NULL) break;
2915 encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1);
2917 serv_printf("--%s", boundary);
2918 serv_printf("Content-type: %s", att->content_type);
2919 serv_printf("Content-disposition: attachment; "
2920 "filename=\"%s\"", att->filename);
2921 serv_puts("Content-transfer-encoding: base64");
2923 serv_write(encoded, encoded_strlen);
2928 serv_printf("--%s--", boundary);
2936 * \brief Post message (or don't post message)
2938 * Note regarding the "dont_post" variable:
2939 * A random value (actually, it's just a timestamp) is inserted as a hidden
2940 * field called "postseq" when the display_enter page is generated. This
2941 * value is checked when posting, using the static variable dont_post. If a
2942 * user attempts to post twice using the same dont_post value, the message is
2943 * discarded. This prevents the accidental double-saving of the same message
2944 * if the user happens to click the browser "back" button.
2946 void post_message(void)
2949 char encoded_subject[1024];
2950 static long dont_post = (-1L);
2951 struct wc_attachment *att, *aptr;
2952 int is_anonymous = 0;
2955 if (!IsEmptyStr(bstr("force_room"))) {
2956 gotoroom(bstr("force_room"));
2959 display_name = bstr("display_name");
2960 if (!strcmp(display_name, "__ANONYMOUS__")) {
2965 if (WC->upload_length > 0) {
2967 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WC->upload_length);
2968 /** There's an attachment. Save it to this struct... */
2969 att = malloc(sizeof(struct wc_attachment));
2970 memset(att, 0, sizeof(struct wc_attachment));
2971 att->length = WC->upload_length;
2972 strcpy(att->content_type, WC->upload_content_type);
2973 strcpy(att->filename, WC->upload_filename);
2976 /** And add it to the list. */
2977 if (WC->first_attachment == NULL) {
2978 WC->first_attachment = att;
2981 aptr = WC->first_attachment;
2982 while (aptr->next != NULL) aptr = aptr->next;
2987 * Mozilla sends a simple filename, which is what we want,
2988 * but Satan's Browser sends an entire pathname. Reduce
2989 * the path to just a filename if we need to.
2991 while (num_tokens(att->filename, '/') > 1) {
2992 remove_token(att->filename, 0, '/');
2994 while (num_tokens(att->filename, '\\') > 1) {
2995 remove_token(att->filename, 0, '\\');
2999 * Transfer control of this memory from the upload struct
3000 * to the attachment struct.
3002 att->data = WC->upload;
3003 WC->upload_length = 0;
3009 if (!IsEmptyStr(bstr("cancel_button"))) {
3010 sprintf(WC->ImportantMessage,
3011 _("Cancelled. Message was not posted."));
3012 } else if (!IsEmptyStr(bstr("attach_button"))) {
3015 } else if (atol(bstr("postseq")) == dont_post) {
3016 sprintf(WC->ImportantMessage,
3017 _("Automatically cancelled because you have already "
3018 "saved this message."));
3020 webcit_rfc2047encode(encoded_subject, sizeof encoded_subject, bstr("subject"));
3021 sprintf(buf, "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s",
3029 bstr("my_email_addr")
3032 serv_getln(buf, sizeof buf);
3033 if (buf[0] == '4') {
3034 post_mime_to_server();
3035 if ( (!IsEmptyStr(bstr("recp")))
3036 || (!IsEmptyStr(bstr("cc" )))
3037 || (!IsEmptyStr(bstr("bcc" )))
3039 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
3042 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
3044 dont_post = atol(bstr("postseq"));
3046 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
3047 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3053 free_attachments(WC);
3056 * We may have been supplied with instructions regarding the location
3057 * to which we must return after posting. If found, go there.
3059 if (!IsEmptyStr(bstr("return_to"))) {
3060 http_redirect(bstr("return_to"));
3063 * If we were editing a page in a wiki room, go to that page now.
3065 else if (!IsEmptyStr(bstr("wikipage"))) {
3066 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
3070 * Otherwise, just go to the "read messages" loop.
3073 readloop("readnew");
3081 * \brief display the message entry screen
3083 void display_enter(void)
3089 struct wc_attachment *att;
3090 int recipient_required = 0;
3091 int subject_required = 0;
3092 int recipient_bad = 0;
3094 int is_anonymous = 0;
3095 long existing_page = (-1L);
3099 if (!IsEmptyStr(bstr("force_room"))) {
3100 gotoroom(bstr("force_room"));
3103 display_name = bstr("display_name");
3104 if (!strcmp(display_name, "__ANONYMOUS__")) {
3109 /** First test to see whether this is a room that requires recipients to be entered */
3110 serv_puts("ENT0 0");
3111 serv_getln(buf, sizeof buf);
3113 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
3114 recipient_required = 1;
3116 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3117 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3118 readloop("readnew");
3122 /* Is the server strongly recommending that the user enter a message subject? */
3123 if ((buf[3] != '\0') && (buf[4] != '\0')) {
3124 subject_required = extract_int(&buf[4], 1);
3128 * Are we perhaps in an address book view? If so, then an "enter
3129 * message" command really means "add new entry."
3131 if (WC->wc_default_view == VIEW_ADDRESSBOOK) {
3132 do_edit_vcard(-1, "", "", WC->wc_roomname);
3136 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
3138 * Are we perhaps in a calendar room? If so, then an "enter
3139 * message" command really means "add new calendar item."
3141 if (WC->wc_default_view == VIEW_CALENDAR) {
3142 display_edit_event();
3147 * Are we perhaps in a tasks view? If so, then an "enter
3148 * message" command really means "add new task."
3150 if (WC->wc_default_view == VIEW_TASKS) {
3151 display_edit_task();
3157 * Otherwise proceed normally.
3158 * Do a custom room banner with no navbar...
3160 output_headers(1, 1, 2, 0, 0, 0);
3161 wprintf("<div id=\"banner\">\n");
3162 embed_room_banner(NULL, navbar_none);
3163 wprintf("</div>\n");
3164 wprintf("<div id=\"content\">\n"
3165 "<div class=\"fix_scrollbar_bug message \">");
3167 /** Now check our actual recipients if there are any */
3168 if (recipient_required) {
3169 sprintf(buf, "ENT0 0|%s|%d|0||%s||%s|%s|%s",
3173 bstr("cc"), bstr("bcc"), bstr("wikipage"));
3175 serv_getln(buf, sizeof buf);
3177 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
3178 if (!IsEmptyStr(bstr("recp")) &&
3179 !IsEmptyStr(bstr("cc" )) &&
3180 !IsEmptyStr(bstr("bcc" ))) {
3184 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3185 wprintf("<em>%s</em><br />\n", &buf[4]);
3190 /** If we got this far, we can display the message entry screen. */
3192 /** begin message entry screen */
3194 "enctype=\"multipart/form-data\" "
3196 "accept-charset=\"UTF-8\" "
3198 "name=\"enterform\""
3200 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
3201 if (WC->wc_view == VIEW_WIKI) {
3202 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
3204 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
3205 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
3206 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
3207 escputs(WC->wc_roomname);
3210 /** submit or cancel buttons */
3211 wprintf("<p class=\"send_edit_msg\">");
3212 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3213 if (recipient_required) {
3214 wprintf(_("Send message"));
3216 wprintf(_("Post message"));
3219 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3224 wprintf("<img src=\"static/newmess3_24x.gif\" class=\"imgedit\">");
3225 wprintf(" "); /** header bar */
3226 webcit_fmt_date(buf, now, 0);
3228 wprintf("\n"); /** header bar */
3230 wprintf("<table width=\"100%%\" class=\"edit_msg_table\">");
3232 wprintf("<th><label for=\"from_id\" > ");
3233 wprintf(_(" <I>from</I> "));
3234 wprintf("</label></th>");
3236 wprintf("<td colspan=\"2\">");
3238 /* Allow the user to select any of his valid screen names */
3240 wprintf("<select name=\"display_name\" size=1 id=\"from_id\">\n");
3243 serv_getln(buf, sizeof buf);
3244 if (buf[0] == '1') {
3245 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3246 wprintf("<option %s value=\"",
3247 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
3252 wprintf("</option>\n");
3256 if (WC->room_flags & QR_ANONOPT) {
3257 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
3258 ((!strcasecmp(bstr("__ANONYMOUS__"), WC->wc_fullname)) ? "selected" : ""),
3263 wprintf("</select>\n");
3265 /* If this is an email (not a post), allow the user to select any of his
3266 * valid email addresses.
3268 if (recipient_required) {
3270 serv_getln(buf, sizeof buf);
3271 if (buf[0] == '1') {
3272 wprintf("<select name=\"my_email_addr\" size=1>\n");
3273 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3274 wprintf("<option value=\"");
3278 wprintf("></option>\n");
3280 wprintf("</select>\n");
3284 wprintf(_(" <I>in</I> "));
3285 escputs(WC->wc_roomname);
3287 wprintf("</td></tr>");
3289 if (recipient_required) {
3293 wprintf("<tr><th><label for=\"recp_id\"> ");
3295 wprintf("</label></th>"
3296 "<td><input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
3297 ccraw = bstr("recp");
3298 len = strlen(ccraw);
3299 copy = (char*) malloc(len * 2 + 1);
3300 memcpy(copy, ccraw, len + 1);
3302 utf8ify_rfc822_string(copy);
3306 wprintf("\" size=45 maxlength=1000 />");
3307 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
3308 wprintf("</td><td rowspan=\"3\" align=\"left\" valign=\"top\">");
3310 /** Pop open an address book -- begin **/
3312 "<a href=\"javascript:PopOpenAddressBook('recp_id|%s|cc_id|%s|bcc_id|%s');\" "
3314 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
3316 _("To:"), _("CC:"), _("BCC:"),
3317 _("Contacts"), _("Contacts")
3319 /** Pop open an address book -- end **/
3321 wprintf("</td></tr>");
3323 wprintf("<tr><th><label for=\"cc_id\"> ");
3325 wprintf("</label></th>"
3326 "<td><input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
3328 len = strlen(ccraw);
3329 copy = (char*) malloc(len * 2 + 1);
3330 memcpy(copy, ccraw, len + 1);
3332 utf8ify_rfc822_string(copy);
3336 wprintf("\" size=45 maxlength=1000 />");
3337 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
3338 wprintf("</td></tr>");
3340 wprintf("<tr><th><label for=\"bcc_id\"> ");
3342 wprintf("</label></th>"
3343 "<td><input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
3344 ccraw = bstr("bcc");
3345 len = strlen(ccraw);
3346 copy = (char*) malloc(len * 2 + 1);
3347 memcpy(copy, ccraw, len + 1);
3349 utf8ify_rfc822_string(copy);
3353 wprintf("\" size=45 maxlength=1000 />");
3354 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
3355 wprintf("</td></tr>");
3357 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
3358 wprintf("<script type=\"text/javascript\"> \n"
3359 " activate_entmsg_autocompleters(); \n"
3365 wprintf("<tr><th><label for=\"subject_id\" > ");
3366 if (recipient_required || subject_required) {
3367 wprintf(_("Subject:"));
3370 wprintf(_("Subject (optional):"));
3372 wprintf("</label></th>"
3373 "<td colspan=\"2\">"
3374 "<input type=\"text\" name=\"subject\" id=\"subject_id\" value=\"");
3375 escputs(bstr("subject"));
3376 wprintf("\" size=45 maxlength=70>\n");
3377 wprintf("</td></tr>");
3379 wprintf("<tr><td colspan=\"3\">\n");
3381 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
3383 /** If we're continuing from a previous edit, put our partially-composed message back... */
3384 msgescputs(bstr("msgtext"));
3386 /* If we're forwarding a message, insert it here... */
3387 if (atol(bstr("fwdquote")) > 0L) {
3388 wprintf("<br><div align=center><i>");
3389 wprintf(_("--- forwarded message ---"));
3390 wprintf("</i></div><br>");
3391 pullquote_message(atol(bstr("fwdquote")), 1, 1);
3394 /** If we're replying quoted, insert the quote here... */
3395 else if (atol(bstr("replyquote")) > 0L) {
3398 pullquote_message(atol(bstr("replyquote")), 0, 1);
3399 wprintf("</blockquote><br>");
3402 /** If we're editing a wiki page, insert the existing page here... */
3403 else if (WC->wc_view == VIEW_WIKI) {
3404 safestrncpy(buf, bstr("wikipage"), sizeof buf);
3405 str_wiki_index(buf);
3406 existing_page = locate_message_by_uid(buf);
3407 if (existing_page >= 0L) {
3408 pullquote_message(existing_page, 1, 0);
3412 /** Insert our signature if appropriate... */
3413 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
3414 get_preference("use_sig", buf, sizeof buf);
3415 if (!strcasecmp(buf, "yes")) {
3417 get_preference("signature", ebuf, sizeof ebuf);
3418 euid_unescapize(buf, ebuf);
3419 wprintf("<br>--<br>");
3421 for (i=0; i<len; ++i) {
3422 if (buf[i] == '\n') {
3425 else if (buf[i] == '<') {
3428 else if (buf[i] == '>') {
3431 else if (buf[i] == '&') {
3434 else if (buf[i] == '\"') {
3437 else if (buf[i] == '\'') {
3440 else if (isprint(buf[i])) {
3441 wprintf("%c", buf[i]);
3447 wprintf("</textarea>\n");
3449 /** Make sure we only insert our signature once */
3450 /** We don't care if it was there or not before, it needs to be there now. */
3451 wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
3454 * The following template embeds the TinyMCE richedit control, and automatically
3455 * transforms the textarea into a richedit textarea.
3457 do_template("richedit");
3459 /** Enumerate any attachments which are already in place... */
3460 wprintf("<div class=\"attachment buttons\"><img src=\"static/diskette_24x.gif\" class=\"imgedit\" > ");
3461 wprintf(_("Attachments:"));
3463 wprintf("<select name=\"which_attachment\" size=1>");
3464 for (att = WC->first_attachment; att != NULL; att = att->next) {
3465 wprintf("<option value=\"");
3466 urlescputs(att->filename);
3468 escputs(att->filename);
3469 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3470 wprintf("</option>\n");
3472 wprintf("</select>");
3474 /** Now offer the ability to attach additional files... */
3475 wprintf(" ");
3476 wprintf(_("Attach file:"));
3477 wprintf(" <input name=\"attachfile\" class=\"attachfile\" "
3478 "size=16 type=\"file\">\n "
3479 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3480 wprintf("</div>"); /* End of "attachment buttons" div */
3483 wprintf("</td></tr></table>");
3485 wprintf("</form>\n");
3486 wprintf("</div>\n"); /* end of "fix_scrollbar_bug" div */
3488 /* NOTE: address_book_popup() will close the "content" div. Don't close it here. */
3489 DONE: address_book_popup();
3495 * \brief delete a message
3497 void delete_msg(void)
3502 msgid = atol(bstr("msgid"));
3504 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3505 serv_printf("DELE %ld", msgid);
3507 else { /** Otherwise move it to Trash */
3508 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3511 serv_getln(buf, sizeof buf);
3512 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3514 readloop("readnew");
3519 * \brief move a message to another folder
3526 msgid = atol(bstr("msgid"));
3528 if (!IsEmptyStr(bstr("move_button"))) {
3529 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3531 serv_getln(buf, sizeof buf);
3532 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3534 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3537 readloop("readnew");
3545 * \brief Confirm move of a message
3547 void confirm_move_msg(void)
3553 msgid = atol(bstr("msgid"));
3556 output_headers(1, 1, 2, 0, 0, 0);
3557 wprintf("<div id=\"banner\">\n");
3559 wprintf(_("Confirm move of message"));
3561 wprintf("</div>\n");
3563 wprintf("<div id=\"content\" class=\"service\">\n");
3565 wprintf("<CENTER>");
3567 wprintf(_("Move this message to:"));
3568 wprintf("<br />\n");
3570 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3571 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
3572 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3574 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3576 serv_getln(buf, sizeof buf);
3577 if (buf[0] == '1') {
3578 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3579 extract_token(targ, buf, 0, '|', sizeof targ);
3580 wprintf("<OPTION>");
3585 wprintf("</SELECT>\n");
3586 wprintf("<br />\n");
3588 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3590 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3591 wprintf("</form></CENTER>\n");
3593 wprintf("</CENTER>\n");