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 /*----------------------------------------------------------------------------*/
28 typedef void (*MsgPartEvaluatorFunc)(message_summary *Sum, StrBuf *Buf);
30 typedef struct _MsgPartEvaluatorStruct {
31 MsgPartEvaluatorFunc f;
32 }MsgPartEvaluatorStruct;
35 /*----------------------------------------------------------------------------*/
38 int load_message(message_summary *Msg,
52 lprintf(1, "-------------------MSG4 %ld|%s--------------\n", Msg->msgnum, ChrPtr(Msg->PartNum));
53 if (Msg->PartNum != NULL)
54 serv_printf("MSG4 %ld|%s", Msg->msgnum, ChrPtr(Msg->PartNum));
56 serv_printf("MSG4 %ld", Msg->msgnum);
58 StrBuf_ServGetln(Buf);
59 if (GetServerStatus(Buf, NULL) != 1) {
61 StrBufAppendPrintf(*Error, "<strong>");
62 StrBufAppendPrintf(*Error, _("ERROR:"));
63 StrBufAppendPrintf(*Error, "</strong> %s<br />\n", &buf[4]);
68 /** begin everythingamundo table */
69 HdrToken = NewStrBuf();
70 while ((StrBuf_ServGetln(Buf)>=0) && !Done) {
71 if ( (StrLength(Buf)==3) &&
72 !strcmp(ChrPtr(Buf), "000"))
76 lprintf(1, _("unexpected end of message"));
77 if (Msg->MsgBody->Data == NULL)
78 Msg->MsgBody->Data = NewStrBuf();
79 Msg->MsgBody->ContentType = NewStrBufPlain(HKEY("text/html"));
80 StrBufAppendPrintf(Msg->MsgBody->Data, "<div><i>");
81 StrBufAppendPrintf(Msg->MsgBody->Data, _("unexpected end of message"));
82 StrBufAppendPrintf(Msg->MsgBody->Data, " (1)</i><br /><br />\n");
83 StrBufAppendPrintf(Msg->MsgBody->Data, "</div>\n");
88 case 0:/* Citadel Message Headers */
89 if (StrLength(Buf) == 0) {
93 StrBufExtract_token(HdrToken, Buf, 0, '=');
94 StrBufCutLeft(Buf, StrLength(HdrToken) + 1);
97 if (dbg_analyze_msg) lprintf(1, ":: [%s] = [%s]\n", ChrPtr(HdrToken), ChrPtr(Buf));
99 /* look up one of the examine_* functions to parse the content */
100 if (GetHash(MsgHeaderHandler, SKEY(HdrToken), &vHdr) &&
102 Hdr = (headereval*)vHdr;
103 Hdr->evaluator(Msg, Buf, FoundCharset);
104 if (Hdr->Type == 1) {
108 else LogError(Target,
110 "don't know how to handle message header[%s]\n",
114 case 1:/* Message Mime Header */
115 if (StrLength(Buf) == 0) {
117 if (Msg->MsgBody->ContentType == NULL)
118 /* end of header or no header? */
119 Msg->MsgBody->ContentType = NewStrBufPlain(HKEY("text/plain"));
120 /* usual end of mime header */
124 StrBufExtract_token(HdrToken, Buf, 0, ':');
125 if (StrLength(HdrToken) > 0) {
126 StrBufCutLeft(Buf, StrLength(HdrToken) + 1);
128 if (dbg_analyze_msg) lprintf(1, ":: [%s] = [%s]\n", ChrPtr(HdrToken), ChrPtr(Buf));
130 /* the examine*'s know how to do with mime headers too... */
131 if (GetHash(MsgHeaderHandler, SKEY(HdrToken), &vHdr) &&
133 Hdr = (headereval*)vHdr;
134 Hdr->evaluator(Msg, Buf, FoundCharset);
139 case 2: /* Message Body */
141 if (Msg->MsgBody->size_known > 0) {
142 StrBuf_ServGetBLOBBuffered(Msg->MsgBody->Data, Msg->MsgBody->length);
144 /*/ todo: check next line, if not 000, append following lines */
147 if (StrLength(Msg->MsgBody->Data) > 0)
148 StrBufAppendBufPlain(Msg->MsgBody->Data, "\n", 1, 0);
149 StrBufAppendBuf(Msg->MsgBody->Data, Buf, 0);
153 StrBufAppendBuf(Msg->MsgBody->Data, Buf, 0);
158 if (Msg->AllAttach == NULL)
159 Msg->AllAttach = NewHash(1,NULL);
160 /* now we put the body mimepart we read above into the mimelist */
161 Put(Msg->AllAttach, SKEY(Msg->MsgBody->PartNum), Msg->MsgBody, DestroyMime);
163 /* Generate a reply-to address */
164 if (StrLength(Msg->Rfca) > 0) {
165 if (Msg->reply_to == NULL)
166 Msg->reply_to = NewStrBuf();
167 if (StrLength(Msg->from) > 0) {
168 StrBufPrintf(Msg->reply_to, "%s <%s>", ChrPtr(Msg->from), ChrPtr(Msg->Rfca));
171 FlushStrBuf(Msg->reply_to);
172 StrBufAppendBuf(Msg->reply_to, Msg->Rfca, 0);
177 if ((StrLength(Msg->OtherNode)>0) &&
178 (strcasecmp(ChrPtr(Msg->OtherNode), ChrPtr(WCC->serv_info->serv_nodename))) &&
179 (strcasecmp(ChrPtr(Msg->OtherNode), ChrPtr(WCC->serv_info->serv_humannode)) ))
181 if (Msg->reply_to == NULL)
182 Msg->reply_to = NewStrBuf();
183 StrBufPrintf(Msg->reply_to,
186 ChrPtr(Msg->OtherNode));
189 if (Msg->reply_to == NULL)
190 Msg->reply_to = NewStrBuf();
191 FlushStrBuf(Msg->reply_to);
192 StrBufAppendBuf(Msg->reply_to, Msg->from, 0);
196 FreeStrBuf(&HdrToken);
203 * I wanna SEE that message!
205 * msgnum Message number to display
206 * printable_view Nonzero to display a printable view
207 * section Optional for encapsulated message/rfc822 submessage
209 int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, const StrBuf *PartNum, const StrBuf **OutMime)
212 StrBuf *FoundCharset;
215 message_summary *Msg = NULL;
219 WCTemplputParams SubTP;
220 StrBuf *Error = NULL;
223 FoundCharset = NewStrBuf();
224 Msg = (message_summary *)malloc(sizeof(message_summary));
225 memset(Msg, 0, sizeof(message_summary));
226 Msg->msgnum = msgnum;
227 Msg->PartNum = PartNum;
228 Msg->MsgBody = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
229 memset(Msg->MsgBody, 0, sizeof(wc_mime_attachment));
230 Msg->MsgBody->msgnum = msgnum;
232 if (!load_message(Msg, FoundCharset, &Error)) {
233 StrBufAppendBuf(Target, Error, 0);
237 /* strip the bare contenttype, so we ommit charset etc. */
238 StrBufExtract_token(Buf, Msg->MsgBody->ContentType, 0, ';');
240 /* look up the renderer, that will convert this mimeitem into the htmlized form */
241 if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
243 RenderMimeFuncStruct *Render;
244 Render = (RenderMimeFuncStruct*)vHdr;
245 Render->f(Msg->MsgBody, NULL, FoundCharset);
248 if (StrLength(Msg->reply_references)> 0) {
249 /* Trim down excessively long lists of thread references. We eliminate the
250 * second one in the list so that the thread root remains intact.
252 int rrtok = num_tokens(ChrPtr(Msg->reply_references), '|');
253 int rrlen = StrLength(Msg->reply_references);
254 if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
255 StrBufRemove_token(Msg->reply_references, 1, '|');
259 /* now check if we need to translate some mimeparts, and remove the duplicate */
260 it = GetNewHashPos(Msg->AllAttach, 0);
261 while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) &&
263 wc_mime_attachment *Mime = (wc_mime_attachment*) vMime;
264 evaluate_mime_part(Msg, Mime);
267 memset(&SubTP, 0, sizeof(WCTemplputParams));
268 SubTP.Filter.ContextType = CTX_MAILSUM;
270 *OutMime = DoTemplate(tmpl, tmpllen, Target, &SubTP);
272 DestroyMessageSummary(Msg);
273 FreeStrBuf(&FoundCharset);
281 HttpStatus(long CitadelStatus)
283 long httpstatus = 502;
284 long MajorStat = MAJORCODE(CitadelStatus);
285 long MinorStat = MINORCODE(CitadelStatus);
287 switch (MAJORCODE(CitadelStatus))
289 case LISTING_FOLLOWS:
294 switch (MINORCODE(CitadelStatus))
302 case HIGHER_ACCESS_REQUIRED:
303 case MAX_SESSIONS_EXCEEDED:
305 case RESOURCE_NOT_OPEN:
307 case INVALID_FLOOR_OPERATION:
313 case MESSAGE_NOT_FOUND:
323 case CMD_NOT_SUPPORTED:
324 case PASSWORD_REQUIRED:
325 case ALREADY_LOGGED_IN:
326 case USERNAME_REQUIRED:
328 case SERVER_SHUTTING_DOWN:
339 case START_CHAT_MODE:
343 httpstatus = 502; /* aeh... whut? */
351 * Unadorned HTML output of an individual message, suitable
352 * for placing in a hidden iframe, for printing, or whatever
354 * msgnum_as_string == Message number, as a string instead of as a long int
356 void handle_one_message(void)
360 const StrBuf *Destination;
366 StrBuf *CmdBuf = NULL;
370 pMsg = strchr(ChrPtr(WCC->Hdr->HR.ReqLine), '/');
372 HttpStatus(CitStatus);
376 msgnum = atol(pMsg + 1);
377 StrBufCutAt(WCC->Hdr->HR.ReqLine, 0, pMsg);
378 gotoroom(WCC->Hdr->HR.ReqLine);
379 switch (WCC->Hdr->HR.eReqType)
383 Tmpl = sbstr("template");
384 if (StrLength(Tmpl) > 0)
385 read_message(WCC->WBuf, SKEY(Tmpl), msgnum, NULL, &Mime);
387 read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
388 http_transmit_thing(ChrPtr(Mime), 0);
391 CmdBuf = NewStrBuf ();
392 if (WCC->wc_is_trash) { /** Delete from Trash is a real delete */
393 serv_printf("DELE %ld", msgnum);
395 else { /** Otherwise move it to Trash */
396 serv_printf("MOVE %ld|_TRASH_|0", msgnum);
398 StrBuf_ServGetln(CmdBuf);
399 FlushStrBuf(WCC->ImportantMsg);
400 StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
401 GetServerStatus(CmdBuf, &CitStatus);
402 HttpStatus(CitStatus);
407 if (GetHash(WCC->Hdr->HTTPHeaders, HKEY("DESTINATION"), &vLine) &&
409 Destination = (StrBuf*) vLine;
410 serv_printf("MOVE %ld|%s|%d", msgnum, ChrPtr(Destination), CopyMessage);
411 StrBuf_ServGetln(CmdBuf);
412 FlushStrBuf(WCC->ImportantMsg);
413 StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
414 GetServerStatus(CmdBuf, &CitStatus);
415 HttpStatus(CitStatus);
426 * Unadorned HTML output of an individual message, suitable
427 * for placing in a hidden iframe, for printing, or whatever
429 * msgnum_as_string == Message number, as a string instead of as a long int
431 void embed_message(void) {
436 StrBuf *CmdBuf = NULL;
438 msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/');
439 switch (WCC->Hdr->HR.eReqType)
443 Tmpl = sbstr("template");
444 if (StrLength(Tmpl) > 0)
445 read_message(WCC->WBuf, SKEY(Tmpl), msgnum, NULL, &Mime);
447 read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
448 http_transmit_thing(ChrPtr(Mime), 0);
451 CmdBuf = NewStrBuf ();
452 if (WCC->wc_is_trash) { /** Delete from Trash is a real delete */
453 serv_printf("DELE %ld", msgnum);
455 else { /** Otherwise move it to Trash */
456 serv_printf("MOVE %ld|_TRASH_|0", msgnum);
458 StrBuf_ServGetln(CmdBuf);
459 FlushStrBuf(WCC->ImportantMsg);
460 StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
470 * Printable view of a message
472 * msgnum_as_string == Message number, as a string instead of as a long int
474 void print_message(void) {
478 msgnum = StrBufExtract_long(WC->Hdr->HR.ReqLine, 0, '/');
479 output_headers(0, 0, 0, 0, 0, 0);
481 hprintf("Content-type: text/html\r\n"
482 "Server: " PACKAGE_STRING "\r\n"
483 "Connection: close\r\n");
487 read_message(WC->WBuf, HKEY("view_message_print"), msgnum, NULL, &Mime);
493 * Mobile browser view of message
495 * @param msg_num_as_string Message number as a string instead of as a long int
497 void mobile_message_view(void)
502 msgnum = StrBufExtract_long(WC->Hdr->HR.ReqLine, 0, '/');
503 output_headers(1, 0, 0, 0, 0, 1);
505 do_template("msgcontrols", NULL);
506 read_message(WC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
511 * \brief Display a message's headers
513 * \param msgnum_as_string Message number, as a string instead of as a long int
515 void display_headers(void) {
519 msgnum = StrBufExtract_long(WC->Hdr->HR.ReqLine, 0, '/');
520 output_headers(0, 0, 0, 0, 0, 0);
522 hprintf("Content-type: text/plain\r\n"
524 "Connection: close\r\n",
528 serv_printf("MSG2 %ld|3", msgnum);
529 serv_getln(buf, sizeof buf);
531 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
532 wprintf("%s\n", buf);
540 message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSubject, long MsgNum)
543 MsgPartEvaluatorStruct *Eval;
544 message_summary *Msg;
553 serv_printf("MSG0 %ld|1", MsgNum); /* ask for headers only */
555 StrBuf_ServGetln(Buf);
556 if (GetServerStatus(Buf, NULL) == 1) {
561 Msg = (message_summary*)malloc(sizeof(message_summary));
562 memset(Msg, 0, sizeof(message_summary));
563 while (len = StrBuf_ServGetln(Buf),
565 strcmp(ChrPtr(Buf), "000")== 0)){
567 ebuf = strchr(ChrPtr(Buf), '=');
569 if (GetHash(MsgEvaluators, buf, nBuf, &vEval) && vEval != NULL) {
570 Eval = (MsgPartEvaluatorStruct*) vEval;
571 StrBufCutLeft(Buf, nBuf + 1);
574 else lprintf(1, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
584 * load message pointers from the server for a "read messages" operation
586 * servcmd: the citadel command to send to the citserver
587 * with_headers: also include some of the headers with the message numbers (more expensive)
589 int load_msg_ptrs(const char *servcmd, int with_headers)
591 StrBuf* FoundCharset = NULL;
593 message_summary *Msg;
600 const char *Ptr = NULL;
602 if (WCC->summ != NULL) {
603 DeleteHash(&WCC->summ);
605 WCC->summ = NewHash(1, Flathash);
610 StrBuf_ServGetln(Buf);
611 if (GetServerStatus(Buf, NULL) != 1) {
616 while (len = StrBuf_ServGetln(Buf),
618 strcmp(ChrPtr(Buf), "000")!= 0))
620 if (nummsgs < maxload) {
623 Msg = (message_summary*)malloc(sizeof(message_summary));
624 memset(Msg, 0, sizeof(message_summary));
626 Msg->msgnum = StrBufExtractNext_long(Buf, &Ptr, '|');
627 Msg->date = StrBufExtractNext_long(Buf, &Ptr, '|');
629 * as citserver probably gives us messages in forward date sorting
630 * nummsgs should be the same order as the message date.
632 if (Msg->date == 0) {
634 if (StrLength(Buf) < 32)
638 Msg->from = NewStrBufPlain(NULL, StrLength(Buf));
639 StrBufExtract_NextToken(Buf2, Buf, &Ptr, '|');
640 if (StrLength(Buf2) != 0) {
641 /** Handle senders with RFC2047 encoding */
642 StrBuf_RFC822_to_Utf8(Msg->from, Buf2, WCC->DefaultCharset, FoundCharset);
646 StrBufExtract_NextToken(Buf2, Buf, &Ptr, '|');
647 if ((StrLength(Buf2) !=0 ) &&
648 ( ((WCC->room_flags & QR_NETWORK)
649 || ((strcasecmp(ChrPtr(Buf2), ChrPtr(WCC->serv_info->serv_nodename))
650 && (strcasecmp(ChrPtr(Buf2), ChrPtr(WCC->serv_info->serv_fqdn))))))))
652 StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
653 StrBufAppendBuf(Msg->from, Buf2, 0);
657 StrBufExtract_token(Msg->inetaddr, Buf, 4, '|');
659 StrBufSkip_NTokenS(Buf, &Ptr, '|', 1);
660 Msg->subj = NewStrBufPlain(NULL, StrLength(Buf));
661 StrBufExtract_NextToken(Buf2, Buf, &Ptr, '|');
662 if (StrLength(Buf2) == 0)
663 StrBufAppendBufPlain(Msg->subj, _("(no subject)"), -1,0);
665 StrBuf_RFC822_to_Utf8(Msg->subj, Buf2, WCC->DefaultCharset, FoundCharset);
666 if ((StrLength(Msg->subj) > 75) &&
667 (StrBuf_Utf8StrLen(Msg->subj) > 75)) {
668 StrBuf_Utf8StrCut(Msg->subj, 72);
669 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"
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;
869 if (havebstr("is_summary") && (1 == (ibstr("is_summary"))))
870 WCC->wc_view = VIEW_MAILBOX;
873 output_headers(1, 1, 1, 0, 0, 0);
874 } else if (WCC->wc_view == VIEW_MAILBOX) {
875 jsonMessageListHdr();
878 switch (WCC->wc_view) {
880 sprintf(buf, "wiki?room=%s&page=home", ChrPtr(WCC->wc_roomname));
886 strcpy(cmd, "MSGS ALL");
888 parse_calendar_view_request(&calv);
891 strcpy(cmd, "MSGS ALL");
895 strcpy(cmd, "MSGS ALL");
897 wprintf("<div id=\"new_notes_here\"></div>\n");
899 case VIEW_ADDRESSBOOK:
900 is_singlecard = ibstr("is_singlecard");
901 if (is_singlecard != 1) {
902 if (oper == do_search) {
903 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
906 strcpy(cmd, "MSGS ALL");
917 defaultsortorder = 2;
920 care_for_empty_list = 0;
922 /* Generally using maxmsgs|startmsg is not required
923 in mailbox view, but we have a 'safemode' for clients
924 (*cough* Exploder) that simply can't handle too many */
925 if (havebstr("maxmsgs")) maxmsgs = ibstr("maxmsgs");
926 else maxmsgs = 9999999;
927 if (havebstr("startmsg")) startmsg = lbstr("startmsg");
928 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
929 (oper == do_search) ? "SEARCH" : "ALL",
930 (oper == do_search) ? bstr("query") : ""
936 defaultsortorder = 1;
939 care_for_empty_list = 1;
941 rlid[oper].cmd(cmd, sizeof(cmd));
942 SetAccessCommand(oper);
944 if (havebstr("maxmsgs"))
945 maxmsgs = ibstr("maxmsgs");
946 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
948 if (havebstr("startmsg")) {
949 startmsg = lbstr("startmsg");
954 nummsgs = load_msg_ptrs(cmd, with_headers);
956 if (care_for_empty_list) {
957 wprintf("<div class=\"nomsgs\"><br><em>");
960 wprintf(_("No new messages."));
963 wprintf(_("No old messages."));
966 wprintf(_("No messages here."));
968 wprintf("</em><br></div>\n");
976 memset(&SubTP, 0, sizeof(WCTemplputParams));
977 SubTP.Filter.ContextType = CTX_NONE;
978 SubTP.Context = NULL;
979 SortIt = RetrieveSort(&SubTP, NULL, 0,
980 HKEY("date"), defaultsortorder);
982 SortByPayload(WCC->summ, SortIt);
983 if (WCC->wc_view == VIEW_BBS) {
984 if (lbstr("SortOrder") == 2) {
986 num_displayed = -DEFAULT_MAXMSGS;
990 num_displayed = DEFAULT_MAXMSGS;
994 if (startmsg < 0) startmsg = (bbs_reverse) ? nummsgs - 1 : 0;
996 if (load_seen) load_seen_flags();
999 * If we're to print s.th. above the message list...
1001 switch (WCC->wc_view) {
1003 BBViewToolBar = NewStrBufPlain(NULL, SIZ);
1004 MessageDropdown = NewStrBufPlain(NULL, SIZ);
1006 maxmsgs = DrawMessageDropdown(MessageDropdown, maxmsgs, startmsg, num_displayed);
1007 if (num_displayed < 0) {
1008 startmsg += maxmsgs;
1009 if (num_displayed != maxmsgs)
1010 maxmsgs = abs(maxmsgs) + 1;
1012 maxmsgs = abs(maxmsgs);
1015 memset(&SubTP, 0, sizeof(WCTemplputParams));
1016 SubTP.Filter.ContextType = CTX_STRBUF;
1017 SubTP.Context = MessageDropdown;
1018 DoTemplate(HKEY("msg_listselector_top"), BBViewToolBar, &SubTP);
1019 StrBufAppendBuf(WCC->WBuf, BBViewToolBar, 0);
1020 FlushStrBuf(BBViewToolBar);
1023 WCC->startmsg = startmsg;
1024 WCC->maxmsgs = maxmsgs;
1025 WCC->num_displayed = 0;
1027 /* Put some helpful data in vars for mailsummary_json */
1028 svputlong("READLOOP:TOTALMSGS", nummsgs);
1029 svputlong("READLOOP:STARTMSG", startmsg);
1030 svputlong("WCVIEW", WCC->wc_view);
1032 * iterate over each message. if we need to load an attachment, do it here.
1034 if (WCC->wc_view == VIEW_MAILBOX) goto NO_MSG_LOOP;
1036 * iterate over each message. if we need to load an attachment, do it here.
1038 at = GetNewHashPos(WCC->summ, 0);
1039 num_displayed = i = 0;
1040 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
1041 Msg = (message_summary*) vMsg;
1042 if ((Msg->msgnum >= startmsg) && (num_displayed <= maxmsgs)) {
1043 switch (WCC->wc_view) {
1046 case VIEW_CALBRIEF: /* load the mime attachments for special tasks... */
1048 load_calendar_item(Msg, Msg->is_new, &calv);
1051 display_task(Msg, Msg->is_new);
1054 display_note(Msg, Msg->is_new);
1056 case VIEW_ADDRESSBOOK:
1058 fetch_ab_name(Msg, &ab_name);
1059 if (ab_name == NULL)
1062 addrbook = realloc(addrbook,
1063 (sizeof(addrbookent) * num_ab) );
1064 safestrncpy(addrbook[num_ab-1].ab_name, ab_name,
1065 sizeof(addrbook[num_ab-1].ab_name));
1066 addrbook[num_ab-1].ab_msgnum = Msg->msgnum;
1069 case VIEW_BBS: /* Tag the mails we want to show in bbview... */
1071 if (displayed_msgs == NULL) {
1072 displayed_msgs = malloc(sizeof(long) *
1073 (maxmsgs<nummsgs ? maxmsgs + 1 : nummsgs + 1));
1075 if ((i >= startmsg) && (i < startmsg + maxmsgs)) {
1076 displayed_msgs[num_displayed] = Msg->msgnum;
1077 if (lowest_displayed < 0) lowest_displayed = a;
1078 highest_displayed = a;
1090 * Done iterating the message list. now tasks we want to do after.
1092 switch (WCC->wc_view) {
1094 DoTemplate(HKEY("mailsummary_json"),NULL, &SubTP);
1097 if (displayed_msgs != NULL) {
1098 /** if we do a split bbview in the future, begin messages div here */
1100 for (a=0; a<num_displayed; ++a) {
1101 read_message(WCC->WBuf, HKEY("view_message"), displayed_msgs[a], NULL, &Mime);
1104 /** if we do a split bbview in the future, end messages div here */
1106 free(displayed_msgs);
1107 displayed_msgs = NULL;
1109 memset(&SubTP, 0, sizeof(WCTemplputParams));
1110 SubTP.Filter.ContextType = CTX_STRBUF;
1111 SubTP.Context = MessageDropdown;
1112 DoTemplate(HKEY("msg_listselector_bottom"), BBViewToolBar, &SubTP);
1113 StrBufAppendBuf(WCC->WBuf, BBViewToolBar, 0);
1115 FreeStrBuf(&BBViewToolBar);
1116 FreeStrBuf(&MessageDropdown);
1121 switch (WCC->wc_view) {
1126 render_calendar_view(&calv);
1129 do_tasks_view(); /** Render the task list */
1133 case VIEW_ADDRESSBOOK:
1135 read_message(WC->WBuf, HKEY("view_message"), lbstr("startmsg"), NULL, &Mime);
1137 do_addrbook_view(addrbook, num_ab); /** Render the address book */
1144 /** Note: wDumpContent() will output one additional </div> tag. */
1145 if (WCC->wc_view != VIEW_MAILBOX) {
1146 /* We ought to move this out into template */
1153 if (WCC->summ != NULL) {
1154 DeleteHash(&WCC->summ);
1156 if (addrbook != NULL) free(addrbook);
1157 FreeStrBuf(&BBViewToolBar);
1162 * Back end for post_message()
1163 * ... this is where the actual message gets transmitted to the server.
1165 void post_mime_to_server(void) {
1166 wcsession *WCC = WC;
1167 char top_boundary[SIZ];
1168 char alt_boundary[SIZ];
1169 int is_multipart = 0;
1171 wc_mime_attachment *att;
1173 size_t encoded_length;
1174 size_t encoded_strlen;
1175 char *txtmail = NULL;
1177 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
1178 ChrPtr(WCC->serv_info->serv_fqdn),
1182 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
1183 ChrPtr(WCC->serv_info->serv_fqdn),
1188 /* RFC2045 requires this, and some clients look for it... */
1189 serv_puts("MIME-Version: 1.0");
1190 serv_puts("X-Mailer: " PACKAGE_STRING);
1192 /* If there are attachments, we have to do multipart/mixed */
1193 if (GetCount(WCC->attachments) > 0) {
1198 /* Remember, serv_printf() appends an extra newline */
1199 serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
1200 serv_printf("This is a multipart message in MIME format.\n");
1201 serv_printf("--%s", top_boundary);
1204 /* Remember, serv_printf() appends an extra newline */
1205 serv_printf("Content-type: multipart/alternative; "
1206 "boundary=\"%s\"\n", alt_boundary);
1207 serv_printf("This is a multipart message in MIME format.\n");
1208 serv_printf("--%s", alt_boundary);
1210 serv_puts("Content-type: text/plain; charset=utf-8");
1211 serv_puts("Content-Transfer-Encoding: quoted-printable");
1213 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
1214 text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */
1217 serv_printf("--%s", alt_boundary);
1219 serv_puts("Content-type: text/html; charset=utf-8");
1220 serv_puts("Content-Transfer-Encoding: quoted-printable");
1222 serv_puts("<html><body>\r\n");
1223 text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */
1224 serv_puts("</body></html>\r\n");
1226 serv_printf("--%s--", alt_boundary);
1234 /* Add in the attachments */
1235 it = GetNewHashPos(WCC->attachments, 0);
1236 while (GetNextHashPos(WCC->attachments, it, &len, &Key, &vAtt)) {
1237 att = (wc_mime_attachment *)vAtt;
1238 encoded_length = ((att->length * 150) / 100);
1239 encoded = malloc(encoded_length);
1240 if (encoded == NULL) break;
1241 encoded_strlen = CtdlEncodeBase64(encoded, ChrPtr(att->Data), StrLength(att->Data), 1);
1243 serv_printf("--%s", top_boundary);
1244 serv_printf("Content-type: %s", ChrPtr(att->ContentType));
1245 serv_printf("Content-disposition: attachment; filename=\"%s\"", ChrPtr(att->FileName));
1246 serv_puts("Content-transfer-encoding: base64");
1248 serv_write(encoded, encoded_strlen);
1253 serv_printf("--%s--", top_boundary);
1262 * Post message (or don't post message)
1264 * Note regarding the "dont_post" variable:
1265 * A random value (actually, it's just a timestamp) is inserted as a hidden
1266 * field called "postseq" when the display_enter page is generated. This
1267 * value is checked when posting, using the static variable dont_post. If a
1268 * user attempts to post twice using the same dont_post value, the message is
1269 * discarded. This prevents the accidental double-saving of the same message
1270 * if the user happens to click the browser "back" button.
1272 void post_message(void)
1275 StrBuf *encoded_subject = NULL;
1276 static long dont_post = (-1L);
1277 wc_mime_attachment *att;
1278 int is_anonymous = 0;
1279 const StrBuf *display_name = NULL;
1280 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 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WCC->upload_length);
1300 /** There's an attachment. Save it to this struct... */
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);
1308 if (WCC->attachments == NULL)
1309 WCC->attachments = NewHash(1, NULL);
1310 /* And add it to the list. */
1311 n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
1312 Put(WCC->attachments, N, n, att, DestroyMime);
1315 * Mozilla sends a simple filename, which is what we want,
1316 * but Satan's Browser sends an entire pathname. Reduce
1317 * the path to just a filename if we need to.
1319 pch = strrchr(ChrPtr(att->FileName), '/');
1321 StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1);
1323 pch = strrchr(ChrPtr(att->FileName), '\\');
1325 StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1);
1329 * Transfer control of this memory from the upload struct
1330 * to the attachment struct.
1332 att->Data = NewStrBufPlain(WCC->upload, WCC->upload_length);
1334 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;
1360 if (havebstr("references"))
1362 const StrBuf *ref = sbstr("references");
1363 references = NewStrBufPlain(ChrPtr(ref), StrLength(ref));
1364 if (*ChrPtr(references) == '|') { /* remove leading '|' if present */
1365 StrBufCutLeft(references, 1);
1367 StrBufReplaceChars(references, '|', '!');
1369 if (havebstr("subject")) {
1372 * make enough room for the encoded string;
1373 * plus the QP header
1375 Subj = sbstr("subject");
1377 StrBufRFC2047encode(&encoded_subject, Subj);
1379 Recp = sbstr("recp");
1382 Wikipage = sbstr("wikipage");
1383 my_email_addr = sbstr("my_email_addr");
1385 CmdBuf = NewStrBufPlain(NULL,
1388 StrLength(encoded_subject) +
1391 StrLength(Wikipage) +
1392 StrLength(my_email_addr) +
1393 StrLength(references));
1395 StrBufPrintf(CmdBuf,
1399 ChrPtr(encoded_subject),
1400 ChrPtr(display_name),
1404 ChrPtr(my_email_addr),
1405 ChrPtr(references));
1406 FreeStrBuf(&references);
1408 lprintf(9, "%s\n", ChrPtr(CmdBuf));
1409 serv_puts(ChrPtr(CmdBuf));
1410 serv_getln(buf, sizeof buf);
1411 FreeStrBuf(&CmdBuf);
1412 FreeStrBuf(&encoded_subject);
1413 if (buf[0] == '4') {
1414 post_mime_to_server();
1415 if ( (havebstr("recp"))
1416 || (havebstr("cc" ))
1417 || (havebstr("bcc" ))
1419 sprintf(WCC->ImportantMessage, _("Message has been sent.\n"));
1422 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
1424 dont_post = lbstr("postseq");
1426 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
1427 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1433 DeleteHash(&WCC->attachments);
1436 * We may have been supplied with instructions regarding the location
1437 * to which we must return after posting. If found, go there.
1439 if (havebstr("return_to")) {
1440 http_redirect(bstr("return_to"));
1443 * If we were editing a page in a wiki room, go to that page now.
1445 else if (havebstr("wikipage")) {
1446 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
1450 * Otherwise, just go to the "read messages" loop.
1461 * \brief display the message entry screen
1463 void display_enter(void)
1467 const StrBuf *display_name = NULL;
1468 int recipient_required = 0;
1469 int subject_required = 0;
1470 int recipient_bad = 0;
1471 int is_anonymous = 0;
1472 wcsession *WCC = WC;
1476 if (havebstr("force_room")) {
1477 gotoroom(sbstr("force_room"));
1480 display_name = sbstr("display_name");
1481 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
1482 display_name = NULL;
1486 /** First test to see whether this is a room that requires recipients to be entered */
1487 serv_puts("ENT0 0");
1488 serv_getln(buf, sizeof buf);
1490 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
1491 recipient_required = 1;
1493 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
1494 sprintf(WCC->ImportantMessage, "%s", &buf[4]);
1499 /* Is the server strongly recommending that the user enter a message subject? */
1500 if ((buf[3] != '\0') && (buf[4] != '\0')) {
1501 subject_required = extract_int(&buf[4], 1);
1505 * Are we perhaps in an address book view? If so, then an "enter
1506 * message" command really means "add new entry."
1508 if (WCC->wc_default_view == VIEW_ADDRESSBOOK) {
1509 do_edit_vcard(-1, "", NULL, NULL, "", ChrPtr(WCC->wc_roomname));
1514 * Are we perhaps in a calendar room? If so, then an "enter
1515 * message" command really means "add new calendar item."
1517 if (WCC->wc_default_view == VIEW_CALENDAR) {
1518 display_edit_event();
1523 * Are we perhaps in a tasks view? If so, then an "enter
1524 * message" command really means "add new task."
1526 if (WCC->wc_default_view == VIEW_TASKS) {
1527 display_edit_task();
1532 * Otherwise proceed normally.
1533 * Do a custom room banner with no navbar...
1536 if (recipient_required) {
1537 const StrBuf *Recp = NULL;
1538 const StrBuf *Cc = NULL;
1539 const StrBuf *Bcc = NULL;
1540 const StrBuf *Wikipage = NULL;
1541 StrBuf *CmdBuf = NULL;
1542 const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
1544 Recp = sbstr("recp");
1547 Wikipage = sbstr("wikipage");
1549 CmdBuf = NewStrBufPlain(NULL,
1552 StrLength(display_name) +
1555 StrLength(Wikipage));
1557 StrBufPrintf(CmdBuf,
1561 ChrPtr(display_name),
1565 serv_puts(ChrPtr(CmdBuf));
1566 serv_getln(buf, sizeof buf);
1567 FreeStrBuf(&CmdBuf);
1569 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
1570 if (havebstr("recp") &&
1576 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
1577 wprintf("<em>%s</em><br />\n", &buf[4]);/*TODO -> important message */
1581 svputlong("RCPTREQUIRED", recipient_required);
1582 svputlong("SUBJREQUIRED", recipient_required || subject_required);
1585 output_headers(1, 0, 0, 0, 1, 0);
1586 DoTemplate(HKEY("edit_message"), NULL, &NoCtx);
1593 * \brief delete a message
1595 void delete_msg(void)
1600 msgid = lbstr("msgid");
1602 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
1603 serv_printf("DELE %ld", msgid);
1605 else { /** Otherwise move it to Trash */
1606 serv_printf("MOVE %ld|_TRASH_|0", msgid);
1609 serv_getln(buf, sizeof buf);
1610 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1617 * \brief move a message to another folder
1624 msgid = lbstr("msgid");
1626 if (havebstr("move_button")) {
1627 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
1629 serv_getln(buf, sizeof buf);
1630 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1632 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
1643 * Confirm move of a message
1645 void confirm_move_msg(void)
1651 msgid = lbstr("msgid");
1654 output_headers(1, 1, 2, 0, 0, 0);
1655 wprintf("<div id=\"banner\">\n");
1657 wprintf(_("Confirm move of message"));
1659 wprintf("</div>\n");
1661 wprintf("<div id=\"content\" class=\"service\">\n");
1663 wprintf("<CENTER>");
1665 wprintf(_("Move this message to:"));
1666 wprintf("<br />\n");
1668 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
1669 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1670 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
1672 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
1674 serv_getln(buf, sizeof buf);
1675 if (buf[0] == '1') {
1676 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1677 extract_token(targ, buf, 0, '|', sizeof targ);
1678 wprintf("<OPTION>");
1683 wprintf("</SELECT>\n");
1684 wprintf("<br />\n");
1686 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
1688 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
1689 wprintf("</form></CENTER>\n");
1691 wprintf("</CENTER>\n");
1697 * Generic function to output an arbitrary MIME attachment from
1698 * message being composed
1700 * partnum The MIME part to be output
1701 * filename Fake filename to give
1702 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
1704 void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
1707 StrBuf *content_type;
1708 wc_mime_attachment *part;
1710 if (GetHash(WC->attachments, SKEY(partnum), &vPart) &&
1712 part = (wc_mime_attachment*) vPart;
1713 if (force_download) {
1714 content_type = NewStrBufPlain(HKEY("application/octet-stream"));
1717 content_type = NewStrBufDup(part->ContentType);
1719 StrBufAppendBuf(WC->WBuf, part->Data, 0);
1720 http_transmit_thing(ChrPtr(content_type), 0);
1722 hprintf("HTTP/1.1 404 %s\n", ChrPtr(partnum));
1723 output_headers(0, 0, 0, 0, 0, 0);
1724 hprintf("Content-Type: text/plain\r\n");
1725 wprintf(_("An error occurred while retrieving this part: %s/%s\n"),
1726 ChrPtr(partnum), ChrPtr(filename));
1729 FreeStrBuf(&content_type);
1734 * Generic function to output an arbitrary MIME part from an arbitrary
1735 * message number on the server.
1737 * msgnum Number of the item on the citadel server
1738 * partnum The MIME part to be output
1739 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
1741 void mimepart(int force_download)
1745 wcsession *WCC = WC;
1748 StrBuf *ContentType = NewStrBufPlain(HKEY("application/octet-stream"));
1751 att = Buf = NewStrBuf();
1752 msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/');
1753 StrBufExtract_token(att, WCC->Hdr->HR.ReqLine, 1, '/');
1755 serv_printf("OPNA %ld|%s", msgnum, ChrPtr(att));
1756 StrBuf_ServGetln(Buf);
1757 if (GetServerStatus(Buf, NULL) == 2) {
1758 StrBufCutLeft(Buf, 4);
1759 bytes = StrBufExtract_long(Buf, 0, '|');
1760 if (!force_download) {
1761 StrBufExtract_token(ContentType, Buf, 3, '|');
1764 read_server_binary(WCC->WBuf, bytes, Buf);
1766 StrBuf_ServGetln(Buf);
1767 CT = ChrPtr(ContentType);
1769 if (!force_download) {
1770 if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
1771 StrBufExtract_token(Buf, WCC->Hdr->HR.ReqLine, 2, '/');
1772 CT = GuessMimeByFilename(SKEY(Buf));
1774 if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
1775 CT = GuessMimeType(SKEY(WCC->WBuf));
1778 http_transmit_thing(CT, 0);
1780 StrBufCutLeft(Buf, 4);
1781 hprintf("HTTP/1.1 404 %s\n", ChrPtr(Buf));
1782 output_headers(0, 0, 0, 0, 0, 0);
1783 hprintf("Content-Type: text/plain\r\n");
1784 wprintf(_("An error occurred while retrieving this part: %s\n"),
1788 FreeStrBuf(&ContentType);
1794 * Read any MIME part of a message, from the server, into memory.
1796 StrBuf *load_mimepart(long msgnum, char *partnum)
1802 serv_printf("DLAT %ld|%s", msgnum, partnum);
1803 StrBuf_ServGetln(Buf);
1804 if (GetServerStatus(Buf, NULL) == 6) {
1805 StrBufCutLeft(Buf, 4);
1806 bytes = StrBufExtract_long(Buf, 0, '|');
1809 StrBuf_ServGetBLOBBuffered(Buf, bytes);
1819 * Read any MIME part of a message, from the server, into memory.
1821 void MimeLoadData(wc_mime_attachment *Mime)
1825 /* TODO: is there a chance the contenttype is different to the one we know? */
1826 serv_printf("DLAT %ld|%s", Mime->msgnum, ChrPtr(Mime->PartNum));
1828 StrBuf_ServGetln(Buf);
1829 if (GetServerStatus(Buf, NULL) == 6) {
1830 bytes = extract_long(&(ChrPtr(Buf)[4]), 0);
1832 if (Mime->Data == NULL)
1833 Mime->Data = NewStrBufPlain(NULL, bytes);
1834 StrBuf_ServGetBLOBBuffered(Mime->Data, bytes);
1837 FlushStrBuf(Mime->Data);
1838 /* TODO XImportant message */
1846 void view_mimepart(void) {
1850 void download_mimepart(void) {
1854 void view_postpart(void) {
1855 StrBuf *filename = NewStrBuf();
1856 StrBuf *partnum = NewStrBuf();
1858 StrBufExtract_token(partnum, WC->Hdr->HR.ReqLine, 0, '/');
1859 StrBufExtract_token(filename, WC->Hdr->HR.ReqLine, 1, '/');
1861 postpart(partnum, filename, 0);
1863 FreeStrBuf(&filename);
1864 FreeStrBuf(&partnum);
1867 void download_postpart(void) {
1868 StrBuf *filename = NewStrBuf();
1869 StrBuf *partnum = NewStrBuf();
1871 StrBufExtract_token(partnum, WC->Hdr->HR.ReqLine, 0, '/');
1872 StrBufExtract_token(filename, WC->Hdr->HR.ReqLine, 1, '/');
1874 postpart(partnum, filename, 1);
1876 FreeStrBuf(&filename);
1877 FreeStrBuf(&partnum);
1880 void h_readnew(void) { readloop(readnew);}
1881 void h_readold(void) { readloop(readold);}
1882 void h_readfwd(void) { readloop(readfwd);}
1883 void h_headers(void) { readloop(headers);}
1884 void h_do_search(void) { readloop(do_search);}
1886 void jsonMessageListHdr(void)
1888 /* TODO: make a generic function */
1889 hprintf("HTTP/1.1 200 OK\r\n");
1890 hprintf("Content-type: application/json; charset=utf-8\r\n");
1891 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
1892 hprintf("Connection: close\r\n");
1893 hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
1896 /* Spit out the new summary view. This is basically a static page, so clients can cache the layout, all the dirty work is javascript :) */
1897 void new_summary_view(void) {
1899 DoTemplate(HKEY("msg_listview"),NULL,&NoCtx);
1900 DoTemplate(HKEY("trailing"),NULL,&NoCtx);
1903 /** Output message list in JSON-format */
1904 void jsonMessageList(void) {
1905 const StrBuf *room = sbstr("room");
1906 long oper = (havebstr("query")) ? do_search : readnew;
1917 RegisterPreference("use_sig",
1918 _("Attach signature to email messages?"),
1921 RegisterPreference("signature", _("Use this signature:"), PRF_QP_STRING, NULL);
1922 RegisterPreference("default_header_charset",
1923 _("Default character set for email headers:"),
1926 RegisterPreference("defaultfrom", _("Preferred email address"), PRF_STRING, NULL);
1927 RegisterPreference("defaultname",
1928 _("Preferred display name for email messages"),
1931 RegisterPreference("defaulthandle",
1932 _("Preferred display name for bulletin board posts"),
1935 RegisterPreference("mailbox",_("Mailbox view mode"), PRF_STRING, NULL);
1937 WebcitAddUrlHandler(HKEY("readnew"), h_readnew, NEED_URL);
1938 WebcitAddUrlHandler(HKEY("readold"), h_readold, NEED_URL);
1939 WebcitAddUrlHandler(HKEY("readfwd"), h_readfwd, NEED_URL);
1940 WebcitAddUrlHandler(HKEY("headers"), h_headers, NEED_URL);
1941 WebcitAddUrlHandler(HKEY("do_search"), h_do_search, 0);
1942 WebcitAddUrlHandler(HKEY("display_enter"), display_enter, 0);
1943 WebcitAddUrlHandler(HKEY("post"), post_message, 0);
1944 WebcitAddUrlHandler(HKEY("move_msg"), move_msg, 0);
1945 WebcitAddUrlHandler(HKEY("delete_msg"), delete_msg, 0);
1946 WebcitAddUrlHandler(HKEY("confirm_move_msg"), confirm_move_msg, 0);
1947 WebcitAddUrlHandler(HKEY("msg"), embed_message, NEED_URL);
1948 WebcitAddUrlHandler(HKEY("message"), handle_one_message, NEED_URL|XHTTP_COMMANDS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
1949 WebcitAddUrlHandler(HKEY("printmsg"), print_message, NEED_URL);
1950 WebcitAddUrlHandler(HKEY("mobilemsg"), mobile_message_view, NEED_URL);
1951 WebcitAddUrlHandler(HKEY("msgheaders"), display_headers, NEED_URL);
1953 WebcitAddUrlHandler(HKEY("mimepart"), view_mimepart, NEED_URL);
1954 WebcitAddUrlHandler(HKEY("mimepart_download"), download_mimepart, NEED_URL);
1955 WebcitAddUrlHandler(HKEY("postpart"), view_postpart, NEED_URL);
1956 WebcitAddUrlHandler(HKEY("postpart_download"), download_postpart, NEED_URL);
1959 WebcitAddUrlHandler(HKEY("roommsgs"), jsonMessageList,0);
1964 SessionDetachModule_MSG
1967 DeleteHash(&sess->summ);