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);
358 /* strip the bare contenttype, so we ommit charset etc. */
359 StrBufExtract_token(Buf, Msg->MsgBody->ContentType, 0, ';');
361 if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
363 RenderMimeFunc Render;
364 Render = (RenderMimeFunc)vHdr;
365 Render(Msg->MsgBody, NULL, FoundCharset);
368 if (StrLength(Msg->reply_references)> 0) {
369 /* Trim down excessively long lists of thread references. We eliminate the
370 * second one in the list so that the thread root remains intact.
372 int rrtok = num_tokens(ChrPtr(Msg->reply_references), '|');
373 int rrlen = StrLength(Msg->reply_references);
374 if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
375 remove_token(reply_references, 1, '|');////todo
379 /* Generate a reply-to address */
380 if (StrLength(Msg->Rfca) > 0) {
381 if (Msg->reply_to == NULL)
382 Msg->reply_to = NewStrBuf();
383 if (StrLength(Msg->from) > 0) {
384 StrBufPrintf(Msg->reply_to, "%s <%s>", ChrPtr(Msg->from), ChrPtr(Msg->Rfca));
387 FlushStrBuf(Msg->reply_to);
388 StrBufAppendBuf(Msg->reply_to, Msg->Rfca, 0);
393 if ((StrLength(Msg->OtherNode)>0) &&
394 (strcasecmp(ChrPtr(Msg->OtherNode), serv_info.serv_nodename)) &&
395 (strcasecmp(ChrPtr(Msg->OtherNode), serv_info.serv_humannode)) )
397 if (Msg->reply_to == NULL)
398 Msg->reply_to = NewStrBuf();
399 StrBufPrintf(Msg->reply_to,
402 ChrPtr(Msg->OtherNode));
405 if (Msg->reply_to == NULL)
406 Msg->reply_to = NewStrBuf();
407 FlushStrBuf(Msg->reply_to);
408 StrBufAppendBuf(Msg->reply_to, Msg->from, 0);
411 it = GetNewHashPos();
412 while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) &&
414 wc_mime_attachment *Mime = (wc_mime_attachment*) vMime;
415 evaluate_mime_part(Msg, Mime);
419 DoTemplate(tmpl, tmpllen, Target, Msg, CTX_MAILSUM);
421 DestroyMessageSummary(Msg);
422 FreeStrBuf(&FoundCharset);
423 FreeStrBuf(&HdrToken);
431 * Unadorned HTML output of an individual message, suitable
432 * for placing in a hidden iframe, for printing, or whatever
434 * msgnum_as_string == Message number, as a string instead of as a long int
436 void embed_message(void) {
438 const StrBuf *Tmpl = sbstr("template");
440 msgnum = StrTol(WC->UrlFragment1);
441 if (StrLength(Tmpl) > 0)
442 read_message(WC->WBuf, SKEY(Tmpl), msgnum, 0, NULL);
444 read_message(WC->WBuf, HKEY("view_message"), msgnum, 0, NULL);
449 * Printable view of a message
451 * msgnum_as_string == Message number, as a string instead of as a long int
453 void print_message(void) {
456 msgnum = StrTol(WC->UrlFragment1);
457 output_headers(0, 0, 0, 0, 0, 0);
459 hprintf("Content-type: text/html\r\n"
460 "Server: " PACKAGE_STRING "\r\n"
461 "Connection: close\r\n");
465 read_message(WC->WBuf, HKEY("view_message_print"), msgnum, 1, NULL);
471 * Mobile browser view of message
473 * @param msg_num_as_string Message number as a string instead of as a long int
475 void mobile_message_view(void) {
477 msgnum = StrTol(WC->UrlFragment1);
478 output_headers(1, 0, 0, 0, 0, 1);
480 do_template("msgcontrols", NULL);
481 read_message(WC->WBuf, HKEY("view_message"), msgnum,1, NULL);
486 * \brief Display a message's headers
488 * \param msgnum_as_string Message number, as a string instead of as a long int
490 void display_headers(void) {
494 msgnum = StrTol(WC->UrlFragment1);
495 output_headers(0, 0, 0, 0, 0, 0);
497 hprintf("Content-type: text/plain\r\n"
499 "Connection: close\r\n",
503 serv_printf("MSG2 %ld|3", msgnum);
504 serv_getln(buf, sizeof buf);
506 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
507 wprintf("%s\n", buf);
517 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
518 * or 'reply quoted' operations.
520 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
521 * in this function. Doing so would throw a JavaScript error in the
522 * 'supplied text' argument to the editor.
524 * \param msgnum Message number of the message we want to quote
525 * \param forward_attachments Nonzero if we want attachments to be forwarded
527 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
528 struct wcsession *WCC = WC;
530 char mime_partnum[256];
531 char mime_filename[256];
532 char mime_content_type[256];
533 char mime_charset[256];
534 char mime_disposition[256];
536 char *attachments = NULL;
538 int num_attachments = 0;
540 char m_subject[1024];
552 iconv_t ic = (iconv_t)(-1) ;
553 char *ibuf; /**< Buffer of characters to be converted */
554 char *obuf; /**< Buffer for converted characters */
555 size_t ibuflen; /**< Length of input buffer */
556 size_t obuflen; /**< Length of output buffer */
557 char *osav; /**< Saved pointer to output buffer */
563 strcpy(reply_to, "");
564 strcpy(mime_content_type, "text/plain");
565 strcpy(mime_charset, "us-ascii");
567 serv_printf("MSG4 %ld", msgnum);
568 serv_getln(buf, sizeof buf);
570 wprintf(_("ERROR:"));
571 wprintf("%s<br />", &buf[4]);
575 strcpy(m_subject, "");
577 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
578 if (!strcmp(buf, "000")) {
579 wprintf("%s (3)", _("unexpected end of message"));
582 if (include_headers) {
583 if (!strncasecmp(buf, "nhdr=yes", 8))
587 if (!strncasecmp(buf, "type=", 5))
588 format_type = atoi(&buf[5]);
589 if (!strncasecmp(buf, "from=", 5)) {
590 strcpy(from, &buf[5]);
592 utf8ify_rfc822_string(from);
595 if (!strncasecmp(buf, "subj=", 5)) {
596 strcpy(m_subject, &buf[5]);
598 if ((!strncasecmp(buf, "hnod=", 5))
599 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
600 wprintf("(%s) ", &buf[5]);
602 if ((!strncasecmp(buf, "room=", 5))
603 && (strcasecmp(&buf[5], WC->wc_roomname))
604 && (!IsEmptyStr(&buf[5])) ) {
606 wprintf("%s> ", &buf[5]);
608 if (!strncasecmp(buf, "rfca=", 5)) {
609 strcpy(rfca, &buf[5]);
614 if (!strncasecmp(buf, "node=", 5)) {
615 strcpy(node, &buf[5]);
616 if ( ((WC->room_flags & QR_NETWORK)
617 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
618 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
619 && (IsEmptyStr(rfca))
621 wprintf("@%s ", &buf[5]);
624 if (!strncasecmp(buf, "rcpt=", 5)) {
627 utf8ify_rfc822_string(to);
630 if (!strncasecmp(buf, "time=", 5)) {
631 webcit_fmt_date(now, atol(&buf[5]), 0);
637 * Save attachment info for later. We can't start downloading them
638 * yet because we're in the middle of a server transaction.
640 if (!strncasecmp(buf, "part=", 5)) {
641 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
644 sprintf(ptr, "%s%s\n",
645 ((attachments != NULL) ? attachments : ""),
650 lprintf(9, "attachments=<%s>\n", attachments);
656 if (include_headers) {
659 utf8ify_rfc822_string(m_subject);
660 if (!IsEmptyStr(m_subject)) {
661 wprintf(_("Subject:"));
663 msgescputs(m_subject);
674 * Learn the content type
676 strcpy(mime_content_type, "text/plain");
677 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
678 if (!strcmp(buf, "000")) {
679 wprintf("%s (4)", _("unexpected end of message"));
682 if (!strncasecmp(buf, "Content-type: ", 14)) {
684 safestrncpy(mime_content_type, &buf[14],
685 sizeof(mime_content_type));
686 for (i=0; i<strlen(mime_content_type); ++i) {
687 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
688 safestrncpy(mime_charset, &mime_content_type[i+8],
689 sizeof mime_charset);
692 len = strlen(mime_content_type);
693 for (i=0; i<len; ++i) {
694 if (mime_content_type[i] == ';') {
695 mime_content_type[i] = 0;
699 len = strlen(mime_charset);
700 for (i=0; i<len; ++i) {
701 if (mime_charset[i] == ';') {
709 /** Set up a character set conversion if we need to (and if we can) */
711 if ( (strcasecmp(mime_charset, "us-ascii"))
712 && (strcasecmp(mime_charset, "UTF-8"))
713 && (strcasecmp(mime_charset, ""))
715 ctdl_iconv_open("UTF-8", mime_charset, &ic);
716 if (ic == (iconv_t)(-1) ) {
717 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
718 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
723 /** Messages in legacy Citadel variformat get handled thusly... */
724 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
728 /* Boring old 80-column fixed format text gets handled this way... */
729 else if (!strcasecmp(mime_content_type, "text/plain")) {
730 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
733 if ((len > 0) && (buf[len-1] == '\n')) buf[--len] = 0;
734 if ((len > 0) && (buf[len-1] == '\r')) buf[--len] = 0;
737 if (ic != (iconv_t)(-1) ) {
741 obuf = (char *) malloc(obuflen);
743 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
744 osav[SIZ-obuflen] = 0;
745 safestrncpy(buf, osav, sizeof buf);
751 while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
754 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
755 wprintf("<blockquote>");
757 } else if ((bq == 1) &&
758 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
759 wprintf("</blockquote>");
763 url(buf, sizeof(buf));
765 wprintf("</tt><br />");
767 wprintf("</i><br />");
770 /** HTML just gets escaped and stuffed back into the editor */
771 else if (!strcasecmp(mime_content_type, "text/html")) {
772 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
776 }//// TODO: charset? utf8?
778 /** Unknown weirdness ... don't know how to handle this content type */
780 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
784 /** end of body handler */
787 * If there were attachments, we have to download them and insert them
788 * into the attachment chain for the forwarded message we are composing.
790 if ( (forward_attachments) && (num_attachments) ) {
791 for (i=0; i<num_attachments; ++i) {
792 extract_token(buf, attachments, i, '\n', sizeof buf);
793 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
794 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
795 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
796 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
797 mime_length = extract_int(buf, 5);
800 * tracing ... uncomment if necessary
803 lprintf(9, "fwd filename: %s\n", mime_filename);
804 lprintf(9, "fwd partnum : %s\n", mime_partnum);
805 lprintf(9, "fwd conttype: %s\n", mime_content_type);
806 lprintf(9, "fwd dispose : %s\n", mime_disposition);
807 lprintf(9, "fwd length : %d\n", mime_length);
809 if ( (!strcasecmp(mime_disposition, "inline"))
810 || (!strcasecmp(mime_disposition, "attachment")) ) {
814 /* Create an attachment struct from this mime part... */
815 att = malloc(sizeof(wc_attachment));
816 memset(att, 0, sizeof(wc_attachment));
817 att->length = mime_length;
818 att->content_type = NewStrBufPlain(mime_content_type, -1);
819 att->filename = NewStrBufPlain(mime_filename, -1);
820 att->data = load_mimepart(msgnum, mime_partnum);
822 if (WCC->attachments == NULL)
823 WCC->attachments = NewHash(1, NULL);
824 /* And add it to the list. */
825 n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
826 Put(WCC->attachments, N, n, att, free_attachment);
833 if (ic != (iconv_t)(-1) ) {
838 if (attachments != NULL) {
846 message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSubject, long MsgNum)
849 MsgPartEvaluatorFunc Eval;
850 message_summary *Msg;
859 serv_printf("MSG0 %ld|1", MsgNum); /* ask for headers only */
861 StrBuf_ServGetln(Buf);
862 if (GetServerStatus(Buf, NULL) == 1) {
867 Msg = (message_summary*)malloc(sizeof(message_summary));
868 memset(Msg, 0, sizeof(message_summary));
869 while (len = StrBuf_ServGetln(Buf),
871 strcmp(ChrPtr(Buf), "000")== 0)){
873 ebuf = strchr(ChrPtr(Buf), '=');
875 if (GetHash(MsgEvaluators, buf, nBuf, &vEval) && vEval != NULL) {
876 Eval = (MsgPartEvaluatorFunc) vEval;
877 StrBufCutLeft(Buf, nBuf + 1);
880 else lprintf(1, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
887 * \brief display the adressbook overview
888 * \param msgnum the citadel message number
889 * \param alpha what????
891 void display_addressbook(long msgnum, char alpha) {
893 /* char mime_partnum[SIZ]; */
894 /* char mime_filename[SIZ]; */
895 /* char mime_content_type[SIZ]; */
896 ///char mime_disposition[SIZ];
898 char vcard_partnum[SIZ];
899 char *vcard_source = NULL;
900 message_summary summ;////TODO: this will leak
902 memset(&summ, 0, sizeof(summ));
903 ///safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
904 ///Load Message headers
906 if (!IsEmptyStr(vcard_partnum)) {
907 vcard_source = load_mimepart(msgnum, vcard_partnum);
908 if (vcard_source != NULL) {
910 /** Display the summary line */
911 display_vcard(WC->WBuf, vcard_source, alpha, 0, NULL,msgnum);
913 /** If it's my vCard I can edit it */
914 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
915 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
916 || (WC->wc_view == VIEW_ADDRESSBOOK)
918 wprintf("<a href=\"edit_vcard?"
919 "msgnum=%ld&partnum=%s\">",
920 msgnum, vcard_partnum);
921 wprintf("[%s]</a>", _("edit"));
933 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
934 * \param namebuf name to analyze, reverse if nescessary
936 void lastfirst_firstlast(char *namebuf) {
941 if (namebuf == NULL) return;
942 if (strchr(namebuf, ';') != NULL) return;
944 i = num_tokens(namebuf, ' ');
947 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
948 remove_token(namebuf, i-1, ' ');
949 strcpy(firstname, namebuf);
950 sprintf(namebuf, "%s; %s", lastname, firstname);
954 * \brief fetch what??? name
955 * \param msgnum the citadel message number
956 * \param namebuf where to put the name in???
958 void fetch_ab_name(message_summary *Msg, char *namebuf) {
960 char mime_partnum[SIZ];
961 char mime_filename[SIZ];
962 char mime_content_type[SIZ];
963 char mime_disposition[SIZ];
965 char vcard_partnum[SIZ];
966 char *vcard_source = NULL;
968 message_summary summ;/// TODO this will lak
970 if (namebuf == NULL) return;
973 memset(&summ, 0, sizeof(summ));
974 //////safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
976 sprintf(buf, "MSG0 %ld|0", Msg->msgnum); /** unfortunately we need the mime info now */
978 serv_getln(buf, sizeof buf);
979 if (buf[0] != '1') return;
981 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
982 if (!strncasecmp(buf, "part=", 5)) {
983 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
984 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
985 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
986 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
987 mime_length = extract_int(&buf[5], 5);
989 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
990 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
991 strcpy(vcard_partnum, mime_partnum);
997 if (!IsEmptyStr(vcard_partnum)) {
998 vcard_source = load_mimepart(Msg->msgnum, vcard_partnum);
999 if (vcard_source != NULL) {
1001 /* Grab the name off the card */
1002 display_vcard(WC->WBuf, vcard_source, 0, 0, namebuf, Msg->msgnum);
1008 lastfirst_firstlast(namebuf);
1010 len = strlen(namebuf);
1011 for (i=0; i<len; ++i) {
1012 if (namebuf[i] != ';') return;
1014 strcpy(namebuf, _("(no name)"));
1022 * load message pointers from the server for a "read messages" operation
1024 * servcmd: the citadel command to send to the citserver
1025 * with_headers: also include some of the headers with the message numbers (more expensive)
1027 int load_msg_ptrs(char *servcmd, int with_headers)
1029 StrBuf* FoundCharset = NULL;
1030 struct wcsession *WCC = WC;
1031 message_summary *Msg;
1034 ///time_t datestamp;
1035 //char fullname[128];
1036 //char nodename[128];
1037 //char inetaddr[128];
1038 //char subject[1024];
1045 ////int num_summ_alloc = 0;
1047 if (WCC->summ != NULL) {
1048 if (WCC->summ != NULL)
1049 DeleteHash(&WCC->summ);
1051 WCC->summ = NewHash(1, Flathash);
1053 maxload = 1000;/// TODO
1057 StrBuf_ServGetln(Buf);
1058 if (GetServerStatus(Buf, NULL) != 1) {
1062 // TODO if (with_headers) { //// TODO: Have Attachments?
1064 while (len = StrBuf_ServGetln(Buf),
1066 strcmp(ChrPtr(Buf), "000")!= 0))
1068 if (nummsgs < maxload) {
1069 Msg = (message_summary*)malloc(sizeof(message_summary));
1070 memset(Msg, 0, sizeof(message_summary));
1072 Msg->msgnum = StrBufExtract_long(Buf, 0, '|');
1073 Msg->date = StrBufExtract_long(Buf, 1, '|');
1075 Msg->from = NewStrBufPlain(NULL, StrLength(Buf));
1076 StrBufExtract_token(Buf2, Buf, 2, '|');
1077 if (StrLength(Buf2) != 0) {
1078 /** Handle senders with RFC2047 encoding */
1079 StrBuf_RFC822_to_Utf8(Msg->from, Buf2, WCC->DefaultCharset, FoundCharset);
1083 StrBufExtract_token(Buf2, Buf, 3, '|');
1084 if ((StrLength(Buf2) !=0 ) &&
1085 ( ((WCC->room_flags & QR_NETWORK)
1086 || ((strcasecmp(ChrPtr(Buf2), serv_info.serv_nodename)
1087 && (strcasecmp(ChrPtr(Buf2), serv_info.serv_fqdn)))))))
1089 StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
1090 StrBufAppendBuf(Msg->from, Buf2, 0);
1094 StrBufExtract_token(Msg->inetaddr, Buf, 4, '|');
1097 Msg->subj = NewStrBufPlain(NULL, StrLength(Buf));
1098 StrBufExtract_token(Buf2, Buf, 5, '|');
1099 if (StrLength(Buf2) == 0)
1100 StrBufAppendBufPlain(Msg->subj, _("(no subj)"), 0, -1);
1102 StrBuf_RFC822_to_Utf8(Msg->subj, Buf2, WCC->DefaultCharset, FoundCharset);
1103 if ((StrLength(Msg->subj) > 75) &&
1104 (StrBuf_Utf8StrLen(Msg->subj) > 75)) {
1105 StrBuf_Utf8StrCut(Msg->subj, 72);
1106 StrBufAppendBufPlain(Msg->subj, HKEY("..."), 0);
1111 if ((StrLength(Msg->from) > 25) &&
1112 (StrBuf_Utf8StrLen(Msg->from) > 25)) {
1113 StrBuf_Utf8StrCut(Msg->from, 23);
1114 StrBufAppendBufPlain(Msg->from, HKEY("..."), 0);
1117 Put(WCC->summ, (const char *)&n, sizeof(n), Msg, DestroyMessageSummary);
1132 * command loop for reading messages
1134 * Set oper to "readnew" or "readold" or "readfwd" or "headers"
1136 void readloop(char *oper)
1139 message_summary *Msg;
1148 long *displayed_msgs = NULL;
1149 int num_displayed = 0;
1151 int is_addressbook = 0;
1152 int is_singlecard = 0;
1153 int is_calendar = 0;
1154 struct calview calv;
1159 int lowest_displayed = (-1);
1160 int highest_displayed = 0;
1161 addrbookent *addrbook = NULL;
1163 const StrBuf *sortby = NULL;
1165 int SortBy = eRDate;
1166 const StrBuf *sortpref_value;
1167 int bbs_reverse = 0;
1168 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
1170 const char *HashKey;
1173 if (WCC->wc_view == VIEW_WIKI) {
1174 sprintf(buf, "wiki?room=%s&page=home", WCC->wc_roomname);
1179 startmsg = lbstr("startmsg");
1180 maxmsgs = ibstr("maxmsgs");
1181 is_summary = (ibstr("is_summary") && !WCC->is_mobile);
1182 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1184 sortpref_value = get_room_pref("sort");
1186 sortby = sbstr("sortby");
1187 if ( (!IsEmptyStr(ChrPtr(sortby))) &&
1188 (strcasecmp(ChrPtr(sortby), ChrPtr(sortpref_value)) != 0)) {
1189 set_room_pref("sort", NewStrBufDup(sortby), 1);
1190 sortpref_value = NULL;
1191 sortpref_value = sortby;
1194 SortBy = StrToESort(sortpref_value);
1195 /* message board sort */
1196 if (SortBy == eReverse) {
1203 output_headers(1, 1, 1, 0, 0, 0);
1206 * When in summary mode, always show ALL messages instead of just
1207 * new or old. Otherwise, show what the user asked for.
1209 if (!strcmp(oper, "readnew")) {
1210 strcpy(cmd, "MSGS NEW");
1212 else if (!strcmp(oper, "readold")) {
1213 strcpy(cmd, "MSGS OLD");
1215 else if (!strcmp(oper, "do_search")) {
1216 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
1219 strcpy(cmd, "MSGS ALL");
1222 if ((WCC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1) && !WCC->is_mobile) {
1224 if (!strcmp(oper, "do_search")) {
1225 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
1228 strcpy(cmd, "MSGS ALL");
1232 if ((WCC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
1234 if (!strcmp(oper, "do_search")) {
1235 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
1238 strcpy(cmd, "MSGS ALL");
1243 if (is_summary) { /**< fetch header summary */
1244 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
1245 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
1246 (!strcmp(oper, "do_search") ? bstr("query") : "")
1251 if (WCC->is_mobile) {
1253 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
1254 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
1255 (!strcmp(oper, "do_search") ? bstr("query") : "")
1261 * Are we doing a summary view? If so, we need to know old messages
1262 * and new messages, so we can do that pretty boldface thing for the
1265 strcpy(old_msgs, "");
1266 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){
1268 serv_getln(buf, sizeof buf);
1269 if (buf[0] == '2') {
1270 strcpy(old_msgs, &buf[4]);
1274 is_singlecard = ibstr("is_singlecard");
1276 if (WCC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
1278 strcpy(cmd, "MSGS ALL|||1");
1280 parse_calendar_view_request(&calv);
1282 if (WCC->wc_default_view == VIEW_TASKS) { /**< tasks */
1284 strcpy(cmd, "MSGS ALL");
1287 if (WCC->wc_default_view == VIEW_NOTES) { /**< notes */
1289 strcpy(cmd, "MSGS ALL");
1294 wprintf("<div id=\"new_notes_here\"></div>\n");
1297 nummsgs = load_msg_ptrs(cmd, (is_summary || WCC->is_mobile));
1300 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
1301 wprintf("<div align=\"center\"><br /><em>");
1302 if (!strcmp(oper, "readnew")) {
1303 wprintf(_("No new messages."));
1304 } else if (!strcmp(oper, "readold")) {
1305 wprintf(_("No old messages."));
1307 wprintf(_("No messages here."));
1309 wprintf("</em><br /></div>\n");
1315 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){
1317 message_summary *Msg;
1319 at = GetNewHashPos();
1320 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
1321 /** Are you a new message, or an old message? */
1322 Msg = (message_summary*) vMsg;
1324 if (is_msg_in_mset(old_msgs, Msg->msgnum)) {
1335 if (startmsg == 0L) {
1337 startmsg = WCC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
1340 startmsg = WCC->msgarr[0];
1344 if (is_summary || WCC->is_mobile) {
1345 SortByPayload(WCC->summ, SortFuncs[SortBy]);
1350 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
1351 " document.onkeydown = CtdlMsgListKeyPress; "
1352 " if (document.layers) { "
1353 " document.captureEvents(Event.KEYPRESS); "
1358 /** note that Date and Delete are now in the same column */
1359 wprintf("<div id=\"message_list_hdr\">"
1360 "<div class=\"fix_scrollbar_bug\">"
1361 "<table cellspacing=0 style=\"width:100%%\">"
1364 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"
1365 "<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> </th>\n"
1366 "<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> \n"
1368 "<input type=\"submit\" name=\"delete_button\" id=\"delbutton\" "
1369 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
1376 SortByStrings[SubjectInvertSortString[SortBy]],
1377 SortIcons[SortSubjectToIcon[SortBy]],
1378 SENDER_COL_WIDTH_PCT,
1380 SortByStrings[SenderInvertSortString[SortBy]],
1381 SortIcons[SortSenderToIcon[SortBy]],
1382 DATE_PLUS_BUTTONS_WIDTH_PCT,
1384 SortByStrings[DateInvertSortString[SortBy]],
1385 SortIcons[SortDateToIcon[SortBy]],
1388 wprintf("</table></div></div>\n");
1389 wprintf("<div id=\"message_list\">"
1391 "<div class=\"fix_scrollbar_bug\">\n"
1392 "<table class=\"mailbox_summary\" id=\"summary_headers\" "
1393 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
1395 } else if (WCC->is_mobile) {
1396 wprintf("<div id=\"message_list\">");
1401 * Set the "is_bbview" variable if it appears that we are looking at
1402 * a classic bulletin board view.
1404 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
1405 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
1410 * If we're not currently looking at ALL requested
1411 * messages, then display the selector bar
1414 /** begin bbview scroller */
1415 wprintf("<form name=\"msgomatictop\" class=\"selector_top\" > \n <p>");
1416 wprintf(_("Reading #"));//// TODO this isn't used, should it? : , lowest_displayed, highest_displayed);
1418 wprintf("<select name=\"whichones\" size=\"1\" "
1419 "OnChange=\"location.href=msgomatictop.whichones.options"
1420 "[selectedIndex].value\">\n");
1423 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
1425 lo = b - maxmsgs + 2;
1427 wprintf("<option %s value="
1432 "%d-%d</option> \n",
1433 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
1442 for (b=0; b<nummsgs; b = b + maxmsgs) {
1444 hi = b + maxmsgs + 1;
1445 if (hi > nummsgs) hi = nummsgs;
1446 wprintf("<option %s value="
1451 "%d-%d</option> \n",
1452 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
1461 wprintf("<option value=\"%s?startmsg=%ld"
1462 "&maxmsgs=9999999&is_summary=%d\">",
1464 WCC->msgarr[0], is_summary);
1466 wprintf("</option>");
1467 wprintf("</select> ");
1468 wprintf(_("of %d messages."), nummsgs);
1470 /** forward/reverse */
1471 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
1472 "OnChange=\"location.href='%s?sortby=forward'\"",
1473 (bbs_reverse ? "" : "checked"),
1477 wprintf(_("oldest to newest"));
1478 wprintf(" ");
1480 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
1481 "OnChange=\"location.href='%s?sortby=reverse'\"",
1482 (bbs_reverse ? "checked" : ""),
1486 wprintf(_("newest to oldest"));
1489 wprintf("</p></form>\n");
1490 /** end bbview scroller */
1493 at = GetNewHashPos();
1494 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
1495 Msg = (message_summary*) vMsg;
1496 if ((Msg->msgnum >= startmsg) && (num_displayed < maxmsgs)) {
1498 /** Display the message */
1500 DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
1502 else if (is_addressbook) {
1503 fetch_ab_name(Msg, buf);
1505 addrbook = realloc(addrbook,
1506 (sizeof(addrbookent) * num_ab) );
1507 safestrncpy(addrbook[num_ab-1].ab_name, buf,
1508 sizeof(addrbook[num_ab-1].ab_name));
1509 addrbook[num_ab-1].ab_msgnum = Msg->msgnum;
1511 else if (is_calendar) {
1512 load_calendar_item(Msg, Msg->is_new, &calv);
1514 else if (is_tasks) {
1515 display_task(Msg, Msg->is_new);
1517 else if (is_notes) {
1518 display_note(Msg, Msg->is_new);
1519 } else if (WCC->is_mobile) {
1520 DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
1523 if (displayed_msgs == NULL) {
1524 displayed_msgs = malloc(sizeof(long) *
1525 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
1527 displayed_msgs[num_displayed] = Msg->msgnum;
1530 if (lowest_displayed < 0) lowest_displayed = a;
1531 highest_displayed = a;
1539 if (displayed_msgs != NULL) {
1541 qsort(displayed_msgs, num_displayed, sizeof(long), qlongcmp_r);
1544 /** if we do a split bbview in the future, begin messages div here */
1546 for (a=0; a<num_displayed; ++a) {
1547 read_message(WC->WBuf, HKEY("view_message"), displayed_msgs[a], 0, NULL);
1550 /** if we do a split bbview in the future, end messages div here */
1552 free(displayed_msgs);
1553 displayed_msgs = NULL;
1558 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
1559 wprintf("</div>"); /**< end of 'message_list' div */
1561 /** Here's the grab-it-to-resize-the-message-list widget */
1562 wprintf("<div id=\"resize_msglist\" "
1563 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
1564 "<div class=\"fix_scrollbar_bug\"> <hr>"
1568 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
1569 } else if (WCC->is_mobile) {
1574 * Bump these because although we're thinking in zero base, the user
1575 * is a drooling idiot and is thinking in one base.
1578 ++highest_displayed;
1581 * If we're not currently looking at ALL requested
1582 * messages, then display the selector bar
1585 /** begin bbview scroller */
1586 wprintf("<form name=\"msgomatic\" class=\"selector_bottom\" > \n <p>");
1587 wprintf(_("Reading #")); /// TODO: this isn't used: , lowest_displayed, highest_displayed);
1589 wprintf("<select name=\"whichones\" size=\"1\" "
1590 "OnChange=\"location.href=msgomatic.whichones.options"
1591 "[selectedIndex].value\">\n");
1594 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
1596 lo = b - maxmsgs + 2;
1598 wprintf("<option %s value="
1603 "%d-%d</option> \n",
1604 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
1613 for (b=0; b<nummsgs; b = b + maxmsgs) {
1615 hi = b + maxmsgs + 1;
1616 if (hi > nummsgs) hi = nummsgs;
1617 wprintf("<option %s value="
1622 "%d-%d</option> \n",
1623 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
1632 wprintf("<option value=\"%s&startmsg=%ld"
1633 "&maxmsgs=9999999&is_summary=%d\">",
1635 WCC->msgarr[0], is_summary);
1637 wprintf("</option>");
1638 wprintf("</select> ");
1639 wprintf(_("of %d messages."), nummsgs);
1641 /** forward/reverse */
1642 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
1643 "OnChange=\"location.href='%s&sortby=forward'\"",
1644 (bbs_reverse ? "" : "checked"),
1648 wprintf(_("oldest to newest"));
1649 wprintf(" ");
1650 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
1651 "OnChange=\"location.href='%s&sortby=reverse'\"",
1652 (bbs_reverse ? "checked" : ""),
1656 wprintf(_("newest to oldest"));
1659 wprintf("</p></form>\n");
1660 /** end bbview scroller */
1665 do_tasks_view(); /** Render the task list */
1669 render_calendar_view(&calv);
1672 if (is_addressbook) {
1673 do_addrbook_view(addrbook, num_ab); /** Render the address book */
1676 /** Note: wDumpContent() will output one additional </div> tag. */
1677 wprintf("</div>\n"); /** end of 'content' div */
1680 /** free the summary */
1681 if (WCC->summ != NULL) {
1682 DeleteHash(&WCC->summ);
1684 if (addrbook != NULL) free(addrbook);
1689 * Back end for post_message()
1690 * ... this is where the actual message gets transmitted to the server.
1692 void post_mime_to_server(void) {
1693 struct wcsession *WCC = WC;
1694 char top_boundary[SIZ];
1695 char alt_boundary[SIZ];
1696 int is_multipart = 0;
1700 size_t encoded_length;
1701 size_t encoded_strlen;
1702 char *txtmail = NULL;
1704 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
1705 serv_info.serv_fqdn,
1709 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
1710 serv_info.serv_fqdn,
1715 /* RFC2045 requires this, and some clients look for it... */
1716 serv_puts("MIME-Version: 1.0");
1717 serv_puts("X-Mailer: " PACKAGE_STRING);
1719 /* If there are attachments, we have to do multipart/mixed */
1720 if (GetCount(WCC->attachments) > 0) {
1725 /* Remember, serv_printf() appends an extra newline */
1726 serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
1727 serv_printf("This is a multipart message in MIME format.\n");
1728 serv_printf("--%s", top_boundary);
1731 /* Remember, serv_printf() appends an extra newline */
1732 serv_printf("Content-type: multipart/alternative; "
1733 "boundary=\"%s\"\n", alt_boundary);
1734 serv_printf("This is a multipart message in MIME format.\n");
1735 serv_printf("--%s", alt_boundary);
1737 serv_puts("Content-type: text/plain; charset=utf-8");
1738 serv_puts("Content-Transfer-Encoding: quoted-printable");
1740 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
1741 text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */
1744 serv_printf("--%s", alt_boundary);
1746 serv_puts("Content-type: text/html; charset=utf-8");
1747 serv_puts("Content-Transfer-Encoding: quoted-printable");
1749 serv_puts("<html><body>\r\n");
1750 text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */
1751 serv_puts("</body></html>\r\n");
1753 serv_printf("--%s--", alt_boundary);
1761 /* Add in the attachments */
1762 it = GetNewHashPos();
1763 while (GetNextHashPos(WCC->attachments, it, &len, &Key, &vAtt)) {
1764 att = (wc_attachment*)vAtt;
1765 encoded_length = ((att->length * 150) / 100);
1766 encoded = malloc(encoded_length);
1767 if (encoded == NULL) break;
1768 encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1);
1770 serv_printf("--%s", top_boundary);
1771 serv_printf("Content-type: %s", ChrPtr(att->content_type));
1772 serv_printf("Content-disposition: attachment; filename=\"%s\"", ChrPtr(att->filename));
1773 serv_puts("Content-transfer-encoding: base64");
1775 serv_write(encoded, encoded_strlen);
1780 serv_printf("--%s--", top_boundary);
1789 * Post message (or don't post message)
1791 * Note regarding the "dont_post" variable:
1792 * A random value (actually, it's just a timestamp) is inserted as a hidden
1793 * field called "postseq" when the display_enter page is generated. This
1794 * value is checked when posting, using the static variable dont_post. If a
1795 * user attempts to post twice using the same dont_post value, the message is
1796 * discarded. This prevents the accidental double-saving of the same message
1797 * if the user happens to click the browser "back" button.
1799 void post_message(void)
1802 StrBuf *encoded_subject = NULL;
1803 static long dont_post = (-1L);
1805 int is_anonymous = 0;
1806 const StrBuf *display_name = NULL;
1807 struct wcsession *WCC = WC;
1809 if (havebstr("force_room")) {
1810 gotoroom(bstr("force_room"));
1813 if (havebstr("display_name")) {
1814 display_name = sbstr("display_name");
1815 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
1816 display_name = NULL;
1821 if (WCC->upload_length > 0) {
1826 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WCC->upload_length);
1827 /** There's an attachment. Save it to this struct... */
1828 att = malloc(sizeof(wc_attachment));
1829 memset(att, 0, sizeof(wc_attachment));
1830 att->length = WCC->upload_length;
1831 att->content_type = NewStrBufPlain(WCC->upload_content_type, -1);
1832 att->filename = NewStrBufPlain(WCC->upload_filename, -1);
1835 if (WCC->attachments == NULL)
1836 WCC->attachments = NewHash(1, NULL);
1837 /* And add it to the list. */
1838 n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
1839 Put(WCC->attachments, N, n, att, free_attachment);
1842 * Mozilla sends a simple filename, which is what we want,
1843 * but Satan's Browser sends an entire pathname. Reduce
1844 * the path to just a filename if we need to.
1846 pch = strrchr(ChrPtr(att->filename), '/');
1848 StrBufCutLeft(att->filename, pch - ChrPtr(att->filename));
1850 pch = strrchr(ChrPtr(att->filename), '\\');
1852 StrBufCutLeft(att->filename, pch - ChrPtr(att->filename));
1856 * Transfer control of this memory from the upload struct
1857 * to the attachment struct.
1859 att->data = WCC->upload;
1860 WCC->upload_length = 0;
1866 if (havebstr("cancel_button")) {
1867 sprintf(WCC->ImportantMessage,
1868 _("Cancelled. Message was not posted."));
1869 } else if (havebstr("attach_button")) {
1872 } else if (lbstr("postseq") == dont_post) {
1873 sprintf(WCC->ImportantMessage,
1874 _("Automatically cancelled because you have already "
1875 "saved this message."));
1877 const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s";
1878 const StrBuf *Recp = NULL;
1879 const StrBuf *Cc = NULL;
1880 const StrBuf *Bcc = NULL;
1881 const StrBuf *Wikipage = NULL;
1882 const StrBuf *my_email_addr = NULL;
1883 StrBuf *CmdBuf = NULL;;
1884 StrBuf *references = NULL;
1886 if (havebstr("references"))
1888 const StrBuf *ref = sbstr("references");
1889 references = NewStrBufPlain(ChrPtr(ref), StrLength(ref));
1890 lprintf(9, "Converting: %s\n", ChrPtr(references));
1891 StrBufReplaceChars(references, '|', '!');
1892 lprintf(9, "Converted: %s\n", ChrPtr(references));
1894 if (havebstr("subject")) {
1897 * make enough room for the encoded string;
1898 * plus the QP header
1900 Subj = sbstr("subject");
1902 StrBufRFC2047encode(&encoded_subject, Subj);
1904 Recp = sbstr("recp");
1907 Wikipage = sbstr("wikipage");
1908 my_email_addr = sbstr("my_email_addr");
1910 CmdBuf = NewStrBufPlain(NULL,
1913 StrLength(encoded_subject) +
1916 StrLength(Wikipage) +
1917 StrLength(my_email_addr) +
1918 StrLength(references));
1920 StrBufPrintf(CmdBuf,
1924 ChrPtr(encoded_subject),
1925 ChrPtr(display_name),
1929 ChrPtr(my_email_addr),
1930 ChrPtr(references));
1931 FreeStrBuf(&references);
1933 lprintf(9, "%s\n", CmdBuf);
1934 serv_puts(ChrPtr(CmdBuf));
1935 serv_getln(buf, sizeof buf);
1936 FreeStrBuf(&CmdBuf);
1937 FreeStrBuf(&encoded_subject);
1938 if (buf[0] == '4') {
1939 post_mime_to_server();
1940 if ( (havebstr("recp"))
1941 || (havebstr("cc" ))
1942 || (havebstr("bcc" ))
1944 sprintf(WCC->ImportantMessage, _("Message has been sent.\n"));
1947 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
1949 dont_post = lbstr("postseq");
1951 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
1952 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1958 DeleteHash(&WCC->attachments);
1961 * We may have been supplied with instructions regarding the location
1962 * to which we must return after posting. If found, go there.
1964 if (havebstr("return_to")) {
1965 http_redirect(bstr("return_to"));
1968 * If we were editing a page in a wiki room, go to that page now.
1970 else if (havebstr("wikipage")) {
1971 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
1975 * Otherwise, just go to the "read messages" loop.
1978 readloop("readnew");
1986 * \brief display the message entry screen
1988 void display_enter(void)
1992 const StrBuf *display_name = NULL;
1993 /////wc_attachment *att;
1994 int recipient_required = 0;
1995 int subject_required = 0;
1996 int recipient_bad = 0;
1997 int is_anonymous = 0;
1999 struct wcsession *WCC = WC;
2003 if (havebstr("force_room")) {
2004 gotoroom(bstr("force_room"));
2007 display_name = sbstr("display_name");
2008 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
2009 display_name = NULL;
2013 /** First test to see whether this is a room that requires recipients to be entered */
2014 serv_puts("ENT0 0");
2015 serv_getln(buf, sizeof buf);
2017 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
2018 recipient_required = 1;
2020 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2021 sprintf(WCC->ImportantMessage, "%s", &buf[4]);
2022 readloop("readnew");
2026 /* Is the server strongly recommending that the user enter a message subject? */
2027 if ((buf[3] != '\0') && (buf[4] != '\0')) {
2028 subject_required = extract_int(&buf[4], 1);
2032 * Are we perhaps in an address book view? If so, then an "enter
2033 * message" command really means "add new entry."
2035 if (WCC->wc_default_view == VIEW_ADDRESSBOOK) {
2036 do_edit_vcard(-1, "", "", WCC->wc_roomname);
2041 * Are we perhaps in a calendar room? If so, then an "enter
2042 * message" command really means "add new calendar item."
2044 if (WCC->wc_default_view == VIEW_CALENDAR) {
2045 display_edit_event();
2050 * Are we perhaps in a tasks view? If so, then an "enter
2051 * message" command really means "add new task."
2053 if (WCC->wc_default_view == VIEW_TASKS) {
2054 display_edit_task();
2059 * Otherwise proceed normally.
2060 * Do a custom room banner with no navbar...
2063 if (recipient_required) {
2064 const StrBuf *Recp = NULL;
2065 const StrBuf *Cc = NULL;
2066 const StrBuf *Bcc = NULL;
2067 const StrBuf *Wikipage = NULL;
2068 StrBuf *CmdBuf = NULL;;
2069 const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
2071 Recp = sbstr("recp");
2074 Wikipage = sbstr("wikipage");
2076 CmdBuf = NewStrBufPlain(NULL,
2079 StrLength(display_name) +
2082 StrLength(Wikipage));
2084 StrBufPrintf(CmdBuf,
2088 ChrPtr(display_name),
2092 serv_puts(ChrPtr(CmdBuf));
2093 serv_getln(buf, sizeof buf);
2094 FreeStrBuf(&CmdBuf);
2096 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
2097 if (havebstr("recp") &&
2103 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2104 wprintf("<em>%s</em><br />\n", &buf[4]);/// -> important message
2108 svputlong("RCPTREQUIRED", recipient_required);
2109 svputlong("SUBJREQUIRED", recipient_required || subject_required);
2112 output_headers(1, 0, 0, 0, 1, 0);
2113 DoTemplate(HKEY("edit_message"), NULL, NULL, CTX_NONE);
2120 * \brief delete a message
2122 void delete_msg(void)
2127 msgid = lbstr("msgid");
2129 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
2130 serv_printf("DELE %ld", msgid);
2132 else { /** Otherwise move it to Trash */
2133 serv_printf("MOVE %ld|_TRASH_|0", msgid);
2136 serv_getln(buf, sizeof buf);
2137 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2139 readloop("readnew");
2144 * \brief move a message to another folder
2151 msgid = lbstr("msgid");
2153 if (havebstr("move_button")) {
2154 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
2156 serv_getln(buf, sizeof buf);
2157 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2159 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
2162 readloop("readnew");
2170 * Confirm move of a message
2172 void confirm_move_msg(void)
2178 msgid = lbstr("msgid");
2181 output_headers(1, 1, 2, 0, 0, 0);
2182 wprintf("<div id=\"banner\">\n");
2184 wprintf(_("Confirm move of message"));
2186 wprintf("</div>\n");
2188 wprintf("<div id=\"content\" class=\"service\">\n");
2190 wprintf("<CENTER>");
2192 wprintf(_("Move this message to:"));
2193 wprintf("<br />\n");
2195 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
2196 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2197 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
2199 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
2201 serv_getln(buf, sizeof buf);
2202 if (buf[0] == '1') {
2203 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2204 extract_token(targ, buf, 0, '|', sizeof targ);
2205 wprintf("<OPTION>");
2210 wprintf("</SELECT>\n");
2211 wprintf("<br />\n");
2213 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
2215 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
2216 wprintf("</form></CENTER>\n");
2218 wprintf("</CENTER>\n");
2222 void readnew(void) { readloop("readnew");}
2223 void readold(void) { readloop("readold");}
2224 void readfwd(void) { readloop("readfwd");}
2225 void headers(void) { readloop("headers");}
2226 void do_search(void) { readloop("do_search");}
2237 WebcitAddUrlHandler(HKEY("readnew"), readnew, 0);
2238 WebcitAddUrlHandler(HKEY("readold"), readold, 0);
2239 WebcitAddUrlHandler(HKEY("readfwd"), readfwd, 0);
2240 WebcitAddUrlHandler(HKEY("headers"), headers, 0);
2241 WebcitAddUrlHandler(HKEY("do_search"), do_search, 0);
2242 WebcitAddUrlHandler(HKEY("display_enter"), display_enter, 0);
2243 WebcitAddUrlHandler(HKEY("post"), post_message, 0);
2244 WebcitAddUrlHandler(HKEY("move_msg"), move_msg, 0);
2245 WebcitAddUrlHandler(HKEY("delete_msg"), delete_msg, 0);
2246 WebcitAddUrlHandler(HKEY("confirm_move_msg"), confirm_move_msg, 0);
2247 WebcitAddUrlHandler(HKEY("msg"), embed_message, NEED_URL|AJAX);
2248 WebcitAddUrlHandler(HKEY("printmsg"), print_message, NEED_URL);
2249 WebcitAddUrlHandler(HKEY("mobilemsg"), mobile_message_view, NEED_URL);
2250 WebcitAddUrlHandler(HKEY("msgheaders"), display_headers, NEED_URL);