5 * \defgroup MsgDisp Functions which deal with the fetching and displaying of messages.
11 #include "webserver.h"
14 #define SUBJ_COL_WIDTH_PCT 50 /**< ??? */
15 #define SENDER_COL_WIDTH_PCT 30 /**< ??? */
16 #define DATE_PLUS_BUTTONS_WIDTH_PCT 20 /**< ??? */
19 * Address book entry (keep it short and sweet, it's just a quickie lookup
20 * which we can use to get to the real meat and bones later)
23 char ab_name[64]; /**< name string */
24 long ab_msgnum; /**< number in the citadel???? */
31 * \brief Handle subjects with RFC2047 encoding
33 * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=
34 * \param buf the stringbuffer to process
36 void utf8ify_rfc822_string(char *buf) {
42 iconv_t ic = (iconv_t)(-1) ;
43 char *ibuf; /**< Buffer of characters to be converted */
44 char *obuf; /**< Buffer for converted characters */
45 size_t ibuflen; /**< Length of input buffer */
46 size_t obuflen; /**< Length of output buffer */
47 char *isav; /**< Saved pointer to input buffer */
48 char *osav; /**< Saved pointer to output buffer */
51 while (start=strstr(buf, "=?"), end=strstr(buf, "?="),
52 ((start != NULL) && (end != NULL) && (end > start)) )
54 extract_token(charset, start, 1, '?', sizeof charset);
55 extract_token(encoding, start, 2, '?', sizeof encoding);
56 extract_token(istr, start, 3, '?', sizeof istr);
64 if (!strcasecmp(encoding, "B")) { /**< base64 */
65 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
67 else if (!strcasecmp(encoding, "Q")) { /**< quoted-printable */
68 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, strlen(istr));
71 strcpy(ibuf, istr); /**< huh? */
72 ibuflen = strlen(istr);
75 ic = iconv_open("UTF-8", charset);
76 if (ic != (iconv_t)(-1) ) {
79 obuf = (char *) malloc(obuflen);
81 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
82 osav[1024-obuflen] = 0;
87 remove_token(end, 0, '?');
88 remove_token(end, 0, '?');
89 remove_token(end, 0, '?');
90 remove_token(end, 0, '?');
93 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
102 remove_token(end, 0, '?');
103 remove_token(end, 0, '?');
104 remove_token(end, 0, '?');
105 remove_token(end, 0, '?');
106 strcpy(end, &end[1]);
108 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
115 * Since spammers will go to all sorts of absurd lengths to get their
116 * messages through, there are LOTS of corrupt headers out there.
117 * So, prevent a really badly formed RFC2047 header from throwing
118 * this function into an infinite loop.
121 if (passes > 20) return;
129 * \brief Look for URL's embedded in a buffer and make them linkable. We use a
130 * target window in order to keep the BBS session in its own window.
131 * \param buf the message buffer
147 for (pos = 0; pos < strlen(buf); ++pos) {
148 if (!strncasecmp(&buf[pos], "http://", 7))
150 if (!strncasecmp(&buf[pos], "ftp://", 6))
157 if ((start > 0) && (buf[start - 1] == '<'))
159 if ((start > 0) && (buf[start - 1] == '['))
161 if ((start > 0) && (buf[start - 1] == '('))
163 if ((start > 0) && (buf[start - 1] == '{'))
166 for (pos = strlen(buf); pos > start; --pos) {
167 if ((buf[pos] == ' ') || (buf[pos] == ench))
171 strncpy(urlbuf, &buf[start], end - start);
172 urlbuf[end - start] = 0;
174 strncpy(outbuf, buf, start);
175 sprintf(&outbuf[start], "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
176 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
177 strcat(outbuf, &buf[end]);
178 if ( strlen(outbuf) < 250 )
184 * \brief Turn a vCard "n" (name) field into something displayable.
185 * \param name the name field to convert
187 void vcard_n_prettyize(char *name)
192 original_name = strdup(name);
193 for (i=0; i<5; ++i) {
194 if (strlen(original_name) > 0) {
195 if (original_name[strlen(original_name)-1] == ' ') {
196 original_name[strlen(original_name)-1] = 0;
198 if (original_name[strlen(original_name)-1] == ';') {
199 original_name[strlen(original_name)-1] = 0;
204 for (i=0; i<strlen(original_name); ++i) {
205 if (original_name[i] == ';') {
209 name[strlen(name)+1] = 0;
210 name[strlen(name)] = original_name[i];
220 * \brief preparse a vcard name
221 * display_vcard() calls this after parsing the textual vCard into
222 * our 'struct vCard' data object.
223 * This gets called instead of display_parsed_vcard() if we are only looking
224 * to extract the person's name instead of displaying the card.
225 * \param v the vcard to retrieve the name from
226 * \param storename where to put the name at
228 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
231 strcpy(storename, "");
233 name = vcard_get_prop(v, "n", 1, 0, 0);
235 strcpy(storename, name);
236 /* vcard_n_prettyize(storename); */
244 * \brief html print a vcard
245 * display_vcard() calls this after parsing the textual vCard into
246 * our 'struct vCard' data object.
248 * Set 'full' to nonzero to display the full card, otherwise it will only
249 * show a summary line.
251 * This code is a bit ugly, so perhaps an explanation is due: we do this
252 * in two passes through the vCard fields. On the first pass, we process
253 * fields we understand, and then render them in a pretty fashion at the
254 * end. Then we make a second pass, outputting all the fields we don't
255 * understand in a simple two-column name/value format.
256 * \param v the vCard to display
257 * \param full display all items of the vcard?
259 void display_parsed_vcard(struct vCard *v, int full) {
265 char *thisname, *thisvalue;
266 char firsttoken[SIZ];
275 strcpy(fullname, "");
283 name = vcard_get_prop(v, "fn", 1, 0, 0);
287 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
288 strcpy(fullname, name);
289 vcard_n_prettyize(fullname);
299 wprintf("<div align=center><table bgcolor=#aaaaaa width=50%%>");
300 for (pass=1; pass<=2; ++pass) {
302 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
304 thisname = strdup(v->prop[i].name);
305 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
307 for (j=0; j<num_tokens(thisname, ';'); ++j) {
308 extract_token(buf, thisname, j, ';', sizeof buf);
309 if (!strcasecmp(buf, "encoding=quoted-printable")) {
311 remove_token(thisname, j, ';');
313 if (!strcasecmp(buf, "encoding=base64")) {
315 remove_token(thisname, j, ';');
320 thisvalue = malloc(strlen(v->prop[i].value) + 50);
321 j = CtdlDecodeQuotedPrintable(
322 thisvalue, v->prop[i].value,
323 strlen(v->prop[i].value) );
327 thisvalue = malloc(strlen(v->prop[i].value) + 50);
329 thisvalue, v->prop[i].value,
330 strlen(v->prop[i].value) );
333 thisvalue = strdup(v->prop[i].value);
336 /** Various fields we may encounter ***/
338 /** N is name, but only if there's no FN already there */
339 if (!strcasecmp(firsttoken, "n")) {
340 if (strlen(fullname) == 0) {
341 strcpy(fullname, thisvalue);
342 vcard_n_prettyize(fullname);
346 /** FN (full name) is a true 'display name' field */
347 else if (!strcasecmp(firsttoken, "fn")) {
348 strcpy(fullname, thisvalue);
352 else if (!strcasecmp(firsttoken, "title")) {
353 strcpy(title, thisvalue);
357 else if (!strcasecmp(firsttoken, "org")) {
358 strcpy(org, thisvalue);
361 else if (!strcasecmp(firsttoken, "email")) {
362 if (strlen(mailto) > 0) strcat(mailto, "<br />");
364 "<a href=\"display_enter"
365 "?force_room=_MAIL_?recp=");
367 urlesc(&mailto[strlen(mailto)], fullname);
368 urlesc(&mailto[strlen(mailto)], " <");
369 urlesc(&mailto[strlen(mailto)], thisvalue);
370 urlesc(&mailto[strlen(mailto)], ">");
372 strcat(mailto, "\">");
373 stresc(&mailto[strlen(mailto)], thisvalue, 1, 1);
374 strcat(mailto, "</A>");
376 else if (!strcasecmp(firsttoken, "tel")) {
377 if (strlen(phone) > 0) strcat(phone, "<br />");
378 strcat(phone, thisvalue);
379 for (j=0; j<num_tokens(thisname, ';'); ++j) {
380 extract_token(buf, thisname, j, ';', sizeof buf);
381 if (!strcasecmp(buf, "tel"))
383 else if (!strcasecmp(buf, "work"))
384 strcat(phone, _(" (work)"));
385 else if (!strcasecmp(buf, "home"))
386 strcat(phone, _(" (home)"));
387 else if (!strcasecmp(buf, "cell"))
388 strcat(phone, _(" (cell)"));
396 else if (!strcasecmp(firsttoken, "adr")) {
399 wprintf(_("Address:"));
400 wprintf("</TD><TD>");
401 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
402 extract_token(buf, thisvalue, j, ';', sizeof buf);
403 if (strlen(buf) > 0) {
405 if (j<3) wprintf("<br />");
409 wprintf("</TD></TR>\n");
412 else if (!strcasecmp(firsttoken, "version")) {
415 else if (!strcasecmp(firsttoken, "rev")) {
418 else if (!strcasecmp(firsttoken, "label")) {
423 /*** Don't show extra fields. They're ugly.
427 wprintf("</TD><TD>");
429 wprintf("</TD></TR>\n");
439 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
440 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
441 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
442 "<FONT SIZE=+1><B>");
444 wprintf("</B></FONT>");
445 if (strlen(title) > 0) {
446 wprintf("<div align=right>");
450 if (strlen(org) > 0) {
451 wprintf("<div align=right>");
455 wprintf("</TD></TR>\n");
457 if (strlen(phone) > 0) {
459 wprintf(_("Telephone:"));
460 wprintf("</td><td>%s</td></tr>\n", phone);
462 if (strlen(mailto) > 0) {
464 wprintf(_("E-mail:"));
465 wprintf("</td><td>%s</td></tr>\n", mailto);
471 wprintf("</table></div>\n");
477 * \brief Display a textual vCard
478 * (Converts to a vCard object and then calls the actual display function)
479 * Set 'full' to nonzero to display the whole card instead of a one-liner.
480 * Or, if "storename" is non-NULL, just store the person's name in that
481 * buffer instead of displaying the card at all.
482 * \param vcard_source the buffer containing the vcard text
483 * \param alpha what???
484 * \param full should we usse all lines?
485 * \param storename where to store???
487 void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
493 v = vcard_load(vcard_source);
494 if (v == NULL) return;
496 name = vcard_get_prop(v, "n", 1, 0, 0);
502 if (storename != NULL) {
503 fetchname_parsed_vcard(v, storename);
505 else if ( (alpha == 0)
506 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
507 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
509 display_parsed_vcard(v, full);
517 * \brief I wanna SEE that message!
518 * \param msgnum the citadel number of the message to display
519 * \param printable_view are we doing a print view?
520 * \param section Optional for encapsulated message/rfc822 submessage)
522 void read_message(long msgnum, int printable_view, char *section) {
524 char mime_partnum[256];
525 char mime_filename[256];
526 char mime_content_type[256];
527 char mime_charset[256];
528 char mime_disposition[256];
531 char mime_submessages[256];
538 char reply_all[4096];
544 char vcard_partnum[256];
545 char cal_partnum[256];
546 char *part_source = NULL;
548 iconv_t ic = (iconv_t)(-1) ;
549 char *ibuf; /**< Buffer of characters to be converted */
550 char *obuf; /**< Buffer for converted characters */
551 size_t ibuflen; /**< Length of input buffer */
552 size_t obuflen; /**< Length of output buffer */
553 char *osav; /**< Saved pointer to output buffer */
559 strcpy(reply_to, "");
560 strcpy(reply_all, "");
561 strcpy(vcard_partnum, "");
562 strcpy(cal_partnum, "");
563 strcpy(mime_http, "");
564 strcpy(mime_content_type, "text/plain");
565 strcpy(mime_charset, "us-ascii");
566 strcpy(mime_submessages, "");
568 serv_printf("MSG4 %ld|%s", msgnum, section);
569 serv_getln(buf, sizeof buf);
572 wprintf(_("ERROR:"));
573 wprintf("</STRONG> %s<br />\n", &buf[4]);
577 /** begin everythingamundo table */
578 if (!printable_view) {
579 wprintf("<div class=\"fix_scrollbar_bug\">\n");
580 wprintf("<table width=100%% border=1 cellspacing=0 "
581 "cellpadding=0><TR><TD>\n");
584 /** begin message header table */
585 wprintf("<table width=100%% border=0 cellspacing=0 "
586 "cellpadding=1 bgcolor=\"#CCCCCC\"><tr><td>\n");
588 wprintf("<span class=\"message_header\">");
589 strcpy(m_subject, "");
592 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
593 if (!strcmp(buf, "000")) {
595 wprintf(_("unexpected end of message"));
596 wprintf("</i><br /><br />\n");
597 wprintf("</span>\n");
600 if (!strncasecmp(buf, "nhdr=yes", 8))
604 if (!strncasecmp(buf, "type=", 5))
605 format_type = atoi(&buf[5]);
606 if (!strncasecmp(buf, "from=", 5)) {
607 strcpy(from, &buf[5]);
609 wprintf("<a href=\"showuser?who=");
611 utf8ify_rfc822_string(from);
618 if (!strncasecmp(buf, "subj=", 5)) {
619 safestrncpy(m_subject, &buf[5], sizeof m_subject);
621 if (!strncasecmp(buf, "cccc=", 5)) {
622 safestrncpy(m_cc, &buf[5], sizeof m_cc);
623 if (strlen(reply_all) > 0) {
624 strcat(reply_all, ", ");
626 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
627 (sizeof reply_all - strlen(reply_all)) );
629 if ((!strncasecmp(buf, "hnod=", 5))
630 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
631 wprintf("(%s) ", &buf[5]);
633 if ((!strncasecmp(buf, "room=", 5))
634 && (strcasecmp(&buf[5], WC->wc_roomname))
635 && (strlen(&buf[5])>0) ) {
637 wprintf("%s> ", &buf[5]);
639 if (!strncasecmp(buf, "rfca=", 5)) {
640 strcpy(rfca, &buf[5]);
646 if (!strncasecmp(buf, "node=", 5)) {
647 strcpy(node, &buf[5]);
648 if ( ((WC->room_flags & QR_NETWORK)
649 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
650 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
653 wprintf("@%s ", &buf[5]);
656 if (!strncasecmp(buf, "rcpt=", 5)) {
660 if (strlen(reply_all) > 0) {
661 strcat(reply_all, ", ");
663 safestrncpy(&reply_all[strlen(reply_all)], &buf[5],
664 (sizeof reply_all - strlen(reply_all)) );
666 if (!strncasecmp(buf, "time=", 5)) {
667 fmt_date(now, atol(&buf[5]), 0);
671 if (!strncasecmp(buf, "part=", 5)) {
672 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
673 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
674 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
675 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
676 mime_length = extract_int(&buf[5], 5);
678 if (!strcasecmp(mime_content_type, "message/rfc822")) {
679 if (strlen(mime_submessages) > 0) {
680 strcat(mime_submessages, "|");
682 strcat(mime_submessages, mime_partnum);
684 else if ((!strcasecmp(mime_disposition, "inline"))
685 && (!strncasecmp(mime_content_type, "image/", 6)) ){
686 snprintf(&mime_http[strlen(mime_http)],
687 (sizeof(mime_http) - strlen(mime_http) - 1),
688 "<img src=\"mimepart/%ld/%s/%s\">",
689 msgnum, mime_partnum, mime_filename);
691 else if ( (!strcasecmp(mime_disposition, "attachment"))
692 || (!strcasecmp(mime_disposition, "inline")) ) {
693 snprintf(&mime_http[strlen(mime_http)],
694 (sizeof(mime_http) - strlen(mime_http) - 1),
695 "<a href=\"mimepart/%ld/%s/%s\" "
696 "target=\"wc.%ld.%s\">"
697 "<img src=\"static/diskette_24x.gif\" "
698 "border=0 align=middle>\n"
699 "%s (%s, %d bytes)</a><br />\n",
700 msgnum, mime_partnum, mime_filename,
701 msgnum, mime_partnum,
703 mime_content_type, mime_length
707 /** begin handler prep ***/
708 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
709 strcpy(vcard_partnum, mime_partnum);
712 if (!strcasecmp(mime_content_type, "text/calendar")) {
713 strcpy(cal_partnum, mime_partnum);
716 /** end handler prep ***/
722 /** Generate a reply-to address */
723 if (strlen(rfca) > 0) {
724 strcpy(reply_to, rfca);
727 if ( (strlen(node) > 0)
728 && (strcasecmp(node, serv_info.serv_nodename))
729 && (strcasecmp(node, serv_info.serv_humannode)) ) {
730 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
734 snprintf(reply_to, sizeof(reply_to), "%s", from);
744 utf8ify_rfc822_string(m_cc);
745 utf8ify_rfc822_string(m_subject);
747 if (strlen(m_cc) > 0) {
749 "<span class=\"message_subject\">");
755 if (strlen(m_subject) > 0) {
757 "<span class=\"message_subject\">");
758 wprintf(_("Subject:"));
765 /** start msg buttons */
766 if (!printable_view) {
767 wprintf("<td align=right><span class=\"msgbuttons\">\n");
770 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
771 wprintf("<a href=\"display_enter");
772 if (WC->is_mailbox) {
773 wprintf("?replyquote=%ld", msgnum);
776 urlescputs(reply_to);
777 if (strlen(m_subject) > 0) {
778 wprintf("?subject=");
779 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
780 urlescputs(m_subject);
782 wprintf("\">[%s]</a> ", _("Reply"));
786 if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
787 if (!WC->is_mailbox) {
788 wprintf("<a href=\"display_enter");
789 wprintf("?replyquote=%ld", msgnum);
791 urlescputs(reply_to);
792 if (strlen(m_subject) > 0) {
793 wprintf("?subject=");
794 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
795 urlescputs(m_subject);
797 wprintf("\">[%s]</a> ", _("ReplyQuoted"));
802 if (WC->wc_view == VIEW_MAILBOX) {
803 wprintf("<a href=\"display_enter");
804 wprintf("?replyquote=%ld", msgnum);
806 urlescputs(reply_to);
808 urlescputs(reply_all);
809 if (strlen(m_subject) > 0) {
810 wprintf("?subject=");
811 if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
812 urlescputs(m_subject);
814 wprintf("\">[%s]</a> ", _("ReplyAll"));
818 if (WC->wc_view == VIEW_MAILBOX) {
819 wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
820 if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
821 urlescputs(m_subject);
822 wprintf("\">[%s]</a> ", _("Forward"));
825 /** If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
826 if ( (WC->is_room_aide) || (WC->is_mailbox) ) {
828 wprintf("<a href=\"confirm_move_msg?msgid=%ld\">[%s]</a> ",
832 wprintf("<a href=\"delete_msg?msgid=%ld\" "
833 "onClick=\"return confirm('%s');\">"
834 "[%s]</a> ", msgnum, _("Delete this message?"), _("Delete")
839 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'); \" >"
840 "[%s]</a>", msgnum, msgnum, _("Headers"));
844 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'); \" >"
845 "[%s]</a>", msgnum, msgnum, _("Print"));
847 wprintf("</span></td>");
850 wprintf("</tr></table>\n");
853 wprintf("<table border=0 width=100%% bgcolor=\"#FFFFFF\" "
854 "cellpadding=1 cellspacing=0><tr><td>");
857 * Learn the content type
859 strcpy(mime_content_type, "text/plain");
860 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
861 if (!strcmp(buf, "000")) {
863 wprintf(_("unexpected end of message"));
864 wprintf("</i><br /><br />\n");
867 if (!strncasecmp(buf, "Content-type: ", 14)) {
868 safestrncpy(mime_content_type, &buf[14],
869 sizeof(mime_content_type));
870 for (i=0; i<strlen(mime_content_type); ++i) {
871 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
872 safestrncpy(mime_charset, &mime_content_type[i+8],
873 sizeof mime_charset);
876 for (i=0; i<strlen(mime_content_type); ++i) {
877 if (mime_content_type[i] == ';') {
878 mime_content_type[i] = 0;
884 /** Set up a character set conversion if we need to (and if we can) */
886 if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
887 if ( (strcasecmp(mime_charset, "us-ascii"))
888 && (strcasecmp(mime_charset, "UTF-8"))
889 && (strcasecmp(mime_charset, ""))
891 ic = iconv_open("UTF-8", mime_charset);
892 if (ic == (iconv_t)(-1) ) {
893 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
894 __FILE__, __LINE__, mime_charset, strerror(errno));
899 /** Messages in legacy Citadel variformat get handled thusly... */
900 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
904 /** Boring old 80-column fixed format text gets handled this way... */
905 else if ( (!strcasecmp(mime_content_type, "text/plain"))
906 || (!strcasecmp(mime_content_type, "text")) ) {
907 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
908 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
909 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
912 if (ic != (iconv_t)(-1) ) {
914 ibuflen = strlen(ibuf);
916 obuf = (char *) malloc(obuflen);
918 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
919 osav[SIZ-obuflen] = 0;
920 safestrncpy(buf, osav, sizeof buf);
925 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
926 buf[strlen(buf) - 1] = 0;
928 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
929 wprintf("<blockquote>");
931 } else if ((bq == 1) &&
932 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
933 wprintf("</blockquote>");
939 wprintf("</tt><br />\n");
941 wprintf("</i><br />");
944 else /** HTML is fun, but we've got to strip it first */
945 if (!strcasecmp(mime_content_type, "text/html")) {
946 output_html(mime_charset);
949 /** Unknown weirdness */
951 wprintf(_("I don't know how to display %s"), mime_content_type);
952 wprintf("<br />\n", mime_content_type);
953 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
956 /** If there are attached submessages, display them now... */
957 if ( (strlen(mime_submessages) > 0) && (!section[0]) ) {
958 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
959 extract_token(buf, mime_submessages, i, '|', sizeof buf);
960 /** use printable_view to suppress buttons */
961 wprintf("<blockquote>");
962 read_message(msgnum, 1, buf);
963 wprintf("</blockquote>");
968 /** Afterwards, offer links to download attachments 'n' such */
969 if ( (strlen(mime_http) > 0) && (!section[0]) ) {
970 wprintf("%s", mime_http);
973 /** Handler for vCard parts */
974 if (strlen(vcard_partnum) > 0) {
975 part_source = load_mimepart(msgnum, vcard_partnum);
976 if (part_source != NULL) {
978 /** If it's my vCard I can edit it */
979 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
980 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
981 || (WC->wc_view == VIEW_ADDRESSBOOK)
983 wprintf("<a href=\"edit_vcard?"
984 "msgnum=%ld?partnum=%s\">",
985 msgnum, vcard_partnum);
986 wprintf("[%s]</a>", _("edit"));
989 /** In all cases, display the full card */
990 display_vcard(part_source, 0, 1, NULL);
994 /** Handler for calendar parts */
995 if (strlen(cal_partnum) > 0) {
996 part_source = load_mimepart(msgnum, cal_partnum);
997 if (part_source != NULL) {
998 cal_process_attachment(part_source,
999 msgnum, cal_partnum);
1009 wprintf("</td></tr></table>\n");
1011 /** end everythingamundo table */
1012 if (!printable_view) {
1013 wprintf("</td></tr></table>\n");
1014 wprintf("</div><br />\n");
1018 if (ic != (iconv_t)(-1) ) {
1027 * \brief Unadorned HTML output of an individual message, suitable
1028 * for placing in a hidden iframe, for printing, or whatever
1029 * \param msgnum_as_string the message to embed???
1031 void embed_message(char *msgnum_as_string) {
1034 msgnum = atol(msgnum_as_string);
1035 begin_ajax_response();
1036 read_message(msgnum, 0, "");
1037 end_ajax_response();
1042 * \brief Printable view of a message
1043 * \param msgnum_as_string the message to print???
1045 void print_message(char *msgnum_as_string) {
1048 msgnum = atol(msgnum_as_string);
1049 output_headers(0, 0, 0, 0, 0, 0);
1051 wprintf("Content-type: text/html\r\n"
1053 "Connection: close\r\n",
1057 wprintf("\r\n\r\n<html>\n"
1058 "<head><title>Printable view</title></head>\n"
1059 "<body onLoad=\" window.print(); window.close(); \">\n"
1062 read_message(msgnum, 1, "");
1064 wprintf("\n</body></html>\n\n");
1071 * \brief Display a message's headers
1072 * \param msgnum_as_string the message headers to print???
1074 void display_headers(char *msgnum_as_string) {
1078 msgnum = atol(msgnum_as_string);
1079 output_headers(0, 0, 0, 0, 0, 0);
1081 wprintf("Content-type: text/plain\r\n"
1083 "Connection: close\r\n",
1087 serv_printf("MSG2 %ld|3", msgnum);
1088 serv_getln(buf, sizeof buf);
1089 if (buf[0] == '1') {
1090 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1091 wprintf("%s\n", buf);
1101 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1102 * or 'reply quoted' operations.
1104 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1105 * in this function. Doing so would throw a JavaScript error in the
1106 * 'supplied text' argument to the editor.
1107 * \param msgnum the citadel message number
1108 * \param forward_attachments atachment to forward???
1110 void pullquote_message(long msgnum, int forward_attachments) {
1112 char mime_partnum[256];
1113 char mime_filename[256];
1114 char mime_content_type[256];
1115 char mime_charset[256];
1116 char mime_disposition[256];
1118 char mime_http[SIZ];
1119 char *attachments = NULL;
1120 int num_attachments = 0;
1121 struct wc_attachment *att, *aptr;
1122 char m_subject[256];
1128 int format_type = 0;
1133 iconv_t ic = (iconv_t)(-1) ;
1134 char *ibuf; /**< Buffer of characters to be converted */
1135 char *obuf; /**< Buffer for converted characters */
1136 size_t ibuflen; /**< Length of input buffer */
1137 size_t obuflen; /**< Length of output buffer */
1138 char *osav; /**< Saved pointer to output buffer */
1144 strcpy(reply_to, "");
1145 strcpy(mime_http, "");
1146 strcpy(mime_content_type, "text/plain");
1147 strcpy(mime_charset, "us-ascii");
1149 serv_printf("MSG4 %ld", msgnum);
1150 serv_getln(buf, sizeof buf);
1151 if (buf[0] != '1') {
1152 wprintf(_("ERROR:"));
1153 wprintf("%s<br />", &buf[4]);
1157 strcpy(m_subject, "");
1159 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1160 if (!strcmp(buf, "000")) {
1161 wprintf(_("unexpected end of message"));
1164 if (!strncasecmp(buf, "nhdr=yes", 8))
1168 if (!strncasecmp(buf, "type=", 5))
1169 format_type = atoi(&buf[5]);
1170 if (!strncasecmp(buf, "from=", 5)) {
1171 strcpy(from, &buf[5]);
1172 wprintf(_("from "));
1174 utf8ify_rfc822_string(from);
1178 if (!strncasecmp(buf, "subj=", 5)) {
1179 strcpy(m_subject, &buf[5]);
1181 if ((!strncasecmp(buf, "hnod=", 5))
1182 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1183 wprintf("(%s) ", &buf[5]);
1185 if ((!strncasecmp(buf, "room=", 5))
1186 && (strcasecmp(&buf[5], WC->wc_roomname))
1187 && (strlen(&buf[5])>0) ) {
1189 wprintf("%s> ", &buf[5]);
1191 if (!strncasecmp(buf, "rfca=", 5)) {
1192 strcpy(rfca, &buf[5]);
1198 if (!strncasecmp(buf, "node=", 5)) {
1199 strcpy(node, &buf[5]);
1200 if ( ((WC->room_flags & QR_NETWORK)
1201 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1202 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1203 && (strlen(rfca)==0)
1205 wprintf("@%s ", &buf[5]);
1208 if (!strncasecmp(buf, "rcpt=", 5)) {
1210 wprintf("%s ", &buf[5]);
1212 if (!strncasecmp(buf, "time=", 5)) {
1213 fmt_date(now, atol(&buf[5]), 0);
1214 wprintf("%s ", now);
1218 * Save attachment info for later. We can't start downloading them
1219 * yet because we're in the middle of a server transaction.
1221 if (!strncasecmp(buf, "part=", 5)) {
1223 attachments = realloc(attachments, (num_attachments * 1024));
1224 strcat(attachments, &buf[5]);
1225 strcat(attachments, "\n");
1233 utf8ify_rfc822_string(m_subject);
1235 if (strlen(m_subject) > 0) {
1236 wprintf(_("Subject:"));
1238 msgescputs(m_subject);
1248 * Learn the content type
1250 strcpy(mime_content_type, "text/plain");
1251 while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) {
1252 if (!strcmp(buf, "000")) {
1253 wprintf(_("unexpected end of message"));
1256 if (!strncasecmp(buf, "Content-type: ", 14)) {
1257 safestrncpy(mime_content_type, &buf[14],
1258 sizeof(mime_content_type));
1259 for (i=0; i<strlen(mime_content_type); ++i) {
1260 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1261 safestrncpy(mime_charset, &mime_content_type[i+8],
1262 sizeof mime_charset);
1265 for (i=0; i<strlen(mime_content_type); ++i) {
1266 if (mime_content_type[i] == ';') {
1267 mime_content_type[i] = 0;
1273 /** Set up a character set conversion if we need to (and if we can) */
1275 if ( (strcasecmp(mime_charset, "us-ascii"))
1276 && (strcasecmp(mime_charset, "UTF-8"))
1277 && (strcasecmp(mime_charset, ""))
1279 ic = iconv_open("UTF-8", mime_charset);
1280 if (ic == (iconv_t)(-1) ) {
1281 lprintf(5, "%s:%d iconv_open() failed: %s\n",
1282 __FILE__, __LINE__, strerror(errno));
1287 /** Messages in legacy Citadel variformat get handled thusly... */
1288 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1292 /* Boring old 80-column fixed format text gets handled this way... */
1293 else if (!strcasecmp(mime_content_type, "text/plain")) {
1294 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1295 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
1296 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
1299 if (ic != (iconv_t)(-1) ) {
1301 ibuflen = strlen(ibuf);
1303 obuf = (char *) malloc(obuflen);
1305 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1306 osav[SIZ-obuflen] = 0;
1307 safestrncpy(buf, osav, sizeof buf);
1312 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
1313 buf[strlen(buf) - 1] = 0;
1315 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1316 wprintf("<blockquote>");
1318 } else if ((bq == 1) &&
1319 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1320 wprintf("</blockquote>");
1326 wprintf("</tt><br />");
1328 wprintf("</i><br />");
1331 /** HTML just gets escaped and stuffed back into the editor */
1332 else if (!strcasecmp(mime_content_type, "text/html")) {
1333 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1338 /** Unknown weirdness ... don't know how to handle this content type */
1340 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1344 /** end of body handler */
1347 * If there were attachments, we have to download them and insert them
1348 * into the attachment chain for the forwarded message we are composing.
1350 if ( (forward_attachments) && (num_attachments) ) {
1351 for (i=0; i<num_attachments; ++i) {
1352 extract_token(buf, attachments, i, '\n', sizeof buf);
1353 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1354 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1355 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1356 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1357 mime_length = extract_int(buf, 5);
1360 * tracing ... uncomment if necessary
1362 lprintf(9, "fwd filename: %s\n", mime_filename);
1363 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1364 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1365 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1366 lprintf(9, "fwd length : %d\n", mime_length);
1369 if ( (!strcasecmp(mime_disposition, "inline"))
1370 || (!strcasecmp(mime_disposition, "attachment")) ) {
1372 /* Create an attachment struct from this mime part... */
1373 att = malloc(sizeof(struct wc_attachment));
1374 memset(att, 0, sizeof(struct wc_attachment));
1375 att->length = mime_length;
1376 strcpy(att->content_type, mime_content_type);
1377 strcpy(att->filename, mime_filename);
1379 att->data = load_mimepart(msgnum, mime_partnum);
1381 /* And add it to the list. */
1382 if (WC->first_attachment == NULL) {
1383 WC->first_attachment = att;
1386 aptr = WC->first_attachment;
1387 while (aptr->next != NULL) aptr = aptr->next;
1397 if (ic != (iconv_t)(-1) ) {
1404 * \brief display sumarized item???
1405 * \param num hom many? which???
1407 void display_summarized(int num) {
1410 wprintf("<tr id=\"m%ld\" style=\"width:100%%;font-weight:%s;background-color:#ffffff\" "
1411 "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
1412 WC->summ[num].msgnum,
1413 (WC->summ[num].is_new ? "bold" : "normal"),
1414 WC->summ[num].msgnum
1417 wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
1418 escputs(WC->summ[num].subj);
1421 wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
1422 escputs(WC->summ[num].from);
1425 wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
1426 fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
1436 * \brief display the adressbook overview
1437 * \param msgnum the citadel message number
1438 * \param alpha what????
1440 void display_addressbook(long msgnum, char alpha) {
1442 char mime_partnum[SIZ];
1443 char mime_filename[SIZ];
1444 char mime_content_type[SIZ];
1445 char mime_disposition[SIZ];
1447 char vcard_partnum[SIZ];
1448 char *vcard_source = NULL;
1449 struct message_summary summ;
1451 memset(&summ, 0, sizeof(summ));
1452 safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1454 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
1456 serv_getln(buf, sizeof buf);
1457 if (buf[0] != '1') return;
1459 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1460 if (!strncasecmp(buf, "part=", 5)) {
1461 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1462 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1463 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1464 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1465 mime_length = extract_int(&buf[5], 5);
1467 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1468 strcpy(vcard_partnum, mime_partnum);
1474 if (strlen(vcard_partnum) > 0) {
1475 vcard_source = load_mimepart(msgnum, vcard_partnum);
1476 if (vcard_source != NULL) {
1478 /** Display the summary line */
1479 display_vcard(vcard_source, alpha, 0, NULL);
1481 /** If it's my vCard I can edit it */
1482 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1483 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1484 || (WC->wc_view == VIEW_ADDRESSBOOK)
1486 wprintf("<a href=\"edit_vcard?"
1487 "msgnum=%ld?partnum=%s\">",
1488 msgnum, vcard_partnum);
1489 wprintf("[%s]</a>", _("edit"));
1501 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1502 * \param namebuf name to analyze, reverse if nescessary
1504 void lastfirst_firstlast(char *namebuf) {
1505 char firstname[SIZ];
1509 if (namebuf == NULL) return;
1510 if (strchr(namebuf, ';') != NULL) return;
1512 i = num_tokens(namebuf, ' ');
1515 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1516 remove_token(namebuf, i-1, ' ');
1517 strcpy(firstname, namebuf);
1518 sprintf(namebuf, "%s; %s", lastname, firstname);
1522 * \brief fetch what??? name
1523 * \param msgnum the citadel message number
1524 * \param namebuf where to put the name in???
1526 void fetch_ab_name(long msgnum, char *namebuf) {
1528 char mime_partnum[SIZ];
1529 char mime_filename[SIZ];
1530 char mime_content_type[SIZ];
1531 char mime_disposition[SIZ];
1533 char vcard_partnum[SIZ];
1534 char *vcard_source = NULL;
1536 struct message_summary summ;
1538 if (namebuf == NULL) return;
1539 strcpy(namebuf, "");
1541 memset(&summ, 0, sizeof(summ));
1542 safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1544 sprintf(buf, "MSG0 %ld|1", msgnum); /** ask for headers only */
1546 serv_getln(buf, sizeof buf);
1547 if (buf[0] != '1') return;
1549 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1550 if (!strncasecmp(buf, "part=", 5)) {
1551 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1552 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1553 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1554 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1555 mime_length = extract_int(&buf[5], 5);
1557 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
1558 strcpy(vcard_partnum, mime_partnum);
1564 if (strlen(vcard_partnum) > 0) {
1565 vcard_source = load_mimepart(msgnum, vcard_partnum);
1566 if (vcard_source != NULL) {
1568 /* Grab the name off the card */
1569 display_vcard(vcard_source, 0, 0, namebuf);
1575 lastfirst_firstlast(namebuf);
1577 for (i=0; i<strlen(namebuf); ++i) {
1578 if (namebuf[i] != ';') return;
1580 strcpy(namebuf, _("(no name)"));
1586 * \brief Record compare function for sorting address book indices
1587 * \param ab1 adressbook one
1588 * \param ab2 adressbook two
1590 int abcmp(const void *ab1, const void *ab2) {
1592 (((const struct addrbookent *)ab1)->ab_name),
1593 (((const struct addrbookent *)ab2)->ab_name)
1599 * \brief Helper function for do_addrbook_view()
1600 * Converts a name into a three-letter tab label
1601 * \param tabbuf the tabbuffer to add name to
1602 * \param name the name to add to the tabbuffer
1604 void nametab(char *tabbuf, char *name) {
1605 stresc(tabbuf, name, 0, 0);
1606 tabbuf[0] = toupper(tabbuf[0]);
1607 tabbuf[1] = tolower(tabbuf[1]);
1608 tabbuf[2] = tolower(tabbuf[2]);
1614 * \brief Render the address book using info we gathered during the scan
1615 * \param addrbook the addressbook to render
1616 * \param num_ab the number of the addressbook
1618 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
1622 static int NAMESPERPAGE = 60;
1626 char tabfirst_label[SIZ];
1628 char tablast_label[SIZ];
1631 wprintf("<br /><br /><br /><div align=\"center\"><i>");
1632 wprintf(_("This address book is empty."));
1633 wprintf("</i></div>\n");
1638 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
1641 num_pages = num_ab / NAMESPERPAGE;
1643 page = atoi(bstr("page"));
1646 for (i=0; i<=num_pages; ++i) {
1648 wprintf("<a href=\"readfwd?page=%d\">", i);
1653 tabfirst = i * NAMESPERPAGE;
1654 tablast = tabfirst + NAMESPERPAGE - 1;
1655 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
1656 nametab(tabfirst_label, addrbook[tabfirst].ab_name);
1657 nametab(tablast_label, addrbook[tablast].ab_name);
1658 wprintf("[%s - %s]",
1659 tabfirst_label, tablast_label
1668 wprintf("<br />\n");
1670 wprintf("<table border=0 cellspacing=0 "
1671 "cellpadding=3 width=100%%>\n"
1674 for (i=0; i<num_ab; ++i) {
1676 if ((i / NAMESPERPAGE) == page) {
1678 if ((displayed % 4) == 0) {
1679 if (displayed > 0) {
1683 wprintf("<tr bgcolor=\"#%s\">",
1684 (bg ? "DDDDDD" : "FFFFFF")
1690 wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
1691 addrbook[i].ab_msgnum);
1692 wprintf("?maxmsgs=1?summary=0?alpha=%s\">", bstr("alpha"));
1693 vcard_n_prettyize(addrbook[i].ab_name);
1694 escputs(addrbook[i].ab_name);
1695 wprintf("</a></td>\n");
1700 wprintf("</tr></table>\n");
1706 * \brief load message pointers from the server
1707 * \param servcmd the citadel command to send to the citserver
1708 * \param with_headers what headers???
1710 int load_msg_ptrs(char *servcmd, int with_headers)
1721 int num_summ_alloc = 0;
1723 if (WC->summ != NULL) {
1728 num_summ_alloc = 100;
1730 WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
1733 maxload = sizeof(WC->msgarr) / sizeof(long) ;
1735 serv_getln(buf, sizeof buf);
1736 if (buf[0] != '1') {
1737 wprintf("<EM>%s</EM><br />\n", &buf[4]);
1740 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1741 if (nummsgs < maxload) {
1742 WC->msgarr[nummsgs] = extract_long(buf, 0);
1743 datestamp = extract_long(buf, 1);
1744 extract_token(fullname, buf, 2, '|', sizeof fullname);
1745 extract_token(nodename, buf, 3, '|', sizeof nodename);
1746 extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
1747 extract_token(subject, buf, 5, '|', sizeof subject);
1751 if (nummsgs > num_summ_alloc) {
1752 num_summ_alloc *= 2;
1753 WC->summ = realloc(WC->summ,
1754 num_summ_alloc * sizeof(struct message_summary));
1758 memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
1759 WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
1760 safestrncpy(WC->summ[nummsgs-1].subj,
1761 _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
1762 if (strlen(fullname) > 0) {
1763 safestrncpy(WC->summ[nummsgs-1].from,
1764 fullname, sizeof WC->summ[nummsgs-1].from);
1766 if (strlen(subject) > 0) {
1767 safestrncpy(WC->summ[nummsgs-1].subj, subject,
1768 sizeof WC->summ[nummsgs-1].subj);
1771 /** Handle subjects with RFC2047 encoding */
1772 utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
1774 if (strlen(WC->summ[nummsgs-1].subj) > 75) {
1775 strcpy(&WC->summ[nummsgs-1].subj[72], "...");
1778 if (strlen(nodename) > 0) {
1779 if ( ((WC->room_flags & QR_NETWORK)
1780 || ((strcasecmp(nodename, serv_info.serv_nodename)
1781 && (strcasecmp(nodename, serv_info.serv_fqdn)))))
1783 strcat(WC->summ[nummsgs-1].from, " @ ");
1784 strcat(WC->summ[nummsgs-1].from, nodename);
1788 WC->summ[nummsgs-1].date = datestamp;
1791 /** Handle senders with RFC2047 encoding */
1792 utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
1794 if (strlen(WC->summ[nummsgs-1].from) > 25) {
1795 strcpy(&WC->summ[nummsgs-1].from[22], "...");
1804 * \brief compare what????
1805 * \param s1 first thing to compare
1806 * \param s2 second thing to compare
1808 int longcmp_r(const void *s1, const void *s2) {
1815 if (l1 > l2) return(-1);
1816 if (l1 < l2) return(+1);
1822 * \brief compare what????
1823 * \param s1 first thing to compare
1824 * \param s2 second thing to compare
1826 int summcmp_subj(const void *s1, const void *s2) {
1827 struct message_summary *summ1;
1828 struct message_summary *summ2;
1830 summ1 = (struct message_summary *)s1;
1831 summ2 = (struct message_summary *)s2;
1832 return strcasecmp(summ1->subj, summ2->subj);
1836 * \brief compare what????
1837 * \param s1 first thing to compare
1838 * \param s2 second thing to compare
1840 int summcmp_rsubj(const void *s1, const void *s2) {
1841 struct message_summary *summ1;
1842 struct message_summary *summ2;
1844 summ1 = (struct message_summary *)s1;
1845 summ2 = (struct message_summary *)s2;
1846 return strcasecmp(summ2->subj, summ1->subj);
1850 * \brief compare what????
1851 * \param s1 first thing to compare
1852 * \param s2 second thing to compare
1854 int summcmp_sender(const void *s1, const void *s2) {
1855 struct message_summary *summ1;
1856 struct message_summary *summ2;
1858 summ1 = (struct message_summary *)s1;
1859 summ2 = (struct message_summary *)s2;
1860 return strcasecmp(summ1->from, summ2->from);
1864 * \brief compare what????
1865 * \param s1 first thing to compare
1866 * \param s2 second thing to compare
1868 int summcmp_rsender(const void *s1, const void *s2) {
1869 struct message_summary *summ1;
1870 struct message_summary *summ2;
1872 summ1 = (struct message_summary *)s1;
1873 summ2 = (struct message_summary *)s2;
1874 return strcasecmp(summ2->from, summ1->from);
1878 * \brief compare what????
1879 * \param s1 first thing to compare
1880 * \param s2 second thing to compare
1882 int summcmp_date(const void *s1, const void *s2) {
1883 struct message_summary *summ1;
1884 struct message_summary *summ2;
1886 summ1 = (struct message_summary *)s1;
1887 summ2 = (struct message_summary *)s2;
1889 if (summ1->date < summ2->date) return -1;
1890 else if (summ1->date > summ2->date) return +1;
1895 * \brief compare what????
1896 * \param s1 first thing to compare
1897 * \param s2 second thing to compare
1899 int summcmp_rdate(const void *s1, const void *s2) {
1900 struct message_summary *summ1;
1901 struct message_summary *summ2;
1903 summ1 = (struct message_summary *)s1;
1904 summ2 = (struct message_summary *)s2;
1906 if (summ1->date < summ2->date) return +1;
1907 else if (summ1->date > summ2->date) return -1;
1912 * \brief command loop for reading messages
1913 * \param oper what???
1915 void readloop(char *oper)
1924 long *displayed_msgs = NULL;
1925 int num_displayed = 0;
1927 int is_addressbook = 0;
1928 int is_singlecard = 0;
1929 int is_calendar = 0;
1934 int lowest_displayed = (-1);
1935 int highest_displayed = 0;
1936 struct addrbookent *addrbook = NULL;
1938 char *sortby = NULL;
1939 char sortpref_name[128];
1940 char sortpref_value[128];
1941 char *subjsort_button;
1942 char *sendsort_button;
1943 char *datesort_button;
1944 int bbs_reverse = 0;
1946 if (WC->wc_view == VIEW_WIKI) {
1947 sprintf(buf, "wiki?room=%s?page=home", WC->wc_roomname);
1952 startmsg = atol(bstr("startmsg"));
1953 maxmsgs = atoi(bstr("maxmsgs"));
1954 is_summary = atoi(bstr("summary"));
1955 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1957 snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WC->wc_roomname);
1958 get_preference(sortpref_name, sortpref_value, sizeof sortpref_value);
1960 sortby = bstr("sortby");
1961 if ( (strlen(sortby) > 0) && (strcasecmp(sortby, sortpref_value)) ) {
1962 set_preference(sortpref_name, sortby, 1);
1964 if (strlen(sortby) == 0) sortby = sortpref_value;
1967 if (strlen(sortby) == 0) sortby = "rdate";
1969 /** message board sort */
1970 if (!strcasecmp(sortby, "reverse")) {
1977 output_headers(1, 1, 1, 0, 0, 0);
1980 * When in summary mode, always show ALL messages instead of just
1981 * new or old. Otherwise, show what the user asked for.
1983 if (!strcmp(oper, "readnew")) {
1984 strcpy(cmd, "MSGS NEW");
1986 else if (!strcmp(oper, "readold")) {
1987 strcpy(cmd, "MSGS OLD");
1990 strcpy(cmd, "MSGS ALL");
1993 if ((WC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) {
1995 strcpy(cmd, "MSGS ALL");
1998 if ((WC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2000 strcpy(cmd, "MSGS ALL");
2005 strcpy(cmd, "MSGS ALL|||1"); /**< fetch header summary */
2011 * Are we doing a summary view? If so, we need to know old messages
2012 * and new messages, so we can do that pretty boldface thing for the
2015 strcpy(old_msgs, "");
2018 serv_getln(buf, sizeof buf);
2019 if (buf[0] == '2') {
2020 strcpy(old_msgs, &buf[4]);
2024 is_singlecard = atoi(bstr("is_singlecard"));
2026 if (WC->wc_view == VIEW_CALENDAR) { /**< calendar */
2028 strcpy(cmd, "MSGS ALL");
2031 if (WC->wc_view == VIEW_TASKS) { /**< tasks */
2033 strcpy(cmd, "MSGS ALL");
2036 if (WC->wc_view == VIEW_NOTES) { /**< notes */
2038 strcpy(cmd, "MSGS ALL");
2042 nummsgs = load_msg_ptrs(cmd, is_summary);
2045 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2047 if (!strcmp(oper, "readnew")) {
2048 wprintf(_("No new messages."));
2049 } else if (!strcmp(oper, "readold")) {
2050 wprintf(_("No old messages."));
2052 wprintf(_("No messages here."));
2061 for (a = 0; a < nummsgs; ++a) {
2062 /** Are you a new message, or an old message? */
2064 if (is_msg_in_mset(old_msgs, WC->msgarr[a])) {
2065 WC->summ[a].is_new = 0;
2068 WC->summ[a].is_new = 1;
2074 if (startmsg == 0L) {
2076 startmsg = WC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2079 startmsg = WC->msgarr[0];
2084 if (!strcasecmp(sortby, "subject")) {
2085 qsort(WC->summ, WC->num_summ,
2086 sizeof(struct message_summary), summcmp_subj);
2088 else if (!strcasecmp(sortby, "rsubject")) {
2089 qsort(WC->summ, WC->num_summ,
2090 sizeof(struct message_summary), summcmp_rsubj);
2092 else if (!strcasecmp(sortby, "sender")) {
2093 qsort(WC->summ, WC->num_summ,
2094 sizeof(struct message_summary), summcmp_sender);
2096 else if (!strcasecmp(sortby, "rsender")) {
2097 qsort(WC->summ, WC->num_summ,
2098 sizeof(struct message_summary), summcmp_rsender);
2100 else if (!strcasecmp(sortby, "date")) {
2101 qsort(WC->summ, WC->num_summ,
2102 sizeof(struct message_summary), summcmp_date);
2104 else if (!strcasecmp(sortby, "rdate")) {
2105 qsort(WC->summ, WC->num_summ,
2106 sizeof(struct message_summary), summcmp_rdate);
2110 if (!strcasecmp(sortby, "subject")) {
2111 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsubject\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2113 else if (!strcasecmp(sortby, "rsubject")) {
2114 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2117 subjsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=subject\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2120 if (!strcasecmp(sortby, "sender")) {
2121 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rsender\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2123 else if (!strcasecmp(sortby, "rsender")) {
2124 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2127 sendsort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=sender\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2130 if (!strcasecmp(sortby, "date")) {
2131 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/down_pointer.gif\" /></a>" ;
2133 else if (!strcasecmp(sortby, "rdate")) {
2134 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=date\"><img border=\"0\" src=\"static/up_pointer.gif\" /></a>" ;
2137 datesort_button = "<a href=\"readfwd?startmsg=1?maxmsgs=9999999?summary=1?sortby=rdate\"><img border=\"0\" src=\"static/sort_none.gif\" /></a>" ;
2141 wprintf("</div>\n"); /** end of 'content' div */
2143 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2144 " document.onkeydown = CtdlMsgListKeyPress; "
2145 " if (document.layers) { "
2146 " document.captureEvents(Event.KEYPRESS); "
2151 /** note that Date and Delete are now in the same column */
2152 wprintf("<div id=\"message_list_hdr\">"
2153 "<div class=\"fix_scrollbar_bug\">"
2154 "<table cellspacing=0 style=\"width:100%%\">"
2157 wprintf("<td width=%d%%><b><i>%s</i></b> %s</td>"
2158 "<td width=%d%%><b><i>%s</i></b> %s</td>"
2159 "<td width=%d%%><b><i>%s</i></b> %s"
2161 "<input type=\"submit\" name=\"delete_button\" style=\"font-size:6pt\" "
2162 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2168 _("Subject"), subjsort_button,
2169 SENDER_COL_WIDTH_PCT,
2170 _("Sender"), sendsort_button,
2171 DATE_PLUS_BUTTONS_WIDTH_PCT,
2172 _("Date"), datesort_button,
2175 wprintf("</table></div></div>\n");
2177 wprintf("<div id=\"message_list\">"
2179 "<div class=\"fix_scrollbar_bug\">\n"
2181 "<table class=\"mailbox_summary\" id=\"summary_headers\" rules=rows "
2182 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2186 for (a = 0; a < nummsgs; ++a) {
2187 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
2189 /** Display the message */
2191 display_summarized(a);
2193 else if (is_addressbook) {
2194 fetch_ab_name(WC->msgarr[a], buf);
2196 addrbook = realloc(addrbook,
2197 (sizeof(struct addrbookent) * num_ab) );
2198 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2199 sizeof(addrbook[num_ab-1].ab_name));
2200 addrbook[num_ab-1].ab_msgnum = WC->msgarr[a];
2202 else if (is_calendar) {
2203 display_calendar(WC->msgarr[a]);
2205 else if (is_tasks) {
2206 display_task(WC->msgarr[a]);
2208 else if (is_notes) {
2209 display_note(WC->msgarr[a]);
2212 if (displayed_msgs == NULL) {
2213 displayed_msgs = malloc(sizeof(long) *
2214 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2216 displayed_msgs[num_displayed] = WC->msgarr[a];
2219 if (lowest_displayed < 0) lowest_displayed = a;
2220 highest_displayed = a;
2227 * Set the "is_bbview" variable if it appears that we are looking at
2228 * a classic bulletin board view.
2230 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2231 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2236 if (displayed_msgs != NULL) {
2238 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2241 /** if we do a split bbview in the future, begin messages div here */
2243 for (a=0; a<num_displayed; ++a) {
2244 read_message(displayed_msgs[a], 0, "");
2247 /** if we do a split bbview in the future, end messages div here */
2249 free(displayed_msgs);
2250 displayed_msgs = NULL;
2255 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2256 wprintf("</div>"); /**< end of 'message_list' div */
2258 /** Here's the grab-it-to-resize-the-message-list widget */
2259 wprintf("<div id=\"resize_msglist\" "
2260 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2261 "<div class=\"fix_scrollbar_bug\">"
2262 "<table width=100%% border=3 cellspacing=0 "
2263 "bgcolor=\"#cccccc\" "
2264 "cellpadding=0><TR><TD> </td></tr></table>"
2268 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2272 * Bump these because although we're thinking in zero base, the user
2273 * is a drooling idiot and is thinking in one base.
2276 ++highest_displayed;
2279 * If we're not currently looking at ALL requested
2280 * messages, then display the selector bar
2283 /** begin bbview scroller */
2284 wprintf("<form name=\"msgomatic\">");
2285 wprintf(_("Reading #"), lowest_displayed, highest_displayed);
2287 wprintf("<select name=\"whichones\" size=\"1\" "
2288 "OnChange=\"location.href=msgomatic.whichones.options"
2289 "[selectedIndex].value\">\n");
2292 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2294 lo = b - maxmsgs + 2;
2296 wprintf("<option %s value="
2301 "%d-%d</option> \n",
2302 ((WC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2311 for (b=0; b<nummsgs; b = b + maxmsgs) {
2313 hi = b + maxmsgs + 1;
2314 if (hi > nummsgs) hi = nummsgs;
2315 wprintf("<option %s value="
2320 "%d-%d</option> \n",
2321 ((WC->msgarr[b] == startmsg) ? "selected" : ""),
2330 wprintf("<option value=\"%s?startmsg=%ld"
2331 "?maxmsgs=9999999?summary=%d\">"
2335 WC->msgarr[0], is_summary);
2337 wprintf("</select> ");
2338 wprintf(_("of %d messages."), nummsgs);
2340 /** forward/reverse */
2341 wprintf(" <select name=\"direction\" size=\"1\" "
2342 "OnChange=\"location.href=msgomatic.direction.options"
2343 "[selectedIndex].value\">\n"
2346 wprintf("<option %s value=\"%s?sortby=forward\">oldest to newest</option>\n",
2347 (bbs_reverse ? "" : "selected"),
2351 wprintf("<option %s value=\"%s?sortby=reverse\">newest to oldest</option>\n",
2352 (bbs_reverse ? "selected" : ""),
2356 wprintf("</select></form>\n");
2357 /** end bbview scroller */
2362 do_tasks_view(); /** Render the task list */
2366 do_calendar_view(); /** Render the calendar */
2369 if (is_addressbook) {
2370 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2373 /** Note: wDumpContent() will output one additional </div> tag. */
2375 if (addrbook != NULL) free(addrbook);
2377 /** free the summary */
2378 if (WC->summ != NULL) {
2387 * \brief Back end for post_message()
2388 * ... this is where the actual message gets transmitted to the server.
2390 void post_mime_to_server(void) {
2392 int is_multipart = 0;
2394 struct wc_attachment *att;
2396 size_t encoded_length;
2398 /** RFC2045 requires this, and some clients look for it... */
2399 serv_puts("MIME-Version: 1.0");
2401 /** If there are attachments, we have to do multipart/mixed */
2402 if (WC->first_attachment != NULL) {
2407 sprintf(boundary, "---Citadel-Multipart-%s-%04x%04x---",
2408 serv_info.serv_fqdn,
2413 /** Remember, serv_printf() appends an extra newline */
2414 serv_printf("Content-type: multipart/mixed; "
2415 "boundary=\"%s\"\n", boundary);
2416 serv_printf("This is a multipart message in MIME format.\n");
2417 serv_printf("--%s", boundary);
2420 serv_puts("Content-type: text/html; charset=utf-8");
2422 serv_puts("<html><body>\n"); /** Future templates go here */
2423 text_to_server(bstr("msgtext"), 0);
2424 serv_puts("</body></html>\n");
2429 /** Add in the attachments */
2430 for (att = WC->first_attachment; att!=NULL; att=att->next) {
2432 encoded_length = ((att->length * 150) / 100);
2433 encoded = malloc(encoded_length);
2434 if (encoded == NULL) break;
2435 CtdlEncodeBase64(encoded, att->data, att->length);
2437 serv_printf("--%s", boundary);
2438 serv_printf("Content-type: %s", att->content_type);
2439 serv_printf("Content-disposition: attachment; "
2440 "filename=\"%s\"", att->filename);
2441 serv_puts("Content-transfer-encoding: base64");
2443 serv_write(encoded, strlen(encoded));
2448 serv_printf("--%s--", boundary);
2456 * \brief Post message (or don't post message)
2458 * Note regarding the "dont_post" variable:
2459 * A random value (actually, it's just a timestamp) is inserted as a hidden
2460 * field called "postseq" when the display_enter page is generated. This
2461 * value is checked when posting, using the static variable dont_post. If a
2462 * user attempts to post twice using the same dont_post value, the message is
2463 * discarded. This prevents the accidental double-saving of the same message
2464 * if the user happens to click the browser "back" button.
2466 void post_message(void)
2469 static long dont_post = (-1L);
2470 struct wc_attachment *att, *aptr;
2471 int is_anonymous = 0;
2473 if (!strcasecmp(bstr("is_anonymous"), "yes")) {
2477 if (WC->upload_length > 0) {
2479 /** There's an attachment. Save it to this struct... */
2480 att = malloc(sizeof(struct wc_attachment));
2481 memset(att, 0, sizeof(struct wc_attachment));
2482 att->length = WC->upload_length;
2483 strcpy(att->content_type, WC->upload_content_type);
2484 strcpy(att->filename, WC->upload_filename);
2487 /** And add it to the list. */
2488 if (WC->first_attachment == NULL) {
2489 WC->first_attachment = att;
2492 aptr = WC->first_attachment;
2493 while (aptr->next != NULL) aptr = aptr->next;
2498 * Mozilla sends a simple filename, which is what we want,
2499 * but Satan's Browser sends an entire pathname. Reduce
2500 * the path to just a filename if we need to.
2502 while (num_tokens(att->filename, '/') > 1) {
2503 remove_token(att->filename, 0, '/');
2505 while (num_tokens(att->filename, '\\') > 1) {
2506 remove_token(att->filename, 0, '\\');
2510 * Transfer control of this memory from the upload struct
2511 * to the attachment struct.
2513 att->data = WC->upload;
2514 WC->upload_length = 0;
2520 if (strlen(bstr("cancel_button")) > 0) {
2521 sprintf(WC->ImportantMessage,
2522 _("Cancelled. Message was not posted."));
2523 } else if (strlen(bstr("attach_button")) > 0) {
2526 } else if (atol(bstr("postseq")) == dont_post) {
2527 sprintf(WC->ImportantMessage,
2528 _("Automatically cancelled because you have already "
2529 "saved this message."));
2531 sprintf(buf, "ENT0 1|%s|%d|4|%s|||%s|%s",
2539 serv_getln(buf, sizeof buf);
2540 if (buf[0] == '4') {
2541 post_mime_to_server();
2542 if ( (strlen(bstr("recp")) > 0)
2543 || (strlen(bstr("cc")) > 0)
2544 || (strlen(bstr("bcc")) > 0)
2546 sprintf(WC->ImportantMessage, _("Message has been sent.\n"));
2549 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2551 dont_post = atol(bstr("postseq"));
2553 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2559 free_attachments(WC);
2560 readloop("readnew");
2567 * \brief display the message entry screen
2569 void display_enter(void)
2574 struct wc_attachment *att;
2575 int recipient_required = 0;
2576 int recipient_bad = 0;
2578 int is_anonymous = 0;
2580 if (strlen(bstr("force_room")) > 0) {
2581 gotoroom(bstr("force_room"));
2584 if (!strcasecmp(bstr("is_anonymous"), "yes")) {
2589 * Are we perhaps in an address book view? If so, then an "enter
2590 * message" command really means "add new entry."
2592 if (WC->wc_view == VIEW_ADDRESSBOOK) {
2593 do_edit_vcard(-1, "", "");
2597 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
2599 * Are we perhaps in a calendar view? If so, then an "enter
2600 * message" command really means "add new calendar item."
2602 if (WC->wc_view == VIEW_CALENDAR) {
2603 display_edit_event();
2608 * Are we perhaps in a tasks view? If so, then an "enter
2609 * message" command really means "add new task."
2611 if (WC->wc_view == VIEW_TASKS) {
2612 display_edit_task();
2618 * Otherwise proceed normally.
2619 * Do a custom room banner with no navbar...
2621 output_headers(1, 1, 2, 0, 0, 0);
2622 wprintf("<div id=\"banner\">\n");
2623 embed_room_banner(NULL, navbar_none);
2624 wprintf("</div>\n");
2625 wprintf("<div id=\"content\">\n"
2626 "<div class=\"fix_scrollbar_bug\">"
2627 "<table width=100%% border=0 bgcolor=\"#ffffff\"><tr><td>");
2629 /** First test to see whether this is a room that requires recipients to be entered */
2630 serv_puts("ENT0 0");
2631 serv_getln(buf, sizeof buf);
2632 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
2633 recipient_required = 1;
2635 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2636 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2640 /** Now check our actual recipients if there are any */
2641 if (recipient_required) {
2642 sprintf(buf, "ENT0 0|%s|%d|0||||%s|%s", bstr("recp"), is_anonymous, bstr("cc"), bstr("bcc"));
2644 serv_getln(buf, sizeof buf);
2646 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
2647 if (strlen(bstr("recp")) + strlen(bstr("cc")) + strlen(bstr("bcc")) > 0) {
2651 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2652 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2657 /** If we got this far, we can display the message entry screen. */
2660 fmt_date(buf, now, 0);
2661 strcat(&buf[strlen(buf)], _(" <I>from</I> "));
2662 stresc(&buf[strlen(buf)], WC->wc_fullname, 1, 1);
2664 /* Don't need this anymore, it's in the input box below
2665 if (strlen(bstr("recp")) > 0) {
2666 strcat(&buf[strlen(buf)], _(" <I>to</I> "));
2667 stresc(&buf[strlen(buf)], bstr("recp"), 1, 1);
2671 strcat(&buf[strlen(buf)], _(" <I>in</I> "));
2672 stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
2674 /** begin message entry screen */
2675 wprintf("<form enctype=\"multipart/form-data\" "
2676 "method=\"POST\" action=\"post\" "
2677 "name=\"enterform\""
2679 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2681 wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
2682 wprintf("%s\n", buf); /** header bar */
2683 if (WC->room_flags & QR_ANONOPT) {
2685 "<input type=\"checkbox\" name=\"is_anonymous\" value=\"yes\" %s>",
2686 (is_anonymous ? "checked" : "")
2688 wprintf("Anonymous");
2690 wprintf("<br>\n"); /** header bar */
2692 wprintf("<table border=\"0\" width=\"100%%\">\n");
2693 if (recipient_required) {
2695 wprintf("<tr><td>");
2696 wprintf("<font size=-1>");
2700 "<input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
2701 escputs(bstr("recp"));
2702 wprintf("\" size=50 maxlength=1000 />");
2703 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
2704 wprintf("</td><td></td></tr>\n");
2706 wprintf("<tr><td>");
2707 wprintf("<font size=-1>");
2711 "<input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
2712 escputs(bstr("cc"));
2713 wprintf("\" size=50 maxlength=1000 />");
2714 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
2715 wprintf("</td><td></td></tr>\n");
2717 wprintf("<tr><td>");
2718 wprintf("<font size=-1>");
2722 "<input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
2723 escputs(bstr("bcc"));
2724 wprintf("\" size=50 maxlength=1000 />");
2725 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
2726 wprintf("</td><td></td></tr>\n");
2728 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
2729 wprintf("<script type=\"text/javascript\"> \n"
2730 " activate_entmsg_autocompleters(); \n"
2735 wprintf("<tr><td>");
2736 wprintf("<font size=-1>");
2737 wprintf(_("Subject (optional):"));
2740 "<input type=\"text\" name=\"subject\" value=\"");
2741 escputs(bstr("subject"));
2742 wprintf("\" size=50 maxlength=70></td><td>\n");
2744 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2745 if (recipient_required) {
2746 wprintf(_("Send message"));
2748 wprintf(_("Post message"));
2751 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2752 wprintf("</td></tr></table>\n");
2754 wprintf("<center>");
2756 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
2758 /** If we're continuing from a previous edit, put our partially-composed message back... */
2759 msgescputs(bstr("msgtext"));
2761 /* If we're forwarding a message, insert it here... */
2762 if (atol(bstr("fwdquote")) > 0L) {
2763 wprintf("<br><div align=center><i>");
2764 wprintf(_("--- forwarded message ---"));
2765 wprintf("</i></div><br>");
2766 pullquote_message(atol(bstr("fwdquote")), 1);
2769 /** If we're replying quoted, insert the quote here... */
2770 else if (atol(bstr("replyquote")) > 0L) {
2773 pullquote_message(atol(bstr("replyquote")), 0);
2774 wprintf("</blockquote>\n\n");
2777 /** Insert our signature if appropriate... */
2778 if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
2779 get_preference("use_sig", buf, sizeof buf);
2780 if (!strcasecmp(buf, "yes")) {
2781 get_preference("signature", ebuf, sizeof ebuf);
2782 euid_unescapize(buf, ebuf);
2783 wprintf("<br>--<br>");
2784 for (i=0; i<strlen(buf); ++i) {
2785 if (buf[i] == '\n') {
2788 else if (buf[i] == '<') {
2791 else if (buf[i] == '>') {
2794 else if (buf[i] == '&') {
2797 else if (buf[i] == '\"') {
2800 else if (buf[i] == '\'') {
2803 else if (isprint(buf[i])) {
2804 wprintf("%c", buf[i]);
2810 wprintf("</textarea>");
2811 wprintf("</center><br />\n");
2814 * The following script embeds the TinyMCE richedit control, and automatically
2815 * transforms the textarea into a richedit textarea.
2818 "<script language=\"javascript\" type=\"text/javascript\" src=\"tiny_mce/tiny_mce.js\"></script>\n"
2819 "<script language=\"javascript\" type=\"text/javascript\">"
2821 " mode : \"textareas\", width : \"100%%\", browsers : \"msie,gecko\", "
2822 " theme : \"advanced\", plugins : \"iespell\", "
2823 " theme_advanced_buttons1 : \"bold, italic, underline, strikethrough, justifyleft, justifycenter, justifyright, justifyfull, bullist, numlist, cut, copy, paste, link, image, help, forecolor, iespell, code\", "
2824 " theme_advanced_buttons2 : \"\", "
2825 " theme_advanced_buttons3 : \"\" "
2831 /** Enumerate any attachments which are already in place... */
2832 wprintf("<img src=\"static/diskette_24x.gif\" border=0 "
2833 "align=middle height=16 width=16> ");
2834 wprintf(_("Attachments:"));
2836 wprintf("<select name=\"which_attachment\" size=1>");
2837 for (att = WC->first_attachment; att != NULL; att = att->next) {
2838 wprintf("<option value=\"");
2839 urlescputs(att->filename);
2841 escputs(att->filename);
2842 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
2843 wprintf("</option>\n");
2845 wprintf("</select>");
2847 /** Now offer the ability to attach additional files... */
2848 wprintf(" ");
2849 wprintf(_("Attach file:"));
2850 wprintf(" <input NAME=\"attachfile\" "
2851 "SIZE=16 TYPE=\"file\">\n "
2852 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
2854 /** Seth asked for these to be at the top *and* bottom... */
2855 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2856 if (recipient_required) {
2857 wprintf(_("Send message"));
2859 wprintf(_("Post message"));
2862 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2864 /** Make sure we only insert our signature once */
2865 if (strcmp(bstr("sig_inserted"), "yes")) {
2866 wprintf("<INPUT TYPE=\"hidden\" NAME=\"sig_inserted\" VALUE=\"yes\">\n");
2869 wprintf("</form>\n");
2871 wprintf("</td></tr></table></div>\n");
2872 DONE: wDumpContent(1);
2878 * \brief delete a message
2880 void delete_msg(void)
2885 msgid = atol(bstr("msgid"));
2887 output_headers(1, 1, 1, 0, 0, 0);
2889 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
2890 serv_printf("DELE %ld", msgid);
2892 else { /** Otherwise move it to Trash */
2893 serv_printf("MOVE %ld|_TRASH_|0", msgid);
2896 serv_getln(buf, sizeof buf);
2897 wprintf("<EM>%s</EM><br />\n", &buf[4]);
2906 * \brief Confirm move of a message
2908 void confirm_move_msg(void)
2914 msgid = atol(bstr("msgid"));
2917 output_headers(1, 1, 2, 0, 0, 0);
2918 wprintf("<div id=\"banner\">\n");
2919 wprintf("<TABLE WIDTH=100%% BORDER=0><TR><TD>");
2920 wprintf("<SPAN CLASS=\"titlebar\">");
2921 wprintf(_("Confirm move of message"));
2922 wprintf("</SPAN>\n");
2923 wprintf("</TD></TR></TABLE>\n");
2924 wprintf("</div>\n<div id=\"content\">\n");
2926 wprintf("<CENTER>");
2928 wprintf(_("Move this message to:"));
2929 wprintf("<br />\n");
2931 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
2932 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
2934 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
2936 serv_getln(buf, sizeof buf);
2937 if (buf[0] == '1') {
2938 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2939 extract_token(targ, buf, 0, '|', sizeof targ);
2940 wprintf("<OPTION>");
2945 wprintf("</SELECT>\n");
2946 wprintf("<br />\n");
2948 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
2950 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
2951 wprintf("</form></CENTER>\n");
2953 wprintf("</CENTER>\n");
2959 * \brief move a message to another folder
2966 msgid = atol(bstr("msgid"));
2968 if (strlen(bstr("move_button")) > 0) {
2969 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
2971 serv_getln(buf, sizeof buf);
2972 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2974 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
2977 readloop("readnew");