4 * Functions which deal with the fetching and displaying of messages.
12 #define SUBJ_COL_WIDTH_PCT 50 /**< Mailbox view column width */
13 #define SENDER_COL_WIDTH_PCT 30 /**< Mailbox view column width */
14 #define DATE_PLUS_BUTTONS_WIDTH_PCT 20 /**< Mailbox view column width */
16 void display_enter(void);
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 * 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 * tocode Target encoding
37 * 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 inline char *FindNextEnd (char *bptr)
60 /* Find the next ?Q? */
61 end = strchr(bptr + 2, '?');
62 if (end == NULL) return NULL;
63 if (((*(end + 1) == 'B') || (*(end + 1) == 'Q')) &&
64 (*(end + 2) == '?')) {
65 /* skip on to the end of the cluster, the next ?= */
66 end = strstr(end + 3, "?=");
69 /* sort of half valid encoding, try to find an end. */
70 end = strstr(bptr, "?=");
75 * Handle subjects with RFC2047 encoding such as:
76 * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=
78 void utf8ify_rfc822_string(char *buf) {
79 char *start, *end, *next, *nextend, *ptr;
84 iconv_t ic = (iconv_t)(-1) ;
85 char *ibuf; /**< Buffer of characters to be converted */
86 char *obuf; /**< Buffer for converted characters */
87 size_t ibuflen; /**< Length of input buffer */
88 size_t obuflen; /**< Length of output buffer */
89 char *isav; /**< Saved pointer to input buffer */
90 char *osav; /**< Saved pointer to output buffer */
93 int illegal_non_rfc2047_encoding = 0;
95 /* Sometimes, badly formed messages contain strings which were simply
96 * written out directly in some foreign character set instead of
97 * using RFC2047 encoding. This is illegal but we will attempt to
98 * handle it anyway by converting from a user-specified default
99 * charset to UTF-8 if we see any nonprintable characters.
102 for (i=0; i<len; ++i) {
103 if ((buf[i] < 32) || (buf[i] > 126)) {
104 illegal_non_rfc2047_encoding = 1;
105 i = len; ///< take a shortcut, it won't be more than one.
108 if (illegal_non_rfc2047_encoding) {
109 StrBuf *default_header_charset;
110 get_preference("default_header_charset", &default_header_charset);
111 if ( (strcasecmp(ChrPtr(default_header_charset), "UTF-8")) &&
112 (strcasecmp(ChrPtr(default_header_charset), "us-ascii")) ) {
113 ic = ctdl_iconv_open("UTF-8", ChrPtr(default_header_charset));
114 if (ic != (iconv_t)(-1) ) {
117 safestrncpy(ibuf, buf, 1024);
118 ibuflen = strlen(ibuf);
120 obuf = (char *) malloc(obuflen);
122 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
123 osav[1024-obuflen] = 0;
132 /* pre evaluate the first pair */
133 nextend = end = NULL;
135 start = strstr(buf, "=?");
137 end = FindNextEnd (start);
139 while ((start != NULL) && (end != NULL))
141 next = strstr(end, "=?");
143 nextend = FindNextEnd(next);
147 /* did we find two partitions */
148 if ((next != NULL) &&
152 while ((ptr < next) &&
158 /* did we find a gab just filled with blanks? */
163 len - (next - start));
165 /* now terminate the gab at the end */
166 delta = (next - end) - 2;
170 /* move next to its new location. */
175 /* our next-pair is our new first pair now. */
180 /* Now we handle foreign character sets properly encoded
183 while (start=strstr(buf, "=?"), end=FindNextEnd((start != NULL)? start : buf),
184 ((start != NULL) && (end != NULL) && (end > start)) )
186 extract_token(charset, start, 1, '?', sizeof charset);
187 extract_token(encoding, start, 2, '?', sizeof encoding);
188 extract_token(istr, start, 3, '?', sizeof istr);
192 if (!strcasecmp(encoding, "B")) { /**< base64 */
193 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
195 else if (!strcasecmp(encoding, "Q")) { /**< quoted-printable */
203 if (istr[pos] == '_') istr[pos] = ' ';
207 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, len);
210 strcpy(ibuf, istr); /**< unknown encoding */
211 ibuflen = strlen(istr);
214 ic = ctdl_iconv_open("UTF-8", charset);
215 if (ic != (iconv_t)(-1) ) {
217 obuf = (char *) malloc(obuflen);
219 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
220 osav[1024-obuflen] = 0;
225 remove_token(end, 0, '?');
226 remove_token(end, 0, '?');
227 remove_token(end, 0, '?');
228 remove_token(end, 0, '?');
229 strcpy(end, &end[1]);
231 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
240 remove_token(end, 0, '?');
241 remove_token(end, 0, '?');
242 remove_token(end, 0, '?');
243 remove_token(end, 0, '?');
244 strcpy(end, &end[1]);
246 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
253 * Since spammers will go to all sorts of absurd lengths to get their
254 * messages through, there are LOTS of corrupt headers out there.
255 * So, prevent a really badly formed RFC2047 header from throwing
256 * this function into an infinite loop.
259 if (passes > 20) return;
264 inline void utf8ify_rfc822_string(char *a){};
272 * \brief RFC2047-encode a header field if necessary.
273 * If no non-ASCII characters are found, the string
274 * will be copied verbatim without encoding.
276 * \param target Target buffer.
277 * \param maxlen Maximum size of target buffer.
278 * \param source Source string to be encoded.
279 * \param SourceLen Length of the source string
280 * \returns encoded length; -1 if non success.
282 int webcit_rfc2047encode(char *target, int maxlen, char *source, long SourceLen)
284 const char headerStr[] = "=?UTF-8?Q?";
285 int need_to_encode = 0;
290 if ((source == NULL) ||
292 (SourceLen > maxlen)) return -1;
294 while ((!IsEmptyStr (&source[i])) &&
295 (need_to_encode == 0) &&
297 if (((unsigned char) source[i] < 32) ||
298 ((unsigned char) source[i] > 126)) {
304 if (!need_to_encode) {
305 memcpy (target, source, SourceLen);
306 target[SourceLen] = '\0';
310 if (sizeof (headerStr + SourceLen + 2) > maxlen)
312 memcpy (target, headerStr, sizeof (headerStr));
313 len = sizeof (headerStr) - 1;
314 for (i=0; (i < SourceLen) && (len + 3< maxlen) ; ++i) {
315 ch = (unsigned char) source[i];
316 if ((ch < 32) || (ch > 126) || (ch == 61)) {
317 sprintf(&target[len], "=%02X", ch);
321 sprintf(&target[len], "%c", ch);
326 if (len + 2 < maxlen) {
327 strcat(&target[len], "?=");
339 * Look for URL's embedded in a buffer and make them linkable. We use a
340 * target window in order to keep the Citadel session in its own window.
342 void url(char *buf, size_t bufsize)
344 int len, UrlLen, Offset, TrailerLen, outpos;
345 char *start, *end, *pos;
352 lprintf(1, "URL: content longer than buffer!");
356 for (pos = buf; (pos < end) && (start == NULL); ++pos) {
357 if (!strncasecmp(pos, "http://", 7))
359 if (!strncasecmp(pos, "ftp://", 6))
366 for (pos = buf+len; pos > start; --pos) {
367 if ( (!isprint(*pos))
386 UrlLen = end - start;
387 if (UrlLen > sizeof(urlbuf)){
388 lprintf(1, "URL: content longer than buffer!");
391 memcpy(urlbuf, start, UrlLen);
392 urlbuf[UrlLen] = '\0';
394 Offset = start - buf;
395 if ((Offset != 0) && (Offset < sizeof(outbuf)))
396 memcpy(outbuf, buf, Offset);
397 outpos = snprintf(&outbuf[Offset], sizeof(outbuf) - Offset,
398 "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
399 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
400 if (outpos >= sizeof(outbuf) - Offset) {
401 lprintf(1, "URL: content longer than buffer!");
405 TrailerLen = len - (end - start);
407 memcpy(outbuf + Offset + outpos, end, TrailerLen);
408 if (Offset + outpos + TrailerLen > bufsize) {
409 lprintf(1, "URL: content longer than buffer!");
412 memcpy (buf, outbuf, Offset + outpos + TrailerLen);
413 *(buf + Offset + outpos + TrailerLen) = '\0';
418 * \brief Turn a vCard "n" (name) field into something displayable.
419 * \param name the name field to convert
421 void vcard_n_prettyize(char *name)
426 original_name = strdup(name);
427 len = strlen(original_name);
428 for (i=0; i<5; ++i) {
430 if (original_name[len-1] == ' ') {
431 original_name[--len] = 0;
433 if (original_name[len-1] == ';') {
434 original_name[--len] = 0;
440 for (i=0; i<len; ++i) {
441 if (original_name[i] == ';') {
446 name[j++] = original_name[i];
457 * \brief preparse a vcard name
458 * display_vcard() calls this after parsing the textual vCard into
459 * our 'struct vCard' data object.
460 * This gets called instead of display_parsed_vcard() if we are only looking
461 * to extract the person's name instead of displaying the card.
462 * \param v the vcard to retrieve the name from
463 * \param storename where to put the name at
465 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
468 strcpy(storename, "");
470 name = vcard_get_prop(v, "n", 1, 0, 0);
472 strcpy(storename, name);
473 /* vcard_n_prettyize(storename); */
481 * \brief html print a vcard
482 * display_vcard() calls this after parsing the textual vCard into
483 * our 'struct vCard' data object.
485 * Set 'full' to nonzero to display the full card, otherwise it will only
486 * show a summary line.
488 * This code is a bit ugly, so perhaps an explanation is due: we do this
489 * in two passes through the vCard fields. On the first pass, we process
490 * fields we understand, and then render them in a pretty fashion at the
491 * end. Then we make a second pass, outputting all the fields we don't
492 * understand in a simple two-column name/value format.
493 * \param v the vCard to display
494 * \param full display all items of the vcard?
495 * \param msgnum Citadel message pointer
497 void display_parsed_vcard(struct vCard *v, int full, long msgnum) {
503 char *thisname, *thisvalue;
504 char firsttoken[SIZ];
513 strcpy(fullname, "");
521 name = vcard_get_prop(v, "fn", 1, 0, 0);
525 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
526 strcpy(fullname, name);
527 vcard_n_prettyize(fullname);
537 wprintf("<div align=center>"
538 "<table bgcolor=#aaaaaa width=50%%>");
539 for (pass=1; pass<=2; ++pass) {
541 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
543 thisname = strdup(v->prop[i].name);
544 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
546 for (j=0; j<num_tokens(thisname, ';'); ++j) {
547 extract_token(buf, thisname, j, ';', sizeof buf);
548 if (!strcasecmp(buf, "encoding=quoted-printable")) {
550 remove_token(thisname, j, ';');
552 if (!strcasecmp(buf, "encoding=base64")) {
554 remove_token(thisname, j, ';');
558 len = strlen(v->prop[i].value);
559 /* if we have some untagged QP, detect it here. */
560 if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
561 utf8ify_rfc822_string(v->prop[i].value);
564 // %ff can become 6 bytes in utf8
565 thisvalue = malloc(len * 2 + 3);
566 j = CtdlDecodeQuotedPrintable(
567 thisvalue, v->prop[i].value,
572 // ff will become one byte..
573 thisvalue = malloc(len + 50);
575 thisvalue, v->prop[i].value,
576 strlen(v->prop[i].value) );
579 thisvalue = strdup(v->prop[i].value);
582 /** Various fields we may encounter ***/
584 /** N is name, but only if there's no FN already there */
585 if (!strcasecmp(firsttoken, "n")) {
586 if (IsEmptyStr(fullname)) {
587 strcpy(fullname, thisvalue);
588 vcard_n_prettyize(fullname);
592 /** FN (full name) is a true 'display name' field */
593 else if (!strcasecmp(firsttoken, "fn")) {
594 strcpy(fullname, thisvalue);
598 else if (!strcasecmp(firsttoken, "title")) {
599 strcpy(title, thisvalue);
603 else if (!strcasecmp(firsttoken, "org")) {
604 strcpy(org, thisvalue);
607 else if (!strcasecmp(firsttoken, "email")) {
609 if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
611 "<a href=\"display_enter"
612 "?force_room=_MAIL_?recp=");
614 len = strlen(mailto);
615 urlesc(&mailto[len], SIZ - len, "\"");
616 len = strlen(mailto);
617 urlesc(&mailto[len], SIZ - len, fullname);
618 len = strlen(mailto);
619 urlesc(&mailto[len], SIZ - len, "\" <");
620 len = strlen(mailto);
621 urlesc(&mailto[len], SIZ - len, thisvalue);
622 len = strlen(mailto);
623 urlesc(&mailto[len], SIZ - len, ">");
625 strcat(mailto, "\">");
626 len = strlen(mailto);
627 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
628 strcat(mailto, "</A>");
630 else if (!strcasecmp(firsttoken, "tel")) {
631 if (!IsEmptyStr(phone)) strcat(phone, "<br />");
632 strcat(phone, thisvalue);
633 for (j=0; j<num_tokens(thisname, ';'); ++j) {
634 extract_token(buf, thisname, j, ';', sizeof buf);
635 if (!strcasecmp(buf, "tel"))
637 else if (!strcasecmp(buf, "work"))
638 strcat(phone, _(" (work)"));
639 else if (!strcasecmp(buf, "home"))
640 strcat(phone, _(" (home)"));
641 else if (!strcasecmp(buf, "cell"))
642 strcat(phone, _(" (cell)"));
650 else if (!strcasecmp(firsttoken, "adr")) {
653 wprintf(_("Address:"));
654 wprintf("</TD><TD>");
655 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
656 extract_token(buf, thisvalue, j, ';', sizeof buf);
657 if (!IsEmptyStr(buf)) {
659 if (j<3) wprintf("<br />");
663 wprintf("</TD></TR>\n");
666 /* else if (!strcasecmp(firsttoken, "photo") && full && pass == 2) {
667 // Only output on second pass
669 wprintf(_("Photo:"));
670 wprintf("</td><td>");
671 wprintf("<img src=\"/vcardphoto/%ld/\" alt=\"Contact photo\"/>",msgnum);
672 wprintf("</td></tr>\n");
674 else if (!strcasecmp(firsttoken, "version")) {
677 else if (!strcasecmp(firsttoken, "rev")) {
680 else if (!strcasecmp(firsttoken, "label")) {
685 /*** Don't show extra fields. They're ugly.
689 wprintf("</TD><TD>");
691 wprintf("</TD></TR>\n");
701 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
702 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
703 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
704 "<FONT SIZE=+1><B>");
706 wprintf("</B></FONT>");
707 if (!IsEmptyStr(title)) {
708 wprintf("<div align=right>");
712 if (!IsEmptyStr(org)) {
713 wprintf("<div align=right>");
717 wprintf("</TD></TR>\n");
719 if (!IsEmptyStr(phone)) {
721 wprintf(_("Telephone:"));
722 wprintf("</td><td>%s</td></tr>\n", phone);
724 if (!IsEmptyStr(mailto)) {
726 wprintf(_("E-mail:"));
727 wprintf("</td><td>%s</td></tr>\n", mailto);
733 wprintf("</table></div>\n");
739 * \brief Display a textual vCard
740 * (Converts to a vCard object and then calls the actual display function)
741 * Set 'full' to nonzero to display the whole card instead of a one-liner.
742 * Or, if "storename" is non-NULL, just store the person's name in that
743 * buffer instead of displaying the card at all.
744 * \param vcard_source the buffer containing the vcard text
745 * \param alpha what???
746 * \param full should we usse all lines?
747 * \param storename where to store???
748 * \param msgnum Citadel message pointer
750 void display_vcard(char *vcard_source, char alpha, int full, char *storename,
757 v = vcard_load(vcard_source);
758 if (v == NULL) return;
760 name = vcard_get_prop(v, "n", 1, 0, 0);
762 utf8ify_rfc822_string(name);
767 if (storename != NULL) {
768 fetchname_parsed_vcard(v, storename);
770 else if ( (alpha == 0)
771 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
772 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
774 display_parsed_vcard(v, full,msgnum);
788 * I wanna SEE that message!
790 * msgnum Message number to display
791 * printable_view Nonzero to display a printable view
792 * section Optional for encapsulated message/rfc822 submessage
794 void read_message(long msgnum, int printable_view, char *section) {
796 char mime_partnum[256] = "";
797 char mime_name[256] = "";
798 char mime_filename[256] = "";
799 char escaped_mime_filename[256] = "";
800 char mime_content_type[256] = "";
801 const char *mime_content_type_ptr;
802 char mime_charset[256] = "";
803 char mime_disposition[256] = "";
805 struct attach_link *attach_links = NULL;
806 int num_attach_links = 0;
807 char mime_submessages[256] = "";
808 char m_subject[1024] = "";
809 char m_cc[1024] = "";
813 char reply_to[512] = "";
814 char reply_all[4096] = "";
815 char reply_references[1024] = "";
816 char reply_inreplyto[256] = "";
822 char vcard_partnum[256] = "";
823 char cal_partnum[256] = "";
824 char *part_source = NULL;
825 char msg4_partnum[32] = "";
827 iconv_t ic = (iconv_t)(-1) ;
828 char *ibuf; /**< Buffer of characters to be converted */
829 char *obuf; /**< Buffer for converted characters */
830 size_t ibuflen; /**< Length of input buffer */
831 size_t obuflen; /**< Length of output buffer */
832 char *osav; /**< Saved pointer to output buffer */
835 strcpy(mime_content_type, "text/plain");
836 strcpy(mime_charset, "us-ascii");
837 strcpy(mime_submessages, "");
839 serv_printf("MSG4 %ld|%s", msgnum, section);
840 serv_getln(buf, sizeof buf);
843 wprintf(_("ERROR:"));
844 wprintf("</strong> %s<br />\n", &buf[4]);
848 /** begin everythingamundo table */
849 if (!printable_view) {
850 wprintf("<div class=\"fix_scrollbar_bug message\" ");
851 wprintf("onMouseOver=document.getElementById(\"msg%ld\").style.visibility=\"visible\" ", msgnum);
852 wprintf("onMouseOut=document.getElementById(\"msg%ld\").style.visibility=\"hidden\" >", msgnum);
855 /** begin message header table */
856 wprintf("<div class=\"message_header\">");
858 strcpy(m_subject, "");
861 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
862 if (!strcmp(buf, "000")) {
864 wprintf(_("unexpected end of message"));
865 wprintf(" (1)</i><br /><br />\n");
869 if (!strncasecmp(buf, "nhdr=yes", 8))
873 if (!strncasecmp(buf, "type=", 5))
874 format_type = atoi(&buf[5]);
875 if (!strncasecmp(buf, "from=", 5)) {
876 strcpy(from, &buf[5]);
878 wprintf("<a href=\"showuser?who=");
879 utf8ify_rfc822_string(from);
885 if (!strncasecmp(buf, "subj=", 5)) {
886 safestrncpy(m_subject, &buf[5], sizeof m_subject);
888 if (!strncasecmp(buf, "msgn=", 5)) {
889 safestrncpy(reply_inreplyto, &buf[5], sizeof reply_inreplyto);
891 if (!strncasecmp(buf, "wefw=", 5)) {
892 safestrncpy(reply_references, &buf[5], sizeof reply_references);
894 if (!strncasecmp(buf, "cccc=", 5)) {
896 safestrncpy(m_cc, &buf[5], sizeof m_cc);
897 if (!IsEmptyStr(reply_all)) {
898 strcat(reply_all, ", ");
900 len = strlen(reply_all);
901 safestrncpy(&reply_all[len], &buf[5],
902 (sizeof reply_all - len) );
904 if ((!strncasecmp(buf, "hnod=", 5))
905 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
906 wprintf("(%s) ", &buf[5]);
908 if ((!strncasecmp(buf, "room=", 5))
909 && (strcasecmp(&buf[5], WC->wc_roomname))
910 && (!IsEmptyStr(&buf[5])) ) {
912 wprintf("%s> ", &buf[5]);
914 if (!strncasecmp(buf, "rfca=", 5)) {
915 strcpy(rfca, &buf[5]);
921 if (!strncasecmp(buf, "node=", 5)) {
922 strcpy(node, &buf[5]);
923 if ( ((WC->room_flags & QR_NETWORK)
924 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
925 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
926 && (IsEmptyStr(rfca))
928 wprintf("@%s ", &buf[5]);
931 if (!strncasecmp(buf, "rcpt=", 5)) {
934 if (!IsEmptyStr(reply_all)) {
935 strcat(reply_all, ", ");
937 len = strlen(reply_all);
938 safestrncpy(&reply_all[len], &buf[5],
939 (sizeof reply_all - len) );
940 utf8ify_rfc822_string(&buf[5]);
944 if (!strncasecmp(buf, "time=", 5)) {
945 webcit_fmt_date(now, atol(&buf[5]), 0);
951 if (!strncasecmp(buf, "part=", 5)) {
952 extract_token(mime_name, &buf[5], 0, '|', sizeof mime_filename);
953 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
954 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
955 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
956 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
957 mime_length = extract_int(&buf[5], 5);
960 striplt(mime_filename);
961 if ( (IsEmptyStr(mime_filename)) && (!IsEmptyStr(mime_name)) ) {
962 strcpy(mime_filename, mime_name);
965 if (!strcasecmp(mime_content_type, "message/rfc822")) {
966 if (!IsEmptyStr(mime_submessages)) {
967 strcat(mime_submessages, "|");
969 strcat(mime_submessages, mime_partnum);
971 else if ((!strcasecmp(mime_disposition, "inline"))
972 && (!strncasecmp(mime_content_type, "image/", 6)) ){
974 attach_links = realloc(attach_links,
975 (num_attach_links*sizeof(struct attach_link)));
976 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
977 snprintf(attach_links[num_attach_links-1].html, 1024,
978 "<img src=\"mimepart/%ld/%s/%s\">",
979 msgnum, mime_partnum, mime_filename);
981 else if ( ( (!strcasecmp(mime_disposition, "attachment"))
982 || (!strcasecmp(mime_disposition, "inline"))
983 || (!strcasecmp(mime_disposition, ""))
984 ) && (!IsEmptyStr(mime_content_type))
987 attach_links = realloc(attach_links,
988 (num_attach_links*sizeof(struct attach_link)));
989 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
990 utf8ify_rfc822_string(mime_filename);
992 mime_content_type_ptr = mime_content_type;
993 if (strcasecmp(mime_content_type, "application/octet-stream") == 0) {
994 mime_content_type_ptr = GuessMimeByFilename(mime_filename,
995 strlen(mime_filename));
997 urlesc(escaped_mime_filename, 265, mime_filename);
998 snprintf(attach_links[num_attach_links-1].html, 1024,
999 "<img src=\"display_mime_icon?type=%s\" "
1000 "border=0 align=middle>\n"
1001 "%s (%s, %d bytes) [ "
1002 "<a href=\"mimepart/%ld/%s/%s\""
1003 "target=\"wc.%ld.%s\">%s</a>"
1005 "<a href=\"mimepart_download/%ld/%s/%s\">%s</a>"
1007 mime_content_type_ptr,
1009 mime_content_type, mime_length,
1010 msgnum, mime_partnum, escaped_mime_filename,
1011 msgnum, mime_partnum,
1013 msgnum, mime_partnum, escaped_mime_filename,
1018 /** begin handler prep ***/
1019 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1020 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1021 strcpy(vcard_partnum, mime_partnum);
1024 if ( (!strcasecmp(mime_content_type, "text/calendar"))
1025 || (!strcasecmp(mime_content_type, "application/ics")) ) {
1026 strcpy(cal_partnum, mime_partnum);
1029 /** end handler prep ***/
1035 /* Trim down excessively long lists of thread references. We eliminate the
1036 * second one in the list so that the thread root remains intact.
1038 int rrtok = num_tokens(reply_references, '|');
1039 int rrlen = strlen(reply_references);
1040 if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
1041 remove_token(reply_references, 1, '|');
1044 /* Generate a reply-to address */
1045 if (!IsEmptyStr(rfca)) {
1046 if (!IsEmptyStr(from)) {
1047 snprintf(reply_to, sizeof(reply_to), "%s <%s>", from, rfca);
1050 strcpy(reply_to, rfca);
1054 if ((!IsEmptyStr(node))
1055 && (strcasecmp(node, serv_info.serv_nodename))
1056 && (strcasecmp(node, serv_info.serv_humannode)) ) {
1057 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
1061 snprintf(reply_to, sizeof(reply_to), "%s", from);
1069 utf8ify_rfc822_string(m_cc);
1070 utf8ify_rfc822_string(m_subject);
1072 /** start msg buttons */
1074 if (!printable_view) {
1075 wprintf("<p id=\"msg%ld\" class=\"msgbuttons\" >\n",msgnum);
1078 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
1079 wprintf("<a href=\"display_enter");
1080 if (WC->is_mailbox) {
1081 wprintf("?replyquote=%ld", msgnum);
1084 urlescputs(reply_to);
1085 if (!IsEmptyStr(m_subject)) {
1086 wprintf("?subject=");
1087 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%%20");
1088 urlescputs(m_subject);
1090 wprintf("?references=");
1091 if (!IsEmptyStr(reply_references)) {
1092 urlescputs(reply_references);
1095 urlescputs(reply_inreplyto);
1096 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Reply"));
1100 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
1101 if (!WC->is_mailbox) {
1102 wprintf("<a href=\"display_enter");
1103 wprintf("?replyquote=%ld", msgnum);
1105 urlescputs(reply_to);
1106 if (!IsEmptyStr(m_subject)) {
1107 wprintf("?subject=");
1108 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%%20");
1109 urlescputs(m_subject);
1111 wprintf("?references=");
1112 if (!IsEmptyStr(reply_references)) {
1113 urlescputs(reply_references);
1116 urlescputs(reply_inreplyto);
1117 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyQuoted"));
1122 if (WC->wc_view == VIEW_MAILBOX) {
1123 wprintf("<a href=\"display_enter");
1124 wprintf("?replyquote=%ld", msgnum);
1126 urlescputs(reply_to);
1128 urlescputs(reply_all);
1129 if (!IsEmptyStr(m_subject)) {
1130 wprintf("?subject=");
1131 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%%20");
1132 urlescputs(m_subject);
1134 wprintf("?references=");
1135 if (!IsEmptyStr(reply_references)) {
1136 urlescputs(reply_references);
1139 urlescputs(reply_inreplyto);
1140 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyAll"));
1144 if (WC->wc_view == VIEW_MAILBOX) {
1145 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
1146 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%%20");
1147 urlescputs(m_subject);
1148 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Forward"));
1151 /* If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
1152 if ( (WC->is_room_aide) || (WC->is_mailbox) || (WC->room_flags2 & QR2_COLLABDEL) ) {
1154 wprintf("<a href=\"confirm_move_msg?msgid=%ld\"><span>[</span>%s<span>]</span></a> ",
1158 wprintf("<a href=\"delete_msg?msgid=%ld\" "
1159 "onClick=\"return confirm('%s');\">"
1160 "<span>[</span>%s<span>]</span> "
1161 "</a> ", msgnum, _("Delete this message?"), _("Delete")
1166 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'); \" >"
1167 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Headers"));
1171 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'); \" >"
1172 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Print"));
1178 if (!IsEmptyStr(m_cc)) {
1185 if (!IsEmptyStr(m_subject)) {
1186 wprintf("<p class=\"message_subject\">");
1187 wprintf(_("Subject:"));
1196 wprintf("<div class=\"message_content\">");
1199 * Learn the content type
1201 strcpy(mime_content_type, "text/plain");
1202 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1203 if (!strcmp(buf, "000")) {
1204 /* This is not necessarily an error condition. See bug #226. */
1207 if (!strncasecmp(buf, "X-Citadel-MSG4-Partnum:", 23)) {
1208 safestrncpy(msg4_partnum, &buf[23], sizeof(msg4_partnum));
1209 striplt(msg4_partnum);
1211 if (!strncasecmp(buf, "Content-type:", 13)) {
1213 safestrncpy(mime_content_type, &buf[13], sizeof(mime_content_type));
1214 striplt(mime_content_type);
1215 len = strlen(mime_content_type);
1216 for (i=0; i<len; ++i) {
1217 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1218 safestrncpy(mime_charset, &mime_content_type[i+8],
1219 sizeof mime_charset);
1222 for (i=0; i<len; ++i) {
1223 if (mime_content_type[i] == ';') {
1224 mime_content_type[i] = 0;
1228 len = strlen(mime_charset);
1229 for (i=0; i<len; ++i) {
1230 if (mime_charset[i] == ';') {
1231 mime_charset[i] = 0;
1238 /* Set up a character set conversion if we need to (and if we can) */
1240 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
1241 if ( (strcasecmp(mime_charset, "us-ascii"))
1242 && (strcasecmp(mime_charset, "UTF-8"))
1243 && (strcasecmp(mime_charset, ""))
1245 ic = ctdl_iconv_open("UTF-8", mime_charset);
1246 if (ic == (iconv_t)(-1) ) {
1247 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1248 __FILE__, __LINE__, mime_charset, strerror(errno));
1253 /* Messages in legacy Citadel variformat get handled thusly... */
1254 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1258 /* Boring old 80-column fixed format text gets handled this way... */
1259 else if ( (!strcasecmp(mime_content_type, "text/plain"))
1260 || (!strcasecmp(mime_content_type, "text")) ) {
1262 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1265 if ((len > 0) && buf[len-1] == '\n') buf[--len] = 0;
1266 if ((len > 0) && buf[len-1] == '\r') buf[--len] = 0;
1269 if (ic != (iconv_t)(-1) ) {
1271 ibuflen = strlen(ibuf);
1273 obuf = (char *) malloc(obuflen);
1275 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1276 osav[SIZ-obuflen] = 0;
1277 safestrncpy(buf, osav, sizeof buf);
1283 while ((!IsEmptyStr(buf)) && (isspace(buf[len-1])))
1286 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1287 wprintf("<blockquote>");
1289 } else if ((bq == 1) &&
1290 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1291 wprintf("</blockquote>");
1295 url(buf, sizeof(buf));
1297 wprintf("</tt><br />\n");
1299 wprintf("</i><br />");
1302 /* HTML is fun, but we've got to strip it first */
1303 else if (!strcasecmp(mime_content_type, "text/html")) {
1304 output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
1307 /* Unknown weirdness */
1309 wprintf(_("I don't know how to display %s"), mime_content_type);
1310 wprintf("<br />\n");
1311 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1314 ENDBODY: /* If there are attached submessages, display them now... */
1316 if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
1317 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1318 extract_token(buf, mime_submessages, i, '|', sizeof buf);
1319 /** use printable_view to suppress buttons */
1320 wprintf("<blockquote>");
1321 read_message(msgnum, 1, buf);
1322 wprintf("</blockquote>");
1327 /* Afterwards, offer links to download attachments 'n' such */
1328 if ( (num_attach_links > 0) && (!section[0]) ) {
1329 for (i=0; i<num_attach_links; ++i) {
1330 if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
1331 wprintf("%s", attach_links[i].html);
1336 /* Handler for vCard parts */
1337 if (!IsEmptyStr(vcard_partnum)) {
1338 part_source = load_mimepart(msgnum, vcard_partnum);
1339 if (part_source != NULL) {
1341 /** If it's my vCard I can edit it */
1342 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1343 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1344 || (WC->wc_view == VIEW_ADDRESSBOOK)
1346 wprintf("<a href=\"edit_vcard?msgnum=%ld?partnum=%s\">",
1347 msgnum, vcard_partnum);
1348 wprintf("[%s]</a>", _("edit"));
1351 /* In all cases, display the full card */
1352 display_vcard(part_source, 0, 1, NULL,msgnum);
1356 /* Handler for calendar parts */
1357 if (!IsEmptyStr(cal_partnum)) {
1358 part_source = load_mimepart(msgnum, cal_partnum);
1359 if (part_source != NULL) {
1360 cal_process_attachment(part_source, msgnum, cal_partnum);
1369 wprintf("</div>\n");
1371 /* end everythingamundo table */
1372 if (!printable_view) {
1373 wprintf("</div>\n");
1376 if (num_attach_links > 0) {
1381 if (ic != (iconv_t)(-1) ) {
1390 * Unadorned HTML output of an individual message, suitable
1391 * for placing in a hidden iframe, for printing, or whatever
1393 * msgnum_as_string == Message number, as a string instead of as a long int
1395 void embed_message(void) {
1398 msgnum = StrTol(WC->UrlFragment1);
1399 read_message(msgnum, 0, "");
1404 * Printable view of a message
1406 * msgnum_as_string == Message number, as a string instead of as a long int
1408 void print_message(void) {
1411 msgnum = StrTol(WC->UrlFragment1);
1412 output_headers(0, 0, 0, 0, 0, 0);
1414 hprintf("Content-type: text/html\r\n"
1416 "Connection: close\r\n",
1420 wprintf("\r\n<html>\n<head><title>");
1421 escputs(WC->wc_fullname);
1422 wprintf("</title></head>\n"
1423 "<body onLoad=\" window.print(); window.close(); \">\n"
1426 read_message(msgnum, 1, "");
1428 wprintf("\n</body></html>\n\n");
1433 * Mobile browser view of message
1435 * @param msg_num_as_string Message number as a string instead of as a long int
1437 void mobile_message_view(void) {
1439 msgnum = StrTol(WC->UrlFragment1);
1440 output_headers(1, 0, 0, 0, 0, 1);
1442 do_template("msgcontrols");
1443 read_message(msgnum,1, "");
1448 * \brief Display a message's headers
1450 * \param msgnum_as_string Message number, as a string instead of as a long int
1452 void display_headers(void) {
1456 msgnum = StrTol(WC->UrlFragment1);
1457 output_headers(0, 0, 0, 0, 0, 0);
1459 hprintf("Content-type: text/plain\r\n"
1461 "Connection: close\r\n",
1465 serv_printf("MSG2 %ld|3", msgnum);
1466 serv_getln(buf, sizeof buf);
1467 if (buf[0] == '1') {
1468 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1469 wprintf("%s\n", buf);
1479 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1480 * or 'reply quoted' operations.
1482 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1483 * in this function. Doing so would throw a JavaScript error in the
1484 * 'supplied text' argument to the editor.
1486 * \param msgnum Message number of the message we want to quote
1487 * \param forward_attachments Nonzero if we want attachments to be forwarded
1489 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1491 char mime_partnum[256];
1492 char mime_filename[256];
1493 char mime_content_type[256];
1494 char mime_charset[256];
1495 char mime_disposition[256];
1497 char *attachments = NULL;
1499 int num_attachments = 0;
1500 struct wc_attachment *att, *aptr;
1501 char m_subject[1024];
1508 int format_type = 0;
1513 iconv_t ic = (iconv_t)(-1) ;
1514 char *ibuf; /**< Buffer of characters to be converted */
1515 char *obuf; /**< Buffer for converted characters */
1516 size_t ibuflen; /**< Length of input buffer */
1517 size_t obuflen; /**< Length of output buffer */
1518 char *osav; /**< Saved pointer to output buffer */
1524 strcpy(reply_to, "");
1525 strcpy(mime_content_type, "text/plain");
1526 strcpy(mime_charset, "us-ascii");
1528 serv_printf("MSG4 %ld", msgnum);
1529 serv_getln(buf, sizeof buf);
1530 if (buf[0] != '1') {
1531 wprintf(_("ERROR:"));
1532 wprintf("%s<br />", &buf[4]);
1536 strcpy(m_subject, "");
1538 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1539 if (!strcmp(buf, "000")) {
1540 wprintf("%s (3)", _("unexpected end of message"));
1543 if (include_headers) {
1544 if (!strncasecmp(buf, "nhdr=yes", 8))
1548 if (!strncasecmp(buf, "type=", 5))
1549 format_type = atoi(&buf[5]);
1550 if (!strncasecmp(buf, "from=", 5)) {
1551 strcpy(from, &buf[5]);
1552 wprintf(_("from "));
1553 utf8ify_rfc822_string(from);
1556 if (!strncasecmp(buf, "subj=", 5)) {
1557 strcpy(m_subject, &buf[5]);
1559 if ((!strncasecmp(buf, "hnod=", 5))
1560 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1561 wprintf("(%s) ", &buf[5]);
1563 if ((!strncasecmp(buf, "room=", 5))
1564 && (strcasecmp(&buf[5], WC->wc_roomname))
1565 && (!IsEmptyStr(&buf[5])) ) {
1567 wprintf("%s> ", &buf[5]);
1569 if (!strncasecmp(buf, "rfca=", 5)) {
1570 strcpy(rfca, &buf[5]);
1575 if (!strncasecmp(buf, "node=", 5)) {
1576 strcpy(node, &buf[5]);
1577 if ( ((WC->room_flags & QR_NETWORK)
1578 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1579 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1580 && (IsEmptyStr(rfca))
1582 wprintf("@%s ", &buf[5]);
1585 if (!strncasecmp(buf, "rcpt=", 5)) {
1587 strcpy(to, &buf[5]);
1588 utf8ify_rfc822_string(to);
1591 if (!strncasecmp(buf, "time=", 5)) {
1592 webcit_fmt_date(now, atol(&buf[5]), 0);
1593 wprintf("%s ", now);
1598 * Save attachment info for later. We can't start downloading them
1599 * yet because we're in the middle of a server transaction.
1601 if (!strncasecmp(buf, "part=", 5)) {
1602 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1605 sprintf(ptr, "%s%s\n",
1606 ((attachments != NULL) ? attachments : ""),
1611 lprintf(9, "attachments=<%s>\n", attachments);
1617 if (include_headers) {
1620 utf8ify_rfc822_string(m_subject);
1621 if (!IsEmptyStr(m_subject)) {
1622 wprintf(_("Subject:"));
1624 msgescputs(m_subject);
1635 * Learn the content type
1637 strcpy(mime_content_type, "text/plain");
1638 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1639 if (!strcmp(buf, "000")) {
1640 wprintf("%s (4)", _("unexpected end of message"));
1643 if (!strncasecmp(buf, "Content-type: ", 14)) {
1645 safestrncpy(mime_content_type, &buf[14],
1646 sizeof(mime_content_type));
1647 for (i=0; i<strlen(mime_content_type); ++i) {
1648 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1649 safestrncpy(mime_charset, &mime_content_type[i+8],
1650 sizeof mime_charset);
1653 len = strlen(mime_content_type);
1654 for (i=0; i<len; ++i) {
1655 if (mime_content_type[i] == ';') {
1656 mime_content_type[i] = 0;
1660 len = strlen(mime_charset);
1661 for (i=0; i<len; ++i) {
1662 if (mime_charset[i] == ';') {
1663 mime_charset[i] = 0;
1670 /** Set up a character set conversion if we need to (and if we can) */
1672 if ( (strcasecmp(mime_charset, "us-ascii"))
1673 && (strcasecmp(mime_charset, "UTF-8"))
1674 && (strcasecmp(mime_charset, ""))
1676 ic = ctdl_iconv_open("UTF-8", mime_charset);
1677 if (ic == (iconv_t)(-1) ) {
1678 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1679 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1684 /** Messages in legacy Citadel variformat get handled thusly... */
1685 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1689 /* Boring old 80-column fixed format text gets handled this way... */
1690 else if (!strcasecmp(mime_content_type, "text/plain")) {
1691 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1694 if (buf[len-1] == '\n') buf[--len] = 0;
1695 if (buf[len-1] == '\r') buf[--len] = 0;
1698 if (ic != (iconv_t)(-1) ) {
1702 obuf = (char *) malloc(obuflen);
1704 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1705 osav[SIZ-obuflen] = 0;
1706 safestrncpy(buf, osav, sizeof buf);
1712 while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
1715 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1716 wprintf("<blockquote>");
1718 } else if ((bq == 1) &&
1719 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1720 wprintf("</blockquote>");
1724 url(buf, sizeof(buf));
1726 wprintf("</tt><br />");
1728 wprintf("</i><br />");
1731 /** HTML just gets escaped and stuffed back into the editor */
1732 else if (!strcasecmp(mime_content_type, "text/html")) {
1733 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1737 }//// TODO: charset? utf8?
1739 /** Unknown weirdness ... don't know how to handle this content type */
1741 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1745 /** end of body handler */
1748 * If there were attachments, we have to download them and insert them
1749 * into the attachment chain for the forwarded message we are composing.
1751 if ( (forward_attachments) && (num_attachments) ) {
1752 for (i=0; i<num_attachments; ++i) {
1753 extract_token(buf, attachments, i, '\n', sizeof buf);
1754 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1755 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1756 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1757 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1758 mime_length = extract_int(buf, 5);
1761 * tracing ... uncomment if necessary
1764 lprintf(9, "fwd filename: %s\n", mime_filename);
1765 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1766 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1767 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1768 lprintf(9, "fwd length : %d\n", mime_length);
1770 if ( (!strcasecmp(mime_disposition, "inline"))
1771 || (!strcasecmp(mime_disposition, "attachment")) ) {
1773 /* Create an attachment struct from this mime part... */
1774 att = malloc(sizeof(struct wc_attachment));
1775 memset(att, 0, sizeof(struct wc_attachment));
1776 att->length = mime_length;
1777 strcpy(att->content_type, mime_content_type);
1778 strcpy(att->filename, mime_filename);
1780 att->data = load_mimepart(msgnum, mime_partnum);
1782 /* And add it to the list. */
1783 if (WC->first_attachment == NULL) {
1784 WC->first_attachment = att;
1787 aptr = WC->first_attachment;
1788 while (aptr->next != NULL) aptr = aptr->next;
1797 if (ic != (iconv_t)(-1) ) {
1802 if (attachments != NULL) {
1808 * \brief Display one row in the mailbox summary view
1810 * \param num The row number to be displayed
1812 void display_summarized(int num) {
1814 wprintf("<tr id=\"m%ld\" style=\"font-weight:%s;\" "
1815 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1816 WC->summ[num].msgnum,
1817 (WC->summ[num].is_new ? "bold" : "normal"),
1818 WC->summ[num].msgnum
1821 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1823 escputs(WC->summ[num].subj);//////////////////////////////////TODO: QP DECODE
1826 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1827 escputs(WC->summ[num].from);
1830 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1831 webcit_fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1838 * \brief Output a message row for the mobile view
1839 * \param The row number
1841 void display_mobile_summary(int num) {
1843 wprintf("\n<div><div id=\"m%ld\" style=\"font-weight:%s;\" "
1844 "onClick=\"CtdlLoadMsgMouseDown(event,%ld)\">",
1845 WC->summ[num].msgnum,
1846 (WC->summ[num].is_new ? "bold" : "normal"),
1847 WC->summ[num].msgnum
1849 wprintf("<span class=\"from\">%s</span>",WC->summ[num].from);
1850 wprintf("<span style=\"float: right;\">");
1851 webcit_fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1853 wprintf("</span><br/><span class=\"subject\">");
1854 escputs(WC->summ[num].subj);
1855 wprintf("</span></div><div id=\"m_%ld\" class=\"msgview\" onMouseDown=\"\"></div></div>",WC->summ[num].msgnum);
1859 * \brief display the adressbook overview
1860 * \param msgnum the citadel message number
1861 * \param alpha what????
1863 void display_addressbook(long msgnum, char alpha) {
1865 char mime_partnum[SIZ];
1866 char mime_filename[SIZ];
1867 char mime_content_type[SIZ];
1868 char mime_disposition[SIZ];
1870 char vcard_partnum[SIZ];
1871 char *vcard_source = NULL;
1872 struct message_summary summ;
1874 memset(&summ, 0, sizeof(summ));
1875 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1877 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1879 serv_getln(buf, sizeof buf);
1880 if (buf[0] != '1') return;
1882 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1883 if (!strncasecmp(buf, "part=", 5)) {
1884 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1885 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1886 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1887 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1888 mime_length = extract_int(&buf[5], 5);
1890 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1891 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1892 strcpy(vcard_partnum, mime_partnum);
1898 if (!IsEmptyStr(vcard_partnum)) {
1899 vcard_source = load_mimepart(msgnum, vcard_partnum);
1900 if (vcard_source != NULL) {
1902 /** Display the summary line */
1903 display_vcard(vcard_source, alpha, 0, NULL,msgnum);
1905 /** If it's my vCard I can edit it */
1906 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1907 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1908 || (WC->wc_view == VIEW_ADDRESSBOOK)
1910 wprintf("<a href=\"edit_vcard?"
1911 "msgnum=%ld?partnum=%s\">",
1912 msgnum, vcard_partnum);
1913 wprintf("[%s]</a>", _("edit"));
1925 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1926 * \param namebuf name to analyze, reverse if nescessary
1928 void lastfirst_firstlast(char *namebuf) {
1929 char firstname[SIZ];
1933 if (namebuf == NULL) return;
1934 if (strchr(namebuf, ';') != NULL) return;
1936 i = num_tokens(namebuf, ' ');
1939 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1940 remove_token(namebuf, i-1, ' ');
1941 strcpy(firstname, namebuf);
1942 sprintf(namebuf, "%s; %s", lastname, firstname);
1946 * \brief fetch what??? name
1947 * \param msgnum the citadel message number
1948 * \param namebuf where to put the name in???
1950 void fetch_ab_name(long msgnum, char *namebuf) {
1952 char mime_partnum[SIZ];
1953 char mime_filename[SIZ];
1954 char mime_content_type[SIZ];
1955 char mime_disposition[SIZ];
1957 char vcard_partnum[SIZ];
1958 char *vcard_source = NULL;
1960 struct message_summary summ;
1962 if (namebuf == NULL) return;
1963 strcpy(namebuf, "");
1965 memset(&summ, 0, sizeof(summ));
1966 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1968 sprintf(buf, "MSG0 %ld|0", msgnum); /** unfortunately we need the mime info now */
1970 serv_getln(buf, sizeof buf);
1971 if (buf[0] != '1') return;
1973 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1974 if (!strncasecmp(buf, "part=", 5)) {
1975 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1976 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1977 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1978 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1979 mime_length = extract_int(&buf[5], 5);
1981 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1982 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1983 strcpy(vcard_partnum, mime_partnum);
1989 if (!IsEmptyStr(vcard_partnum)) {
1990 vcard_source = load_mimepart(msgnum, vcard_partnum);
1991 if (vcard_source != NULL) {
1993 /* Grab the name off the card */
1994 display_vcard(vcard_source, 0, 0, namebuf,msgnum);
2000 lastfirst_firstlast(namebuf);
2002 len = strlen(namebuf);
2003 for (i=0; i<len; ++i) {
2004 if (namebuf[i] != ';') return;
2006 strcpy(namebuf, _("(no name)"));
2012 * \brief Record compare function for sorting address book indices
2013 * \param ab1 adressbook one
2014 * \param ab2 adressbook two
2016 int abcmp(const void *ab1, const void *ab2) {
2018 (((const struct addrbookent *)ab1)->ab_name),
2019 (((const struct addrbookent *)ab2)->ab_name)
2025 * \brief Helper function for do_addrbook_view()
2026 * Converts a name into a three-letter tab label
2027 * \param tabbuf the tabbuffer to add name to
2028 * \param name the name to add to the tabbuffer
2030 void nametab(char *tabbuf, long len, char *name) {
2031 stresc(tabbuf, len, name, 0, 0);
2032 tabbuf[0] = toupper(tabbuf[0]);
2033 tabbuf[1] = tolower(tabbuf[1]);
2034 tabbuf[2] = tolower(tabbuf[2]);
2040 * \brief Render the address book using info we gathered during the scan
2041 * \param addrbook the addressbook to render
2042 * \param num_ab the number of the addressbook
2044 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
2048 static int NAMESPERPAGE = 60;
2051 char tabfirst_label[64];
2053 char tablast_label[64];
2054 char this_tablabel[64];
2059 wprintf("<br /><br /><br /><div align=\"center\"><i>");
2060 wprintf(_("This address book is empty."));
2061 wprintf("</i></div>\n");
2066 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
2069 num_pages = (num_ab / NAMESPERPAGE) + 1;
2071 tablabels = malloc(num_pages * sizeof (char *));
2072 if (tablabels == NULL) {
2073 wprintf("<br /><br /><br /><div align=\"center\"><i>");
2074 wprintf(_("An internal error has occurred."));
2075 wprintf("</i></div>\n");
2079 for (i=0; i<num_pages; ++i) {
2080 tabfirst = i * NAMESPERPAGE;
2081 tablast = tabfirst + NAMESPERPAGE - 1;
2082 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
2083 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
2084 nametab(tablast_label, 64, addrbook[tablast].ab_name);
2085 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
2086 tablabels[i] = strdup(this_tablabel);
2089 tabbed_dialog(num_pages, tablabels);
2092 for (i=0; i<num_ab; ++i) {
2094 if ((i / NAMESPERPAGE) != page) { /* New tab */
2095 page = (i / NAMESPERPAGE);
2097 wprintf("</tr></table>\n");
2098 end_tab(page-1, num_pages);
2100 begin_tab(page, num_pages);
2101 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
2105 if ((displayed % 4) == 0) {
2106 if (displayed > 0) {
2110 wprintf("<tr bgcolor=\"#%s\">",
2111 (bg ? "DDDDDD" : "FFFFFF")
2117 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
2118 addrbook[i].ab_msgnum);
2119 wprintf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
2120 vcard_n_prettyize(addrbook[i].ab_name);
2121 escputs(addrbook[i].ab_name);
2122 wprintf("</a></td>\n");
2126 wprintf("</tr></table>\n");
2127 end_tab((num_pages-1), num_pages);
2129 for (i=0; i<num_pages; ++i) {
2138 * \brief load message pointers from the server
2139 * \param servcmd the citadel command to send to the citserver
2140 * \param with_headers what headers???
2142 int load_msg_ptrs(char *servcmd, int with_headers)
2155 int num_summ_alloc = 0;
2157 if (WC->summ != NULL) {
2162 num_summ_alloc = 100;
2164 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
2167 maxload = sizeof(WC->msgarr) / sizeof(long) ;
2169 serv_getln(buf, sizeof buf);
2170 if (buf[0] != '1') {
2173 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2174 if (nummsgs < maxload) {
2175 WC->msgarr[nummsgs] = extract_long(buf, 0);
2176 datestamp = extract_long(buf, 1);
2177 extract_token(fullname, buf, 2, '|', sizeof fullname);
2178 extract_token(nodename, buf, 3, '|', sizeof nodename);
2179 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
2180 extract_token(subject, buf, 5, '|', sizeof subject);
2184 if (nummsgs > num_summ_alloc) {
2185 num_summ_alloc *= 2;
2186 WC->summ = realloc(WC->summ,
2187 num_summ_alloc * sizeof(struct message_summary));
2191 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
2192 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
2193 safestrncpy(WC->summ[nummsgs-1].subj,
2194 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
2195 if (!IsEmptyStr(subject)) {
2196 /** Handle subjects with RFC2047 encoding */
2197 utf8ify_rfc822_string(subject);
2198 safestrncpy(WC->summ[nummsgs-1].subj, subject,
2199 sizeof WC->summ[nummsgs-1].subj);
2201 sbjlen = Ctdl_Utf8StrLen(WC->summ[nummsgs-1].subj);
2203 ptr = Ctdl_Utf8StrCut(WC->summ[nummsgs-1].subj, 72);
2208 if (!IsEmptyStr(fullname)) {
2209 /** Handle senders with RFC2047 encoding */
2210 utf8ify_rfc822_string(fullname);
2211 safestrncpy(WC->summ[nummsgs-1].from,
2212 fullname, sizeof WC->summ[nummsgs-1].from);
2214 if ((!IsEmptyStr(nodename)) &&
2215 ( ((WC->room_flags & QR_NETWORK)
2216 || ((strcasecmp(nodename, serv_info.serv_nodename)
2217 && (strcasecmp(nodename, serv_info.serv_fqdn)))))))
2219 strcat(WC->summ[nummsgs-1].from, " @ ");
2220 strcat(WC->summ[nummsgs-1].from, nodename);
2223 sbjlen = Ctdl_Utf8StrLen(WC->summ[nummsgs-1].from);
2225 ptr = Ctdl_Utf8StrCut(WC->summ[nummsgs-1].from, 23);
2229 WC->summ[nummsgs-1].date = datestamp;
2237 typedef int (*QSortFunction) (const void*, const void*);
2239 * \brief qsort() compatible function to compare two longs in descending order.
2241 * \param s1 first number to compare
2242 * \param s2 second number to compare
2244 int longcmp_r(const void *s1, const void *s2) {
2251 if (l1 > l2) return(-1);
2252 if (l1 < l2) return(+1);
2258 * \brief qsort() compatible function to compare two message summary structs by ascending subject.
2260 * \param s1 first item to compare
2261 * \param s2 second item to compare
2263 int summcmp_subj(const void *s1, const void *s2) {
2264 struct message_summary *summ1;
2265 struct message_summary *summ2;
2267 summ1 = (struct message_summary *)s1;
2268 summ2 = (struct message_summary *)s2;
2269 return strcasecmp(summ1->subj, summ2->subj);
2273 * \brief qsort() compatible function to compare two message summary structs by descending subject.
2275 * \param s1 first item to compare
2276 * \param s2 second item to compare
2278 int summcmp_rsubj(const void *s1, const void *s2) {
2279 struct message_summary *summ1;
2280 struct message_summary *summ2;
2282 summ1 = (struct message_summary *)s1;
2283 summ2 = (struct message_summary *)s2;
2284 return strcasecmp(summ2->subj, summ1->subj);
2288 * \brief qsort() compatible function to compare two message summary structs by ascending sender.
2290 * \param s1 first item to compare
2291 * \param s2 second item to compare
2293 int summcmp_sender(const void *s1, const void *s2) {
2294 struct message_summary *summ1;
2295 struct message_summary *summ2;
2297 summ1 = (struct message_summary *)s1;
2298 summ2 = (struct message_summary *)s2;
2299 return strcasecmp(summ1->from, summ2->from);
2303 * \brief qsort() compatible function to compare two message summary structs by descending sender.
2305 * \param s1 first item to compare
2306 * \param s2 second item to compare
2308 int summcmp_rsender(const void *s1, const void *s2) {
2309 struct message_summary *summ1;
2310 struct message_summary *summ2;
2312 summ1 = (struct message_summary *)s1;
2313 summ2 = (struct message_summary *)s2;
2314 return strcasecmp(summ2->from, summ1->from);
2318 * \brief qsort() compatible function to compare two message summary structs by ascending date.
2320 * \param s1 first item to compare
2321 * \param s2 second item to compare
2323 int summcmp_date(const void *s1, const void *s2) {
2324 struct message_summary *summ1;
2325 struct message_summary *summ2;
2327 summ1 = (struct message_summary *)s1;
2328 summ2 = (struct message_summary *)s2;
2330 if (summ1->date < summ2->date) return -1;
2331 else if (summ1->date > summ2->date) return +1;
2336 * \brief qsort() compatible function to compare two message summary structs by descending date.
2338 * \param s1 first item to compare
2339 * \param s2 second item to compare
2341 int summcmp_rdate(const void *s1, const void *s2) {
2342 struct message_summary *summ1;
2343 struct message_summary *summ2;
2345 summ1 = (struct message_summary *)s1;
2346 summ2 = (struct message_summary *)s2;
2348 if (summ1->date < summ2->date) return +1;
2349 else if (summ1->date > summ2->date) return -1;
2360 const char* SortIcons[3] = {
2361 "static/up_pointer.gif",
2362 "static/down_pointer.gif",
2363 "static/sort_none.gif"
2366 enum {/// SortByEnum
2377 /** SortEnum to plain string representation */
2378 static const char* SortByStrings[] = {
2389 /** SortEnum to sort-Function Table */
2390 const QSortFunction SortFuncs[eUnSet] = {
2400 /** given a SortEnum, which icon should we choose? */
2401 const int SortDateToIcon[eUnSet] = { eUp, eDown, eNone, eNone, eNone, eNone, eNone};
2402 const int SortSubjectToIcon[eUnSet] = { eNone, eNone, eUp, eDown, eNone, eNone, eNone};
2403 const int SortSenderToIcon[eUnSet] = { eNone, eNone, eNone, eNone, eUp, eDown, eNone};
2405 /** given a SortEnum, which would be the "opposite" search option? */
2406 const int DateInvertSortString[eUnSet] = { eRDate, eDate, eDate, eDate, eDate, eDate, eDate};
2407 const int SubjectInvertSortString[eUnSet] = { eSubject, eSubject, eRSubject, eUnSet, eSubject, eSubject, eSubject};
2408 const int SenderInvertSortString[eUnSet] = { eSender, eSender, eSender, eSender, eRSender, eUnSet, eSender};
2412 * \Brief Translates sortoption String to its SortEnum representation
2413 * \param SortBy string to translate
2414 * \return the enum matching the string; defaults to RDate
2417 int StrToESort (StrBuf *sortby)
2421 if (!IsEmptyStr(ChrPtr(sortby))) while (result < eUnSet){
2422 if (!strcasecmp(ChrPtr(sortby),
2423 SortByStrings[result]))
2434 * \brief command loop for reading messages
2436 * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
2438 void readloop(char *oper)
2447 long *displayed_msgs = NULL;
2448 int num_displayed = 0;
2450 int is_addressbook = 0;
2451 int is_singlecard = 0;
2452 int is_calendar = 0;
2457 int lowest_displayed = (-1);
2458 int highest_displayed = 0;
2459 struct addrbookent *addrbook = NULL;
2461 StrBuf *sortby = NULL;
2463 int SortBy = eRDate;
2464 StrBuf *sortpref_name;
2465 StrBuf *sortpref_value;
2466 int bbs_reverse = 0;
2467 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
2469 if (WCC->wc_view == VIEW_WIKI) {
2470 sprintf(buf, "wiki?room=%s?page=home", WCC->wc_roomname);
2475 startmsg = lbstr("startmsg");
2476 maxmsgs = ibstr("maxmsgs");
2477 is_summary = (ibstr("is_summary") && !WCC->is_mobile);
2478 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2480 sortpref_name = NewStrBuf ();
2481 StrBufPrintf(sortpref_name, "sort %s", WCC->wc_roomname);
2482 get_pref(sortpref_name, &sortpref_value);
2484 sortby = NewStrBufPlain(bstr("sortby"), -1);
2485 if ( (!IsEmptyStr(ChrPtr(sortby))) &&
2486 (strcasecmp(ChrPtr(sortby), ChrPtr(sortpref_value)) != 0)) {
2487 set_pref(sortpref_name, sortby, 1);
2488 sortpref_value = NULL;
2489 sortpref_value = sortby;
2491 FreeStrBuf(&sortby);
2493 FreeStrBuf(&sortpref_name);
2494 SortBy = StrToESort(sortpref_value);
2495 /** message board sort */
2496 if (SortBy == eReverse) {
2503 output_headers(1, 1, 1, 0, 0, 0);
2506 * When in summary mode, always show ALL messages instead of just
2507 * new or old. Otherwise, show what the user asked for.
2509 if (!strcmp(oper, "readnew")) {
2510 strcpy(cmd, "MSGS NEW");
2512 else if (!strcmp(oper, "readold")) {
2513 strcpy(cmd, "MSGS OLD");
2515 else if (!strcmp(oper, "do_search")) {
2516 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2519 strcpy(cmd, "MSGS ALL");
2522 if ((WCC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1) && !WCC->is_mobile) {
2524 if (!strcmp(oper, "do_search")) {
2525 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2528 strcpy(cmd, "MSGS ALL");
2532 if ((WCC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2534 if (!strcmp(oper, "do_search")) {
2535 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2538 strcpy(cmd, "MSGS ALL");
2543 if (is_summary) { /**< fetch header summary */
2544 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
2545 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2546 (!strcmp(oper, "do_search") ? bstr("query") : "")
2551 if (WCC->is_mobile) {
2553 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
2554 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2555 (!strcmp(oper, "do_search") ? bstr("query") : "")
2561 * Are we doing a summary view? If so, we need to know old messages
2562 * and new messages, so we can do that pretty boldface thing for the
2565 strcpy(old_msgs, "");
2566 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){
2568 serv_getln(buf, sizeof buf);
2569 if (buf[0] == '2') {
2570 strcpy(old_msgs, &buf[4]);
2574 is_singlecard = ibstr("is_singlecard");
2576 if (WCC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2578 strcpy(cmd, "MSGS ALL|||1");
2581 if (WCC->wc_default_view == VIEW_TASKS) { /**< tasks */
2583 strcpy(cmd, "MSGS ALL");
2586 if (WCC->wc_default_view == VIEW_NOTES) { /**< notes */
2588 strcpy(cmd, "MSGS ALL");
2593 wprintf("<div id=\"new_notes_here\"></div>\n");
2596 nummsgs = load_msg_ptrs(cmd, (is_summary || WCC->is_mobile));
2599 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2600 wprintf("<div align=\"center\"><br /><em>");
2601 if (!strcmp(oper, "readnew")) {
2602 wprintf(_("No new messages."));
2603 } else if (!strcmp(oper, "readold")) {
2604 wprintf(_("No old messages."));
2606 wprintf(_("No messages here."));
2608 wprintf("</em><br /></div>\n");
2614 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){
2615 for (a = 0; a < nummsgs; ++a) {
2616 /** Are you a new message, or an old message? */
2618 if (is_msg_in_mset(old_msgs, WCC->msgarr[a])) {
2619 WCC->summ[a].is_new = 0;
2622 WCC->summ[a].is_new = 1;
2628 if (startmsg == 0L) {
2630 startmsg = WCC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2633 startmsg = WCC->msgarr[0];
2637 if (is_summary || WCC->is_mobile) {
2638 qsort(WCC->summ, WCC->num_summ,
2639 sizeof(struct message_summary), SortFuncs[SortBy]);
2645 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2646 " document.onkeydown = CtdlMsgListKeyPress; "
2647 " if (document.layers) { "
2648 " document.captureEvents(Event.KEYPRESS); "
2653 /** note that Date and Delete are now in the same column */
2654 wprintf("<div id=\"message_list_hdr\">"
2655 "<div class=\"fix_scrollbar_bug\">"
2656 "<table cellspacing=0 style=\"width:100%%\">"
2659 wprintf("<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> </th>\n"
2660 "<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> </th>\n"
2661 "<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> \n"
2663 "<input type=\"submit\" name=\"delete_button\" id=\"delbutton\" "
2664 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2671 SortByStrings[SubjectInvertSortString[SortBy]],
2672 SortIcons[SortSubjectToIcon[SortBy]],
2673 SENDER_COL_WIDTH_PCT,
2675 SortByStrings[SenderInvertSortString[SortBy]],
2676 SortIcons[SortSenderToIcon[SortBy]],
2677 DATE_PLUS_BUTTONS_WIDTH_PCT,
2679 SortByStrings[DateInvertSortString[SortBy]],
2680 SortIcons[SortDateToIcon[SortBy]],
2683 wprintf("</table></div></div>\n");
2684 wprintf("<div id=\"message_list\">"
2686 "<div class=\"fix_scrollbar_bug\">\n"
2687 "<table class=\"mailbox_summary\" id=\"summary_headers\" "
2688 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2690 } else if (WCC->is_mobile) {
2691 wprintf("<div id=\"message_list\">");
2696 * Set the "is_bbview" variable if it appears that we are looking at
2697 * a classic bulletin board view.
2699 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2700 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2705 * If we're not currently looking at ALL requested
2706 * messages, then display the selector bar
2709 /** begin bbview scroller */
2710 wprintf("<form name=\"msgomatictop\" class=\"selector_top\" > \n <p>");
2711 wprintf(_("Reading #"));//// TODO this isn't used, should it? : , lowest_displayed, highest_displayed);
2713 wprintf("<select name=\"whichones\" size=\"1\" "
2714 "OnChange=\"location.href=msgomatictop.whichones.options"
2715 "[selectedIndex].value\">\n");
2718 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2720 lo = b - maxmsgs + 2;
2722 wprintf("<option %s value="
2727 "%d-%d</option> \n",
2728 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2737 for (b=0; b<nummsgs; b = b + maxmsgs) {
2739 hi = b + maxmsgs + 1;
2740 if (hi > nummsgs) hi = nummsgs;
2741 wprintf("<option %s value="
2746 "%d-%d</option> \n",
2747 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2756 wprintf("<option value=\"%s?startmsg=%ld"
2757 "?maxmsgs=9999999?is_summary=%d\">",
2759 WCC->msgarr[0], is_summary);
2761 wprintf("</option>");
2762 wprintf("</select> ");
2763 wprintf(_("of %d messages."), nummsgs);
2765 /** forward/reverse */
2766 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2767 "OnChange=\"location.href='%s?sortby=forward'\"",
2768 (bbs_reverse ? "" : "checked"),
2772 wprintf(_("oldest to newest"));
2773 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 */
2787 for (a = 0; a < nummsgs; ++a) {
2788 if ((WCC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2790 /** Display the message */
2792 display_summarized(a);
2794 else if (is_addressbook) {
2795 fetch_ab_name(WCC->msgarr[a], buf);
2797 addrbook = realloc(addrbook,
2798 (sizeof(struct addrbookent) * num_ab) );
2799 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2800 sizeof(addrbook[num_ab-1].ab_name));
2801 addrbook[num_ab-1].ab_msgnum = WCC->msgarr[a];
2803 else if (is_calendar) {
2804 display_calendar(WCC->msgarr[a], WCC->summ[a].is_new);
2806 else if (is_tasks) {
2807 display_task(WCC->msgarr[a], WCC->summ[a].is_new);
2809 else if (is_notes) {
2810 display_note(WCC->msgarr[a], WCC->summ[a].is_new);
2811 } else if (WCC->is_mobile) {
2812 display_mobile_summary(a);
2815 if (displayed_msgs == NULL) {
2816 displayed_msgs = malloc(sizeof(long) *
2817 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2819 displayed_msgs[num_displayed] = WCC->msgarr[a];
2822 if (lowest_displayed < 0) lowest_displayed = a;
2823 highest_displayed = a;
2830 if (displayed_msgs != NULL) {
2832 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2835 /** if we do a split bbview in the future, begin messages div here */
2837 for (a=0; a<num_displayed; ++a) {
2838 read_message(displayed_msgs[a], 0, "");
2841 /** if we do a split bbview in the future, end messages div here */
2843 free(displayed_msgs);
2844 displayed_msgs = NULL;
2849 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2850 wprintf("</div>"); /**< end of 'message_list' div */
2852 /** Here's the grab-it-to-resize-the-message-list widget */
2853 wprintf("<div id=\"resize_msglist\" "
2854 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2855 "<div class=\"fix_scrollbar_bug\"> <hr>"
2859 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2860 } else if (WCC->is_mobile) {
2865 * Bump these because although we're thinking in zero base, the user
2866 * is a drooling idiot and is thinking in one base.
2869 ++highest_displayed;
2872 * If we're not currently looking at ALL requested
2873 * messages, then display the selector bar
2876 /** begin bbview scroller */
2877 wprintf("<form name=\"msgomatic\" class=\"selector_bottom\" > \n <p>");
2878 wprintf(_("Reading #")); /// TODO: this isn't used: , lowest_displayed, highest_displayed);
2880 wprintf("<select name=\"whichones\" size=\"1\" "
2881 "OnChange=\"location.href=msgomatic.whichones.options"
2882 "[selectedIndex].value\">\n");
2885 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2887 lo = b - maxmsgs + 2;
2889 wprintf("<option %s value="
2894 "%d-%d</option> \n",
2895 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2904 for (b=0; b<nummsgs; b = b + maxmsgs) {
2906 hi = b + maxmsgs + 1;
2907 if (hi > nummsgs) hi = nummsgs;
2908 wprintf("<option %s value="
2913 "%d-%d</option> \n",
2914 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2923 wprintf("<option value=\"%s?startmsg=%ld"
2924 "?maxmsgs=9999999?is_summary=%d\">",
2926 WCC->msgarr[0], is_summary);
2928 wprintf("</option>");
2929 wprintf("</select> ");
2930 wprintf(_("of %d messages."), nummsgs);
2932 /** forward/reverse */
2933 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2934 "OnChange=\"location.href='%s?sortby=forward'\"",
2935 (bbs_reverse ? "" : "checked"),
2939 wprintf(_("oldest to newest"));
2940 wprintf(" ");
2941 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2942 "OnChange=\"location.href='%s?sortby=reverse'\"",
2943 (bbs_reverse ? "checked" : ""),
2947 wprintf(_("newest to oldest"));
2950 wprintf("</p></form>\n");
2951 /** end bbview scroller */
2956 do_tasks_view(); /** Render the task list */
2960 do_calendar_view(); /** Render the calendar */
2963 if (is_addressbook) {
2964 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2967 /** Note: wDumpContent() will output one additional </div> tag. */
2968 wprintf("</div>\n"); /** end of 'content' div */
2971 /** free the summary */
2972 if (WCC->summ != NULL) {
2977 if (addrbook != NULL) free(addrbook);
2982 * Back end for post_message()
2983 * ... this is where the actual message gets transmitted to the server.
2985 void post_mime_to_server(void) {
2986 char top_boundary[SIZ];
2987 char alt_boundary[SIZ];
2988 int is_multipart = 0;
2990 struct wc_attachment *att;
2992 size_t encoded_length;
2993 size_t encoded_strlen;
2994 char *txtmail = NULL;
2996 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
2997 serv_info.serv_fqdn,
3001 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
3002 serv_info.serv_fqdn,
3007 /* RFC2045 requires this, and some clients look for it... */
3008 serv_puts("MIME-Version: 1.0");
3009 serv_puts("X-Mailer: " PACKAGE_STRING);
3011 /* If there are attachments, we have to do multipart/mixed */
3012 if (WC->first_attachment != NULL) {
3017 /* Remember, serv_printf() appends an extra newline */
3018 serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
3019 serv_printf("This is a multipart message in MIME format.\n");
3020 serv_printf("--%s", top_boundary);
3023 /* Remember, serv_printf() appends an extra newline */
3024 serv_printf("Content-type: multipart/alternative; "
3025 "boundary=\"%s\"\n", alt_boundary);
3026 serv_printf("This is a multipart message in MIME format.\n");
3027 serv_printf("--%s", alt_boundary);
3029 serv_puts("Content-type: text/plain; charset=utf-8");
3030 serv_puts("Content-Transfer-Encoding: quoted-printable");
3032 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
3033 text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */
3036 serv_printf("--%s", alt_boundary);
3038 serv_puts("Content-type: text/html; charset=utf-8");
3039 serv_puts("Content-Transfer-Encoding: quoted-printable");
3041 serv_puts("<html><body>\r\n");
3042 text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */
3043 serv_puts("</body></html>\r\n");
3045 serv_printf("--%s--", alt_boundary);
3049 /* Add in the attachments */
3050 for (att = WC->first_attachment; att!=NULL; att=att->next) {
3052 encoded_length = ((att->length * 150) / 100);
3053 encoded = malloc(encoded_length);
3054 if (encoded == NULL) break;
3055 encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1);
3057 serv_printf("--%s", top_boundary);
3058 serv_printf("Content-type: %s", att->content_type);
3059 serv_printf("Content-disposition: attachment; filename=\"%s\"", att->filename);
3060 serv_puts("Content-transfer-encoding: base64");
3062 serv_write(encoded, encoded_strlen);
3067 serv_printf("--%s--", top_boundary);
3075 * Post message (or don't post message)
3077 * Note regarding the "dont_post" variable:
3078 * A random value (actually, it's just a timestamp) is inserted as a hidden
3079 * field called "postseq" when the display_enter page is generated. This
3080 * value is checked when posting, using the static variable dont_post. If a
3081 * user attempts to post twice using the same dont_post value, the message is
3082 * discarded. This prevents the accidental double-saving of the same message
3083 * if the user happens to click the browser "back" button.
3085 void post_message(void)
3088 StrBuf *encoded_subject = NULL;
3089 static long dont_post = (-1L);
3090 struct wc_attachment *att, *aptr;
3091 int is_anonymous = 0;
3092 const StrBuf *display_name = NULL;
3093 struct wcsession *WCC = WC;
3095 if (havebstr("force_room")) {
3096 gotoroom(bstr("force_room"));
3099 if (havebstr("display_name")) {
3100 display_name = sbstr("display_name");
3101 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
3102 display_name = NULL;
3107 if (WCC->upload_length > 0) {
3109 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WCC->upload_length);
3110 /** There's an attachment. Save it to this struct... */
3111 att = malloc(sizeof(struct wc_attachment));
3112 memset(att, 0, sizeof(struct wc_attachment));
3113 att->length = WCC->upload_length;
3114 strcpy(att->content_type, WCC->upload_content_type);
3115 strcpy(att->filename, WCC->upload_filename);
3118 /** And add it to the list. */
3119 if (WCC->first_attachment == NULL) {
3120 WCC->first_attachment = att;
3123 aptr = WCC->first_attachment;
3124 while (aptr->next != NULL) aptr = aptr->next;
3129 * Mozilla sends a simple filename, which is what we want,
3130 * but Satan's Browser sends an entire pathname. Reduce
3131 * the path to just a filename if we need to.
3133 while (num_tokens(att->filename, '/') > 1) {
3134 remove_token(att->filename, 0, '/');
3136 while (num_tokens(att->filename, '\\') > 1) {
3137 remove_token(att->filename, 0, '\\');
3141 * Transfer control of this memory from the upload struct
3142 * to the attachment struct.
3144 att->data = WCC->upload;
3145 WCC->upload_length = 0;
3151 if (havebstr("cancel_button")) {
3152 sprintf(WCC->ImportantMessage,
3153 _("Cancelled. Message was not posted."));
3154 } else if (havebstr("attach_button")) {
3157 } else if (lbstr("postseq") == dont_post) {
3158 sprintf(WCC->ImportantMessage,
3159 _("Automatically cancelled because you have already "
3160 "saved this message."));
3162 const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s";
3163 const StrBuf *Recp = NULL;
3164 const StrBuf *Cc = NULL;
3165 const StrBuf *Bcc = NULL;
3166 const StrBuf *Wikipage = NULL;
3167 const StrBuf *my_email_addr = NULL;
3168 StrBuf *CmdBuf = NULL;;
3169 StrBuf *references = NULL;
3171 if (havebstr("references"))
3173 const StrBuf *ref = sbstr("references");
3174 references = NewStrBufPlain(ChrPtr(ref), StrLength(ref));
3175 lprintf(9, "Converting: %s\n", ChrPtr(references));
3176 StrBufReplaceChars(references, '|', '!');
3177 lprintf(9, "Converted: %s\n", ChrPtr(references));
3179 if (havebstr("subject")) {
3182 * make enough room for the encoded string;
3183 * plus the QP header
3185 Subj = sbstr("subject");
3187 StrBufRFC2047encode(&encoded_subject, Subj);
3189 Recp = sbstr("recp");
3192 Wikipage = sbstr("wikipage");
3193 my_email_addr = sbstr("my_email_addr");
3195 CmdBuf = NewStrBufPlain(NULL,
3198 StrLength(encoded_subject) +
3201 StrLength(Wikipage) +
3202 StrLength(my_email_addr) +
3203 StrLength(references));
3205 StrBufPrintf(CmdBuf,
3209 ChrPtr(encoded_subject),
3210 ChrPtr(display_name),
3214 ChrPtr(my_email_addr),
3215 ChrPtr(references));
3217 lprintf(9, "%s\n", CmdBuf);
3218 serv_puts(ChrPtr(CmdBuf));
3219 serv_getln(buf, sizeof buf);
3220 FreeStrBuf(&CmdBuf);
3221 FreeStrBuf(&encoded_subject);
3222 if (buf[0] == '4') {
3223 post_mime_to_server();
3224 if ( (havebstr("recp"))
3225 || (havebstr("cc" ))
3226 || (havebstr("bcc" ))
3228 sprintf(WCC->ImportantMessage, _("Message has been sent.\n"));
3231 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
3233 dont_post = lbstr("postseq");
3235 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
3236 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3242 free_attachments(WCC);
3245 * We may have been supplied with instructions regarding the location
3246 * to which we must return after posting. If found, go there.
3248 if (havebstr("return_to")) {
3249 http_redirect(bstr("return_to"));
3252 * If we were editing a page in a wiki room, go to that page now.
3254 else if (havebstr("wikipage")) {
3255 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
3259 * Otherwise, just go to the "read messages" loop.
3262 readloop("readnew");
3270 * \brief display the message entry screen
3272 void display_enter(void)
3277 const StrBuf *display_name = NULL;
3278 struct wc_attachment *att;
3279 int recipient_required = 0;
3280 int subject_required = 0;
3281 int recipient_bad = 0;
3282 int is_anonymous = 0;
3283 long existing_page = (-1L);
3284 struct wcsession *WCC = WC;
3288 if (havebstr("force_room")) {
3289 gotoroom(bstr("force_room"));
3292 display_name = sbstr("display_name");
3293 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
3294 display_name = NULL;
3298 /** First test to see whether this is a room that requires recipients to be entered */
3299 serv_puts("ENT0 0");
3300 serv_getln(buf, sizeof buf);
3302 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
3303 recipient_required = 1;
3305 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3306 sprintf(WCC->ImportantMessage, "%s", &buf[4]);
3307 readloop("readnew");
3311 /* Is the server strongly recommending that the user enter a message subject? */
3312 if ((buf[3] != '\0') && (buf[4] != '\0')) {
3313 subject_required = extract_int(&buf[4], 1);
3317 * Are we perhaps in an address book view? If so, then an "enter
3318 * message" command really means "add new entry."
3320 if (WCC->wc_default_view == VIEW_ADDRESSBOOK) {
3321 do_edit_vcard(-1, "", "", WCC->wc_roomname);
3326 * Are we perhaps in a calendar room? If so, then an "enter
3327 * message" command really means "add new calendar item."
3329 if (WCC->wc_default_view == VIEW_CALENDAR) {
3330 display_edit_event();
3335 * Are we perhaps in a tasks view? If so, then an "enter
3336 * message" command really means "add new task."
3338 if (WCC->wc_default_view == VIEW_TASKS) {
3339 display_edit_task();
3344 * Otherwise proceed normally.
3345 * Do a custom room banner with no navbar...
3347 output_headers(1, 1, 2, 0, 0, 0);
3348 wprintf("<div id=\"banner\">\n");
3349 embed_room_banner(NULL, navbar_none);
3350 wprintf("</div>\n");
3351 wprintf("<div id=\"content\">\n"
3352 "<div class=\"fix_scrollbar_bug message \">");
3354 /* Now check our actual recipients if there are any */
3355 if (recipient_required) {
3356 const StrBuf *Recp = NULL;
3357 const StrBuf *Cc = NULL;
3358 const StrBuf *Bcc = NULL;
3359 const StrBuf *Wikipage = NULL;
3360 StrBuf *CmdBuf = NULL;;
3361 const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
3363 Recp = sbstr("recp");
3366 Wikipage = sbstr("wikipage");
3368 CmdBuf = NewStrBufPlain(NULL,
3371 StrLength(display_name) +
3374 StrLength(Wikipage));
3376 StrBufPrintf(CmdBuf,
3380 ChrPtr(display_name),
3384 serv_puts(ChrPtr(CmdBuf));
3385 serv_getln(buf, sizeof buf);
3386 FreeStrBuf(&CmdBuf);
3388 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
3389 if (havebstr("recp") &&
3395 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3396 wprintf("<em>%s</em><br />\n", &buf[4]);
3401 /** If we got this far, we can display the message entry screen. */
3403 /* begin message entry screen */
3405 "enctype=\"multipart/form-data\" "
3407 "accept-charset=\"UTF-8\" "
3409 "name=\"enterform\""
3411 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
3412 if (WCC->wc_view == VIEW_WIKI) {
3413 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
3415 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
3416 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WCC->nonce);
3417 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
3418 escputs(WCC->wc_roomname);
3420 wprintf("<input type=\"hidden\" name=\"references\" value=\"");
3421 escputs(bstr("references"));
3424 /** submit or cancel buttons */
3425 wprintf("<p class=\"send_edit_msg\">");
3426 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3427 if (recipient_required) {
3428 wprintf(_("Send message"));
3430 wprintf(_("Post message"));
3433 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3438 wprintf("<img src=\"static/newmess3_24x.gif\" class=\"imgedit\">");
3439 wprintf(" "); /** header bar */
3440 webcit_fmt_date(buf, now, 0);
3442 wprintf("\n"); /** header bar */
3444 wprintf("<table width=\"100%%\" class=\"edit_msg_table\">");
3446 wprintf("<th><label for=\"from_id\" > ");
3447 wprintf(_(" <I>from</I> "));
3448 wprintf("</label></th>");
3450 wprintf("<td colspan=\"2\">");
3452 /* Allow the user to select any of his valid screen names */
3454 wprintf("<select name=\"display_name\" size=1 id=\"from_id\">\n");
3457 serv_getln(buf, sizeof buf);
3458 if (buf[0] == '1') {
3459 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3460 wprintf("<option %s value=\"",
3461 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
3466 wprintf("</option>\n");
3470 if (WCC->room_flags & QR_ANONOPT) {
3471 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
3472 ((!strcasecmp(bstr("__ANONYMOUS__"), WCC->wc_fullname)) ? "selected" : ""),
3477 wprintf("</select>\n");
3479 /* If this is an email (not a post), allow the user to select any of his
3480 * valid email addresses.
3482 if (recipient_required) {
3484 serv_getln(buf, sizeof buf);
3485 if (buf[0] == '1') {
3486 wprintf("<select name=\"my_email_addr\" size=1>\n");
3487 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3488 wprintf("<option value=\"");
3492 wprintf("></option>\n");
3494 wprintf("</select>\n");
3498 wprintf(_(" <I>in</I> "));
3499 escputs(WCC->wc_roomname);
3501 wprintf("</td></tr>");
3503 if (recipient_required) {
3507 wprintf("<tr><th><label for=\"recp_id\"> ");
3509 wprintf("</label></th>"
3510 "<td><input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
3511 ccraw = xbstr("recp", &len);
3512 copy = (char*) malloc(len * 2 + 1);
3513 memcpy(copy, ccraw, len + 1);
3514 utf8ify_rfc822_string(copy);
3517 wprintf("\" size=45 maxlength=1000 />");
3518 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
3519 wprintf("</td><td rowspan=\"3\" align=\"left\" valign=\"top\">");
3521 /** Pop open an address book -- begin **/
3523 "<a href=\"javascript:PopOpenAddressBook('recp_id|%s|cc_id|%s|bcc_id|%s');\" "
3525 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
3527 _("To:"), _("CC:"), _("BCC:"),
3528 _("Contacts"), _("Contacts")
3530 /** Pop open an address book -- end **/
3532 wprintf("</td></tr>");
3534 wprintf("<tr><th><label for=\"cc_id\"> ");
3536 wprintf("</label></th>"
3537 "<td><input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
3538 ccraw = xbstr("cc", &len);
3539 copy = (char*) malloc(len * 2 + 1);
3540 memcpy(copy, ccraw, len + 1);
3541 utf8ify_rfc822_string(copy);
3544 wprintf("\" size=45 maxlength=1000 />");
3545 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
3546 wprintf("</td></tr>");
3548 wprintf("<tr><th><label for=\"bcc_id\"> ");
3550 wprintf("</label></th>"
3551 "<td><input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
3552 ccraw = xbstr("bcc", &len);
3553 copy = (char*) malloc(len * 2 + 1);
3554 memcpy(copy, ccraw, len + 1);
3555 utf8ify_rfc822_string(copy);
3558 wprintf("\" size=45 maxlength=1000 />");
3559 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
3560 wprintf("</td></tr>");
3562 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
3563 wprintf("<script type=\"text/javascript\"> \n"
3564 " activate_entmsg_autocompleters(); \n"
3570 wprintf("<tr><th><label for=\"subject_id\" > ");
3571 if (recipient_required || subject_required) {
3572 wprintf(_("Subject:"));
3575 wprintf(_("Subject (optional):"));
3577 wprintf("</label></th>"
3578 "<td colspan=\"2\">"
3579 "<input type=\"text\" name=\"subject\" id=\"subject_id\" value=\"");
3580 escputs(bstr("subject"));
3581 wprintf("\" size=45 maxlength=70>\n");
3582 wprintf("</td></tr>");
3584 wprintf("<tr><td colspan=\"3\">\n");
3586 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
3588 /** If we're continuing from a previous edit, put our partially-composed message back... */
3589 msgescputs(bstr("msgtext"));
3591 /* If we're forwarding a message, insert it here... */
3592 if (lbstr("fwdquote") > 0L) {
3593 wprintf("<br><div align=center><i>");
3594 wprintf(_("--- forwarded message ---"));
3595 wprintf("</i></div><br>");
3596 pullquote_message(lbstr("fwdquote"), 1, 1);
3599 /** If we're replying quoted, insert the quote here... */
3600 else if (lbstr("replyquote") > 0L) {
3603 pullquote_message(lbstr("replyquote"), 0, 1);
3604 wprintf("</blockquote><br>");
3607 /** If we're editing a wiki page, insert the existing page here... */
3608 else if (WCC->wc_view == VIEW_WIKI) {
3609 safestrncpy(buf, bstr("wikipage"), sizeof buf);
3610 str_wiki_index(buf);
3611 existing_page = locate_message_by_uid(buf);
3612 if (existing_page >= 0L) {
3613 pullquote_message(existing_page, 1, 0);
3617 /** Insert our signature if appropriate... */
3618 if ( (WCC->is_mailbox) && !yesbstr("sig_inserted") ) {
3620 get_pref_yesno("use_sig", &UseSig, 0);
3623 const char *sig, *esig;
3625 get_preference("signature", &ebuf);
3627 StrBufEUid_unescapize(Sig, ebuf);
3629 esig = sig + StrLength(Sig);
3630 wprintf("<br>--<br>");
3631 while (sig <= esig) {
3635 else if (*sig == '<') {
3638 else if (*sig == '>') {
3641 else if (*sig == '&') {
3644 else if (*sig == '\"') {
3647 else if (*sig == '\'') {
3650 else /* since we're utf 8, is this a good idea? if (isprint(*sig))*/ {
3651 wprintf("%c", *sig);
3658 wprintf("</textarea>\n");
3660 /** Make sure we only insert our signature once */
3661 /** We don't care if it was there or not before, it needs to be there now. */
3662 wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
3665 * The following template embeds the TinyMCE richedit control, and automatically
3666 * transforms the textarea into a richedit textarea.
3668 do_template("richedit");
3670 /** Enumerate any attachments which are already in place... */
3671 wprintf("<div class=\"attachment buttons\"><img src=\"static/diskette_24x.gif\" class=\"imgedit\" > ");
3672 wprintf(_("Attachments:"));
3674 wprintf("<select name=\"which_attachment\" size=1>");
3675 for (att = WCC->first_attachment; att != NULL; att = att->next) {
3676 wprintf("<option value=\"");
3677 urlescputs(att->filename);
3679 escputs(att->filename);
3680 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3681 wprintf("</option>\n");
3683 wprintf("</select>");
3685 /** Now offer the ability to attach additional files... */
3686 wprintf(" ");
3687 wprintf(_("Attach file:"));
3688 wprintf(" <input name=\"attachfile\" class=\"attachfile\" "
3689 "size=16 type=\"file\">\n "
3690 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3691 wprintf("</div>"); /* End of "attachment buttons" div */
3694 wprintf("</td></tr></table>");
3696 wprintf("</form>\n");
3697 wprintf("</div>\n"); /* end of "fix_scrollbar_bug" div */
3699 /* NOTE: address_book_popup() will close the "content" div. Don't close it here. */
3700 DONE: address_book_popup();
3706 * \brief delete a message
3708 void delete_msg(void)
3713 msgid = lbstr("msgid");
3715 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3716 serv_printf("DELE %ld", msgid);
3718 else { /** Otherwise move it to Trash */
3719 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3722 serv_getln(buf, sizeof buf);
3723 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3725 readloop("readnew");
3730 * \brief move a message to another folder
3737 msgid = lbstr("msgid");
3739 if (havebstr("move_button")) {
3740 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3742 serv_getln(buf, sizeof buf);
3743 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3745 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3748 readloop("readnew");
3756 * Confirm move of a message
3758 void confirm_move_msg(void)
3764 msgid = lbstr("msgid");
3767 output_headers(1, 1, 2, 0, 0, 0);
3768 wprintf("<div id=\"banner\">\n");
3770 wprintf(_("Confirm move of message"));
3772 wprintf("</div>\n");
3774 wprintf("<div id=\"content\" class=\"service\">\n");
3776 wprintf("<CENTER>");
3778 wprintf(_("Move this message to:"));
3779 wprintf("<br />\n");
3781 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3782 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
3783 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3785 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3787 serv_getln(buf, sizeof buf);
3788 if (buf[0] == '1') {
3789 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3790 extract_token(targ, buf, 0, '|', sizeof targ);
3791 wprintf("<OPTION>");
3796 wprintf("</SELECT>\n");
3797 wprintf("<br />\n");
3799 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3801 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3802 wprintf("</form></CENTER>\n");
3804 wprintf("</CENTER>\n");
3808 void readnew(void) { readloop("readnew");}
3809 void readold(void) { readloop("readold");}
3810 void readfwd(void) { readloop("readfwd");}
3811 void headers(void) { readloop("headers");}
3812 void do_search(void) { readloop("do_search");}
3818 WebcitAddUrlHandler(HKEY("readnew"), readnew, 0);
3819 WebcitAddUrlHandler(HKEY("readold"), readold, 0);
3820 WebcitAddUrlHandler(HKEY("readfwd"), readfwd, 0);
3821 WebcitAddUrlHandler(HKEY("headers"), headers, 0);
3822 WebcitAddUrlHandler(HKEY("do_search"), do_search, 0);
3823 WebcitAddUrlHandler(HKEY("display_enter"), display_enter, 0);
3824 WebcitAddUrlHandler(HKEY("post"), post_message, 0);
3825 WebcitAddUrlHandler(HKEY("move_msg"), move_msg, 0);
3826 WebcitAddUrlHandler(HKEY("delete_msg"), delete_msg, 0);
3827 WebcitAddUrlHandler(HKEY("confirm_move_msg"), confirm_move_msg, 0);
3828 WebcitAddUrlHandler(HKEY("msg"), embed_message, NEED_URL|AJAX);
3829 WebcitAddUrlHandler(HKEY("printmsg"), print_message, NEED_URL);
3830 WebcitAddUrlHandler(HKEY("mobilemsg"), mobile_message_view, NEED_URL);
3831 WebcitAddUrlHandler(HKEY("msgheaders"), display_headers, NEED_URL);