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;
368 //msgnum = StrTol(WCC->UrlFragment3);
369 //gotoroom(WCC->UrlFragment2);
370 switch (WCC->Hdr->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);
417 * Unadorned HTML output of an individual message, suitable
418 * for placing in a hidden iframe, for printing, or whatever
420 * msgnum_as_string == Message number, as a string instead of as a long int
422 void embed_message(void) {
427 StrBuf *CmdBuf = NULL;
429 msgnum = StrBufExtract_long(WCC->Hdr->ReqLine, 2, '/');
430 switch (WCC->Hdr->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 * msgnum_as_string == Message number, as a string instead of as a long int
465 void print_message(void) {
469 msgnum = StrBufExtract_long(WC->Hdr->ReqLine, 2, '/');
470 output_headers(0, 0, 0, 0, 0, 0);
472 hprintf("Content-type: text/html\r\n"
473 "Server: " PACKAGE_STRING "\r\n"
474 "Connection: close\r\n");
478 read_message(WC->WBuf, HKEY("view_message_print"), msgnum, NULL, &Mime);
484 * Mobile browser view of message
486 * @param msg_num_as_string Message number as a string instead of as a long int
488 void mobile_message_view(void)
493 msgnum = StrBufExtract_long(WC->Hdr->ReqLine, 2, '/');
494 output_headers(1, 0, 0, 0, 0, 1);
496 do_template("msgcontrols", NULL);
497 read_message(WC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
502 * \brief Display a message's headers
504 * \param msgnum_as_string Message number, as a string instead of as a long int
506 void display_headers(void) {
510 msgnum = StrBufExtract_long(WC->Hdr->ReqLine, 2, '/');
511 output_headers(0, 0, 0, 0, 0, 0);
513 hprintf("Content-type: text/plain\r\n"
515 "Connection: close\r\n",
519 serv_printf("MSG2 %ld|3", msgnum);
520 serv_getln(buf, sizeof buf);
522 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
523 wprintf("%s\n", buf);
531 message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSubject, long MsgNum)
534 MsgPartEvaluatorStruct *Eval;
535 message_summary *Msg;
544 serv_printf("MSG0 %ld|1", MsgNum); /* ask for headers only */
546 StrBuf_ServGetln(Buf);
547 if (GetServerStatus(Buf, NULL) == 1) {
552 Msg = (message_summary*)malloc(sizeof(message_summary));
553 memset(Msg, 0, sizeof(message_summary));
554 while (len = StrBuf_ServGetln(Buf),
556 strcmp(ChrPtr(Buf), "000")== 0)){
558 ebuf = strchr(ChrPtr(Buf), '=');
560 if (GetHash(MsgEvaluators, buf, nBuf, &vEval) && vEval != NULL) {
561 Eval = (MsgPartEvaluatorStruct*) vEval;
562 StrBufCutLeft(Buf, nBuf + 1);
565 else lprintf(1, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
575 * load message pointers from the server for a "read messages" operation
577 * servcmd: the citadel command to send to the citserver
578 * with_headers: also include some of the headers with the message numbers (more expensive)
580 int load_msg_ptrs(const char *servcmd, int with_headers)
582 StrBuf* FoundCharset = NULL;
584 message_summary *Msg;
591 const char *Ptr = NULL;
593 if (WCC->summ != NULL) {
594 DeleteHash(&WCC->summ);
596 WCC->summ = NewHash(1, Flathash);
601 StrBuf_ServGetln(Buf);
602 if (GetServerStatus(Buf, NULL) != 1) {
607 while (len = StrBuf_ServGetln(Buf),
609 strcmp(ChrPtr(Buf), "000")!= 0))
611 if (nummsgs < maxload) {
614 Msg = (message_summary*)malloc(sizeof(message_summary));
615 memset(Msg, 0, sizeof(message_summary));
617 Msg->msgnum = StrBufExtractNext_long(Buf, &Ptr, '|');
618 Msg->date = StrBufExtractNext_long(Buf, &Ptr, '|');
620 * as citserver probably gives us messages in forward date sorting
621 * nummsgs should be the same order as the message date.
623 if (Msg->date == 0) {
625 if (StrLength(Buf) < 32)
629 Msg->from = NewStrBufPlain(NULL, StrLength(Buf));
630 StrBufExtract_NextToken(Buf2, Buf, &Ptr, '|');
631 if (StrLength(Buf2) != 0) {
632 /** Handle senders with RFC2047 encoding */
633 StrBuf_RFC822_to_Utf8(Msg->from, Buf2, WCC->DefaultCharset, FoundCharset);
637 StrBufExtract_NextToken(Buf2, Buf, &Ptr, '|');
638 if ((StrLength(Buf2) !=0 ) &&
639 ( ((WCC->room_flags & QR_NETWORK)
640 || ((strcasecmp(ChrPtr(Buf2), ChrPtr(WCC->serv_info->serv_nodename))
641 && (strcasecmp(ChrPtr(Buf2), ChrPtr(WCC->serv_info->serv_fqdn))))))))
643 StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
644 StrBufAppendBuf(Msg->from, Buf2, 0);
648 StrBufExtract_token(Msg->inetaddr, Buf, 4, '|');
650 StrBufSkip_NTokenS(Buf, &Ptr, '|', 1);
651 Msg->subj = NewStrBufPlain(NULL, StrLength(Buf));
652 StrBufExtract_NextToken(Buf2, Buf, &Ptr, '|');
653 if (StrLength(Buf2) == 0)
654 StrBufAppendBufPlain(Msg->subj, _("(no subject)"), -1,0);
656 StrBuf_RFC822_to_Utf8(Msg->subj, Buf2, WCC->DefaultCharset, FoundCharset);
657 if ((StrLength(Msg->subj) > 75) &&
658 (StrBuf_Utf8StrLen(Msg->subj) > 75)) {
659 StrBuf_Utf8StrCut(Msg->subj, 72);
660 StrBufAppendBufPlain(Msg->subj, HKEY("..."), 0);
665 if ((StrLength(Msg->from) > 25) &&
666 (StrBuf_Utf8StrLen(Msg->from) > 25)) {
667 StrBuf_Utf8StrCut(Msg->from, 23);
668 StrBufAppendBufPlain(Msg->from, HKEY("..."), 0);
672 Put(WCC->summ, (const char *)&n, sizeof(n), Msg, DestroyMessageSummary);
682 inline message_summary* GetMessagePtrAt(int n, HashList *Summ)
690 GetHashAt(Summ, n, &HKLen, &Key, &vMsg);
691 return (message_summary*) vMsg;
695 long DrawMessageDropdown(StrBuf *Selector, long maxmsgs, long startmsg, int nMessages)
708 WCTemplputParams SubTP;
710 memset(&SubTP, 0, sizeof(WCTemplputParams));
711 SubTP.Filter.ContextType = CTX_LONGVECTOR;
712 SubTP.Context = &vector;
713 TmpBuf = NewStrBuf();
714 At = GetNewHashPos(WCC->summ, nMessages);
715 nItems = GetCount(WCC->summ);
719 vector[1] = startmsg;
723 vector[3] = abs(nMessages);
724 lo = GetHashPosCounter(At);
726 if (lo + nMessages >= nItems) {
728 vector[3] = nItems - lo;
733 hi = lo + nMessages - 1;
736 if (lo + nMessages < -1) {
740 if ((lo % abs(nMessages)) != 0) {
741 int offset = (lo % abs(nMessages) *
742 (nMessages / abs(nMessages)));
744 vector[3] = abs(offset);
752 done = !GetNextHashPos(WCC->summ, At, &hklen, &key, &vMsg);
755 * Bump these because although we're thinking in zero base, the user
756 * is a drooling idiot and is thinking in one base.
762 dbg_print_longvector(vector);
763 DoTemplate(HKEY("select_messageindex"), TmpBuf, &SubTP);
764 StrBufAppendBuf(Selector, TmpBuf, 0);
768 if (maxmsgs == 9999999) {
775 dbg_print_longvector(vector);
776 DoTemplate(HKEY("select_messageindex_all"), TmpBuf, &SubTP);
777 StrBufAppendBuf(Selector, TmpBuf, 0);
783 void load_seen_flags(void)
785 message_summary *Msg;
793 OldMsg = NewStrBuf();
795 StrBuf_ServGetln(OldMsg);
796 if (GetServerStatus(OldMsg, NULL) == 2) {
797 StrBufCutLeft(OldMsg, 4);
803 at = GetNewHashPos(WCC->summ, 0);
804 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
805 /** Are you a new message, or an old message? */
806 Msg = (message_summary*) vMsg;
807 if (is_msg_in_mset(ChrPtr(OldMsg), Msg->msgnum)) {
818 extern readloop_struct rlid[];
821 * command loop for reading messages
823 * Set oper to "readnew" or "readold" or "readfwd" or "headers"
825 void readloop(long oper)
827 StrBuf *MessageDropdown = NULL;
828 StrBuf *BBViewToolBar = NULL;
830 message_summary *Msg;
834 int with_headers = 0;
838 long *displayed_msgs = NULL;
839 int num_displayed = 0;
840 int is_singlecard = 0;
843 int lowest_displayed = (-1);
844 int highest_displayed = 0;
845 addrbookent *addrbook = NULL;
852 int care_for_empty_list = 0;
855 int defaultsortorder = 0;
856 WCTemplputParams SubTP;
860 if (havebstr("is_summary") && (1 == (ibstr("is_summary"))))
861 WCC->wc_view = VIEW_MAILBOX;
864 output_headers(1, 1, 1, 0, 0, 0);
865 } else if (WCC->wc_view == VIEW_MAILBOX) {
866 jsonMessageListHdr();
869 switch (WCC->wc_view) {
871 sprintf(buf, "wiki?room=%s&page=home", ChrPtr(WCC->wc_roomname));
877 strcpy(cmd, "MSGS ALL");
879 parse_calendar_view_request(&calv);
882 strcpy(cmd, "MSGS ALL");
886 strcpy(cmd, "MSGS ALL");
888 wprintf("<div id=\"new_notes_here\"></div>\n");
890 case VIEW_ADDRESSBOOK:
891 is_singlecard = ibstr("is_singlecard");
892 if (is_singlecard != 1) {
893 if (oper == do_search) {
894 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
897 strcpy(cmd, "MSGS ALL");
908 defaultsortorder = 2;
911 care_for_empty_list = 0;
913 /* Generally using maxmsgs|startmsg is not required
914 in mailbox view, but we have a 'safemode' for clients
915 (*cough* Exploder) that simply can't handle too many */
916 if (havebstr("maxmsgs")) maxmsgs = ibstr("maxmsgs");
917 else maxmsgs = 9999999;
918 if (havebstr("startmsg")) startmsg = lbstr("startmsg");
919 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
920 (oper == do_search) ? "SEARCH" : "ALL",
921 (oper == do_search) ? bstr("query") : ""
927 defaultsortorder = 1;
930 care_for_empty_list = 1;
932 rlid[oper].cmd(cmd, sizeof(cmd));
933 SetAccessCommand(oper);
935 if (havebstr("maxmsgs"))
936 maxmsgs = ibstr("maxmsgs");
937 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
939 if (havebstr("startmsg")) {
940 startmsg = lbstr("startmsg");
945 nummsgs = load_msg_ptrs(cmd, with_headers);
947 if (care_for_empty_list) {
948 wprintf("<div class=\"nomsgs\"><br><em>");
951 wprintf(_("No new messages."));
954 wprintf(_("No old messages."));
957 wprintf(_("No messages here."));
959 wprintf("</em><br></div>\n");
967 memset(&SubTP, 0, sizeof(WCTemplputParams));
968 SubTP.Filter.ContextType = CTX_NONE;
969 SubTP.Context = NULL;
970 SortIt = RetrieveSort(&SubTP, NULL, 0,
971 HKEY("date"), defaultsortorder);
973 SortByPayload(WCC->summ, SortIt);
974 if (WCC->wc_view == VIEW_BBS) {
975 if (lbstr("SortOrder") == 2) {
977 num_displayed = -DEFAULT_MAXMSGS;
981 num_displayed = DEFAULT_MAXMSGS;
985 if (startmsg < 0) startmsg = (bbs_reverse) ? nummsgs - 1 : 0;
987 if (load_seen) load_seen_flags();
990 * If we're to print s.th. above the message list...
992 switch (WCC->wc_view) {
994 BBViewToolBar = NewStrBuf();
995 MessageDropdown = NewStrBuf();
997 maxmsgs = DrawMessageDropdown(MessageDropdown, maxmsgs, startmsg, num_displayed);
998 if (num_displayed < 0) {
1000 if (num_displayed != maxmsgs)
1001 maxmsgs = abs(maxmsgs) + 1;
1003 maxmsgs = abs(maxmsgs);
1006 memset(&SubTP, 0, sizeof(WCTemplputParams));
1007 SubTP.Filter.ContextType = CTX_STRBUF;
1008 SubTP.Context = MessageDropdown;
1009 DoTemplate(HKEY("msg_listselector_top"), BBViewToolBar, &SubTP);
1010 StrBufAppendBuf(WCC->WBuf, BBViewToolBar, 0);
1011 FlushStrBuf(BBViewToolBar);
1014 WCC->startmsg = startmsg;
1015 WCC->maxmsgs = maxmsgs;
1016 WCC->num_displayed = 0;
1018 /* Put some helpful data in vars for mailsummary_json */
1019 svputlong("READLOOP:TOTALMSGS", nummsgs);
1020 svputlong("READLOOP:STARTMSG", startmsg);
1021 svputlong("WCVIEW", WCC->wc_view);
1023 * iterate over each message. if we need to load an attachment, do it here.
1025 if (WCC->wc_view == VIEW_MAILBOX) goto NO_MSG_LOOP;
1027 * iterate over each message. if we need to load an attachment, do it here.
1029 at = GetNewHashPos(WCC->summ, 0);
1030 num_displayed = i = 0;
1031 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
1032 Msg = (message_summary*) vMsg;
1033 if ((Msg->msgnum >= startmsg) && (num_displayed <= maxmsgs)) {
1034 switch (WCC->wc_view) {
1037 case VIEW_CALBRIEF: /* load the mime attachments for special tasks... */
1039 load_calendar_item(Msg, Msg->is_new, &calv);
1042 display_task(Msg, Msg->is_new);
1045 display_note(Msg, Msg->is_new);
1047 case VIEW_ADDRESSBOOK:
1049 fetch_ab_name(Msg, &ab_name);
1050 if (ab_name == NULL)
1053 addrbook = realloc(addrbook,
1054 (sizeof(addrbookent) * num_ab) );
1055 safestrncpy(addrbook[num_ab-1].ab_name, ab_name,
1056 sizeof(addrbook[num_ab-1].ab_name));
1057 addrbook[num_ab-1].ab_msgnum = Msg->msgnum;
1060 case VIEW_BBS: /* Tag the mails we want to show in bbview... */
1062 if (displayed_msgs == NULL) {
1063 displayed_msgs = malloc(sizeof(long) *
1064 (maxmsgs<nummsgs ? maxmsgs + 1 : nummsgs + 1));
1066 if ((i >= startmsg) && (i < startmsg + maxmsgs)) {
1067 displayed_msgs[num_displayed] = Msg->msgnum;
1068 if (lowest_displayed < 0) lowest_displayed = a;
1069 highest_displayed = a;
1081 * Done iterating the message list. now tasks we want to do after.
1083 switch (WCC->wc_view) {
1085 DoTemplate(HKEY("mailsummary_json"),NULL, &SubTP);
1088 if (displayed_msgs != NULL) {
1089 /** if we do a split bbview in the future, begin messages div here */
1091 for (a=0; a<num_displayed; ++a) {
1092 read_message(WCC->WBuf, HKEY("view_message"), displayed_msgs[a], NULL, &Mime);
1095 /** if we do a split bbview in the future, end messages div here */
1097 free(displayed_msgs);
1098 displayed_msgs = NULL;
1100 memset(&SubTP, 0, sizeof(WCTemplputParams));
1101 SubTP.Filter.ContextType = CTX_STRBUF;
1102 SubTP.Context = MessageDropdown;
1103 DoTemplate(HKEY("msg_listselector_bottom"), BBViewToolBar, &SubTP);
1104 StrBufAppendBuf(WCC->WBuf, BBViewToolBar, 0);
1106 FreeStrBuf(&BBViewToolBar);
1107 FreeStrBuf(&MessageDropdown);
1112 switch (WCC->wc_view) {
1117 render_calendar_view(&calv);
1120 do_tasks_view(); /** Render the task list */
1124 case VIEW_ADDRESSBOOK:
1126 read_message(WC->WBuf, HKEY("view_message"), lbstr("startmsg"), NULL, &Mime);
1128 do_addrbook_view(addrbook, num_ab); /** Render the address book */
1135 /** Note: wDumpContent() will output one additional </div> tag. */
1136 if (WCC->wc_view != VIEW_MAILBOX) {
1137 /* We ought to move this out into template */
1144 if (WCC->summ != NULL) {
1145 DeleteHash(&WCC->summ);
1147 if (addrbook != NULL) free(addrbook);
1148 FreeStrBuf(&BBViewToolBar);
1153 * Back end for post_message()
1154 * ... this is where the actual message gets transmitted to the server.
1156 void post_mime_to_server(void) {
1157 wcsession *WCC = WC;
1158 char top_boundary[SIZ];
1159 char alt_boundary[SIZ];
1160 int is_multipart = 0;
1162 wc_mime_attachment *att;
1164 size_t encoded_length;
1165 size_t encoded_strlen;
1166 char *txtmail = NULL;
1168 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
1169 ChrPtr(WCC->serv_info->serv_fqdn),
1173 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
1174 ChrPtr(WCC->serv_info->serv_fqdn),
1179 /* RFC2045 requires this, and some clients look for it... */
1180 serv_puts("MIME-Version: 1.0");
1181 serv_puts("X-Mailer: " PACKAGE_STRING);
1183 /* If there are attachments, we have to do multipart/mixed */
1184 if (GetCount(WCC->attachments) > 0) {
1189 /* Remember, serv_printf() appends an extra newline */
1190 serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
1191 serv_printf("This is a multipart message in MIME format.\n");
1192 serv_printf("--%s", top_boundary);
1195 /* Remember, serv_printf() appends an extra newline */
1196 serv_printf("Content-type: multipart/alternative; "
1197 "boundary=\"%s\"\n", alt_boundary);
1198 serv_printf("This is a multipart message in MIME format.\n");
1199 serv_printf("--%s", alt_boundary);
1201 serv_puts("Content-type: text/plain; charset=utf-8");
1202 serv_puts("Content-Transfer-Encoding: quoted-printable");
1204 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
1205 text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */
1208 serv_printf("--%s", alt_boundary);
1210 serv_puts("Content-type: text/html; charset=utf-8");
1211 serv_puts("Content-Transfer-Encoding: quoted-printable");
1213 serv_puts("<html><body>\r\n");
1214 text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */
1215 serv_puts("</body></html>\r\n");
1217 serv_printf("--%s--", alt_boundary);
1225 /* Add in the attachments */
1226 it = GetNewHashPos(WCC->attachments, 0);
1227 while (GetNextHashPos(WCC->attachments, it, &len, &Key, &vAtt)) {
1228 att = (wc_mime_attachment *)vAtt;
1229 encoded_length = ((att->length * 150) / 100);
1230 encoded = malloc(encoded_length);
1231 if (encoded == NULL) break;
1232 encoded_strlen = CtdlEncodeBase64(encoded, ChrPtr(att->Data), StrLength(att->Data), 1);
1234 serv_printf("--%s", top_boundary);
1235 serv_printf("Content-type: %s", ChrPtr(att->ContentType));
1236 serv_printf("Content-disposition: attachment; filename=\"%s\"", ChrPtr(att->FileName));
1237 serv_puts("Content-transfer-encoding: base64");
1239 serv_write(encoded, encoded_strlen);
1244 serv_printf("--%s--", top_boundary);
1253 * Post message (or don't post message)
1255 * Note regarding the "dont_post" variable:
1256 * A random value (actually, it's just a timestamp) is inserted as a hidden
1257 * field called "postseq" when the display_enter page is generated. This
1258 * value is checked when posting, using the static variable dont_post. If a
1259 * user attempts to post twice using the same dont_post value, the message is
1260 * discarded. This prevents the accidental double-saving of the same message
1261 * if the user happens to click the browser "back" button.
1263 void post_message(void)
1266 StrBuf *encoded_subject = NULL;
1267 static long dont_post = (-1L);
1268 wc_mime_attachment *att;
1269 int is_anonymous = 0;
1270 const StrBuf *display_name = NULL;
1271 wcsession *WCC = WC;
1273 if (havebstr("force_room")) {
1274 gotoroom(sbstr("force_room"));
1277 if (havebstr("display_name")) {
1278 display_name = sbstr("display_name");
1279 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
1280 display_name = NULL;
1285 if (WCC->upload_length > 0) {
1290 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WCC->upload_length);
1291 /** There's an attachment. Save it to this struct... */
1292 att = malloc(sizeof(wc_mime_attachment));
1293 memset(att, 0, sizeof(wc_mime_attachment ));
1294 att->length = WCC->upload_length;
1295 att->ContentType = NewStrBufPlain(WCC->upload_content_type, -1);
1296 att->FileName = NewStrBufPlain(WCC->upload_filename, -1);
1299 if (WCC->attachments == NULL)
1300 WCC->attachments = NewHash(1, NULL);
1301 /* And add it to the list. */
1302 n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
1303 Put(WCC->attachments, N, n, att, DestroyMime);
1306 * Mozilla sends a simple filename, which is what we want,
1307 * but Satan's Browser sends an entire pathname. Reduce
1308 * the path to just a filename if we need to.
1310 pch = strrchr(ChrPtr(att->FileName), '/');
1312 StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1);
1314 pch = strrchr(ChrPtr(att->FileName), '\\');
1316 StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1);
1320 * Transfer control of this memory from the upload struct
1321 * to the attachment struct.
1323 att->Data = NewStrBufPlain(WCC->upload, WCC->upload_length);
1325 WCC->upload_length = 0;
1331 if (havebstr("cancel_button")) {
1332 sprintf(WCC->ImportantMessage,
1333 _("Cancelled. Message was not posted."));
1334 } else if (havebstr("attach_button")) {
1337 } else if (lbstr("postseq") == dont_post) {
1338 sprintf(WCC->ImportantMessage,
1339 _("Automatically cancelled because you have already "
1340 "saved this message."));
1342 const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s";
1343 const StrBuf *Recp = NULL;
1344 const StrBuf *Cc = NULL;
1345 const StrBuf *Bcc = NULL;
1346 const StrBuf *Wikipage = NULL;
1347 const StrBuf *my_email_addr = NULL;
1348 StrBuf *CmdBuf = NULL;
1349 StrBuf *references = NULL;
1351 if (havebstr("references"))
1353 const StrBuf *ref = sbstr("references");
1354 references = NewStrBufPlain(ChrPtr(ref), StrLength(ref));
1355 if (*ChrPtr(references) == '|') { /* remove leading '|' if present */
1356 StrBufCutLeft(references, 1);
1358 StrBufReplaceChars(references, '|', '!');
1360 if (havebstr("subject")) {
1363 * make enough room for the encoded string;
1364 * plus the QP header
1366 Subj = sbstr("subject");
1368 StrBufRFC2047encode(&encoded_subject, Subj);
1370 Recp = sbstr("recp");
1373 Wikipage = sbstr("wikipage");
1374 my_email_addr = sbstr("my_email_addr");
1376 CmdBuf = NewStrBufPlain(NULL,
1379 StrLength(encoded_subject) +
1382 StrLength(Wikipage) +
1383 StrLength(my_email_addr) +
1384 StrLength(references));
1386 StrBufPrintf(CmdBuf,
1390 ChrPtr(encoded_subject),
1391 ChrPtr(display_name),
1395 ChrPtr(my_email_addr),
1396 ChrPtr(references));
1397 FreeStrBuf(&references);
1399 lprintf(9, "%s\n", ChrPtr(CmdBuf));
1400 serv_puts(ChrPtr(CmdBuf));
1401 serv_getln(buf, sizeof buf);
1402 FreeStrBuf(&CmdBuf);
1403 FreeStrBuf(&encoded_subject);
1404 if (buf[0] == '4') {
1405 post_mime_to_server();
1406 if ( (havebstr("recp"))
1407 || (havebstr("cc" ))
1408 || (havebstr("bcc" ))
1410 sprintf(WCC->ImportantMessage, _("Message has been sent.\n"));
1413 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
1415 dont_post = lbstr("postseq");
1417 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
1418 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1424 DeleteHash(&WCC->attachments);
1427 * We may have been supplied with instructions regarding the location
1428 * to which we must return after posting. If found, go there.
1430 if (havebstr("return_to")) {
1431 http_redirect(bstr("return_to"));
1434 * If we were editing a page in a wiki room, go to that page now.
1436 else if (havebstr("wikipage")) {
1437 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
1441 * Otherwise, just go to the "read messages" loop.
1452 * \brief display the message entry screen
1454 void display_enter(void)
1458 const StrBuf *display_name = NULL;
1459 int recipient_required = 0;
1460 int subject_required = 0;
1461 int recipient_bad = 0;
1462 int is_anonymous = 0;
1463 wcsession *WCC = WC;
1467 if (havebstr("force_room")) {
1468 gotoroom(sbstr("force_room"));
1471 display_name = sbstr("display_name");
1472 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
1473 display_name = NULL;
1477 /** First test to see whether this is a room that requires recipients to be entered */
1478 serv_puts("ENT0 0");
1479 serv_getln(buf, sizeof buf);
1481 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
1482 recipient_required = 1;
1484 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
1485 sprintf(WCC->ImportantMessage, "%s", &buf[4]);
1490 /* Is the server strongly recommending that the user enter a message subject? */
1491 if ((buf[3] != '\0') && (buf[4] != '\0')) {
1492 subject_required = extract_int(&buf[4], 1);
1496 * Are we perhaps in an address book view? If so, then an "enter
1497 * message" command really means "add new entry."
1499 if (WCC->wc_default_view == VIEW_ADDRESSBOOK) {
1500 do_edit_vcard(-1, "", NULL, NULL, "", ChrPtr(WCC->wc_roomname));
1505 * Are we perhaps in a calendar room? If so, then an "enter
1506 * message" command really means "add new calendar item."
1508 if (WCC->wc_default_view == VIEW_CALENDAR) {
1509 display_edit_event();
1514 * Are we perhaps in a tasks view? If so, then an "enter
1515 * message" command really means "add new task."
1517 if (WCC->wc_default_view == VIEW_TASKS) {
1518 display_edit_task();
1523 * Otherwise proceed normally.
1524 * Do a custom room banner with no navbar...
1527 if (recipient_required) {
1528 const StrBuf *Recp = NULL;
1529 const StrBuf *Cc = NULL;
1530 const StrBuf *Bcc = NULL;
1531 const StrBuf *Wikipage = NULL;
1532 StrBuf *CmdBuf = NULL;
1533 const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
1535 Recp = sbstr("recp");
1538 Wikipage = sbstr("wikipage");
1540 CmdBuf = NewStrBufPlain(NULL,
1543 StrLength(display_name) +
1546 StrLength(Wikipage));
1548 StrBufPrintf(CmdBuf,
1552 ChrPtr(display_name),
1556 serv_puts(ChrPtr(CmdBuf));
1557 serv_getln(buf, sizeof buf);
1558 FreeStrBuf(&CmdBuf);
1560 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
1561 if (havebstr("recp") &&
1567 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
1568 wprintf("<em>%s</em><br />\n", &buf[4]);/*TODO -> important message */
1572 svputlong("RCPTREQUIRED", recipient_required);
1573 svputlong("SUBJREQUIRED", recipient_required || subject_required);
1576 output_headers(1, 0, 0, 0, 1, 0);
1577 DoTemplate(HKEY("edit_message"), NULL, &NoCtx);
1584 * \brief delete a message
1586 void delete_msg(void)
1591 msgid = lbstr("msgid");
1593 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
1594 serv_printf("DELE %ld", msgid);
1596 else { /** Otherwise move it to Trash */
1597 serv_printf("MOVE %ld|_TRASH_|0", msgid);
1600 serv_getln(buf, sizeof buf);
1601 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1608 * \brief move a message to another folder
1615 msgid = lbstr("msgid");
1617 if (havebstr("move_button")) {
1618 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
1620 serv_getln(buf, sizeof buf);
1621 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1623 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
1634 * Confirm move of a message
1636 void confirm_move_msg(void)
1642 msgid = lbstr("msgid");
1645 output_headers(1, 1, 2, 0, 0, 0);
1646 wprintf("<div id=\"banner\">\n");
1648 wprintf(_("Confirm move of message"));
1650 wprintf("</div>\n");
1652 wprintf("<div id=\"content\" class=\"service\">\n");
1654 wprintf("<CENTER>");
1656 wprintf(_("Move this message to:"));
1657 wprintf("<br />\n");
1659 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
1660 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1661 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
1663 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
1665 serv_getln(buf, sizeof buf);
1666 if (buf[0] == '1') {
1667 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1668 extract_token(targ, buf, 0, '|', sizeof targ);
1669 wprintf("<OPTION>");
1674 wprintf("</SELECT>\n");
1675 wprintf("<br />\n");
1677 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
1679 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
1680 wprintf("</form></CENTER>\n");
1682 wprintf("</CENTER>\n");
1688 * Generic function to output an arbitrary MIME attachment from
1689 * message being composed
1691 * partnum The MIME part to be output
1692 * filename Fake filename to give
1693 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
1695 void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
1698 StrBuf *content_type;
1699 wc_mime_attachment *part;
1701 if (GetHash(WC->attachments, SKEY(partnum), &vPart) &&
1703 part = (wc_mime_attachment*) vPart;
1704 if (force_download) {
1705 content_type = NewStrBufPlain(HKEY("application/octet-stream"));
1708 content_type = NewStrBufDup(part->ContentType);
1710 StrBufAppendBuf(WC->WBuf, part->Data, 0);
1711 http_transmit_thing(ChrPtr(content_type), 0);
1713 hprintf("HTTP/1.1 404 %s\n", ChrPtr(partnum));
1714 output_headers(0, 0, 0, 0, 0, 0);
1715 hprintf("Content-Type: text/plain\r\n");
1716 wprintf(_("An error occurred while retrieving this part: %s/%s\n"),
1717 ChrPtr(partnum), ChrPtr(filename));
1720 FreeStrBuf(&content_type);
1725 * Generic function to output an arbitrary MIME part from an arbitrary
1726 * message number on the server.
1728 * msgnum Number of the item on the citadel server
1729 * partnum The MIME part to be output
1730 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
1732 void mimepart(int force_download)
1735 wcsession *WCC = WC;
1738 StrBuf *ContentType = NewStrBufPlain(HKEY("application/octet-stream"));
1741 msgnum = StrBufExtract_long(WCC->Hdr->ReqLine, 2, '/');
1742 att = StrBufExtract_long(WCC->Hdr->ReqLine, 3, '/');
1745 serv_printf("OPNA %ld|%ld", msgnum, att);
1746 StrBuf_ServGetln(Buf);
1747 if (GetServerStatus(Buf, NULL) == 2) {
1748 StrBufCutLeft(Buf, 4);
1749 bytes = StrBufExtract_long(Buf, 0, '|');
1750 if (!force_download) {
1751 StrBufExtract_token(ContentType, Buf, 3, '|');
1754 read_server_binary(WCC->WBuf, bytes, Buf);
1756 StrBuf_ServGetln(Buf);
1757 CT = ChrPtr(ContentType);
1759 if (!force_download) {
1760 if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
1761 StrBufExtract_token(Buf, WCC->Hdr->ReqLine, 4, '/');
1762 CT = GuessMimeByFilename(SKEY(Buf));
1764 if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
1765 CT = GuessMimeType(SKEY(WCC->WBuf));
1768 http_transmit_thing(CT, 0);
1770 StrBufCutLeft(Buf, 4);
1771 hprintf("HTTP/1.1 404 %s\n", ChrPtr(Buf));
1772 output_headers(0, 0, 0, 0, 0, 0);
1773 hprintf("Content-Type: text/plain\r\n");
1774 wprintf(_("An error occurred while retrieving this part: %s\n"),
1778 FreeStrBuf(&ContentType);
1784 * Read any MIME part of a message, from the server, into memory.
1786 StrBuf *load_mimepart(long msgnum, char *partnum)
1792 serv_printf("DLAT %ld|%s", msgnum, partnum);
1793 StrBuf_ServGetln(Buf);
1794 if (GetServerStatus(Buf, NULL) == 6) {
1795 StrBufCutLeft(Buf, 4);
1796 bytes = StrBufExtract_long(Buf, 0, '|');
1799 StrBuf_ServGetBLOBBuffered(Buf, bytes);
1809 * Read any MIME part of a message, from the server, into memory.
1811 void MimeLoadData(wc_mime_attachment *Mime)
1815 /* TODO: is there a chance the contenttype is different to the one we know? */
1816 serv_printf("DLAT %ld|%s", Mime->msgnum, ChrPtr(Mime->PartNum));
1818 StrBuf_ServGetln(Buf);
1819 if (GetServerStatus(Buf, NULL) == 6) {
1820 bytes = extract_long(&(ChrPtr(Buf)[4]), 0);
1822 if (Mime->Data == NULL)
1823 Mime->Data = NewStrBufPlain(NULL, bytes);
1824 StrBuf_ServGetBLOBBuffered(Mime->Data, bytes);
1827 FlushStrBuf(Mime->Data);
1828 /* TODO XImportant message */
1836 void view_mimepart(void) {
1840 void download_mimepart(void) {
1844 void view_postpart(void) {
1845 StrBuf *filename = NewStrBuf();
1846 StrBuf *partnum = NewStrBuf();
1848 StrBufExtract_token(partnum, WC->Hdr->ReqLine, 2, '/');
1849 StrBufExtract_token(filename, WC->Hdr->ReqLine, 3, '/');
1851 postpart(partnum, filename, 0);
1853 FreeStrBuf(&filename);
1854 FreeStrBuf(&partnum);
1857 void download_postpart(void) {
1858 StrBuf *filename = NewStrBuf();
1859 StrBuf *partnum = NewStrBuf();
1861 StrBufExtract_token(partnum, WC->Hdr->ReqLine, 2, '/');
1862 StrBufExtract_token(filename, WC->Hdr->ReqLine, 3, '/');
1864 postpart(partnum, filename, 1);
1866 FreeStrBuf(&filename);
1867 FreeStrBuf(&partnum);
1870 void h_readnew(void) { readloop(readnew);}
1871 void h_readold(void) { readloop(readold);}
1872 void h_readfwd(void) { readloop(readfwd);}
1873 void h_headers(void) { readloop(headers);}
1874 void h_do_search(void) { readloop(do_search);}
1876 void jsonMessageListHdr(void)
1878 /* TODO: make a generic function */
1879 hprintf("HTTP/1.1 200 OK\r\n");
1880 hprintf("Content-type: application/json; charset=utf-8\r\n");
1881 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
1882 hprintf("Connection: close\r\n");
1883 hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
1886 /* Spit out the new summary view. This is basically a static page, so clients can cache the layout, all the dirty work is javascript :) */
1887 void new_summary_view(void) {
1889 DoTemplate(HKEY("msg_listview"),NULL,&NoCtx);
1890 DoTemplate(HKEY("trailing"),NULL,&NoCtx);
1893 /** Output message list in JSON-format */
1894 void jsonMessageList(void) {
1895 const StrBuf *room = sbstr("room");
1896 long oper = (havebstr("query")) ? do_search : readnew;
1907 RegisterPreference("use_sig",
1908 _("Attach signature to email messages?"),
1911 RegisterPreference("signature", _("Use this signature:"), PRF_QP_STRING, NULL);
1912 RegisterPreference("default_header_charset",
1913 _("Default character set for email headers:"),
1916 RegisterPreference("defaultfrom", _("Preferred email address"), PRF_STRING, NULL);
1917 RegisterPreference("defaultname",
1918 _("Preferred display name for email messages"),
1921 RegisterPreference("defaulthandle",
1922 _("Preferred display name for bulletin board posts"),
1925 RegisterPreference("mailbox",_("Mailbox view mode"), PRF_STRING, NULL);
1927 WebcitAddUrlHandler(HKEY("readnew"), h_readnew, NEED_URL);
1928 WebcitAddUrlHandler(HKEY("readold"), h_readold, NEED_URL);
1929 WebcitAddUrlHandler(HKEY("readfwd"), h_readfwd, NEED_URL);
1930 WebcitAddUrlHandler(HKEY("headers"), h_headers, NEED_URL);
1931 WebcitAddUrlHandler(HKEY("do_search"), h_do_search, 0);
1932 WebcitAddUrlHandler(HKEY("display_enter"), display_enter, 0);
1933 WebcitAddUrlHandler(HKEY("post"), post_message, 0);
1934 WebcitAddUrlHandler(HKEY("move_msg"), move_msg, 0);
1935 WebcitAddUrlHandler(HKEY("delete_msg"), delete_msg, 0);
1936 WebcitAddUrlHandler(HKEY("confirm_move_msg"), confirm_move_msg, 0);
1937 WebcitAddUrlHandler(HKEY("msg"), embed_message, NEED_URL);
1938 WebcitAddUrlHandler(HKEY("message"), handle_one_message, NEED_URL|XHTTP_COMMANDS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
1939 WebcitAddUrlHandler(HKEY("printmsg"), print_message, NEED_URL);
1940 WebcitAddUrlHandler(HKEY("mobilemsg"), mobile_message_view, NEED_URL);
1941 WebcitAddUrlHandler(HKEY("msgheaders"), display_headers, NEED_URL);
1943 WebcitAddUrlHandler(HKEY("mimepart"), view_mimepart, NEED_URL);
1944 WebcitAddUrlHandler(HKEY("mimepart_download"), download_mimepart, NEED_URL);
1945 WebcitAddUrlHandler(HKEY("postpart"), view_postpart, NEED_URL);
1946 WebcitAddUrlHandler(HKEY("postpart_download"), download_postpart, NEED_URL);
1949 WebcitAddUrlHandler(HKEY("roommsgs"), jsonMessageList,0);
1954 SessionDetachModule_MSG
1957 DeleteHash(&sess->summ);