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 */
17 * Address book entry (keep it short and sweet, it's just a quickie lookup
18 * which we can use to get to the real meat and bones later)
21 char ab_name[64]; /**< name string */
22 long ab_msgnum; /**< message number of address book entry */
30 * \brief Wrapper around iconv_open()
31 * Our version adds aliases for non-standard Microsoft charsets
32 * such as 'MS950', aliasing them to names like 'CP950'
34 * \param tocode Target encoding
35 * \param fromcode Source encoding
37 iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode)
39 iconv_t ic = (iconv_t)(-1) ;
40 ic = iconv_open(tocode, fromcode);
41 if (ic == (iconv_t)(-1) ) {
42 char alias_fromcode[64];
43 if ( (strlen(fromcode) == 5) && (!strncasecmp(fromcode, "MS", 2)) ) {
44 safestrncpy(alias_fromcode, fromcode, sizeof alias_fromcode);
45 alias_fromcode[0] = 'C';
46 alias_fromcode[1] = 'P';
47 ic = iconv_open(tocode, alias_fromcode);
55 inline char *FindNextEnd (char *bptr)
58 /* Find the next ?Q? */
59 end = strchr(bptr + 2, '?');
60 if (end == NULL) return NULL;
61 if (((*(end + 1) == 'B') || (*(end + 1) == 'Q')) &&
62 (*(end + 2) == '?')) {
63 /* skip on to the end of the cluster, the next ?= */
64 end = strstr(end + 3, "?=");
67 /* sort of half valid encoding, try to find an end. */
68 end = strstr(bptr, "?=");
73 * \brief Handle subjects with RFC2047 encoding
75 * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=
76 * \param buf the stringbuffer to process
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 char default_header_charset[128];
110 get_preference("default_header_charset", default_header_charset, sizeof default_header_charset);
111 if ( (strcasecmp(default_header_charset, "UTF-8")) && (strcasecmp(default_header_charset, "us-ascii")) ) {
112 ic = ctdl_iconv_open("UTF-8", default_header_charset);
113 if (ic != (iconv_t)(-1) ) {
116 safestrncpy(ibuf, buf, 1024);
117 ibuflen = strlen(ibuf);
119 obuf = (char *) malloc(obuflen);
121 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
122 osav[1024-obuflen] = 0;
131 /* pre evaluate the first pair */
132 nextend = end = NULL;
134 start = strstr(buf, "=?");
136 end = FindNextEnd (start);
138 while ((start != NULL) && (end != NULL))
140 next = strstr(end, "=?");
142 nextend = FindNextEnd(next);
146 /* did we find two partitions */
147 if ((next != NULL) &&
151 while ((ptr < next) &&
157 /* did we find a gab just filled with blanks? */
162 len - (next - start));
164 /* now terminate the gab at the end */
165 delta = (next - end) - 2;
169 /* move next to its new location. */
174 /* our next-pair is our new first pair now. */
179 /** Now we handle foreign character sets properly encoded
182 while (start=strstr(buf, "=?"), end=FindNextEnd((start != NULL)? start : buf),
183 ((start != NULL) && (end != NULL) && (end > start)) )
185 extract_token(charset, start, 1, '?', sizeof charset);
186 extract_token(encoding, start, 2, '?', sizeof encoding);
187 extract_token(istr, start, 3, '?', sizeof istr);
191 if (!strcasecmp(encoding, "B")) { /**< base64 */
192 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
194 else if (!strcasecmp(encoding, "Q")) { /**< quoted-printable */
202 if (istr[pos] == '_') istr[pos] = ' ';
206 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, len);
209 strcpy(ibuf, istr); /**< unknown encoding */
210 ibuflen = strlen(istr);
213 ic = ctdl_iconv_open("UTF-8", charset);
214 if (ic != (iconv_t)(-1) ) {
216 obuf = (char *) malloc(obuflen);
218 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
219 osav[1024-obuflen] = 0;
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%s%s", buf, osav, end);
239 remove_token(end, 0, '?');
240 remove_token(end, 0, '?');
241 remove_token(end, 0, '?');
242 remove_token(end, 0, '?');
243 strcpy(end, &end[1]);
245 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
252 * Since spammers will go to all sorts of absurd lengths to get their
253 * messages through, there are LOTS of corrupt headers out there.
254 * So, prevent a really badly formed RFC2047 header from throwing
255 * this function into an infinite loop.
258 if (passes > 20) return;
263 inline void utf8ify_rfc822_string(char *a){};
271 * \brief RFC2047-encode a header field if necessary.
272 * If no non-ASCII characters are found, the string
273 * will be copied verbatim without encoding.
275 * \param target Target buffer.
276 * \param maxlen Maximum size of target buffer.
277 * \param source Source string to be encoded.
278 * \param SourceLen Length of the source string
279 * \returns encoded length; -1 if non success.
281 int webcit_rfc2047encode(char *target, int maxlen, char *source, long SourceLen)
283 const char headerStr[] = "=?UTF-8?Q?";
284 int need_to_encode = 0;
289 if ((source == NULL) ||
291 (SourceLen > maxlen)) return -1;
293 while ((!IsEmptyStr (&source[i])) &&
294 (need_to_encode == 0) &&
296 if (((unsigned char) source[i] < 32) ||
297 ((unsigned char) source[i] > 126)) {
303 if (!need_to_encode) {
304 memcpy (target, source, SourceLen);
308 if (sizeof (headerStr + SourceLen + 2) > maxlen)
310 memcpy (target, headerStr, sizeof (headerStr));
311 len = sizeof (headerStr);
312 for (i=0; (i < SourceLen) && (len < maxlen) ; ++i) {
313 ch = (unsigned char) source[i];
314 if ((ch < 32) || (ch > 126) || (ch == 61)) {
315 sprintf(&target[len], "=%02X", ch);
319 sprintf(&target[len], "%c", ch);
324 if (len + 2 < maxlen) {
325 strcat(&target[len], "?=");
337 * \brief Look for URL's embedded in a buffer and make them linkable. We use a
338 * target window in order to keep the BBS session in its own window.
339 * \param buf the message buffer
344 char *start, *end, *pos;
351 for (pos = buf; (pos < end) && (start == NULL); ++pos) {
352 if (!strncasecmp(pos, "http://", 7))
354 if (!strncasecmp(pos, "ftp://", 6))
361 for (pos = buf+len; pos > start; --pos) {
362 if ( (!isprint(*pos))
381 strncpy(urlbuf, start, end - start);
382 urlbuf[end - start] = '\0';
385 strncpy(outbuf, buf, start - buf );
386 sprintf(&outbuf[start-buf], "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
387 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
389 if ( strlen(outbuf) < 250 )
395 * \brief Turn a vCard "n" (name) field into something displayable.
396 * \param name the name field to convert
398 void vcard_n_prettyize(char *name)
403 original_name = strdup(name);
404 len = strlen(original_name);
405 for (i=0; i<5; ++i) {
407 if (original_name[len-1] == ' ') {
408 original_name[--len] = 0;
410 if (original_name[len-1] == ';') {
411 original_name[--len] = 0;
417 for (i=0; i<len; ++i) {
418 if (original_name[i] == ';') {
423 name[j++] = original_name[i];
434 * \brief preparse a vcard name
435 * display_vcard() calls this after parsing the textual vCard into
436 * our 'struct vCard' data object.
437 * This gets called instead of display_parsed_vcard() if we are only looking
438 * to extract the person's name instead of displaying the card.
439 * \param v the vcard to retrieve the name from
440 * \param storename where to put the name at
442 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
445 strcpy(storename, "");
447 name = vcard_get_prop(v, "n", 1, 0, 0);
449 strcpy(storename, name);
450 /* vcard_n_prettyize(storename); */
458 * \brief html print a vcard
459 * display_vcard() calls this after parsing the textual vCard into
460 * our 'struct vCard' data object.
462 * Set 'full' to nonzero to display the full card, otherwise it will only
463 * show a summary line.
465 * This code is a bit ugly, so perhaps an explanation is due: we do this
466 * in two passes through the vCard fields. On the first pass, we process
467 * fields we understand, and then render them in a pretty fashion at the
468 * end. Then we make a second pass, outputting all the fields we don't
469 * understand in a simple two-column name/value format.
470 * \param v the vCard to display
471 * \param full display all items of the vcard?
473 void display_parsed_vcard(struct vCard *v, int full) {
479 char *thisname, *thisvalue;
480 char firsttoken[SIZ];
489 strcpy(fullname, "");
497 name = vcard_get_prop(v, "fn", 1, 0, 0);
501 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
502 strcpy(fullname, name);
503 vcard_n_prettyize(fullname);
513 wprintf("<div align=center>"
514 "<table bgcolor=#aaaaaa width=50%%>");
515 for (pass=1; pass<=2; ++pass) {
517 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
519 thisname = strdup(v->prop[i].name);
520 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
522 for (j=0; j<num_tokens(thisname, ';'); ++j) {
523 extract_token(buf, thisname, j, ';', sizeof buf);
524 if (!strcasecmp(buf, "encoding=quoted-printable")) {
526 remove_token(thisname, j, ';');
528 if (!strcasecmp(buf, "encoding=base64")) {
530 remove_token(thisname, j, ';');
534 len = strlen(v->prop[i].value);
535 /* if we have some untagged QP, detect it here. */
536 if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
537 utf8ify_rfc822_string(v->prop[i].value);
540 // %ff can become 6 bytes in utf8
541 thisvalue = malloc(len * 2 + 3);
542 j = CtdlDecodeQuotedPrintable(
543 thisvalue, v->prop[i].value,
548 // ff will become one byte..
549 thisvalue = malloc(len + 50);
551 thisvalue, v->prop[i].value,
552 strlen(v->prop[i].value) );
555 thisvalue = strdup(v->prop[i].value);
558 /** Various fields we may encounter ***/
560 /** N is name, but only if there's no FN already there */
561 if (!strcasecmp(firsttoken, "n")) {
562 if (IsEmptyStr(fullname)) {
563 strcpy(fullname, thisvalue);
564 vcard_n_prettyize(fullname);
568 /** FN (full name) is a true 'display name' field */
569 else if (!strcasecmp(firsttoken, "fn")) {
570 strcpy(fullname, thisvalue);
574 else if (!strcasecmp(firsttoken, "title")) {
575 strcpy(title, thisvalue);
579 else if (!strcasecmp(firsttoken, "org")) {
580 strcpy(org, thisvalue);
583 else if (!strcasecmp(firsttoken, "email")) {
585 if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
587 "<a href=\"display_enter"
588 "?force_room=_MAIL_?recp=");
590 len = strlen(mailto);
591 urlesc(&mailto[len], SIZ - len, "\"");
592 len = strlen(mailto);
593 urlesc(&mailto[len], SIZ - len, fullname);
594 len = strlen(mailto);
595 urlesc(&mailto[len], SIZ - len, "\" <");
596 len = strlen(mailto);
597 urlesc(&mailto[len], SIZ - len, thisvalue);
598 len = strlen(mailto);
599 urlesc(&mailto[len], SIZ - len, ">");
601 strcat(mailto, "\">");
602 len = strlen(mailto);
603 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
604 strcat(mailto, "</A>");
606 else if (!strcasecmp(firsttoken, "tel")) {
607 if (!IsEmptyStr(phone)) strcat(phone, "<br />");
608 strcat(phone, thisvalue);
609 for (j=0; j<num_tokens(thisname, ';'); ++j) {
610 extract_token(buf, thisname, j, ';', sizeof buf);
611 if (!strcasecmp(buf, "tel"))
613 else if (!strcasecmp(buf, "work"))
614 strcat(phone, _(" (work)"));
615 else if (!strcasecmp(buf, "home"))
616 strcat(phone, _(" (home)"));
617 else if (!strcasecmp(buf, "cell"))
618 strcat(phone, _(" (cell)"));
626 else if (!strcasecmp(firsttoken, "adr")) {
629 wprintf(_("Address:"));
630 wprintf("</TD><TD>");
631 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
632 extract_token(buf, thisvalue, j, ';', sizeof buf);
633 if (!IsEmptyStr(buf)) {
635 if (j<3) wprintf("<br />");
639 wprintf("</TD></TR>\n");
642 else if (!strcasecmp(firsttoken, "version")) {
645 else if (!strcasecmp(firsttoken, "rev")) {
648 else if (!strcasecmp(firsttoken, "label")) {
653 /*** Don't show extra fields. They're ugly.
657 wprintf("</TD><TD>");
659 wprintf("</TD></TR>\n");
669 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
670 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
671 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
672 "<FONT SIZE=+1><B>");
674 wprintf("</B></FONT>");
675 if (!IsEmptyStr(title)) {
676 wprintf("<div align=right>");
680 if (!IsEmptyStr(org)) {
681 wprintf("<div align=right>");
685 wprintf("</TD></TR>\n");
687 if (!IsEmptyStr(phone)) {
689 wprintf(_("Telephone:"));
690 wprintf("</td><td>%s</td></tr>\n", phone);
692 if (!IsEmptyStr(mailto)) {
694 wprintf(_("E-mail:"));
695 wprintf("</td><td>%s</td></tr>\n", mailto);
701 wprintf("</table></div>\n");
707 * \brief Display a textual vCard
708 * (Converts to a vCard object and then calls the actual display function)
709 * Set 'full' to nonzero to display the whole card instead of a one-liner.
710 * Or, if "storename" is non-NULL, just store the person's name in that
711 * buffer instead of displaying the card at all.
712 * \param vcard_source the buffer containing the vcard text
713 * \param alpha what???
714 * \param full should we usse all lines?
715 * \param storename where to store???
717 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
723 v = vcard_load(vcard_source);
724 if (v == NULL) return;
726 name = vcard_get_prop(v, "n", 1, 0, 0);
728 utf8ify_rfc822_string(name);
733 if (storename != NULL) {
734 fetchname_parsed_vcard(v, storename);
736 else if ( (alpha == 0)
737 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
738 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
740 display_parsed_vcard(v, full);
754 * I wanna SEE that message!
756 * msgnum Message number to display
757 * printable_view Nonzero to display a printable view
758 * section Optional for encapsulated message/rfc822 submessage
760 void read_message(long msgnum, int printable_view, char *section) {
762 char mime_partnum[256] = "";
763 char mime_name[256] = "";
764 char mime_filename[256] = "";
765 char escaped_mime_filename[256] = "";
766 char mime_content_type[256] = "";
767 const char *mime_content_type_ptr;
768 char mime_charset[256] = "";
769 char mime_disposition[256] = "";
771 struct attach_link *attach_links = NULL;
772 int num_attach_links = 0;
773 char mime_submessages[256] = "";
774 char m_subject[1024] = "";
775 char m_cc[1024] = "";
779 char reply_to[512] = "";
780 char reply_all[4096] = "";
786 char vcard_partnum[256] = "";
787 char cal_partnum[256] = "";
788 char *part_source = NULL;
789 char msg4_partnum[32] = "";
791 iconv_t ic = (iconv_t)(-1) ;
792 char *ibuf; /**< Buffer of characters to be converted */
793 char *obuf; /**< Buffer for converted characters */
794 size_t ibuflen; /**< Length of input buffer */
795 size_t obuflen; /**< Length of output buffer */
796 char *osav; /**< Saved pointer to output buffer */
799 strcpy(mime_content_type, "text/plain");
800 strcpy(mime_charset, "us-ascii");
801 strcpy(mime_submessages, "");
803 serv_printf("MSG4 %ld|%s", msgnum, section);
804 serv_getln(buf, sizeof buf);
807 wprintf(_("ERROR:"));
808 wprintf("</strong> %s<br />\n", &buf[4]);
812 /** begin everythingamundo table */
813 if (!printable_view) {
814 wprintf("<div class=\"fix_scrollbar_bug message\" ");
815 wprintf("onMouseOver=document.getElementById(\"msg%ld\").style.visibility=\"visible\" ", msgnum);
816 wprintf("onMouseOut=document.getElementById(\"msg%ld\").style.visibility=\"hidden\" >", msgnum);
819 /** begin message header table */
820 wprintf("<div class=\"message_header\">");
822 strcpy(m_subject, "");
825 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
826 if (!strcmp(buf, "000")) {
828 wprintf(_("unexpected end of message"));
829 wprintf(" (1)</i><br /><br />\n");
833 if (!strncasecmp(buf, "nhdr=yes", 8))
837 if (!strncasecmp(buf, "type=", 5))
838 format_type = atoi(&buf[5]);
839 if (!strncasecmp(buf, "from=", 5)) {
840 strcpy(from, &buf[5]);
842 wprintf("<a href=\"showuser?who=");
843 utf8ify_rfc822_string(from);
849 if (!strncasecmp(buf, "subj=", 5)) {
850 safestrncpy(m_subject, &buf[5], sizeof m_subject);
852 if (!strncasecmp(buf, "cccc=", 5)) {
854 safestrncpy(m_cc, &buf[5], sizeof m_cc);
855 if (!IsEmptyStr(reply_all)) {
856 strcat(reply_all, ", ");
858 len = strlen(reply_all);
859 safestrncpy(&reply_all[len], &buf[5],
860 (sizeof reply_all - len) );
862 if ((!strncasecmp(buf, "hnod=", 5))
863 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
864 wprintf("(%s) ", &buf[5]);
866 if ((!strncasecmp(buf, "room=", 5))
867 && (strcasecmp(&buf[5], WC->wc_roomname))
868 && (!IsEmptyStr(&buf[5])) ) {
870 wprintf("%s> ", &buf[5]);
872 if (!strncasecmp(buf, "rfca=", 5)) {
873 strcpy(rfca, &buf[5]);
879 if (!strncasecmp(buf, "node=", 5)) {
880 strcpy(node, &buf[5]);
881 if ( ((WC->room_flags & QR_NETWORK)
882 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
883 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
884 && (IsEmptyStr(rfca))
886 wprintf("@%s ", &buf[5]);
889 if (!strncasecmp(buf, "rcpt=", 5)) {
892 if (!IsEmptyStr(reply_all)) {
893 strcat(reply_all, ", ");
895 len = strlen(reply_all);
896 safestrncpy(&reply_all[len], &buf[5],
897 (sizeof reply_all - len) );
898 utf8ify_rfc822_string(&buf[5]);
902 if (!strncasecmp(buf, "time=", 5)) {
903 webcit_fmt_date(now, atol(&buf[5]), 0);
909 if (!strncasecmp(buf, "part=", 5)) {
910 extract_token(mime_name, &buf[5], 0, '|', sizeof mime_filename);
911 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
912 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
913 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
914 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
915 mime_length = extract_int(&buf[5], 5);
918 striplt(mime_filename);
919 if ( (IsEmptyStr(mime_filename)) && (!IsEmptyStr(mime_name)) ) {
920 strcpy(mime_filename, mime_name);
923 if (!strcasecmp(mime_content_type, "message/rfc822")) {
924 if (!IsEmptyStr(mime_submessages)) {
925 strcat(mime_submessages, "|");
927 strcat(mime_submessages, mime_partnum);
929 else if ((!strcasecmp(mime_disposition, "inline"))
930 && (!strncasecmp(mime_content_type, "image/", 6)) ){
932 attach_links = realloc(attach_links,
933 (num_attach_links*sizeof(struct attach_link)));
934 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
935 snprintf(attach_links[num_attach_links-1].html, 1024,
936 "<img src=\"mimepart/%ld/%s/%s\">",
937 msgnum, mime_partnum, mime_filename);
939 else if ( ( (!strcasecmp(mime_disposition, "attachment"))
940 || (!strcasecmp(mime_disposition, "inline"))
941 || (!strcasecmp(mime_disposition, ""))
942 ) && (!IsEmptyStr(mime_content_type))
945 attach_links = realloc(attach_links,
946 (num_attach_links*sizeof(struct attach_link)));
947 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
948 utf8ify_rfc822_string(mime_filename);
950 mime_content_type_ptr = mime_content_type;
951 if (strcasecmp(mime_content_type, "application/octet-stream") == 0) {
952 mime_content_type_ptr = GuessMimeByFilename(mime_filename,
953 strlen(mime_filename));
955 urlesc(escaped_mime_filename, 265, mime_filename);
956 snprintf(attach_links[num_attach_links-1].html, 1024,
957 "<img src=\"display_mime_icon?type=%s\" "
958 "border=0 align=middle>\n"
959 "%s (%s, %d bytes) [ "
960 "<a href=\"mimepart/%ld/%s/%s\""
961 "target=\"wc.%ld.%s\">%s</a>"
963 "<a href=\"mimepart_download/%ld/%s/%s\">%s</a>"
965 mime_content_type_ptr,
967 mime_content_type, mime_length,
968 msgnum, mime_partnum, escaped_mime_filename,
969 msgnum, mime_partnum,
971 msgnum, mime_partnum, escaped_mime_filename,
976 /** begin handler prep ***/
977 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
978 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
979 strcpy(vcard_partnum, mime_partnum);
982 if ( (!strcasecmp(mime_content_type, "text/calendar"))
983 || (!strcasecmp(mime_content_type, "application/ics")) ) {
984 strcpy(cal_partnum, mime_partnum);
987 /** end handler prep ***/
993 /** Generate a reply-to address */
994 if (!IsEmptyStr(rfca)) {
995 if (!IsEmptyStr(from)) {
996 snprintf(reply_to, sizeof(reply_to), "%s <%s>", from, rfca);
999 strcpy(reply_to, rfca);
1003 if ((!IsEmptyStr(node))
1004 && (strcasecmp(node, serv_info.serv_nodename))
1005 && (strcasecmp(node, serv_info.serv_humannode)) ) {
1006 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
1010 snprintf(reply_to, sizeof(reply_to), "%s", from);
1018 utf8ify_rfc822_string(m_cc);
1019 utf8ify_rfc822_string(m_subject);
1021 /** start msg buttons */
1023 if (!printable_view) {
1024 wprintf("<p id=\"msg%ld\" class=\"msgbuttons\" >\n",msgnum);
1027 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
1028 wprintf("<a href=\"display_enter");
1029 if (WC->is_mailbox) {
1030 wprintf("?replyquote=%ld", msgnum);
1033 urlescputs(reply_to);
1034 if (!IsEmptyStr(m_subject)) {
1035 wprintf("?subject=");
1036 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
1037 urlescputs(m_subject);
1039 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Reply"));
1043 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
1044 if (!WC->is_mailbox) {
1045 wprintf("<a href=\"display_enter");
1046 wprintf("?replyquote=%ld", msgnum);
1048 urlescputs(reply_to);
1049 if (!IsEmptyStr(m_subject)) {
1050 wprintf("?subject=");
1051 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
1052 urlescputs(m_subject);
1054 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyQuoted"));
1059 if (WC->wc_view == VIEW_MAILBOX) {
1060 wprintf("<a href=\"display_enter");
1061 wprintf("?replyquote=%ld", msgnum);
1063 urlescputs(reply_to);
1065 urlescputs(reply_all);
1066 if (!IsEmptyStr(m_subject)) {
1067 wprintf("?subject=");
1068 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
1069 urlescputs(m_subject);
1071 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyAll"));
1075 if (WC->wc_view == VIEW_MAILBOX) {
1076 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
1077 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
1078 urlescputs(m_subject);
1079 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Forward"));
1082 /** If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
1083 if ( (WC->is_room_aide) || (WC->is_mailbox) || (WC->room_flags2 & QR2_COLLABDEL) ) {
1085 wprintf("<a href=\"confirm_move_msg?msgid=%ld\"><span>[</span>%s<span>]</span></a> ",
1089 wprintf("<a href=\"delete_msg?msgid=%ld\" "
1090 "onClick=\"return confirm('%s');\">"
1091 "<span>[</span>%s<span>]</span> "
1092 "</a> ", msgnum, _("Delete this message?"), _("Delete")
1097 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'); \" >"
1098 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Headers"));
1102 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'); \" >"
1103 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Print"));
1109 if (!IsEmptyStr(m_cc)) {
1116 if (!IsEmptyStr(m_subject)) {
1117 wprintf("<p class=\"message_subject\">");
1118 wprintf(_("Subject:"));
1127 wprintf("<div class=\"message_content\">");
1130 * Learn the content type
1132 strcpy(mime_content_type, "text/plain");
1133 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1134 if (!strcmp(buf, "000")) {
1135 /* This is not necessarily an error condition. See bug #226. */
1138 if (!strncasecmp(buf, "X-Citadel-MSG4-Partnum:", 23)) {
1139 safestrncpy(msg4_partnum, &buf[23], sizeof(msg4_partnum));
1140 striplt(msg4_partnum);
1142 if (!strncasecmp(buf, "Content-type:", 13)) {
1144 safestrncpy(mime_content_type, &buf[13], sizeof(mime_content_type));
1145 striplt(mime_content_type);
1146 len = strlen(mime_content_type);
1147 for (i=0; i<len; ++i) {
1148 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1149 safestrncpy(mime_charset, &mime_content_type[i+8],
1150 sizeof mime_charset);
1153 for (i=0; i<len; ++i) {
1154 if (mime_content_type[i] == ';') {
1155 mime_content_type[i] = 0;
1159 len = strlen(mime_charset);
1160 for (i=0; i<len; ++i) {
1161 if (mime_charset[i] == ';') {
1162 mime_charset[i] = 0;
1169 /** Set up a character set conversion if we need to (and if we can) */
1171 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
1172 if ( (strcasecmp(mime_charset, "us-ascii"))
1173 && (strcasecmp(mime_charset, "UTF-8"))
1174 && (strcasecmp(mime_charset, ""))
1176 ic = ctdl_iconv_open("UTF-8", mime_charset);
1177 if (ic == (iconv_t)(-1) ) {
1178 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1179 __FILE__, __LINE__, mime_charset, strerror(errno));
1184 /** Messages in legacy Citadel variformat get handled thusly... */
1185 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1189 /** Boring old 80-column fixed format text gets handled this way... */
1190 else if ( (!strcasecmp(mime_content_type, "text/plain"))
1191 || (!strcasecmp(mime_content_type, "text")) ) {
1193 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1196 if ((len > 0) && buf[len-1] == '\n') buf[--len] = 0;
1197 if ((len > 0) && buf[len-1] == '\r') buf[--len] = 0;
1200 if (ic != (iconv_t)(-1) ) {
1202 ibuflen = strlen(ibuf);
1204 obuf = (char *) malloc(obuflen);
1206 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1207 osav[SIZ-obuflen] = 0;
1208 safestrncpy(buf, osav, sizeof buf);
1214 while ((!IsEmptyStr(buf)) && (isspace(buf[len-1])))
1217 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1218 wprintf("<blockquote>");
1220 } else if ((bq == 1) &&
1221 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1222 wprintf("</blockquote>");
1228 wprintf("</tt><br />\n");
1230 wprintf("</i><br />");
1233 else /** HTML is fun, but we've got to strip it first */
1234 if (!strcasecmp(mime_content_type, "text/html")) {
1235 output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
1238 /** Unknown weirdness */
1240 wprintf(_("I don't know how to display %s"), mime_content_type);
1241 wprintf("<br />\n", mime_content_type);
1242 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1245 ENDBODY: /* If there are attached submessages, display them now... */
1247 if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
1248 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1249 extract_token(buf, mime_submessages, i, '|', sizeof buf);
1250 /** use printable_view to suppress buttons */
1251 wprintf("<blockquote>");
1252 read_message(msgnum, 1, buf);
1253 wprintf("</blockquote>");
1258 /** Afterwards, offer links to download attachments 'n' such */
1259 if ( (num_attach_links > 0) && (!section[0]) ) {
1260 for (i=0; i<num_attach_links; ++i) {
1261 if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
1262 wprintf("%s", attach_links[i].html);
1267 /** Handler for vCard parts */
1268 if (!IsEmptyStr(vcard_partnum)) {
1269 part_source = load_mimepart(msgnum, vcard_partnum);
1270 if (part_source != NULL) {
1272 /** If it's my vCard I can edit it */
1273 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1274 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1275 || (WC->wc_view == VIEW_ADDRESSBOOK)
1277 wprintf("<a href=\"edit_vcard?"
1278 "msgnum=%ld?partnum=%s\">",
1279 msgnum, vcard_partnum);
1280 wprintf("[%s]</a>", _("edit"));
1283 /** In all cases, display the full card */
1284 display_vcard(part_source, 0, 1, NULL);
1288 /** Handler for calendar parts */
1289 if (!IsEmptyStr(cal_partnum)) {
1290 part_source = load_mimepart(msgnum, cal_partnum);
1291 if (part_source != NULL) {
1292 cal_process_attachment(part_source,
1293 msgnum, cal_partnum);
1302 wprintf("</div>\n");
1304 /** end everythingamundo table */
1305 if (!printable_view) {
1306 wprintf("</div>\n");
1309 if (num_attach_links > 0) {
1314 if (ic != (iconv_t)(-1) ) {
1323 * \brief Unadorned HTML output of an individual message, suitable
1324 * for placing in a hidden iframe, for printing, or whatever
1326 * \param msgnum_as_string Message number, as a string instead of as a long int
1328 void embed_message(char *msgnum_as_string) {
1331 msgnum = atol(msgnum_as_string);
1332 begin_ajax_response();
1333 read_message(msgnum, 0, "");
1334 end_ajax_response();
1339 * \brief Printable view of a message
1341 * \param msgnum_as_string Message number, as a string instead of as a long int
1343 void print_message(char *msgnum_as_string) {
1346 msgnum = atol(msgnum_as_string);
1347 output_headers(0, 0, 0, 0, 0, 0);
1349 wprintf("Content-type: text/html\r\n"
1351 "Connection: close\r\n",
1355 wprintf("\r\n\r\n<html>\n"
1356 "<head><title>Printable view</title></head>\n"
1357 "<body onLoad=\" window.print(); window.close(); \">\n"
1360 read_message(msgnum, 1, "");
1362 wprintf("\n</body></html>\n\n");
1369 * \brief Display a message's headers
1371 * \param msgnum_as_string Message number, as a string instead of as a long int
1373 void display_headers(char *msgnum_as_string) {
1377 msgnum = atol(msgnum_as_string);
1378 output_headers(0, 0, 0, 0, 0, 0);
1380 wprintf("Content-type: text/plain\r\n"
1382 "Connection: close\r\n",
1386 serv_printf("MSG2 %ld|3", msgnum);
1387 serv_getln(buf, sizeof buf);
1388 if (buf[0] == '1') {
1389 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1390 wprintf("%s\n", buf);
1400 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1401 * or 'reply quoted' operations.
1403 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1404 * in this function. Doing so would throw a JavaScript error in the
1405 * 'supplied text' argument to the editor.
1407 * \param msgnum Message number of the message we want to quote
1408 * \param forward_attachments Nonzero if we want attachments to be forwarded
1410 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1412 char mime_partnum[256];
1413 char mime_filename[256];
1414 char mime_content_type[256];
1415 char mime_charset[256];
1416 char mime_disposition[256];
1418 char *attachments = NULL;
1420 int num_attachments = 0;
1421 struct wc_attachment *att, *aptr;
1422 char m_subject[1024];
1429 int format_type = 0;
1434 iconv_t ic = (iconv_t)(-1) ;
1435 char *ibuf; /**< Buffer of characters to be converted */
1436 char *obuf; /**< Buffer for converted characters */
1437 size_t ibuflen; /**< Length of input buffer */
1438 size_t obuflen; /**< Length of output buffer */
1439 char *osav; /**< Saved pointer to output buffer */
1445 strcpy(reply_to, "");
1446 strcpy(mime_content_type, "text/plain");
1447 strcpy(mime_charset, "us-ascii");
1449 serv_printf("MSG4 %ld", msgnum);
1450 serv_getln(buf, sizeof buf);
1451 if (buf[0] != '1') {
1452 wprintf(_("ERROR:"));
1453 wprintf("%s<br />", &buf[4]);
1457 strcpy(m_subject, "");
1459 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1460 if (!strcmp(buf, "000")) {
1461 wprintf("%s (3)", _("unexpected end of message"));
1464 if (include_headers) {
1465 if (!strncasecmp(buf, "nhdr=yes", 8))
1469 if (!strncasecmp(buf, "type=", 5))
1470 format_type = atoi(&buf[5]);
1471 if (!strncasecmp(buf, "from=", 5)) {
1472 strcpy(from, &buf[5]);
1473 wprintf(_("from "));
1474 utf8ify_rfc822_string(from);
1477 if (!strncasecmp(buf, "subj=", 5)) {
1478 strcpy(m_subject, &buf[5]);
1480 if ((!strncasecmp(buf, "hnod=", 5))
1481 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1482 wprintf("(%s) ", &buf[5]);
1484 if ((!strncasecmp(buf, "room=", 5))
1485 && (strcasecmp(&buf[5], WC->wc_roomname))
1486 && (!IsEmptyStr(&buf[5])) ) {
1488 wprintf("%s> ", &buf[5]);
1490 if (!strncasecmp(buf, "rfca=", 5)) {
1491 strcpy(rfca, &buf[5]);
1497 if (!strncasecmp(buf, "node=", 5)) {
1498 strcpy(node, &buf[5]);
1499 if ( ((WC->room_flags & QR_NETWORK)
1500 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1501 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1502 && (IsEmptyStr(rfca))
1504 wprintf("@%s ", &buf[5]);
1507 if (!strncasecmp(buf, "rcpt=", 5)) {
1509 strcpy(to, &buf[5]);
1510 utf8ify_rfc822_string(to);
1513 if (!strncasecmp(buf, "time=", 5)) {
1514 webcit_fmt_date(now, atol(&buf[5]), 0);
1515 wprintf("%s ", now);
1520 * Save attachment info for later. We can't start downloading them
1521 * yet because we're in the middle of a server transaction.
1523 if (!strncasecmp(buf, "part=", 5)) {
1524 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1527 sprintf(ptr, "%s%s\n",
1528 ((attachments != NULL) ? attachments : ""),
1533 lprintf(9, "attachments=<%s>\n", attachments);
1539 if (include_headers) {
1542 utf8ify_rfc822_string(m_subject);
1543 if (!IsEmptyStr(m_subject)) {
1544 wprintf(_("Subject:"));
1546 msgescputs(m_subject);
1557 * Learn the content type
1559 strcpy(mime_content_type, "text/plain");
1560 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1561 if (!strcmp(buf, "000")) {
1562 wprintf("%s (4)", _("unexpected end of message"));
1565 if (!strncasecmp(buf, "Content-type: ", 14)) {
1567 safestrncpy(mime_content_type, &buf[14],
1568 sizeof(mime_content_type));
1569 for (i=0; i<strlen(mime_content_type); ++i) {
1570 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1571 safestrncpy(mime_charset, &mime_content_type[i+8],
1572 sizeof mime_charset);
1575 len = strlen(mime_content_type);
1576 for (i=0; i<len; ++i) {
1577 if (mime_content_type[i] == ';') {
1578 mime_content_type[i] = 0;
1582 len = strlen(mime_charset);
1583 for (i=0; i<len; ++i) {
1584 if (mime_charset[i] == ';') {
1585 mime_charset[i] = 0;
1592 /** Set up a character set conversion if we need to (and if we can) */
1594 if ( (strcasecmp(mime_charset, "us-ascii"))
1595 && (strcasecmp(mime_charset, "UTF-8"))
1596 && (strcasecmp(mime_charset, ""))
1598 ic = ctdl_iconv_open("UTF-8", mime_charset);
1599 if (ic == (iconv_t)(-1) ) {
1600 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1601 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1606 /** Messages in legacy Citadel variformat get handled thusly... */
1607 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1611 /* Boring old 80-column fixed format text gets handled this way... */
1612 else if (!strcasecmp(mime_content_type, "text/plain")) {
1613 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1616 if (buf[len-1] == '\n') buf[--len] = 0;
1617 if (buf[len-1] == '\r') buf[--len] = 0;
1620 if (ic != (iconv_t)(-1) ) {
1624 obuf = (char *) malloc(obuflen);
1626 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1627 osav[SIZ-obuflen] = 0;
1628 safestrncpy(buf, osav, sizeof buf);
1634 while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
1637 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1638 wprintf("<blockquote>");
1640 } else if ((bq == 1) &&
1641 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1642 wprintf("</blockquote>");
1648 wprintf("</tt><br />");
1650 wprintf("</i><br />");
1653 /** HTML just gets escaped and stuffed back into the editor */
1654 else if (!strcasecmp(mime_content_type, "text/html")) {
1655 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1661 /** Unknown weirdness ... don't know how to handle this content type */
1663 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1667 /** end of body handler */
1670 * If there were attachments, we have to download them and insert them
1671 * into the attachment chain for the forwarded message we are composing.
1673 if ( (forward_attachments) && (num_attachments) ) {
1674 for (i=0; i<num_attachments; ++i) {
1675 extract_token(buf, attachments, i, '\n', sizeof buf);
1676 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1677 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1678 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1679 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1680 mime_length = extract_int(buf, 5);
1683 * tracing ... uncomment if necessary
1686 lprintf(9, "fwd filename: %s\n", mime_filename);
1687 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1688 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1689 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1690 lprintf(9, "fwd length : %d\n", mime_length);
1692 if ( (!strcasecmp(mime_disposition, "inline"))
1693 || (!strcasecmp(mime_disposition, "attachment")) ) {
1695 /* Create an attachment struct from this mime part... */
1696 att = malloc(sizeof(struct wc_attachment));
1697 memset(att, 0, sizeof(struct wc_attachment));
1698 att->length = mime_length;
1699 strcpy(att->content_type, mime_content_type);
1700 strcpy(att->filename, mime_filename);
1702 att->data = load_mimepart(msgnum, mime_partnum);
1704 /* And add it to the list. */
1705 if (WC->first_attachment == NULL) {
1706 WC->first_attachment = att;
1709 aptr = WC->first_attachment;
1710 while (aptr->next != NULL) aptr = aptr->next;
1719 if (ic != (iconv_t)(-1) ) {
1724 if (attachments != NULL) {
1730 * \brief Display one row in the mailbox summary view
1732 * \param num The row number to be displayed
1734 void display_summarized(int num) {
1737 wprintf("<tr id=\"m%ld\" style=\"font-weight:%s;\" "
1738 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1739 WC->summ[num].msgnum,
1740 (WC->summ[num].is_new ? "bold" : "normal"),
1741 WC->summ[num].msgnum
1744 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1746 escputs(WC->summ[num].subj);//////////////////////////////////TODO: QP DECODE
1749 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1750 escputs(WC->summ[num].from);
1753 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1754 webcit_fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1764 * \brief display the adressbook overview
1765 * \param msgnum the citadel message number
1766 * \param alpha what????
1768 void display_addressbook(long msgnum, char alpha) {
1770 char mime_partnum[SIZ];
1771 char mime_filename[SIZ];
1772 char mime_content_type[SIZ];
1773 char mime_disposition[SIZ];
1775 char vcard_partnum[SIZ];
1776 char *vcard_source = NULL;
1777 struct message_summary summ;
1779 memset(&summ, 0, sizeof(summ));
1780 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1782 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1784 serv_getln(buf, sizeof buf);
1785 if (buf[0] != '1') return;
1787 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1788 if (!strncasecmp(buf, "part=", 5)) {
1789 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1790 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1791 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1792 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1793 mime_length = extract_int(&buf[5], 5);
1795 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1796 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1797 strcpy(vcard_partnum, mime_partnum);
1803 if (!IsEmptyStr(vcard_partnum)) {
1804 vcard_source = load_mimepart(msgnum, vcard_partnum);
1805 if (vcard_source != NULL) {
1807 /** Display the summary line */
1808 display_vcard(vcard_source, alpha, 0, NULL);
1810 /** If it's my vCard I can edit it */
1811 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1812 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1813 || (WC->wc_view == VIEW_ADDRESSBOOK)
1815 wprintf("<a href=\"edit_vcard?"
1816 "msgnum=%ld?partnum=%s\">",
1817 msgnum, vcard_partnum);
1818 wprintf("[%s]</a>", _("edit"));
1830 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1831 * \param namebuf name to analyze, reverse if nescessary
1833 void lastfirst_firstlast(char *namebuf) {
1834 char firstname[SIZ];
1838 if (namebuf == NULL) return;
1839 if (strchr(namebuf, ';') != NULL) return;
1841 i = num_tokens(namebuf, ' ');
1844 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1845 remove_token(namebuf, i-1, ' ');
1846 strcpy(firstname, namebuf);
1847 sprintf(namebuf, "%s; %s", lastname, firstname);
1851 * \brief fetch what??? name
1852 * \param msgnum the citadel message number
1853 * \param namebuf where to put the name in???
1855 void fetch_ab_name(long msgnum, char *namebuf) {
1857 char mime_partnum[SIZ];
1858 char mime_filename[SIZ];
1859 char mime_content_type[SIZ];
1860 char mime_disposition[SIZ];
1862 char vcard_partnum[SIZ];
1863 char *vcard_source = NULL;
1865 struct message_summary summ;
1867 if (namebuf == NULL) return;
1868 strcpy(namebuf, "");
1870 memset(&summ, 0, sizeof(summ));
1871 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1873 sprintf(buf, "MSG0 %ld|0", msgnum); /** unfortunately we need the mime info now */
1875 serv_getln(buf, sizeof buf);
1876 if (buf[0] != '1') return;
1878 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1879 if (!strncasecmp(buf, "part=", 5)) {
1880 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1881 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1882 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1883 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1884 mime_length = extract_int(&buf[5], 5);
1886 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1887 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1888 strcpy(vcard_partnum, mime_partnum);
1894 if (!IsEmptyStr(vcard_partnum)) {
1895 vcard_source = load_mimepart(msgnum, vcard_partnum);
1896 if (vcard_source != NULL) {
1898 /* Grab the name off the card */
1899 display_vcard(vcard_source, 0, 0, namebuf);
1905 lastfirst_firstlast(namebuf);
1907 len = strlen(namebuf);
1908 for (i=0; i<len; ++i) {
1909 if (namebuf[i] != ';') return;
1911 strcpy(namebuf, _("(no name)"));
1917 * \brief Record compare function for sorting address book indices
1918 * \param ab1 adressbook one
1919 * \param ab2 adressbook two
1921 int abcmp(const void *ab1, const void *ab2) {
1923 (((const struct addrbookent *)ab1)->ab_name),
1924 (((const struct addrbookent *)ab2)->ab_name)
1930 * \brief Helper function for do_addrbook_view()
1931 * Converts a name into a three-letter tab label
1932 * \param tabbuf the tabbuffer to add name to
1933 * \param name the name to add to the tabbuffer
1935 void nametab(char *tabbuf, long len, char *name) {
1936 stresc(tabbuf, len, name, 0, 0);
1937 tabbuf[0] = toupper(tabbuf[0]);
1938 tabbuf[1] = tolower(tabbuf[1]);
1939 tabbuf[2] = tolower(tabbuf[2]);
1945 * \brief Render the address book using info we gathered during the scan
1946 * \param addrbook the addressbook to render
1947 * \param num_ab the number of the addressbook
1949 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1953 static int NAMESPERPAGE = 60;
1956 char tabfirst_label[64];
1958 char tablast_label[64];
1959 char this_tablabel[64];
1964 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1965 wprintf(_("This address book is empty."));
1966 wprintf("</i></div>\n");
1971 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1974 num_pages = (num_ab / NAMESPERPAGE) + 1;
1976 tablabels = malloc(num_pages * sizeof (char *));
1977 if (tablabels == NULL) {
1978 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1979 wprintf(_("An internal error has occurred."));
1980 wprintf("</i></div>\n");
1984 for (i=0; i<num_pages; ++i) {
1985 tabfirst = i * NAMESPERPAGE;
1986 tablast = tabfirst + NAMESPERPAGE - 1;
1987 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1988 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
1989 nametab(tablast_label, 64, addrbook[tablast].ab_name);
1990 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
1991 tablabels[i] = strdup(this_tablabel);
1994 tabbed_dialog(num_pages, tablabels);
1997 for (i=0; i<num_ab; ++i) {
1999 if ((i / NAMESPERPAGE) != page) { /* New tab */
2000 page = (i / NAMESPERPAGE);
2002 wprintf("</tr></table>\n");
2003 end_tab(page-1, num_pages);
2005 begin_tab(page, num_pages);
2006 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
2010 if ((displayed % 4) == 0) {
2011 if (displayed > 0) {
2015 wprintf("<tr bgcolor=\"#%s\">",
2016 (bg ? "DDDDDD" : "FFFFFF")
2022 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
2023 addrbook[i].ab_msgnum);
2024 wprintf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
2025 vcard_n_prettyize(addrbook[i].ab_name);
2026 escputs(addrbook[i].ab_name);
2027 wprintf("</a></td>\n");
2031 wprintf("</tr></table>\n");
2032 end_tab((num_pages-1), num_pages);
2034 for (i=0; i<num_pages; ++i) {
2043 * \brief load message pointers from the server
2044 * \param servcmd the citadel command to send to the citserver
2045 * \param with_headers what headers???
2047 int load_msg_ptrs(char *servcmd, int with_headers)
2059 int num_summ_alloc = 0;
2061 if (WC->summ != NULL) {
2066 num_summ_alloc = 100;
2068 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
2071 maxload = sizeof(WC->msgarr) / sizeof(long) ;
2073 serv_getln(buf, sizeof buf);
2074 if (buf[0] != '1') {
2077 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2078 if (nummsgs < maxload) {
2079 WC->msgarr[nummsgs] = extract_long(buf, 0);
2080 datestamp = extract_long(buf, 1);
2081 extract_token(fullname, buf, 2, '|', sizeof fullname);
2082 extract_token(nodename, buf, 3, '|', sizeof nodename);
2083 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
2084 extract_token(subject, buf, 5, '|', sizeof subject);
2088 if (nummsgs > num_summ_alloc) {
2089 num_summ_alloc *= 2;
2090 WC->summ = realloc(WC->summ,
2091 num_summ_alloc * sizeof(struct message_summary));
2095 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
2096 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
2097 safestrncpy(WC->summ[nummsgs-1].subj,
2098 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
2099 if (!IsEmptyStr(fullname)) {
2100 /** Handle senders with RFC2047 encoding */
2101 utf8ify_rfc822_string(fullname);
2102 safestrncpy(WC->summ[nummsgs-1].from,
2103 fullname, sizeof WC->summ[nummsgs-1].from);
2105 if (!IsEmptyStr(subject)) {
2106 /** Handle subjects with RFC2047 encoding */
2107 utf8ify_rfc822_string(subject);
2108 safestrncpy(WC->summ[nummsgs-1].subj, subject,
2109 sizeof WC->summ[nummsgs-1].subj);
2111 sbjlen = Ctdl_Utf8StrLen(WC->summ[nummsgs-1].subj);
2114 ptr = Ctdl_Utf8StrCut(WC->summ[nummsgs-1].subj, 72);
2119 if (!IsEmptyStr(nodename)) {
2120 if ( ((WC->room_flags & QR_NETWORK)
2121 || ((strcasecmp(nodename, serv_info.serv_nodename)
2122 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
2124 strcat(WC->summ[nummsgs-1].from, " @ ");
2125 strcat(WC->summ[nummsgs-1].from, nodename);
2129 WC->summ[nummsgs-1].date = datestamp;
2131 /** Handle senders with RFC2047 encoding */
2132 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
2133 if (strlen(WC->summ[nummsgs-1].from) > 25) {
2134 strcpy(&WC->summ[nummsgs-1].from[22], "...");
2143 * \brief qsort() compatible function to compare two longs in descending order.
2145 * \param s1 first number to compare
2146 * \param s2 second number to compare
2148 int longcmp_r(const void *s1, const void *s2) {
2155 if (l1 > l2) return(-1);
2156 if (l1 < l2) return(+1);
2162 * \brief qsort() compatible function to compare two message summary structs by ascending subject.
2164 * \param s1 first item to compare
2165 * \param s2 second item to compare
2167 int summcmp_subj(const void *s1, const void *s2) {
2168 struct message_summary *summ1;
2169 struct message_summary *summ2;
2171 summ1 = (struct message_summary *)s1;
2172 summ2 = (struct message_summary *)s2;
2173 return strcasecmp(summ1->subj, summ2->subj);
2177 * \brief qsort() compatible function to compare two message summary structs by descending subject.
2179 * \param s1 first item to compare
2180 * \param s2 second item to compare
2182 int summcmp_rsubj(const void *s1, const void *s2) {
2183 struct message_summary *summ1;
2184 struct message_summary *summ2;
2186 summ1 = (struct message_summary *)s1;
2187 summ2 = (struct message_summary *)s2;
2188 return strcasecmp(summ2->subj, summ1->subj);
2192 * \brief qsort() compatible function to compare two message summary structs by ascending sender.
2194 * \param s1 first item to compare
2195 * \param s2 second item to compare
2197 int summcmp_sender(const void *s1, const void *s2) {
2198 struct message_summary *summ1;
2199 struct message_summary *summ2;
2201 summ1 = (struct message_summary *)s1;
2202 summ2 = (struct message_summary *)s2;
2203 return strcasecmp(summ1->from, summ2->from);
2207 * \brief qsort() compatible function to compare two message summary structs by descending sender.
2209 * \param s1 first item to compare
2210 * \param s2 second item to compare
2212 int summcmp_rsender(const void *s1, const void *s2) {
2213 struct message_summary *summ1;
2214 struct message_summary *summ2;
2216 summ1 = (struct message_summary *)s1;
2217 summ2 = (struct message_summary *)s2;
2218 return strcasecmp(summ2->from, summ1->from);
2222 * \brief qsort() compatible function to compare two message summary structs by ascending date.
2224 * \param s1 first item to compare
2225 * \param s2 second item to compare
2227 int summcmp_date(const void *s1, const void *s2) {
2228 struct message_summary *summ1;
2229 struct message_summary *summ2;
2231 summ1 = (struct message_summary *)s1;
2232 summ2 = (struct message_summary *)s2;
2234 if (summ1->date < summ2->date) return -1;
2235 else if (summ1->date > summ2->date) return +1;
2240 * \brief qsort() compatible function to compare two message summary structs by descending date.
2242 * \param s1 first item to compare
2243 * \param s2 second item to compare
2245 int summcmp_rdate(const void *s1, const void *s2) {
2246 struct message_summary *summ1;
2247 struct message_summary *summ2;
2249 summ1 = (struct message_summary *)s1;
2250 summ2 = (struct message_summary *)s2;
2252 if (summ1->date < summ2->date) return +1;
2253 else if (summ1->date > summ2->date) return -1;
2260 * \brief command loop for reading messages
2262 * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
2264 void readloop(char *oper)
2273 long *displayed_msgs = NULL;
2274 int num_displayed = 0;
2276 int is_addressbook = 0;
2277 int is_singlecard = 0;
2278 int is_calendar = 0;
2283 int lowest_displayed = (-1);
2284 int highest_displayed = 0;
2285 struct addrbookent *addrbook = NULL;
2287 char *sortby = NULL;
2288 char sortpref_name[128];
2289 char sortpref_value[128];
2290 char *subjsort_button;
2291 char *sendsort_button;
2292 char *datesort_button;
2293 int bbs_reverse = 0;
2294 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
2296 if (WCC->wc_view == VIEW_WIKI) {
2297 sprintf(buf, "wiki?room=%s?page=home", WCC->wc_roomname);
2302 startmsg = atol(bstr("startmsg"));
2303 maxmsgs = atoi(bstr("maxmsgs"));
2304 is_summary = atoi(bstr("is_summary"));
2305 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2307 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WCC->wc_roomname);
2308 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
2310 sortby = bstr("sortby");
2311 if ( (!IsEmptyStr(sortby)) && (strcasecmp(sortby, sortpref_value)) ) {
2312 set_preference(sortpref_name, sortby, 1);
2314 if (IsEmptyStr(sortby)) sortby = sortpref_value;
2317 if (IsEmptyStr(sortby)) sortby = "rdate";
2319 /** message board sort */
2320 if (!strcasecmp(sortby, "reverse")) {
2327 output_headers(1, 1, 1, 0, 0, 0);
2330 * When in summary mode, always show ALL messages instead of just
2331 * new or old. Otherwise, show what the user asked for.
2333 if (!strcmp(oper, "readnew")) {
2334 strcpy(cmd, "MSGS NEW");
2336 else if (!strcmp(oper, "readold")) {
2337 strcpy(cmd, "MSGS OLD");
2339 else if (!strcmp(oper, "do_search")) {
2340 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2343 strcpy(cmd, "MSGS ALL");
2346 if ((WCC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
2348 if (!strcmp(oper, "do_search")) {
2349 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2352 strcpy(cmd, "MSGS ALL");
2356 if ((WCC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2358 if (!strcmp(oper, "do_search")) {
2359 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2362 strcpy(cmd, "MSGS ALL");
2367 if (is_summary) { /**< fetch header summary */
2368 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
2369 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2370 (!strcmp(oper, "do_search") ? bstr("query") : "")
2377 * Are we doing a summary view? If so, we need to know old messages
2378 * and new messages, so we can do that pretty boldface thing for the
2381 strcpy(old_msgs, "");
2382 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR)){
2384 serv_getln(buf, sizeof buf);
2385 if (buf[0] == '2') {
2386 strcpy(old_msgs, &buf[4]);
2390 is_singlecard = atoi(bstr("is_singlecard"));
2392 if (WCC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2394 strcpy(cmd, "MSGS ALL|||1");
2397 if (WCC->wc_default_view == VIEW_TASKS) { /**< tasks */
2399 strcpy(cmd, "MSGS ALL");
2402 if (WCC->wc_default_view == VIEW_NOTES) { /**< notes */
2404 strcpy(cmd, "MSGS ALL");
2409 wprintf("<div align=center>%s</div>\n", _("Click on any note to edit it."));
2410 wprintf("<div id=\"new_notes_here\"></div>\n");
2413 nummsgs = load_msg_ptrs(cmd, is_summary);
2416 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2417 wprintf("<div align=\"center\"><br /><em>");
2418 if (!strcmp(oper, "readnew")) {
2419 wprintf(_("No new messages."));
2420 } else if (!strcmp(oper, "readold")) {
2421 wprintf(_("No old messages."));
2423 wprintf(_("No messages here."));
2425 wprintf("</em><br /></div>\n");
2431 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR)){
2432 for (a = 0; a < nummsgs; ++a) {
2433 /** Are you a new message, or an old message? */
2435 if (is_msg_in_mset(old_msgs, WCC->msgarr[a])) {
2436 WCC->summ[a].is_new = 0;
2439 WCC->summ[a].is_new = 1;
2445 if (startmsg == 0L) {
2447 startmsg = WCC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2450 startmsg = WCC->msgarr[0];
2455 if (!strcasecmp(sortby, "subject")) {
2456 qsort(WCC->summ, WCC->num_summ,
2457 sizeof(struct message_summary), summcmp_subj);
2459 else if (!strcasecmp(sortby, "rsubject")) {
2460 qsort(WCC->summ, WCC->num_summ,
2461 sizeof(struct message_summary), summcmp_rsubj);
2463 else if (!strcasecmp(sortby, "sender")) {
2464 qsort(WCC->summ, WCC->num_summ,
2465 sizeof(struct message_summary), summcmp_sender);
2467 else if (!strcasecmp(sortby, "rsender")) {
2468 qsort(WCC->summ, WCC->num_summ,
2469 sizeof(struct message_summary), summcmp_rsender);
2471 else if (!strcasecmp(sortby, "date")) {
2472 qsort(WCC->summ, WCC->num_summ,
2473 sizeof(struct message_summary), summcmp_date);
2475 else if (!strcasecmp(sortby, "rdate")) {
2476 qsort(WCC->summ, WCC->num_summ,
2477 sizeof(struct message_summary), summcmp_rdate);
2481 if (!strcasecmp(sortby, "subject")) {
2482 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2484 else if (!strcasecmp(sortby, "rsubject")) {
2485 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2488 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2491 if (!strcasecmp(sortby, "sender")) {
2492 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2494 else if (!strcasecmp(sortby, "rsender")) {
2495 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2498 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2501 if (!strcasecmp(sortby, "date")) {
2502 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2504 else if (!strcasecmp(sortby, "rdate")) {
2505 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2508 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2513 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2514 " document.onkeydown = CtdlMsgListKeyPress; "
2515 " if (document.layers) { "
2516 " document.captureEvents(Event.KEYPRESS); "
2521 /** note that Date and Delete are now in the same column */
2522 wprintf("<div id=\"message_list_hdr\">"
2523 "<div class=\"fix_scrollbar_bug\">"
2524 "<table cellspacing=0 style=\"width:100%%\">"
2527 wprintf("<th width=%d%%>%s %s</th>"
2528 "<th width=%d%%>%s %s</th>"
2529 "<th width=%d%%>%s %s"
2531 "<input type=\"submit\" name=\"delete_button\" id=\"delbutton\" "
2532 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2538 _("Subject"), subjsort_button,
2539 SENDER_COL_WIDTH_PCT,
2540 _("Sender"), sendsort_button,
2541 DATE_PLUS_BUTTONS_WIDTH_PCT,
2542 _("Date"), datesort_button,
2545 wprintf("</table></div></div>\n");
2547 wprintf("<div id=\"message_list\">"
2549 "<div class=\"fix_scrollbar_bug\">\n"
2551 "<table class=\"mailbox_summary\" id=\"summary_headers\" "
2552 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2558 * Set the "is_bbview" variable if it appears that we are looking at
2559 * a classic bulletin board view.
2561 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2562 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2567 * If we're not currently looking at ALL requested
2568 * messages, then display the selector bar
2571 /** begin bbview scroller */
2572 wprintf("<form name=\"msgomatictop\" class=\"selector_top\" > \n <p>");
2573 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2575 wprintf("<select name=\"whichones\" size=\"1\" "
2576 "OnChange=\"location.href=msgomatictop.whichones.options"
2577 "[selectedIndex].value\">\n");
2580 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2582 lo = b - maxmsgs + 2;
2584 wprintf("<option %s value="
2589 "%d-%d</option> \n",
2590 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2599 for (b=0; b<nummsgs; b = b + maxmsgs) {
2601 hi = b + maxmsgs + 1;
2602 if (hi > nummsgs) hi = nummsgs;
2603 wprintf("<option %s value="
2608 "%d-%d</option> \n",
2609 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2618 wprintf("<option value=\"%s?startmsg=%ld"
2619 "?maxmsgs=9999999?is_summary=%d\">",
2621 WCC->msgarr[0], is_summary);
2623 wprintf("</option>");
2624 wprintf("</select> ");
2625 wprintf(_("of %d messages."), nummsgs);
2627 /** forward/reverse */
2628 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2629 "OnChange=\"location.href='%s?sortby=forward'\"",
2630 (bbs_reverse ? "" : "checked"),
2634 wprintf(_("oldest to newest"));
2635 wprintf(" ");
2637 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2638 "OnChange=\"location.href='%s?sortby=reverse'\"",
2639 (bbs_reverse ? "checked" : ""),
2643 wprintf(_("newest to oldest"));
2646 wprintf("</p></form>\n");
2647 /** end bbview scroller */
2652 wprintf ("<script src=\"/static/dragdrop.js\" type=\"text/javascript\"></script>\n");
2657 for (a = 0; a < nummsgs; ++a) {
2658 if ((WCC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2660 /** Display the message */
2662 display_summarized(a);
2664 else if (is_addressbook) {
2665 fetch_ab_name(WCC->msgarr[a], buf);
2667 addrbook = realloc(addrbook,
2668 (sizeof(struct addrbookent) * num_ab) );
2669 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2670 sizeof(addrbook[num_ab-1].ab_name));
2671 addrbook[num_ab-1].ab_msgnum = WCC->msgarr[a];
2673 else if (is_calendar) {
2674 display_calendar(WCC->msgarr[a], WCC->summ[a].is_new);
2676 else if (is_tasks) {
2677 display_task(WCC->msgarr[a], WCC->summ[a].is_new);
2679 else if (is_notes) {
2680 display_note(WCC->msgarr[a], WCC->summ[a].is_new);
2683 if (displayed_msgs == NULL) {
2684 displayed_msgs = malloc(sizeof(long) *
2685 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2687 displayed_msgs[num_displayed] = WCC->msgarr[a];
2690 if (lowest_displayed < 0) lowest_displayed = a;
2691 highest_displayed = a;
2698 if (displayed_msgs != NULL) {
2700 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2703 /** if we do a split bbview in the future, begin messages div here */
2705 for (a=0; a<num_displayed; ++a) {
2706 read_message(displayed_msgs[a], 0, "");
2709 /** if we do a split bbview in the future, end messages div here */
2711 free(displayed_msgs);
2712 displayed_msgs = NULL;
2717 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2718 wprintf("</div>"); /**< end of 'message_list' div */
2720 /** Here's the grab-it-to-resize-the-message-list widget */
2721 wprintf("<div id=\"resize_msglist\" "
2722 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2723 "<div class=\"fix_scrollbar_bug\"> <hr>"
2727 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2731 * Bump these because although we're thinking in zero base, the user
2732 * is a drooling idiot and is thinking in one base.
2735 ++highest_displayed;
2738 * If we're not currently looking at ALL requested
2739 * messages, then display the selector bar
2742 /** begin bbview scroller */
2743 wprintf("<form name=\"msgomatic\" class=\"selector_bottom\" > \n <p>");
2744 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2746 wprintf("<select name=\"whichones\" size=\"1\" "
2747 "OnChange=\"location.href=msgomatic.whichones.options"
2748 "[selectedIndex].value\">\n");
2751 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2753 lo = b - maxmsgs + 2;
2755 wprintf("<option %s value="
2760 "%d-%d</option> \n",
2761 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2770 for (b=0; b<nummsgs; b = b + maxmsgs) {
2772 hi = b + maxmsgs + 1;
2773 if (hi > nummsgs) hi = nummsgs;
2774 wprintf("<option %s value="
2779 "%d-%d</option> \n",
2780 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2789 wprintf("<option value=\"%s?startmsg=%ld"
2790 "?maxmsgs=9999999?is_summary=%d\">",
2792 WCC->msgarr[0], is_summary);
2794 wprintf("</option>");
2795 wprintf("</select> ");
2796 wprintf(_("of %d messages."), nummsgs);
2798 /** forward/reverse */
2799 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2800 "OnChange=\"location.href='%s?sortby=forward'\"",
2801 (bbs_reverse ? "" : "checked"),
2805 wprintf(_("oldest to newest"));
2806 wprintf(" ");
2807 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2808 "OnChange=\"location.href='%s?sortby=reverse'\"",
2809 (bbs_reverse ? "checked" : ""),
2813 wprintf(_("newest to oldest"));
2816 wprintf("</p></form>\n");
2817 /** end bbview scroller */
2822 // wprintf ("</div>\n");
2823 wprintf ("<div id=\"wastebin\" align=middle>Drop notes here to remove them.</div>\n");
2824 wprintf ("<script type=\"text/javascript\">\n");
2825 // wprintf ("//<![CDATA[\n");
2826 wprintf ("Droppables.add(\"wastebin\",\n");
2828 wprintf ("\t\taccept:'notes',\n");
2829 wprintf ("\t\tonDrop:function(element)\n");
2830 wprintf ("\t\t{\n");
2831 wprintf ("\t\t\tElement.hide(element);\n");
2832 wprintf ("\t\t\tnew Ajax.Updater('notes', 'delnote',\n");
2833 wprintf ("\t\t\t{\n");
2834 wprintf ("\t\t\t\tasynchronous:true,\n");
2835 wprintf ("\t\t\t\tevalScripts:true,\n");
2836 wprintf ("\t\t\t\tonComplete:function(request)\n");
2837 wprintf ("\t\t\t\t{\n");
2838 wprintf ("\t\t\t\t\tElement.hide('indicator')\n");
2839 wprintf ("\t\t\t\t},\n");
2840 wprintf ("\t\t\t\tonLoading:function(request)\n");
2841 wprintf ("\t\t\t\t{\n");
2842 wprintf ("\t\t\t\t\tElement.show('indicator')\n");
2843 wprintf ("\t\t\t\t},\n");
2844 wprintf ("\t\t\t\tparameters:'id=' + encodeURIComponent(element.id)\n");
2845 wprintf ("\t\t\t})\n");
2846 wprintf ("\t\t}\n");
2848 // wprintf ("//]]>\n");
2849 wprintf ("</script>\n");
2856 do_tasks_view(); /** Render the task list */
2860 do_calendar_view(); /** Render the calendar */
2863 if (is_addressbook) {
2864 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2867 /** Note: wDumpContent() will output one additional </div> tag. */
2868 wprintf("</div>\n"); /** end of 'content' div */
2871 /** free the summary */
2872 if (WCC->summ != NULL) {
2877 if (addrbook != NULL) free(addrbook);
2882 * \brief Back end for post_message()
2883 * ... this is where the actual message gets transmitted to the server.
2885 void post_mime_to_server(void) {
2886 char top_boundary[SIZ];
2887 char alt_boundary[SIZ];
2888 int is_multipart = 0;
2890 struct wc_attachment *att;
2892 size_t encoded_length;
2893 size_t encoded_strlen;
2894 char *txtmail = NULL;
2896 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
2897 serv_info.serv_fqdn,
2901 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
2902 serv_info.serv_fqdn,
2907 /** RFC2045 requires this, and some clients look for it... */
2908 serv_puts("MIME-Version: 1.0");
2909 serv_puts("X-Mailer: " PACKAGE_STRING);
2911 /** If there are attachments, we have to do multipart/mixed */
2912 if (WC->first_attachment != NULL) {
2917 /** Remember, serv_printf() appends an extra newline */
2918 serv_printf("Content-type: multipart/mixed; "
2919 "boundary=\"%s\"\n", top_boundary);
2920 serv_printf("This is a multipart message in MIME format.\n");
2921 serv_printf("--%s", top_boundary);
2926 /* Remember, serv_printf() appends an extra newline */
2927 serv_printf("Content-type: multipart/alternative; "
2928 "boundary=\"%s\"\n", alt_boundary);
2929 serv_printf("This is a multipart message in MIME format.\n");
2930 serv_printf("--%s", alt_boundary);
2932 serv_puts("Content-type: text/plain; charset=utf-8");
2933 serv_puts("Content-Transfer-Encoding: quoted-printable");
2935 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
2936 text_to_server_qp(txtmail); /** Transmit message in quoted-printable encoding */
2939 serv_printf("--%s", alt_boundary);
2941 serv_puts("Content-type: text/html; charset=utf-8");
2942 serv_puts("Content-Transfer-Encoding: quoted-printable");
2944 serv_puts("<html><body>\r\n");
2945 text_to_server_qp(bstr("msgtext")); /** Transmit message in quoted-printable encoding */
2946 serv_puts("</body></html>\r\n");
2949 serv_printf("--%s--", alt_boundary);
2957 /** Add in the attachments */
2958 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2960 encoded_length = ((att->length * 150) / 100);
2961 encoded = malloc(encoded_length);
2962 if (encoded == NULL) break;
2963 encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1);
2965 serv_printf("--%s", top_boundary);
2966 serv_printf("Content-type: %s", att->content_type);
2967 serv_printf("Content-disposition: attachment; "
2968 "filename=\"%s\"", att->filename);
2969 serv_puts("Content-transfer-encoding: base64");
2971 serv_write(encoded, encoded_strlen);
2976 serv_printf("--%s--", top_boundary);
2984 * \brief Post message (or don't post message)
2986 * Note regarding the "dont_post" variable:
2987 * A random value (actually, it's just a timestamp) is inserted as a hidden
2988 * field called "postseq" when the display_enter page is generated. This
2989 * value is checked when posting, using the static variable dont_post. If a
2990 * user attempts to post twice using the same dont_post value, the message is
2991 * discarded. This prevents the accidental double-saving of the same message
2992 * if the user happens to click the browser "back" button.
2994 void post_message(void)
2999 char *encoded_subject;
3000 static long dont_post = (-1L);
3001 struct wc_attachment *att, *aptr;
3002 int is_anonymous = 0;
3003 const char *display_name;
3005 struct wcsession *WCC = WC;
3007 if (!IsEmptyStr(bstr("force_room"))) {
3008 gotoroom(bstr("force_room"));
3011 if (GetHash(WCC->urlstrings, HKEY("display_name"), &U)) {
3012 u = (urlcontent*) U;
3013 display_name = u->url_data;
3014 dpLen = u->url_data_size;
3019 if (!strcmp(display_name, "__ANONYMOUS__")) {
3024 if (WCC->upload_length > 0) {
3026 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WCC->upload_length);
3027 /** There's an attachment. Save it to this struct... */
3028 att = malloc(sizeof(struct wc_attachment));
3029 memset(att, 0, sizeof(struct wc_attachment));
3030 att->length = WCC->upload_length;
3031 strcpy(att->content_type, WCC->upload_content_type);
3032 strcpy(att->filename, WCC->upload_filename);
3035 /** And add it to the list. */
3036 if (WCC->first_attachment == NULL) {
3037 WCC->first_attachment = att;
3040 aptr = WCC->first_attachment;
3041 while (aptr->next != NULL) aptr = aptr->next;
3046 * Mozilla sends a simple filename, which is what we want,
3047 * but Satan's Browser sends an entire pathname. Reduce
3048 * the path to just a filename if we need to.
3050 while (num_tokens(att->filename, '/') > 1) {
3051 remove_token(att->filename, 0, '/');
3053 while (num_tokens(att->filename, '\\') > 1) {
3054 remove_token(att->filename, 0, '\\');
3058 * Transfer control of this memory from the upload struct
3059 * to the attachment struct.
3061 att->data = WCC->upload;
3062 WCC->upload_length = 0;
3068 if (!IsEmptyStr(bstr("cancel_button"))) {
3069 sprintf(WCC->ImportantMessage,
3070 _("Cancelled. Message was not posted."));
3071 } else if (!IsEmptyStr(bstr("attach_button"))) {
3074 } else if (atol(bstr("postseq")) == dont_post) {
3075 sprintf(WCC->ImportantMessage,
3076 _("Automatically cancelled because you have already "
3077 "saved this message."));
3079 const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s";
3080 const char *Recp = "";
3081 const char *Cc = "";
3082 const char *Bcc = "";
3083 const char *Wikipage = "";
3084 const char *my_email_addr = "";
3085 char *CmdBuf = NULL;;
3088 if (GetHash(WCC->urlstrings, HKEY("subject"), &U)) {
3089 u = (urlcontent*) U;
3091 * make enough room for the encoded string;
3092 * plus the QP header
3094 len = u->url_data_size * 3 + 32;
3095 encoded_subject = malloc (len);
3096 len = webcit_rfc2047encode(encoded_subject, len,
3097 u->url_data, u->url_data_size);
3099 free (encoded_subject);
3103 len += sizeof (CMD) + dpLen;
3105 if (GetHash(WCC->urlstrings, HKEY("recp"), &U)) {
3106 u = (urlcontent*) U;
3108 len += u->url_data_size; }
3110 if (GetHash(WCC->urlstrings, HKEY("cc"), &U)) {
3111 u = (urlcontent*) U;
3113 len += u->url_data_size;
3116 if (GetHash(WCC->urlstrings, HKEY("bcc"), &U)) {
3117 u = (urlcontent*) U;
3119 len += u->url_data_size;
3122 if (GetHash(WCC->urlstrings, HKEY("wikipage"), &U)) {
3123 u = (urlcontent*) U;
3124 Wikipage = u->url_data;
3125 len += u->url_data_size;
3128 if (GetHash(WCC->urlstrings, HKEY("my_email_addr"), &U)) {
3129 u = (urlcontent*) U;
3130 my_email_addr = u->url_data;
3131 len += u->url_data_size;
3134 CmdBuf = (char*) malloc (len + 1);
3137 snprintf(CmdBuf, len + 1, CMD,
3147 serv_getln(buf, sizeof buf);
3149 free (encoded_subject);
3150 if (buf[0] == '4') {
3151 post_mime_to_server();
3152 if ( (!IsEmptyStr(bstr("recp")))
3153 || (!IsEmptyStr(bstr("cc" )))
3154 || (!IsEmptyStr(bstr("bcc" )))
3156 sprintf(WCC->ImportantMessage, _("Message has been sent.\n"));
3159 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
3161 dont_post = atol(bstr("postseq"));
3163 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
3164 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3170 free_attachments(WCC);
3173 * We may have been supplied with instructions regarding the location
3174 * to which we must return after posting. If found, go there.
3176 if (!IsEmptyStr(bstr("return_to"))) {
3177 http_redirect(bstr("return_to"));
3180 * If we were editing a page in a wiki room, go to that page now.
3182 else if (!IsEmptyStr(bstr("wikipage"))) {
3183 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
3187 * Otherwise, just go to the "read messages" loop.
3190 readloop("readnew");
3198 * \brief display the message entry screen
3200 void display_enter(void)
3206 struct wc_attachment *att;
3207 int recipient_required = 0;
3208 int subject_required = 0;
3209 int recipient_bad = 0;
3211 int is_anonymous = 0;
3212 long existing_page = (-1L);
3216 if (!IsEmptyStr(bstr("force_room"))) {
3217 gotoroom(bstr("force_room"));
3220 display_name = bstr("display_name");
3221 if (!strcmp(display_name, "__ANONYMOUS__")) {
3226 /** First test to see whether this is a room that requires recipients to be entered */
3227 serv_puts("ENT0 0");
3228 serv_getln(buf, sizeof buf);
3230 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
3231 recipient_required = 1;
3233 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3234 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3235 readloop("readnew");
3239 /* Is the server strongly recommending that the user enter a message subject? */
3240 if ((buf[3] != '\0') && (buf[4] != '\0')) {
3241 subject_required = extract_int(&buf[4], 1);
3245 * Are we perhaps in an address book view? If so, then an "enter
3246 * message" command really means "add new entry."
3248 if (WC->wc_default_view == VIEW_ADDRESSBOOK) {
3249 do_edit_vcard(-1, "", "", WC->wc_roomname);
3254 * Are we perhaps in a calendar room? If so, then an "enter
3255 * message" command really means "add new calendar item."
3257 if (WC->wc_default_view == VIEW_CALENDAR) {
3258 display_edit_event();
3263 * Are we perhaps in a tasks view? If so, then an "enter
3264 * message" command really means "add new task."
3266 if (WC->wc_default_view == VIEW_TASKS) {
3267 display_edit_task();
3272 * Otherwise proceed normally.
3273 * Do a custom room banner with no navbar...
3275 output_headers(1, 1, 2, 0, 0, 0);
3276 wprintf("<div id=\"banner\">\n");
3277 embed_room_banner(NULL, navbar_none);
3278 wprintf("</div>\n");
3279 wprintf("<div id=\"content\">\n"
3280 "<div class=\"fix_scrollbar_bug message \">");
3282 /** Now check our actual recipients if there are any */
3283 if (recipient_required) {
3284 sprintf(buf, "ENT0 0|%s|%d|0||%s||%s|%s|%s",
3288 bstr("cc"), bstr("bcc"), bstr("wikipage"));
3290 serv_getln(buf, sizeof buf);
3292 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
3293 if (!IsEmptyStr(bstr("recp")) &&
3294 !IsEmptyStr(bstr("cc" )) &&
3295 !IsEmptyStr(bstr("bcc" ))) {
3299 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3300 wprintf("<em>%s</em><br />\n", &buf[4]);
3305 /** If we got this far, we can display the message entry screen. */
3307 /** begin message entry screen */
3309 "enctype=\"multipart/form-data\" "
3311 "accept-charset=\"UTF-8\" "
3313 "name=\"enterform\""
3315 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
3316 if (WC->wc_view == VIEW_WIKI) {
3317 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
3319 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
3320 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
3321 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
3322 escputs(WC->wc_roomname);
3325 /** submit or cancel buttons */
3326 wprintf("<p class=\"send_edit_msg\">");
3327 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3328 if (recipient_required) {
3329 wprintf(_("Send message"));
3331 wprintf(_("Post message"));
3334 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3339 wprintf("<img src=\"static/newmess3_24x.gif\" class=\"imgedit\">");
3340 wprintf(" "); /** header bar */
3341 webcit_fmt_date(buf, now, 0);
3343 wprintf("\n"); /** header bar */
3345 wprintf("<table width=\"100%%\" class=\"edit_msg_table\">");
3347 wprintf("<th><label for=\"from_id\" > ");
3348 wprintf(_(" <I>from</I> "));
3349 wprintf("</label></th>");
3351 wprintf("<td colspan=\"2\">");
3353 /* Allow the user to select any of his valid screen names */
3355 wprintf("<select name=\"display_name\" size=1 id=\"from_id\">\n");
3358 serv_getln(buf, sizeof buf);
3359 if (buf[0] == '1') {
3360 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3361 wprintf("<option %s value=\"",
3362 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
3367 wprintf("</option>\n");
3371 if (WC->room_flags & QR_ANONOPT) {
3372 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
3373 ((!strcasecmp(bstr("__ANONYMOUS__"), WC->wc_fullname)) ? "selected" : ""),
3378 wprintf("</select>\n");
3380 /* If this is an email (not a post), allow the user to select any of his
3381 * valid email addresses.
3383 if (recipient_required) {
3385 serv_getln(buf, sizeof buf);
3386 if (buf[0] == '1') {
3387 wprintf("<select name=\"my_email_addr\" size=1>\n");
3388 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3389 wprintf("<option value=\"");
3393 wprintf("></option>\n");
3395 wprintf("</select>\n");
3399 wprintf(_(" <I>in</I> "));
3400 escputs(WC->wc_roomname);
3402 wprintf("</td></tr>");
3404 if (recipient_required) {
3408 wprintf("<tr><th><label for=\"recp_id\"> ");
3410 wprintf("</label></th>"
3411 "<td><input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
3412 ccraw = bstr("recp");
3413 len = strlen(ccraw);
3414 copy = (char*) malloc(len * 2 + 1);
3415 memcpy(copy, ccraw, len + 1);
3416 utf8ify_rfc822_string(copy);
3419 wprintf("\" size=45 maxlength=1000 />");
3420 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
3421 wprintf("</td><td rowspan=\"3\" align=\"left\" valign=\"top\">");
3423 /** Pop open an address book -- begin **/
3425 "<a href=\"javascript:PopOpenAddressBook('recp_id|%s|cc_id|%s|bcc_id|%s');\" "
3427 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
3429 _("To:"), _("CC:"), _("BCC:"),
3430 _("Contacts"), _("Contacts")
3432 /** Pop open an address book -- end **/
3434 wprintf("</td></tr>");
3436 wprintf("<tr><th><label for=\"cc_id\"> ");
3438 wprintf("</label></th>"
3439 "<td><input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
3441 len = strlen(ccraw);
3442 copy = (char*) malloc(len * 2 + 1);
3443 memcpy(copy, ccraw, len + 1);
3444 utf8ify_rfc822_string(copy);
3447 wprintf("\" size=45 maxlength=1000 />");
3448 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
3449 wprintf("</td></tr>");
3451 wprintf("<tr><th><label for=\"bcc_id\"> ");
3453 wprintf("</label></th>"
3454 "<td><input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
3455 ccraw = bstr("bcc");
3456 len = strlen(ccraw);
3457 copy = (char*) malloc(len * 2 + 1);
3458 memcpy(copy, ccraw, len + 1);
3459 utf8ify_rfc822_string(copy);
3462 wprintf("\" size=45 maxlength=1000 />");
3463 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
3464 wprintf("</td></tr>");
3466 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
3467 wprintf("<script type=\"text/javascript\"> \n"
3468 " activate_entmsg_autocompleters(); \n"
3474 wprintf("<tr><th><label for=\"subject_id\" > ");
3475 if (recipient_required || subject_required) {
3476 wprintf(_("Subject:"));
3479 wprintf(_("Subject (optional):"));
3481 wprintf("</label></th>"
3482 "<td colspan=\"2\">"
3483 "<input type=\"text\" name=\"subject\" id=\"subject_id\" value=\"");
3484 escputs(bstr("subject"));
3485 wprintf("\" size=45 maxlength=70>\n");
3486 wprintf("</td></tr>");
3488 wprintf("<tr><td colspan=\"3\">\n");
3490 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
3492 /** If we're continuing from a previous edit, put our partially-composed message back... */
3493 msgescputs(bstr("msgtext"));
3495 /* If we're forwarding a message, insert it here... */
3496 if (atol(bstr("fwdquote")) > 0L) {
3497 wprintf("<br><div align=center><i>");
3498 wprintf(_("--- forwarded message ---"));
3499 wprintf("</i></div><br>");
3500 pullquote_message(atol(bstr("fwdquote")), 1, 1);
3503 /** If we're replying quoted, insert the quote here... */
3504 else if (atol(bstr("replyquote")) > 0L) {
3507 pullquote_message(atol(bstr("replyquote")), 0, 1);
3508 wprintf("</blockquote><br>");
3511 /** If we're editing a wiki page, insert the existing page here... */
3512 else if (WC->wc_view == VIEW_WIKI) {
3513 safestrncpy(buf, bstr("wikipage"), sizeof buf);
3514 str_wiki_index(buf);
3515 existing_page = locate_message_by_uid(buf);
3516 if (existing_page >= 0L) {
3517 pullquote_message(existing_page, 1, 0);
3521 /** Insert our signature if appropriate... */
3522 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
3523 get_preference("use_sig", buf, sizeof buf);
3524 if (!strcasecmp(buf, "yes")) {
3526 get_preference("signature", ebuf, sizeof ebuf);
3527 euid_unescapize(buf, ebuf);
3528 wprintf("<br>--<br>");
3530 for (i=0; i<len; ++i) {
3531 if (buf[i] == '\n') {
3534 else if (buf[i] == '<') {
3537 else if (buf[i] == '>') {
3540 else if (buf[i] == '&') {
3543 else if (buf[i] == '\"') {
3546 else if (buf[i] == '\'') {
3549 else if (isprint(buf[i])) {
3550 wprintf("%c", buf[i]);
3556 wprintf("</textarea>\n");
3558 /** Make sure we only insert our signature once */
3559 /** We don't care if it was there or not before, it needs to be there now. */
3560 wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
3563 * The following template embeds the TinyMCE richedit control, and automatically
3564 * transforms the textarea into a richedit textarea.
3566 do_template("richedit");
3568 /** Enumerate any attachments which are already in place... */
3569 wprintf("<div class=\"attachment buttons\"><img src=\"static/diskette_24x.gif\" class=\"imgedit\" > ");
3570 wprintf(_("Attachments:"));
3572 wprintf("<select name=\"which_attachment\" size=1>");
3573 for (att = WC->first_attachment; att != NULL; att = att->next) {
3574 wprintf("<option value=\"");
3575 urlescputs(att->filename);
3577 escputs(att->filename);
3578 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3579 wprintf("</option>\n");
3581 wprintf("</select>");
3583 /** Now offer the ability to attach additional files... */
3584 wprintf(" ");
3585 wprintf(_("Attach file:"));
3586 wprintf(" <input name=\"attachfile\" class=\"attachfile\" "
3587 "size=16 type=\"file\">\n "
3588 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3589 wprintf("</div>"); /* End of "attachment buttons" div */
3592 wprintf("</td></tr></table>");
3594 wprintf("</form>\n");
3595 wprintf("</div>\n"); /* end of "fix_scrollbar_bug" div */
3597 /* NOTE: address_book_popup() will close the "content" div. Don't close it here. */
3598 DONE: address_book_popup();
3604 * \brief delete a message
3606 void delete_msg(void)
3611 msgid = atol(bstr("msgid"));
3613 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3614 serv_printf("DELE %ld", msgid);
3616 else { /** Otherwise move it to Trash */
3617 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3620 serv_getln(buf, sizeof buf);
3621 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3623 readloop("readnew");
3628 * \brief move a message to another folder
3635 msgid = atol(bstr("msgid"));
3637 if (!IsEmptyStr(bstr("move_button"))) {
3638 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3640 serv_getln(buf, sizeof buf);
3641 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3643 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3646 readloop("readnew");
3654 * \brief Confirm move of a message
3656 void confirm_move_msg(void)
3662 msgid = atol(bstr("msgid"));
3665 output_headers(1, 1, 2, 0, 0, 0);
3666 wprintf("<div id=\"banner\">\n");
3668 wprintf(_("Confirm move of message"));
3670 wprintf("</div>\n");
3672 wprintf("<div id=\"content\" class=\"service\">\n");
3674 wprintf("<CENTER>");
3676 wprintf(_("Move this message to:"));
3677 wprintf("<br />\n");
3679 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3680 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
3681 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3683 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3685 serv_getln(buf, sizeof buf);
3686 if (buf[0] == '1') {
3687 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3688 extract_token(targ, buf, 0, '|', sizeof targ);
3689 wprintf("<OPTION>");
3694 wprintf("</SELECT>\n");
3695 wprintf("<br />\n");
3697 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3699 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3700 wprintf("</form></CENTER>\n");
3702 wprintf("</CENTER>\n");