4 * Functions which deal with the fetching and displaying of messages.
12 HashList *MsgHeaderHandler = NULL;
13 HashList *MsgEvaluators = NULL;
14 HashList *MimeRenderHandler = NULL;
16 #define SUBJ_COL_WIDTH_PCT 50 /**< Mailbox view column width */
17 #define SENDER_COL_WIDTH_PCT 30 /**< Mailbox view column width */
18 #define DATE_PLUS_BUTTONS_WIDTH_PCT 20 /**< Mailbox view column width */
22 void display_enter(void);
23 int longcmp_r(const void *s1, const void *s2);
24 int summcmp_subj(const void *s1, const void *s2);
25 int summcmp_rsubj(const void *s1, const void *s2);
26 int summcmp_sender(const void *s1, const void *s2);
27 int summcmp_rsender(const void *s1, const void *s2);
28 int summcmp_date(const void *s1, const void *s2);
29 int summcmp_rdate(const void *s1, const void *s2);
31 /*----------------------------------------------------------------------------*/
34 typedef void (*MsgPartEvaluatorFunc)(message_summary *Sum, StrBuf *Buf);
38 /*----------------------------------------------------------------------------*/
43 * I wanna SEE that message!
45 * msgnum Message number to display
46 * printable_view Nonzero to display a printable view
47 * section Optional for encapsulated message/rfc822 submessage
49 int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, int printable_view, const StrBuf *PartNum) {
55 message_summary *Msg = NULL;
59 // char mime_submessages[256] = "";
60 char reply_references[1024] = "";
67 lprintf(1, "----------%s---------MSG4 %ld|%s--------------\n", tmpl, msgnum, ChrPtr(PartNum));
68 serv_printf("MSG4 %ld|%s", msgnum, ChrPtr(PartNum));
69 StrBuf_ServGetln(Buf);
70 if (GetServerStatus(Buf, NULL) != 1) {
71 StrBufAppendPrintf(Target, "<strong>");
72 StrBufAppendPrintf(Target, _("ERROR:"));
73 StrBufAppendPrintf(Target, "</strong> %s<br />\n", &buf[4]);
78 /** begin everythingamundo table */
81 HdrToken = NewStrBuf();
82 Msg = (message_summary *)malloc(sizeof(message_summary));
83 memset(Msg, 0, sizeof(message_summary));
85 Msg->PartNum = PartNum;
86 Msg->MsgBody = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
87 memset(Msg->MsgBody, 0, sizeof(wc_mime_attachment));
88 FoundCharset = NewStrBuf();
89 while ((StrBuf_ServGetln(Buf)>=0) && !Done) {
90 if ( (StrLength(Buf)==3) &&
91 !strcmp(ChrPtr(Buf), "000"))
95 lprintf(1, _("unexpected end of message"));
97 Msg->MsgBody->ContentType = NewStrBufPlain(HKEY("text/html"));
98 StrBufAppendPrintf(Msg->MsgBody->Data, "<div><i>");
99 StrBufAppendPrintf(Msg->MsgBody->Data, _("unexpected end of message"));
100 StrBufAppendPrintf(Msg->MsgBody->Data, " (1)</i><br /><br />\n");
101 StrBufAppendPrintf(Msg->MsgBody->Data, "</div>\n");
106 case 0:/* Citadel Message Headers */
107 if (StrLength(Buf) == 0) {
111 StrBufExtract_token(HdrToken, Buf, 0, '=');
112 StrBufCutLeft(Buf, StrLength(HdrToken) + 1);
114 lprintf(1, ":: [%s] = [%s]\n", ChrPtr(HdrToken), ChrPtr(Buf));
115 if (GetHash(MsgHeaderHandler, SKEY(HdrToken), &vHdr) &&
117 Hdr = (headereval*)vHdr;
118 Hdr->evaluator(Msg, Buf, FoundCharset);
119 if (Hdr->Type == 1) {
123 else lprintf(1, "don't know how to handle message header[%s]\n", ChrPtr(HdrToken));
125 case 1:/* Message Mime Header */
126 if (StrLength(Buf) == 0) {
128 if (Msg->MsgBody->ContentType == NULL)
129 /* end of header or no header? */
130 Msg->MsgBody->ContentType = NewStrBufPlain(HKEY("text/plain"));
131 /* usual end of mime header */
135 StrBufExtract_token(HdrToken, Buf, 0, ':');
136 if (StrLength(HdrToken) > 0) {
137 StrBufCutLeft(Buf, StrLength(HdrToken) + 1);
138 lprintf(1, ":: [%s] = [%s]\n", ChrPtr(HdrToken), ChrPtr(Buf));
139 if (GetHash(MsgHeaderHandler, SKEY(HdrToken), &vHdr) &&
141 Hdr = (headereval*)vHdr;
142 Hdr->evaluator(Msg, Buf, FoundCharset);
147 case 2: /* Message Body */
149 if (Msg->MsgBody->size_known > 0) {
150 StrBuf_ServGetBLOB(Msg->MsgBody->Data, Msg->MsgBody->length);
152 /// todo: check next line, if not 000, append following lines
155 if (StrLength(Msg->MsgBody->Data) > 0)
156 StrBufAppendBufPlain(Msg->MsgBody->Data, "\n", 1, 0);
157 StrBufAppendBuf(Msg->MsgBody->Data, Buf, 0);
161 StrBufAppendBuf(Msg->MsgBody->Data, Buf, 0);
166 if (Msg->AllAttach == NULL)
167 Msg->AllAttach = NewHash(1,NULL);
168 Put(Msg->AllAttach, SKEY(Msg->MsgBody->PartNum), Msg->MsgBody, DestroyMime);
170 /* strip the bare contenttype, so we ommit charset etc. */
171 StrBufExtract_token(Buf, Msg->MsgBody->ContentType, 0, ';');
173 if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
175 RenderMimeFunc Render;
176 Render = (RenderMimeFunc)vHdr;
177 Render(Msg->MsgBody, NULL, FoundCharset);
180 if (StrLength(Msg->reply_references)> 0) {
181 /* Trim down excessively long lists of thread references. We eliminate the
182 * second one in the list so that the thread root remains intact.
184 int rrtok = num_tokens(ChrPtr(Msg->reply_references), '|');
185 int rrlen = StrLength(Msg->reply_references);
186 if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
187 remove_token(reply_references, 1, '|');////todo
191 /* Generate a reply-to address */
192 if (StrLength(Msg->Rfca) > 0) {
193 if (Msg->reply_to == NULL)
194 Msg->reply_to = NewStrBuf();
195 if (StrLength(Msg->from) > 0) {
196 StrBufPrintf(Msg->reply_to, "%s <%s>", ChrPtr(Msg->from), ChrPtr(Msg->Rfca));
199 FlushStrBuf(Msg->reply_to);
200 StrBufAppendBuf(Msg->reply_to, Msg->Rfca, 0);
205 if ((StrLength(Msg->OtherNode)>0) &&
206 (strcasecmp(ChrPtr(Msg->OtherNode), serv_info.serv_nodename)) &&
207 (strcasecmp(ChrPtr(Msg->OtherNode), serv_info.serv_humannode)) )
209 if (Msg->reply_to == NULL)
210 Msg->reply_to = NewStrBuf();
211 StrBufPrintf(Msg->reply_to,
214 ChrPtr(Msg->OtherNode));
217 if (Msg->reply_to == NULL)
218 Msg->reply_to = NewStrBuf();
219 FlushStrBuf(Msg->reply_to);
220 StrBufAppendBuf(Msg->reply_to, Msg->from, 0);
223 it = GetNewHashPos(Msg->AllAttach, 0);
224 while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) &&
226 wc_mime_attachment *Mime = (wc_mime_attachment*) vMime;
227 evaluate_mime_part(Msg, Mime);
231 DoTemplate(tmpl, tmpllen, Target, Msg, CTX_MAILSUM);
233 DestroyMessageSummary(Msg);
234 FreeStrBuf(&FoundCharset);
235 FreeStrBuf(&HdrToken);
243 * Unadorned HTML output of an individual message, suitable
244 * for placing in a hidden iframe, for printing, or whatever
246 * msgnum_as_string == Message number, as a string instead of as a long int
248 void embed_message(void) {
250 const StrBuf *Tmpl = sbstr("template");
252 msgnum = StrTol(WC->UrlFragment1);
253 if (StrLength(Tmpl) > 0)
254 read_message(WC->WBuf, SKEY(Tmpl), msgnum, 0, NULL);
256 read_message(WC->WBuf, HKEY("view_message"), msgnum, 0, NULL);
261 * Printable view of a message
263 * msgnum_as_string == Message number, as a string instead of as a long int
265 void print_message(void) {
268 msgnum = StrTol(WC->UrlFragment1);
269 output_headers(0, 0, 0, 0, 0, 0);
271 hprintf("Content-type: text/html\r\n"
272 "Server: " PACKAGE_STRING "\r\n"
273 "Connection: close\r\n");
277 read_message(WC->WBuf, HKEY("view_message_print"), msgnum, 1, NULL);
283 * Mobile browser view of message
285 * @param msg_num_as_string Message number as a string instead of as a long int
287 void mobile_message_view(void) {
289 msgnum = StrTol(WC->UrlFragment1);
290 output_headers(1, 0, 0, 0, 0, 1);
292 do_template("msgcontrols", NULL);
293 read_message(WC->WBuf, HKEY("view_message"), msgnum,1, NULL);
298 * \brief Display a message's headers
300 * \param msgnum_as_string Message number, as a string instead of as a long int
302 void display_headers(void) {
306 msgnum = StrTol(WC->UrlFragment1);
307 output_headers(0, 0, 0, 0, 0, 0);
309 hprintf("Content-type: text/plain\r\n"
311 "Connection: close\r\n",
315 serv_printf("MSG2 %ld|3", msgnum);
316 serv_getln(buf, sizeof buf);
318 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
319 wprintf("%s\n", buf);
329 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
330 * or 'reply quoted' operations.
332 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
333 * in this function. Doing so would throw a JavaScript error in the
334 * 'supplied text' argument to the editor.
336 * \param msgnum Message number of the message we want to quote
337 * \param forward_attachments Nonzero if we want attachments to be forwarded
339 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
340 struct wcsession *WCC = WC;
342 char mime_partnum[256];
343 char mime_filename[256];
344 char mime_content_type[256];
345 char mime_charset[256];
346 char mime_disposition[256];
348 char *attachments = NULL;
350 int num_attachments = 0;
352 char m_subject[1024];
364 iconv_t ic = (iconv_t)(-1) ;
365 char *ibuf; /**< Buffer of characters to be converted */
366 char *obuf; /**< Buffer for converted characters */
367 size_t ibuflen; /**< Length of input buffer */
368 size_t obuflen; /**< Length of output buffer */
369 char *osav; /**< Saved pointer to output buffer */
375 strcpy(reply_to, "");
376 strcpy(mime_content_type, "text/plain");
377 strcpy(mime_charset, "us-ascii");
379 serv_printf("MSG4 %ld", msgnum);
380 serv_getln(buf, sizeof buf);
382 wprintf(_("ERROR:"));
383 wprintf("%s<br />", &buf[4]);
387 strcpy(m_subject, "");
389 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
390 if (!strcmp(buf, "000")) {
391 wprintf("%s (3)", _("unexpected end of message"));
394 if (include_headers) {
395 if (!strncasecmp(buf, "nhdr=yes", 8))
399 if (!strncasecmp(buf, "type=", 5))
400 format_type = atoi(&buf[5]);
401 if (!strncasecmp(buf, "from=", 5)) {
402 strcpy(from, &buf[5]);
404 utf8ify_rfc822_string(from);
407 if (!strncasecmp(buf, "subj=", 5)) {
408 strcpy(m_subject, &buf[5]);
410 if ((!strncasecmp(buf, "hnod=", 5))
411 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
412 wprintf("(%s) ", &buf[5]);
414 if ((!strncasecmp(buf, "room=", 5))
415 && (strcasecmp(&buf[5], WC->wc_roomname))
416 && (!IsEmptyStr(&buf[5])) ) {
418 wprintf("%s> ", &buf[5]);
420 if (!strncasecmp(buf, "rfca=", 5)) {
421 strcpy(rfca, &buf[5]);
426 if (!strncasecmp(buf, "node=", 5)) {
427 strcpy(node, &buf[5]);
428 if ( ((WC->room_flags & QR_NETWORK)
429 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
430 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
431 && (IsEmptyStr(rfca))
433 wprintf("@%s ", &buf[5]);
436 if (!strncasecmp(buf, "rcpt=", 5)) {
439 utf8ify_rfc822_string(to);
442 if (!strncasecmp(buf, "time=", 5)) {
443 webcit_fmt_date(now, atol(&buf[5]), 0);
449 * Save attachment info for later. We can't start downloading them
450 * yet because we're in the middle of a server transaction.
452 if (!strncasecmp(buf, "part=", 5)) {
453 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
456 sprintf(ptr, "%s%s\n",
457 ((attachments != NULL) ? attachments : ""),
462 lprintf(9, "attachments=<%s>\n", attachments);
468 if (include_headers) {
471 utf8ify_rfc822_string(m_subject);
472 if (!IsEmptyStr(m_subject)) {
473 wprintf(_("Subject:"));
475 msgescputs(m_subject);
486 * Learn the content type
488 strcpy(mime_content_type, "text/plain");
489 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
490 if (!strcmp(buf, "000")) {
491 wprintf("%s (4)", _("unexpected end of message"));
494 if (!strncasecmp(buf, "Content-type: ", 14)) {
496 safestrncpy(mime_content_type, &buf[14],
497 sizeof(mime_content_type));
498 for (i=0; i<strlen(mime_content_type); ++i) {
499 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
500 safestrncpy(mime_charset, &mime_content_type[i+8],
501 sizeof mime_charset);
504 len = strlen(mime_content_type);
505 for (i=0; i<len; ++i) {
506 if (mime_content_type[i] == ';') {
507 mime_content_type[i] = 0;
511 len = strlen(mime_charset);
512 for (i=0; i<len; ++i) {
513 if (mime_charset[i] == ';') {
521 /** Set up a character set conversion if we need to (and if we can) */
523 if ( (strcasecmp(mime_charset, "us-ascii"))
524 && (strcasecmp(mime_charset, "UTF-8"))
525 && (strcasecmp(mime_charset, ""))
527 ctdl_iconv_open("UTF-8", mime_charset, &ic);
528 if (ic == (iconv_t)(-1) ) {
529 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
530 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
535 /** Messages in legacy Citadel variformat get handled thusly... */
536 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
540 /* Boring old 80-column fixed format text gets handled this way... */
541 else if (!strcasecmp(mime_content_type, "text/plain")) {
542 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
545 if ((len > 0) && (buf[len-1] == '\n')) buf[--len] = 0;
546 if ((len > 0) && (buf[len-1] == '\r')) buf[--len] = 0;
549 if (ic != (iconv_t)(-1) ) {
553 obuf = (char *) malloc(obuflen);
555 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
556 osav[SIZ-obuflen] = 0;
557 safestrncpy(buf, osav, sizeof buf);
563 while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
566 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
567 wprintf("<blockquote>");
569 } else if ((bq == 1) &&
570 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
571 wprintf("</blockquote>");
575 url(buf, sizeof(buf));
577 wprintf("</tt><br />");
579 wprintf("</i><br />");
582 /** HTML just gets escaped and stuffed back into the editor */
583 else if (!strcasecmp(mime_content_type, "text/html")) {
584 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
588 }//// TODO: charset? utf8?
590 /** Unknown weirdness ... don't know how to handle this content type */
592 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
596 /** end of body handler */
599 * If there were attachments, we have to download them and insert them
600 * into the attachment chain for the forwarded message we are composing.
602 if ( (forward_attachments) && (num_attachments) ) {
603 for (i=0; i<num_attachments; ++i) {
604 extract_token(buf, attachments, i, '\n', sizeof buf);
605 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
606 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
607 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
608 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
609 mime_length = extract_int(buf, 5);
612 * tracing ... uncomment if necessary
615 lprintf(9, "fwd filename: %s\n", mime_filename);
616 lprintf(9, "fwd partnum : %s\n", mime_partnum);
617 lprintf(9, "fwd conttype: %s\n", mime_content_type);
618 lprintf(9, "fwd dispose : %s\n", mime_disposition);
619 lprintf(9, "fwd length : %d\n", mime_length);
621 if ( (!strcasecmp(mime_disposition, "inline"))
622 || (!strcasecmp(mime_disposition, "attachment")) ) {
626 /* Create an attachment struct from this mime part... */
627 att = malloc(sizeof(wc_attachment));
628 memset(att, 0, sizeof(wc_attachment));
629 att->length = mime_length;
630 att->content_type = NewStrBufPlain(mime_content_type, -1);
631 att->filename = NewStrBufPlain(mime_filename, -1);
632 att->data = load_mimepart(msgnum, mime_partnum);
634 if (WCC->attachments == NULL)
635 WCC->attachments = NewHash(1, NULL);
636 /* And add it to the list. */
637 n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
638 Put(WCC->attachments, N, n, att, free_attachment);
645 if (ic != (iconv_t)(-1) ) {
650 if (attachments != NULL) {
658 message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSubject, long MsgNum)
661 MsgPartEvaluatorFunc Eval;
662 message_summary *Msg;
671 serv_printf("MSG0 %ld|1", MsgNum); /* ask for headers only */
673 StrBuf_ServGetln(Buf);
674 if (GetServerStatus(Buf, NULL) == 1) {
679 Msg = (message_summary*)malloc(sizeof(message_summary));
680 memset(Msg, 0, sizeof(message_summary));
681 while (len = StrBuf_ServGetln(Buf),
683 strcmp(ChrPtr(Buf), "000")== 0)){
685 ebuf = strchr(ChrPtr(Buf), '=');
687 if (GetHash(MsgEvaluators, buf, nBuf, &vEval) && vEval != NULL) {
688 Eval = (MsgPartEvaluatorFunc) vEval;
689 StrBufCutLeft(Buf, nBuf + 1);
692 else lprintf(1, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
699 * \brief display the adressbook overview
700 * \param msgnum the citadel message number
701 * \param alpha what????
703 void display_addressbook(long msgnum, char alpha) {
705 /* char mime_partnum[SIZ]; */
706 /* char mime_filename[SIZ]; */
707 /* char mime_content_type[SIZ]; */
708 ///char mime_disposition[SIZ];
710 char vcard_partnum[SIZ];
711 char *vcard_source = NULL;
712 message_summary summ;////TODO: this will leak
714 memset(&summ, 0, sizeof(summ));
715 ///safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
716 ///Load Message headers
718 if (!IsEmptyStr(vcard_partnum)) {
719 vcard_source = load_mimepart(msgnum, vcard_partnum);
720 if (vcard_source != NULL) {
722 /** Display the summary line */
723 display_vcard(WC->WBuf, vcard_source, alpha, 0, NULL,msgnum);
725 /** If it's my vCard I can edit it */
726 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
727 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
728 || (WC->wc_view == VIEW_ADDRESSBOOK)
730 wprintf("<a href=\"edit_vcard?"
731 "msgnum=%ld&partnum=%s\">",
732 msgnum, vcard_partnum);
733 wprintf("[%s]</a>", _("edit"));
745 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
746 * \param namebuf name to analyze, reverse if nescessary
748 void lastfirst_firstlast(char *namebuf) {
753 if (namebuf == NULL) return;
754 if (strchr(namebuf, ';') != NULL) return;
756 i = num_tokens(namebuf, ' ');
759 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
760 remove_token(namebuf, i-1, ' ');
761 strcpy(firstname, namebuf);
762 sprintf(namebuf, "%s; %s", lastname, firstname);
766 * \brief fetch what??? name
767 * \param msgnum the citadel message number
768 * \param namebuf where to put the name in???
770 void fetch_ab_name(message_summary *Msg, char *namebuf) {
772 char mime_partnum[SIZ];
773 char mime_filename[SIZ];
774 char mime_content_type[SIZ];
775 char mime_disposition[SIZ];
777 char vcard_partnum[SIZ];
778 char *vcard_source = NULL;
780 message_summary summ;/// TODO this will lak
782 if (namebuf == NULL) return;
785 memset(&summ, 0, sizeof(summ));
786 //////safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
788 sprintf(buf, "MSG0 %ld|0", Msg->msgnum); /** unfortunately we need the mime info now */
790 serv_getln(buf, sizeof buf);
791 if (buf[0] != '1') return;
793 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
794 if (!strncasecmp(buf, "part=", 5)) {
795 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
796 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
797 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
798 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
799 mime_length = extract_int(&buf[5], 5);
801 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
802 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
803 strcpy(vcard_partnum, mime_partnum);
809 if (!IsEmptyStr(vcard_partnum)) {
810 vcard_source = load_mimepart(Msg->msgnum, vcard_partnum);
811 if (vcard_source != NULL) {
813 /* Grab the name off the card */
814 display_vcard(WC->WBuf, vcard_source, 0, 0, namebuf, Msg->msgnum);
820 lastfirst_firstlast(namebuf);
822 len = strlen(namebuf);
823 for (i=0; i<len; ++i) {
824 if (namebuf[i] != ';') return;
826 strcpy(namebuf, _("(no name)"));
834 * load message pointers from the server for a "read messages" operation
836 * servcmd: the citadel command to send to the citserver
837 * with_headers: also include some of the headers with the message numbers (more expensive)
839 int load_msg_ptrs(char *servcmd, int with_headers)
841 StrBuf* FoundCharset = NULL;
842 struct wcsession *WCC = WC;
843 message_summary *Msg;
847 //char fullname[128];
848 //char nodename[128];
849 //char inetaddr[128];
850 //char subject[1024];
857 ////int num_summ_alloc = 0;
859 if (WCC->summ != NULL) {
860 if (WCC->summ != NULL)
861 DeleteHash(&WCC->summ);
863 WCC->summ = NewHash(1, Flathash);
869 StrBuf_ServGetln(Buf);
870 if (GetServerStatus(Buf, NULL) != 1) {
874 // TODO if (with_headers) { //// TODO: Have Attachments?
876 while (len = StrBuf_ServGetln(Buf),
878 strcmp(ChrPtr(Buf), "000")!= 0))
880 if (nummsgs < maxload) {
881 Msg = (message_summary*)malloc(sizeof(message_summary));
882 memset(Msg, 0, sizeof(message_summary));
884 Msg->msgnum = StrBufExtract_long(Buf, 0, '|');
885 Msg->date = StrBufExtract_long(Buf, 1, '|');
887 Msg->from = NewStrBufPlain(NULL, StrLength(Buf));
888 StrBufExtract_token(Buf2, Buf, 2, '|');
889 if (StrLength(Buf2) != 0) {
890 /** Handle senders with RFC2047 encoding */
891 StrBuf_RFC822_to_Utf8(Msg->from, Buf2, WCC->DefaultCharset, FoundCharset);
895 StrBufExtract_token(Buf2, Buf, 3, '|');
896 if ((StrLength(Buf2) !=0 ) &&
897 ( ((WCC->room_flags & QR_NETWORK)
898 || ((strcasecmp(ChrPtr(Buf2), serv_info.serv_nodename)
899 && (strcasecmp(ChrPtr(Buf2), serv_info.serv_fqdn)))))))
901 StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
902 StrBufAppendBuf(Msg->from, Buf2, 0);
906 StrBufExtract_token(Msg->inetaddr, Buf, 4, '|');
909 Msg->subj = NewStrBufPlain(NULL, StrLength(Buf));
910 StrBufExtract_token(Buf2, Buf, 5, '|');
911 if (StrLength(Buf2) == 0)
912 StrBufAppendBufPlain(Msg->subj, _("(no subj)"), 0, -1);
914 StrBuf_RFC822_to_Utf8(Msg->subj, Buf2, WCC->DefaultCharset, FoundCharset);
915 if ((StrLength(Msg->subj) > 75) &&
916 (StrBuf_Utf8StrLen(Msg->subj) > 75)) {
917 StrBuf_Utf8StrCut(Msg->subj, 72);
918 StrBufAppendBufPlain(Msg->subj, HKEY("..."), 0);
923 if ((StrLength(Msg->from) > 25) &&
924 (StrBuf_Utf8StrLen(Msg->from) > 25)) {
925 StrBuf_Utf8StrCut(Msg->from, 23);
926 StrBufAppendBufPlain(Msg->from, HKEY("..."), 0);
929 Put(WCC->summ, (const char *)&n, sizeof(n), Msg, DestroyMessageSummary);
939 inline message_summary* GetMessagePtrAt(int n, HashList *Summ)
944 GetHash(Summ, (const char*)&n, sizeof(n), &vMsg);
945 return (message_summary*) vMsg;
949 void DrawMessageSummarySelector(StrBuf *BBViewToolBar, long maxmsgs, long startmsg)
951 struct wcsession *WCC = WC;
952 message_summary* Msg;
963 StrBuf *Selector = NewStrBuf();
965 At = GetNewHashPos(WCC->summ, (lbstr("SortOrder") == 1)? -maxmsgs : maxmsgs);
966 nItems = GetCount(WCC->summ);
969 vector[1] = startmsg;
975 lo = GetHashPosCounter(At);
976 if (lo + maxmsgs > nItems) {
982 done = !GetNextHashPos(WCC->summ, At, &hklen, &key, &vMsg);
983 Msg = (message_summary*) vMsg;
984 n = (Msg==NULL)? 0 : Msg->msgnum;
990 FlushStrBuf(BBViewToolBar); /** abuse our target buffer to contstruct one item in it */
991 DoTemplate(HKEY("select_messageindex"), BBViewToolBar, &vector, CTX_LONGVECTOR);
992 StrBufAppendBuf(Selector, BBViewToolBar, 0);
995 vector[6] = StartMsg;
996 FlushStrBuf(BBViewToolBar);
997 DoTemplate(HKEY("select_messageindex_all"), BBViewToolBar, &vector, CTX_LONGVECTOR);
998 StrBufAppendBuf(Selector, BBViewToolBar, 0);
1000 FlushStrBuf(BBViewToolBar);
1001 DoTemplate(HKEY("msg_listselector"), BBViewToolBar, Selector, CTX_STRBUF);
1002 FreeStrBuf(&Selector);
1007 * command loop for reading messages
1009 * Set oper to "readnew" or "readold" or "readfwd" or "headers"
1011 void readloop(char *oper)
1013 StrBuf *BBViewToolBar = NULL;
1015 message_summary *Msg;
1024 long *displayed_msgs = NULL;
1025 int num_displayed = 0;
1027 int is_addressbook = 0;
1028 int is_singlecard = 0;
1029 int is_calendar = 0;
1030 struct calview calv;
1034 int lowest_displayed = (-1);
1035 int highest_displayed = 0;
1036 addrbookent *addrbook = NULL;
1038 int bbs_reverse = 0;
1039 struct wcsession *WCC = WC;
1041 const char *HashKey;
1043 int care_for_empty_list = 0;
1047 switch (WCC->wc_view) {
1049 sprintf(buf, "wiki?room=%s&page=home", WCC->wc_roomname);
1055 strcpy(cmd, "MSGS ALL|||1");
1057 parse_calendar_view_request(&calv);
1061 strcpy(cmd, "MSGS ALL");
1066 strcpy(cmd, "MSGS ALL");
1068 wprintf("<div id=\"new_notes_here\"></div>\n");
1070 case VIEW_ADDRESSBOOK:
1071 is_singlecard = ibstr("is_singlecard");
1074 if (!strcmp(oper, "do_search")) {
1075 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
1078 strcpy(cmd, "MSGS ALL");
1085 care_for_empty_list = 1;
1086 startmsg = lbstr("startmsg");
1087 if (havebstr("maxmsgs"))
1088 maxmsgs = ibstr("maxmsgs");
1089 is_summary = (ibstr("is_summary") && !WCC->is_mobile);
1090 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1095 * When in summary mode, always show ALL messages instead of just
1096 * new or old. Otherwise, show what the user asked for.
1098 if (!strcmp(oper, "readnew")) {
1099 strcpy(cmd, "MSGS NEW");
1101 else if (!strcmp(oper, "readold")) {
1102 strcpy(cmd, "MSGS OLD");
1104 else if (!strcmp(oper, "do_search")) {
1105 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
1108 strcpy(cmd, "MSGS ALL");
1111 if ((WCC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1) && !WCC->is_mobile) {
1113 if (!strcmp(oper, "do_search")) {
1114 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
1117 strcpy(cmd, "MSGS ALL");
1121 is_bbview = !is_summary;
1122 if (is_summary) { /**< fetch header summary */
1124 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
1125 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
1126 (!strcmp(oper, "do_search") ? bstr("query") : "")
1131 if (startmsg == 0L) {
1133 Msg = GetMessagePtrAt((nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0, WCC->summ);
1134 startmsg = (Msg==NULL)? 0 : Msg->msgnum;
1137 Msg = GetMessagePtrAt(0, WCC->summ);
1138 startmsg = (Msg==NULL)? 0 : Msg->msgnum;
1141 sortit = is_summary || WCC->is_mobile;
1145 output_headers(1, 1, 1, 0, 0, 0);
1148 if (WCC->is_mobile) {
1150 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
1151 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
1152 (!strcmp(oper, "do_search") ? bstr("query") : "")
1158 * Are we doing a summary view? If so, we need to know old messages
1159 * and new messages, so we can do that pretty boldface thing for the
1164 nummsgs = load_msg_ptrs(cmd, (is_summary || WCC->is_mobile));
1166 if (care_for_empty_list) {
1167 wprintf("<div align=\"center\"><br /><em>");
1168 if (!strcmp(oper, "readnew")) {
1169 wprintf(_("No new messages."));
1170 } else if (!strcmp(oper, "readold")) {
1171 wprintf(_("No old messages."));
1173 wprintf(_("No messages here."));
1175 wprintf("</em><br /></div>\n");
1184 strcpy(old_msgs, "");
1186 serv_getln(buf, sizeof buf);
1187 if (buf[0] == '2') {
1188 strcpy(old_msgs, &buf[4]);
1190 at = GetNewHashPos(WCC->summ, 0);
1191 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
1192 /** Are you a new message, or an old message? */
1193 Msg = (message_summary*) vMsg;
1194 if (is_msg_in_mset(old_msgs, Msg->msgnum)) {
1206 SortIt = RetrieveSort(CTX_MAILSUM, NULL,
1209 SortByPayload(WCC->summ, SortIt);
1213 do_template("summary_header", NULL);
1214 } else if (WCC->is_mobile) {
1215 wprintf("<div id=\"message_list\">");
1220 * If we're not currently looking at ALL requested
1221 * messages, then display the selector bar
1224 BBViewToolBar = NewStrBuf();
1225 maxmsgs = 20; //// todo?
1227 DrawMessageSummarySelector(BBViewToolBar, maxmsgs, startmsg);
1228 StrBufAppendBuf(WCC->WBuf, BBViewToolBar, 0);
1231 at = GetNewHashPos(WCC->summ, 0);
1232 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
1233 Msg = (message_summary*) vMsg;
1234 if ((Msg->msgnum >= startmsg) && (num_displayed < maxmsgs)) {
1236 /** Display the message */
1238 DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
1240 else if (is_addressbook) {
1241 fetch_ab_name(Msg, buf);
1243 addrbook = realloc(addrbook,
1244 (sizeof(addrbookent) * num_ab) );
1245 safestrncpy(addrbook[num_ab-1].ab_name, buf,
1246 sizeof(addrbook[num_ab-1].ab_name));
1247 addrbook[num_ab-1].ab_msgnum = Msg->msgnum;
1249 else if (is_calendar) {
1250 load_calendar_item(Msg, Msg->is_new, &calv);
1252 else if (is_tasks) {
1253 display_task(Msg, Msg->is_new);
1255 else if (is_notes) {
1256 display_note(Msg, Msg->is_new);
1257 } else if (WCC->is_mobile) {
1258 DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
1261 if (displayed_msgs == NULL) {
1262 displayed_msgs = malloc(sizeof(long) *
1263 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
1265 displayed_msgs[num_displayed] = Msg->msgnum;
1268 if (lowest_displayed < 0) lowest_displayed = a;
1269 highest_displayed = a;
1277 if (displayed_msgs != NULL) {
1279 ////TODOqsort(displayed_msgs, num_displayed, sizeof(long), qlongcmp_r);
1282 /** if we do a split bbview in the future, begin messages div here */
1284 for (a=0; a<num_displayed; ++a) {
1285 read_message(WC->WBuf, HKEY("view_message"), displayed_msgs[a], 0, NULL);
1288 /** if we do a split bbview in the future, end messages div here */
1290 free(displayed_msgs);
1291 displayed_msgs = NULL;
1296 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
1297 wprintf("</div>"); /**< end of 'message_list' div */
1299 /** Here's the grab-it-to-resize-the-message-list widget */
1300 wprintf("<div id=\"resize_msglist\" "
1301 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
1302 "<div class=\"fix_scrollbar_bug\"> <hr>"
1306 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
1307 } else if (WCC->is_mobile) {
1312 * Bump these because although we're thinking in zero base, the user
1313 * is a drooling idiot and is thinking in one base.
1316 ++highest_displayed;
1319 * If we're not currently looking at ALL requested
1320 * messages, then display the selector bar
1323 /** begin bbview scroller */
1324 StrBufAppendBuf(WCC->WBuf, BBViewToolBar, 0);
1329 do_tasks_view(); /** Render the task list */
1333 render_calendar_view(&calv);
1336 if (is_addressbook) {
1337 do_addrbook_view(addrbook, num_ab); /** Render the address book */
1340 /** Note: wDumpContent() will output one additional </div> tag. */
1341 wprintf("</div>\n"); /** end of 'content' div */
1344 /** free the summary */
1345 if (WCC->summ != NULL) {
1346 DeleteHash(&WCC->summ);
1348 if (addrbook != NULL) free(addrbook);
1349 FreeStrBuf(&BBViewToolBar);
1354 * Back end for post_message()
1355 * ... this is where the actual message gets transmitted to the server.
1357 void post_mime_to_server(void) {
1358 struct wcsession *WCC = WC;
1359 char top_boundary[SIZ];
1360 char alt_boundary[SIZ];
1361 int is_multipart = 0;
1365 size_t encoded_length;
1366 size_t encoded_strlen;
1367 char *txtmail = NULL;
1369 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
1370 serv_info.serv_fqdn,
1374 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
1375 serv_info.serv_fqdn,
1380 /* RFC2045 requires this, and some clients look for it... */
1381 serv_puts("MIME-Version: 1.0");
1382 serv_puts("X-Mailer: " PACKAGE_STRING);
1384 /* If there are attachments, we have to do multipart/mixed */
1385 if (GetCount(WCC->attachments) > 0) {
1390 /* Remember, serv_printf() appends an extra newline */
1391 serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
1392 serv_printf("This is a multipart message in MIME format.\n");
1393 serv_printf("--%s", top_boundary);
1396 /* Remember, serv_printf() appends an extra newline */
1397 serv_printf("Content-type: multipart/alternative; "
1398 "boundary=\"%s\"\n", alt_boundary);
1399 serv_printf("This is a multipart message in MIME format.\n");
1400 serv_printf("--%s", alt_boundary);
1402 serv_puts("Content-type: text/plain; charset=utf-8");
1403 serv_puts("Content-Transfer-Encoding: quoted-printable");
1405 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
1406 text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */
1409 serv_printf("--%s", alt_boundary);
1411 serv_puts("Content-type: text/html; charset=utf-8");
1412 serv_puts("Content-Transfer-Encoding: quoted-printable");
1414 serv_puts("<html><body>\r\n");
1415 text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */
1416 serv_puts("</body></html>\r\n");
1418 serv_printf("--%s--", alt_boundary);
1426 /* Add in the attachments */
1427 it = GetNewHashPos(WCC->attachments, 0);
1428 while (GetNextHashPos(WCC->attachments, it, &len, &Key, &vAtt)) {
1429 att = (wc_attachment*)vAtt;
1430 encoded_length = ((att->length * 150) / 100);
1431 encoded = malloc(encoded_length);
1432 if (encoded == NULL) break;
1433 encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1);
1435 serv_printf("--%s", top_boundary);
1436 serv_printf("Content-type: %s", ChrPtr(att->content_type));
1437 serv_printf("Content-disposition: attachment; filename=\"%s\"", ChrPtr(att->filename));
1438 serv_puts("Content-transfer-encoding: base64");
1440 serv_write(encoded, encoded_strlen);
1445 serv_printf("--%s--", top_boundary);
1454 * Post message (or don't post message)
1456 * Note regarding the "dont_post" variable:
1457 * A random value (actually, it's just a timestamp) is inserted as a hidden
1458 * field called "postseq" when the display_enter page is generated. This
1459 * value is checked when posting, using the static variable dont_post. If a
1460 * user attempts to post twice using the same dont_post value, the message is
1461 * discarded. This prevents the accidental double-saving of the same message
1462 * if the user happens to click the browser "back" button.
1464 void post_message(void)
1467 StrBuf *encoded_subject = NULL;
1468 static long dont_post = (-1L);
1470 int is_anonymous = 0;
1471 const StrBuf *display_name = NULL;
1472 struct wcsession *WCC = WC;
1474 if (havebstr("force_room")) {
1475 gotoroom(bstr("force_room"));
1478 if (havebstr("display_name")) {
1479 display_name = sbstr("display_name");
1480 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
1481 display_name = NULL;
1486 if (WCC->upload_length > 0) {
1491 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WCC->upload_length);
1492 /** There's an attachment. Save it to this struct... */
1493 att = malloc(sizeof(wc_attachment));
1494 memset(att, 0, sizeof(wc_attachment));
1495 att->length = WCC->upload_length;
1496 att->content_type = NewStrBufPlain(WCC->upload_content_type, -1);
1497 att->filename = NewStrBufPlain(WCC->upload_filename, -1);
1500 if (WCC->attachments == NULL)
1501 WCC->attachments = NewHash(1, NULL);
1502 /* And add it to the list. */
1503 n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
1504 Put(WCC->attachments, N, n, att, free_attachment);
1507 * Mozilla sends a simple filename, which is what we want,
1508 * but Satan's Browser sends an entire pathname. Reduce
1509 * the path to just a filename if we need to.
1511 pch = strrchr(ChrPtr(att->filename), '/');
1513 StrBufCutLeft(att->filename, pch - ChrPtr(att->filename));
1515 pch = strrchr(ChrPtr(att->filename), '\\');
1517 StrBufCutLeft(att->filename, pch - ChrPtr(att->filename));
1521 * Transfer control of this memory from the upload struct
1522 * to the attachment struct.
1524 att->data = WCC->upload;
1525 WCC->upload_length = 0;
1531 if (havebstr("cancel_button")) {
1532 sprintf(WCC->ImportantMessage,
1533 _("Cancelled. Message was not posted."));
1534 } else if (havebstr("attach_button")) {
1537 } else if (lbstr("postseq") == dont_post) {
1538 sprintf(WCC->ImportantMessage,
1539 _("Automatically cancelled because you have already "
1540 "saved this message."));
1542 const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s";
1543 const StrBuf *Recp = NULL;
1544 const StrBuf *Cc = NULL;
1545 const StrBuf *Bcc = NULL;
1546 const StrBuf *Wikipage = NULL;
1547 const StrBuf *my_email_addr = NULL;
1548 StrBuf *CmdBuf = NULL;;
1549 StrBuf *references = NULL;
1551 if (havebstr("references"))
1553 const StrBuf *ref = sbstr("references");
1554 references = NewStrBufPlain(ChrPtr(ref), StrLength(ref));
1555 lprintf(9, "Converting: %s\n", ChrPtr(references));
1556 StrBufReplaceChars(references, '|', '!');
1557 lprintf(9, "Converted: %s\n", ChrPtr(references));
1559 if (havebstr("subject")) {
1562 * make enough room for the encoded string;
1563 * plus the QP header
1565 Subj = sbstr("subject");
1567 StrBufRFC2047encode(&encoded_subject, Subj);
1569 Recp = sbstr("recp");
1572 Wikipage = sbstr("wikipage");
1573 my_email_addr = sbstr("my_email_addr");
1575 CmdBuf = NewStrBufPlain(NULL,
1578 StrLength(encoded_subject) +
1581 StrLength(Wikipage) +
1582 StrLength(my_email_addr) +
1583 StrLength(references));
1585 StrBufPrintf(CmdBuf,
1589 ChrPtr(encoded_subject),
1590 ChrPtr(display_name),
1594 ChrPtr(my_email_addr),
1595 ChrPtr(references));
1596 FreeStrBuf(&references);
1598 lprintf(9, "%s\n", CmdBuf);
1599 serv_puts(ChrPtr(CmdBuf));
1600 serv_getln(buf, sizeof buf);
1601 FreeStrBuf(&CmdBuf);
1602 FreeStrBuf(&encoded_subject);
1603 if (buf[0] == '4') {
1604 post_mime_to_server();
1605 if ( (havebstr("recp"))
1606 || (havebstr("cc" ))
1607 || (havebstr("bcc" ))
1609 sprintf(WCC->ImportantMessage, _("Message has been sent.\n"));
1612 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
1614 dont_post = lbstr("postseq");
1616 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
1617 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1623 DeleteHash(&WCC->attachments);
1626 * We may have been supplied with instructions regarding the location
1627 * to which we must return after posting. If found, go there.
1629 if (havebstr("return_to")) {
1630 http_redirect(bstr("return_to"));
1633 * If we were editing a page in a wiki room, go to that page now.
1635 else if (havebstr("wikipage")) {
1636 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
1640 * Otherwise, just go to the "read messages" loop.
1643 readloop("readnew");
1651 * \brief display the message entry screen
1653 void display_enter(void)
1657 const StrBuf *display_name = NULL;
1658 /////wc_attachment *att;
1659 int recipient_required = 0;
1660 int subject_required = 0;
1661 int recipient_bad = 0;
1662 int is_anonymous = 0;
1664 struct wcsession *WCC = WC;
1668 if (havebstr("force_room")) {
1669 gotoroom(bstr("force_room"));
1672 display_name = sbstr("display_name");
1673 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
1674 display_name = NULL;
1678 /** First test to see whether this is a room that requires recipients to be entered */
1679 serv_puts("ENT0 0");
1680 serv_getln(buf, sizeof buf);
1682 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
1683 recipient_required = 1;
1685 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
1686 sprintf(WCC->ImportantMessage, "%s", &buf[4]);
1687 readloop("readnew");
1691 /* Is the server strongly recommending that the user enter a message subject? */
1692 if ((buf[3] != '\0') && (buf[4] != '\0')) {
1693 subject_required = extract_int(&buf[4], 1);
1697 * Are we perhaps in an address book view? If so, then an "enter
1698 * message" command really means "add new entry."
1700 if (WCC->wc_default_view == VIEW_ADDRESSBOOK) {
1701 do_edit_vcard(-1, "", "", WCC->wc_roomname);
1706 * Are we perhaps in a calendar room? If so, then an "enter
1707 * message" command really means "add new calendar item."
1709 if (WCC->wc_default_view == VIEW_CALENDAR) {
1710 display_edit_event();
1715 * Are we perhaps in a tasks view? If so, then an "enter
1716 * message" command really means "add new task."
1718 if (WCC->wc_default_view == VIEW_TASKS) {
1719 display_edit_task();
1724 * Otherwise proceed normally.
1725 * Do a custom room banner with no navbar...
1728 if (recipient_required) {
1729 const StrBuf *Recp = NULL;
1730 const StrBuf *Cc = NULL;
1731 const StrBuf *Bcc = NULL;
1732 const StrBuf *Wikipage = NULL;
1733 StrBuf *CmdBuf = NULL;;
1734 const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
1736 Recp = sbstr("recp");
1739 Wikipage = sbstr("wikipage");
1741 CmdBuf = NewStrBufPlain(NULL,
1744 StrLength(display_name) +
1747 StrLength(Wikipage));
1749 StrBufPrintf(CmdBuf,
1753 ChrPtr(display_name),
1757 serv_puts(ChrPtr(CmdBuf));
1758 serv_getln(buf, sizeof buf);
1759 FreeStrBuf(&CmdBuf);
1761 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
1762 if (havebstr("recp") &&
1768 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
1769 wprintf("<em>%s</em><br />\n", &buf[4]);/// -> important message
1773 svputlong("RCPTREQUIRED", recipient_required);
1774 svputlong("SUBJREQUIRED", recipient_required || subject_required);
1777 output_headers(1, 0, 0, 0, 1, 0);
1778 DoTemplate(HKEY("edit_message"), NULL, NULL, CTX_NONE);
1785 * \brief delete a message
1787 void delete_msg(void)
1792 msgid = lbstr("msgid");
1794 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
1795 serv_printf("DELE %ld", msgid);
1797 else { /** Otherwise move it to Trash */
1798 serv_printf("MOVE %ld|_TRASH_|0", msgid);
1801 serv_getln(buf, sizeof buf);
1802 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1804 readloop("readnew");
1809 * \brief move a message to another folder
1816 msgid = lbstr("msgid");
1818 if (havebstr("move_button")) {
1819 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
1821 serv_getln(buf, sizeof buf);
1822 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1824 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
1827 readloop("readnew");
1835 * Confirm move of a message
1837 void confirm_move_msg(void)
1843 msgid = lbstr("msgid");
1846 output_headers(1, 1, 2, 0, 0, 0);
1847 wprintf("<div id=\"banner\">\n");
1849 wprintf(_("Confirm move of message"));
1851 wprintf("</div>\n");
1853 wprintf("<div id=\"content\" class=\"service\">\n");
1855 wprintf("<CENTER>");
1857 wprintf(_("Move this message to:"));
1858 wprintf("<br />\n");
1860 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
1861 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1862 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
1864 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
1866 serv_getln(buf, sizeof buf);
1867 if (buf[0] == '1') {
1868 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1869 extract_token(targ, buf, 0, '|', sizeof targ);
1870 wprintf("<OPTION>");
1875 wprintf("</SELECT>\n");
1876 wprintf("<br />\n");
1878 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
1880 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
1881 wprintf("</form></CENTER>\n");
1883 wprintf("</CENTER>\n");
1887 void readnew(void) { readloop("readnew");}
1888 void readold(void) { readloop("readold");}
1889 void readfwd(void) { readloop("readfwd");}
1890 void headers(void) { readloop("headers");}
1891 void do_search(void) { readloop("do_search");}
1902 WebcitAddUrlHandler(HKEY("readnew"), readnew, NEED_URL);
1903 WebcitAddUrlHandler(HKEY("readold"), readold, NEED_URL);
1904 WebcitAddUrlHandler(HKEY("readfwd"), readfwd, NEED_URL);
1905 WebcitAddUrlHandler(HKEY("headers"), headers, NEED_URL);
1906 WebcitAddUrlHandler(HKEY("do_search"), do_search, 0);
1907 WebcitAddUrlHandler(HKEY("display_enter"), display_enter, 0);
1908 WebcitAddUrlHandler(HKEY("post"), post_message, 0);
1909 WebcitAddUrlHandler(HKEY("move_msg"), move_msg, 0);
1910 WebcitAddUrlHandler(HKEY("delete_msg"), delete_msg, 0);
1911 WebcitAddUrlHandler(HKEY("confirm_move_msg"), confirm_move_msg, 0);
1912 WebcitAddUrlHandler(HKEY("msg"), embed_message, NEED_URL|AJAX);
1913 WebcitAddUrlHandler(HKEY("printmsg"), print_message, NEED_URL);
1914 WebcitAddUrlHandler(HKEY("mobilemsg"), mobile_message_view, NEED_URL);
1915 WebcitAddUrlHandler(HKEY("msgheaders"), display_headers, NEED_URL);