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.
279 void webcit_rfc2047encode(char *target, int maxlen, char *source)
281 int need_to_encode = 0;
285 if (target == NULL) return;
286 len = strlen(source);
287 for (i=0; i<len; ++i) {
288 if ((source[i] < 32) || (source[i] > 126)) {
290 i = len; ///< shortcut. won't become more than 1
294 if (!need_to_encode) {
295 safestrncpy(target, source, maxlen);
299 strcpy(target, "=?UTF-8?Q?");
300 for (i=0; i<len; ++i) {
301 ch = (unsigned char) source[i];
302 if ((ch < 32) || (ch > 126) || (ch == 61)) {
303 sprintf(&target[strlen(target)], "=%02X", ch);
306 sprintf(&target[strlen(target)], "%c", ch);
310 strcat(target, "?=");
317 * \brief Look for URL's embedded in a buffer and make them linkable. We use a
318 * target window in order to keep the BBS session in its own window.
319 * \param buf the message buffer
324 char *start, *end, *pos;
331 for (pos = buf; (pos < end) && (start == NULL); ++pos) {
332 if (!strncasecmp(pos, "http://", 7))
334 if (!strncasecmp(pos, "ftp://", 6))
341 for (pos = buf+len; pos > start; --pos) {
342 if ( (!isprint(*pos))
361 strncpy(urlbuf, start, end - start);
362 urlbuf[end - start] = '\0';
365 strncpy(outbuf, buf, start - buf );
366 sprintf(&outbuf[start-buf], "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
367 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
369 if ( strlen(outbuf) < 250 )
375 * \brief Turn a vCard "n" (name) field into something displayable.
376 * \param name the name field to convert
378 void vcard_n_prettyize(char *name)
383 original_name = strdup(name);
384 len = strlen(original_name);
385 for (i=0; i<5; ++i) {
387 if (original_name[len-1] == ' ') {
388 original_name[--len] = 0;
390 if (original_name[len-1] == ';') {
391 original_name[--len] = 0;
397 for (i=0; i<len; ++i) {
398 if (original_name[i] == ';') {
403 name[j++] = original_name[i];
414 * \brief preparse a vcard name
415 * display_vcard() calls this after parsing the textual vCard into
416 * our 'struct vCard' data object.
417 * This gets called instead of display_parsed_vcard() if we are only looking
418 * to extract the person's name instead of displaying the card.
419 * \param v the vcard to retrieve the name from
420 * \param storename where to put the name at
422 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
425 strcpy(storename, "");
427 name = vcard_get_prop(v, "n", 1, 0, 0);
429 strcpy(storename, name);
430 /* vcard_n_prettyize(storename); */
438 * \brief html print a vcard
439 * display_vcard() calls this after parsing the textual vCard into
440 * our 'struct vCard' data object.
442 * Set 'full' to nonzero to display the full card, otherwise it will only
443 * show a summary line.
445 * This code is a bit ugly, so perhaps an explanation is due: we do this
446 * in two passes through the vCard fields. On the first pass, we process
447 * fields we understand, and then render them in a pretty fashion at the
448 * end. Then we make a second pass, outputting all the fields we don't
449 * understand in a simple two-column name/value format.
450 * \param v the vCard to display
451 * \param full display all items of the vcard?
453 void display_parsed_vcard(struct vCard *v, int full) {
459 char *thisname, *thisvalue;
460 char firsttoken[SIZ];
469 strcpy(fullname, "");
477 name = vcard_get_prop(v, "fn", 1, 0, 0);
481 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
482 strcpy(fullname, name);
483 vcard_n_prettyize(fullname);
493 wprintf("<div align=center>"
494 "<table bgcolor=#aaaaaa width=50%%>");
495 for (pass=1; pass<=2; ++pass) {
497 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
499 thisname = strdup(v->prop[i].name);
500 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
502 for (j=0; j<num_tokens(thisname, ';'); ++j) {
503 extract_token(buf, thisname, j, ';', sizeof buf);
504 if (!strcasecmp(buf, "encoding=quoted-printable")) {
506 remove_token(thisname, j, ';');
508 if (!strcasecmp(buf, "encoding=base64")) {
510 remove_token(thisname, j, ';');
514 len = strlen(v->prop[i].value);
515 /* if we have some untagged QP, detect it here. */
516 if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
517 utf8ify_rfc822_string(v->prop[i].value);
520 // %ff can become 6 bytes in utf8
521 thisvalue = malloc(len * 2 + 3);
522 j = CtdlDecodeQuotedPrintable(
523 thisvalue, v->prop[i].value,
528 // ff will become one byte..
529 thisvalue = malloc(len + 50);
531 thisvalue, v->prop[i].value,
532 strlen(v->prop[i].value) );
535 thisvalue = strdup(v->prop[i].value);
538 /** Various fields we may encounter ***/
540 /** N is name, but only if there's no FN already there */
541 if (!strcasecmp(firsttoken, "n")) {
542 if (IsEmptyStr(fullname)) {
543 strcpy(fullname, thisvalue);
544 vcard_n_prettyize(fullname);
548 /** FN (full name) is a true 'display name' field */
549 else if (!strcasecmp(firsttoken, "fn")) {
550 strcpy(fullname, thisvalue);
554 else if (!strcasecmp(firsttoken, "title")) {
555 strcpy(title, thisvalue);
559 else if (!strcasecmp(firsttoken, "org")) {
560 strcpy(org, thisvalue);
563 else if (!strcasecmp(firsttoken, "email")) {
565 if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
567 "<a href=\"display_enter"
568 "?force_room=_MAIL_?recp=");
570 len = strlen(mailto);
571 urlesc(&mailto[len], SIZ - len, "\"");
572 len = strlen(mailto);
573 urlesc(&mailto[len], SIZ - len, fullname);
574 len = strlen(mailto);
575 urlesc(&mailto[len], SIZ - len, "\" <");
576 len = strlen(mailto);
577 urlesc(&mailto[len], SIZ - len, thisvalue);
578 len = strlen(mailto);
579 urlesc(&mailto[len], SIZ - len, ">");
581 strcat(mailto, "\">");
582 len = strlen(mailto);
583 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
584 strcat(mailto, "</A>");
586 else if (!strcasecmp(firsttoken, "tel")) {
587 if (!IsEmptyStr(phone)) strcat(phone, "<br />");
588 strcat(phone, thisvalue);
589 for (j=0; j<num_tokens(thisname, ';'); ++j) {
590 extract_token(buf, thisname, j, ';', sizeof buf);
591 if (!strcasecmp(buf, "tel"))
593 else if (!strcasecmp(buf, "work"))
594 strcat(phone, _(" (work)"));
595 else if (!strcasecmp(buf, "home"))
596 strcat(phone, _(" (home)"));
597 else if (!strcasecmp(buf, "cell"))
598 strcat(phone, _(" (cell)"));
606 else if (!strcasecmp(firsttoken, "adr")) {
609 wprintf(_("Address:"));
610 wprintf("</TD><TD>");
611 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
612 extract_token(buf, thisvalue, j, ';', sizeof buf);
613 if (!IsEmptyStr(buf)) {
615 if (j<3) wprintf("<br />");
619 wprintf("</TD></TR>\n");
622 else if (!strcasecmp(firsttoken, "version")) {
625 else if (!strcasecmp(firsttoken, "rev")) {
628 else if (!strcasecmp(firsttoken, "label")) {
633 /*** Don't show extra fields. They're ugly.
637 wprintf("</TD><TD>");
639 wprintf("</TD></TR>\n");
649 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
650 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
651 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
652 "<FONT SIZE=+1><B>");
654 wprintf("</B></FONT>");
655 if (!IsEmptyStr(title)) {
656 wprintf("<div align=right>");
660 if (!IsEmptyStr(org)) {
661 wprintf("<div align=right>");
665 wprintf("</TD></TR>\n");
667 if (!IsEmptyStr(phone)) {
669 wprintf(_("Telephone:"));
670 wprintf("</td><td>%s</td></tr>\n", phone);
672 if (!IsEmptyStr(mailto)) {
674 wprintf(_("E-mail:"));
675 wprintf("</td><td>%s</td></tr>\n", mailto);
681 wprintf("</table></div>\n");
687 * \brief Display a textual vCard
688 * (Converts to a vCard object and then calls the actual display function)
689 * Set 'full' to nonzero to display the whole card instead of a one-liner.
690 * Or, if "storename" is non-NULL, just store the person's name in that
691 * buffer instead of displaying the card at all.
692 * \param vcard_source the buffer containing the vcard text
693 * \param alpha what???
694 * \param full should we usse all lines?
695 * \param storename where to store???
697 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
703 v = vcard_load(vcard_source);
704 if (v == NULL) return;
706 name = vcard_get_prop(v, "n", 1, 0, 0);
708 utf8ify_rfc822_string(name);
713 if (storename != NULL) {
714 fetchname_parsed_vcard(v, storename);
716 else if ( (alpha == 0)
717 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
718 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
720 display_parsed_vcard(v, full);
734 * I wanna SEE that message!
736 * msgnum Message number to display
737 * printable_view Nonzero to display a printable view
738 * section Optional for encapsulated message/rfc822 submessage
740 void read_message(long msgnum, int printable_view, char *section) {
742 char mime_partnum[256] = "";
743 char mime_name[256] = "";
744 char mime_filename[256] = "";
745 char escaped_mime_filename[256] = "";
746 char mime_content_type[256] = "";
747 const char *mime_content_type_ptr;
748 char mime_charset[256] = "";
749 char mime_disposition[256] = "";
751 struct attach_link *attach_links = NULL;
752 int num_attach_links = 0;
753 char mime_submessages[256] = "";
754 char m_subject[1024] = "";
755 char m_cc[1024] = "";
759 char reply_to[512] = "";
760 char reply_all[4096] = "";
766 char vcard_partnum[256] = "";
767 char cal_partnum[256] = "";
768 char *part_source = NULL;
769 char msg4_partnum[32] = "";
771 iconv_t ic = (iconv_t)(-1) ;
772 char *ibuf; /**< Buffer of characters to be converted */
773 char *obuf; /**< Buffer for converted characters */
774 size_t ibuflen; /**< Length of input buffer */
775 size_t obuflen; /**< Length of output buffer */
776 char *osav; /**< Saved pointer to output buffer */
779 strcpy(mime_content_type, "text/plain");
780 strcpy(mime_charset, "us-ascii");
781 strcpy(mime_submessages, "");
783 serv_printf("MSG4 %ld|%s", msgnum, section);
784 serv_getln(buf, sizeof buf);
787 wprintf(_("ERROR:"));
788 wprintf("</strong> %s<br />\n", &buf[4]);
792 /** begin everythingamundo table */
793 if (!printable_view) {
794 wprintf("<div class=\"fix_scrollbar_bug message\" ");
795 wprintf("onMouseOver=document.getElementById(\"msg%ld\").style.visibility=\"visible\" ", msgnum);
796 wprintf("onMouseOut=document.getElementById(\"msg%ld\").style.visibility=\"hidden\" >", msgnum);
799 /** begin message header table */
800 wprintf("<div class=\"message_header\">");
802 strcpy(m_subject, "");
805 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
806 if (!strcmp(buf, "000")) {
808 wprintf(_("unexpected end of message"));
809 wprintf(" (1)</i><br /><br />\n");
813 if (!strncasecmp(buf, "nhdr=yes", 8))
817 if (!strncasecmp(buf, "type=", 5))
818 format_type = atoi(&buf[5]);
819 if (!strncasecmp(buf, "from=", 5)) {
820 strcpy(from, &buf[5]);
822 wprintf("<a href=\"showuser?who=");
823 utf8ify_rfc822_string(from);
829 if (!strncasecmp(buf, "subj=", 5)) {
830 safestrncpy(m_subject, &buf[5], sizeof m_subject);
832 if (!strncasecmp(buf, "cccc=", 5)) {
834 safestrncpy(m_cc, &buf[5], sizeof m_cc);
835 if (!IsEmptyStr(reply_all)) {
836 strcat(reply_all, ", ");
838 len = strlen(reply_all);
839 safestrncpy(&reply_all[len], &buf[5],
840 (sizeof reply_all - len) );
842 if ((!strncasecmp(buf, "hnod=", 5))
843 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
844 wprintf("(%s) ", &buf[5]);
846 if ((!strncasecmp(buf, "room=", 5))
847 && (strcasecmp(&buf[5], WC->wc_roomname))
848 && (!IsEmptyStr(&buf[5])) ) {
850 wprintf("%s> ", &buf[5]);
852 if (!strncasecmp(buf, "rfca=", 5)) {
853 strcpy(rfca, &buf[5]);
859 if (!strncasecmp(buf, "node=", 5)) {
860 strcpy(node, &buf[5]);
861 if ( ((WC->room_flags & QR_NETWORK)
862 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
863 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
864 && (IsEmptyStr(rfca))
866 wprintf("@%s ", &buf[5]);
869 if (!strncasecmp(buf, "rcpt=", 5)) {
872 if (!IsEmptyStr(reply_all)) {
873 strcat(reply_all, ", ");
875 len = strlen(reply_all);
876 safestrncpy(&reply_all[len], &buf[5],
877 (sizeof reply_all - len) );
878 utf8ify_rfc822_string(&buf[5]);
882 if (!strncasecmp(buf, "time=", 5)) {
883 webcit_fmt_date(now, atol(&buf[5]), 0);
889 if (!strncasecmp(buf, "part=", 5)) {
890 extract_token(mime_name, &buf[5], 0, '|', sizeof mime_filename);
891 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
892 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
893 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
894 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
895 mime_length = extract_int(&buf[5], 5);
898 striplt(mime_filename);
899 if ( (IsEmptyStr(mime_filename)) && (!IsEmptyStr(mime_name)) ) {
900 strcpy(mime_filename, mime_name);
903 if (!strcasecmp(mime_content_type, "message/rfc822")) {
904 if (!IsEmptyStr(mime_submessages)) {
905 strcat(mime_submessages, "|");
907 strcat(mime_submessages, mime_partnum);
909 else if ((!strcasecmp(mime_disposition, "inline"))
910 && (!strncasecmp(mime_content_type, "image/", 6)) ){
912 attach_links = realloc(attach_links,
913 (num_attach_links*sizeof(struct attach_link)));
914 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
915 snprintf(attach_links[num_attach_links-1].html, 1024,
916 "<img src=\"mimepart/%ld/%s/%s\">",
917 msgnum, mime_partnum, mime_filename);
919 else if ( ( (!strcasecmp(mime_disposition, "attachment"))
920 || (!strcasecmp(mime_disposition, "inline"))
921 || (!strcasecmp(mime_disposition, ""))
922 ) && (!IsEmptyStr(mime_content_type))
925 attach_links = realloc(attach_links,
926 (num_attach_links*sizeof(struct attach_link)));
927 safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
928 utf8ify_rfc822_string(mime_filename);
930 mime_content_type_ptr = mime_content_type;
931 if (strcasecmp(mime_content_type, "application/octet-stream") == 0) {
932 mime_content_type_ptr = GuessMimeByFilename(mime_filename,
933 strlen(mime_filename));
935 urlesc(escaped_mime_filename, 265, mime_filename);
936 snprintf(attach_links[num_attach_links-1].html, 1024,
937 "<img src=\"display_mime_icon?type=%s\" "
938 "border=0 align=middle>\n"
939 "%s (%s, %d bytes) [ "
940 "<a href=\"mimepart/%ld/%s/%s\""
941 "target=\"wc.%ld.%s\">%s</a>"
943 "<a href=\"mimepart_download/%ld/%s/%s\">%s</a>"
945 mime_content_type_ptr,
947 mime_content_type, mime_length,
948 msgnum, mime_partnum, escaped_mime_filename,
949 msgnum, mime_partnum,
951 msgnum, mime_partnum, escaped_mime_filename,
956 /** begin handler prep ***/
957 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
958 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
959 strcpy(vcard_partnum, mime_partnum);
962 if ( (!strcasecmp(mime_content_type, "text/calendar"))
963 || (!strcasecmp(mime_content_type, "application/ics")) ) {
964 strcpy(cal_partnum, mime_partnum);
967 /** end handler prep ***/
973 /** Generate a reply-to address */
974 if (!IsEmptyStr(rfca)) {
975 if (!IsEmptyStr(from)) {
976 snprintf(reply_to, sizeof(reply_to), "%s <%s>", from, rfca);
979 strcpy(reply_to, rfca);
983 if ((!IsEmptyStr(node))
984 && (strcasecmp(node, serv_info.serv_nodename))
985 && (strcasecmp(node, serv_info.serv_humannode)) ) {
986 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
990 snprintf(reply_to, sizeof(reply_to), "%s", from);
998 utf8ify_rfc822_string(m_cc);
999 utf8ify_rfc822_string(m_subject);
1001 /** start msg buttons */
1003 if (!printable_view) {
1004 wprintf("<p id=\"msg%ld\" class=\"msgbuttons\" >\n",msgnum);
1007 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
1008 wprintf("<a href=\"display_enter");
1009 if (WC->is_mailbox) {
1010 wprintf("?replyquote=%ld", msgnum);
1013 urlescputs(reply_to);
1014 if (!IsEmptyStr(m_subject)) {
1015 wprintf("?subject=");
1016 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
1017 urlescputs(m_subject);
1019 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Reply"));
1023 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
1024 if (!WC->is_mailbox) {
1025 wprintf("<a href=\"display_enter");
1026 wprintf("?replyquote=%ld", msgnum);
1028 urlescputs(reply_to);
1029 if (!IsEmptyStr(m_subject)) {
1030 wprintf("?subject=");
1031 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
1032 urlescputs(m_subject);
1034 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyQuoted"));
1039 if (WC->wc_view == VIEW_MAILBOX) {
1040 wprintf("<a href=\"display_enter");
1041 wprintf("?replyquote=%ld", msgnum);
1043 urlescputs(reply_to);
1045 urlescputs(reply_all);
1046 if (!IsEmptyStr(m_subject)) {
1047 wprintf("?subject=");
1048 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
1049 urlescputs(m_subject);
1051 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyAll"));
1055 if (WC->wc_view == VIEW_MAILBOX) {
1056 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
1057 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
1058 urlescputs(m_subject);
1059 wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Forward"));
1062 /** If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
1063 if ( (WC->is_room_aide) || (WC->is_mailbox) || (WC->room_flags2 & QR2_COLLABDEL) ) {
1065 wprintf("<a href=\"confirm_move_msg?msgid=%ld\"><span>[</span>%s<span>]</span></a> ",
1069 wprintf("<a href=\"delete_msg?msgid=%ld\" "
1070 "onClick=\"return confirm('%s');\">"
1071 "<span>[</span>%s<span>]</span> "
1072 "</a> ", msgnum, _("Delete this message?"), _("Delete")
1077 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'); \" >"
1078 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Headers"));
1082 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'); \" >"
1083 "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Print"));
1089 if (!IsEmptyStr(m_cc)) {
1096 if (!IsEmptyStr(m_subject)) {
1097 wprintf("<p class=\"message_subject\">");
1098 wprintf(_("Subject:"));
1107 wprintf("<div class=\"message_content\">");
1110 * Learn the content type
1112 strcpy(mime_content_type, "text/plain");
1113 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1114 if (!strcmp(buf, "000")) {
1115 /* This is not necessarily an error condition. See bug #226. */
1118 if (!strncasecmp(buf, "X-Citadel-MSG4-Partnum:", 23)) {
1119 safestrncpy(msg4_partnum, &buf[23], sizeof(msg4_partnum));
1120 striplt(msg4_partnum);
1122 if (!strncasecmp(buf, "Content-type:", 13)) {
1124 safestrncpy(mime_content_type, &buf[13], sizeof(mime_content_type));
1125 striplt(mime_content_type);
1126 len = strlen(mime_content_type);
1127 for (i=0; i<len; ++i) {
1128 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1129 safestrncpy(mime_charset, &mime_content_type[i+8],
1130 sizeof mime_charset);
1133 for (i=0; i<len; ++i) {
1134 if (mime_content_type[i] == ';') {
1135 mime_content_type[i] = 0;
1139 len = strlen(mime_charset);
1140 for (i=0; i<len; ++i) {
1141 if (mime_charset[i] == ';') {
1142 mime_charset[i] = 0;
1149 /** Set up a character set conversion if we need to (and if we can) */
1151 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
1152 if ( (strcasecmp(mime_charset, "us-ascii"))
1153 && (strcasecmp(mime_charset, "UTF-8"))
1154 && (strcasecmp(mime_charset, ""))
1156 ic = ctdl_iconv_open("UTF-8", mime_charset);
1157 if (ic == (iconv_t)(-1) ) {
1158 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1159 __FILE__, __LINE__, mime_charset, strerror(errno));
1164 /** Messages in legacy Citadel variformat get handled thusly... */
1165 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1169 /** Boring old 80-column fixed format text gets handled this way... */
1170 else if ( (!strcasecmp(mime_content_type, "text/plain"))
1171 || (!strcasecmp(mime_content_type, "text")) ) {
1173 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1176 if ((len > 0) && buf[len-1] == '\n') buf[--len] = 0;
1177 if ((len > 0) && buf[len-1] == '\r') buf[--len] = 0;
1180 if (ic != (iconv_t)(-1) ) {
1182 ibuflen = strlen(ibuf);
1184 obuf = (char *) malloc(obuflen);
1186 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1187 osav[SIZ-obuflen] = 0;
1188 safestrncpy(buf, osav, sizeof buf);
1194 while ((!IsEmptyStr(buf)) && (isspace(buf[len-1])))
1197 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1198 wprintf("<blockquote>");
1200 } else if ((bq == 1) &&
1201 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1202 wprintf("</blockquote>");
1208 wprintf("</tt><br />\n");
1210 wprintf("</i><br />");
1213 else /** HTML is fun, but we've got to strip it first */
1214 if (!strcasecmp(mime_content_type, "text/html")) {
1215 output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
1218 /** Unknown weirdness */
1220 wprintf(_("I don't know how to display %s"), mime_content_type);
1221 wprintf("<br />\n", mime_content_type);
1222 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1225 ENDBODY: /* If there are attached submessages, display them now... */
1227 if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
1228 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1229 extract_token(buf, mime_submessages, i, '|', sizeof buf);
1230 /** use printable_view to suppress buttons */
1231 wprintf("<blockquote>");
1232 read_message(msgnum, 1, buf);
1233 wprintf("</blockquote>");
1238 /** Afterwards, offer links to download attachments 'n' such */
1239 if ( (num_attach_links > 0) && (!section[0]) ) {
1240 for (i=0; i<num_attach_links; ++i) {
1241 if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
1242 wprintf("%s", attach_links[i].html);
1247 /** Handler for vCard parts */
1248 if (!IsEmptyStr(vcard_partnum)) {
1249 part_source = load_mimepart(msgnum, vcard_partnum);
1250 if (part_source != NULL) {
1252 /** If it's my vCard I can edit it */
1253 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1254 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1255 || (WC->wc_view == VIEW_ADDRESSBOOK)
1257 wprintf("<a href=\"edit_vcard?"
1258 "msgnum=%ld?partnum=%s\">",
1259 msgnum, vcard_partnum);
1260 wprintf("[%s]</a>", _("edit"));
1263 /** In all cases, display the full card */
1264 display_vcard(part_source, 0, 1, NULL);
1268 /** Handler for calendar parts */
1269 if (!IsEmptyStr(cal_partnum)) {
1270 part_source = load_mimepart(msgnum, cal_partnum);
1271 if (part_source != NULL) {
1272 cal_process_attachment(part_source,
1273 msgnum, cal_partnum);
1282 wprintf("</div>\n");
1284 /** end everythingamundo table */
1285 if (!printable_view) {
1286 wprintf("</div>\n");
1289 if (num_attach_links > 0) {
1294 if (ic != (iconv_t)(-1) ) {
1303 * \brief Unadorned HTML output of an individual message, suitable
1304 * for placing in a hidden iframe, for printing, or whatever
1306 * \param msgnum_as_string Message number, as a string instead of as a long int
1308 void embed_message(char *msgnum_as_string) {
1311 msgnum = atol(msgnum_as_string);
1312 begin_ajax_response();
1313 read_message(msgnum, 0, "");
1314 end_ajax_response();
1319 * \brief Printable view of a message
1321 * \param msgnum_as_string Message number, as a string instead of as a long int
1323 void print_message(char *msgnum_as_string) {
1326 msgnum = atol(msgnum_as_string);
1327 output_headers(0, 0, 0, 0, 0, 0);
1329 wprintf("Content-type: text/html\r\n"
1331 "Connection: close\r\n",
1335 wprintf("\r\n\r\n<html>\n"
1336 "<head><title>Printable view</title></head>\n"
1337 "<body onLoad=\" window.print(); window.close(); \">\n"
1340 read_message(msgnum, 1, "");
1342 wprintf("\n</body></html>\n\n");
1349 * \brief Display a message's headers
1351 * \param msgnum_as_string Message number, as a string instead of as a long int
1353 void display_headers(char *msgnum_as_string) {
1357 msgnum = atol(msgnum_as_string);
1358 output_headers(0, 0, 0, 0, 0, 0);
1360 wprintf("Content-type: text/plain\r\n"
1362 "Connection: close\r\n",
1366 serv_printf("MSG2 %ld|3", msgnum);
1367 serv_getln(buf, sizeof buf);
1368 if (buf[0] == '1') {
1369 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1370 wprintf("%s\n", buf);
1380 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1381 * or 'reply quoted' operations.
1383 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1384 * in this function. Doing so would throw a JavaScript error in the
1385 * 'supplied text' argument to the editor.
1387 * \param msgnum Message number of the message we want to quote
1388 * \param forward_attachments Nonzero if we want attachments to be forwarded
1390 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1392 char mime_partnum[256];
1393 char mime_filename[256];
1394 char mime_content_type[256];
1395 char mime_charset[256];
1396 char mime_disposition[256];
1398 char *attachments = NULL;
1400 int num_attachments = 0;
1401 struct wc_attachment *att, *aptr;
1402 char m_subject[1024];
1409 int format_type = 0;
1414 iconv_t ic = (iconv_t)(-1) ;
1415 char *ibuf; /**< Buffer of characters to be converted */
1416 char *obuf; /**< Buffer for converted characters */
1417 size_t ibuflen; /**< Length of input buffer */
1418 size_t obuflen; /**< Length of output buffer */
1419 char *osav; /**< Saved pointer to output buffer */
1425 strcpy(reply_to, "");
1426 strcpy(mime_content_type, "text/plain");
1427 strcpy(mime_charset, "us-ascii");
1429 serv_printf("MSG4 %ld", msgnum);
1430 serv_getln(buf, sizeof buf);
1431 if (buf[0] != '1') {
1432 wprintf(_("ERROR:"));
1433 wprintf("%s<br />", &buf[4]);
1437 strcpy(m_subject, "");
1439 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1440 if (!strcmp(buf, "000")) {
1441 wprintf("%s (3)", _("unexpected end of message"));
1444 if (include_headers) {
1445 if (!strncasecmp(buf, "nhdr=yes", 8))
1449 if (!strncasecmp(buf, "type=", 5))
1450 format_type = atoi(&buf[5]);
1451 if (!strncasecmp(buf, "from=", 5)) {
1452 strcpy(from, &buf[5]);
1453 wprintf(_("from "));
1454 utf8ify_rfc822_string(from);
1457 if (!strncasecmp(buf, "subj=", 5)) {
1458 strcpy(m_subject, &buf[5]);
1460 if ((!strncasecmp(buf, "hnod=", 5))
1461 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1462 wprintf("(%s) ", &buf[5]);
1464 if ((!strncasecmp(buf, "room=", 5))
1465 && (strcasecmp(&buf[5], WC->wc_roomname))
1466 && (!IsEmptyStr(&buf[5])) ) {
1468 wprintf("%s> ", &buf[5]);
1470 if (!strncasecmp(buf, "rfca=", 5)) {
1471 strcpy(rfca, &buf[5]);
1477 if (!strncasecmp(buf, "node=", 5)) {
1478 strcpy(node, &buf[5]);
1479 if ( ((WC->room_flags & QR_NETWORK)
1480 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1481 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1482 && (IsEmptyStr(rfca))
1484 wprintf("@%s ", &buf[5]);
1487 if (!strncasecmp(buf, "rcpt=", 5)) {
1489 strcpy(to, &buf[5]);
1490 utf8ify_rfc822_string(to);
1493 if (!strncasecmp(buf, "time=", 5)) {
1494 webcit_fmt_date(now, atol(&buf[5]), 0);
1495 wprintf("%s ", now);
1500 * Save attachment info for later. We can't start downloading them
1501 * yet because we're in the middle of a server transaction.
1503 if (!strncasecmp(buf, "part=", 5)) {
1504 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1507 sprintf(ptr, "%s%s\n",
1508 ((attachments != NULL) ? attachments : ""),
1513 lprintf(9, "attachments=<%s>\n", attachments);
1519 if (include_headers) {
1522 utf8ify_rfc822_string(m_subject);
1523 if (!IsEmptyStr(m_subject)) {
1524 wprintf(_("Subject:"));
1526 msgescputs(m_subject);
1537 * Learn the content type
1539 strcpy(mime_content_type, "text/plain");
1540 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1541 if (!strcmp(buf, "000")) {
1542 wprintf("%s (4)", _("unexpected end of message"));
1545 if (!strncasecmp(buf, "Content-type: ", 14)) {
1547 safestrncpy(mime_content_type, &buf[14],
1548 sizeof(mime_content_type));
1549 for (i=0; i<strlen(mime_content_type); ++i) {
1550 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1551 safestrncpy(mime_charset, &mime_content_type[i+8],
1552 sizeof mime_charset);
1555 len = strlen(mime_content_type);
1556 for (i=0; i<len; ++i) {
1557 if (mime_content_type[i] == ';') {
1558 mime_content_type[i] = 0;
1562 len = strlen(mime_charset);
1563 for (i=0; i<len; ++i) {
1564 if (mime_charset[i] == ';') {
1565 mime_charset[i] = 0;
1572 /** Set up a character set conversion if we need to (and if we can) */
1574 if ( (strcasecmp(mime_charset, "us-ascii"))
1575 && (strcasecmp(mime_charset, "UTF-8"))
1576 && (strcasecmp(mime_charset, ""))
1578 ic = ctdl_iconv_open("UTF-8", mime_charset);
1579 if (ic == (iconv_t)(-1) ) {
1580 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1581 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1586 /** Messages in legacy Citadel variformat get handled thusly... */
1587 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1591 /* Boring old 80-column fixed format text gets handled this way... */
1592 else if (!strcasecmp(mime_content_type, "text/plain")) {
1593 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1596 if (buf[len-1] == '\n') buf[--len] = 0;
1597 if (buf[len-1] == '\r') buf[--len] = 0;
1600 if (ic != (iconv_t)(-1) ) {
1604 obuf = (char *) malloc(obuflen);
1606 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1607 osav[SIZ-obuflen] = 0;
1608 safestrncpy(buf, osav, sizeof buf);
1614 while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
1617 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1618 wprintf("<blockquote>");
1620 } else if ((bq == 1) &&
1621 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1622 wprintf("</blockquote>");
1628 wprintf("</tt><br />");
1630 wprintf("</i><br />");
1633 /** HTML just gets escaped and stuffed back into the editor */
1634 else if (!strcasecmp(mime_content_type, "text/html")) {
1635 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1641 /** Unknown weirdness ... don't know how to handle this content type */
1643 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1647 /** end of body handler */
1650 * If there were attachments, we have to download them and insert them
1651 * into the attachment chain for the forwarded message we are composing.
1653 if ( (forward_attachments) && (num_attachments) ) {
1654 for (i=0; i<num_attachments; ++i) {
1655 extract_token(buf, attachments, i, '\n', sizeof buf);
1656 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1657 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1658 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1659 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1660 mime_length = extract_int(buf, 5);
1663 * tracing ... uncomment if necessary
1666 lprintf(9, "fwd filename: %s\n", mime_filename);
1667 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1668 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1669 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1670 lprintf(9, "fwd length : %d\n", mime_length);
1672 if ( (!strcasecmp(mime_disposition, "inline"))
1673 || (!strcasecmp(mime_disposition, "attachment")) ) {
1675 /* Create an attachment struct from this mime part... */
1676 att = malloc(sizeof(struct wc_attachment));
1677 memset(att, 0, sizeof(struct wc_attachment));
1678 att->length = mime_length;
1679 strcpy(att->content_type, mime_content_type);
1680 strcpy(att->filename, mime_filename);
1682 att->data = load_mimepart(msgnum, mime_partnum);
1684 /* And add it to the list. */
1685 if (WC->first_attachment == NULL) {
1686 WC->first_attachment = att;
1689 aptr = WC->first_attachment;
1690 while (aptr->next != NULL) aptr = aptr->next;
1699 if (ic != (iconv_t)(-1) ) {
1704 if (attachments != NULL) {
1710 * \brief Display one row in the mailbox summary view
1712 * \param num The row number to be displayed
1714 void display_summarized(int num) {
1717 wprintf("<tr id=\"m%ld\" style=\"font-weight:%s;\" "
1718 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1719 WC->summ[num].msgnum,
1720 (WC->summ[num].is_new ? "bold" : "normal"),
1721 WC->summ[num].msgnum
1724 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1726 escputs(WC->summ[num].subj);//////////////////////////////////TODO: QP DECODE
1729 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1730 escputs(WC->summ[num].from);
1733 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1734 webcit_fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1744 * \brief display the adressbook overview
1745 * \param msgnum the citadel message number
1746 * \param alpha what????
1748 void display_addressbook(long msgnum, char alpha) {
1750 char mime_partnum[SIZ];
1751 char mime_filename[SIZ];
1752 char mime_content_type[SIZ];
1753 char mime_disposition[SIZ];
1755 char vcard_partnum[SIZ];
1756 char *vcard_source = NULL;
1757 struct message_summary summ;
1759 memset(&summ, 0, sizeof(summ));
1760 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1762 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1764 serv_getln(buf, sizeof buf);
1765 if (buf[0] != '1') return;
1767 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1768 if (!strncasecmp(buf, "part=", 5)) {
1769 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1770 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1771 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1772 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1773 mime_length = extract_int(&buf[5], 5);
1775 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1776 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1777 strcpy(vcard_partnum, mime_partnum);
1783 if (!IsEmptyStr(vcard_partnum)) {
1784 vcard_source = load_mimepart(msgnum, vcard_partnum);
1785 if (vcard_source != NULL) {
1787 /** Display the summary line */
1788 display_vcard(vcard_source, alpha, 0, NULL);
1790 /** If it's my vCard I can edit it */
1791 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1792 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1793 || (WC->wc_view == VIEW_ADDRESSBOOK)
1795 wprintf("<a href=\"edit_vcard?"
1796 "msgnum=%ld?partnum=%s\">",
1797 msgnum, vcard_partnum);
1798 wprintf("[%s]</a>", _("edit"));
1810 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1811 * \param namebuf name to analyze, reverse if nescessary
1813 void lastfirst_firstlast(char *namebuf) {
1814 char firstname[SIZ];
1818 if (namebuf == NULL) return;
1819 if (strchr(namebuf, ';') != NULL) return;
1821 i = num_tokens(namebuf, ' ');
1824 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1825 remove_token(namebuf, i-1, ' ');
1826 strcpy(firstname, namebuf);
1827 sprintf(namebuf, "%s; %s", lastname, firstname);
1831 * \brief fetch what??? name
1832 * \param msgnum the citadel message number
1833 * \param namebuf where to put the name in???
1835 void fetch_ab_name(long msgnum, char *namebuf) {
1837 char mime_partnum[SIZ];
1838 char mime_filename[SIZ];
1839 char mime_content_type[SIZ];
1840 char mime_disposition[SIZ];
1842 char vcard_partnum[SIZ];
1843 char *vcard_source = NULL;
1845 struct message_summary summ;
1847 if (namebuf == NULL) return;
1848 strcpy(namebuf, "");
1850 memset(&summ, 0, sizeof(summ));
1851 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1853 sprintf(buf, "MSG0 %ld|0", msgnum); /** unfortunately we need the mime info now */
1855 serv_getln(buf, sizeof buf);
1856 if (buf[0] != '1') return;
1858 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1859 if (!strncasecmp(buf, "part=", 5)) {
1860 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1861 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1862 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1863 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1864 mime_length = extract_int(&buf[5], 5);
1866 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1867 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1868 strcpy(vcard_partnum, mime_partnum);
1874 if (!IsEmptyStr(vcard_partnum)) {
1875 vcard_source = load_mimepart(msgnum, vcard_partnum);
1876 if (vcard_source != NULL) {
1878 /* Grab the name off the card */
1879 display_vcard(vcard_source, 0, 0, namebuf);
1885 lastfirst_firstlast(namebuf);
1887 len = strlen(namebuf);
1888 for (i=0; i<len; ++i) {
1889 if (namebuf[i] != ';') return;
1891 strcpy(namebuf, _("(no name)"));
1897 * \brief Record compare function for sorting address book indices
1898 * \param ab1 adressbook one
1899 * \param ab2 adressbook two
1901 int abcmp(const void *ab1, const void *ab2) {
1903 (((const struct addrbookent *)ab1)->ab_name),
1904 (((const struct addrbookent *)ab2)->ab_name)
1910 * \brief Helper function for do_addrbook_view()
1911 * Converts a name into a three-letter tab label
1912 * \param tabbuf the tabbuffer to add name to
1913 * \param name the name to add to the tabbuffer
1915 void nametab(char *tabbuf, long len, char *name) {
1916 stresc(tabbuf, len, name, 0, 0);
1917 tabbuf[0] = toupper(tabbuf[0]);
1918 tabbuf[1] = tolower(tabbuf[1]);
1919 tabbuf[2] = tolower(tabbuf[2]);
1925 * \brief Render the address book using info we gathered during the scan
1926 * \param addrbook the addressbook to render
1927 * \param num_ab the number of the addressbook
1929 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1933 static int NAMESPERPAGE = 60;
1936 char tabfirst_label[64];
1938 char tablast_label[64];
1939 char this_tablabel[64];
1944 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1945 wprintf(_("This address book is empty."));
1946 wprintf("</i></div>\n");
1951 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1954 num_pages = (num_ab / NAMESPERPAGE) + 1;
1956 tablabels = malloc(num_pages * sizeof (char *));
1957 if (tablabels == NULL) {
1958 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1959 wprintf(_("An internal error has occurred."));
1960 wprintf("</i></div>\n");
1964 for (i=0; i<num_pages; ++i) {
1965 tabfirst = i * NAMESPERPAGE;
1966 tablast = tabfirst + NAMESPERPAGE - 1;
1967 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1968 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
1969 nametab(tablast_label, 64, addrbook[tablast].ab_name);
1970 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
1971 tablabels[i] = strdup(this_tablabel);
1974 tabbed_dialog(num_pages, tablabels);
1977 for (i=0; i<num_ab; ++i) {
1979 if ((i / NAMESPERPAGE) != page) { /* New tab */
1980 page = (i / NAMESPERPAGE);
1982 wprintf("</tr></table>\n");
1983 end_tab(page-1, num_pages);
1985 begin_tab(page, num_pages);
1986 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
1990 if ((displayed % 4) == 0) {
1991 if (displayed > 0) {
1995 wprintf("<tr bgcolor=\"#%s\">",
1996 (bg ? "DDDDDD" : "FFFFFF")
2002 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
2003 addrbook[i].ab_msgnum);
2004 wprintf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
2005 vcard_n_prettyize(addrbook[i].ab_name);
2006 escputs(addrbook[i].ab_name);
2007 wprintf("</a></td>\n");
2011 wprintf("</tr></table>\n");
2012 end_tab((num_pages-1), num_pages);
2014 for (i=0; i<num_pages; ++i) {
2023 * \brief load message pointers from the server
2024 * \param servcmd the citadel command to send to the citserver
2025 * \param with_headers what headers???
2027 int load_msg_ptrs(char *servcmd, int with_headers)
2039 int num_summ_alloc = 0;
2041 if (WC->summ != NULL) {
2046 num_summ_alloc = 100;
2048 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
2051 maxload = sizeof(WC->msgarr) / sizeof(long) ;
2053 serv_getln(buf, sizeof buf);
2054 if (buf[0] != '1') {
2057 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2058 if (nummsgs < maxload) {
2059 WC->msgarr[nummsgs] = extract_long(buf, 0);
2060 datestamp = extract_long(buf, 1);
2061 extract_token(fullname, buf, 2, '|', sizeof fullname);
2062 extract_token(nodename, buf, 3, '|', sizeof nodename);
2063 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
2064 extract_token(subject, buf, 5, '|', sizeof subject);
2068 if (nummsgs > num_summ_alloc) {
2069 num_summ_alloc *= 2;
2070 WC->summ = realloc(WC->summ,
2071 num_summ_alloc * sizeof(struct message_summary));
2075 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
2076 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
2077 safestrncpy(WC->summ[nummsgs-1].subj,
2078 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
2079 if (!IsEmptyStr(fullname)) {
2080 /** Handle senders with RFC2047 encoding */
2081 utf8ify_rfc822_string(fullname);
2082 safestrncpy(WC->summ[nummsgs-1].from,
2083 fullname, sizeof WC->summ[nummsgs-1].from);
2085 if (!IsEmptyStr(subject)) {
2086 /** Handle subjects with RFC2047 encoding */
2087 utf8ify_rfc822_string(subject);
2088 safestrncpy(WC->summ[nummsgs-1].subj, subject,
2089 sizeof WC->summ[nummsgs-1].subj);
2091 sbjlen = Ctdl_Utf8StrLen(WC->summ[nummsgs-1].subj);
2094 ptr = Ctdl_Utf8StrCut(WC->summ[nummsgs-1].subj, 72);
2099 if (!IsEmptyStr(nodename)) {
2100 if ( ((WC->room_flags & QR_NETWORK)
2101 || ((strcasecmp(nodename, serv_info.serv_nodename)
2102 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
2104 strcat(WC->summ[nummsgs-1].from, " @ ");
2105 strcat(WC->summ[nummsgs-1].from, nodename);
2109 WC->summ[nummsgs-1].date = datestamp;
2111 /** Handle senders with RFC2047 encoding */
2112 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
2113 if (strlen(WC->summ[nummsgs-1].from) > 25) {
2114 strcpy(&WC->summ[nummsgs-1].from[22], "...");
2123 * \brief qsort() compatible function to compare two longs in descending order.
2125 * \param s1 first number to compare
2126 * \param s2 second number to compare
2128 int longcmp_r(const void *s1, const void *s2) {
2135 if (l1 > l2) return(-1);
2136 if (l1 < l2) return(+1);
2142 * \brief qsort() compatible function to compare two message summary structs by ascending subject.
2144 * \param s1 first item to compare
2145 * \param s2 second item to compare
2147 int summcmp_subj(const void *s1, const void *s2) {
2148 struct message_summary *summ1;
2149 struct message_summary *summ2;
2151 summ1 = (struct message_summary *)s1;
2152 summ2 = (struct message_summary *)s2;
2153 return strcasecmp(summ1->subj, summ2->subj);
2157 * \brief qsort() compatible function to compare two message summary structs by descending subject.
2159 * \param s1 first item to compare
2160 * \param s2 second item to compare
2162 int summcmp_rsubj(const void *s1, const void *s2) {
2163 struct message_summary *summ1;
2164 struct message_summary *summ2;
2166 summ1 = (struct message_summary *)s1;
2167 summ2 = (struct message_summary *)s2;
2168 return strcasecmp(summ2->subj, summ1->subj);
2172 * \brief qsort() compatible function to compare two message summary structs by ascending sender.
2174 * \param s1 first item to compare
2175 * \param s2 second item to compare
2177 int summcmp_sender(const void *s1, const void *s2) {
2178 struct message_summary *summ1;
2179 struct message_summary *summ2;
2181 summ1 = (struct message_summary *)s1;
2182 summ2 = (struct message_summary *)s2;
2183 return strcasecmp(summ1->from, summ2->from);
2187 * \brief qsort() compatible function to compare two message summary structs by descending sender.
2189 * \param s1 first item to compare
2190 * \param s2 second item to compare
2192 int summcmp_rsender(const void *s1, const void *s2) {
2193 struct message_summary *summ1;
2194 struct message_summary *summ2;
2196 summ1 = (struct message_summary *)s1;
2197 summ2 = (struct message_summary *)s2;
2198 return strcasecmp(summ2->from, summ1->from);
2202 * \brief qsort() compatible function to compare two message summary structs by ascending date.
2204 * \param s1 first item to compare
2205 * \param s2 second item to compare
2207 int summcmp_date(const void *s1, const void *s2) {
2208 struct message_summary *summ1;
2209 struct message_summary *summ2;
2211 summ1 = (struct message_summary *)s1;
2212 summ2 = (struct message_summary *)s2;
2214 if (summ1->date < summ2->date) return -1;
2215 else if (summ1->date > summ2->date) return +1;
2220 * \brief qsort() compatible function to compare two message summary structs by descending date.
2222 * \param s1 first item to compare
2223 * \param s2 second item to compare
2225 int summcmp_rdate(const void *s1, const void *s2) {
2226 struct message_summary *summ1;
2227 struct message_summary *summ2;
2229 summ1 = (struct message_summary *)s1;
2230 summ2 = (struct message_summary *)s2;
2232 if (summ1->date < summ2->date) return +1;
2233 else if (summ1->date > summ2->date) return -1;
2240 * \brief command loop for reading messages
2242 * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
2244 void readloop(char *oper)
2253 long *displayed_msgs = NULL;
2254 int num_displayed = 0;
2256 int is_addressbook = 0;
2257 int is_singlecard = 0;
2258 int is_calendar = 0;
2263 int lowest_displayed = (-1);
2264 int highest_displayed = 0;
2265 struct addrbookent *addrbook = NULL;
2267 char *sortby = NULL;
2268 char sortpref_name[128];
2269 char sortpref_value[128];
2270 char *subjsort_button;
2271 char *sendsort_button;
2272 char *datesort_button;
2273 int bbs_reverse = 0;
2274 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
2276 if (WCC->wc_view == VIEW_WIKI) {
2277 sprintf(buf, "wiki?room=%s?page=home", WCC->wc_roomname);
2282 startmsg = atol(bstr("startmsg"));
2283 maxmsgs = atoi(bstr("maxmsgs"));
2284 is_summary = atoi(bstr("is_summary"));
2285 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2287 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WCC->wc_roomname);
2288 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
2290 sortby = bstr("sortby");
2291 if ( (!IsEmptyStr(sortby)) && (strcasecmp(sortby, sortpref_value)) ) {
2292 set_preference(sortpref_name, sortby, 1);
2294 if (IsEmptyStr(sortby)) sortby = sortpref_value;
2297 if (IsEmptyStr(sortby)) sortby = "rdate";
2299 /** message board sort */
2300 if (!strcasecmp(sortby, "reverse")) {
2307 output_headers(1, 1, 1, 0, 0, 0);
2310 * When in summary mode, always show ALL messages instead of just
2311 * new or old. Otherwise, show what the user asked for.
2313 if (!strcmp(oper, "readnew")) {
2314 strcpy(cmd, "MSGS NEW");
2316 else if (!strcmp(oper, "readold")) {
2317 strcpy(cmd, "MSGS OLD");
2319 else if (!strcmp(oper, "do_search")) {
2320 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2323 strcpy(cmd, "MSGS ALL");
2326 if ((WCC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
2328 if (!strcmp(oper, "do_search")) {
2329 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2332 strcpy(cmd, "MSGS ALL");
2336 if ((WCC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2338 if (!strcmp(oper, "do_search")) {
2339 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2342 strcpy(cmd, "MSGS ALL");
2347 if (is_summary) { /**< fetch header summary */
2348 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
2349 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2350 (!strcmp(oper, "do_search") ? bstr("query") : "")
2357 * Are we doing a summary view? If so, we need to know old messages
2358 * and new messages, so we can do that pretty boldface thing for the
2361 strcpy(old_msgs, "");
2362 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR)){
2364 serv_getln(buf, sizeof buf);
2365 if (buf[0] == '2') {
2366 strcpy(old_msgs, &buf[4]);
2370 is_singlecard = atoi(bstr("is_singlecard"));
2372 if (WCC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2374 strcpy(cmd, "MSGS ALL|||1");
2377 if (WCC->wc_default_view == VIEW_TASKS) { /**< tasks */
2379 strcpy(cmd, "MSGS ALL");
2382 if (WCC->wc_default_view == VIEW_NOTES) { /**< notes */
2384 strcpy(cmd, "MSGS ALL");
2389 wprintf("<div align=center>%s</div>\n", _("Click on any note to edit it."));
2390 wprintf("<div id=\"new_notes_here\"></div>\n");
2393 nummsgs = load_msg_ptrs(cmd, is_summary);
2396 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2397 wprintf("<div align=\"center\"><br /><em>");
2398 if (!strcmp(oper, "readnew")) {
2399 wprintf(_("No new messages."));
2400 } else if (!strcmp(oper, "readold")) {
2401 wprintf(_("No old messages."));
2403 wprintf(_("No messages here."));
2405 wprintf("</em><br /></div>\n");
2411 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR)){
2412 for (a = 0; a < nummsgs; ++a) {
2413 /** Are you a new message, or an old message? */
2415 if (is_msg_in_mset(old_msgs, WCC->msgarr[a])) {
2416 WCC->summ[a].is_new = 0;
2419 WCC->summ[a].is_new = 1;
2425 if (startmsg == 0L) {
2427 startmsg = WCC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2430 startmsg = WCC->msgarr[0];
2435 if (!strcasecmp(sortby, "subject")) {
2436 qsort(WCC->summ, WCC->num_summ,
2437 sizeof(struct message_summary), summcmp_subj);
2439 else if (!strcasecmp(sortby, "rsubject")) {
2440 qsort(WCC->summ, WCC->num_summ,
2441 sizeof(struct message_summary), summcmp_rsubj);
2443 else if (!strcasecmp(sortby, "sender")) {
2444 qsort(WCC->summ, WCC->num_summ,
2445 sizeof(struct message_summary), summcmp_sender);
2447 else if (!strcasecmp(sortby, "rsender")) {
2448 qsort(WCC->summ, WCC->num_summ,
2449 sizeof(struct message_summary), summcmp_rsender);
2451 else if (!strcasecmp(sortby, "date")) {
2452 qsort(WCC->summ, WCC->num_summ,
2453 sizeof(struct message_summary), summcmp_date);
2455 else if (!strcasecmp(sortby, "rdate")) {
2456 qsort(WCC->summ, WCC->num_summ,
2457 sizeof(struct message_summary), summcmp_rdate);
2461 if (!strcasecmp(sortby, "subject")) {
2462 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2464 else if (!strcasecmp(sortby, "rsubject")) {
2465 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2468 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2471 if (!strcasecmp(sortby, "sender")) {
2472 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2474 else if (!strcasecmp(sortby, "rsender")) {
2475 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2478 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2481 if (!strcasecmp(sortby, "date")) {
2482 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2484 else if (!strcasecmp(sortby, "rdate")) {
2485 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2488 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2493 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2494 " document.onkeydown = CtdlMsgListKeyPress; "
2495 " if (document.layers) { "
2496 " document.captureEvents(Event.KEYPRESS); "
2501 /** note that Date and Delete are now in the same column */
2502 wprintf("<div id=\"message_list_hdr\">"
2503 "<div class=\"fix_scrollbar_bug\">"
2504 "<table cellspacing=0 style=\"width:100%%\">"
2507 wprintf("<th width=%d%%>%s %s</th>"
2508 "<th width=%d%%>%s %s</th>"
2509 "<th width=%d%%>%s %s"
2511 "<input type=\"submit\" name=\"delete_button\" id=\"delbutton\" "
2512 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2518 _("Subject"), subjsort_button,
2519 SENDER_COL_WIDTH_PCT,
2520 _("Sender"), sendsort_button,
2521 DATE_PLUS_BUTTONS_WIDTH_PCT,
2522 _("Date"), datesort_button,
2525 wprintf("</table></div></div>\n");
2527 wprintf("<div id=\"message_list\">"
2529 "<div class=\"fix_scrollbar_bug\">\n"
2531 "<table class=\"mailbox_summary\" id=\"summary_headers\" "
2532 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2538 * Set the "is_bbview" variable if it appears that we are looking at
2539 * a classic bulletin board view.
2541 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2542 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2547 * If we're not currently looking at ALL requested
2548 * messages, then display the selector bar
2551 /** begin bbview scroller */
2552 wprintf("<form name=\"msgomatictop\" class=\"selector_top\" > \n <p>");
2553 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2555 wprintf("<select name=\"whichones\" size=\"1\" "
2556 "OnChange=\"location.href=msgomatictop.whichones.options"
2557 "[selectedIndex].value\">\n");
2560 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2562 lo = b - maxmsgs + 2;
2564 wprintf("<option %s value="
2569 "%d-%d</option> \n",
2570 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2579 for (b=0; b<nummsgs; b = b + maxmsgs) {
2581 hi = b + maxmsgs + 1;
2582 if (hi > nummsgs) hi = nummsgs;
2583 wprintf("<option %s value="
2588 "%d-%d</option> \n",
2589 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2598 wprintf("<option value=\"%s?startmsg=%ld"
2599 "?maxmsgs=9999999?is_summary=%d\">",
2601 WCC->msgarr[0], is_summary);
2603 wprintf("</option>");
2604 wprintf("</select> ");
2605 wprintf(_("of %d messages."), nummsgs);
2607 /** forward/reverse */
2608 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2609 "OnChange=\"location.href='%s?sortby=forward'\"",
2610 (bbs_reverse ? "" : "checked"),
2614 wprintf(_("oldest to newest"));
2615 wprintf(" ");
2617 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2618 "OnChange=\"location.href='%s?sortby=reverse'\"",
2619 (bbs_reverse ? "checked" : ""),
2623 wprintf(_("newest to oldest"));
2626 wprintf("</p></form>\n");
2627 /** end bbview scroller */
2632 wprintf ("<script src=\"/static/dragdrop.js\" type=\"text/javascript\"></script>\n");
2637 for (a = 0; a < nummsgs; ++a) {
2638 if ((WCC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2640 /** Display the message */
2642 display_summarized(a);
2644 else if (is_addressbook) {
2645 fetch_ab_name(WCC->msgarr[a], buf);
2647 addrbook = realloc(addrbook,
2648 (sizeof(struct addrbookent) * num_ab) );
2649 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2650 sizeof(addrbook[num_ab-1].ab_name));
2651 addrbook[num_ab-1].ab_msgnum = WCC->msgarr[a];
2653 else if (is_calendar) {
2654 display_calendar(WCC->msgarr[a], WCC->summ[a].is_new);
2656 else if (is_tasks) {
2657 display_task(WCC->msgarr[a], WCC->summ[a].is_new);
2659 else if (is_notes) {
2660 display_note(WCC->msgarr[a], WCC->summ[a].is_new);
2663 if (displayed_msgs == NULL) {
2664 displayed_msgs = malloc(sizeof(long) *
2665 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2667 displayed_msgs[num_displayed] = WCC->msgarr[a];
2670 if (lowest_displayed < 0) lowest_displayed = a;
2671 highest_displayed = a;
2678 if (displayed_msgs != NULL) {
2680 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2683 /** if we do a split bbview in the future, begin messages div here */
2685 for (a=0; a<num_displayed; ++a) {
2686 read_message(displayed_msgs[a], 0, "");
2689 /** if we do a split bbview in the future, end messages div here */
2691 free(displayed_msgs);
2692 displayed_msgs = NULL;
2697 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2698 wprintf("</div>"); /**< end of 'message_list' div */
2700 /** Here's the grab-it-to-resize-the-message-list widget */
2701 wprintf("<div id=\"resize_msglist\" "
2702 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2703 "<div class=\"fix_scrollbar_bug\"> <hr>"
2707 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2711 * Bump these because although we're thinking in zero base, the user
2712 * is a drooling idiot and is thinking in one base.
2715 ++highest_displayed;
2718 * If we're not currently looking at ALL requested
2719 * messages, then display the selector bar
2722 /** begin bbview scroller */
2723 wprintf("<form name=\"msgomatic\" class=\"selector_bottom\" > \n <p>");
2724 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2726 wprintf("<select name=\"whichones\" size=\"1\" "
2727 "OnChange=\"location.href=msgomatic.whichones.options"
2728 "[selectedIndex].value\">\n");
2731 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2733 lo = b - maxmsgs + 2;
2735 wprintf("<option %s value="
2740 "%d-%d</option> \n",
2741 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2750 for (b=0; b<nummsgs; b = b + maxmsgs) {
2752 hi = b + maxmsgs + 1;
2753 if (hi > nummsgs) hi = nummsgs;
2754 wprintf("<option %s value="
2759 "%d-%d</option> \n",
2760 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2769 wprintf("<option value=\"%s?startmsg=%ld"
2770 "?maxmsgs=9999999?is_summary=%d\">",
2772 WCC->msgarr[0], is_summary);
2774 wprintf("</option>");
2775 wprintf("</select> ");
2776 wprintf(_("of %d messages."), nummsgs);
2778 /** forward/reverse */
2779 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2780 "OnChange=\"location.href='%s?sortby=forward'\"",
2781 (bbs_reverse ? "" : "checked"),
2785 wprintf(_("oldest to newest"));
2786 wprintf(" ");
2787 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2788 "OnChange=\"location.href='%s?sortby=reverse'\"",
2789 (bbs_reverse ? "checked" : ""),
2793 wprintf(_("newest to oldest"));
2796 wprintf("</p></form>\n");
2797 /** end bbview scroller */
2802 // wprintf ("</div>\n");
2803 wprintf ("<div id=\"wastebin\" align=middle>Drop notes here to remove them.</div>\n");
2804 wprintf ("<script type=\"text/javascript\">\n");
2805 // wprintf ("//<![CDATA[\n");
2806 wprintf ("Droppables.add(\"wastebin\",\n");
2808 wprintf ("\t\taccept:'notes',\n");
2809 wprintf ("\t\tonDrop:function(element)\n");
2810 wprintf ("\t\t{\n");
2811 wprintf ("\t\t\tElement.hide(element);\n");
2812 wprintf ("\t\t\tnew Ajax.Updater('notes', 'delnote',\n");
2813 wprintf ("\t\t\t{\n");
2814 wprintf ("\t\t\t\tasynchronous:true,\n");
2815 wprintf ("\t\t\t\tevalScripts:true,\n");
2816 wprintf ("\t\t\t\tonComplete:function(request)\n");
2817 wprintf ("\t\t\t\t{\n");
2818 wprintf ("\t\t\t\t\tElement.hide('indicator')\n");
2819 wprintf ("\t\t\t\t},\n");
2820 wprintf ("\t\t\t\tonLoading:function(request)\n");
2821 wprintf ("\t\t\t\t{\n");
2822 wprintf ("\t\t\t\t\tElement.show('indicator')\n");
2823 wprintf ("\t\t\t\t},\n");
2824 wprintf ("\t\t\t\tparameters:'id=' + encodeURIComponent(element.id)\n");
2825 wprintf ("\t\t\t})\n");
2826 wprintf ("\t\t}\n");
2828 // wprintf ("//]]>\n");
2829 wprintf ("</script>\n");
2836 do_tasks_view(); /** Render the task list */
2840 do_calendar_view(); /** Render the calendar */
2843 if (is_addressbook) {
2844 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2847 /** Note: wDumpContent() will output one additional </div> tag. */
2848 wprintf("</div>\n"); /** end of 'content' div */
2851 /** free the summary */
2852 if (WCC->summ != NULL) {
2857 if (addrbook != NULL) free(addrbook);
2862 * \brief Back end for post_message()
2863 * ... this is where the actual message gets transmitted to the server.
2865 void post_mime_to_server(void) {
2866 char top_boundary[SIZ];
2867 char alt_boundary[SIZ];
2868 int is_multipart = 0;
2870 struct wc_attachment *att;
2872 size_t encoded_length;
2873 size_t encoded_strlen;
2874 char *txtmail = NULL;
2876 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
2877 serv_info.serv_fqdn,
2881 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
2882 serv_info.serv_fqdn,
2887 /** RFC2045 requires this, and some clients look for it... */
2888 serv_puts("MIME-Version: 1.0");
2889 serv_puts("X-Mailer: " PACKAGE_STRING);
2891 /** If there are attachments, we have to do multipart/mixed */
2892 if (WC->first_attachment != NULL) {
2897 /** Remember, serv_printf() appends an extra newline */
2898 serv_printf("Content-type: multipart/mixed; "
2899 "boundary=\"%s\"\n", top_boundary);
2900 serv_printf("This is a multipart message in MIME format.\n");
2901 serv_printf("--%s", top_boundary);
2906 /* Remember, serv_printf() appends an extra newline */
2907 serv_printf("Content-type: multipart/alternative; "
2908 "boundary=\"%s\"\n", alt_boundary);
2909 serv_printf("This is a multipart message in MIME format.\n");
2910 serv_printf("--%s", alt_boundary);
2912 serv_puts("Content-type: text/plain; charset=utf-8");
2913 serv_puts("Content-Transfer-Encoding: quoted-printable");
2915 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
2916 text_to_server_qp(txtmail); /** Transmit message in quoted-printable encoding */
2919 serv_printf("--%s", alt_boundary);
2921 serv_puts("Content-type: text/html; charset=utf-8");
2922 serv_puts("Content-Transfer-Encoding: quoted-printable");
2924 serv_puts("<html><body>\r\n");
2925 text_to_server_qp(bstr("msgtext")); /** Transmit message in quoted-printable encoding */
2926 serv_puts("</body></html>\r\n");
2929 serv_printf("--%s--", alt_boundary);
2937 /** Add in the attachments */
2938 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2940 encoded_length = ((att->length * 150) / 100);
2941 encoded = malloc(encoded_length);
2942 if (encoded == NULL) break;
2943 encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1);
2945 serv_printf("--%s", top_boundary);
2946 serv_printf("Content-type: %s", att->content_type);
2947 serv_printf("Content-disposition: attachment; "
2948 "filename=\"%s\"", att->filename);
2949 serv_puts("Content-transfer-encoding: base64");
2951 serv_write(encoded, encoded_strlen);
2956 serv_printf("--%s--", top_boundary);
2964 * \brief Post message (or don't post message)
2966 * Note regarding the "dont_post" variable:
2967 * A random value (actually, it's just a timestamp) is inserted as a hidden
2968 * field called "postseq" when the display_enter page is generated. This
2969 * value is checked when posting, using the static variable dont_post. If a
2970 * user attempts to post twice using the same dont_post value, the message is
2971 * discarded. This prevents the accidental double-saving of the same message
2972 * if the user happens to click the browser "back" button.
2974 void post_message(void)
2977 char encoded_subject[1024];
2978 static long dont_post = (-1L);
2979 struct wc_attachment *att, *aptr;
2980 int is_anonymous = 0;
2983 if (!IsEmptyStr(bstr("force_room"))) {
2984 gotoroom(bstr("force_room"));
2987 display_name = bstr("display_name");
2988 if (!strcmp(display_name, "__ANONYMOUS__")) {
2993 if (WC->upload_length > 0) {
2995 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WC->upload_length);
2996 /** There's an attachment. Save it to this struct... */
2997 att = malloc(sizeof(struct wc_attachment));
2998 memset(att, 0, sizeof(struct wc_attachment));
2999 att->length = WC->upload_length;
3000 strcpy(att->content_type, WC->upload_content_type);
3001 strcpy(att->filename, WC->upload_filename);
3004 /** And add it to the list. */
3005 if (WC->first_attachment == NULL) {
3006 WC->first_attachment = att;
3009 aptr = WC->first_attachment;
3010 while (aptr->next != NULL) aptr = aptr->next;
3015 * Mozilla sends a simple filename, which is what we want,
3016 * but Satan's Browser sends an entire pathname. Reduce
3017 * the path to just a filename if we need to.
3019 while (num_tokens(att->filename, '/') > 1) {
3020 remove_token(att->filename, 0, '/');
3022 while (num_tokens(att->filename, '\\') > 1) {
3023 remove_token(att->filename, 0, '\\');
3027 * Transfer control of this memory from the upload struct
3028 * to the attachment struct.
3030 att->data = WC->upload;
3031 WC->upload_length = 0;
3037 if (!IsEmptyStr(bstr("cancel_button"))) {
3038 sprintf(WC->ImportantMessage,
3039 _("Cancelled. Message was not posted."));
3040 } else if (!IsEmptyStr(bstr("attach_button"))) {
3043 } else if (atol(bstr("postseq")) == dont_post) {
3044 sprintf(WC->ImportantMessage,
3045 _("Automatically cancelled because you have already "
3046 "saved this message."));
3048 webcit_rfc2047encode(encoded_subject, sizeof encoded_subject, bstr("subject"));
3049 sprintf(buf, "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s",
3057 bstr("my_email_addr")
3060 serv_getln(buf, sizeof buf);
3061 if (buf[0] == '4') {
3062 post_mime_to_server();
3063 if ( (!IsEmptyStr(bstr("recp")))
3064 || (!IsEmptyStr(bstr("cc" )))
3065 || (!IsEmptyStr(bstr("bcc" )))
3067 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
3070 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
3072 dont_post = atol(bstr("postseq"));
3074 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
3075 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3081 free_attachments(WC);
3084 * We may have been supplied with instructions regarding the location
3085 * to which we must return after posting. If found, go there.
3087 if (!IsEmptyStr(bstr("return_to"))) {
3088 http_redirect(bstr("return_to"));
3091 * If we were editing a page in a wiki room, go to that page now.
3093 else if (!IsEmptyStr(bstr("wikipage"))) {
3094 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
3098 * Otherwise, just go to the "read messages" loop.
3101 readloop("readnew");
3109 * \brief display the message entry screen
3111 void display_enter(void)
3117 struct wc_attachment *att;
3118 int recipient_required = 0;
3119 int subject_required = 0;
3120 int recipient_bad = 0;
3122 int is_anonymous = 0;
3123 long existing_page = (-1L);
3127 if (!IsEmptyStr(bstr("force_room"))) {
3128 gotoroom(bstr("force_room"));
3131 display_name = bstr("display_name");
3132 if (!strcmp(display_name, "__ANONYMOUS__")) {
3137 /** First test to see whether this is a room that requires recipients to be entered */
3138 serv_puts("ENT0 0");
3139 serv_getln(buf, sizeof buf);
3141 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
3142 recipient_required = 1;
3144 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3145 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3146 readloop("readnew");
3150 /* Is the server strongly recommending that the user enter a message subject? */
3151 if ((buf[3] != '\0') && (buf[4] != '\0')) {
3152 subject_required = extract_int(&buf[4], 1);
3156 * Are we perhaps in an address book view? If so, then an "enter
3157 * message" command really means "add new entry."
3159 if (WC->wc_default_view == VIEW_ADDRESSBOOK) {
3160 do_edit_vcard(-1, "", "", WC->wc_roomname);
3165 * Are we perhaps in a calendar room? If so, then an "enter
3166 * message" command really means "add new calendar item."
3168 if (WC->wc_default_view == VIEW_CALENDAR) {
3169 display_edit_event();
3174 * Are we perhaps in a tasks view? If so, then an "enter
3175 * message" command really means "add new task."
3177 if (WC->wc_default_view == VIEW_TASKS) {
3178 display_edit_task();
3183 * Otherwise proceed normally.
3184 * Do a custom room banner with no navbar...
3186 output_headers(1, 1, 2, 0, 0, 0);
3187 wprintf("<div id=\"banner\">\n");
3188 embed_room_banner(NULL, navbar_none);
3189 wprintf("</div>\n");
3190 wprintf("<div id=\"content\">\n"
3191 "<div class=\"fix_scrollbar_bug message \">");
3193 /** Now check our actual recipients if there are any */
3194 if (recipient_required) {
3195 sprintf(buf, "ENT0 0|%s|%d|0||%s||%s|%s|%s",
3199 bstr("cc"), bstr("bcc"), bstr("wikipage"));
3201 serv_getln(buf, sizeof buf);
3203 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
3204 if (!IsEmptyStr(bstr("recp")) &&
3205 !IsEmptyStr(bstr("cc" )) &&
3206 !IsEmptyStr(bstr("bcc" ))) {
3210 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3211 wprintf("<em>%s</em><br />\n", &buf[4]);
3216 /** If we got this far, we can display the message entry screen. */
3218 /** begin message entry screen */
3220 "enctype=\"multipart/form-data\" "
3222 "accept-charset=\"UTF-8\" "
3224 "name=\"enterform\""
3226 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
3227 if (WC->wc_view == VIEW_WIKI) {
3228 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
3230 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
3231 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
3232 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
3233 escputs(WC->wc_roomname);
3236 /** submit or cancel buttons */
3237 wprintf("<p class=\"send_edit_msg\">");
3238 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3239 if (recipient_required) {
3240 wprintf(_("Send message"));
3242 wprintf(_("Post message"));
3245 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3250 wprintf("<img src=\"static/newmess3_24x.gif\" class=\"imgedit\">");
3251 wprintf(" "); /** header bar */
3252 webcit_fmt_date(buf, now, 0);
3254 wprintf("\n"); /** header bar */
3256 wprintf("<table width=\"100%%\" class=\"edit_msg_table\">");
3258 wprintf("<th><label for=\"from_id\" > ");
3259 wprintf(_(" <I>from</I> "));
3260 wprintf("</label></th>");
3262 wprintf("<td colspan=\"2\">");
3264 /* Allow the user to select any of his valid screen names */
3266 wprintf("<select name=\"display_name\" size=1 id=\"from_id\">\n");
3269 serv_getln(buf, sizeof buf);
3270 if (buf[0] == '1') {
3271 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3272 wprintf("<option %s value=\"",
3273 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
3278 wprintf("</option>\n");
3282 if (WC->room_flags & QR_ANONOPT) {
3283 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
3284 ((!strcasecmp(bstr("__ANONYMOUS__"), WC->wc_fullname)) ? "selected" : ""),
3289 wprintf("</select>\n");
3291 /* If this is an email (not a post), allow the user to select any of his
3292 * valid email addresses.
3294 if (recipient_required) {
3296 serv_getln(buf, sizeof buf);
3297 if (buf[0] == '1') {
3298 wprintf("<select name=\"my_email_addr\" size=1>\n");
3299 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3300 wprintf("<option value=\"");
3304 wprintf("></option>\n");
3306 wprintf("</select>\n");
3310 wprintf(_(" <I>in</I> "));
3311 escputs(WC->wc_roomname);
3313 wprintf("</td></tr>");
3315 if (recipient_required) {
3319 wprintf("<tr><th><label for=\"recp_id\"> ");
3321 wprintf("</label></th>"
3322 "<td><input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
3323 ccraw = bstr("recp");
3324 len = strlen(ccraw);
3325 copy = (char*) malloc(len * 2 + 1);
3326 memcpy(copy, ccraw, len + 1);
3327 utf8ify_rfc822_string(copy);
3330 wprintf("\" size=45 maxlength=1000 />");
3331 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
3332 wprintf("</td><td rowspan=\"3\" align=\"left\" valign=\"top\">");
3334 /** Pop open an address book -- begin **/
3336 "<a href=\"javascript:PopOpenAddressBook('recp_id|%s|cc_id|%s|bcc_id|%s');\" "
3338 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
3340 _("To:"), _("CC:"), _("BCC:"),
3341 _("Contacts"), _("Contacts")
3343 /** Pop open an address book -- end **/
3345 wprintf("</td></tr>");
3347 wprintf("<tr><th><label for=\"cc_id\"> ");
3349 wprintf("</label></th>"
3350 "<td><input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
3352 len = strlen(ccraw);
3353 copy = (char*) malloc(len * 2 + 1);
3354 memcpy(copy, ccraw, len + 1);
3355 utf8ify_rfc822_string(copy);
3358 wprintf("\" size=45 maxlength=1000 />");
3359 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
3360 wprintf("</td></tr>");
3362 wprintf("<tr><th><label for=\"bcc_id\"> ");
3364 wprintf("</label></th>"
3365 "<td><input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
3366 ccraw = bstr("bcc");
3367 len = strlen(ccraw);
3368 copy = (char*) malloc(len * 2 + 1);
3369 memcpy(copy, ccraw, len + 1);
3370 utf8ify_rfc822_string(copy);
3373 wprintf("\" size=45 maxlength=1000 />");
3374 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
3375 wprintf("</td></tr>");
3377 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
3378 wprintf("<script type=\"text/javascript\"> \n"
3379 " activate_entmsg_autocompleters(); \n"
3385 wprintf("<tr><th><label for=\"subject_id\" > ");
3386 if (recipient_required || subject_required) {
3387 wprintf(_("Subject:"));
3390 wprintf(_("Subject (optional):"));
3392 wprintf("</label></th>"
3393 "<td colspan=\"2\">"
3394 "<input type=\"text\" name=\"subject\" id=\"subject_id\" value=\"");
3395 escputs(bstr("subject"));
3396 wprintf("\" size=45 maxlength=70>\n");
3397 wprintf("</td></tr>");
3399 wprintf("<tr><td colspan=\"3\">\n");
3401 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
3403 /** If we're continuing from a previous edit, put our partially-composed message back... */
3404 msgescputs(bstr("msgtext"));
3406 /* If we're forwarding a message, insert it here... */
3407 if (atol(bstr("fwdquote")) > 0L) {
3408 wprintf("<br><div align=center><i>");
3409 wprintf(_("--- forwarded message ---"));
3410 wprintf("</i></div><br>");
3411 pullquote_message(atol(bstr("fwdquote")), 1, 1);
3414 /** If we're replying quoted, insert the quote here... */
3415 else if (atol(bstr("replyquote")) > 0L) {
3418 pullquote_message(atol(bstr("replyquote")), 0, 1);
3419 wprintf("</blockquote><br>");
3422 /** If we're editing a wiki page, insert the existing page here... */
3423 else if (WC->wc_view == VIEW_WIKI) {
3424 safestrncpy(buf, bstr("wikipage"), sizeof buf);
3425 str_wiki_index(buf);
3426 existing_page = locate_message_by_uid(buf);
3427 if (existing_page >= 0L) {
3428 pullquote_message(existing_page, 1, 0);
3432 /** Insert our signature if appropriate... */
3433 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
3434 get_preference("use_sig", buf, sizeof buf);
3435 if (!strcasecmp(buf, "yes")) {
3437 get_preference("signature", ebuf, sizeof ebuf);
3438 euid_unescapize(buf, ebuf);
3439 wprintf("<br>--<br>");
3441 for (i=0; i<len; ++i) {
3442 if (buf[i] == '\n') {
3445 else if (buf[i] == '<') {
3448 else if (buf[i] == '>') {
3451 else if (buf[i] == '&') {
3454 else if (buf[i] == '\"') {
3457 else if (buf[i] == '\'') {
3460 else if (isprint(buf[i])) {
3461 wprintf("%c", buf[i]);
3467 wprintf("</textarea>\n");
3469 /** Make sure we only insert our signature once */
3470 /** We don't care if it was there or not before, it needs to be there now. */
3471 wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
3474 * The following template embeds the TinyMCE richedit control, and automatically
3475 * transforms the textarea into a richedit textarea.
3477 do_template("richedit");
3479 /** Enumerate any attachments which are already in place... */
3480 wprintf("<div class=\"attachment buttons\"><img src=\"static/diskette_24x.gif\" class=\"imgedit\" > ");
3481 wprintf(_("Attachments:"));
3483 wprintf("<select name=\"which_attachment\" size=1>");
3484 for (att = WC->first_attachment; att != NULL; att = att->next) {
3485 wprintf("<option value=\"");
3486 urlescputs(att->filename);
3488 escputs(att->filename);
3489 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3490 wprintf("</option>\n");
3492 wprintf("</select>");
3494 /** Now offer the ability to attach additional files... */
3495 wprintf(" ");
3496 wprintf(_("Attach file:"));
3497 wprintf(" <input name=\"attachfile\" class=\"attachfile\" "
3498 "size=16 type=\"file\">\n "
3499 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3500 wprintf("</div>"); /* End of "attachment buttons" div */
3503 wprintf("</td></tr></table>");
3505 wprintf("</form>\n");
3506 wprintf("</div>\n"); /* end of "fix_scrollbar_bug" div */
3508 /* NOTE: address_book_popup() will close the "content" div. Don't close it here. */
3509 DONE: address_book_popup();
3515 * \brief delete a message
3517 void delete_msg(void)
3522 msgid = atol(bstr("msgid"));
3524 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3525 serv_printf("DELE %ld", msgid);
3527 else { /** Otherwise move it to Trash */
3528 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3531 serv_getln(buf, sizeof buf);
3532 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3534 readloop("readnew");
3539 * \brief move a message to another folder
3546 msgid = atol(bstr("msgid"));
3548 if (!IsEmptyStr(bstr("move_button"))) {
3549 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3551 serv_getln(buf, sizeof buf);
3552 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3554 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3557 readloop("readnew");
3565 * \brief Confirm move of a message
3567 void confirm_move_msg(void)
3573 msgid = atol(bstr("msgid"));
3576 output_headers(1, 1, 2, 0, 0, 0);
3577 wprintf("<div id=\"banner\">\n");
3579 wprintf(_("Confirm move of message"));
3581 wprintf("</div>\n");
3583 wprintf("<div id=\"content\" class=\"service\">\n");
3585 wprintf("<CENTER>");
3587 wprintf(_("Move this message to:"));
3588 wprintf("<br />\n");
3590 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3591 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
3592 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3594 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3596 serv_getln(buf, sizeof buf);
3597 if (buf[0] == '1') {
3598 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3599 extract_token(targ, buf, 0, '|', sizeof targ);
3600 wprintf("<OPTION>");
3605 wprintf("</SELECT>\n");
3606 wprintf("<br />\n");
3608 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3610 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3611 wprintf("</form></CENTER>\n");
3613 wprintf("</CENTER>\n");