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 const char* SortIcons[3] = {
39 "static/up_pointer.gif",
40 "static/down_pointer.gif",
41 "static/sort_none.gif"
55 /* SortEnum to plain string representation */
56 static const char* SortByStrings[] = {
67 /* SortEnum to sort-Function Table */
68 const CompareFunc SortFuncs[eUnSet] = {
78 /* given a SortEnum, which icon should we choose? */
79 const int SortDateToIcon[eUnSet] = { eUp, eDown, eNone, eNone, eNone, eNone, eNone};
80 const int SortSubjectToIcon[eUnSet] = { eNone, eNone, eUp, eDown, eNone, eNone, eNone};
81 const int SortSenderToIcon[eUnSet] = { eNone, eNone, eNone, eNone, eUp, eDown, eNone};
83 /* given a SortEnum, which would be the "opposite" search option? */
84 const int DateInvertSortString[eUnSet] = { eRDate, eDate, eDate, eDate, eDate, eDate, eDate};
85 const int SubjectInvertSortString[eUnSet] = { eSubject, eSubject, eRSubject, eUnSet, eSubject, eSubject, eSubject};
86 const int SenderInvertSortString[eUnSet] = { eSender, eSender, eSender, eSender, eRSender, eUnSet, eSender};
90 /*----------------------------------------------------------------------------*/
93 * Translates sortoption String to its SortEnum representation
94 * returns the enum matching the string; defaults to RDate
97 int StrToESort (const StrBuf *sortby)
101 if (!IsEmptyStr(ChrPtr(sortby))) while (result < eUnSet){
102 if (!strcasecmp(ChrPtr(sortby),
103 SortByStrings[result]))
111 typedef int (*QSortFunction) (const void*, const void*);
114 * qsort() compatible function to compare two longs in descending order.
116 int longcmp_r(const void *s1, const void *s2) {
120 l1 = *(long *)GetSearchPayload(s1);
121 l2 = *(long *)GetSearchPayload(s2);
123 if (l1 > l2) return(-1);
124 if (l1 < l2) return(+1);
129 * qsort() compatible function to compare two longs in descending order.
131 int qlongcmp_r(const void *s1, const void *s2) {
135 if (l1 > l2) return(-1);
136 if (l1 < l2) return(+1);
142 * qsort() compatible function to compare two message summary structs by ascending subject.
144 int summcmp_subj(const void *s1, const void *s2) {
145 message_summary *summ1;
146 message_summary *summ2;
148 summ1 = (message_summary *)GetSearchPayload(s1);
149 summ2 = (message_summary *)GetSearchPayload(s2);
150 return strcasecmp(ChrPtr(summ1->subj), ChrPtr(summ2->subj));
154 * qsort() compatible function to compare two message summary structs by descending subject.
156 int summcmp_rsubj(const void *s1, const void *s2) {
157 message_summary *summ1;
158 message_summary *summ2;
160 summ1 = (message_summary *)GetSearchPayload(s1);
161 summ2 = (message_summary *)GetSearchPayload(s2);
162 return strcasecmp(ChrPtr(summ2->subj), ChrPtr(summ1->subj));
166 * qsort() compatible function to compare two message summary structs by ascending sender.
168 int summcmp_sender(const void *s1, const void *s2) {
169 message_summary *summ1;
170 message_summary *summ2;
172 summ1 = (message_summary *)GetSearchPayload(s1);
173 summ2 = (message_summary *)GetSearchPayload(s2);
174 return strcasecmp(ChrPtr(summ1->from), ChrPtr(summ2->from));
178 * qsort() compatible function to compare two message summary structs by descending sender.
180 int summcmp_rsender(const void *s1, const void *s2) {
181 message_summary *summ1;
182 message_summary *summ2;
184 summ1 = (message_summary *)GetSearchPayload(s1);
185 summ2 = (message_summary *)GetSearchPayload(s2);
186 return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from));
190 * qsort() compatible function to compare two message summary structs by ascending date.
192 int summcmp_date(const void *s1, const void *s2) {
193 message_summary *summ1;
194 message_summary *summ2;
196 summ1 = (message_summary *)GetSearchPayload(s1);
197 summ2 = (message_summary *)GetSearchPayload(s2);
199 if (summ1->date < summ2->date) return -1;
200 else if (summ1->date > summ2->date) return +1;
205 * qsort() compatible function to compare two message summary structs by descending date.
207 int summcmp_rdate(const void *s1, const void *s2) {
208 message_summary *summ1;
209 message_summary *summ2;
211 summ1 = (message_summary *)GetSearchPayload(s1);
212 summ2 = (message_summary *)GetSearchPayload(s2);
214 if (summ1->date < summ2->date) return +1;
215 else if (summ1->date > summ2->date) return -1;
225 * I wanna SEE that message!
227 * msgnum Message number to display
228 * printable_view Nonzero to display a printable view
229 * section Optional for encapsulated message/rfc822 submessage
231 int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, int printable_view, const StrBuf *PartNum) {
234 StrBuf *FoundCharset;
237 message_summary *Msg = NULL;
241 // char mime_submessages[256] = "";
242 char reply_references[1024] = "";
249 lprintf(1, "----------%s---------MSG4 %ld|%s--------------\n", tmpl, msgnum, ChrPtr(PartNum));
250 serv_printf("MSG4 %ld|%s", msgnum, ChrPtr(PartNum));
251 StrBuf_ServGetln(Buf);
252 if (GetServerStatus(Buf, NULL) != 1) {
253 StrBufAppendPrintf(Target, "<strong>");
254 StrBufAppendPrintf(Target, _("ERROR:"));
255 StrBufAppendPrintf(Target, "</strong> %s<br />\n", &buf[4]);
260 /** begin everythingamundo table */
263 HdrToken = NewStrBuf();
264 Msg = (message_summary *)malloc(sizeof(message_summary));
265 memset(Msg, 0, sizeof(message_summary));
266 Msg->msgnum = msgnum;
267 Msg->PartNum = PartNum;
268 Msg->MsgBody = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
269 memset(Msg->MsgBody, 0, sizeof(wc_mime_attachment));
270 FoundCharset = NewStrBuf();
271 while ((StrBuf_ServGetln(Buf)>=0) && !Done) {
272 if ( (StrLength(Buf)==3) &&
273 !strcmp(ChrPtr(Buf), "000"))
277 lprintf(1, _("unexpected end of message"));
278 StrBufAppendPrintf(Target, "<i>");
279 StrBufAppendPrintf(Target, _("unexpected end of message"));
280 StrBufAppendPrintf(Target, " (1)</i><br /><br />\n");
281 StrBufAppendPrintf(Target, "</div>\n");
283 FreeStrBuf(&HdrToken);
284 DestroyMessageSummary(Msg);
285 FreeStrBuf(&FoundCharset);
293 case 0:/* Citadel Message Headers */
294 if (StrLength(Buf) == 0) {
298 StrBufExtract_token(HdrToken, Buf, 0, '=');
299 StrBufCutLeft(Buf, StrLength(HdrToken) + 1);
301 lprintf(1, ":: [%s] = [%s]\n", ChrPtr(HdrToken), ChrPtr(Buf));
302 if (GetHash(MsgHeaderHandler, SKEY(HdrToken), &vHdr) &&
304 Hdr = (headereval*)vHdr;
305 Hdr->evaluator(Msg, Buf, FoundCharset);
306 if (Hdr->Type == 1) {
310 else lprintf(1, "don't know how to handle message header[%s]\n", ChrPtr(HdrToken));
312 case 1:/* Message Mime Header */
313 if (StrLength(Buf) == 0) {
315 if (Msg->MsgBody->ContentType == NULL)
316 /* end of header or no header? */
317 Msg->MsgBody->ContentType = NewStrBufPlain(HKEY("text/plain"));
318 /* usual end of mime header */
322 StrBufExtract_token(HdrToken, Buf, 0, ':');
323 if (StrLength(HdrToken) > 0) {
324 StrBufCutLeft(Buf, StrLength(HdrToken) + 1);
325 lprintf(1, ":: [%s] = [%s]\n", ChrPtr(HdrToken), ChrPtr(Buf));
326 if (GetHash(MsgHeaderHandler, SKEY(HdrToken), &vHdr) &&
328 Hdr = (headereval*)vHdr;
329 Hdr->evaluator(Msg, Buf, FoundCharset);
334 case 2: /* Message Body */
336 if (Msg->MsgBody->size_known > 0) {
337 StrBuf_ServGetBLOB(Msg->MsgBody->Data, Msg->MsgBody->length);
339 /// todo: check next line, if not 000, append following lines
342 if (StrLength(Msg->MsgBody->Data) > 0)
343 StrBufAppendBufPlain(Msg->MsgBody->Data, "\n", 1, 0);
344 StrBufAppendBuf(Msg->MsgBody->Data, Buf, 0);
348 StrBufAppendBuf(Msg->MsgBody->Data, Buf, 0);
353 if (Msg->AllAttach == NULL)
354 Msg->AllAttach = NewHash(1,NULL);
355 Put(Msg->AllAttach, SKEY(Msg->MsgBody->PartNum), Msg->MsgBody, DestroyMime);
357 /* strip the bare contenttype, so we ommit charset etc. */
358 StrBufExtract_token(Buf, Msg->MsgBody->ContentType, 0, ';');
360 if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
362 RenderMimeFunc Render;
363 Render = (RenderMimeFunc)vHdr;
364 Render(Msg->MsgBody, NULL, FoundCharset);
367 if (StrLength(Msg->reply_references)> 0) {
368 /* Trim down excessively long lists of thread references. We eliminate the
369 * second one in the list so that the thread root remains intact.
371 int rrtok = num_tokens(ChrPtr(Msg->reply_references), '|');
372 int rrlen = StrLength(Msg->reply_references);
373 if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
374 remove_token(reply_references, 1, '|');////todo
378 /* Generate a reply-to address */
379 if (StrLength(Msg->Rfca) > 0) {
380 if (Msg->reply_to == NULL)
381 Msg->reply_to = NewStrBuf();
382 if (StrLength(Msg->from) > 0) {
383 StrBufPrintf(Msg->reply_to, "%s <%s>", ChrPtr(Msg->from), ChrPtr(Msg->Rfca));
386 FlushStrBuf(Msg->reply_to);
387 StrBufAppendBuf(Msg->reply_to, Msg->Rfca, 0);
392 if ((StrLength(Msg->OtherNode)>0) &&
393 (strcasecmp(ChrPtr(Msg->OtherNode), serv_info.serv_nodename)) &&
394 (strcasecmp(ChrPtr(Msg->OtherNode), serv_info.serv_humannode)) )
396 if (Msg->reply_to == NULL)
397 Msg->reply_to = NewStrBuf();
398 StrBufPrintf(Msg->reply_to,
401 ChrPtr(Msg->OtherNode));
404 if (Msg->reply_to == NULL)
405 Msg->reply_to = NewStrBuf();
406 FlushStrBuf(Msg->reply_to);
407 StrBufAppendBuf(Msg->reply_to, Msg->from, 0);
410 it = GetNewHashPos();
411 while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) &&
413 wc_mime_attachment *Mime = (wc_mime_attachment*) vMime;
414 evaluate_mime_part(Msg, Mime);
418 DoTemplate(tmpl, tmpllen, Target, Msg, CTX_MAILSUM);
420 DestroyMessageSummary(Msg);
421 FreeStrBuf(&FoundCharset);
422 FreeStrBuf(&HdrToken);
430 * Unadorned HTML output of an individual message, suitable
431 * for placing in a hidden iframe, for printing, or whatever
433 * msgnum_as_string == Message number, as a string instead of as a long int
435 void embed_message(void) {
437 const StrBuf *Tmpl = sbstr("template");
439 msgnum = StrTol(WC->UrlFragment1);
440 if (StrLength(Tmpl) > 0)
441 read_message(WC->WBuf, SKEY(Tmpl), msgnum, 0, NULL);
443 read_message(WC->WBuf, HKEY("view_message"), msgnum, 0, NULL);
448 * Printable view of a message
450 * msgnum_as_string == Message number, as a string instead of as a long int
452 void print_message(void) {
455 msgnum = StrTol(WC->UrlFragment1);
456 output_headers(0, 0, 0, 0, 0, 0);
458 hprintf("Content-type: text/html\r\n"
459 "Server: " PACKAGE_STRING "\r\n"
460 "Connection: close\r\n");
464 read_message(WC->WBuf, HKEY("view_message_print"), msgnum, 1, NULL);
470 * Mobile browser view of message
472 * @param msg_num_as_string Message number as a string instead of as a long int
474 void mobile_message_view(void) {
476 msgnum = StrTol(WC->UrlFragment1);
477 output_headers(1, 0, 0, 0, 0, 1);
479 do_template("msgcontrols", NULL);
480 read_message(WC->WBuf, HKEY("view_message"), msgnum,1, NULL);
485 * \brief Display a message's headers
487 * \param msgnum_as_string Message number, as a string instead of as a long int
489 void display_headers(void) {
493 msgnum = StrTol(WC->UrlFragment1);
494 output_headers(0, 0, 0, 0, 0, 0);
496 hprintf("Content-type: text/plain\r\n"
498 "Connection: close\r\n",
502 serv_printf("MSG2 %ld|3", msgnum);
503 serv_getln(buf, sizeof buf);
505 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
506 wprintf("%s\n", buf);
516 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
517 * or 'reply quoted' operations.
519 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
520 * in this function. Doing so would throw a JavaScript error in the
521 * 'supplied text' argument to the editor.
523 * \param msgnum Message number of the message we want to quote
524 * \param forward_attachments Nonzero if we want attachments to be forwarded
526 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
527 struct wcsession *WCC = WC;
529 char mime_partnum[256];
530 char mime_filename[256];
531 char mime_content_type[256];
532 char mime_charset[256];
533 char mime_disposition[256];
535 char *attachments = NULL;
537 int num_attachments = 0;
539 char m_subject[1024];
551 iconv_t ic = (iconv_t)(-1) ;
552 char *ibuf; /**< Buffer of characters to be converted */
553 char *obuf; /**< Buffer for converted characters */
554 size_t ibuflen; /**< Length of input buffer */
555 size_t obuflen; /**< Length of output buffer */
556 char *osav; /**< Saved pointer to output buffer */
562 strcpy(reply_to, "");
563 strcpy(mime_content_type, "text/plain");
564 strcpy(mime_charset, "us-ascii");
566 serv_printf("MSG4 %ld", msgnum);
567 serv_getln(buf, sizeof buf);
569 wprintf(_("ERROR:"));
570 wprintf("%s<br />", &buf[4]);
574 strcpy(m_subject, "");
576 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
577 if (!strcmp(buf, "000")) {
578 wprintf("%s (3)", _("unexpected end of message"));
581 if (include_headers) {
582 if (!strncasecmp(buf, "nhdr=yes", 8))
586 if (!strncasecmp(buf, "type=", 5))
587 format_type = atoi(&buf[5]);
588 if (!strncasecmp(buf, "from=", 5)) {
589 strcpy(from, &buf[5]);
591 utf8ify_rfc822_string(from);
594 if (!strncasecmp(buf, "subj=", 5)) {
595 strcpy(m_subject, &buf[5]);
597 if ((!strncasecmp(buf, "hnod=", 5))
598 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
599 wprintf("(%s) ", &buf[5]);
601 if ((!strncasecmp(buf, "room=", 5))
602 && (strcasecmp(&buf[5], WC->wc_roomname))
603 && (!IsEmptyStr(&buf[5])) ) {
605 wprintf("%s> ", &buf[5]);
607 if (!strncasecmp(buf, "rfca=", 5)) {
608 strcpy(rfca, &buf[5]);
613 if (!strncasecmp(buf, "node=", 5)) {
614 strcpy(node, &buf[5]);
615 if ( ((WC->room_flags & QR_NETWORK)
616 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
617 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
618 && (IsEmptyStr(rfca))
620 wprintf("@%s ", &buf[5]);
623 if (!strncasecmp(buf, "rcpt=", 5)) {
626 utf8ify_rfc822_string(to);
629 if (!strncasecmp(buf, "time=", 5)) {
630 webcit_fmt_date(now, atol(&buf[5]), 0);
636 * Save attachment info for later. We can't start downloading them
637 * yet because we're in the middle of a server transaction.
639 if (!strncasecmp(buf, "part=", 5)) {
640 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
643 sprintf(ptr, "%s%s\n",
644 ((attachments != NULL) ? attachments : ""),
649 lprintf(9, "attachments=<%s>\n", attachments);
655 if (include_headers) {
658 utf8ify_rfc822_string(m_subject);
659 if (!IsEmptyStr(m_subject)) {
660 wprintf(_("Subject:"));
662 msgescputs(m_subject);
673 * Learn the content type
675 strcpy(mime_content_type, "text/plain");
676 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
677 if (!strcmp(buf, "000")) {
678 wprintf("%s (4)", _("unexpected end of message"));
681 if (!strncasecmp(buf, "Content-type: ", 14)) {
683 safestrncpy(mime_content_type, &buf[14],
684 sizeof(mime_content_type));
685 for (i=0; i<strlen(mime_content_type); ++i) {
686 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
687 safestrncpy(mime_charset, &mime_content_type[i+8],
688 sizeof mime_charset);
691 len = strlen(mime_content_type);
692 for (i=0; i<len; ++i) {
693 if (mime_content_type[i] == ';') {
694 mime_content_type[i] = 0;
698 len = strlen(mime_charset);
699 for (i=0; i<len; ++i) {
700 if (mime_charset[i] == ';') {
708 /** Set up a character set conversion if we need to (and if we can) */
710 if ( (strcasecmp(mime_charset, "us-ascii"))
711 && (strcasecmp(mime_charset, "UTF-8"))
712 && (strcasecmp(mime_charset, ""))
714 ctdl_iconv_open("UTF-8", mime_charset, &ic);
715 if (ic == (iconv_t)(-1) ) {
716 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
717 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
722 /** Messages in legacy Citadel variformat get handled thusly... */
723 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
727 /* Boring old 80-column fixed format text gets handled this way... */
728 else if (!strcasecmp(mime_content_type, "text/plain")) {
729 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
732 if ((len > 0) && (buf[len-1] == '\n')) buf[--len] = 0;
733 if ((len > 0) && (buf[len-1] == '\r')) buf[--len] = 0;
736 if (ic != (iconv_t)(-1) ) {
740 obuf = (char *) malloc(obuflen);
742 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
743 osav[SIZ-obuflen] = 0;
744 safestrncpy(buf, osav, sizeof buf);
750 while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
753 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
754 wprintf("<blockquote>");
756 } else if ((bq == 1) &&
757 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
758 wprintf("</blockquote>");
762 url(buf, sizeof(buf));
764 wprintf("</tt><br />");
766 wprintf("</i><br />");
769 /** HTML just gets escaped and stuffed back into the editor */
770 else if (!strcasecmp(mime_content_type, "text/html")) {
771 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
775 }//// TODO: charset? utf8?
777 /** Unknown weirdness ... don't know how to handle this content type */
779 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
783 /** end of body handler */
786 * If there were attachments, we have to download them and insert them
787 * into the attachment chain for the forwarded message we are composing.
789 if ( (forward_attachments) && (num_attachments) ) {
790 for (i=0; i<num_attachments; ++i) {
791 extract_token(buf, attachments, i, '\n', sizeof buf);
792 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
793 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
794 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
795 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
796 mime_length = extract_int(buf, 5);
799 * tracing ... uncomment if necessary
802 lprintf(9, "fwd filename: %s\n", mime_filename);
803 lprintf(9, "fwd partnum : %s\n", mime_partnum);
804 lprintf(9, "fwd conttype: %s\n", mime_content_type);
805 lprintf(9, "fwd dispose : %s\n", mime_disposition);
806 lprintf(9, "fwd length : %d\n", mime_length);
808 if ( (!strcasecmp(mime_disposition, "inline"))
809 || (!strcasecmp(mime_disposition, "attachment")) ) {
813 /* Create an attachment struct from this mime part... */
814 att = malloc(sizeof(wc_attachment));
815 memset(att, 0, sizeof(wc_attachment));
816 att->length = mime_length;
817 att->content_type = NewStrBufPlain(mime_content_type, -1);
818 att->filename = NewStrBufPlain(mime_filename, -1);
819 att->data = load_mimepart(msgnum, mime_partnum);
821 if (WCC->attachments == NULL)
822 WCC->attachments = NewHash(1, NULL);
823 /* And add it to the list. */
824 n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
825 Put(WCC->attachments, N, n, att, free_attachment);
832 if (ic != (iconv_t)(-1) ) {
837 if (attachments != NULL) {
845 message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSubject, long MsgNum)
848 MsgPartEvaluatorFunc Eval;
849 message_summary *Msg;
858 serv_printf("MSG0 %ld|1", MsgNum); /* ask for headers only */
860 StrBuf_ServGetln(Buf);
861 if (GetServerStatus(Buf, NULL) == 1) {
866 Msg = (message_summary*)malloc(sizeof(message_summary));
867 memset(Msg, 0, sizeof(message_summary));
868 while (len = StrBuf_ServGetln(Buf),
870 strcmp(ChrPtr(Buf), "000")== 0)){
872 ebuf = strchr(ChrPtr(Buf), '=');
874 if (GetHash(MsgEvaluators, buf, nBuf, &vEval) && vEval != NULL) {
875 Eval = (MsgPartEvaluatorFunc) vEval;
876 StrBufCutLeft(Buf, nBuf + 1);
879 else lprintf(1, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
886 * \brief display the adressbook overview
887 * \param msgnum the citadel message number
888 * \param alpha what????
890 void display_addressbook(long msgnum, char alpha) {
892 /* char mime_partnum[SIZ]; */
893 /* char mime_filename[SIZ]; */
894 /* char mime_content_type[SIZ]; */
895 ///char mime_disposition[SIZ];
897 char vcard_partnum[SIZ];
898 char *vcard_source = NULL;
899 message_summary summ;////TODO: this will leak
901 memset(&summ, 0, sizeof(summ));
902 ///safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
903 ///Load Message headers
905 if (!IsEmptyStr(vcard_partnum)) {
906 vcard_source = load_mimepart(msgnum, vcard_partnum);
907 if (vcard_source != NULL) {
909 /** Display the summary line */
910 display_vcard(WC->WBuf, vcard_source, alpha, 0, NULL,msgnum);
912 /** If it's my vCard I can edit it */
913 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
914 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
915 || (WC->wc_view == VIEW_ADDRESSBOOK)
917 wprintf("<a href=\"edit_vcard?"
918 "msgnum=%ld&partnum=%s\">",
919 msgnum, vcard_partnum);
920 wprintf("[%s]</a>", _("edit"));
932 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
933 * \param namebuf name to analyze, reverse if nescessary
935 void lastfirst_firstlast(char *namebuf) {
940 if (namebuf == NULL) return;
941 if (strchr(namebuf, ';') != NULL) return;
943 i = num_tokens(namebuf, ' ');
946 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
947 remove_token(namebuf, i-1, ' ');
948 strcpy(firstname, namebuf);
949 sprintf(namebuf, "%s; %s", lastname, firstname);
953 * \brief fetch what??? name
954 * \param msgnum the citadel message number
955 * \param namebuf where to put the name in???
957 void fetch_ab_name(message_summary *Msg, char *namebuf) {
959 char mime_partnum[SIZ];
960 char mime_filename[SIZ];
961 char mime_content_type[SIZ];
962 char mime_disposition[SIZ];
964 char vcard_partnum[SIZ];
965 char *vcard_source = NULL;
967 message_summary summ;/// TODO this will lak
969 if (namebuf == NULL) return;
972 memset(&summ, 0, sizeof(summ));
973 //////safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
975 sprintf(buf, "MSG0 %ld|0", Msg->msgnum); /** unfortunately we need the mime info now */
977 serv_getln(buf, sizeof buf);
978 if (buf[0] != '1') return;
980 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
981 if (!strncasecmp(buf, "part=", 5)) {
982 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
983 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
984 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
985 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
986 mime_length = extract_int(&buf[5], 5);
988 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
989 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
990 strcpy(vcard_partnum, mime_partnum);
996 if (!IsEmptyStr(vcard_partnum)) {
997 vcard_source = load_mimepart(Msg->msgnum, vcard_partnum);
998 if (vcard_source != NULL) {
1000 /* Grab the name off the card */
1001 display_vcard(WC->WBuf, vcard_source, 0, 0, namebuf, Msg->msgnum);
1007 lastfirst_firstlast(namebuf);
1009 len = strlen(namebuf);
1010 for (i=0; i<len; ++i) {
1011 if (namebuf[i] != ';') return;
1013 strcpy(namebuf, _("(no name)"));
1021 * load message pointers from the server for a "read messages" operation
1023 * servcmd: the citadel command to send to the citserver
1024 * with_headers: also include some of the headers with the message numbers (more expensive)
1026 int load_msg_ptrs(char *servcmd, int with_headers)
1028 StrBuf* FoundCharset = NULL;
1029 struct wcsession *WCC = WC;
1030 message_summary *Msg;
1033 ///time_t datestamp;
1034 //char fullname[128];
1035 //char nodename[128];
1036 //char inetaddr[128];
1037 //char subject[1024];
1044 ////int num_summ_alloc = 0;
1046 if (WCC->summ != NULL) {
1047 if (WCC->summ != NULL)
1048 DeleteHash(&WCC->summ);
1050 WCC->summ = NewHash(1, Flathash);
1056 StrBuf_ServGetln(Buf);
1057 if (GetServerStatus(Buf, NULL) != 1) {
1061 // TODO if (with_headers) { //// TODO: Have Attachments?
1063 while (len = StrBuf_ServGetln(Buf),
1065 strcmp(ChrPtr(Buf), "000")!= 0))
1067 if (nummsgs < maxload) {
1068 Msg = (message_summary*)malloc(sizeof(message_summary));
1069 memset(Msg, 0, sizeof(message_summary));
1071 Msg->msgnum = StrBufExtract_long(Buf, 0, '|');
1072 Msg->date = StrBufExtract_long(Buf, 1, '|');
1074 Msg->from = NewStrBufPlain(NULL, StrLength(Buf));
1075 StrBufExtract_token(Buf2, Buf, 2, '|');
1076 if (StrLength(Buf2) != 0) {
1077 /** Handle senders with RFC2047 encoding */
1078 StrBuf_RFC822_to_Utf8(Msg->from, Buf2, WCC->DefaultCharset, FoundCharset);
1082 StrBufExtract_token(Buf2, Buf, 3, '|');
1083 if ((StrLength(Buf2) !=0 ) &&
1084 ( ((WCC->room_flags & QR_NETWORK)
1085 || ((strcasecmp(ChrPtr(Buf2), serv_info.serv_nodename)
1086 && (strcasecmp(ChrPtr(Buf2), serv_info.serv_fqdn)))))))
1088 StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
1089 StrBufAppendBuf(Msg->from, Buf2, 0);
1093 StrBufExtract_token(Msg->inetaddr, Buf, 4, '|');
1096 Msg->subj = NewStrBufPlain(NULL, StrLength(Buf));
1097 StrBufExtract_token(Buf2, Buf, 5, '|');
1098 if (StrLength(Buf2) == 0)
1099 StrBufAppendBufPlain(Msg->subj, _("(no subj)"), 0, -1);
1101 StrBuf_RFC822_to_Utf8(Msg->subj, Buf2, WCC->DefaultCharset, FoundCharset);
1102 if ((StrLength(Msg->subj) > 75) &&
1103 (StrBuf_Utf8StrLen(Msg->subj) > 75)) {
1104 StrBuf_Utf8StrCut(Msg->subj, 72);
1105 StrBufAppendBufPlain(Msg->subj, HKEY("..."), 0);
1110 if ((StrLength(Msg->from) > 25) &&
1111 (StrBuf_Utf8StrLen(Msg->from) > 25)) {
1112 StrBuf_Utf8StrCut(Msg->from, 23);
1113 StrBufAppendBufPlain(Msg->from, HKEY("..."), 0);
1116 Put(WCC->summ, (const char *)&n, sizeof(n), Msg, DestroyMessageSummary);
1131 * command loop for reading messages
1133 * Set oper to "readnew" or "readold" or "readfwd" or "headers"
1135 void readloop(char *oper)
1138 message_summary *Msg;
1147 long *displayed_msgs = NULL;
1148 int num_displayed = 0;
1150 int is_addressbook = 0;
1151 int is_singlecard = 0;
1152 int is_calendar = 0;
1153 struct calview calv;
1158 int lowest_displayed = (-1);
1159 int highest_displayed = 0;
1160 addrbookent *addrbook = NULL;
1162 const StrBuf *sortby = NULL;
1164 int SortBy = eRDate;
1165 const StrBuf *sortpref_value;
1166 int bbs_reverse = 0;
1167 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
1169 const char *HashKey;
1172 if (WCC->wc_view == VIEW_WIKI) {
1173 sprintf(buf, "wiki?room=%s&page=home", WCC->wc_roomname);
1178 startmsg = lbstr("startmsg");
1179 maxmsgs = ibstr("maxmsgs");
1180 is_summary = (ibstr("is_summary") && !WCC->is_mobile);
1181 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1183 sortpref_value = get_room_pref("sort");
1185 sortby = sbstr("sortby");
1186 if ( (!IsEmptyStr(ChrPtr(sortby))) &&
1187 (strcasecmp(ChrPtr(sortby), ChrPtr(sortpref_value)) != 0)) {
1188 set_room_pref("sort", NewStrBufDup(sortby), 1);
1189 sortpref_value = NULL;
1190 sortpref_value = sortby;
1193 SortBy = StrToESort(sortpref_value);
1194 /* message board sort */
1195 if (SortBy == eReverse) {
1202 output_headers(1, 1, 1, 0, 0, 0);
1205 * When in summary mode, always show ALL messages instead of just
1206 * new or old. Otherwise, show what the user asked for.
1208 if (!strcmp(oper, "readnew")) {
1209 strcpy(cmd, "MSGS NEW");
1211 else if (!strcmp(oper, "readold")) {
1212 strcpy(cmd, "MSGS OLD");
1214 else if (!strcmp(oper, "do_search")) {
1215 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
1218 strcpy(cmd, "MSGS ALL");
1221 if ((WCC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1) && !WCC->is_mobile) {
1223 if (!strcmp(oper, "do_search")) {
1224 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
1227 strcpy(cmd, "MSGS ALL");
1231 if ((WCC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
1233 if (!strcmp(oper, "do_search")) {
1234 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
1237 strcpy(cmd, "MSGS ALL");
1242 if (is_summary) { /**< fetch header summary */
1243 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
1244 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
1245 (!strcmp(oper, "do_search") ? bstr("query") : "")
1250 if (WCC->is_mobile) {
1252 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
1253 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
1254 (!strcmp(oper, "do_search") ? bstr("query") : "")
1260 * Are we doing a summary view? If so, we need to know old messages
1261 * and new messages, so we can do that pretty boldface thing for the
1264 strcpy(old_msgs, "");
1265 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){
1267 serv_getln(buf, sizeof buf);
1268 if (buf[0] == '2') {
1269 strcpy(old_msgs, &buf[4]);
1273 is_singlecard = ibstr("is_singlecard");
1275 if (WCC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
1277 strcpy(cmd, "MSGS ALL|||1");
1279 parse_calendar_view_request(&calv);
1281 if (WCC->wc_default_view == VIEW_TASKS) { /**< tasks */
1283 strcpy(cmd, "MSGS ALL");
1286 if (WCC->wc_default_view == VIEW_NOTES) { /**< notes */
1288 strcpy(cmd, "MSGS ALL");
1293 wprintf("<div id=\"new_notes_here\"></div>\n");
1296 nummsgs = load_msg_ptrs(cmd, (is_summary || WCC->is_mobile));
1299 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
1300 wprintf("<div align=\"center\"><br /><em>");
1301 if (!strcmp(oper, "readnew")) {
1302 wprintf(_("No new messages."));
1303 } else if (!strcmp(oper, "readold")) {
1304 wprintf(_("No old messages."));
1306 wprintf(_("No messages here."));
1308 wprintf("</em><br /></div>\n");
1314 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){
1316 message_summary *Msg;
1318 at = GetNewHashPos();
1319 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
1320 /** Are you a new message, or an old message? */
1321 Msg = (message_summary*) vMsg;
1323 if (is_msg_in_mset(old_msgs, Msg->msgnum)) {
1334 if (startmsg == 0L) {
1336 startmsg = WCC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
1339 startmsg = WCC->msgarr[0];
1343 if (is_summary || WCC->is_mobile) {
1344 SortByPayload(WCC->summ, SortFuncs[SortBy]);
1349 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
1350 " document.onkeydown = CtdlMsgListKeyPress; "
1351 " if (document.layers) { "
1352 " document.captureEvents(Event.KEYPRESS); "
1357 /** note that Date and Delete are now in the same column */
1358 wprintf("<div id=\"message_list_hdr\">"
1359 "<div class=\"fix_scrollbar_bug\">"
1360 "<table cellspacing=0 style=\"width:100%%\">"
1363 wprintf("<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> </th>\n"
1364 "<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> </th>\n"
1365 "<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> \n"
1367 "<input type=\"submit\" name=\"delete_button\" id=\"delbutton\" "
1368 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
1375 SortByStrings[SubjectInvertSortString[SortBy]],
1376 SortIcons[SortSubjectToIcon[SortBy]],
1377 SENDER_COL_WIDTH_PCT,
1379 SortByStrings[SenderInvertSortString[SortBy]],
1380 SortIcons[SortSenderToIcon[SortBy]],
1381 DATE_PLUS_BUTTONS_WIDTH_PCT,
1383 SortByStrings[DateInvertSortString[SortBy]],
1384 SortIcons[SortDateToIcon[SortBy]],
1387 wprintf("</table></div></div>\n");
1388 wprintf("<div id=\"message_list\">"
1390 "<div class=\"fix_scrollbar_bug\">\n"
1391 "<table class=\"mailbox_summary\" id=\"summary_headers\" "
1392 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
1394 } else if (WCC->is_mobile) {
1395 wprintf("<div id=\"message_list\">");
1400 * Set the "is_bbview" variable if it appears that we are looking at
1401 * a classic bulletin board view.
1403 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
1404 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
1409 * If we're not currently looking at ALL requested
1410 * messages, then display the selector bar
1413 /** begin bbview scroller */
1414 wprintf("<form name=\"msgomatictop\" class=\"selector_top\" > \n <p>");
1415 wprintf(_("Reading #"));//// TODO this isn't used, should it? : , lowest_displayed, highest_displayed);
1417 wprintf("<select name=\"whichones\" size=\"1\" "
1418 "OnChange=\"location.href=msgomatictop.whichones.options"
1419 "[selectedIndex].value\">\n");
1422 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
1424 lo = b - maxmsgs + 2;
1426 wprintf("<option %s value="
1431 "%d-%d</option> \n",
1432 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
1441 for (b=0; b<nummsgs; b = b + maxmsgs) {
1443 hi = b + maxmsgs + 1;
1444 if (hi > nummsgs) hi = nummsgs;
1445 wprintf("<option %s value="
1450 "%d-%d</option> \n",
1451 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
1460 wprintf("<option value=\"%s?startmsg=%ld"
1461 "&maxmsgs=9999999&is_summary=%d\">",
1463 WCC->msgarr[0], is_summary);
1465 wprintf("</option>");
1466 wprintf("</select> ");
1467 wprintf(_("of %d messages."), nummsgs);
1469 /** forward/reverse */
1470 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
1471 "OnChange=\"location.href='%s?sortby=forward'\"",
1472 (bbs_reverse ? "" : "checked"),
1476 wprintf(_("oldest to newest"));
1477 wprintf(" ");
1479 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
1480 "OnChange=\"location.href='%s?sortby=reverse'\"",
1481 (bbs_reverse ? "checked" : ""),
1485 wprintf(_("newest to oldest"));
1488 wprintf("</p></form>\n");
1489 /** end bbview scroller */
1492 at = GetNewHashPos();
1493 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
1494 Msg = (message_summary*) vMsg;
1495 if ((Msg->msgnum >= startmsg) && (num_displayed < maxmsgs)) {
1497 /** Display the message */
1499 DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
1501 else if (is_addressbook) {
1502 fetch_ab_name(Msg, buf);
1504 addrbook = realloc(addrbook,
1505 (sizeof(addrbookent) * num_ab) );
1506 safestrncpy(addrbook[num_ab-1].ab_name, buf,
1507 sizeof(addrbook[num_ab-1].ab_name));
1508 addrbook[num_ab-1].ab_msgnum = Msg->msgnum;
1510 else if (is_calendar) {
1511 load_calendar_item(Msg, Msg->is_new, &calv);
1513 else if (is_tasks) {
1514 display_task(Msg, Msg->is_new);
1516 else if (is_notes) {
1517 display_note(Msg, Msg->is_new);
1518 } else if (WCC->is_mobile) {
1519 DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
1522 if (displayed_msgs == NULL) {
1523 displayed_msgs = malloc(sizeof(long) *
1524 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
1526 displayed_msgs[num_displayed] = Msg->msgnum;
1529 if (lowest_displayed < 0) lowest_displayed = a;
1530 highest_displayed = a;
1538 if (displayed_msgs != NULL) {
1540 qsort(displayed_msgs, num_displayed, sizeof(long), qlongcmp_r);
1543 /** if we do a split bbview in the future, begin messages div here */
1545 for (a=0; a<num_displayed; ++a) {
1546 read_message(WC->WBuf, HKEY("view_message"), displayed_msgs[a], 0, NULL);
1549 /** if we do a split bbview in the future, end messages div here */
1551 free(displayed_msgs);
1552 displayed_msgs = NULL;
1557 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
1558 wprintf("</div>"); /**< end of 'message_list' div */
1560 /** Here's the grab-it-to-resize-the-message-list widget */
1561 wprintf("<div id=\"resize_msglist\" "
1562 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
1563 "<div class=\"fix_scrollbar_bug\"> <hr>"
1567 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
1568 } else if (WCC->is_mobile) {
1573 * Bump these because although we're thinking in zero base, the user
1574 * is a drooling idiot and is thinking in one base.
1577 ++highest_displayed;
1580 * If we're not currently looking at ALL requested
1581 * messages, then display the selector bar
1584 /** begin bbview scroller */
1585 wprintf("<form name=\"msgomatic\" class=\"selector_bottom\" > \n <p>");
1586 wprintf(_("Reading #")); /// TODO: this isn't used: , lowest_displayed, highest_displayed);
1588 wprintf("<select name=\"whichones\" size=\"1\" "
1589 "OnChange=\"location.href=msgomatic.whichones.options"
1590 "[selectedIndex].value\">\n");
1593 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
1595 lo = b - maxmsgs + 2;
1597 wprintf("<option %s value="
1602 "%d-%d</option> \n",
1603 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
1612 for (b=0; b<nummsgs; b = b + maxmsgs) {
1614 hi = b + maxmsgs + 1;
1615 if (hi > nummsgs) hi = nummsgs;
1616 wprintf("<option %s value="
1621 "%d-%d</option> \n",
1622 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
1631 wprintf("<option value=\"%s&startmsg=%ld"
1632 "&maxmsgs=9999999&is_summary=%d\">",
1634 WCC->msgarr[0], is_summary);
1636 wprintf("</option>");
1637 wprintf("</select> ");
1638 wprintf(_("of %d messages."), nummsgs);
1640 /** forward/reverse */
1641 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
1642 "OnChange=\"location.href='%s&sortby=forward'\"",
1643 (bbs_reverse ? "" : "checked"),
1647 wprintf(_("oldest to newest"));
1648 wprintf(" ");
1649 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
1650 "OnChange=\"location.href='%s&sortby=reverse'\"",
1651 (bbs_reverse ? "checked" : ""),
1655 wprintf(_("newest to oldest"));
1658 wprintf("</p></form>\n");
1659 /** end bbview scroller */
1664 do_tasks_view(); /** Render the task list */
1668 render_calendar_view(&calv);
1671 if (is_addressbook) {
1672 do_addrbook_view(addrbook, num_ab); /** Render the address book */
1675 /** Note: wDumpContent() will output one additional </div> tag. */
1676 wprintf("</div>\n"); /** end of 'content' div */
1679 /** free the summary */
1680 if (WCC->summ != NULL) {
1681 DeleteHash(&WCC->summ);
1683 if (addrbook != NULL) free(addrbook);
1688 * Back end for post_message()
1689 * ... this is where the actual message gets transmitted to the server.
1691 void post_mime_to_server(void) {
1692 struct wcsession *WCC = WC;
1693 char top_boundary[SIZ];
1694 char alt_boundary[SIZ];
1695 int is_multipart = 0;
1699 size_t encoded_length;
1700 size_t encoded_strlen;
1701 char *txtmail = NULL;
1703 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
1704 serv_info.serv_fqdn,
1708 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
1709 serv_info.serv_fqdn,
1714 /* RFC2045 requires this, and some clients look for it... */
1715 serv_puts("MIME-Version: 1.0");
1716 serv_puts("X-Mailer: " PACKAGE_STRING);
1718 /* If there are attachments, we have to do multipart/mixed */
1719 if (GetCount(WCC->attachments) > 0) {
1724 /* Remember, serv_printf() appends an extra newline */
1725 serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
1726 serv_printf("This is a multipart message in MIME format.\n");
1727 serv_printf("--%s", top_boundary);
1730 /* Remember, serv_printf() appends an extra newline */
1731 serv_printf("Content-type: multipart/alternative; "
1732 "boundary=\"%s\"\n", alt_boundary);
1733 serv_printf("This is a multipart message in MIME format.\n");
1734 serv_printf("--%s", alt_boundary);
1736 serv_puts("Content-type: text/plain; charset=utf-8");
1737 serv_puts("Content-Transfer-Encoding: quoted-printable");
1739 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
1740 text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */
1743 serv_printf("--%s", alt_boundary);
1745 serv_puts("Content-type: text/html; charset=utf-8");
1746 serv_puts("Content-Transfer-Encoding: quoted-printable");
1748 serv_puts("<html><body>\r\n");
1749 text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */
1750 serv_puts("</body></html>\r\n");
1752 serv_printf("--%s--", alt_boundary);
1760 /* Add in the attachments */
1761 it = GetNewHashPos();
1762 while (GetNextHashPos(WCC->attachments, it, &len, &Key, &vAtt)) {
1763 att = (wc_attachment*)vAtt;
1764 encoded_length = ((att->length * 150) / 100);
1765 encoded = malloc(encoded_length);
1766 if (encoded == NULL) break;
1767 encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1);
1769 serv_printf("--%s", top_boundary);
1770 serv_printf("Content-type: %s", ChrPtr(att->content_type));
1771 serv_printf("Content-disposition: attachment; filename=\"%s\"", ChrPtr(att->filename));
1772 serv_puts("Content-transfer-encoding: base64");
1774 serv_write(encoded, encoded_strlen);
1779 serv_printf("--%s--", top_boundary);
1788 * Post message (or don't post message)
1790 * Note regarding the "dont_post" variable:
1791 * A random value (actually, it's just a timestamp) is inserted as a hidden
1792 * field called "postseq" when the display_enter page is generated. This
1793 * value is checked when posting, using the static variable dont_post. If a
1794 * user attempts to post twice using the same dont_post value, the message is
1795 * discarded. This prevents the accidental double-saving of the same message
1796 * if the user happens to click the browser "back" button.
1798 void post_message(void)
1801 StrBuf *encoded_subject = NULL;
1802 static long dont_post = (-1L);
1804 int is_anonymous = 0;
1805 const StrBuf *display_name = NULL;
1806 struct wcsession *WCC = WC;
1808 if (havebstr("force_room")) {
1809 gotoroom(bstr("force_room"));
1812 if (havebstr("display_name")) {
1813 display_name = sbstr("display_name");
1814 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
1815 display_name = NULL;
1820 if (WCC->upload_length > 0) {
1825 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WCC->upload_length);
1826 /** There's an attachment. Save it to this struct... */
1827 att = malloc(sizeof(wc_attachment));
1828 memset(att, 0, sizeof(wc_attachment));
1829 att->length = WCC->upload_length;
1830 att->content_type = NewStrBufPlain(WCC->upload_content_type, -1);
1831 att->filename = NewStrBufPlain(WCC->upload_filename, -1);
1834 if (WCC->attachments == NULL)
1835 WCC->attachments = NewHash(1, NULL);
1836 /* And add it to the list. */
1837 n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
1838 Put(WCC->attachments, N, n, att, free_attachment);
1841 * Mozilla sends a simple filename, which is what we want,
1842 * but Satan's Browser sends an entire pathname. Reduce
1843 * the path to just a filename if we need to.
1845 pch = strrchr(ChrPtr(att->filename), '/');
1847 StrBufCutLeft(att->filename, pch - ChrPtr(att->filename));
1849 pch = strrchr(ChrPtr(att->filename), '\\');
1851 StrBufCutLeft(att->filename, pch - ChrPtr(att->filename));
1855 * Transfer control of this memory from the upload struct
1856 * to the attachment struct.
1858 att->data = WCC->upload;
1859 WCC->upload_length = 0;
1865 if (havebstr("cancel_button")) {
1866 sprintf(WCC->ImportantMessage,
1867 _("Cancelled. Message was not posted."));
1868 } else if (havebstr("attach_button")) {
1871 } else if (lbstr("postseq") == dont_post) {
1872 sprintf(WCC->ImportantMessage,
1873 _("Automatically cancelled because you have already "
1874 "saved this message."));
1876 const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s";
1877 const StrBuf *Recp = NULL;
1878 const StrBuf *Cc = NULL;
1879 const StrBuf *Bcc = NULL;
1880 const StrBuf *Wikipage = NULL;
1881 const StrBuf *my_email_addr = NULL;
1882 StrBuf *CmdBuf = NULL;;
1883 StrBuf *references = NULL;
1885 if (havebstr("references"))
1887 const StrBuf *ref = sbstr("references");
1888 references = NewStrBufPlain(ChrPtr(ref), StrLength(ref));
1889 lprintf(9, "Converting: %s\n", ChrPtr(references));
1890 StrBufReplaceChars(references, '|', '!');
1891 lprintf(9, "Converted: %s\n", ChrPtr(references));
1893 if (havebstr("subject")) {
1896 * make enough room for the encoded string;
1897 * plus the QP header
1899 Subj = sbstr("subject");
1901 StrBufRFC2047encode(&encoded_subject, Subj);
1903 Recp = sbstr("recp");
1906 Wikipage = sbstr("wikipage");
1907 my_email_addr = sbstr("my_email_addr");
1909 CmdBuf = NewStrBufPlain(NULL,
1912 StrLength(encoded_subject) +
1915 StrLength(Wikipage) +
1916 StrLength(my_email_addr) +
1917 StrLength(references));
1919 StrBufPrintf(CmdBuf,
1923 ChrPtr(encoded_subject),
1924 ChrPtr(display_name),
1928 ChrPtr(my_email_addr),
1929 ChrPtr(references));
1930 FreeStrBuf(&references);
1932 lprintf(9, "%s\n", CmdBuf);
1933 serv_puts(ChrPtr(CmdBuf));
1934 serv_getln(buf, sizeof buf);
1935 FreeStrBuf(&CmdBuf);
1936 FreeStrBuf(&encoded_subject);
1937 if (buf[0] == '4') {
1938 post_mime_to_server();
1939 if ( (havebstr("recp"))
1940 || (havebstr("cc" ))
1941 || (havebstr("bcc" ))
1943 sprintf(WCC->ImportantMessage, _("Message has been sent.\n"));
1946 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
1948 dont_post = lbstr("postseq");
1950 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
1951 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1957 DeleteHash(&WCC->attachments);
1960 * We may have been supplied with instructions regarding the location
1961 * to which we must return after posting. If found, go there.
1963 if (havebstr("return_to")) {
1964 http_redirect(bstr("return_to"));
1967 * If we were editing a page in a wiki room, go to that page now.
1969 else if (havebstr("wikipage")) {
1970 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
1974 * Otherwise, just go to the "read messages" loop.
1977 readloop("readnew");
1985 * \brief display the message entry screen
1987 void display_enter(void)
1991 const StrBuf *display_name = NULL;
1992 /////wc_attachment *att;
1993 int recipient_required = 0;
1994 int subject_required = 0;
1995 int recipient_bad = 0;
1996 int is_anonymous = 0;
1998 struct wcsession *WCC = WC;
2002 if (havebstr("force_room")) {
2003 gotoroom(bstr("force_room"));
2006 display_name = sbstr("display_name");
2007 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
2008 display_name = NULL;
2012 /** First test to see whether this is a room that requires recipients to be entered */
2013 serv_puts("ENT0 0");
2014 serv_getln(buf, sizeof buf);
2016 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
2017 recipient_required = 1;
2019 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2020 sprintf(WCC->ImportantMessage, "%s", &buf[4]);
2021 readloop("readnew");
2025 /* Is the server strongly recommending that the user enter a message subject? */
2026 if ((buf[3] != '\0') && (buf[4] != '\0')) {
2027 subject_required = extract_int(&buf[4], 1);
2031 * Are we perhaps in an address book view? If so, then an "enter
2032 * message" command really means "add new entry."
2034 if (WCC->wc_default_view == VIEW_ADDRESSBOOK) {
2035 do_edit_vcard(-1, "", "", WCC->wc_roomname);
2040 * Are we perhaps in a calendar room? If so, then an "enter
2041 * message" command really means "add new calendar item."
2043 if (WCC->wc_default_view == VIEW_CALENDAR) {
2044 display_edit_event();
2049 * Are we perhaps in a tasks view? If so, then an "enter
2050 * message" command really means "add new task."
2052 if (WCC->wc_default_view == VIEW_TASKS) {
2053 display_edit_task();
2058 * Otherwise proceed normally.
2059 * Do a custom room banner with no navbar...
2062 if (recipient_required) {
2063 const StrBuf *Recp = NULL;
2064 const StrBuf *Cc = NULL;
2065 const StrBuf *Bcc = NULL;
2066 const StrBuf *Wikipage = NULL;
2067 StrBuf *CmdBuf = NULL;;
2068 const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
2070 Recp = sbstr("recp");
2073 Wikipage = sbstr("wikipage");
2075 CmdBuf = NewStrBufPlain(NULL,
2078 StrLength(display_name) +
2081 StrLength(Wikipage));
2083 StrBufPrintf(CmdBuf,
2087 ChrPtr(display_name),
2091 serv_puts(ChrPtr(CmdBuf));
2092 serv_getln(buf, sizeof buf);
2093 FreeStrBuf(&CmdBuf);
2095 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
2096 if (havebstr("recp") &&
2102 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2103 wprintf("<em>%s</em><br />\n", &buf[4]);/// -> important message
2107 svputlong("RCPTREQUIRED", recipient_required);
2108 svputlong("SUBJREQUIRED", recipient_required || subject_required);
2111 output_headers(1, 0, 0, 0, 1, 0);
2112 DoTemplate(HKEY("edit_message"), NULL, NULL, CTX_NONE);
2119 * \brief delete a message
2121 void delete_msg(void)
2126 msgid = lbstr("msgid");
2128 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
2129 serv_printf("DELE %ld", msgid);
2131 else { /** Otherwise move it to Trash */
2132 serv_printf("MOVE %ld|_TRASH_|0", msgid);
2135 serv_getln(buf, sizeof buf);
2136 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2138 readloop("readnew");
2143 * \brief move a message to another folder
2150 msgid = lbstr("msgid");
2152 if (havebstr("move_button")) {
2153 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
2155 serv_getln(buf, sizeof buf);
2156 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2158 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
2161 readloop("readnew");
2169 * Confirm move of a message
2171 void confirm_move_msg(void)
2177 msgid = lbstr("msgid");
2180 output_headers(1, 1, 2, 0, 0, 0);
2181 wprintf("<div id=\"banner\">\n");
2183 wprintf(_("Confirm move of message"));
2185 wprintf("</div>\n");
2187 wprintf("<div id=\"content\" class=\"service\">\n");
2189 wprintf("<CENTER>");
2191 wprintf(_("Move this message to:"));
2192 wprintf("<br />\n");
2194 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
2195 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2196 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
2198 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
2200 serv_getln(buf, sizeof buf);
2201 if (buf[0] == '1') {
2202 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2203 extract_token(targ, buf, 0, '|', sizeof targ);
2204 wprintf("<OPTION>");
2209 wprintf("</SELECT>\n");
2210 wprintf("<br />\n");
2212 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
2214 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
2215 wprintf("</form></CENTER>\n");
2217 wprintf("</CENTER>\n");
2221 void readnew(void) { readloop("readnew");}
2222 void readold(void) { readloop("readold");}
2223 void readfwd(void) { readloop("readfwd");}
2224 void headers(void) { readloop("headers");}
2225 void do_search(void) { readloop("do_search");}
2236 WebcitAddUrlHandler(HKEY("readnew"), readnew, 0);
2237 WebcitAddUrlHandler(HKEY("readold"), readold, 0);
2238 WebcitAddUrlHandler(HKEY("readfwd"), readfwd, 0);
2239 WebcitAddUrlHandler(HKEY("headers"), headers, 0);
2240 WebcitAddUrlHandler(HKEY("do_search"), do_search, 0);
2241 WebcitAddUrlHandler(HKEY("display_enter"), display_enter, 0);
2242 WebcitAddUrlHandler(HKEY("post"), post_message, 0);
2243 WebcitAddUrlHandler(HKEY("move_msg"), move_msg, 0);
2244 WebcitAddUrlHandler(HKEY("delete_msg"), delete_msg, 0);
2245 WebcitAddUrlHandler(HKEY("confirm_move_msg"), confirm_move_msg, 0);
2246 WebcitAddUrlHandler(HKEY("msg"), embed_message, NEED_URL|AJAX);
2247 WebcitAddUrlHandler(HKEY("printmsg"), print_message, NEED_URL);
2248 WebcitAddUrlHandler(HKEY("mobilemsg"), mobile_message_view, NEED_URL);
2249 WebcitAddUrlHandler(HKEY("msgheaders"), display_headers, NEED_URL);