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 StrBufLowerCase(Buf);
236 /* look up the renderer, that will convert this mimeitem into the htmlized form */
237 if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
239 RenderMimeFuncStruct *Render;
240 Render = (RenderMimeFuncStruct*)vHdr;
241 Render->f(Msg->MsgBody, NULL, FoundCharset);
244 if (StrLength(Msg->reply_references)> 0) {
245 /* Trim down excessively long lists of thread references. We eliminate the
246 * second one in the list so that the thread root remains intact.
248 int rrtok = num_tokens(ChrPtr(Msg->reply_references), '|');
249 int rrlen = StrLength(Msg->reply_references);
250 if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
251 StrBufRemove_token(Msg->reply_references, 1, '|');
255 /* now check if we need to translate some mimeparts, and remove the duplicate */
256 it = GetNewHashPos(Msg->AllAttach, 0);
257 while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) &&
259 wc_mime_attachment *Mime = (wc_mime_attachment*) vMime;
260 evaluate_mime_part(Msg, Mime);
263 memset(&SubTP, 0, sizeof(WCTemplputParams));
264 SubTP.Filter.ContextType = CTX_MAILSUM;
266 *OutMime = DoTemplate(tmpl, tmpllen, Target, &SubTP);
268 DestroyMessageSummary(Msg);
269 FreeStrBuf(&FoundCharset);
276 HttpStatus(long CitadelStatus)
278 long httpstatus = 502;
280 switch (MAJORCODE(CitadelStatus))
282 case LISTING_FOLLOWS:
287 switch (MINORCODE(CitadelStatus))
295 case HIGHER_ACCESS_REQUIRED:
296 case MAX_SESSIONS_EXCEEDED:
298 case RESOURCE_NOT_OPEN:
300 case INVALID_FLOOR_OPERATION:
306 case MESSAGE_NOT_FOUND:
316 case CMD_NOT_SUPPORTED:
317 case PASSWORD_REQUIRED:
318 case ALREADY_LOGGED_IN:
319 case USERNAME_REQUIRED:
321 case SERVER_SHUTTING_DOWN:
332 case START_CHAT_MODE:
336 httpstatus = 502; /* aeh... whut? */
344 * Unadorned HTML output of an individual message, suitable
345 * for placing in a hidden iframe, for printing, or whatever
347 void handle_one_message(void)
351 const StrBuf *Destination;
357 StrBuf *CmdBuf = NULL;
361 pMsg = strchr(ChrPtr(WCC->Hdr->HR.ReqLine), '/');
363 HttpStatus(CitStatus);
367 msgnum = atol(pMsg + 1);
368 StrBufCutAt(WCC->Hdr->HR.ReqLine, 0, pMsg);
369 gotoroom(WCC->Hdr->HR.ReqLine);
370 switch (WCC->Hdr->HR.eReqType)
374 Tmpl = sbstr("template");
375 if (StrLength(Tmpl) > 0)
376 read_message(WCC->WBuf, SKEY(Tmpl), msgnum, NULL, &Mime);
378 read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
379 http_transmit_thing(ChrPtr(Mime), 0);
382 CmdBuf = NewStrBuf ();
383 if (WCC->wc_is_trash) { /* Delete from Trash is a real delete */
384 serv_printf("DELE %ld", msgnum);
386 else { /* Otherwise move it to Trash */
387 serv_printf("MOVE %ld|_TRASH_|0", msgnum);
389 StrBuf_ServGetln(CmdBuf);
390 FlushStrBuf(WCC->ImportantMsg);
391 StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
392 GetServerStatus(CmdBuf, &CitStatus);
393 HttpStatus(CitStatus);
398 if (GetHash(WCC->Hdr->HTTPHeaders, HKEY("DESTINATION"), &vLine) &&
400 Destination = (StrBuf*) vLine;
401 serv_printf("MOVE %ld|%s|%d", msgnum, ChrPtr(Destination), CopyMessage);
402 StrBuf_ServGetln(CmdBuf);
403 FlushStrBuf(WCC->ImportantMsg);
404 StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
405 GetServerStatus(CmdBuf, &CitStatus);
406 HttpStatus(CitStatus);
419 * Unadorned HTML output of an individual message, suitable
420 * for placing in a hidden iframe, for printing, or whatever
422 void embed_message(void) {
427 StrBuf *CmdBuf = NULL;
429 msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/');
430 switch (WCC->Hdr->HR.eReqType)
434 Tmpl = sbstr("template");
435 if (StrLength(Tmpl) > 0)
436 read_message(WCC->WBuf, SKEY(Tmpl), msgnum, NULL, &Mime);
438 read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
439 http_transmit_thing(ChrPtr(Mime), 0);
442 CmdBuf = NewStrBuf ();
443 if (WCC->wc_is_trash) { /* Delete from Trash is a real delete */
444 serv_printf("DELE %ld", msgnum);
446 else { /* Otherwise move it to Trash */
447 serv_printf("MOVE %ld|_TRASH_|0", msgnum);
449 StrBuf_ServGetln(CmdBuf);
450 FlushStrBuf(WCC->ImportantMsg);
451 StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
461 * Printable view of a message
463 void print_message(void) {
467 msgnum = StrBufExtract_long(WC->Hdr->HR.ReqLine, 0, '/');
468 output_headers(0, 0, 0, 0, 0, 0);
470 hprintf("Content-type: text/html\r\n"
471 "Server: " PACKAGE_STRING "\r\n"
472 "Connection: close\r\n");
476 read_message(WC->WBuf, HKEY("view_message_print"), msgnum, NULL, &Mime);
482 * Mobile browser view of message
484 void mobile_message_view(void)
489 msgnum = StrBufExtract_long(WC->Hdr->HR.ReqLine, 0, '/');
490 output_headers(1, 0, 0, 0, 0, 1);
492 do_template("msgcontrols", NULL);
493 read_message(WC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
498 * Display a message's headers
500 void display_headers(void) {
504 msgnum = StrBufExtract_long(WC->Hdr->HR.ReqLine, 0, '/');
505 output_headers(0, 0, 0, 0, 0, 0);
507 hprintf("Content-type: text/plain\r\n"
509 "Connection: close\r\n",
513 serv_printf("MSG2 %ld|3", msgnum);
514 serv_getln(buf, sizeof buf);
516 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
517 wprintf("%s\n", buf);
525 message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSubject, long MsgNum)
528 MsgPartEvaluatorStruct *Eval;
529 message_summary *Msg;
538 serv_printf("MSG0 %ld|1", MsgNum); /* ask for headers only */
540 StrBuf_ServGetln(Buf);
541 if (GetServerStatus(Buf, NULL) == 1) {
546 Msg = (message_summary*)malloc(sizeof(message_summary));
547 memset(Msg, 0, sizeof(message_summary));
548 while (len = StrBuf_ServGetln(Buf),
550 strcmp(ChrPtr(Buf), "000")== 0)){
552 ebuf = strchr(ChrPtr(Buf), '=');
554 if (GetHash(MsgEvaluators, buf, nBuf, &vEval) && vEval != NULL) {
555 Eval = (MsgPartEvaluatorStruct*) vEval;
556 StrBufCutLeft(Buf, nBuf + 1);
559 else lprintf(1, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
569 * load message pointers from the server for a "read messages" operation
571 * servcmd: the citadel command to send to the citserver
572 * with_headers: also include some of the headers with the message numbers (more expensive)
574 int load_msg_ptrs(const char *servcmd, int with_headers, long *lowest_found, long *highest_found)
576 StrBuf* FoundCharset = NULL;
578 message_summary *Msg;
585 const char *Ptr = NULL;
587 if (lowest_found) *lowest_found = LONG_MAX;
588 if (highest_found) *highest_found = LONG_MIN;
590 if (WCC->summ != NULL) {
591 DeleteHash(&WCC->summ);
593 WCC->summ = NewHash(1, Flathash);
598 StrBuf_ServGetln(Buf);
599 if (GetServerStatus(Buf, NULL) != 1) {
604 while (len = StrBuf_ServGetln(Buf), ((len != 3) || strcmp(ChrPtr(Buf), "000")!= 0))
606 if (nummsgs < maxload) {
609 Msg = (message_summary*)malloc(sizeof(message_summary));
610 memset(Msg, 0, sizeof(message_summary));
612 Msg->msgnum = StrBufExtractNext_long(Buf, &Ptr, '|');
613 Msg->date = StrBufExtractNext_long(Buf, &Ptr, '|');
616 if ((lowest_found) && (Msg->msgnum < *lowest_found)) {
617 *lowest_found = Msg->msgnum;
619 if ((highest_found) && (Msg->msgnum > *highest_found)) {
620 *highest_found = Msg->msgnum;
624 if ((Msg->msgnum == 0) && (StrLength(Buf) < 32)) {
630 * as citserver probably gives us messages in forward date sorting
631 * nummsgs should be the same order as the message date.
633 if (Msg->date == 0) {
635 if (StrLength(Buf) < 32)
639 Msg->from = NewStrBufPlain(NULL, StrLength(Buf));
640 StrBufExtract_NextToken(Buf2, Buf, &Ptr, '|');
641 if (StrLength(Buf2) != 0) {
642 /* Handle senders with RFC2047 encoding */
643 StrBuf_RFC822_to_Utf8(Msg->from, Buf2, WCC->DefaultCharset, FoundCharset);
647 StrBufExtract_NextToken(Buf2, Buf, &Ptr, '|');
648 if ((StrLength(Buf2) !=0 ) &&
649 ( ((WCC->room_flags & QR_NETWORK)
650 || ((strcasecmp(ChrPtr(Buf2), ChrPtr(WCC->serv_info->serv_nodename))
651 && (strcasecmp(ChrPtr(Buf2), ChrPtr(WCC->serv_info->serv_fqdn))))))))
653 StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
654 StrBufAppendBuf(Msg->from, Buf2, 0);
657 /* Internet address (not used)
658 * StrBufExtract_token(Msg->inetaddr, Buf, 4, '|');
660 StrBufSkip_NTokenS(Buf, &Ptr, '|', 1);
661 Msg->subj = NewStrBufPlain(NULL, StrLength(Buf));
662 StrBufExtract_NextToken(Buf2, Buf, &Ptr, '|');
663 if (StrLength(Buf2) == 0)
664 StrBufAppendBufPlain(Msg->subj, _("(no subject)"), -1,0);
666 StrBuf_RFC822_to_Utf8(Msg->subj, Buf2, WCC->DefaultCharset, FoundCharset);
667 if ((StrLength(Msg->subj) > 75) &&
668 (StrBuf_Utf8StrLen(Msg->subj) > 75)) {
669 StrBuf_Utf8StrCut(Msg->subj, 72);
670 StrBufAppendBufPlain(Msg->subj, HKEY("..."), 0);
674 if ((StrLength(Msg->from) > 25) &&
675 (StrBuf_Utf8StrLen(Msg->from) > 25)) {
676 StrBuf_Utf8StrCut(Msg->from, 23);
677 StrBufAppendBufPlain(Msg->from, HKEY("..."), 0);
681 Put(WCC->summ, (const char *)&n, sizeof(n), Msg, DestroyMessageSummary);
691 inline message_summary* GetMessagePtrAt(int n, HashList *Summ)
699 GetHashAt(Summ, n, &HKLen, &Key, &vMsg);
700 return (message_summary*) vMsg;
704 /* startmsg is an index within the message list.
705 * starting_from is the Citadel message number to be supplied to a "MSGS GT" operation
707 long DrawMessageDropdown(StrBuf *Selector, long maxmsgs, long startmsg, int nMessages, long starting_from)
720 WCTemplputParams SubTP;
722 memset(&SubTP, 0, sizeof(WCTemplputParams));
723 SubTP.Filter.ContextType = CTX_LONGVECTOR;
724 SubTP.Context = &vector;
725 TmpBuf = NewStrBufPlain(NULL, SIZ);
726 At = GetNewHashPos(WCC->summ, nMessages);
727 nItems = GetCount(WCC->summ);
731 vector[1] = startmsg;
733 vector[7] = starting_from;
736 vector[3] = abs(nMessages);
737 lo = GetHashPosCounter(At);
739 if (lo + nMessages >= nItems) {
741 vector[3] = nItems - lo;
746 hi = lo + nMessages - 1;
749 if (lo + nMessages < -1) {
753 if ((lo % abs(nMessages)) != 0) {
754 int offset = (lo % abs(nMessages) *
755 (nMessages / abs(nMessages)));
757 vector[3] = abs(offset);
765 done = !GetNextHashPos(WCC->summ, At, &hklen, &key, &vMsg);
768 * Bump these because although we're thinking in zero base, the user
769 * is a drooling idiot and is thinking in one base.
775 dbg_print_longvector(vector);
776 DoTemplate(HKEY("select_messageindex"), TmpBuf, &SubTP);
777 StrBufAppendBuf(Selector, TmpBuf, 0);
781 if (maxmsgs == 9999999) {
788 dbg_print_longvector(vector);
789 DoTemplate(HKEY("select_messageindex_all"), TmpBuf, &SubTP);
790 StrBufAppendBuf(Selector, TmpBuf, 0);
796 void load_seen_flags(void)
798 message_summary *Msg;
806 OldMsg = NewStrBuf();
808 StrBuf_ServGetln(OldMsg);
809 if (GetServerStatus(OldMsg, NULL) == 2) {
810 StrBufCutLeft(OldMsg, 4);
816 at = GetNewHashPos(WCC->summ, 0);
817 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
818 /* Are you a new message, or an old message? */
819 Msg = (message_summary*) vMsg;
820 if (is_msg_in_mset(ChrPtr(OldMsg), Msg->msgnum)) {
831 extern readloop_struct rlid[];
834 * command loop for reading messages
836 * Set oper to "readnew" or "readold" or "readfwd" or "headers" or "readgt"
838 void readloop(long oper)
840 StrBuf *MessageDropdown = NULL;
841 StrBuf *BBViewToolBar = NULL;
843 message_summary *Msg;
847 int with_headers = 0;
851 long *displayed_msgs = NULL;
852 int num_displayed = 0;
853 int is_singlecard = 0;
856 int lowest_displayed = (-1);
857 int highest_displayed = 0;
858 addrbookent *addrbook = NULL;
865 int care_for_empty_list = 0;
868 int defaultsortorder = 0;
869 WCTemplputParams SubTP;
872 long lowest_found = (-1);
873 long highest_found = (-1);
875 if (havebstr("is_summary") && (1 == (ibstr("is_summary"))))
876 WCC->wc_view = VIEW_MAILBOX;
879 output_headers(1, 1, 1, 0, 0, 0);
880 } else if (WCC->wc_view == VIEW_MAILBOX) {
881 jsonMessageListHdr();
884 switch (WCC->wc_view) {
886 sprintf(buf, "wiki?room=%s&page=home", ChrPtr(WCC->wc_roomname));
892 strcpy(cmd, "MSGS ALL");
894 parse_calendar_view_request(&calv);
897 strcpy(cmd, "MSGS ALL");
901 strcpy(cmd, "MSGS ALL");
903 wprintf("<div id=\"new_notes_here\"></div>\n");
905 case VIEW_ADDRESSBOOK:
906 is_singlecard = ibstr("is_singlecard");
907 if (is_singlecard != 1) {
908 if (oper == do_search) {
909 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
912 strcpy(cmd, "MSGS ALL");
923 defaultsortorder = 2;
926 care_for_empty_list = 0;
928 /* Generally using maxmsgs|startmsg is not required
929 in mailbox view, but we have a 'safemode' for clients
930 (*cough* Exploder) that simply can't handle too many */
931 if (havebstr("maxmsgs")) maxmsgs = ibstr("maxmsgs");
932 else maxmsgs = 9999999;
933 if (havebstr("startmsg")) startmsg = lbstr("startmsg");
934 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
935 (oper == do_search) ? "SEARCH" : "ALL",
936 (oper == do_search) ? bstr("query") : ""
942 defaultsortorder = 1;
945 care_for_empty_list = 1;
947 rlid[oper].cmd(cmd, sizeof(cmd));
949 if (havebstr("maxmsgs"))
950 maxmsgs = ibstr("maxmsgs");
951 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
953 if (havebstr("startmsg")) {
954 startmsg = lbstr("startmsg");
959 nummsgs = load_msg_ptrs(cmd, with_headers, &lowest_found, &highest_found);
961 if (care_for_empty_list) {
962 wprintf("<div class=\"nomsgs\"><br><em>");
965 wprintf(_("No new messages."));
968 wprintf(_("No old messages."));
971 wprintf(_("No messages here."));
973 wprintf("</em><br></div>\n");
981 memset(&SubTP, 0, sizeof(WCTemplputParams));
982 SubTP.Filter.ContextType = CTX_NONE;
983 SubTP.Context = NULL;
984 SortIt = RetrieveSort(&SubTP, NULL, 0,
985 HKEY("date"), defaultsortorder);
987 SortByPayload(WCC->summ, SortIt);
988 if (WCC->wc_view == VIEW_BBS) {
989 if (lbstr("SortOrder") == 2) {
991 num_displayed = -DEFAULT_MAXMSGS;
995 num_displayed = DEFAULT_MAXMSGS;
999 if (startmsg < 0) startmsg = (bbs_reverse) ? nummsgs - 1 : 0;
1001 if (load_seen) load_seen_flags();
1004 * Print any inforation above the message list...
1006 switch (WCC->wc_view) {
1008 BBViewToolBar = NewStrBufPlain(NULL, SIZ);
1009 MessageDropdown = NewStrBufPlain(NULL, SIZ);
1011 maxmsgs = DrawMessageDropdown(MessageDropdown, maxmsgs, startmsg,
1012 num_displayed, lowest_found-1);
1013 if (num_displayed < 0) {
1014 startmsg += maxmsgs;
1015 if (num_displayed != maxmsgs)
1016 maxmsgs = abs(maxmsgs) + 1;
1018 maxmsgs = abs(maxmsgs);
1021 memset(&SubTP, 0, sizeof(WCTemplputParams));
1022 SubTP.Filter.ContextType = CTX_STRBUF;
1023 SubTP.Context = MessageDropdown;
1024 DoTemplate(HKEY("msg_listselector_top"), BBViewToolBar, &SubTP);
1025 StrBufAppendBuf(WCC->WBuf, BBViewToolBar, 0);
1026 FlushStrBuf(BBViewToolBar);
1029 WCC->startmsg = startmsg;
1030 WCC->maxmsgs = maxmsgs;
1031 WCC->num_displayed = 0;
1033 /* Put some helpful data in vars for mailsummary_json */
1034 svputlong("READLOOP:TOTALMSGS", nummsgs);
1035 svputlong("READLOOP:STARTMSG", startmsg);
1036 svputlong("WCVIEW", WCC->wc_view);
1039 * iterate over each message. if we need to load an attachment, do it here.
1041 if (WCC->wc_view == VIEW_MAILBOX) goto NO_MSG_LOOP;
1042 at = GetNewHashPos(WCC->summ, 0);
1043 num_displayed = i = 0;
1044 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
1045 Msg = (message_summary*) vMsg;
1046 if ((Msg->msgnum >= startmsg) && (num_displayed <= maxmsgs)) {
1047 switch (WCC->wc_view) {
1050 case VIEW_CALBRIEF: /* load the mime attachments for special tasks... */
1052 load_calendar_item(Msg, Msg->is_new, &calv);
1055 display_task(Msg, Msg->is_new);
1058 display_note(Msg, Msg->is_new);
1060 case VIEW_ADDRESSBOOK:
1062 fetch_ab_name(Msg, &ab_name);
1063 if (ab_name == NULL)
1066 addrbook = realloc(addrbook,
1067 (sizeof(addrbookent) * num_ab) );
1068 safestrncpy(addrbook[num_ab-1].ab_name, ab_name,
1069 sizeof(addrbook[num_ab-1].ab_name));
1070 addrbook[num_ab-1].ab_msgnum = Msg->msgnum;
1073 case VIEW_BBS: /* Tag the mails we want to show in bbview... */
1075 if (displayed_msgs == NULL) {
1076 displayed_msgs = malloc(sizeof(long) *
1077 (maxmsgs<nummsgs ? maxmsgs + 1 : nummsgs + 1));
1079 if ((i >= startmsg) && (i < startmsg + maxmsgs)) {
1080 displayed_msgs[num_displayed] = Msg->msgnum;
1081 if (lowest_displayed < 0) lowest_displayed = a;
1082 highest_displayed = a;
1094 * Done iterating the message list. now tasks we want to do after.
1096 switch (WCC->wc_view) {
1098 DoTemplate(HKEY("mailsummary_json"),NULL, &SubTP);
1101 if (displayed_msgs != NULL) {
1102 /* if we do a split bbview in the future, begin messages div here */
1104 for (a=0; a<num_displayed; ++a) {
1105 read_message(WCC->WBuf, HKEY("view_message"), displayed_msgs[a], NULL, &Mime);
1108 /* if we do a split bbview in the future, end messages div here */
1110 free(displayed_msgs);
1111 displayed_msgs = NULL;
1113 memset(&SubTP, 0, sizeof(WCTemplputParams));
1114 SubTP.Filter.ContextType = CTX_STRBUF;
1115 SubTP.Context = MessageDropdown;
1116 DoTemplate(HKEY("msg_listselector_bottom"), BBViewToolBar, &SubTP);
1117 StrBufAppendBuf(WCC->WBuf, BBViewToolBar, 0);
1119 FreeStrBuf(&BBViewToolBar);
1120 FreeStrBuf(&MessageDropdown);
1125 switch (WCC->wc_view) {
1130 render_calendar_view(&calv);
1133 do_tasks_view(); /* Render the task list */
1137 case VIEW_ADDRESSBOOK:
1139 read_message(WC->WBuf, HKEY("view_message"), lbstr("startmsg"), NULL, &Mime);
1141 do_addrbook_view(addrbook, num_ab); /* Render the address book */
1148 /* Note: wDumpContent() will output one additional </div> tag. */
1149 if (WCC->wc_view != VIEW_MAILBOX) {
1150 /* We ought to move this out into template */
1157 if (WCC->summ != NULL) {
1158 DeleteHash(&WCC->summ);
1160 if (addrbook != NULL) free(addrbook);
1161 FreeStrBuf(&BBViewToolBar);
1166 * Back end for post_message()
1167 * ... this is where the actual message gets transmitted to the server.
1169 void post_mime_to_server(void) {
1170 wcsession *WCC = WC;
1171 char top_boundary[SIZ];
1172 char alt_boundary[SIZ];
1173 int is_multipart = 0;
1175 wc_mime_attachment *att;
1177 size_t encoded_length;
1178 size_t encoded_strlen;
1179 char *txtmail = NULL;
1181 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
1182 ChrPtr(WCC->serv_info->serv_fqdn),
1186 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
1187 ChrPtr(WCC->serv_info->serv_fqdn),
1192 /* RFC2045 requires this, and some clients look for it... */
1193 serv_puts("MIME-Version: 1.0");
1194 serv_puts("X-Mailer: " PACKAGE_STRING);
1196 /* If there are attachments, we have to do multipart/mixed */
1197 if (GetCount(WCC->attachments) > 0) {
1202 /* Remember, serv_printf() appends an extra newline */
1203 serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
1204 serv_printf("This is a multipart message in MIME format.\n");
1205 serv_printf("--%s", top_boundary);
1208 /* Remember, serv_printf() appends an extra newline */
1209 serv_printf("Content-type: multipart/alternative; "
1210 "boundary=\"%s\"\n", alt_boundary);
1211 serv_printf("This is a multipart message in MIME format.\n");
1212 serv_printf("--%s", alt_boundary);
1214 serv_puts("Content-type: text/plain; charset=utf-8");
1215 serv_puts("Content-Transfer-Encoding: quoted-printable");
1217 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
1218 text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */
1221 serv_printf("--%s", alt_boundary);
1223 serv_puts("Content-type: text/html; charset=utf-8");
1224 serv_puts("Content-Transfer-Encoding: quoted-printable");
1226 serv_puts("<html><body>\r\n");
1227 text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */
1228 serv_puts("</body></html>\r\n");
1230 serv_printf("--%s--", alt_boundary);
1238 /* Add in the attachments */
1239 it = GetNewHashPos(WCC->attachments, 0);
1240 while (GetNextHashPos(WCC->attachments, it, &len, &Key, &vAtt)) {
1241 att = (wc_mime_attachment *)vAtt;
1242 encoded_length = ((att->length * 150) / 100);
1243 encoded = malloc(encoded_length);
1244 if (encoded == NULL) break;
1245 encoded_strlen = CtdlEncodeBase64(encoded, ChrPtr(att->Data), StrLength(att->Data), 1);
1247 serv_printf("--%s", top_boundary);
1248 serv_printf("Content-type: %s", ChrPtr(att->ContentType));
1249 serv_printf("Content-disposition: attachment; filename=\"%s\"", ChrPtr(att->FileName));
1250 serv_puts("Content-transfer-encoding: base64");
1252 serv_write(encoded, encoded_strlen);
1257 serv_printf("--%s--", top_boundary);
1266 * Post message (or don't post message)
1268 * Note regarding the "dont_post" variable:
1269 * A random value (actually, it's just a timestamp) is inserted as a hidden
1270 * field called "postseq" when the display_enter page is generated. This
1271 * value is checked when posting, using the static variable dont_post. If a
1272 * user attempts to post twice using the same dont_post value, the message is
1273 * discarded. This prevents the accidental double-saving of the same message
1274 * if the user happens to click the browser "back" button.
1276 void post_message(void)
1279 StrBuf *encoded_subject = NULL;
1280 static long dont_post = (-1L);
1281 wc_mime_attachment *att;
1282 int is_anonymous = 0;
1283 const StrBuf *display_name = NULL;
1284 wcsession *WCC = WC;
1287 if (havebstr("force_room")) {
1288 gotoroom(sbstr("force_room"));
1291 if (havebstr("display_name")) {
1292 display_name = sbstr("display_name");
1293 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
1294 display_name = NULL;
1299 if (WCC->upload_length > 0) {
1304 /* There's an attachment. Save it to this struct... */
1305 lprintf(9, "Client is uploading %d bytes\n", WCC->upload_length);
1306 att = malloc(sizeof(wc_mime_attachment));
1307 memset(att, 0, sizeof(wc_mime_attachment ));
1308 att->length = WCC->upload_length;
1309 att->ContentType = NewStrBufPlain(WCC->upload_content_type, -1);
1310 att->FileName = NewStrBufPlain(WCC->upload_filename, -1);
1312 if (WCC->attachments == NULL) {
1313 WCC->attachments = NewHash(1, NULL);
1316 /* And add it to the list. */
1317 n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
1318 Put(WCC->attachments, N, n, att, DestroyMime);
1321 * Mozilla sends a simple filename, which is what we want,
1322 * but Satan's Browser sends an entire pathname. Reduce
1323 * the path to just a filename if we need to.
1325 pch = strrchr(ChrPtr(att->FileName), '/');
1327 StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1);
1329 pch = strrchr(ChrPtr(att->FileName), '\\');
1331 StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1);
1335 * Transfer control of this memory from the upload struct
1336 * to the attachment struct.
1338 att->Data = WCC->upload;
1340 WCC->upload_length = 0;
1345 if (havebstr("cancel_button")) {
1346 sprintf(WCC->ImportantMessage,
1347 _("Cancelled. Message was not posted."));
1348 } else if (havebstr("attach_button")) {
1351 } else if (lbstr("postseq") == dont_post) {
1352 sprintf(WCC->ImportantMessage,
1353 _("Automatically cancelled because you have already "
1354 "saved this message."));
1356 const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s";
1357 const StrBuf *Recp = NULL;
1358 const StrBuf *Cc = NULL;
1359 const StrBuf *Bcc = NULL;
1360 const StrBuf *Wikipage = NULL;
1361 const StrBuf *my_email_addr = NULL;
1362 StrBuf *CmdBuf = NULL;
1363 StrBuf *references = NULL;
1366 save_to_drafts = havebstr("save_button");
1369 if (save_to_drafts) {
1370 /* temporarily change to the drafts room */
1371 serv_puts("GOTO _DRAFTS_");
1372 StrBuf_ServGetln(Buf);
1373 if (GetServerStatus(Buf, NULL) != 2) {
1374 /* You probably don't even have a dumb Drafts folder */
1375 StrBufCutLeft(Buf, 4);
1376 lprintf(9, "%s:%d: server save to drafts error: %s\n", __FILE__, __LINE__, ChrPtr(Buf));
1377 StrBufAppendBufPlain(WCC->ImportantMsg, _("Saved to Drafts failed: "), -1, 0);
1378 StrBufAppendBuf(WCC->ImportantMsg, Buf, 0);
1385 if (havebstr("references"))
1387 const StrBuf *ref = sbstr("references");
1388 references = NewStrBufDup(ref);
1389 if (*ChrPtr(references) == '|') { /* remove leading '|' if present */
1390 StrBufCutLeft(references, 1);
1392 StrBufReplaceChars(references, '|', '!');
1394 if (havebstr("subject")) {
1397 * make enough room for the encoded string;
1398 * plus the QP header
1400 Subj = sbstr("subject");
1402 StrBufRFC2047encode(&encoded_subject, Subj);
1404 Recp = sbstr("recp");
1407 Wikipage = sbstr("wikipage");
1408 my_email_addr = sbstr("my_email_addr");
1410 CmdBuf = NewStrBufPlain(NULL,
1413 StrLength(encoded_subject) +
1416 StrLength(Wikipage) +
1417 StrLength(my_email_addr) +
1418 StrLength(references));
1420 StrBufPrintf(CmdBuf,
1422 save_to_drafts?"":ChrPtr(Recp),
1424 ChrPtr(encoded_subject),
1425 ChrPtr(display_name),
1426 save_to_drafts?"":ChrPtr(Cc),
1427 save_to_drafts?"":ChrPtr(Bcc),
1429 ChrPtr(my_email_addr),
1430 ChrPtr(references));
1431 FreeStrBuf(&references);
1432 FreeStrBuf(&encoded_subject);
1434 lprintf(9, "%s\n", ChrPtr(CmdBuf));
1435 serv_puts(ChrPtr(CmdBuf));
1436 FreeStrBuf(&CmdBuf);
1438 StrBuf_ServGetln(Buf);
1439 if (GetServerStatus(Buf, NULL) == 4) {
1440 if (save_to_drafts) {
1441 if ( (havebstr("recp"))
1442 || (havebstr("cc" ))
1443 || (havebstr("bcc" )) ) {
1444 /* save recipient headers or room to post to */
1445 serv_printf("To: %s", ChrPtr(Recp));
1446 serv_printf("Cc: %s", ChrPtr(Cc));
1447 serv_printf("Bcc: %s", ChrPtr(Bcc));
1449 serv_printf("X-Citadel-Room: %s", ChrPtr(WC->wc_roomname));
1452 post_mime_to_server();
1453 if (save_to_drafts) {
1454 StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been saved to Drafts.\n"), -1, 0);
1455 gotoroom(WCC->wc_roomname);
1459 } else if ( (havebstr("recp"))
1460 || (havebstr("cc" ))
1461 || (havebstr("bcc" ))
1463 StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been sent.\n"), -1, 0);
1466 StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been posted.\n"), -1, 0);
1468 dont_post = lbstr("postseq");
1470 StrBufCutLeft(Buf, 4);
1472 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, ChrPtr(Buf));
1473 StrBufAppendBuf(WCC->ImportantMsg, Buf, 0);
1474 if (save_to_drafts) gotoroom(WCC->wc_roomname);
1482 DeleteHash(&WCC->attachments);
1485 * We may have been supplied with instructions regarding the location
1486 * to which we must return after posting. If found, go there.
1488 if (havebstr("return_to")) {
1489 http_redirect(bstr("return_to"));
1492 * If we were editing a page in a wiki room, go to that page now.
1494 else if (havebstr("wikipage")) {
1495 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
1499 * Otherwise, just go to the "read messages" loop.
1510 * display the message entry screen
1512 void display_enter(void)
1516 const StrBuf *display_name = NULL;
1517 int recipient_required = 0;
1518 int subject_required = 0;
1519 int recipient_bad = 0;
1520 int is_anonymous = 0;
1521 wcsession *WCC = WC;
1525 if (havebstr("force_room")) {
1526 gotoroom(sbstr("force_room"));
1529 display_name = sbstr("display_name");
1530 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
1531 display_name = NULL;
1535 /* First test to see whether this is a room that requires recipients to be entered */
1536 serv_puts("ENT0 0");
1537 serv_getln(buf, sizeof buf);
1539 if (!strncmp(buf, "570", 3)) { /* 570 means that we need a recipient here */
1540 recipient_required = 1;
1542 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
1543 sprintf(WCC->ImportantMessage, "%s", &buf[4]);
1548 /* Is the server strongly recommending that the user enter a message subject? */
1549 if ((buf[3] != '\0') && (buf[4] != '\0')) {
1550 subject_required = extract_int(&buf[4], 1);
1554 * Are we perhaps in an address book view? If so, then an "enter
1555 * message" command really means "add new entry."
1557 if (WCC->wc_default_view == VIEW_ADDRESSBOOK) {
1558 do_edit_vcard(-1, "", NULL, NULL, "", ChrPtr(WCC->wc_roomname));
1563 * Are we perhaps in a calendar room? If so, then an "enter
1564 * message" command really means "add new calendar item."
1566 if (WCC->wc_default_view == VIEW_CALENDAR) {
1567 display_edit_event();
1572 * Are we perhaps in a tasks view? If so, then an "enter
1573 * message" command really means "add new task."
1575 if (WCC->wc_default_view == VIEW_TASKS) {
1576 display_edit_task();
1581 * Otherwise proceed normally.
1582 * Do a custom room banner with no navbar...
1585 if (recipient_required) {
1586 const StrBuf *Recp = NULL;
1587 const StrBuf *Cc = NULL;
1588 const StrBuf *Bcc = NULL;
1589 const StrBuf *Wikipage = NULL;
1590 StrBuf *CmdBuf = NULL;
1591 const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
1593 Recp = sbstr("recp");
1596 Wikipage = sbstr("wikipage");
1598 CmdBuf = NewStrBufPlain(NULL,
1601 StrLength(display_name) +
1604 StrLength(Wikipage));
1606 StrBufPrintf(CmdBuf,
1610 ChrPtr(display_name),
1614 serv_puts(ChrPtr(CmdBuf));
1615 serv_getln(buf, sizeof buf);
1616 FreeStrBuf(&CmdBuf);
1618 if (!strncmp(buf, "570", 3)) { /* 570 means we have an invalid recipient listed */
1619 if (havebstr("recp") &&
1625 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
1626 wprintf("<em>%s</em><br />\n", &buf[4]); /* TODO -> important message */
1630 svputlong("RCPTREQUIRED", recipient_required);
1631 svputlong("SUBJREQUIRED", recipient_required || subject_required);
1634 output_headers(1, 0, 0, 0, 1, 0);
1635 DoTemplate(HKEY("edit_message"), NULL, &NoCtx);
1644 void delete_msg(void)
1649 msgid = lbstr("msgid");
1651 if (WC->wc_is_trash) { /* Delete from Trash is a real delete */
1652 serv_printf("DELE %ld", msgid);
1654 else { /* Otherwise move it to Trash */
1655 serv_printf("MOVE %ld|_TRASH_|0", msgid);
1658 serv_getln(buf, sizeof buf);
1659 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1665 * move a message to another room
1672 msgid = lbstr("msgid");
1674 if (havebstr("move_button")) {
1675 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
1677 serv_getln(buf, sizeof buf);
1678 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1680 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
1688 * Confirm move of a message
1690 void confirm_move_msg(void)
1696 msgid = lbstr("msgid");
1699 output_headers(1, 1, 2, 0, 0, 0);
1700 wprintf("<div id=\"banner\">\n");
1702 wprintf(_("Confirm move of message"));
1704 wprintf("</div>\n");
1706 wprintf("<div id=\"content\" class=\"service\">\n");
1708 wprintf("<CENTER>");
1710 wprintf(_("Move this message to:"));
1711 wprintf("<br />\n");
1713 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
1714 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1715 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
1717 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
1719 serv_getln(buf, sizeof buf);
1720 if (buf[0] == '1') {
1721 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1722 extract_token(targ, buf, 0, '|', sizeof targ);
1723 wprintf("<OPTION>");
1728 wprintf("</SELECT>\n");
1729 wprintf("<br />\n");
1731 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
1733 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
1734 wprintf("</form></CENTER>\n");
1736 wprintf("</CENTER>\n");
1742 * Generic function to output an arbitrary MIME attachment from
1743 * message being composed
1745 * partnum The MIME part to be output
1746 * filename Fake filename to give
1747 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
1749 void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
1752 StrBuf *content_type;
1753 wc_mime_attachment *part;
1755 if (GetHash(WC->attachments, SKEY(partnum), &vPart) &&
1757 part = (wc_mime_attachment*) vPart;
1758 if (force_download) {
1759 content_type = NewStrBufPlain(HKEY("application/octet-stream"));
1762 content_type = NewStrBufDup(part->ContentType);
1764 StrBufAppendBuf(WC->WBuf, part->Data, 0);
1765 http_transmit_thing(ChrPtr(content_type), 0);
1767 hprintf("HTTP/1.1 404 %s\n", ChrPtr(partnum));
1768 output_headers(0, 0, 0, 0, 0, 0);
1769 hprintf("Content-Type: text/plain\r\n");
1770 wprintf(_("An error occurred while retrieving this part: %s/%s\n"),
1771 ChrPtr(partnum), ChrPtr(filename));
1774 FreeStrBuf(&content_type);
1779 * Generic function to output an arbitrary MIME part from an arbitrary
1780 * message number on the server.
1782 * msgnum Number of the item on the citadel server
1783 * partnum The MIME part to be output
1784 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
1786 void mimepart(int force_download)
1790 wcsession *WCC = WC;
1793 StrBuf *ContentType = NewStrBufPlain(HKEY("application/octet-stream"));
1796 att = Buf = NewStrBuf();
1797 msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/');
1798 StrBufExtract_token(att, WCC->Hdr->HR.ReqLine, 1, '/');
1800 serv_printf("OPNA %ld|%s", msgnum, ChrPtr(att));
1801 StrBuf_ServGetln(Buf);
1802 if (GetServerStatus(Buf, NULL) == 2) {
1803 StrBufCutLeft(Buf, 4);
1804 bytes = StrBufExtract_long(Buf, 0, '|');
1805 if (!force_download) {
1806 StrBufExtract_token(ContentType, Buf, 3, '|');
1809 read_server_binary(WCC->WBuf, bytes, Buf);
1811 StrBuf_ServGetln(Buf);
1812 CT = ChrPtr(ContentType);
1814 if (!force_download) {
1815 if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
1816 StrBufExtract_token(Buf, WCC->Hdr->HR.ReqLine, 2, '/');
1817 CT = GuessMimeByFilename(SKEY(Buf));
1819 if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
1820 CT = GuessMimeType(SKEY(WCC->WBuf));
1823 http_transmit_thing(CT, 0);
1825 StrBufCutLeft(Buf, 4);
1826 hprintf("HTTP/1.1 404 %s\n", ChrPtr(Buf));
1827 output_headers(0, 0, 0, 0, 0, 0);
1828 hprintf("Content-Type: text/plain\r\n");
1829 wprintf(_("An error occurred while retrieving this part: %s\n"),
1833 FreeStrBuf(&ContentType);
1839 * Read any MIME part of a message, from the server, into memory.
1841 StrBuf *load_mimepart(long msgnum, char *partnum)
1847 serv_printf("DLAT %ld|%s", msgnum, partnum);
1848 StrBuf_ServGetln(Buf);
1849 if (GetServerStatus(Buf, NULL) == 6) {
1850 StrBufCutLeft(Buf, 4);
1851 bytes = StrBufExtract_long(Buf, 0, '|');
1854 StrBuf_ServGetBLOBBuffered(Buf, bytes);
1864 * Read any MIME part of a message, from the server, into memory.
1866 void MimeLoadData(wc_mime_attachment *Mime)
1870 /* TODO: is there a chance the content type is different from the one we know? */
1871 serv_printf("DLAT %ld|%s", Mime->msgnum, ChrPtr(Mime->PartNum));
1873 StrBuf_ServGetln(Buf);
1874 if (GetServerStatus(Buf, NULL) == 6) {
1875 bytes = extract_long(&(ChrPtr(Buf)[4]), 0);
1877 if (Mime->Data == NULL)
1878 Mime->Data = NewStrBufPlain(NULL, bytes);
1879 StrBuf_ServGetBLOBBuffered(Mime->Data, bytes);
1882 FlushStrBuf(Mime->Data);
1883 /* TODO XImportant message */
1891 void view_mimepart(void) {
1895 void download_mimepart(void) {
1899 void view_postpart(void) {
1900 StrBuf *filename = NewStrBuf();
1901 StrBuf *partnum = NewStrBuf();
1903 StrBufExtract_token(partnum, WC->Hdr->HR.ReqLine, 0, '/');
1904 StrBufExtract_token(filename, WC->Hdr->HR.ReqLine, 1, '/');
1906 postpart(partnum, filename, 0);
1908 FreeStrBuf(&filename);
1909 FreeStrBuf(&partnum);
1912 void download_postpart(void) {
1913 StrBuf *filename = NewStrBuf();
1914 StrBuf *partnum = NewStrBuf();
1916 StrBufExtract_token(partnum, WC->Hdr->HR.ReqLine, 0, '/');
1917 StrBufExtract_token(filename, WC->Hdr->HR.ReqLine, 1, '/');
1919 postpart(partnum, filename, 1);
1921 FreeStrBuf(&filename);
1922 FreeStrBuf(&partnum);
1925 void h_readnew(void) { readloop(readnew);}
1926 void h_readold(void) { readloop(readold);}
1927 void h_readfwd(void) { readloop(readfwd);}
1928 void h_headers(void) { readloop(headers);}
1929 void h_do_search(void) { readloop(do_search);}
1930 void h_readgt(void) { readloop(readgt);}
1932 void jsonMessageListHdr(void)
1934 /* TODO: make a generic function */
1935 hprintf("HTTP/1.1 200 OK\r\n");
1936 hprintf("Content-type: application/json; charset=utf-8\r\n");
1937 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
1938 hprintf("Connection: close\r\n");
1939 hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
1943 /* Spit out the new summary view. This is basically a static page, so clients can cache the layout, all the dirty work is javascript :) */
1944 void new_summary_view(void) {
1946 DoTemplate(HKEY("msg_listview"),NULL,&NoCtx);
1947 DoTemplate(HKEY("trailing"),NULL,&NoCtx);
1951 /* Output message list in JSON format */
1952 void jsonMessageList(void) {
1953 const StrBuf *room = sbstr("room");
1954 long oper = (havebstr("query")) ? do_search : readnew;
1965 RegisterPreference("use_sig",
1966 _("Attach signature to email messages?"),
1969 RegisterPreference("signature", _("Use this signature:"), PRF_QP_STRING, NULL);
1970 RegisterPreference("default_header_charset",
1971 _("Default character set for email headers:"),
1974 RegisterPreference("defaultfrom", _("Preferred email address"), PRF_STRING, NULL);
1975 RegisterPreference("defaultname",
1976 _("Preferred display name for email messages"),
1979 RegisterPreference("defaulthandle",
1980 _("Preferred display name for bulletin board posts"),
1983 RegisterPreference("mailbox",_("Mailbox view mode"), PRF_STRING, NULL);
1985 WebcitAddUrlHandler(HKEY("readnew"), h_readnew, NEED_URL);
1986 WebcitAddUrlHandler(HKEY("readold"), h_readold, NEED_URL);
1987 WebcitAddUrlHandler(HKEY("readfwd"), h_readfwd, NEED_URL);
1988 WebcitAddUrlHandler(HKEY("headers"), h_headers, NEED_URL);
1989 WebcitAddUrlHandler(HKEY("readgt"), h_readgt, NEED_URL);
1990 WebcitAddUrlHandler(HKEY("do_search"), h_do_search, 0);
1991 WebcitAddUrlHandler(HKEY("display_enter"), display_enter, 0);
1992 WebcitAddUrlHandler(HKEY("post"), post_message, 0);
1993 WebcitAddUrlHandler(HKEY("move_msg"), move_msg, 0);
1994 WebcitAddUrlHandler(HKEY("delete_msg"), delete_msg, 0);
1995 WebcitAddUrlHandler(HKEY("confirm_move_msg"), confirm_move_msg, 0);
1996 WebcitAddUrlHandler(HKEY("msg"), embed_message, NEED_URL);
1997 WebcitAddUrlHandler(HKEY("message"), handle_one_message, NEED_URL|XHTTP_COMMANDS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
1998 WebcitAddUrlHandler(HKEY("printmsg"), print_message, NEED_URL);
1999 WebcitAddUrlHandler(HKEY("mobilemsg"), mobile_message_view, NEED_URL);
2000 WebcitAddUrlHandler(HKEY("msgheaders"), display_headers, NEED_URL);
2002 WebcitAddUrlHandler(HKEY("mimepart"), view_mimepart, NEED_URL);
2003 WebcitAddUrlHandler(HKEY("mimepart_download"), download_mimepart, NEED_URL);
2004 WebcitAddUrlHandler(HKEY("postpart"), view_postpart, NEED_URL);
2005 WebcitAddUrlHandler(HKEY("postpart_download"), download_postpart, NEED_URL);
2008 WebcitAddUrlHandler(HKEY("roommsgs"), jsonMessageList,0);
2013 SessionDetachModule_MSG
2016 DeleteHash(&sess->summ);