2 * Functions which deal with the fetching and displaying of messages.
4 * Copyright (c) 1996-2011 by the citadel.org team
6 * This program is open source software. You can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "webserver.h"
25 HashList *MsgHeaderHandler = NULL;
26 HashList *MsgEvaluators = NULL;
27 HashList *MimeRenderHandler = NULL;
28 HashList *ReadLoopHandler = NULL;
29 int dbg_analyze_msg = 0;
31 #define SUBJ_COL_WIDTH_PCT 50 /* Mailbox view column width */
32 #define SENDER_COL_WIDTH_PCT 30 /* Mailbox view column width */
33 #define DATE_PLUS_BUTTONS_WIDTH_PCT 20 /* Mailbox view column width */
35 void jsonMessageListHdr(void);
37 void display_enter(void);
39 typedef void (*MsgPartEvaluatorFunc)(message_summary *Sum, StrBuf *Buf);
41 typedef struct _MsgPartEvaluatorStruct {
42 MsgPartEvaluatorFunc f;
43 } MsgPartEvaluatorStruct;
45 int load_message(message_summary *Msg,
59 if (Msg->PartNum != NULL) {
60 serv_printf("MSG4 %ld|%s", Msg->msgnum, ChrPtr(Msg->PartNum));
63 serv_printf("MSG4 %ld", Msg->msgnum);
66 StrBuf_ServGetln(Buf);
67 if (GetServerStatus(Buf, NULL) != 1) {
69 StrBufAppendPrintf(*Error, "<strong>");
70 StrBufAppendPrintf(*Error, _("ERROR:"));
71 StrBufAppendPrintf(*Error, "</strong> %s<br>\n", &buf[4]);
76 /* begin everythingamundo table */
77 HdrToken = NewStrBuf();
78 while (!Done && StrBuf_ServGetln(Buf)>=0) {
79 if ( (StrLength(Buf)==3) &&
80 !strcmp(ChrPtr(Buf), "000"))
84 if (Msg->MsgBody->Data == NULL)
85 Msg->MsgBody->Data = NewStrBuf();
86 Msg->MsgBody->ContentType = NewStrBufPlain(HKEY("text/html"));
87 StrBufAppendPrintf(Msg->MsgBody->Data, "<div><i>");
88 StrBufAppendPrintf(Msg->MsgBody->Data, _("Empty message"));
89 StrBufAppendPrintf(Msg->MsgBody->Data, "</i><br><br>\n");
90 StrBufAppendPrintf(Msg->MsgBody->Data, "</div>\n");
95 case 0:/* Citadel Message Headers */
96 if (StrLength(Buf) == 0) {
100 StrBufExtract_token(HdrToken, Buf, 0, '=');
101 StrBufCutLeft(Buf, StrLength(HdrToken) + 1);
104 if (dbg_analyze_msg) lprintf(1, ":: [%s] = [%s]\n", ChrPtr(HdrToken), ChrPtr(Buf));
106 /* look up one of the examine_* functions to parse the content */
107 if (GetHash(MsgHeaderHandler, SKEY(HdrToken), &vHdr) &&
109 Hdr = (headereval*)vHdr;
110 Hdr->evaluator(Msg, Buf, FoundCharset);
111 if (Hdr->Type == 1) {
115 else LogError(Target,
117 "don't know how to handle message header[%s]\n",
121 case 1:/* Message Mime Header */
122 if (StrLength(Buf) == 0) {
124 if (Msg->MsgBody->ContentType == NULL)
125 /* end of header or no header? */
126 Msg->MsgBody->ContentType = NewStrBufPlain(HKEY("text/plain"));
127 /* usual end of mime header */
131 StrBufExtract_token(HdrToken, Buf, 0, ':');
132 if (StrLength(HdrToken) > 0) {
133 StrBufCutLeft(Buf, StrLength(HdrToken) + 1);
135 if (dbg_analyze_msg) lprintf(1, ":: [%s] = [%s]\n", ChrPtr(HdrToken), ChrPtr(Buf));
137 /* the examine*'s know how to do with mime headers too... */
138 if (GetHash(MsgHeaderHandler, SKEY(HdrToken), &vHdr) &&
140 Hdr = (headereval*)vHdr;
141 Hdr->evaluator(Msg, Buf, FoundCharset);
146 case 2: /* Message Body */
148 if (Msg->MsgBody->size_known > 0) {
149 StrBuf_ServGetBLOBBuffered(Msg->MsgBody->Data, Msg->MsgBody->length);
151 /*/ todo: check next line, if not 000, append following lines */
154 if (StrLength(Msg->MsgBody->Data) > 0)
155 StrBufAppendBufPlain(Msg->MsgBody->Data, "\n", 1, 0);
156 StrBufAppendBuf(Msg->MsgBody->Data, Buf, 0);
160 StrBufAppendBuf(Msg->MsgBody->Data, Buf, 0);
165 if (Msg->AllAttach == NULL)
166 Msg->AllAttach = NewHash(1,NULL);
167 /* now we put the body mimepart we read above into the mimelist */
168 Put(Msg->AllAttach, SKEY(Msg->MsgBody->PartNum), Msg->MsgBody, DestroyMime);
170 /* Generate a reply-to address */
171 if (StrLength(Msg->Rfca) > 0) {
172 if (Msg->reply_to == NULL)
173 Msg->reply_to = NewStrBuf();
174 if (StrLength(Msg->from) > 0) {
175 StrBufPrintf(Msg->reply_to, "%s <%s>", ChrPtr(Msg->from), ChrPtr(Msg->Rfca));
178 FlushStrBuf(Msg->reply_to);
179 StrBufAppendBuf(Msg->reply_to, Msg->Rfca, 0);
184 if ((StrLength(Msg->OtherNode)>0) &&
185 (strcasecmp(ChrPtr(Msg->OtherNode), ChrPtr(WCC->serv_info->serv_nodename))) &&
186 (strcasecmp(ChrPtr(Msg->OtherNode), ChrPtr(WCC->serv_info->serv_humannode)) ))
188 if (Msg->reply_to == NULL)
189 Msg->reply_to = NewStrBuf();
190 StrBufPrintf(Msg->reply_to,
193 ChrPtr(Msg->OtherNode));
196 if (Msg->reply_to == NULL)
197 Msg->reply_to = NewStrBuf();
198 FlushStrBuf(Msg->reply_to);
199 StrBufAppendBuf(Msg->reply_to, Msg->from, 0);
203 FreeStrBuf(&HdrToken);
210 * I wanna SEE that message!
212 * msgnum Message number to display
213 * printable_view Nonzero to display a printable view
214 * section Optional for encapsulated message/rfc822 submessage
216 int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, const StrBuf *PartNum, const StrBuf **OutMime)
219 StrBuf *FoundCharset;
222 message_summary *Msg = NULL;
226 WCTemplputParams SubTP;
227 StrBuf *Error = NULL;
230 FoundCharset = NewStrBuf();
231 Msg = (message_summary *)malloc(sizeof(message_summary));
232 memset(Msg, 0, sizeof(message_summary));
233 Msg->msgnum = msgnum;
234 Msg->PartNum = PartNum;
235 Msg->MsgBody = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
236 memset(Msg->MsgBody, 0, sizeof(wc_mime_attachment));
237 Msg->MsgBody->msgnum = msgnum;
239 if (!load_message(Msg, FoundCharset, &Error)) {
240 StrBufAppendBuf(Target, Error, 0);
244 /* Extract just the content-type (omit attributes such as "charset") */
245 StrBufExtract_token(Buf, Msg->MsgBody->ContentType, 0, ';');
247 StrBufLowerCase(Buf);
249 /* Locate a renderer capable of converting this MIME part into HTML */
250 if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
252 RenderMimeFuncStruct *Render;
253 Render = (RenderMimeFuncStruct*)vHdr;
254 Render->f(Msg->MsgBody, NULL, FoundCharset);
257 if (StrLength(Msg->reply_references)> 0) {
258 /* Trim down excessively long lists of thread references. We eliminate the
259 * second one in the list so that the thread root remains intact.
261 int rrtok = num_tokens(ChrPtr(Msg->reply_references), '|');
262 int rrlen = StrLength(Msg->reply_references);
263 if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
264 StrBufRemove_token(Msg->reply_references, 1, '|');
268 /* now check if we need to translate some mimeparts, and remove the duplicate */
269 it = GetNewHashPos(Msg->AllAttach, 0);
270 while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) &&
272 wc_mime_attachment *Mime = (wc_mime_attachment*) vMime;
273 evaluate_mime_part(Msg, Mime);
276 memset(&SubTP, 0, sizeof(WCTemplputParams));
277 SubTP.Filter.ContextType = CTX_MAILSUM;
279 *OutMime = DoTemplate(tmpl, tmpllen, Target, &SubTP);
281 DestroyMessageSummary(Msg);
282 FreeStrBuf(&FoundCharset);
289 HttpStatus(long CitadelStatus)
291 long httpstatus = 502;
293 switch (MAJORCODE(CitadelStatus))
295 case LISTING_FOLLOWS:
300 switch (MINORCODE(CitadelStatus))
308 case HIGHER_ACCESS_REQUIRED:
309 case MAX_SESSIONS_EXCEEDED:
311 case RESOURCE_NOT_OPEN:
313 case INVALID_FLOOR_OPERATION:
319 case MESSAGE_NOT_FOUND:
329 case CMD_NOT_SUPPORTED:
330 case PASSWORD_REQUIRED:
331 case ALREADY_LOGGED_IN:
332 case USERNAME_REQUIRED:
334 case SERVER_SHUTTING_DOWN:
345 case START_CHAT_MODE:
349 httpstatus = 502; /* aeh... whut? */
357 * Unadorned HTML output of an individual message, suitable
358 * for placing in a hidden iframe, for printing, or whatever
360 void handle_one_message(void)
364 const StrBuf *Destination;
370 StrBuf *CmdBuf = NULL;
374 pMsg = strchr(ChrPtr(WCC->Hdr->HR.ReqLine), '/');
376 HttpStatus(CitStatus);
380 msgnum = atol(pMsg + 1);
381 StrBufCutAt(WCC->Hdr->HR.ReqLine, 0, pMsg);
382 gotoroom(WCC->Hdr->HR.ReqLine);
383 switch (WCC->Hdr->HR.eReqType)
387 Tmpl = sbstr("template");
388 if (StrLength(Tmpl) > 0)
389 read_message(WCC->WBuf, SKEY(Tmpl), msgnum, NULL, &Mime);
391 read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
392 http_transmit_thing(ChrPtr(Mime), 0);
395 CmdBuf = NewStrBuf ();
396 if ((WCC->CurRoom.RAFlags & UA_ISTRASH) != 0) { /* Delete from Trash is a real delete */
397 serv_printf("DELE %ld", msgnum);
399 else { /* Otherwise move it to Trash */
400 serv_printf("MOVE %ld|_TRASH_|0", msgnum);
402 StrBuf_ServGetln(CmdBuf);
403 FlushStrBuf(WCC->ImportantMsg);
404 StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
405 GetServerStatus(CmdBuf, &CitStatus);
406 HttpStatus(CitStatus);
411 if (GetHash(WCC->Hdr->HTTPHeaders, HKEY("DESTINATION"), &vLine) &&
413 Destination = (StrBuf*) vLine;
414 serv_printf("MOVE %ld|%s|%d", msgnum, ChrPtr(Destination), CopyMessage);
415 StrBuf_ServGetln(CmdBuf);
416 FlushStrBuf(WCC->ImportantMsg);
417 StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
418 GetServerStatus(CmdBuf, &CitStatus);
419 HttpStatus(CitStatus);
432 * Unadorned HTML output of an individual message, suitable
433 * for placing in a hidden iframe, for printing, or whatever
435 void embed_message(void) {
440 StrBuf *CmdBuf = NULL;
442 msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/');
443 switch (WCC->Hdr->HR.eReqType)
447 Tmpl = sbstr("template");
448 if (StrLength(Tmpl) > 0)
449 read_message(WCC->WBuf, SKEY(Tmpl), msgnum, NULL, &Mime);
451 read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
452 http_transmit_thing(ChrPtr(Mime), 0);
455 CmdBuf = NewStrBuf ();
456 if ((WCC->CurRoom.RAFlags & UA_ISTRASH) != 0) { /* Delete from Trash is a real delete */
457 serv_printf("DELE %ld", msgnum);
459 else { /* Otherwise move it to Trash */
460 serv_printf("MOVE %ld|_TRASH_|0", msgnum);
462 StrBuf_ServGetln(CmdBuf);
463 FlushStrBuf(WCC->ImportantMsg);
464 StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
474 * Printable view of a message
476 void print_message(void) {
480 msgnum = StrBufExtract_long(WC->Hdr->HR.ReqLine, 0, '/');
481 output_headers(0, 0, 0, 0, 0, 0);
483 hprintf("Content-type: text/html\r\n"
484 "Server: " PACKAGE_STRING "\r\n"
485 "Connection: close\r\n");
489 read_message(WC->WBuf, HKEY("view_message_print"), msgnum, NULL, &Mime);
495 * Mobile browser view of message
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 * Display a message's headers
513 void display_headers(void) {
517 msgnum = StrBufExtract_long(WC->Hdr->HR.ReqLine, 0, '/');
518 output_headers(0, 0, 0, 0, 0, 0);
520 hprintf("Content-type: text/plain\r\n"
522 "Connection: close\r\n",
526 serv_printf("MSG2 %ld|3", msgnum);
527 serv_getln(buf, sizeof buf);
529 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
530 wc_printf("%s\n", buf);
538 message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSubject, long MsgNum)
541 MsgPartEvaluatorStruct *Eval;
542 message_summary *Msg;
551 serv_printf("MSG0 %ld|1", MsgNum); /* ask for headers only */
553 StrBuf_ServGetln(Buf);
554 if (GetServerStatus(Buf, NULL) == 1) {
559 Msg = (message_summary*)malloc(sizeof(message_summary));
560 memset(Msg, 0, sizeof(message_summary));
561 while (len = StrBuf_ServGetln(Buf),
563 strcmp(ChrPtr(Buf), "000")== 0)){
565 ebuf = strchr(ChrPtr(Buf), '=');
567 if (GetHash(MsgEvaluators, buf, nBuf, &vEval) && vEval != NULL) {
568 Eval = (MsgPartEvaluatorStruct*) vEval;
569 StrBufCutLeft(Buf, nBuf + 1);
572 else lprintf(1, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
582 * load message pointers from the server for a "read messages" operation
584 * servcmd: the citadel command to send to the citserver
586 int load_msg_ptrs(const char *servcmd,
587 SharedMessageStatus *Stat,
588 load_msg_ptrs_detailheaders LH)
591 message_summary *Msg;
596 const char *Ptr = NULL;
598 Stat->lowest_found = LONG_MAX;
599 Stat->highest_found = LONG_MIN;
601 if (WCC->summ != NULL) {
602 DeleteHash(&WCC->summ);
604 WCC->summ = NewHash(1, Flathash);
608 StrBuf_ServGetln(Buf);
609 if (GetServerStatus(Buf, NULL) != 1) {
611 return (Stat->nummsgs);
614 while (len = StrBuf_ServGetln(Buf), ((len != 3) || strcmp(ChrPtr(Buf), "000")!= 0))
616 if (Stat->nummsgs < Stat->maxload) {
619 Msg = (message_summary*)malloc(sizeof(message_summary));
620 memset(Msg, 0, sizeof(message_summary));
622 Msg->msgnum = StrBufExtractNext_long(Buf, &Ptr, '|');
623 Msg->date = StrBufExtractNext_long(Buf, &Ptr, '|');
625 if (Stat->nummsgs == 0) {
626 if (Msg->msgnum < Stat->lowest_found) {
627 Stat->lowest_found = Msg->msgnum;
629 if (Msg->msgnum > Stat->highest_found) {
630 Stat->highest_found = Msg->msgnum;
634 if ((Msg->msgnum == 0) && (StrLength(Buf) < 32)) {
640 * as citserver probably gives us messages in forward date sorting
641 * nummsgs should be the same order as the message date.
643 if (Msg->date == 0) {
644 Msg->date = Stat->nummsgs;
645 if (StrLength(Buf) < 32)
648 if ((!skipit) && (LH != NULL)) {
649 if (!LH(Buf, &Ptr, Msg, Buf2)){
655 Put(WCC->summ, (const char *)&n, sizeof(n), Msg, DestroyMessageSummary);
661 return (Stat->nummsgs);
667 * \brief sets FlagToSet for each of ScanMe that appears in MatchMSet
668 * \param ScanMe List of BasicMsgStruct to be searched it MatchSet
669 * \param MatchMSet MSet we want to flag
670 * \param FlagToSet Flag to set on each BasicMsgStruct->Flags if in MSet
672 void SetFlagsFromMSet(HashList *ScanMe, MSet *MatchMSet, int FlagToSet, int Reverse)
678 message_summary *Msg;
680 at = GetNewHashPos(ScanMe, 0);
681 while (GetNextHashPos(ScanMe, at, &HKLen, &HashKey, &vMsg)) {
682 /* Are you a new message, or an old message? */
683 Msg = (message_summary*) vMsg;
684 if (Reverse && IsInMSetList(MatchMSet, Msg->msgnum)) {
685 Msg->Flags = Msg->Flags | FlagToSet;
687 else if (!Reverse && !IsInMSetList(MatchMSet, Msg->msgnum)) {
688 Msg->Flags = Msg->Flags | FlagToSet;
695 void load_seen_flags(void)
701 OldMsg = NewStrBuf();
703 StrBuf_ServGetln(OldMsg);
704 if (GetServerStatus(OldMsg, NULL) == 2) {
705 StrBufCutLeft(OldMsg, 4);
712 if (ParseMSet(&MatchMSet, OldMsg))
714 SetFlagsFromMSet(WCC->summ, MatchMSet, MSGFLAG_READ, 0);
716 DeleteMSet(&MatchMSet);
720 extern readloop_struct rlid[];
722 typedef struct _RoomRenderer{
725 GetParamsGetServerCall_func GetParamsGetServerCall;
726 PrintViewHeader_func PrintViewHeader;
727 LoadMsgFromServer_func LoadMsgFromServer;
728 RenderView_or_Tail_func RenderView_or_Tail;
729 View_Cleanup_func ViewCleanup;
730 load_msg_ptrs_detailheaders LHParse;
735 * command loop for reading messages
737 * Set oper to "readnew" or "readold" or "readfwd" or "headers" or "readgt" or "readlt" or "do_search"
739 void readloop(long oper, eCustomRoomRenderer ForceRenderer)
741 RoomRenderer *ViewMsg;
744 message_summary *Msg;
751 WCTemplputParams SubTP;
752 SharedMessageStatus Stat;
755 if (havebstr("is_summary") && (1 == (ibstr("is_summary")))) {
756 WCC->CurRoom.view = VIEW_MAILBOX;
759 if (havebstr("is_ajax") && (1 == (ibstr("is_ajax")))) {
763 if ((oper == do_search) && (WCC->CurRoom.view == VIEW_WIKI)) {
764 display_wiki_pagelist();
768 if (WCC->CurRoom.view == VIEW_WIKI) {
769 http_redirect("wiki?page=home");
773 memset(&Stat, 0, sizeof(SharedMessageStatus));
774 Stat.maxload = 10000;
775 Stat.lowest_found = (-1);
776 Stat.highest_found = (-1);
777 if (ForceRenderer == eUseDefault)
778 GetHash(ReadLoopHandler, IKEY(WCC->CurRoom.view), &vViewMsg);
780 GetHash(ReadLoopHandler, IKEY(ForceRenderer), &vViewMsg);
781 if (vViewMsg == NULL) {
782 WCC->CurRoom.view = VIEW_BBS;
783 GetHash(ReadLoopHandler, IKEY(WCC->CurRoom.view), &vViewMsg);
785 if (vViewMsg == NULL) {
786 return; // TODO: print message
789 ViewMsg = (RoomRenderer*) vViewMsg;
791 output_headers(1, 1, 1, 0, 0, 0);
792 } else if (WCC->CurRoom.view == VIEW_MAILBOX) {
793 jsonMessageListHdr();
796 if (ViewMsg->GetParamsGetServerCall != NULL) {
797 r = ViewMsg->GetParamsGetServerCall(
812 case 300: /* the callback hook should do the work for us here, since he knows what to do. */
818 if (!IsEmptyStr(cmd))
819 Stat.nummsgs = load_msg_ptrs(cmd, &Stat, ViewMsg->LHParse);
823 memset(&SubTP, 0, sizeof(WCTemplputParams));
824 SubTP.Filter.ContextType = CTX_MAILSUM;
825 SubTP.Context = NULL;
826 SortIt = RetrieveSort(&SubTP, NULL, 0,
827 HKEY("date"), Stat.defaultsortorder);
829 SortByPayload(WCC->summ, SortIt);
831 if (Stat.startmsg < 0) {
835 if (Stat.load_seen) load_seen_flags();
838 * Print any inforation above the message list...
840 if (ViewMsg->PrintViewHeader != NULL)
841 ViewMsg->PrintViewHeader(&Stat, &ViewSpecific);
843 WCC->startmsg = Stat.startmsg;
844 WCC->maxmsgs = Stat.maxmsgs;
845 WCC->num_displayed = 0;
847 /* Put some helpful data in vars for mailsummary_json */
852 StrBufPrintf(Foo, "%ld", Stat.nummsgs);
853 PutBstr(HKEY("__READLOOP:TOTALMSGS"), NewStrBufDup(Foo));
854 StrBufPrintf(Foo, "%ld", Stat.startmsg);
855 PutBstr(HKEY("__READLOOP:STARTMSG"), Foo);
859 * iterate over each message. if we need to load an attachment, do it here.
862 if ((ViewMsg->LoadMsgFromServer != NULL) &&
865 at = GetNewHashPos(WCC->summ, 0);
866 Stat.num_displayed = i = 0;
867 while ( GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
868 Msg = (message_summary*) vMsg;
869 if ((Msg->msgnum >= Stat.startmsg) && (Stat.num_displayed <= Stat.maxmsgs)) {
870 ViewMsg->LoadMsgFromServer(&Stat,
873 (Msg->Flags & MSGFLAG_READ) != 0,
882 * Done iterating the message list. now tasks we want to do after.
884 if (ViewMsg->RenderView_or_Tail != NULL)
885 ViewMsg->RenderView_or_Tail(&Stat, &ViewSpecific, oper);
887 if (ViewMsg->ViewCleanup != NULL)
888 ViewMsg->ViewCleanup(&ViewSpecific);
892 if (WCC->summ != NULL) {
893 DeleteHash(&WCC->summ);
899 * Back end for post_message()
900 * ... this is where the actual message gets transmitted to the server.
902 void post_mime_to_server(void) {
904 char top_boundary[SIZ];
905 char alt_boundary[SIZ];
906 int is_multipart = 0;
908 wc_mime_attachment *att;
910 size_t encoded_length;
911 size_t encoded_strlen;
912 char *txtmail = NULL;
913 int include_text_alt = 0; /* Set to nonzero to include multipart/alternative text/plain */
915 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
916 ChrPtr(WCC->serv_info->serv_fqdn),
920 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
921 ChrPtr(WCC->serv_info->serv_fqdn),
926 /* RFC2045 requires this, and some clients look for it... */
927 serv_puts("MIME-Version: 1.0");
928 serv_puts("X-Mailer: " PACKAGE_STRING);
930 /* If there are attachments, we have to do multipart/mixed */
931 if (GetCount(WCC->attachments) > 0) {
935 /* Only do multipart/alternative for mailboxes. BBS and Wiki rooms don't need it. */
936 if (WC->CurRoom.view == VIEW_MAILBOX) {
937 include_text_alt = 1;
941 /* Remember, serv_printf() appends an extra newline */
942 serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
943 serv_printf("This is a multipart message in MIME format.\n");
944 serv_printf("--%s", top_boundary);
947 /* Remember, serv_printf() appends an extra newline */
948 if (include_text_alt) {
949 serv_printf("Content-type: multipart/alternative; "
950 "boundary=\"%s\"\n", alt_boundary);
951 serv_printf("This is a multipart message in MIME format.\n");
952 serv_printf("--%s", alt_boundary);
954 serv_puts("Content-type: text/plain; charset=utf-8");
955 serv_puts("Content-Transfer-Encoding: quoted-printable");
957 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
958 text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */
961 serv_printf("--%s", alt_boundary);
964 serv_puts("Content-type: text/html; charset=utf-8");
965 serv_puts("Content-Transfer-Encoding: quoted-printable");
967 serv_puts("<html><body>\r\n");
968 text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */
969 serv_puts("</body></html>\r\n");
971 if (include_text_alt) {
972 serv_printf("--%s--", alt_boundary);
981 /* Add in the attachments */
982 it = GetNewHashPos(WCC->attachments, 0);
983 while (GetNextHashPos(WCC->attachments, it, &len, &Key, &vAtt)) {
984 att = (wc_mime_attachment *)vAtt;
985 if (att->length == 0)
987 encoded_length = ((att->length * 150) / 100);
988 encoded = malloc(encoded_length);
989 if (encoded == NULL) break;
990 encoded_strlen = CtdlEncodeBase64(encoded, ChrPtr(att->Data), StrLength(att->Data), 1);
992 serv_printf("--%s", top_boundary);
993 serv_printf("Content-type: %s", ChrPtr(att->ContentType));
994 serv_printf("Content-disposition: attachment; filename=\"%s\"", ChrPtr(att->FileName));
995 serv_puts("Content-transfer-encoding: base64");
997 serv_write(encoded, encoded_strlen);
1002 serv_printf("--%s--", top_boundary);
1011 * Post message (or don't post message)
1013 * Note regarding the "dont_post" variable:
1014 * A random value (actually, it's just a timestamp) is inserted as a hidden
1015 * field called "postseq" when the display_enter page is generated. This
1016 * value is checked when posting, using the static variable dont_post. If a
1017 * user attempts to post twice using the same dont_post value, the message is
1018 * discarded. This prevents the accidental double-saving of the same message
1019 * if the user happens to click the browser "back" button.
1021 void post_message(void)
1024 StrBuf *EmailAddress;
1027 StrBuf *encoded_subject = NULL;
1028 static long dont_post = (-1L);
1029 int is_anonymous = 0;
1030 const StrBuf *display_name = NULL;
1031 wcsession *WCC = WC;
1034 if (havebstr("force_room")) {
1035 gotoroom(sbstr("force_room"));
1038 if (havebstr("display_name")) {
1039 display_name = sbstr("display_name");
1040 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
1041 display_name = NULL;
1046 if (!strcasecmp(bstr("submit_action"), "cancel")) {
1047 sprintf(WCC->ImportantMessage,
1048 _("Cancelled. Message was not posted."));
1049 } else if (lbstr("postseq") == dont_post) {
1050 sprintf(WCC->ImportantMessage,
1051 _("Automatically cancelled because you have already "
1052 "saved this message."));
1054 const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s";
1055 StrBuf *Recp = NULL;
1058 const StrBuf *Wikipage = NULL;
1059 const StrBuf *my_email_addr = NULL;
1060 StrBuf *CmdBuf = NULL;
1061 StrBuf *references = NULL;
1065 save_to_drafts = !strcasecmp(bstr("submit_action"), "drafts");
1068 if (save_to_drafts) {
1069 /* temporarily change to the drafts room */
1070 serv_puts("GOTO _DRAFTS_");
1071 StrBuf_ServGetln(Buf);
1072 if (GetServerStatus(Buf, NULL) != 2) {
1073 /* You probably don't even have a dumb Drafts folder */
1074 StrBufCutLeft(Buf, 4);
1075 lprintf(9, "%s:%d: server save to drafts error: %s\n", __FILE__, __LINE__, ChrPtr(Buf));
1076 StrBufAppendBufPlain(WCC->ImportantMsg, _("Saved to Drafts failed: "), -1, 0);
1077 StrBufAppendBuf(WCC->ImportantMsg, Buf, 0);
1084 if (havebstr("references"))
1086 const StrBuf *ref = sbstr("references");
1087 references = NewStrBufDup(ref);
1088 if (*ChrPtr(references) == '|') { /* remove leading '|' if present */
1089 StrBufCutLeft(references, 1);
1091 StrBufReplaceChars(references, '|', '!');
1093 if (havebstr("subject")) {
1096 * make enough room for the encoded string;
1097 * plus the QP header
1099 Subj = sbstr("subject");
1101 StrBufRFC2047encode(&encoded_subject, Subj);
1103 UserName = NewStrBuf();
1104 EmailAddress = NewStrBuf();
1105 EncBuf = NewStrBuf();
1107 Recp = StrBufSanitizeEmailRecipientVector(sbstr("recp"), UserName, EmailAddress, EncBuf);
1108 Cc = StrBufSanitizeEmailRecipientVector(sbstr("cc"), UserName, EmailAddress, EncBuf);
1109 Bcc = StrBufSanitizeEmailRecipientVector(sbstr("bcc"), UserName, EmailAddress, EncBuf);
1111 FreeStrBuf(&UserName);
1112 FreeStrBuf(&EmailAddress);
1113 FreeStrBuf(&EncBuf);
1115 Wikipage = sbstr("page");
1116 my_email_addr = sbstr("my_email_addr");
1118 HeaderLen = StrLength(Recp) +
1119 StrLength(encoded_subject) +
1122 StrLength(Wikipage) +
1123 StrLength(my_email_addr) +
1124 StrLength(references);
1125 CmdBuf = NewStrBufPlain(NULL, sizeof (CMD) + HeaderLen);
1126 StrBufPrintf(CmdBuf,
1128 save_to_drafts?"":ChrPtr(Recp),
1130 ChrPtr(encoded_subject),
1131 ChrPtr(display_name),
1132 save_to_drafts?"":ChrPtr(Cc),
1133 save_to_drafts?"":ChrPtr(Bcc),
1135 ChrPtr(my_email_addr),
1136 ChrPtr(references));
1137 FreeStrBuf(&references);
1138 FreeStrBuf(&encoded_subject);
1140 if ((HeaderLen + StrLength(sbstr("msgtext")) < 10) &&
1141 (GetCount(WCC->attachments) == 0)){
1142 StrBufAppendBufPlain(WCC->ImportantMsg, _("Refusing to post empty message.\n"), -1, 0);
1143 FreeStrBuf(&CmdBuf);
1148 lprintf(9, "%s\n", ChrPtr(CmdBuf));
1149 serv_puts(ChrPtr(CmdBuf));
1150 FreeStrBuf(&CmdBuf);
1152 StrBuf_ServGetln(Buf);
1153 if (GetServerStatus(Buf, NULL) == 4) {
1154 if (save_to_drafts) {
1155 if ( (havebstr("recp"))
1156 || (havebstr("cc" ))
1157 || (havebstr("bcc" )) ) {
1158 /* save recipient headers or room to post to */
1159 serv_printf("To: %s", ChrPtr(Recp));
1160 serv_printf("Cc: %s", ChrPtr(Cc));
1161 serv_printf("Bcc: %s", ChrPtr(Bcc));
1163 serv_printf("X-Citadel-Room: %s", ChrPtr(WC->CurRoom.name));
1166 post_mime_to_server();
1167 if (save_to_drafts) {
1168 StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been saved to Drafts.\n"), -1, 0);
1169 gotoroom(WCC->CurRoom.name);
1173 } else if ( (havebstr("recp"))
1174 || (havebstr("cc" ))
1175 || (havebstr("bcc" ))
1177 StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been sent.\n"), -1, 0);
1180 StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been posted.\n"), -1, 0);
1182 dont_post = lbstr("postseq");
1184 StrBufCutLeft(Buf, 4);
1186 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, ChrPtr(Buf));
1187 StrBufAppendBuf(WCC->ImportantMsg, Buf, 0);
1188 if (save_to_drafts) gotoroom(WCC->CurRoom.name);
1202 DeleteHash(&WCC->attachments);
1205 * We may have been supplied with instructions regarding the location
1206 * to which we must return after posting. If found, go there.
1208 if (havebstr("return_to")) {
1209 http_redirect(bstr("return_to"));
1212 * If we were editing a page in a wiki room, go to that page now.
1214 else if (havebstr("page")) {
1215 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("page"));
1219 * Otherwise, just go to the "read messages" loop.
1222 readloop(readnew, eUseDefault);
1228 * Client is uploading an attachment
1230 void upload_attachment(void) {
1231 wcsession *WCC = WC;
1237 wc_mime_attachment *att;
1239 lprintf(9, "upload_attachment()\n");
1240 wc_printf("upload_attachment()<br>\n");
1242 if (WCC->upload_length <= 0) {
1243 lprintf(9, "ERROR no attachment was uploaded\n");
1244 wc_printf("ERROR no attachment was uploaded<br>\n");
1248 lprintf(9, "Client is uploading %d bytes\n", WCC->upload_length);
1249 wc_printf("Client is uploading %d bytes<br>\n", WCC->upload_length);
1250 att = malloc(sizeof(wc_mime_attachment));
1251 memset(att, 0, sizeof(wc_mime_attachment ));
1252 att->length = WCC->upload_length;
1253 att->ContentType = NewStrBufPlain(WCC->upload_content_type, -1);
1254 att->FileName = NewStrBufDup(WCC->upload_filename);
1256 if (WCC->attachments == NULL) {
1257 WCC->attachments = NewHash(1, Flathash);
1260 /* And add it to the list. */
1262 if ((GetCount(WCC->attachments) > 0) &&
1263 GetHashAt(WCC->attachments,
1264 GetCount(WCC->attachments) -1,
1265 &newnlen, &newn, &v))
1266 n = *((int*) newn) + 1;
1267 Put(WCC->attachments, IKEY(n), att, DestroyMime);
1270 * Mozilla sends a simple filename, which is what we want,
1271 * but Satan's Browser sends an entire pathname. Reduce
1272 * the path to just a filename if we need to.
1274 pch = strrchr(ChrPtr(att->FileName), '/');
1276 StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1);
1278 pch = strrchr(ChrPtr(att->FileName), '\\');
1280 StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1);
1284 * Transfer control of this memory from the upload struct
1285 * to the attachment struct.
1287 att->Data = WCC->upload;
1289 WCC->upload_length = 0;
1294 * Remove an attachment from the message currently being composed.
1296 * Currently we identify the attachment to be removed by its filename.
1297 * There is probably a better way to do this.
1299 void remove_attachment(void) {
1300 wcsession *WCC = WC;
1301 wc_mime_attachment *att;
1303 StrBuf *WhichAttachment;
1308 WhichAttachment = NewStrBufDup(sbstr("which_attachment"));
1309 StrBufUnescape(WhichAttachment, 0);
1310 at = GetNewHashPos(WCC->attachments, 0);
1312 GetHashPos(WCC->attachments, at, &len, &key, &vAtt);
1314 att = (wc_mime_attachment*) vAtt;
1315 if ((att != NULL) &&
1316 (strcmp(ChrPtr(WhichAttachment),
1317 ChrPtr(att->FileName) ) == 0))
1319 DeleteEntryFromHash(WCC->attachments, at);
1323 while (NextHashPos(WCC->attachments, at));
1324 FreeStrBuf(&WhichAttachment);
1325 wc_printf("remove_attachment() completed\n");
1330 * display the message entry screen
1332 void display_enter(void)
1336 const StrBuf *display_name = NULL;
1337 int recipient_required = 0;
1338 int subject_required = 0;
1339 int recipient_bad = 0;
1340 int is_anonymous = 0;
1341 wcsession *WCC = WC;
1345 if (havebstr("force_room")) {
1346 gotoroom(sbstr("force_room"));
1349 display_name = sbstr("display_name");
1350 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
1351 display_name = NULL;
1355 /* First test to see whether this is a room that requires recipients to be entered */
1356 serv_puts("ENT0 0");
1357 serv_getln(buf, sizeof buf);
1359 if (!strncmp(buf, "570", 3)) { /* 570 means that we need a recipient here */
1360 recipient_required = 1;
1362 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
1363 sprintf(WCC->ImportantMessage, "%s", &buf[4]);
1364 readloop(readnew, eUseDefault);
1368 /* Is the server strongly recommending that the user enter a message subject? */
1369 if ((buf[3] != '\0') && (buf[4] != '\0')) {
1370 subject_required = extract_int(&buf[4], 1);
1374 * Are we perhaps in an address book view? If so, then an "enter
1375 * message" command really means "add new entry."
1377 if (WCC->CurRoom.defview == VIEW_ADDRESSBOOK) {
1378 do_edit_vcard(-1, "", NULL, NULL, "", ChrPtr(WCC->CurRoom.name));
1383 * Are we perhaps in a calendar room? If so, then an "enter
1384 * message" command really means "add new calendar item."
1386 if (WCC->CurRoom.defview == VIEW_CALENDAR) {
1387 display_edit_event();
1392 * Are we perhaps in a tasks view? If so, then an "enter
1393 * message" command really means "add new task."
1395 if (WCC->CurRoom.defview == VIEW_TASKS) {
1396 display_edit_task();
1401 * Otherwise proceed normally.
1402 * Do a custom room banner with no navbar...
1405 if (recipient_required) {
1406 const StrBuf *Recp = NULL;
1407 const StrBuf *Cc = NULL;
1408 const StrBuf *Bcc = NULL;
1409 const StrBuf *Wikipage = NULL;
1410 StrBuf *CmdBuf = NULL;
1411 const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
1413 Recp = sbstr("recp");
1416 Wikipage = sbstr("page");
1418 CmdBuf = NewStrBufPlain(NULL,
1421 StrLength(display_name) +
1424 StrLength(Wikipage));
1426 StrBufPrintf(CmdBuf,
1430 ChrPtr(display_name),
1434 serv_puts(ChrPtr(CmdBuf));
1435 serv_getln(buf, sizeof buf);
1436 FreeStrBuf(&CmdBuf);
1438 if (!strncmp(buf, "570", 3)) { /* 570 means we have an invalid recipient listed */
1439 if (havebstr("recp") &&
1445 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
1446 wc_printf("<em>%s</em><br>\n", &buf[4]); /* TODO -> important message */
1450 if (recipient_required)
1451 PutBstr(HKEY("__RCPTREQUIRED"), NewStrBufPlain(HKEY("1")));
1452 if (recipient_required || subject_required)
1453 PutBstr(HKEY("__SUBJREQUIRED"), NewStrBufPlain(HKEY("1")));
1456 output_headers(1, 0, 0, 0, 1, 0);
1457 DoTemplate(HKEY("edit_message"), NULL, &NoCtx);
1466 void delete_msg(void)
1471 msgid = lbstr("msgid");
1473 if ((WC->CurRoom.RAFlags & UA_ISTRASH) != 0) { /* Delete from Trash is a real delete */
1474 serv_printf("DELE %ld", msgid);
1476 else { /* Otherwise move it to Trash */
1477 serv_printf("MOVE %ld|_TRASH_|0", msgid);
1480 serv_getln(buf, sizeof buf);
1481 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1482 readloop(readnew, eUseDefault);
1487 * move a message to another room
1494 msgid = lbstr("msgid");
1496 if (havebstr("move_button")) {
1497 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
1499 serv_getln(buf, sizeof buf);
1500 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1502 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
1505 readloop(readnew, eUseDefault);
1510 * Confirm move of a message
1512 void confirm_move_msg(void)
1518 msgid = lbstr("msgid");
1521 output_headers(1, 1, 2, 0, 0, 0);
1522 wc_printf("<div id=\"banner\">\n");
1524 wc_printf(_("Confirm move of message"));
1526 wc_printf("</div>\n");
1528 wc_printf("<div id=\"content\" class=\"service\">\n");
1530 wc_printf("<CENTER>");
1532 wc_printf(_("Move this message to:"));
1533 wc_printf("<br>\n");
1535 wc_printf("<form METHOD=\"POST\" action=\"move_msg\">\n");
1536 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1537 wc_printf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
1539 wc_printf("<SELECT NAME=\"target_room\" SIZE=5>\n");
1541 serv_getln(buf, sizeof buf);
1542 if (buf[0] == '1') {
1543 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1544 extract_token(targ, buf, 0, '|', sizeof targ);
1545 wc_printf("<OPTION>");
1550 wc_printf("</SELECT>\n");
1551 wc_printf("<br>\n");
1553 wc_printf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
1554 wc_printf(" ");
1555 wc_printf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
1556 wc_printf("</form></CENTER>\n");
1558 wc_printf("</CENTER>\n");
1564 * Generic function to output an arbitrary MIME attachment from
1565 * message being composed
1567 * partnum The MIME part to be output
1568 * filename Fake filename to give
1569 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
1571 void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
1574 StrBuf *content_type;
1575 wc_mime_attachment *part;
1578 i = StrToi(partnum);
1579 if (GetHash(WC->attachments, IKEY(i), &vPart) &&
1581 part = (wc_mime_attachment*) vPart;
1582 if (force_download) {
1583 content_type = NewStrBufPlain(HKEY("application/octet-stream"));
1586 content_type = NewStrBufDup(part->ContentType);
1588 StrBufAppendBuf(WC->WBuf, part->Data, 0);
1589 http_transmit_thing(ChrPtr(content_type), 0);
1591 hprintf("HTTP/1.1 404 %s\n", ChrPtr(partnum));
1592 output_headers(0, 0, 0, 0, 0, 0);
1593 hprintf("Content-Type: text/plain\r\n");
1595 wc_printf(_("An error occurred while retrieving this part: %s/%s\n"),
1596 ChrPtr(partnum), ChrPtr(filename));
1599 FreeStrBuf(&content_type);
1604 * Generic function to output an arbitrary MIME part from an arbitrary
1605 * message number on the server.
1607 * msgnum Number of the item on the citadel server
1608 * partnum The MIME part to be output
1609 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
1611 void mimepart(int force_download)
1615 wcsession *WCC = WC;
1618 StrBuf *ContentType = NewStrBufPlain(HKEY("application/octet-stream"));
1621 att = Buf = NewStrBuf();
1622 msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/');
1623 StrBufExtract_token(att, WCC->Hdr->HR.ReqLine, 1, '/');
1625 serv_printf("OPNA %ld|%s", msgnum, ChrPtr(att));
1626 StrBuf_ServGetln(Buf);
1627 if (GetServerStatus(Buf, NULL) == 2) {
1628 StrBufCutLeft(Buf, 4);
1629 bytes = StrBufExtract_long(Buf, 0, '|');
1630 if (!force_download) {
1631 StrBufExtract_token(ContentType, Buf, 3, '|');
1634 serv_read_binary(WCC->WBuf, bytes, Buf);
1636 StrBuf_ServGetln(Buf);
1637 CT = ChrPtr(ContentType);
1639 if (!force_download) {
1640 if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
1641 StrBufExtract_token(Buf, WCC->Hdr->HR.ReqLine, 2, '/');
1642 CT = GuessMimeByFilename(SKEY(Buf));
1644 if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
1645 CT = GuessMimeType(SKEY(WCC->WBuf));
1648 http_transmit_thing(CT, 0);
1650 StrBufCutLeft(Buf, 4);
1651 hprintf("HTTP/1.1 404 %s\n", ChrPtr(Buf));
1652 output_headers(0, 0, 0, 0, 0, 0);
1653 hprintf("Content-Type: text/plain\r\n");
1655 wc_printf(_("An error occurred while retrieving this part: %s\n"),
1659 FreeStrBuf(&ContentType);
1665 * Read any MIME part of a message, from the server, into memory.
1667 StrBuf *load_mimepart(long msgnum, char *partnum)
1673 serv_printf("DLAT %ld|%s", msgnum, partnum);
1674 StrBuf_ServGetln(Buf);
1675 if (GetServerStatus(Buf, NULL) == 6) {
1676 StrBufCutLeft(Buf, 4);
1677 bytes = StrBufExtract_long(Buf, 0, '|');
1680 StrBuf_ServGetBLOBBuffered(Buf, bytes);
1690 * Read any MIME part of a message, from the server, into memory.
1692 void MimeLoadData(wc_mime_attachment *Mime)
1697 /* TODO: is there a chance the content type is different from the one we know? */
1699 serv_printf("DLAT %ld|%s", Mime->msgnum, ChrPtr(Mime->PartNum));
1701 StrBuf_ServGetln(Buf);
1702 if (GetServerStatus(Buf, NULL) == 6) {
1703 Ptr = &(ChrPtr(Buf)[4]);
1704 bytes = StrBufExtractNext_long(Buf, &Ptr, '|');
1705 StrBufSkip_NTokenS(Buf, &Ptr, '|', 3); /* filename, cbtype, mimetype */
1706 if (Mime->Charset == NULL) Mime->Charset = NewStrBuf();
1707 StrBufExtract_NextToken(Mime->Charset, Buf, &Ptr, '|');
1709 if (Mime->Data == NULL)
1710 Mime->Data = NewStrBufPlain(NULL, bytes);
1711 StrBuf_ServGetBLOBBuffered(Mime->Data, bytes);
1714 FlushStrBuf(Mime->Data);
1715 /* TODO XImportant message */
1721 void view_mimepart(void) {
1725 void download_mimepart(void) {
1729 void view_postpart(void) {
1730 StrBuf *filename = NewStrBuf();
1731 StrBuf *partnum = NewStrBuf();
1733 StrBufExtract_token(partnum, WC->Hdr->HR.ReqLine, 0, '/');
1734 StrBufExtract_token(filename, WC->Hdr->HR.ReqLine, 1, '/');
1736 postpart(partnum, filename, 0);
1738 FreeStrBuf(&filename);
1739 FreeStrBuf(&partnum);
1742 void download_postpart(void) {
1743 StrBuf *filename = NewStrBuf();
1744 StrBuf *partnum = NewStrBuf();
1746 StrBufExtract_token(partnum, WC->Hdr->HR.ReqLine, 0, '/');
1747 StrBufExtract_token(filename, WC->Hdr->HR.ReqLine, 1, '/');
1749 postpart(partnum, filename, 1);
1751 FreeStrBuf(&filename);
1752 FreeStrBuf(&partnum);
1757 void show_num_attachments(void) {
1758 wc_printf("%d", GetCount(WC->attachments));
1762 void h_readnew(void) { readloop(readnew, eUseDefault);}
1763 void h_readold(void) { readloop(readold, eUseDefault);}
1764 void h_readfwd(void) { readloop(readfwd, eUseDefault);}
1765 void h_headers(void) { readloop(headers, eUseDefault);}
1766 void h_do_search(void) { readloop(do_search, eUseDefault);}
1767 void h_readgt(void) { readloop(readgt, eUseDefault);}
1768 void h_readlt(void) { readloop(readlt, eUseDefault);}
1770 void jsonMessageListHdr(void)
1772 /* TODO: make a generic function */
1773 hprintf("HTTP/1.1 200 OK\r\n");
1774 hprintf("Content-type: application/json; charset=utf-8\r\n");
1775 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
1776 hprintf("Connection: close\r\n");
1777 hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
1782 /* Output message list in JSON format */
1783 void jsonMessageList(void) {
1784 const StrBuf *room = sbstr("room");
1785 long oper = (havebstr("query")) ? do_search : readnew;
1788 readloop(oper, eUseDefault);
1792 void RegisterReadLoopHandlerset(
1794 GetParamsGetServerCall_func GetParamsGetServerCall,
1795 PrintViewHeader_func PrintViewHeader,
1796 load_msg_ptrs_detailheaders LH,
1797 LoadMsgFromServer_func LoadMsgFromServer,
1798 RenderView_or_Tail_func RenderView_or_Tail,
1799 View_Cleanup_func ViewCleanup
1802 RoomRenderer *Handler;
1804 Handler = (RoomRenderer*) malloc(sizeof(RoomRenderer));
1806 Handler->RoomType = RoomType;
1807 Handler->GetParamsGetServerCall = GetParamsGetServerCall;
1808 Handler->PrintViewHeader = PrintViewHeader;
1809 Handler->LoadMsgFromServer = LoadMsgFromServer;
1810 Handler->RenderView_or_Tail = RenderView_or_Tail;
1811 Handler->ViewCleanup = ViewCleanup;
1812 Handler->LHParse = LH;
1814 Put(ReadLoopHandler, IKEY(RoomType), Handler, NULL);
1821 RegisterPreference("use_sig",
1822 _("Attach signature to email messages?"),
1825 RegisterPreference("signature", _("Use this signature:"), PRF_QP_STRING, NULL);
1826 RegisterPreference("default_header_charset",
1827 _("Default character set for email headers:"),
1830 RegisterPreference("defaultfrom", _("Preferred email address"), PRF_STRING, NULL);
1831 RegisterPreference("defaultname",
1832 _("Preferred display name for email messages"),
1835 RegisterPreference("defaulthandle",
1836 _("Preferred display name for bulletin board posts"),
1839 RegisterPreference("mailbox",_("Mailbox view mode"), PRF_STRING, NULL);
1841 WebcitAddUrlHandler(HKEY("readnew"), "", 0, h_readnew, ANONYMOUS|NEED_URL);
1842 WebcitAddUrlHandler(HKEY("readold"), "", 0, h_readold, ANONYMOUS|NEED_URL);
1843 WebcitAddUrlHandler(HKEY("readfwd"), "", 0, h_readfwd, ANONYMOUS|NEED_URL);
1844 WebcitAddUrlHandler(HKEY("headers"), "", 0, h_headers, NEED_URL);
1845 WebcitAddUrlHandler(HKEY("readgt"), "", 0, h_readgt, ANONYMOUS|NEED_URL);
1846 WebcitAddUrlHandler(HKEY("readlt"), "", 0, h_readlt, ANONYMOUS|NEED_URL);
1847 WebcitAddUrlHandler(HKEY("do_search"), "", 0, h_do_search, 0);
1848 WebcitAddUrlHandler(HKEY("display_enter"), "", 0, display_enter, 0);
1849 WebcitAddUrlHandler(HKEY("post"), "", 0, post_message, PROHIBIT_STARTPAGE);
1850 WebcitAddUrlHandler(HKEY("move_msg"), "", 0, move_msg, PROHIBIT_STARTPAGE);
1851 WebcitAddUrlHandler(HKEY("delete_msg"), "", 0, delete_msg, PROHIBIT_STARTPAGE);
1852 WebcitAddUrlHandler(HKEY("confirm_move_msg"), "", 0, confirm_move_msg, PROHIBIT_STARTPAGE);
1853 WebcitAddUrlHandler(HKEY("msg"), "", 0, embed_message, NEED_URL);
1854 WebcitAddUrlHandler(HKEY("message"), "", 0, handle_one_message, NEED_URL|XHTTP_COMMANDS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
1855 WebcitAddUrlHandler(HKEY("printmsg"), "", 0, print_message, NEED_URL);
1856 WebcitAddUrlHandler(HKEY("mobilemsg"), "", 0, mobile_message_view, NEED_URL);
1857 WebcitAddUrlHandler(HKEY("msgheaders"), "", 0, display_headers, NEED_URL);
1859 WebcitAddUrlHandler(HKEY("mimepart"), "", 0, view_mimepart, NEED_URL);
1860 WebcitAddUrlHandler(HKEY("mimepart_download"), "", 0, download_mimepart, NEED_URL);
1861 WebcitAddUrlHandler(HKEY("postpart"), "", 0, view_postpart, NEED_URL|PROHIBIT_STARTPAGE);
1862 WebcitAddUrlHandler(HKEY("postpart_download"), "", 0, download_postpart, NEED_URL|PROHIBIT_STARTPAGE);
1863 WebcitAddUrlHandler(HKEY("upload_attachment"), "", 0, upload_attachment, AJAX);
1864 WebcitAddUrlHandler(HKEY("remove_attachment"), "", 0, remove_attachment, AJAX);
1865 WebcitAddUrlHandler(HKEY("show_num_attachments"), "", 0, show_num_attachments, AJAX);
1868 WebcitAddUrlHandler(HKEY("roommsgs"), "", 0, jsonMessageList,0);
1873 SessionDetachModule_MSG
1876 DeleteHash(&sess->summ);