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 long DrawMessageDropdown(StrBuf *Selector, long maxmsgs, long startmsg, int nMessages)
717 WCTemplputParams SubTP;
719 memset(&SubTP, 0, sizeof(WCTemplputParams));
720 SubTP.Filter.ContextType = CTX_LONGVECTOR;
721 SubTP.Context = &vector;
722 TmpBuf = NewStrBufPlain(NULL, SIZ);
723 At = GetNewHashPos(WCC->summ, nMessages);
724 nItems = GetCount(WCC->summ);
728 vector[1] = startmsg;
732 vector[3] = abs(nMessages);
733 lo = GetHashPosCounter(At);
735 if (lo + nMessages >= nItems) {
737 vector[3] = nItems - lo;
742 hi = lo + nMessages - 1;
745 if (lo + nMessages < -1) {
749 if ((lo % abs(nMessages)) != 0) {
750 int offset = (lo % abs(nMessages) *
751 (nMessages / abs(nMessages)));
753 vector[3] = abs(offset);
761 done = !GetNextHashPos(WCC->summ, At, &hklen, &key, &vMsg);
764 * Bump these because although we're thinking in zero base, the user
765 * is a drooling idiot and is thinking in one base.
771 dbg_print_longvector(vector);
772 DoTemplate(HKEY("select_messageindex"), TmpBuf, &SubTP);
773 StrBufAppendBuf(Selector, TmpBuf, 0);
777 if (maxmsgs == 9999999) {
784 dbg_print_longvector(vector);
785 DoTemplate(HKEY("select_messageindex_all"), TmpBuf, &SubTP);
786 StrBufAppendBuf(Selector, TmpBuf, 0);
792 void load_seen_flags(void)
794 message_summary *Msg;
802 OldMsg = NewStrBuf();
804 StrBuf_ServGetln(OldMsg);
805 if (GetServerStatus(OldMsg, NULL) == 2) {
806 StrBufCutLeft(OldMsg, 4);
812 at = GetNewHashPos(WCC->summ, 0);
813 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
814 /* Are you a new message, or an old message? */
815 Msg = (message_summary*) vMsg;
816 if (is_msg_in_mset(ChrPtr(OldMsg), Msg->msgnum)) {
827 extern readloop_struct rlid[];
830 * command loop for reading messages
832 * Set oper to "readnew" or "readold" or "readfwd" or "headers" or "readgt"
834 void readloop(long oper)
836 StrBuf *MessageDropdown = NULL;
837 StrBuf *BBViewToolBar = NULL;
839 message_summary *Msg;
843 int with_headers = 0;
847 long *displayed_msgs = NULL;
848 int num_displayed = 0;
849 int is_singlecard = 0;
852 int lowest_displayed = (-1);
853 int highest_displayed = 0;
854 addrbookent *addrbook = NULL;
861 int care_for_empty_list = 0;
864 int defaultsortorder = 0;
865 WCTemplputParams SubTP;
868 long lowest_found = (-1);
869 long highest_found = (-1);
871 if (havebstr("is_summary") && (1 == (ibstr("is_summary"))))
872 WCC->wc_view = VIEW_MAILBOX;
875 output_headers(1, 1, 1, 0, 0, 0);
876 } else if (WCC->wc_view == VIEW_MAILBOX) {
877 jsonMessageListHdr();
880 switch (WCC->wc_view) {
882 sprintf(buf, "wiki?room=%s&page=home", ChrPtr(WCC->wc_roomname));
888 strcpy(cmd, "MSGS ALL");
890 parse_calendar_view_request(&calv);
893 strcpy(cmd, "MSGS ALL");
897 strcpy(cmd, "MSGS ALL");
899 wprintf("<div id=\"new_notes_here\"></div>\n");
901 case VIEW_ADDRESSBOOK:
902 is_singlecard = ibstr("is_singlecard");
903 if (is_singlecard != 1) {
904 if (oper == do_search) {
905 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
908 strcpy(cmd, "MSGS ALL");
919 defaultsortorder = 2;
922 care_for_empty_list = 0;
924 /* Generally using maxmsgs|startmsg is not required
925 in mailbox view, but we have a 'safemode' for clients
926 (*cough* Exploder) that simply can't handle too many */
927 if (havebstr("maxmsgs")) maxmsgs = ibstr("maxmsgs");
928 else maxmsgs = 9999999;
929 if (havebstr("startmsg")) startmsg = lbstr("startmsg");
930 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
931 (oper == do_search) ? "SEARCH" : "ALL",
932 (oper == do_search) ? bstr("query") : ""
938 defaultsortorder = 1;
941 care_for_empty_list = 1;
943 rlid[oper].cmd(cmd, sizeof(cmd));
945 if (havebstr("maxmsgs"))
946 maxmsgs = ibstr("maxmsgs");
947 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
949 if (havebstr("startmsg")) {
950 startmsg = lbstr("startmsg");
955 nummsgs = load_msg_ptrs(cmd, with_headers, &lowest_found, &highest_found);
957 if (care_for_empty_list) {
958 wprintf("<div class=\"nomsgs\"><br><em>");
961 wprintf(_("No new messages."));
964 wprintf(_("No old messages."));
967 wprintf(_("No messages here."));
969 wprintf("</em><br></div>\n");
977 memset(&SubTP, 0, sizeof(WCTemplputParams));
978 SubTP.Filter.ContextType = CTX_NONE;
979 SubTP.Context = NULL;
980 SortIt = RetrieveSort(&SubTP, NULL, 0,
981 HKEY("date"), defaultsortorder);
983 SortByPayload(WCC->summ, SortIt);
984 if (WCC->wc_view == VIEW_BBS) {
985 if (lbstr("SortOrder") == 2) {
987 num_displayed = -DEFAULT_MAXMSGS;
991 num_displayed = DEFAULT_MAXMSGS;
995 if (startmsg < 0) startmsg = (bbs_reverse) ? nummsgs - 1 : 0;
997 if (load_seen) load_seen_flags();
1000 * Print any inforation above the message list...
1002 switch (WCC->wc_view) {
1004 BBViewToolBar = NewStrBufPlain(NULL, SIZ);
1005 MessageDropdown = NewStrBufPlain(NULL, SIZ);
1007 maxmsgs = DrawMessageDropdown(MessageDropdown, maxmsgs, startmsg, num_displayed);
1008 if (num_displayed < 0) {
1009 startmsg += maxmsgs;
1010 if (num_displayed != maxmsgs)
1011 maxmsgs = abs(maxmsgs) + 1;
1013 maxmsgs = abs(maxmsgs);
1016 memset(&SubTP, 0, sizeof(WCTemplputParams));
1017 SubTP.Filter.ContextType = CTX_STRBUF;
1018 SubTP.Context = MessageDropdown;
1019 DoTemplate(HKEY("msg_listselector_top"), BBViewToolBar, &SubTP);
1020 StrBufAppendBuf(WCC->WBuf, BBViewToolBar, 0);
1021 FlushStrBuf(BBViewToolBar);
1024 WCC->startmsg = startmsg;
1025 WCC->maxmsgs = maxmsgs;
1026 WCC->num_displayed = 0;
1028 /* Put some helpful data in vars for mailsummary_json */
1029 svputlong("READLOOP:TOTALMSGS", nummsgs);
1030 svputlong("READLOOP:STARTMSG", startmsg);
1031 svputlong("WCVIEW", WCC->wc_view);
1034 * iterate over each message. if we need to load an attachment, do it here.
1036 if (WCC->wc_view == VIEW_MAILBOX) goto NO_MSG_LOOP;
1037 at = GetNewHashPos(WCC->summ, 0);
1038 num_displayed = i = 0;
1039 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
1040 Msg = (message_summary*) vMsg;
1041 if ((Msg->msgnum >= startmsg) && (num_displayed <= maxmsgs)) {
1042 switch (WCC->wc_view) {
1045 case VIEW_CALBRIEF: /* load the mime attachments for special tasks... */
1047 load_calendar_item(Msg, Msg->is_new, &calv);
1050 display_task(Msg, Msg->is_new);
1053 display_note(Msg, Msg->is_new);
1055 case VIEW_ADDRESSBOOK:
1057 fetch_ab_name(Msg, &ab_name);
1058 if (ab_name == NULL)
1061 addrbook = realloc(addrbook,
1062 (sizeof(addrbookent) * num_ab) );
1063 safestrncpy(addrbook[num_ab-1].ab_name, ab_name,
1064 sizeof(addrbook[num_ab-1].ab_name));
1065 addrbook[num_ab-1].ab_msgnum = Msg->msgnum;
1068 case VIEW_BBS: /* Tag the mails we want to show in bbview... */
1070 if (displayed_msgs == NULL) {
1071 displayed_msgs = malloc(sizeof(long) *
1072 (maxmsgs<nummsgs ? maxmsgs + 1 : nummsgs + 1));
1074 if ((i >= startmsg) && (i < startmsg + maxmsgs)) {
1075 displayed_msgs[num_displayed] = Msg->msgnum;
1076 if (lowest_displayed < 0) lowest_displayed = a;
1077 highest_displayed = a;
1089 * Done iterating the message list. now tasks we want to do after.
1091 switch (WCC->wc_view) {
1093 DoTemplate(HKEY("mailsummary_json"),NULL, &SubTP);
1096 if (displayed_msgs != NULL) {
1097 /* if we do a split bbview in the future, begin messages div here */
1099 for (a=0; a<num_displayed; ++a) {
1100 read_message(WCC->WBuf, HKEY("view_message"), displayed_msgs[a], NULL, &Mime);
1103 /* if we do a split bbview in the future, end messages div here */
1105 free(displayed_msgs);
1106 displayed_msgs = NULL;
1108 memset(&SubTP, 0, sizeof(WCTemplputParams));
1109 SubTP.Filter.ContextType = CTX_STRBUF;
1110 SubTP.Context = MessageDropdown;
1111 DoTemplate(HKEY("msg_listselector_bottom"), BBViewToolBar, &SubTP);
1112 StrBufAppendBuf(WCC->WBuf, BBViewToolBar, 0);
1114 FreeStrBuf(&BBViewToolBar);
1115 FreeStrBuf(&MessageDropdown);
1120 switch (WCC->wc_view) {
1125 render_calendar_view(&calv);
1128 do_tasks_view(); /* Render the task list */
1132 case VIEW_ADDRESSBOOK:
1134 read_message(WC->WBuf, HKEY("view_message"), lbstr("startmsg"), NULL, &Mime);
1136 do_addrbook_view(addrbook, num_ab); /* Render the address book */
1143 /* Note: wDumpContent() will output one additional </div> tag. */
1144 if (WCC->wc_view != VIEW_MAILBOX) {
1145 /* We ought to move this out into template */
1152 if (WCC->summ != NULL) {
1153 DeleteHash(&WCC->summ);
1155 if (addrbook != NULL) free(addrbook);
1156 FreeStrBuf(&BBViewToolBar);
1161 * Back end for post_message()
1162 * ... this is where the actual message gets transmitted to the server.
1164 void post_mime_to_server(void) {
1165 wcsession *WCC = WC;
1166 char top_boundary[SIZ];
1167 char alt_boundary[SIZ];
1168 int is_multipart = 0;
1170 wc_mime_attachment *att;
1172 size_t encoded_length;
1173 size_t encoded_strlen;
1174 char *txtmail = NULL;
1176 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
1177 ChrPtr(WCC->serv_info->serv_fqdn),
1181 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
1182 ChrPtr(WCC->serv_info->serv_fqdn),
1187 /* RFC2045 requires this, and some clients look for it... */
1188 serv_puts("MIME-Version: 1.0");
1189 serv_puts("X-Mailer: " PACKAGE_STRING);
1191 /* If there are attachments, we have to do multipart/mixed */
1192 if (GetCount(WCC->attachments) > 0) {
1197 /* Remember, serv_printf() appends an extra newline */
1198 serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
1199 serv_printf("This is a multipart message in MIME format.\n");
1200 serv_printf("--%s", top_boundary);
1203 /* Remember, serv_printf() appends an extra newline */
1204 serv_printf("Content-type: multipart/alternative; "
1205 "boundary=\"%s\"\n", alt_boundary);
1206 serv_printf("This is a multipart message in MIME format.\n");
1207 serv_printf("--%s", alt_boundary);
1209 serv_puts("Content-type: text/plain; charset=utf-8");
1210 serv_puts("Content-Transfer-Encoding: quoted-printable");
1212 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
1213 text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */
1216 serv_printf("--%s", alt_boundary);
1218 serv_puts("Content-type: text/html; charset=utf-8");
1219 serv_puts("Content-Transfer-Encoding: quoted-printable");
1221 serv_puts("<html><body>\r\n");
1222 text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */
1223 serv_puts("</body></html>\r\n");
1225 serv_printf("--%s--", alt_boundary);
1233 /* Add in the attachments */
1234 it = GetNewHashPos(WCC->attachments, 0);
1235 while (GetNextHashPos(WCC->attachments, it, &len, &Key, &vAtt)) {
1236 att = (wc_mime_attachment *)vAtt;
1237 encoded_length = ((att->length * 150) / 100);
1238 encoded = malloc(encoded_length);
1239 if (encoded == NULL) break;
1240 encoded_strlen = CtdlEncodeBase64(encoded, ChrPtr(att->Data), StrLength(att->Data), 1);
1242 serv_printf("--%s", top_boundary);
1243 serv_printf("Content-type: %s", ChrPtr(att->ContentType));
1244 serv_printf("Content-disposition: attachment; filename=\"%s\"", ChrPtr(att->FileName));
1245 serv_puts("Content-transfer-encoding: base64");
1247 serv_write(encoded, encoded_strlen);
1252 serv_printf("--%s--", top_boundary);
1261 * Post message (or don't post message)
1263 * Note regarding the "dont_post" variable:
1264 * A random value (actually, it's just a timestamp) is inserted as a hidden
1265 * field called "postseq" when the display_enter page is generated. This
1266 * value is checked when posting, using the static variable dont_post. If a
1267 * user attempts to post twice using the same dont_post value, the message is
1268 * discarded. This prevents the accidental double-saving of the same message
1269 * if the user happens to click the browser "back" button.
1271 void post_message(void)
1274 StrBuf *encoded_subject = NULL;
1275 static long dont_post = (-1L);
1276 wc_mime_attachment *att;
1277 int is_anonymous = 0;
1278 const StrBuf *display_name = NULL;
1279 wcsession *WCC = WC;
1282 if (havebstr("force_room")) {
1283 gotoroom(sbstr("force_room"));
1286 if (havebstr("display_name")) {
1287 display_name = sbstr("display_name");
1288 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
1289 display_name = NULL;
1294 if (WCC->upload_length > 0) {
1299 /* There's an attachment. Save it to this struct... */
1300 lprintf(9, "Client is uploading %d bytes\n", WCC->upload_length);
1301 att = malloc(sizeof(wc_mime_attachment));
1302 memset(att, 0, sizeof(wc_mime_attachment ));
1303 att->length = WCC->upload_length;
1304 att->ContentType = NewStrBufPlain(WCC->upload_content_type, -1);
1305 att->FileName = NewStrBufPlain(WCC->upload_filename, -1);
1307 if (WCC->attachments == NULL) {
1308 WCC->attachments = NewHash(1, NULL);
1311 /* And add it to the list. */
1312 n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
1313 Put(WCC->attachments, N, n, att, DestroyMime);
1316 * Mozilla sends a simple filename, which is what we want,
1317 * but Satan's Browser sends an entire pathname. Reduce
1318 * the path to just a filename if we need to.
1320 pch = strrchr(ChrPtr(att->FileName), '/');
1322 StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1);
1324 pch = strrchr(ChrPtr(att->FileName), '\\');
1326 StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1);
1330 * Transfer control of this memory from the upload struct
1331 * to the attachment struct.
1333 att->Data = WCC->upload;
1335 WCC->upload_length = 0;
1340 if (havebstr("cancel_button")) {
1341 sprintf(WCC->ImportantMessage,
1342 _("Cancelled. Message was not posted."));
1343 } else if (havebstr("attach_button")) {
1346 } else if (lbstr("postseq") == dont_post) {
1347 sprintf(WCC->ImportantMessage,
1348 _("Automatically cancelled because you have already "
1349 "saved this message."));
1351 const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s";
1352 const StrBuf *Recp = NULL;
1353 const StrBuf *Cc = NULL;
1354 const StrBuf *Bcc = NULL;
1355 const StrBuf *Wikipage = NULL;
1356 const StrBuf *my_email_addr = NULL;
1357 StrBuf *CmdBuf = NULL;
1358 StrBuf *references = NULL;
1361 save_to_drafts = havebstr("save_button");
1364 if (save_to_drafts) {
1365 /* temporarily change to the drafts room */
1366 serv_puts("GOTO _DRAFTS_");
1367 StrBuf_ServGetln(Buf);
1368 if (GetServerStatus(Buf, NULL) != 2) {
1369 /* You probably don't even have a dumb Drafts folder */
1370 StrBufCutLeft(Buf, 4);
1371 lprintf(9, "%s:%d: server save to drafts error: %s\n", __FILE__, __LINE__, ChrPtr(Buf));
1372 StrBufAppendBufPlain(WCC->ImportantMsg, _("Saved to Drafts failed: "), -1, 0);
1373 StrBufAppendBuf(WCC->ImportantMsg, Buf, 0);
1380 if (havebstr("references"))
1382 const StrBuf *ref = sbstr("references");
1383 references = NewStrBufDup(ref);
1384 if (*ChrPtr(references) == '|') { /* remove leading '|' if present */
1385 StrBufCutLeft(references, 1);
1387 StrBufReplaceChars(references, '|', '!');
1389 if (havebstr("subject")) {
1392 * make enough room for the encoded string;
1393 * plus the QP header
1395 Subj = sbstr("subject");
1397 StrBufRFC2047encode(&encoded_subject, Subj);
1399 Recp = sbstr("recp");
1402 Wikipage = sbstr("wikipage");
1403 my_email_addr = sbstr("my_email_addr");
1405 CmdBuf = NewStrBufPlain(NULL,
1408 StrLength(encoded_subject) +
1411 StrLength(Wikipage) +
1412 StrLength(my_email_addr) +
1413 StrLength(references));
1415 StrBufPrintf(CmdBuf,
1417 save_to_drafts?"":ChrPtr(Recp),
1419 ChrPtr(encoded_subject),
1420 ChrPtr(display_name),
1421 save_to_drafts?"":ChrPtr(Cc),
1422 save_to_drafts?"":ChrPtr(Bcc),
1424 ChrPtr(my_email_addr),
1425 ChrPtr(references));
1426 FreeStrBuf(&references);
1427 FreeStrBuf(&encoded_subject);
1429 lprintf(9, "%s\n", ChrPtr(CmdBuf));
1430 serv_puts(ChrPtr(CmdBuf));
1431 FreeStrBuf(&CmdBuf);
1433 StrBuf_ServGetln(Buf);
1434 if (GetServerStatus(Buf, NULL) == 4) {
1435 if (save_to_drafts) {
1436 if ( (havebstr("recp"))
1437 || (havebstr("cc" ))
1438 || (havebstr("bcc" )) ) {
1439 /* save recipient headers or room to post to */
1440 serv_printf("To: %s", ChrPtr(Recp));
1441 serv_printf("Cc: %s", ChrPtr(Cc));
1442 serv_printf("Bcc: %s", ChrPtr(Bcc));
1444 serv_printf("X-Citadel-Room: %s", ChrPtr(WC->wc_roomname));
1447 post_mime_to_server();
1448 if (save_to_drafts) {
1449 StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been saved to Drafts.\n"), -1, 0);
1450 gotoroom(WCC->wc_roomname);
1454 } else if ( (havebstr("recp"))
1455 || (havebstr("cc" ))
1456 || (havebstr("bcc" ))
1458 StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been sent.\n"), -1, 0);
1461 StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been posted.\n"), -1, 0);
1463 dont_post = lbstr("postseq");
1465 StrBufCutLeft(Buf, 4);
1467 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, ChrPtr(Buf));
1468 StrBufAppendBuf(WCC->ImportantMsg, Buf, 0);
1469 if (save_to_drafts) gotoroom(WCC->wc_roomname);
1477 DeleteHash(&WCC->attachments);
1480 * We may have been supplied with instructions regarding the location
1481 * to which we must return after posting. If found, go there.
1483 if (havebstr("return_to")) {
1484 http_redirect(bstr("return_to"));
1487 * If we were editing a page in a wiki room, go to that page now.
1489 else if (havebstr("wikipage")) {
1490 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
1494 * Otherwise, just go to the "read messages" loop.
1505 * display the message entry screen
1507 void display_enter(void)
1511 const StrBuf *display_name = NULL;
1512 int recipient_required = 0;
1513 int subject_required = 0;
1514 int recipient_bad = 0;
1515 int is_anonymous = 0;
1516 wcsession *WCC = WC;
1520 if (havebstr("force_room")) {
1521 gotoroom(sbstr("force_room"));
1524 display_name = sbstr("display_name");
1525 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
1526 display_name = NULL;
1530 /* First test to see whether this is a room that requires recipients to be entered */
1531 serv_puts("ENT0 0");
1532 serv_getln(buf, sizeof buf);
1534 if (!strncmp(buf, "570", 3)) { /* 570 means that we need a recipient here */
1535 recipient_required = 1;
1537 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
1538 sprintf(WCC->ImportantMessage, "%s", &buf[4]);
1543 /* Is the server strongly recommending that the user enter a message subject? */
1544 if ((buf[3] != '\0') && (buf[4] != '\0')) {
1545 subject_required = extract_int(&buf[4], 1);
1549 * Are we perhaps in an address book view? If so, then an "enter
1550 * message" command really means "add new entry."
1552 if (WCC->wc_default_view == VIEW_ADDRESSBOOK) {
1553 do_edit_vcard(-1, "", NULL, NULL, "", ChrPtr(WCC->wc_roomname));
1558 * Are we perhaps in a calendar room? If so, then an "enter
1559 * message" command really means "add new calendar item."
1561 if (WCC->wc_default_view == VIEW_CALENDAR) {
1562 display_edit_event();
1567 * Are we perhaps in a tasks view? If so, then an "enter
1568 * message" command really means "add new task."
1570 if (WCC->wc_default_view == VIEW_TASKS) {
1571 display_edit_task();
1576 * Otherwise proceed normally.
1577 * Do a custom room banner with no navbar...
1580 if (recipient_required) {
1581 const StrBuf *Recp = NULL;
1582 const StrBuf *Cc = NULL;
1583 const StrBuf *Bcc = NULL;
1584 const StrBuf *Wikipage = NULL;
1585 StrBuf *CmdBuf = NULL;
1586 const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
1588 Recp = sbstr("recp");
1591 Wikipage = sbstr("wikipage");
1593 CmdBuf = NewStrBufPlain(NULL,
1596 StrLength(display_name) +
1599 StrLength(Wikipage));
1601 StrBufPrintf(CmdBuf,
1605 ChrPtr(display_name),
1609 serv_puts(ChrPtr(CmdBuf));
1610 serv_getln(buf, sizeof buf);
1611 FreeStrBuf(&CmdBuf);
1613 if (!strncmp(buf, "570", 3)) { /* 570 means we have an invalid recipient listed */
1614 if (havebstr("recp") &&
1620 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
1621 wprintf("<em>%s</em><br />\n", &buf[4]); /* TODO -> important message */
1625 svputlong("RCPTREQUIRED", recipient_required);
1626 svputlong("SUBJREQUIRED", recipient_required || subject_required);
1629 output_headers(1, 0, 0, 0, 1, 0);
1630 DoTemplate(HKEY("edit_message"), NULL, &NoCtx);
1639 void delete_msg(void)
1644 msgid = lbstr("msgid");
1646 if (WC->wc_is_trash) { /* Delete from Trash is a real delete */
1647 serv_printf("DELE %ld", msgid);
1649 else { /* Otherwise move it to Trash */
1650 serv_printf("MOVE %ld|_TRASH_|0", msgid);
1653 serv_getln(buf, sizeof buf);
1654 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1660 * move a message to another room
1667 msgid = lbstr("msgid");
1669 if (havebstr("move_button")) {
1670 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
1672 serv_getln(buf, sizeof buf);
1673 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1675 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
1683 * Confirm move of a message
1685 void confirm_move_msg(void)
1691 msgid = lbstr("msgid");
1694 output_headers(1, 1, 2, 0, 0, 0);
1695 wprintf("<div id=\"banner\">\n");
1697 wprintf(_("Confirm move of message"));
1699 wprintf("</div>\n");
1701 wprintf("<div id=\"content\" class=\"service\">\n");
1703 wprintf("<CENTER>");
1705 wprintf(_("Move this message to:"));
1706 wprintf("<br />\n");
1708 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
1709 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1710 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
1712 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
1714 serv_getln(buf, sizeof buf);
1715 if (buf[0] == '1') {
1716 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1717 extract_token(targ, buf, 0, '|', sizeof targ);
1718 wprintf("<OPTION>");
1723 wprintf("</SELECT>\n");
1724 wprintf("<br />\n");
1726 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
1728 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
1729 wprintf("</form></CENTER>\n");
1731 wprintf("</CENTER>\n");
1737 * Generic function to output an arbitrary MIME attachment from
1738 * message being composed
1740 * partnum The MIME part to be output
1741 * filename Fake filename to give
1742 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
1744 void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
1747 StrBuf *content_type;
1748 wc_mime_attachment *part;
1750 if (GetHash(WC->attachments, SKEY(partnum), &vPart) &&
1752 part = (wc_mime_attachment*) vPart;
1753 if (force_download) {
1754 content_type = NewStrBufPlain(HKEY("application/octet-stream"));
1757 content_type = NewStrBufDup(part->ContentType);
1759 StrBufAppendBuf(WC->WBuf, part->Data, 0);
1760 http_transmit_thing(ChrPtr(content_type), 0);
1762 hprintf("HTTP/1.1 404 %s\n", ChrPtr(partnum));
1763 output_headers(0, 0, 0, 0, 0, 0);
1764 hprintf("Content-Type: text/plain\r\n");
1765 wprintf(_("An error occurred while retrieving this part: %s/%s\n"),
1766 ChrPtr(partnum), ChrPtr(filename));
1769 FreeStrBuf(&content_type);
1774 * Generic function to output an arbitrary MIME part from an arbitrary
1775 * message number on the server.
1777 * msgnum Number of the item on the citadel server
1778 * partnum The MIME part to be output
1779 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
1781 void mimepart(int force_download)
1785 wcsession *WCC = WC;
1788 StrBuf *ContentType = NewStrBufPlain(HKEY("application/octet-stream"));
1791 att = Buf = NewStrBuf();
1792 msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/');
1793 StrBufExtract_token(att, WCC->Hdr->HR.ReqLine, 1, '/');
1795 serv_printf("OPNA %ld|%s", msgnum, ChrPtr(att));
1796 StrBuf_ServGetln(Buf);
1797 if (GetServerStatus(Buf, NULL) == 2) {
1798 StrBufCutLeft(Buf, 4);
1799 bytes = StrBufExtract_long(Buf, 0, '|');
1800 if (!force_download) {
1801 StrBufExtract_token(ContentType, Buf, 3, '|');
1804 read_server_binary(WCC->WBuf, bytes, Buf);
1806 StrBuf_ServGetln(Buf);
1807 CT = ChrPtr(ContentType);
1809 if (!force_download) {
1810 if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
1811 StrBufExtract_token(Buf, WCC->Hdr->HR.ReqLine, 2, '/');
1812 CT = GuessMimeByFilename(SKEY(Buf));
1814 if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
1815 CT = GuessMimeType(SKEY(WCC->WBuf));
1818 http_transmit_thing(CT, 0);
1820 StrBufCutLeft(Buf, 4);
1821 hprintf("HTTP/1.1 404 %s\n", ChrPtr(Buf));
1822 output_headers(0, 0, 0, 0, 0, 0);
1823 hprintf("Content-Type: text/plain\r\n");
1824 wprintf(_("An error occurred while retrieving this part: %s\n"),
1828 FreeStrBuf(&ContentType);
1834 * Read any MIME part of a message, from the server, into memory.
1836 StrBuf *load_mimepart(long msgnum, char *partnum)
1842 serv_printf("DLAT %ld|%s", msgnum, partnum);
1843 StrBuf_ServGetln(Buf);
1844 if (GetServerStatus(Buf, NULL) == 6) {
1845 StrBufCutLeft(Buf, 4);
1846 bytes = StrBufExtract_long(Buf, 0, '|');
1849 StrBuf_ServGetBLOBBuffered(Buf, bytes);
1859 * Read any MIME part of a message, from the server, into memory.
1861 void MimeLoadData(wc_mime_attachment *Mime)
1865 /* TODO: is there a chance the content type is different from the one we know? */
1866 serv_printf("DLAT %ld|%s", Mime->msgnum, ChrPtr(Mime->PartNum));
1868 StrBuf_ServGetln(Buf);
1869 if (GetServerStatus(Buf, NULL) == 6) {
1870 bytes = extract_long(&(ChrPtr(Buf)[4]), 0);
1872 if (Mime->Data == NULL)
1873 Mime->Data = NewStrBufPlain(NULL, bytes);
1874 StrBuf_ServGetBLOBBuffered(Mime->Data, bytes);
1877 FlushStrBuf(Mime->Data);
1878 /* TODO XImportant message */
1886 void view_mimepart(void) {
1890 void download_mimepart(void) {
1894 void view_postpart(void) {
1895 StrBuf *filename = NewStrBuf();
1896 StrBuf *partnum = NewStrBuf();
1898 StrBufExtract_token(partnum, WC->Hdr->HR.ReqLine, 0, '/');
1899 StrBufExtract_token(filename, WC->Hdr->HR.ReqLine, 1, '/');
1901 postpart(partnum, filename, 0);
1903 FreeStrBuf(&filename);
1904 FreeStrBuf(&partnum);
1907 void download_postpart(void) {
1908 StrBuf *filename = NewStrBuf();
1909 StrBuf *partnum = NewStrBuf();
1911 StrBufExtract_token(partnum, WC->Hdr->HR.ReqLine, 0, '/');
1912 StrBufExtract_token(filename, WC->Hdr->HR.ReqLine, 1, '/');
1914 postpart(partnum, filename, 1);
1916 FreeStrBuf(&filename);
1917 FreeStrBuf(&partnum);
1920 void h_readnew(void) { readloop(readnew);}
1921 void h_readold(void) { readloop(readold);}
1922 void h_readfwd(void) { readloop(readfwd);}
1923 void h_headers(void) { readloop(headers);}
1924 void h_do_search(void) { readloop(do_search);}
1925 void h_readgt(void) { readloop(readgt);}
1927 void jsonMessageListHdr(void)
1929 /* TODO: make a generic function */
1930 hprintf("HTTP/1.1 200 OK\r\n");
1931 hprintf("Content-type: application/json; charset=utf-8\r\n");
1932 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
1933 hprintf("Connection: close\r\n");
1934 hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
1938 /* Spit out the new summary view. This is basically a static page, so clients can cache the layout, all the dirty work is javascript :) */
1939 void new_summary_view(void) {
1941 DoTemplate(HKEY("msg_listview"),NULL,&NoCtx);
1942 DoTemplate(HKEY("trailing"),NULL,&NoCtx);
1946 /* Output message list in JSON format */
1947 void jsonMessageList(void) {
1948 const StrBuf *room = sbstr("room");
1949 long oper = (havebstr("query")) ? do_search : readnew;
1960 RegisterPreference("use_sig",
1961 _("Attach signature to email messages?"),
1964 RegisterPreference("signature", _("Use this signature:"), PRF_QP_STRING, NULL);
1965 RegisterPreference("default_header_charset",
1966 _("Default character set for email headers:"),
1969 RegisterPreference("defaultfrom", _("Preferred email address"), PRF_STRING, NULL);
1970 RegisterPreference("defaultname",
1971 _("Preferred display name for email messages"),
1974 RegisterPreference("defaulthandle",
1975 _("Preferred display name for bulletin board posts"),
1978 RegisterPreference("mailbox",_("Mailbox view mode"), PRF_STRING, NULL);
1980 WebcitAddUrlHandler(HKEY("readnew"), h_readnew, NEED_URL);
1981 WebcitAddUrlHandler(HKEY("readold"), h_readold, NEED_URL);
1982 WebcitAddUrlHandler(HKEY("readfwd"), h_readfwd, NEED_URL);
1983 WebcitAddUrlHandler(HKEY("headers"), h_headers, NEED_URL);
1984 WebcitAddUrlHandler(HKEY("readgt"), h_readgt, NEED_URL);
1985 WebcitAddUrlHandler(HKEY("do_search"), h_do_search, 0);
1986 WebcitAddUrlHandler(HKEY("display_enter"), display_enter, 0);
1987 WebcitAddUrlHandler(HKEY("post"), post_message, 0);
1988 WebcitAddUrlHandler(HKEY("move_msg"), move_msg, 0);
1989 WebcitAddUrlHandler(HKEY("delete_msg"), delete_msg, 0);
1990 WebcitAddUrlHandler(HKEY("confirm_move_msg"), confirm_move_msg, 0);
1991 WebcitAddUrlHandler(HKEY("msg"), embed_message, NEED_URL);
1992 WebcitAddUrlHandler(HKEY("message"), handle_one_message, NEED_URL|XHTTP_COMMANDS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
1993 WebcitAddUrlHandler(HKEY("printmsg"), print_message, NEED_URL);
1994 WebcitAddUrlHandler(HKEY("mobilemsg"), mobile_message_view, NEED_URL);
1995 WebcitAddUrlHandler(HKEY("msgheaders"), display_headers, NEED_URL);
1997 WebcitAddUrlHandler(HKEY("mimepart"), view_mimepart, NEED_URL);
1998 WebcitAddUrlHandler(HKEY("mimepart_download"), download_mimepart, NEED_URL);
1999 WebcitAddUrlHandler(HKEY("postpart"), view_postpart, NEED_URL);
2000 WebcitAddUrlHandler(HKEY("postpart_download"), download_postpart, NEED_URL);
2003 WebcitAddUrlHandler(HKEY("roommsgs"), jsonMessageList,0);
2008 SessionDetachModule_MSG
2011 DeleteHash(&sess->summ);