4 * Functions which deal with the fetching and displaying of messages.
12 HashList *MsgHeaderHandler = NULL;
13 HashList *MsgEvaluators = NULL;
14 HashList *MimeRenderHandler = NULL;
15 int dbg_analyze_msg = 0;
17 #define SUBJ_COL_WIDTH_PCT 50 /**< Mailbox view column width */
18 #define SENDER_COL_WIDTH_PCT 30 /**< Mailbox view column width */
19 #define DATE_PLUS_BUTTONS_WIDTH_PCT 20 /**< Mailbox view column width */
21 void jsonMessageListHdr(void);
23 void display_enter(void);
25 typedef void (*MsgPartEvaluatorFunc)(message_summary *Sum, StrBuf *Buf);
27 typedef struct _MsgPartEvaluatorStruct {
28 MsgPartEvaluatorFunc f;
29 } MsgPartEvaluatorStruct;
31 int load_message(message_summary *Msg,
45 lprintf(9, "MSG4 %ld|%s\n", Msg->msgnum, ChrPtr(Msg->PartNum));
46 if (Msg->PartNum != NULL) {
47 serv_printf("MSG4 %ld|%s", Msg->msgnum, ChrPtr(Msg->PartNum));
50 serv_printf("MSG4 %ld", Msg->msgnum);
53 StrBuf_ServGetln(Buf);
54 if (GetServerStatus(Buf, NULL) != 1) {
56 StrBufAppendPrintf(*Error, "<strong>");
57 StrBufAppendPrintf(*Error, _("ERROR:"));
58 StrBufAppendPrintf(*Error, "</strong> %s<br />\n", &buf[4]);
63 /** begin everythingamundo table */
64 HdrToken = NewStrBuf();
65 while ((StrBuf_ServGetln(Buf)>=0) && !Done) {
66 if ( (StrLength(Buf)==3) &&
67 !strcmp(ChrPtr(Buf), "000"))
71 lprintf(1, _("unexpected end of message"));
72 if (Msg->MsgBody->Data == NULL)
73 Msg->MsgBody->Data = NewStrBuf();
74 Msg->MsgBody->ContentType = NewStrBufPlain(HKEY("text/html"));
75 StrBufAppendPrintf(Msg->MsgBody->Data, "<div><i>");
76 StrBufAppendPrintf(Msg->MsgBody->Data, _("unexpected end of message"));
77 StrBufAppendPrintf(Msg->MsgBody->Data, " (1)</i><br /><br />\n");
78 StrBufAppendPrintf(Msg->MsgBody->Data, "</div>\n");
83 case 0:/* Citadel Message Headers */
84 if (StrLength(Buf) == 0) {
88 StrBufExtract_token(HdrToken, Buf, 0, '=');
89 StrBufCutLeft(Buf, StrLength(HdrToken) + 1);
92 if (dbg_analyze_msg) lprintf(1, ":: [%s] = [%s]\n", ChrPtr(HdrToken), ChrPtr(Buf));
94 /* look up one of the examine_* functions to parse the content */
95 if (GetHash(MsgHeaderHandler, SKEY(HdrToken), &vHdr) &&
97 Hdr = (headereval*)vHdr;
98 Hdr->evaluator(Msg, Buf, FoundCharset);
103 else LogError(Target,
105 "don't know how to handle message header[%s]\n",
109 case 1:/* Message Mime Header */
110 if (StrLength(Buf) == 0) {
112 if (Msg->MsgBody->ContentType == NULL)
113 /* end of header or no header? */
114 Msg->MsgBody->ContentType = NewStrBufPlain(HKEY("text/plain"));
115 /* usual end of mime header */
119 StrBufExtract_token(HdrToken, Buf, 0, ':');
120 if (StrLength(HdrToken) > 0) {
121 StrBufCutLeft(Buf, StrLength(HdrToken) + 1);
123 if (dbg_analyze_msg) lprintf(1, ":: [%s] = [%s]\n", ChrPtr(HdrToken), ChrPtr(Buf));
125 /* the examine*'s know how to do with mime headers too... */
126 if (GetHash(MsgHeaderHandler, SKEY(HdrToken), &vHdr) &&
128 Hdr = (headereval*)vHdr;
129 Hdr->evaluator(Msg, Buf, FoundCharset);
134 case 2: /* Message Body */
136 if (Msg->MsgBody->size_known > 0) {
137 StrBuf_ServGetBLOBBuffered(Msg->MsgBody->Data, Msg->MsgBody->length);
139 /*/ todo: check next line, if not 000, append following lines */
142 if (StrLength(Msg->MsgBody->Data) > 0)
143 StrBufAppendBufPlain(Msg->MsgBody->Data, "\n", 1, 0);
144 StrBufAppendBuf(Msg->MsgBody->Data, Buf, 0);
148 StrBufAppendBuf(Msg->MsgBody->Data, Buf, 0);
153 if (Msg->AllAttach == NULL)
154 Msg->AllAttach = NewHash(1,NULL);
155 /* now we put the body mimepart we read above into the mimelist */
156 Put(Msg->AllAttach, SKEY(Msg->MsgBody->PartNum), Msg->MsgBody, DestroyMime);
158 /* Generate a reply-to address */
159 if (StrLength(Msg->Rfca) > 0) {
160 if (Msg->reply_to == NULL)
161 Msg->reply_to = NewStrBuf();
162 if (StrLength(Msg->from) > 0) {
163 StrBufPrintf(Msg->reply_to, "%s <%s>", ChrPtr(Msg->from), ChrPtr(Msg->Rfca));
166 FlushStrBuf(Msg->reply_to);
167 StrBufAppendBuf(Msg->reply_to, Msg->Rfca, 0);
172 if ((StrLength(Msg->OtherNode)>0) &&
173 (strcasecmp(ChrPtr(Msg->OtherNode), ChrPtr(WCC->serv_info->serv_nodename))) &&
174 (strcasecmp(ChrPtr(Msg->OtherNode), ChrPtr(WCC->serv_info->serv_humannode)) ))
176 if (Msg->reply_to == NULL)
177 Msg->reply_to = NewStrBuf();
178 StrBufPrintf(Msg->reply_to,
181 ChrPtr(Msg->OtherNode));
184 if (Msg->reply_to == NULL)
185 Msg->reply_to = NewStrBuf();
186 FlushStrBuf(Msg->reply_to);
187 StrBufAppendBuf(Msg->reply_to, Msg->from, 0);
191 FreeStrBuf(&HdrToken);
198 * I wanna SEE that message!
200 * msgnum Message number to display
201 * printable_view Nonzero to display a printable view
202 * section Optional for encapsulated message/rfc822 submessage
204 int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, const StrBuf *PartNum, const StrBuf **OutMime)
207 StrBuf *FoundCharset;
210 message_summary *Msg = NULL;
214 WCTemplputParams SubTP;
215 StrBuf *Error = NULL;
218 FoundCharset = NewStrBuf();
219 Msg = (message_summary *)malloc(sizeof(message_summary));
220 memset(Msg, 0, sizeof(message_summary));
221 Msg->msgnum = msgnum;
222 Msg->PartNum = PartNum;
223 Msg->MsgBody = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
224 memset(Msg->MsgBody, 0, sizeof(wc_mime_attachment));
225 Msg->MsgBody->msgnum = msgnum;
227 if (!load_message(Msg, FoundCharset, &Error)) {
228 StrBufAppendBuf(Target, Error, 0);
232 /* strip the bare contenttype, so we ommit charset etc. */
233 StrBufExtract_token(Buf, Msg->MsgBody->ContentType, 0, ';');
235 /* look up the renderer, that will convert this mimeitem into the htmlized form */
236 if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
238 RenderMimeFuncStruct *Render;
239 Render = (RenderMimeFuncStruct*)vHdr;
240 Render->f(Msg->MsgBody, NULL, FoundCharset);
243 if (StrLength(Msg->reply_references)> 0) {
244 /* Trim down excessively long lists of thread references. We eliminate the
245 * second one in the list so that the thread root remains intact.
247 int rrtok = num_tokens(ChrPtr(Msg->reply_references), '|');
248 int rrlen = StrLength(Msg->reply_references);
249 if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
250 StrBufRemove_token(Msg->reply_references, 1, '|');
254 /* now check if we need to translate some mimeparts, and remove the duplicate */
255 it = GetNewHashPos(Msg->AllAttach, 0);
256 while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) &&
258 wc_mime_attachment *Mime = (wc_mime_attachment*) vMime;
259 evaluate_mime_part(Msg, Mime);
262 memset(&SubTP, 0, sizeof(WCTemplputParams));
263 SubTP.Filter.ContextType = CTX_MAILSUM;
265 *OutMime = DoTemplate(tmpl, tmpllen, Target, &SubTP);
267 DestroyMessageSummary(Msg);
268 FreeStrBuf(&FoundCharset);
275 HttpStatus(long CitadelStatus)
277 long httpstatus = 502;
279 switch (MAJORCODE(CitadelStatus))
281 case LISTING_FOLLOWS:
286 switch (MINORCODE(CitadelStatus))
294 case HIGHER_ACCESS_REQUIRED:
295 case MAX_SESSIONS_EXCEEDED:
297 case RESOURCE_NOT_OPEN:
299 case INVALID_FLOOR_OPERATION:
305 case MESSAGE_NOT_FOUND:
315 case CMD_NOT_SUPPORTED:
316 case PASSWORD_REQUIRED:
317 case ALREADY_LOGGED_IN:
318 case USERNAME_REQUIRED:
320 case SERVER_SHUTTING_DOWN:
331 case START_CHAT_MODE:
335 httpstatus = 502; /* aeh... whut? */
343 * Unadorned HTML output of an individual message, suitable
344 * for placing in a hidden iframe, for printing, or whatever
346 void handle_one_message(void)
350 const StrBuf *Destination;
356 StrBuf *CmdBuf = NULL;
360 pMsg = strchr(ChrPtr(WCC->Hdr->HR.ReqLine), '/');
362 HttpStatus(CitStatus);
366 msgnum = atol(pMsg + 1);
367 StrBufCutAt(WCC->Hdr->HR.ReqLine, 0, pMsg);
368 gotoroom(WCC->Hdr->HR.ReqLine);
369 switch (WCC->Hdr->HR.eReqType)
373 Tmpl = sbstr("template");
374 if (StrLength(Tmpl) > 0)
375 read_message(WCC->WBuf, SKEY(Tmpl), msgnum, NULL, &Mime);
377 read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
378 http_transmit_thing(ChrPtr(Mime), 0);
381 CmdBuf = NewStrBuf ();
382 if (WCC->wc_is_trash) { /** Delete from Trash is a real delete */
383 serv_printf("DELE %ld", msgnum);
385 else { /** Otherwise move it to Trash */
386 serv_printf("MOVE %ld|_TRASH_|0", msgnum);
388 StrBuf_ServGetln(CmdBuf);
389 FlushStrBuf(WCC->ImportantMsg);
390 StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
391 GetServerStatus(CmdBuf, &CitStatus);
392 HttpStatus(CitStatus);
397 if (GetHash(WCC->Hdr->HTTPHeaders, HKEY("DESTINATION"), &vLine) &&
399 Destination = (StrBuf*) vLine;
400 serv_printf("MOVE %ld|%s|%d", msgnum, ChrPtr(Destination), CopyMessage);
401 StrBuf_ServGetln(CmdBuf);
402 FlushStrBuf(WCC->ImportantMsg);
403 StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
404 GetServerStatus(CmdBuf, &CitStatus);
405 HttpStatus(CitStatus);
418 * Unadorned HTML output of an individual message, suitable
419 * for placing in a hidden iframe, for printing, or whatever
421 void embed_message(void) {
426 StrBuf *CmdBuf = NULL;
428 msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/');
429 switch (WCC->Hdr->HR.eReqType)
433 Tmpl = sbstr("template");
434 if (StrLength(Tmpl) > 0)
435 read_message(WCC->WBuf, SKEY(Tmpl), msgnum, NULL, &Mime);
437 read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
438 http_transmit_thing(ChrPtr(Mime), 0);
441 CmdBuf = NewStrBuf ();
442 if (WCC->wc_is_trash) { /** Delete from Trash is a real delete */
443 serv_printf("DELE %ld", msgnum);
445 else { /** Otherwise move it to Trash */
446 serv_printf("MOVE %ld|_TRASH_|0", msgnum);
448 StrBuf_ServGetln(CmdBuf);
449 FlushStrBuf(WCC->ImportantMsg);
450 StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
460 * Printable view of a message
462 void print_message(void) {
466 msgnum = StrBufExtract_long(WC->Hdr->HR.ReqLine, 0, '/');
467 output_headers(0, 0, 0, 0, 0, 0);
469 hprintf("Content-type: text/html\r\n"
470 "Server: " PACKAGE_STRING "\r\n"
471 "Connection: close\r\n");
475 read_message(WC->WBuf, HKEY("view_message_print"), msgnum, NULL, &Mime);
481 * Mobile browser view of message
483 void mobile_message_view(void)
488 msgnum = StrBufExtract_long(WC->Hdr->HR.ReqLine, 0, '/');
489 output_headers(1, 0, 0, 0, 0, 1);
491 do_template("msgcontrols", NULL);
492 read_message(WC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
497 * Display a message's headers
499 void display_headers(void) {
503 msgnum = StrBufExtract_long(WC->Hdr->HR.ReqLine, 0, '/');
504 output_headers(0, 0, 0, 0, 0, 0);
506 hprintf("Content-type: text/plain\r\n"
508 "Connection: close\r\n",
512 serv_printf("MSG2 %ld|3", msgnum);
513 serv_getln(buf, sizeof buf);
515 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
516 wprintf("%s\n", buf);
524 message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSubject, long MsgNum)
527 MsgPartEvaluatorStruct *Eval;
528 message_summary *Msg;
537 serv_printf("MSG0 %ld|1", MsgNum); /* ask for headers only */
539 StrBuf_ServGetln(Buf);
540 if (GetServerStatus(Buf, NULL) == 1) {
545 Msg = (message_summary*)malloc(sizeof(message_summary));
546 memset(Msg, 0, sizeof(message_summary));
547 while (len = StrBuf_ServGetln(Buf),
549 strcmp(ChrPtr(Buf), "000")== 0)){
551 ebuf = strchr(ChrPtr(Buf), '=');
553 if (GetHash(MsgEvaluators, buf, nBuf, &vEval) && vEval != NULL) {
554 Eval = (MsgPartEvaluatorStruct*) vEval;
555 StrBufCutLeft(Buf, nBuf + 1);
558 else lprintf(1, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
568 * load message pointers from the server for a "read messages" operation
570 * servcmd: the citadel command to send to the citserver
571 * with_headers: also include some of the headers with the message numbers (more expensive)
573 int load_msg_ptrs(const char *servcmd, int with_headers)
575 StrBuf* FoundCharset = NULL;
577 message_summary *Msg;
584 const char *Ptr = NULL;
586 if (WCC->summ != NULL) {
587 DeleteHash(&WCC->summ);
589 WCC->summ = NewHash(1, Flathash);
594 StrBuf_ServGetln(Buf);
595 if (GetServerStatus(Buf, NULL) != 1) {
600 while (len = StrBuf_ServGetln(Buf),
602 strcmp(ChrPtr(Buf), "000")!= 0))
604 if (nummsgs < maxload) {
607 Msg = (message_summary*)malloc(sizeof(message_summary));
608 memset(Msg, 0, sizeof(message_summary));
610 Msg->msgnum = StrBufExtractNext_long(Buf, &Ptr, '|');
611 Msg->date = StrBufExtractNext_long(Buf, &Ptr, '|');
613 if ((Msg->msgnum == 0) && (StrLength(Buf) < 32)) {
618 * as citserver probably gives us messages in forward date sorting
619 * nummsgs should be the same order as the message date.
621 if (Msg->date == 0) {
623 if (StrLength(Buf) < 32)
627 Msg->from = NewStrBufPlain(NULL, StrLength(Buf));
628 StrBufExtract_NextToken(Buf2, Buf, &Ptr, '|');
629 if (StrLength(Buf2) != 0) {
630 /* Handle senders with RFC2047 encoding */
631 StrBuf_RFC822_to_Utf8(Msg->from, Buf2, WCC->DefaultCharset, FoundCharset);
635 StrBufExtract_NextToken(Buf2, Buf, &Ptr, '|');
636 if ((StrLength(Buf2) !=0 ) &&
637 ( ((WCC->room_flags & QR_NETWORK)
638 || ((strcasecmp(ChrPtr(Buf2), ChrPtr(WCC->serv_info->serv_nodename))
639 && (strcasecmp(ChrPtr(Buf2), ChrPtr(WCC->serv_info->serv_fqdn))))))))
641 StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
642 StrBufAppendBuf(Msg->from, Buf2, 0);
645 /* Internet address (not used)
646 * StrBufExtract_token(Msg->inetaddr, Buf, 4, '|');
648 StrBufSkip_NTokenS(Buf, &Ptr, '|', 1);
649 Msg->subj = NewStrBufPlain(NULL, StrLength(Buf));
650 StrBufExtract_NextToken(Buf2, Buf, &Ptr, '|');
651 if (StrLength(Buf2) == 0)
652 StrBufAppendBufPlain(Msg->subj, _("(no subject)"), -1,0);
654 StrBuf_RFC822_to_Utf8(Msg->subj, Buf2, WCC->DefaultCharset, FoundCharset);
655 if ((StrLength(Msg->subj) > 75) &&
656 (StrBuf_Utf8StrLen(Msg->subj) > 75)) {
657 StrBuf_Utf8StrCut(Msg->subj, 72);
658 StrBufAppendBufPlain(Msg->subj, HKEY("..."), 0);
662 if ((StrLength(Msg->from) > 25) &&
663 (StrBuf_Utf8StrLen(Msg->from) > 25)) {
664 StrBuf_Utf8StrCut(Msg->from, 23);
665 StrBufAppendBufPlain(Msg->from, HKEY("..."), 0);
669 Put(WCC->summ, (const char *)&n, sizeof(n), Msg, DestroyMessageSummary);
679 inline message_summary* GetMessagePtrAt(int n, HashList *Summ)
687 GetHashAt(Summ, n, &HKLen, &Key, &vMsg);
688 return (message_summary*) vMsg;
692 long DrawMessageDropdown(StrBuf *Selector, long maxmsgs, long startmsg, int nMessages)
705 WCTemplputParams SubTP;
707 memset(&SubTP, 0, sizeof(WCTemplputParams));
708 SubTP.Filter.ContextType = CTX_LONGVECTOR;
709 SubTP.Context = &vector;
710 TmpBuf = NewStrBufPlain(NULL, SIZ);
711 At = GetNewHashPos(WCC->summ, nMessages);
712 nItems = GetCount(WCC->summ);
716 vector[1] = startmsg;
720 vector[3] = abs(nMessages);
721 lo = GetHashPosCounter(At);
723 if (lo + nMessages >= nItems) {
725 vector[3] = nItems - lo;
730 hi = lo + nMessages - 1;
733 if (lo + nMessages < -1) {
737 if ((lo % abs(nMessages)) != 0) {
738 int offset = (lo % abs(nMessages) *
739 (nMessages / abs(nMessages)));
741 vector[3] = abs(offset);
749 done = !GetNextHashPos(WCC->summ, At, &hklen, &key, &vMsg);
752 * Bump these because although we're thinking in zero base, the user
753 * is a drooling idiot and is thinking in one base.
759 dbg_print_longvector(vector);
760 DoTemplate(HKEY("select_messageindex"), TmpBuf, &SubTP);
761 StrBufAppendBuf(Selector, TmpBuf, 0);
765 if (maxmsgs == 9999999) {
772 dbg_print_longvector(vector);
773 DoTemplate(HKEY("select_messageindex_all"), TmpBuf, &SubTP);
774 StrBufAppendBuf(Selector, TmpBuf, 0);
780 void load_seen_flags(void)
782 message_summary *Msg;
790 OldMsg = NewStrBuf();
792 StrBuf_ServGetln(OldMsg);
793 if (GetServerStatus(OldMsg, NULL) == 2) {
794 StrBufCutLeft(OldMsg, 4);
800 at = GetNewHashPos(WCC->summ, 0);
801 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
802 /** Are you a new message, or an old message? */
803 Msg = (message_summary*) vMsg;
804 if (is_msg_in_mset(ChrPtr(OldMsg), Msg->msgnum)) {
815 extern readloop_struct rlid[];
818 * command loop for reading messages
820 * Set oper to "readnew" or "readold" or "readfwd" or "headers"
822 void readloop(long oper)
824 StrBuf *MessageDropdown = NULL;
825 StrBuf *BBViewToolBar = NULL;
827 message_summary *Msg;
831 int with_headers = 0;
835 long *displayed_msgs = NULL;
836 int num_displayed = 0;
837 int is_singlecard = 0;
840 int lowest_displayed = (-1);
841 int highest_displayed = 0;
842 addrbookent *addrbook = NULL;
849 int care_for_empty_list = 0;
852 int defaultsortorder = 0;
853 WCTemplputParams SubTP;
857 if (havebstr("is_summary") && (1 == (ibstr("is_summary"))))
858 WCC->wc_view = VIEW_MAILBOX;
861 output_headers(1, 1, 1, 0, 0, 0);
862 } else if (WCC->wc_view == VIEW_MAILBOX) {
863 jsonMessageListHdr();
866 switch (WCC->wc_view) {
868 sprintf(buf, "wiki?room=%s&page=home", ChrPtr(WCC->wc_roomname));
874 strcpy(cmd, "MSGS ALL");
876 parse_calendar_view_request(&calv);
879 strcpy(cmd, "MSGS ALL");
883 strcpy(cmd, "MSGS ALL");
885 wprintf("<div id=\"new_notes_here\"></div>\n");
887 case VIEW_ADDRESSBOOK:
888 is_singlecard = ibstr("is_singlecard");
889 if (is_singlecard != 1) {
890 if (oper == do_search) {
891 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
894 strcpy(cmd, "MSGS ALL");
905 defaultsortorder = 2;
908 care_for_empty_list = 0;
910 /* Generally using maxmsgs|startmsg is not required
911 in mailbox view, but we have a 'safemode' for clients
912 (*cough* Exploder) that simply can't handle too many */
913 if (havebstr("maxmsgs")) maxmsgs = ibstr("maxmsgs");
914 else maxmsgs = 9999999;
915 if (havebstr("startmsg")) startmsg = lbstr("startmsg");
916 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
917 (oper == do_search) ? "SEARCH" : "ALL",
918 (oper == do_search) ? bstr("query") : ""
924 defaultsortorder = 1;
927 care_for_empty_list = 1;
929 rlid[oper].cmd(cmd, sizeof(cmd));
930 SetAccessCommand(oper);
932 if (havebstr("maxmsgs"))
933 maxmsgs = ibstr("maxmsgs");
934 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
936 if (havebstr("startmsg")) {
937 startmsg = lbstr("startmsg");
942 nummsgs = load_msg_ptrs(cmd, with_headers);
944 if (care_for_empty_list) {
945 wprintf("<div class=\"nomsgs\"><br><em>");
948 wprintf(_("No new messages."));
951 wprintf(_("No old messages."));
954 wprintf(_("No messages here."));
956 wprintf("</em><br></div>\n");
964 memset(&SubTP, 0, sizeof(WCTemplputParams));
965 SubTP.Filter.ContextType = CTX_NONE;
966 SubTP.Context = NULL;
967 SortIt = RetrieveSort(&SubTP, NULL, 0,
968 HKEY("date"), defaultsortorder);
970 SortByPayload(WCC->summ, SortIt);
971 if (WCC->wc_view == VIEW_BBS) {
972 if (lbstr("SortOrder") == 2) {
974 num_displayed = -DEFAULT_MAXMSGS;
978 num_displayed = DEFAULT_MAXMSGS;
982 if (startmsg < 0) startmsg = (bbs_reverse) ? nummsgs - 1 : 0;
984 if (load_seen) load_seen_flags();
987 * Print any inforation above the message list...
989 switch (WCC->wc_view) {
991 BBViewToolBar = NewStrBufPlain(NULL, SIZ);
992 MessageDropdown = NewStrBufPlain(NULL, SIZ);
994 maxmsgs = DrawMessageDropdown(MessageDropdown, maxmsgs, startmsg, num_displayed);
995 if (num_displayed < 0) {
997 if (num_displayed != maxmsgs)
998 maxmsgs = abs(maxmsgs) + 1;
1000 maxmsgs = abs(maxmsgs);
1003 memset(&SubTP, 0, sizeof(WCTemplputParams));
1004 SubTP.Filter.ContextType = CTX_STRBUF;
1005 SubTP.Context = MessageDropdown;
1006 DoTemplate(HKEY("msg_listselector_top"), BBViewToolBar, &SubTP);
1007 StrBufAppendBuf(WCC->WBuf, BBViewToolBar, 0);
1008 FlushStrBuf(BBViewToolBar);
1011 WCC->startmsg = startmsg;
1012 WCC->maxmsgs = maxmsgs;
1013 WCC->num_displayed = 0;
1015 /* Put some helpful data in vars for mailsummary_json */
1016 svputlong("READLOOP:TOTALMSGS", nummsgs);
1017 svputlong("READLOOP:STARTMSG", startmsg);
1018 svputlong("WCVIEW", WCC->wc_view);
1021 * iterate over each message. if we need to load an attachment, do it here.
1023 if (WCC->wc_view == VIEW_MAILBOX) goto NO_MSG_LOOP;
1024 at = GetNewHashPos(WCC->summ, 0);
1025 num_displayed = i = 0;
1026 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
1027 Msg = (message_summary*) vMsg;
1028 if ((Msg->msgnum >= startmsg) && (num_displayed <= maxmsgs)) {
1029 switch (WCC->wc_view) {
1032 case VIEW_CALBRIEF: /* load the mime attachments for special tasks... */
1034 load_calendar_item(Msg, Msg->is_new, &calv);
1037 display_task(Msg, Msg->is_new);
1040 display_note(Msg, Msg->is_new);
1042 case VIEW_ADDRESSBOOK:
1044 fetch_ab_name(Msg, &ab_name);
1045 if (ab_name == NULL)
1048 addrbook = realloc(addrbook,
1049 (sizeof(addrbookent) * num_ab) );
1050 safestrncpy(addrbook[num_ab-1].ab_name, ab_name,
1051 sizeof(addrbook[num_ab-1].ab_name));
1052 addrbook[num_ab-1].ab_msgnum = Msg->msgnum;
1055 case VIEW_BBS: /* Tag the mails we want to show in bbview... */
1057 if (displayed_msgs == NULL) {
1058 displayed_msgs = malloc(sizeof(long) *
1059 (maxmsgs<nummsgs ? maxmsgs + 1 : nummsgs + 1));
1061 if ((i >= startmsg) && (i < startmsg + maxmsgs)) {
1062 displayed_msgs[num_displayed] = Msg->msgnum;
1063 if (lowest_displayed < 0) lowest_displayed = a;
1064 highest_displayed = a;
1076 * Done iterating the message list. now tasks we want to do after.
1078 switch (WCC->wc_view) {
1080 DoTemplate(HKEY("mailsummary_json"),NULL, &SubTP);
1083 if (displayed_msgs != NULL) {
1084 /** if we do a split bbview in the future, begin messages div here */
1086 for (a=0; a<num_displayed; ++a) {
1087 read_message(WCC->WBuf, HKEY("view_message"), displayed_msgs[a], NULL, &Mime);
1090 /* if we do a split bbview in the future, end messages div here */
1092 free(displayed_msgs);
1093 displayed_msgs = NULL;
1095 memset(&SubTP, 0, sizeof(WCTemplputParams));
1096 SubTP.Filter.ContextType = CTX_STRBUF;
1097 SubTP.Context = MessageDropdown;
1098 DoTemplate(HKEY("msg_listselector_bottom"), BBViewToolBar, &SubTP);
1099 StrBufAppendBuf(WCC->WBuf, BBViewToolBar, 0);
1101 FreeStrBuf(&BBViewToolBar);
1102 FreeStrBuf(&MessageDropdown);
1107 switch (WCC->wc_view) {
1112 render_calendar_view(&calv);
1115 do_tasks_view(); /** Render the task list */
1119 case VIEW_ADDRESSBOOK:
1121 read_message(WC->WBuf, HKEY("view_message"), lbstr("startmsg"), NULL, &Mime);
1123 do_addrbook_view(addrbook, num_ab); /* Render the address book */
1130 /** Note: wDumpContent() will output one additional </div> tag. */
1131 if (WCC->wc_view != VIEW_MAILBOX) {
1132 /* We ought to move this out into template */
1139 if (WCC->summ != NULL) {
1140 DeleteHash(&WCC->summ);
1142 if (addrbook != NULL) free(addrbook);
1143 FreeStrBuf(&BBViewToolBar);
1148 * Back end for post_message()
1149 * ... this is where the actual message gets transmitted to the server.
1151 void post_mime_to_server(void) {
1152 wcsession *WCC = WC;
1153 char top_boundary[SIZ];
1154 char alt_boundary[SIZ];
1155 int is_multipart = 0;
1157 wc_mime_attachment *att;
1159 size_t encoded_length;
1160 size_t encoded_strlen;
1161 char *txtmail = NULL;
1163 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
1164 ChrPtr(WCC->serv_info->serv_fqdn),
1168 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
1169 ChrPtr(WCC->serv_info->serv_fqdn),
1174 /* RFC2045 requires this, and some clients look for it... */
1175 serv_puts("MIME-Version: 1.0");
1176 serv_puts("X-Mailer: " PACKAGE_STRING);
1178 /* If there are attachments, we have to do multipart/mixed */
1179 if (GetCount(WCC->attachments) > 0) {
1184 /* Remember, serv_printf() appends an extra newline */
1185 serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
1186 serv_printf("This is a multipart message in MIME format.\n");
1187 serv_printf("--%s", top_boundary);
1190 /* Remember, serv_printf() appends an extra newline */
1191 serv_printf("Content-type: multipart/alternative; "
1192 "boundary=\"%s\"\n", alt_boundary);
1193 serv_printf("This is a multipart message in MIME format.\n");
1194 serv_printf("--%s", alt_boundary);
1196 serv_puts("Content-type: text/plain; charset=utf-8");
1197 serv_puts("Content-Transfer-Encoding: quoted-printable");
1199 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
1200 text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */
1203 serv_printf("--%s", alt_boundary);
1205 serv_puts("Content-type: text/html; charset=utf-8");
1206 serv_puts("Content-Transfer-Encoding: quoted-printable");
1208 serv_puts("<html><body>\r\n");
1209 text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */
1210 serv_puts("</body></html>\r\n");
1212 serv_printf("--%s--", alt_boundary);
1220 /* Add in the attachments */
1221 it = GetNewHashPos(WCC->attachments, 0);
1222 while (GetNextHashPos(WCC->attachments, it, &len, &Key, &vAtt)) {
1223 att = (wc_mime_attachment *)vAtt;
1224 encoded_length = ((att->length * 150) / 100);
1225 encoded = malloc(encoded_length);
1226 if (encoded == NULL) break;
1227 encoded_strlen = CtdlEncodeBase64(encoded, ChrPtr(att->Data), StrLength(att->Data), 1);
1229 serv_printf("--%s", top_boundary);
1230 serv_printf("Content-type: %s", ChrPtr(att->ContentType));
1231 serv_printf("Content-disposition: attachment; filename=\"%s\"", ChrPtr(att->FileName));
1232 serv_puts("Content-transfer-encoding: base64");
1234 serv_write(encoded, encoded_strlen);
1239 serv_printf("--%s--", top_boundary);
1248 * Post message (or don't post message)
1250 * Note regarding the "dont_post" variable:
1251 * A random value (actually, it's just a timestamp) is inserted as a hidden
1252 * field called "postseq" when the display_enter page is generated. This
1253 * value is checked when posting, using the static variable dont_post. If a
1254 * user attempts to post twice using the same dont_post value, the message is
1255 * discarded. This prevents the accidental double-saving of the same message
1256 * if the user happens to click the browser "back" button.
1258 void post_message(void)
1261 StrBuf *encoded_subject = NULL;
1262 static long dont_post = (-1L);
1263 wc_mime_attachment *att;
1264 int is_anonymous = 0;
1265 const StrBuf *display_name = NULL;
1266 wcsession *WCC = WC;
1269 if (havebstr("force_room")) {
1270 gotoroom(sbstr("force_room"));
1273 if (havebstr("display_name")) {
1274 display_name = sbstr("display_name");
1275 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
1276 display_name = NULL;
1281 if (WCC->upload_length > 0) {
1286 /* There's an attachment. Save it to this struct... */
1287 lprintf(9, "Client is uploading %d bytes\n", WCC->upload_length);
1288 att = malloc(sizeof(wc_mime_attachment));
1289 memset(att, 0, sizeof(wc_mime_attachment ));
1290 att->length = WCC->upload_length;
1291 att->ContentType = NewStrBufPlain(WCC->upload_content_type, -1);
1292 att->FileName = NewStrBufPlain(WCC->upload_filename, -1);
1294 if (WCC->attachments == NULL) {
1295 WCC->attachments = NewHash(1, NULL);
1298 /* And add it to the list. */
1299 n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
1300 Put(WCC->attachments, N, n, att, DestroyMime);
1303 * Mozilla sends a simple filename, which is what we want,
1304 * but Satan's Browser sends an entire pathname. Reduce
1305 * the path to just a filename if we need to.
1307 pch = strrchr(ChrPtr(att->FileName), '/');
1309 StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1);
1311 pch = strrchr(ChrPtr(att->FileName), '\\');
1313 StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1);
1317 * Transfer control of this memory from the upload struct
1318 * to the attachment struct.
1320 att->Data = NewStrBufPlain(WCC->upload, WCC->upload_length);
1322 WCC->upload_length = 0;
1328 if (havebstr("cancel_button")) {
1329 sprintf(WCC->ImportantMessage,
1330 _("Cancelled. Message was not posted."));
1331 } else if (havebstr("attach_button")) {
1334 } else if (lbstr("postseq") == dont_post) {
1335 sprintf(WCC->ImportantMessage,
1336 _("Automatically cancelled because you have already "
1337 "saved this message."));
1339 const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s";
1340 const StrBuf *Recp = NULL;
1341 const StrBuf *Cc = NULL;
1342 const StrBuf *Bcc = NULL;
1343 const StrBuf *Wikipage = NULL;
1344 const StrBuf *my_email_addr = NULL;
1345 StrBuf *CmdBuf = NULL;
1346 StrBuf *references = NULL;
1349 save_to_drafts = havebstr("save_button");
1352 if (save_to_drafts) {
1353 /* temporarily change to the drafts room */
1354 serv_puts("GOTO _DRAFTS_");
1355 StrBuf_ServGetln(Buf);
1356 if (GetServerStatus(Buf, NULL) != 2) {
1357 /* You probably don't even have a dumb Drafts folder */
1358 StrBufCutLeft(Buf, 4);
1359 lprintf(9, "%s:%d: server save to drafts error: %s\n", __FILE__, __LINE__, ChrPtr(Buf));
1360 StrBufAppendBufPlain(WCC->ImportantMsg, _("Saved to Drafts failed: "), -1, 0);
1361 StrBufAppendBuf(WCC->ImportantMsg, Buf, 0);
1368 if (havebstr("references"))
1370 const StrBuf *ref = sbstr("references");
1371 references = NewStrBufDup(ref);
1372 if (*ChrPtr(references) == '|') { /* remove leading '|' if present */
1373 StrBufCutLeft(references, 1);
1375 StrBufReplaceChars(references, '|', '!');
1377 if (havebstr("subject")) {
1380 * make enough room for the encoded string;
1381 * plus the QP header
1383 Subj = sbstr("subject");
1385 StrBufRFC2047encode(&encoded_subject, Subj);
1387 Recp = sbstr("recp");
1390 Wikipage = sbstr("wikipage");
1391 my_email_addr = sbstr("my_email_addr");
1393 CmdBuf = NewStrBufPlain(NULL,
1396 StrLength(encoded_subject) +
1399 StrLength(Wikipage) +
1400 StrLength(my_email_addr) +
1401 StrLength(references));
1403 StrBufPrintf(CmdBuf,
1405 save_to_drafts?"":ChrPtr(Recp),
1407 ChrPtr(encoded_subject),
1408 ChrPtr(display_name),
1409 save_to_drafts?"":ChrPtr(Cc),
1410 save_to_drafts?"":ChrPtr(Bcc),
1412 ChrPtr(my_email_addr),
1413 ChrPtr(references));
1414 FreeStrBuf(&references);
1415 FreeStrBuf(&encoded_subject);
1417 lprintf(9, "%s\n", ChrPtr(CmdBuf));
1418 serv_puts(ChrPtr(CmdBuf));
1419 FreeStrBuf(&CmdBuf);
1421 StrBuf_ServGetln(Buf);
1422 if (GetServerStatus(Buf, NULL) == 4) {
1423 if (save_to_drafts) {
1424 if ( (havebstr("recp"))
1425 || (havebstr("cc" ))
1426 || (havebstr("bcc" )) ) {
1427 /* save recipient headers or room to post to */
1428 serv_printf("To: %s", ChrPtr(Recp));
1429 serv_printf("Cc: %s", ChrPtr(Cc));
1430 serv_printf("Bcc: %s", ChrPtr(Bcc));
1432 serv_printf("X-Citadel-Room: %s", ChrPtr(WC->wc_roomname));
1435 post_mime_to_server();
1436 if (save_to_drafts) {
1437 StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been saved to Drafts.\n"), -1, 0);
1438 gotoroom(WCC->wc_roomname);
1442 } else if ( (havebstr("recp"))
1443 || (havebstr("cc" ))
1444 || (havebstr("bcc" ))
1446 StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been sent.\n"), -1, 0);
1449 StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been posted.\n"), -1, 0);
1451 dont_post = lbstr("postseq");
1453 StrBufCutLeft(Buf, 4);
1455 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, ChrPtr(Buf));
1456 StrBufAppendBuf(WCC->ImportantMsg, Buf, 0);
1457 if (save_to_drafts) gotoroom(WCC->wc_roomname);
1465 DeleteHash(&WCC->attachments);
1468 * We may have been supplied with instructions regarding the location
1469 * to which we must return after posting. If found, go there.
1471 if (havebstr("return_to")) {
1472 http_redirect(bstr("return_to"));
1475 * If we were editing a page in a wiki room, go to that page now.
1477 else if (havebstr("wikipage")) {
1478 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
1482 * Otherwise, just go to the "read messages" loop.
1493 * display the message entry screen
1495 void display_enter(void)
1499 const StrBuf *display_name = NULL;
1500 int recipient_required = 0;
1501 int subject_required = 0;
1502 int recipient_bad = 0;
1503 int is_anonymous = 0;
1504 wcsession *WCC = WC;
1508 if (havebstr("force_room")) {
1509 gotoroom(sbstr("force_room"));
1512 display_name = sbstr("display_name");
1513 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
1514 display_name = NULL;
1518 /* First test to see whether this is a room that requires recipients to be entered */
1519 serv_puts("ENT0 0");
1520 serv_getln(buf, sizeof buf);
1522 if (!strncmp(buf, "570", 3)) { /* 570 means that we need a recipient here */
1523 recipient_required = 1;
1525 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
1526 sprintf(WCC->ImportantMessage, "%s", &buf[4]);
1531 /* Is the server strongly recommending that the user enter a message subject? */
1532 if ((buf[3] != '\0') && (buf[4] != '\0')) {
1533 subject_required = extract_int(&buf[4], 1);
1537 * Are we perhaps in an address book view? If so, then an "enter
1538 * message" command really means "add new entry."
1540 if (WCC->wc_default_view == VIEW_ADDRESSBOOK) {
1541 do_edit_vcard(-1, "", NULL, NULL, "", ChrPtr(WCC->wc_roomname));
1546 * Are we perhaps in a calendar room? If so, then an "enter
1547 * message" command really means "add new calendar item."
1549 if (WCC->wc_default_view == VIEW_CALENDAR) {
1550 display_edit_event();
1555 * Are we perhaps in a tasks view? If so, then an "enter
1556 * message" command really means "add new task."
1558 if (WCC->wc_default_view == VIEW_TASKS) {
1559 display_edit_task();
1564 * Otherwise proceed normally.
1565 * Do a custom room banner with no navbar...
1568 if (recipient_required) {
1569 const StrBuf *Recp = NULL;
1570 const StrBuf *Cc = NULL;
1571 const StrBuf *Bcc = NULL;
1572 const StrBuf *Wikipage = NULL;
1573 StrBuf *CmdBuf = NULL;
1574 const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
1576 Recp = sbstr("recp");
1579 Wikipage = sbstr("wikipage");
1581 CmdBuf = NewStrBufPlain(NULL,
1584 StrLength(display_name) +
1587 StrLength(Wikipage));
1589 StrBufPrintf(CmdBuf,
1593 ChrPtr(display_name),
1597 serv_puts(ChrPtr(CmdBuf));
1598 serv_getln(buf, sizeof buf);
1599 FreeStrBuf(&CmdBuf);
1601 if (!strncmp(buf, "570", 3)) { /* 570 means we have an invalid recipient listed */
1602 if (havebstr("recp") &&
1608 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
1609 wprintf("<em>%s</em><br />\n", &buf[4]); /* TODO -> important message */
1613 svputlong("RCPTREQUIRED", recipient_required);
1614 svputlong("SUBJREQUIRED", recipient_required || subject_required);
1617 output_headers(1, 0, 0, 0, 1, 0);
1618 DoTemplate(HKEY("edit_message"), NULL, &NoCtx);
1627 void delete_msg(void)
1632 msgid = lbstr("msgid");
1634 if (WC->wc_is_trash) { /* Delete from Trash is a real delete */
1635 serv_printf("DELE %ld", msgid);
1637 else { /* Otherwise move it to Trash */
1638 serv_printf("MOVE %ld|_TRASH_|0", msgid);
1641 serv_getln(buf, sizeof buf);
1642 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1648 * move a message to another room
1655 msgid = lbstr("msgid");
1657 if (havebstr("move_button")) {
1658 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
1660 serv_getln(buf, sizeof buf);
1661 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1663 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
1671 * Confirm move of a message
1673 void confirm_move_msg(void)
1679 msgid = lbstr("msgid");
1682 output_headers(1, 1, 2, 0, 0, 0);
1683 wprintf("<div id=\"banner\">\n");
1685 wprintf(_("Confirm move of message"));
1687 wprintf("</div>\n");
1689 wprintf("<div id=\"content\" class=\"service\">\n");
1691 wprintf("<CENTER>");
1693 wprintf(_("Move this message to:"));
1694 wprintf("<br />\n");
1696 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
1697 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1698 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
1700 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
1702 serv_getln(buf, sizeof buf);
1703 if (buf[0] == '1') {
1704 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1705 extract_token(targ, buf, 0, '|', sizeof targ);
1706 wprintf("<OPTION>");
1711 wprintf("</SELECT>\n");
1712 wprintf("<br />\n");
1714 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
1716 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
1717 wprintf("</form></CENTER>\n");
1719 wprintf("</CENTER>\n");
1725 * Generic function to output an arbitrary MIME attachment from
1726 * message being composed
1728 * partnum The MIME part to be output
1729 * filename Fake filename to give
1730 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
1732 void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
1735 StrBuf *content_type;
1736 wc_mime_attachment *part;
1738 if (GetHash(WC->attachments, SKEY(partnum), &vPart) &&
1740 part = (wc_mime_attachment*) vPart;
1741 if (force_download) {
1742 content_type = NewStrBufPlain(HKEY("application/octet-stream"));
1745 content_type = NewStrBufDup(part->ContentType);
1747 StrBufAppendBuf(WC->WBuf, part->Data, 0);
1748 http_transmit_thing(ChrPtr(content_type), 0);
1750 hprintf("HTTP/1.1 404 %s\n", ChrPtr(partnum));
1751 output_headers(0, 0, 0, 0, 0, 0);
1752 hprintf("Content-Type: text/plain\r\n");
1753 wprintf(_("An error occurred while retrieving this part: %s/%s\n"),
1754 ChrPtr(partnum), ChrPtr(filename));
1757 FreeStrBuf(&content_type);
1762 * Generic function to output an arbitrary MIME part from an arbitrary
1763 * message number on the server.
1765 * msgnum Number of the item on the citadel server
1766 * partnum The MIME part to be output
1767 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
1769 void mimepart(int force_download)
1773 wcsession *WCC = WC;
1776 StrBuf *ContentType = NewStrBufPlain(HKEY("application/octet-stream"));
1779 att = Buf = NewStrBuf();
1780 msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/');
1781 StrBufExtract_token(att, WCC->Hdr->HR.ReqLine, 1, '/');
1783 serv_printf("OPNA %ld|%s", msgnum, ChrPtr(att));
1784 StrBuf_ServGetln(Buf);
1785 if (GetServerStatus(Buf, NULL) == 2) {
1786 StrBufCutLeft(Buf, 4);
1787 bytes = StrBufExtract_long(Buf, 0, '|');
1788 if (!force_download) {
1789 StrBufExtract_token(ContentType, Buf, 3, '|');
1792 read_server_binary(WCC->WBuf, bytes, Buf);
1794 StrBuf_ServGetln(Buf);
1795 CT = ChrPtr(ContentType);
1797 if (!force_download) {
1798 if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
1799 StrBufExtract_token(Buf, WCC->Hdr->HR.ReqLine, 2, '/');
1800 CT = GuessMimeByFilename(SKEY(Buf));
1802 if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
1803 CT = GuessMimeType(SKEY(WCC->WBuf));
1806 http_transmit_thing(CT, 0);
1808 StrBufCutLeft(Buf, 4);
1809 hprintf("HTTP/1.1 404 %s\n", ChrPtr(Buf));
1810 output_headers(0, 0, 0, 0, 0, 0);
1811 hprintf("Content-Type: text/plain\r\n");
1812 wprintf(_("An error occurred while retrieving this part: %s\n"),
1816 FreeStrBuf(&ContentType);
1822 * Read any MIME part of a message, from the server, into memory.
1824 StrBuf *load_mimepart(long msgnum, char *partnum)
1830 serv_printf("DLAT %ld|%s", msgnum, partnum);
1831 StrBuf_ServGetln(Buf);
1832 if (GetServerStatus(Buf, NULL) == 6) {
1833 StrBufCutLeft(Buf, 4);
1834 bytes = StrBufExtract_long(Buf, 0, '|');
1837 StrBuf_ServGetBLOBBuffered(Buf, bytes);
1847 * Read any MIME part of a message, from the server, into memory.
1849 void MimeLoadData(wc_mime_attachment *Mime)
1853 /* TODO: is there a chance the content type is different from the one we know? */
1854 serv_printf("DLAT %ld|%s", Mime->msgnum, ChrPtr(Mime->PartNum));
1856 StrBuf_ServGetln(Buf);
1857 if (GetServerStatus(Buf, NULL) == 6) {
1858 bytes = extract_long(&(ChrPtr(Buf)[4]), 0);
1860 if (Mime->Data == NULL)
1861 Mime->Data = NewStrBufPlain(NULL, bytes);
1862 StrBuf_ServGetBLOBBuffered(Mime->Data, bytes);
1865 FlushStrBuf(Mime->Data);
1866 /* TODO XImportant message */
1874 void view_mimepart(void) {
1878 void download_mimepart(void) {
1882 void view_postpart(void) {
1883 StrBuf *filename = NewStrBuf();
1884 StrBuf *partnum = NewStrBuf();
1886 StrBufExtract_token(partnum, WC->Hdr->HR.ReqLine, 0, '/');
1887 StrBufExtract_token(filename, WC->Hdr->HR.ReqLine, 1, '/');
1889 postpart(partnum, filename, 0);
1891 FreeStrBuf(&filename);
1892 FreeStrBuf(&partnum);
1895 void download_postpart(void) {
1896 StrBuf *filename = NewStrBuf();
1897 StrBuf *partnum = NewStrBuf();
1899 StrBufExtract_token(partnum, WC->Hdr->HR.ReqLine, 0, '/');
1900 StrBufExtract_token(filename, WC->Hdr->HR.ReqLine, 1, '/');
1902 postpart(partnum, filename, 1);
1904 FreeStrBuf(&filename);
1905 FreeStrBuf(&partnum);
1908 void h_readnew(void) { readloop(readnew);}
1909 void h_readold(void) { readloop(readold);}
1910 void h_readfwd(void) { readloop(readfwd);}
1911 void h_headers(void) { readloop(headers);}
1912 void h_do_search(void) { readloop(do_search);}
1914 void jsonMessageListHdr(void)
1916 /* TODO: make a generic function */
1917 hprintf("HTTP/1.1 200 OK\r\n");
1918 hprintf("Content-type: application/json; charset=utf-8\r\n");
1919 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
1920 hprintf("Connection: close\r\n");
1921 hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
1925 /* Spit out the new summary view. This is basically a static page, so clients can cache the layout, all the dirty work is javascript :) */
1926 void new_summary_view(void) {
1928 DoTemplate(HKEY("msg_listview"),NULL,&NoCtx);
1929 DoTemplate(HKEY("trailing"),NULL,&NoCtx);
1933 /* Output message list in JSON format */
1934 void jsonMessageList(void) {
1935 const StrBuf *room = sbstr("room");
1936 long oper = (havebstr("query")) ? do_search : readnew;
1947 RegisterPreference("use_sig",
1948 _("Attach signature to email messages?"),
1951 RegisterPreference("signature", _("Use this signature:"), PRF_QP_STRING, NULL);
1952 RegisterPreference("default_header_charset",
1953 _("Default character set for email headers:"),
1956 RegisterPreference("defaultfrom", _("Preferred email address"), PRF_STRING, NULL);
1957 RegisterPreference("defaultname",
1958 _("Preferred display name for email messages"),
1961 RegisterPreference("defaulthandle",
1962 _("Preferred display name for bulletin board posts"),
1965 RegisterPreference("mailbox",_("Mailbox view mode"), PRF_STRING, NULL);
1967 WebcitAddUrlHandler(HKEY("readnew"), h_readnew, NEED_URL);
1968 WebcitAddUrlHandler(HKEY("readold"), h_readold, NEED_URL);
1969 WebcitAddUrlHandler(HKEY("readfwd"), h_readfwd, NEED_URL);
1970 WebcitAddUrlHandler(HKEY("headers"), h_headers, NEED_URL);
1971 WebcitAddUrlHandler(HKEY("do_search"), h_do_search, 0);
1972 WebcitAddUrlHandler(HKEY("display_enter"), display_enter, 0);
1973 WebcitAddUrlHandler(HKEY("post"), post_message, 0);
1974 WebcitAddUrlHandler(HKEY("move_msg"), move_msg, 0);
1975 WebcitAddUrlHandler(HKEY("delete_msg"), delete_msg, 0);
1976 WebcitAddUrlHandler(HKEY("confirm_move_msg"), confirm_move_msg, 0);
1977 WebcitAddUrlHandler(HKEY("msg"), embed_message, NEED_URL);
1978 WebcitAddUrlHandler(HKEY("message"), handle_one_message, NEED_URL|XHTTP_COMMANDS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
1979 WebcitAddUrlHandler(HKEY("printmsg"), print_message, NEED_URL);
1980 WebcitAddUrlHandler(HKEY("mobilemsg"), mobile_message_view, NEED_URL);
1981 WebcitAddUrlHandler(HKEY("msgheaders"), display_headers, NEED_URL);
1983 WebcitAddUrlHandler(HKEY("mimepart"), view_mimepart, NEED_URL);
1984 WebcitAddUrlHandler(HKEY("mimepart_download"), download_mimepart, NEED_URL);
1985 WebcitAddUrlHandler(HKEY("postpart"), view_postpart, NEED_URL);
1986 WebcitAddUrlHandler(HKEY("postpart_download"), download_postpart, NEED_URL);
1989 WebcitAddUrlHandler(HKEY("roommsgs"), jsonMessageList,0);
1994 SessionDetachModule_MSG
1997 DeleteHash(&sess->summ);