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 * Display a message's headers
497 void display_headers(void) {
501 msgnum = StrBufExtract_long(WC->Hdr->HR.ReqLine, 0, '/');
502 output_headers(0, 0, 0, 0, 0, 0);
504 hprintf("Content-type: text/plain\r\n"
506 "Connection: close\r\n",
510 serv_printf("MSG2 %ld|3", msgnum);
511 serv_getln(buf, sizeof buf);
513 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
514 wc_printf("%s\n", buf);
522 message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSubject, long MsgNum)
525 MsgPartEvaluatorStruct *Eval;
526 message_summary *Msg;
535 serv_printf("MSG0 %ld|1", MsgNum); /* ask for headers only */
537 StrBuf_ServGetln(Buf);
538 if (GetServerStatus(Buf, NULL) == 1) {
543 Msg = (message_summary*)malloc(sizeof(message_summary));
544 memset(Msg, 0, sizeof(message_summary));
545 while (len = StrBuf_ServGetln(Buf),
547 strcmp(ChrPtr(Buf), "000")== 0)){
549 ebuf = strchr(ChrPtr(Buf), '=');
551 if (GetHash(MsgEvaluators, buf, nBuf, &vEval) && vEval != NULL) {
552 Eval = (MsgPartEvaluatorStruct*) vEval;
553 StrBufCutLeft(Buf, nBuf + 1);
556 else lprintf(1, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
566 * load message pointers from the server for a "read messages" operation
568 * servcmd: the citadel command to send to the citserver
570 int load_msg_ptrs(const char *servcmd,
571 SharedMessageStatus *Stat,
572 load_msg_ptrs_detailheaders LH)
575 message_summary *Msg;
580 const char *Ptr = NULL;
582 Stat->lowest_found = LONG_MAX;
583 Stat->highest_found = LONG_MIN;
585 if (WCC->summ != NULL) {
586 DeleteHash(&WCC->summ);
588 WCC->summ = NewHash(1, Flathash);
592 StrBuf_ServGetln(Buf);
593 if (GetServerStatus(Buf, NULL) != 1) {
595 return (Stat->nummsgs);
598 while (len = StrBuf_ServGetln(Buf), ((len != 3) || strcmp(ChrPtr(Buf), "000")!= 0))
600 if (Stat->nummsgs < Stat->maxload) {
603 Msg = (message_summary*)malloc(sizeof(message_summary));
604 memset(Msg, 0, sizeof(message_summary));
606 Msg->msgnum = StrBufExtractNext_long(Buf, &Ptr, '|');
607 Msg->date = StrBufExtractNext_long(Buf, &Ptr, '|');
609 if (Stat->nummsgs == 0) {
610 if (Msg->msgnum < Stat->lowest_found) {
611 Stat->lowest_found = Msg->msgnum;
613 if (Msg->msgnum > Stat->highest_found) {
614 Stat->highest_found = Msg->msgnum;
618 if ((Msg->msgnum == 0) && (StrLength(Buf) < 32)) {
624 * as citserver probably gives us messages in forward date sorting
625 * nummsgs should be the same order as the message date.
627 if (Msg->date == 0) {
628 Msg->date = Stat->nummsgs;
629 if (StrLength(Buf) < 32)
632 if ((!skipit) && (LH != NULL)) {
633 if (!LH(Buf, &Ptr, Msg, Buf2)){
639 Put(WCC->summ, (const char *)&n, sizeof(n), Msg, DestroyMessageSummary);
645 return (Stat->nummsgs);
651 * \brief sets FlagToSet for each of ScanMe that appears in MatchMSet
652 * \param ScanMe List of BasicMsgStruct to be searched it MatchSet
653 * \param MatchMSet MSet we want to flag
654 * \param FlagToSet Flag to set on each BasicMsgStruct->Flags if in MSet
656 void SetFlagsFromMSet(HashList *ScanMe, MSet *MatchMSet, int FlagToSet, int Reverse)
662 message_summary *Msg;
664 at = GetNewHashPos(ScanMe, 0);
665 while (GetNextHashPos(ScanMe, at, &HKLen, &HashKey, &vMsg)) {
666 /* Are you a new message, or an old message? */
667 Msg = (message_summary*) vMsg;
668 if (Reverse && IsInMSetList(MatchMSet, Msg->msgnum)) {
669 Msg->Flags = Msg->Flags | FlagToSet;
671 else if (!Reverse && !IsInMSetList(MatchMSet, Msg->msgnum)) {
672 Msg->Flags = Msg->Flags | FlagToSet;
679 void load_seen_flags(void)
685 OldMsg = NewStrBuf();
687 StrBuf_ServGetln(OldMsg);
688 if (GetServerStatus(OldMsg, NULL) == 2) {
689 StrBufCutLeft(OldMsg, 4);
696 if (ParseMSet(&MatchMSet, OldMsg))
698 SetFlagsFromMSet(WCC->summ, MatchMSet, MSGFLAG_READ, 0);
700 DeleteMSet(&MatchMSet);
704 extern readloop_struct rlid[];
706 typedef struct _RoomRenderer{
709 GetParamsGetServerCall_func GetParamsGetServerCall;
710 PrintViewHeader_func PrintViewHeader;
711 LoadMsgFromServer_func LoadMsgFromServer;
712 RenderView_or_Tail_func RenderView_or_Tail;
713 View_Cleanup_func ViewCleanup;
714 load_msg_ptrs_detailheaders LHParse;
719 * command loop for reading messages
721 * Set oper to "readnew" or "readold" or "readfwd" or "headers" or "readgt" or "readlt" or "do_search"
723 void readloop(long oper, eCustomRoomRenderer ForceRenderer)
725 RoomRenderer *ViewMsg;
728 message_summary *Msg;
735 WCTemplputParams SubTP;
736 SharedMessageStatus Stat;
739 if (havebstr("is_summary") && (1 == (ibstr("is_summary")))) {
740 WCC->CurRoom.view = VIEW_MAILBOX;
743 if (havebstr("is_ajax") && (1 == (ibstr("is_ajax")))) {
747 if ((oper == do_search) && (WCC->CurRoom.view == VIEW_WIKI)) {
748 display_wiki_pagelist();
752 if (WCC->CurRoom.view == VIEW_WIKI) {
753 http_redirect("wiki?page=home");
757 memset(&Stat, 0, sizeof(SharedMessageStatus));
758 Stat.maxload = 10000;
759 Stat.lowest_found = (-1);
760 Stat.highest_found = (-1);
761 if (ForceRenderer == eUseDefault)
762 GetHash(ReadLoopHandler, IKEY(WCC->CurRoom.view), &vViewMsg);
764 GetHash(ReadLoopHandler, IKEY(ForceRenderer), &vViewMsg);
765 if (vViewMsg == NULL) {
766 WCC->CurRoom.view = VIEW_BBS;
767 GetHash(ReadLoopHandler, IKEY(WCC->CurRoom.view), &vViewMsg);
769 if (vViewMsg == NULL) {
770 return; // TODO: print message
773 ViewMsg = (RoomRenderer*) vViewMsg;
775 output_headers(1, 1, 1, 0, 0, 0);
776 } else if (WCC->CurRoom.view == VIEW_MAILBOX) {
777 jsonMessageListHdr();
780 if (ViewMsg->GetParamsGetServerCall != NULL) {
781 r = ViewMsg->GetParamsGetServerCall(
796 case 300: /* the callback hook should do the work for us here, since he knows what to do. */
802 if (!IsEmptyStr(cmd))
803 Stat.nummsgs = load_msg_ptrs(cmd, &Stat, ViewMsg->LHParse);
807 memset(&SubTP, 0, sizeof(WCTemplputParams));
808 SubTP.Filter.ContextType = CTX_MAILSUM;
809 SubTP.Context = NULL;
810 SortIt = RetrieveSort(&SubTP, NULL, 0,
811 HKEY("date"), Stat.defaultsortorder);
813 SortByPayload(WCC->summ, SortIt);
815 if (Stat.startmsg < 0) {
819 if (Stat.load_seen) load_seen_flags();
822 * Print any inforation above the message list...
824 if (ViewMsg->PrintViewHeader != NULL)
825 ViewMsg->PrintViewHeader(&Stat, &ViewSpecific);
827 WCC->startmsg = Stat.startmsg;
828 WCC->maxmsgs = Stat.maxmsgs;
829 WCC->num_displayed = 0;
831 /* Put some helpful data in vars for mailsummary_json */
836 StrBufPrintf(Foo, "%ld", Stat.nummsgs);
837 PutBstr(HKEY("__READLOOP:TOTALMSGS"), NewStrBufDup(Foo));
838 StrBufPrintf(Foo, "%ld", Stat.startmsg);
839 PutBstr(HKEY("__READLOOP:STARTMSG"), Foo);
843 * iterate over each message. if we need to load an attachment, do it here.
846 if ((ViewMsg->LoadMsgFromServer != NULL) &&
849 at = GetNewHashPos(WCC->summ, 0);
850 Stat.num_displayed = i = 0;
851 while ( GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
852 Msg = (message_summary*) vMsg;
853 if ((Msg->msgnum >= Stat.startmsg) && (Stat.num_displayed <= Stat.maxmsgs)) {
854 ViewMsg->LoadMsgFromServer(&Stat,
857 (Msg->Flags & MSGFLAG_READ) != 0,
866 * Done iterating the message list. now tasks we want to do after.
868 if (ViewMsg->RenderView_or_Tail != NULL)
869 ViewMsg->RenderView_or_Tail(&Stat, &ViewSpecific, oper);
871 if (ViewMsg->ViewCleanup != NULL)
872 ViewMsg->ViewCleanup(&ViewSpecific);
876 if (WCC->summ != NULL) {
877 DeleteHash(&WCC->summ);
883 * Back end for post_message()
884 * ... this is where the actual message gets transmitted to the server.
886 void post_mime_to_server(void) {
888 char top_boundary[SIZ];
889 char alt_boundary[SIZ];
890 int is_multipart = 0;
892 wc_mime_attachment *att;
894 size_t encoded_length;
895 size_t encoded_strlen;
896 char *txtmail = NULL;
897 int include_text_alt = 0; /* Set to nonzero to include multipart/alternative text/plain */
899 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
900 ChrPtr(WCC->serv_info->serv_fqdn),
904 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
905 ChrPtr(WCC->serv_info->serv_fqdn),
910 /* RFC2045 requires this, and some clients look for it... */
911 serv_puts("MIME-Version: 1.0");
912 serv_puts("X-Mailer: " PACKAGE_STRING);
914 /* If there are attachments, we have to do multipart/mixed */
915 if (GetCount(WCC->attachments) > 0) {
919 /* Only do multipart/alternative for mailboxes. BBS and Wiki rooms don't need it. */
920 if (WC->CurRoom.view == VIEW_MAILBOX) {
921 include_text_alt = 1;
925 /* Remember, serv_printf() appends an extra newline */
926 serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
927 serv_printf("This is a multipart message in MIME format.\n");
928 serv_printf("--%s", top_boundary);
931 /* Remember, serv_printf() appends an extra newline */
932 if (include_text_alt) {
933 serv_printf("Content-type: multipart/alternative; "
934 "boundary=\"%s\"\n", alt_boundary);
935 serv_printf("This is a multipart message in MIME format.\n");
936 serv_printf("--%s", alt_boundary);
938 serv_puts("Content-type: text/plain; charset=utf-8");
939 serv_puts("Content-Transfer-Encoding: quoted-printable");
941 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
942 text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */
945 serv_printf("--%s", alt_boundary);
948 serv_puts("Content-type: text/html; charset=utf-8");
949 serv_puts("Content-Transfer-Encoding: quoted-printable");
951 serv_puts("<html><body>\r\n");
952 text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */
953 serv_puts("</body></html>\r\n");
955 if (include_text_alt) {
956 serv_printf("--%s--", alt_boundary);
965 /* Add in the attachments */
966 it = GetNewHashPos(WCC->attachments, 0);
967 while (GetNextHashPos(WCC->attachments, it, &len, &Key, &vAtt)) {
968 att = (wc_mime_attachment *)vAtt;
969 if (att->length == 0)
971 encoded_length = ((att->length * 150) / 100);
972 encoded = malloc(encoded_length);
973 if (encoded == NULL) break;
974 encoded_strlen = CtdlEncodeBase64(encoded, ChrPtr(att->Data), StrLength(att->Data), 1);
976 serv_printf("--%s", top_boundary);
977 serv_printf("Content-type: %s", ChrPtr(att->ContentType));
978 serv_printf("Content-disposition: attachment; filename=\"%s\"", ChrPtr(att->FileName));
979 serv_puts("Content-transfer-encoding: base64");
981 serv_write(encoded, encoded_strlen);
986 serv_printf("--%s--", top_boundary);
995 * Post message (or don't post message)
997 * Note regarding the "dont_post" variable:
998 * A random value (actually, it's just a timestamp) is inserted as a hidden
999 * field called "postseq" when the display_enter page is generated. This
1000 * value is checked when posting, using the static variable dont_post. If a
1001 * user attempts to post twice using the same dont_post value, the message is
1002 * discarded. This prevents the accidental double-saving of the same message
1003 * if the user happens to click the browser "back" button.
1005 void post_message(void)
1008 StrBuf *EmailAddress;
1011 StrBuf *encoded_subject = NULL;
1012 static long dont_post = (-1L);
1013 int is_anonymous = 0;
1014 const StrBuf *display_name = NULL;
1015 wcsession *WCC = WC;
1018 if (havebstr("force_room")) {
1019 gotoroom(sbstr("force_room"));
1022 if (havebstr("display_name")) {
1023 display_name = sbstr("display_name");
1024 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
1025 display_name = NULL;
1030 if (!strcasecmp(bstr("submit_action"), "cancel")) {
1031 sprintf(WCC->ImportantMessage,
1032 _("Cancelled. Message was not posted."));
1033 } else if (lbstr("postseq") == dont_post) {
1034 sprintf(WCC->ImportantMessage,
1035 _("Automatically cancelled because you have already "
1036 "saved this message."));
1038 const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s";
1039 StrBuf *Recp = NULL;
1042 const StrBuf *Wikipage = NULL;
1043 const StrBuf *my_email_addr = NULL;
1044 StrBuf *CmdBuf = NULL;
1045 StrBuf *references = NULL;
1049 save_to_drafts = !strcasecmp(bstr("submit_action"), "drafts");
1052 if (save_to_drafts) {
1053 /* temporarily change to the drafts room */
1054 serv_puts("GOTO _DRAFTS_");
1055 StrBuf_ServGetln(Buf);
1056 if (GetServerStatus(Buf, NULL) != 2) {
1057 /* You probably don't even have a dumb Drafts folder */
1058 StrBufCutLeft(Buf, 4);
1059 lprintf(9, "%s:%d: server save to drafts error: %s\n", __FILE__, __LINE__, ChrPtr(Buf));
1060 StrBufAppendBufPlain(WCC->ImportantMsg, _("Saved to Drafts failed: "), -1, 0);
1061 StrBufAppendBuf(WCC->ImportantMsg, Buf, 0);
1068 if (havebstr("references"))
1070 const StrBuf *ref = sbstr("references");
1071 references = NewStrBufDup(ref);
1072 if (*ChrPtr(references) == '|') { /* remove leading '|' if present */
1073 StrBufCutLeft(references, 1);
1075 StrBufReplaceChars(references, '|', '!');
1077 if (havebstr("subject")) {
1080 * make enough room for the encoded string;
1081 * plus the QP header
1083 Subj = sbstr("subject");
1085 StrBufRFC2047encode(&encoded_subject, Subj);
1087 UserName = NewStrBuf();
1088 EmailAddress = NewStrBuf();
1089 EncBuf = NewStrBuf();
1091 Recp = StrBufSanitizeEmailRecipientVector(sbstr("recp"), UserName, EmailAddress, EncBuf);
1092 Cc = StrBufSanitizeEmailRecipientVector(sbstr("cc"), UserName, EmailAddress, EncBuf);
1093 Bcc = StrBufSanitizeEmailRecipientVector(sbstr("bcc"), UserName, EmailAddress, EncBuf);
1095 FreeStrBuf(&UserName);
1096 FreeStrBuf(&EmailAddress);
1097 FreeStrBuf(&EncBuf);
1099 Wikipage = sbstr("page");
1100 my_email_addr = sbstr("my_email_addr");
1102 HeaderLen = StrLength(Recp) +
1103 StrLength(encoded_subject) +
1106 StrLength(Wikipage) +
1107 StrLength(my_email_addr) +
1108 StrLength(references);
1109 CmdBuf = NewStrBufPlain(NULL, sizeof (CMD) + HeaderLen);
1110 StrBufPrintf(CmdBuf,
1112 save_to_drafts?"":ChrPtr(Recp),
1114 ChrPtr(encoded_subject),
1115 ChrPtr(display_name),
1116 save_to_drafts?"":ChrPtr(Cc),
1117 save_to_drafts?"":ChrPtr(Bcc),
1119 ChrPtr(my_email_addr),
1120 ChrPtr(references));
1121 FreeStrBuf(&references);
1122 FreeStrBuf(&encoded_subject);
1124 if ((HeaderLen + StrLength(sbstr("msgtext")) < 10) &&
1125 (GetCount(WCC->attachments) == 0)){
1126 StrBufAppendBufPlain(WCC->ImportantMsg, _("Refusing to post empty message.\n"), -1, 0);
1127 FreeStrBuf(&CmdBuf);
1132 lprintf(9, "%s\n", ChrPtr(CmdBuf));
1133 serv_puts(ChrPtr(CmdBuf));
1134 FreeStrBuf(&CmdBuf);
1136 StrBuf_ServGetln(Buf);
1137 if (GetServerStatus(Buf, NULL) == 4) {
1138 if (save_to_drafts) {
1139 if ( (havebstr("recp"))
1140 || (havebstr("cc" ))
1141 || (havebstr("bcc" )) ) {
1142 /* save recipient headers or room to post to */
1143 serv_printf("To: %s", ChrPtr(Recp));
1144 serv_printf("Cc: %s", ChrPtr(Cc));
1145 serv_printf("Bcc: %s", ChrPtr(Bcc));
1147 serv_printf("X-Citadel-Room: %s", ChrPtr(WC->CurRoom.name));
1150 post_mime_to_server();
1151 if (save_to_drafts) {
1152 StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been saved to Drafts.\n"), -1, 0);
1153 gotoroom(WCC->CurRoom.name);
1157 } else if ( (havebstr("recp"))
1158 || (havebstr("cc" ))
1159 || (havebstr("bcc" ))
1161 StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been sent.\n"), -1, 0);
1164 StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been posted.\n"), -1, 0);
1166 dont_post = lbstr("postseq");
1168 StrBufCutLeft(Buf, 4);
1170 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, ChrPtr(Buf));
1171 StrBufAppendBuf(WCC->ImportantMsg, Buf, 0);
1172 if (save_to_drafts) gotoroom(WCC->CurRoom.name);
1186 DeleteHash(&WCC->attachments);
1189 * We may have been supplied with instructions regarding the location
1190 * to which we must return after posting. If found, go there.
1192 if (havebstr("return_to")) {
1193 http_redirect(bstr("return_to"));
1196 * If we were editing a page in a wiki room, go to that page now.
1198 else if (havebstr("page")) {
1199 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("page"));
1203 * Otherwise, just go to the "read messages" loop.
1206 readloop(readnew, eUseDefault);
1212 * Client is uploading an attachment
1214 void upload_attachment(void) {
1215 wcsession *WCC = WC;
1221 wc_mime_attachment *att;
1223 lprintf(9, "upload_attachment()\n");
1224 wc_printf("upload_attachment()<br>\n");
1226 if (WCC->upload_length <= 0) {
1227 lprintf(9, "ERROR no attachment was uploaded\n");
1228 wc_printf("ERROR no attachment was uploaded<br>\n");
1232 lprintf(9, "Client is uploading %d bytes\n", WCC->upload_length);
1233 wc_printf("Client is uploading %d bytes<br>\n", WCC->upload_length);
1234 att = malloc(sizeof(wc_mime_attachment));
1235 memset(att, 0, sizeof(wc_mime_attachment ));
1236 att->length = WCC->upload_length;
1237 att->ContentType = NewStrBufPlain(WCC->upload_content_type, -1);
1238 att->FileName = NewStrBufDup(WCC->upload_filename);
1240 if (WCC->attachments == NULL) {
1241 WCC->attachments = NewHash(1, Flathash);
1244 /* And add it to the list. */
1246 if ((GetCount(WCC->attachments) > 0) &&
1247 GetHashAt(WCC->attachments,
1248 GetCount(WCC->attachments) -1,
1249 &newnlen, &newn, &v))
1250 n = *((int*) newn) + 1;
1251 Put(WCC->attachments, IKEY(n), att, DestroyMime);
1254 * Mozilla sends a simple filename, which is what we want,
1255 * but Satan's Browser sends an entire pathname. Reduce
1256 * the path to just a filename if we need to.
1258 pch = strrchr(ChrPtr(att->FileName), '/');
1260 StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1);
1262 pch = strrchr(ChrPtr(att->FileName), '\\');
1264 StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1);
1268 * Transfer control of this memory from the upload struct
1269 * to the attachment struct.
1271 att->Data = WCC->upload;
1273 WCC->upload_length = 0;
1278 * Remove an attachment from the message currently being composed.
1280 * Currently we identify the attachment to be removed by its filename.
1281 * There is probably a better way to do this.
1283 void remove_attachment(void) {
1284 wcsession *WCC = WC;
1285 wc_mime_attachment *att;
1287 StrBuf *WhichAttachment;
1292 WhichAttachment = NewStrBufDup(sbstr("which_attachment"));
1293 StrBufUnescape(WhichAttachment, 0);
1294 at = GetNewHashPos(WCC->attachments, 0);
1296 GetHashPos(WCC->attachments, at, &len, &key, &vAtt);
1298 att = (wc_mime_attachment*) vAtt;
1299 if ((att != NULL) &&
1300 (strcmp(ChrPtr(WhichAttachment),
1301 ChrPtr(att->FileName) ) == 0))
1303 DeleteEntryFromHash(WCC->attachments, at);
1307 while (NextHashPos(WCC->attachments, at));
1308 FreeStrBuf(&WhichAttachment);
1309 wc_printf("remove_attachment() completed\n");
1314 * display the message entry screen
1316 void display_enter(void)
1320 const StrBuf *display_name = NULL;
1321 int recipient_required = 0;
1322 int subject_required = 0;
1323 int recipient_bad = 0;
1324 int is_anonymous = 0;
1325 wcsession *WCC = WC;
1329 if (havebstr("force_room")) {
1330 gotoroom(sbstr("force_room"));
1333 display_name = sbstr("display_name");
1334 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
1335 display_name = NULL;
1339 /* First test to see whether this is a room that requires recipients to be entered */
1340 serv_puts("ENT0 0");
1341 serv_getln(buf, sizeof buf);
1343 if (!strncmp(buf, "570", 3)) { /* 570 means that we need a recipient here */
1344 recipient_required = 1;
1346 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
1347 sprintf(WCC->ImportantMessage, "%s", &buf[4]);
1348 readloop(readnew, eUseDefault);
1352 /* Is the server strongly recommending that the user enter a message subject? */
1353 if ((buf[3] != '\0') && (buf[4] != '\0')) {
1354 subject_required = extract_int(&buf[4], 1);
1358 * Are we perhaps in an address book view? If so, then an "enter
1359 * message" command really means "add new entry."
1361 if (WCC->CurRoom.defview == VIEW_ADDRESSBOOK) {
1362 do_edit_vcard(-1, "", NULL, NULL, "", ChrPtr(WCC->CurRoom.name));
1367 * Are we perhaps in a calendar room? If so, then an "enter
1368 * message" command really means "add new calendar item."
1370 if (WCC->CurRoom.defview == VIEW_CALENDAR) {
1371 display_edit_event();
1376 * Are we perhaps in a tasks view? If so, then an "enter
1377 * message" command really means "add new task."
1379 if (WCC->CurRoom.defview == VIEW_TASKS) {
1380 display_edit_task();
1385 * Otherwise proceed normally.
1386 * Do a custom room banner with no navbar...
1389 if (recipient_required) {
1390 const StrBuf *Recp = NULL;
1391 const StrBuf *Cc = NULL;
1392 const StrBuf *Bcc = NULL;
1393 const StrBuf *Wikipage = NULL;
1394 StrBuf *CmdBuf = NULL;
1395 const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
1397 Recp = sbstr("recp");
1400 Wikipage = sbstr("page");
1402 CmdBuf = NewStrBufPlain(NULL,
1405 StrLength(display_name) +
1408 StrLength(Wikipage));
1410 StrBufPrintf(CmdBuf,
1414 ChrPtr(display_name),
1418 serv_puts(ChrPtr(CmdBuf));
1419 serv_getln(buf, sizeof buf);
1420 FreeStrBuf(&CmdBuf);
1422 if (!strncmp(buf, "570", 3)) { /* 570 means we have an invalid recipient listed */
1423 if (havebstr("recp") &&
1429 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
1430 wc_printf("<em>%s</em><br>\n", &buf[4]); /* TODO -> important message */
1434 if (recipient_required)
1435 PutBstr(HKEY("__RCPTREQUIRED"), NewStrBufPlain(HKEY("1")));
1436 if (recipient_required || subject_required)
1437 PutBstr(HKEY("__SUBJREQUIRED"), NewStrBufPlain(HKEY("1")));
1440 output_headers(1, 0, 0, 0, 1, 0);
1441 DoTemplate(HKEY("edit_message"), NULL, &NoCtx);
1450 void delete_msg(void)
1455 msgid = lbstr("msgid");
1457 if ((WC->CurRoom.RAFlags & UA_ISTRASH) != 0) { /* Delete from Trash is a real delete */
1458 serv_printf("DELE %ld", msgid);
1460 else { /* Otherwise move it to Trash */
1461 serv_printf("MOVE %ld|_TRASH_|0", msgid);
1464 serv_getln(buf, sizeof buf);
1465 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1466 readloop(readnew, eUseDefault);
1471 * move a message to another room
1478 msgid = lbstr("msgid");
1480 if (havebstr("move_button")) {
1481 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
1483 serv_getln(buf, sizeof buf);
1484 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1486 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
1489 readloop(readnew, eUseDefault);
1494 * Confirm move of a message
1496 void confirm_move_msg(void)
1502 msgid = lbstr("msgid");
1505 output_headers(1, 1, 2, 0, 0, 0);
1506 wc_printf("<div id=\"banner\">\n");
1508 wc_printf(_("Confirm move of message"));
1510 wc_printf("</div>\n");
1512 wc_printf("<div id=\"content\" class=\"service\">\n");
1514 wc_printf("<CENTER>");
1516 wc_printf(_("Move this message to:"));
1517 wc_printf("<br>\n");
1519 wc_printf("<form METHOD=\"POST\" action=\"move_msg\">\n");
1520 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1521 wc_printf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
1523 wc_printf("<SELECT NAME=\"target_room\" SIZE=5>\n");
1525 serv_getln(buf, sizeof buf);
1526 if (buf[0] == '1') {
1527 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1528 extract_token(targ, buf, 0, '|', sizeof targ);
1529 wc_printf("<OPTION>");
1534 wc_printf("</SELECT>\n");
1535 wc_printf("<br>\n");
1537 wc_printf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
1538 wc_printf(" ");
1539 wc_printf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
1540 wc_printf("</form></CENTER>\n");
1542 wc_printf("</CENTER>\n");
1548 * Generic function to output an arbitrary MIME attachment from
1549 * message being composed
1551 * partnum The MIME part to be output
1552 * filename Fake filename to give
1553 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
1555 void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
1558 StrBuf *content_type;
1559 wc_mime_attachment *part;
1562 i = StrToi(partnum);
1563 if (GetHash(WC->attachments, IKEY(i), &vPart) &&
1565 part = (wc_mime_attachment*) vPart;
1566 if (force_download) {
1567 content_type = NewStrBufPlain(HKEY("application/octet-stream"));
1570 content_type = NewStrBufDup(part->ContentType);
1572 StrBufAppendBuf(WC->WBuf, part->Data, 0);
1573 http_transmit_thing(ChrPtr(content_type), 0);
1575 hprintf("HTTP/1.1 404 %s\n", ChrPtr(partnum));
1576 output_headers(0, 0, 0, 0, 0, 0);
1577 hprintf("Content-Type: text/plain\r\n");
1579 wc_printf(_("An error occurred while retrieving this part: %s/%s\n"),
1580 ChrPtr(partnum), ChrPtr(filename));
1583 FreeStrBuf(&content_type);
1588 * Generic function to output an arbitrary MIME part from an arbitrary
1589 * message number on the server.
1591 * msgnum Number of the item on the citadel server
1592 * partnum The MIME part to be output
1593 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
1595 void mimepart(int force_download)
1599 wcsession *WCC = WC;
1602 StrBuf *ContentType = NewStrBufPlain(HKEY("application/octet-stream"));
1605 att = Buf = NewStrBuf();
1606 msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/');
1607 StrBufExtract_token(att, WCC->Hdr->HR.ReqLine, 1, '/');
1609 serv_printf("OPNA %ld|%s", msgnum, ChrPtr(att));
1610 StrBuf_ServGetln(Buf);
1611 if (GetServerStatus(Buf, NULL) == 2) {
1612 StrBufCutLeft(Buf, 4);
1613 bytes = StrBufExtract_long(Buf, 0, '|');
1614 if (!force_download) {
1615 StrBufExtract_token(ContentType, Buf, 3, '|');
1618 serv_read_binary(WCC->WBuf, bytes, Buf);
1620 StrBuf_ServGetln(Buf);
1621 CT = ChrPtr(ContentType);
1623 if (!force_download) {
1624 if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
1625 StrBufExtract_token(Buf, WCC->Hdr->HR.ReqLine, 2, '/');
1626 CT = GuessMimeByFilename(SKEY(Buf));
1628 if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
1629 CT = GuessMimeType(SKEY(WCC->WBuf));
1632 http_transmit_thing(CT, 0);
1634 StrBufCutLeft(Buf, 4);
1635 hprintf("HTTP/1.1 404 %s\n", ChrPtr(Buf));
1636 output_headers(0, 0, 0, 0, 0, 0);
1637 hprintf("Content-Type: text/plain\r\n");
1639 wc_printf(_("An error occurred while retrieving this part: %s\n"),
1643 FreeStrBuf(&ContentType);
1649 * Read any MIME part of a message, from the server, into memory.
1651 StrBuf *load_mimepart(long msgnum, char *partnum)
1657 serv_printf("DLAT %ld|%s", msgnum, partnum);
1658 StrBuf_ServGetln(Buf);
1659 if (GetServerStatus(Buf, NULL) == 6) {
1660 StrBufCutLeft(Buf, 4);
1661 bytes = StrBufExtract_long(Buf, 0, '|');
1664 StrBuf_ServGetBLOBBuffered(Buf, bytes);
1674 * Read any MIME part of a message, from the server, into memory.
1676 void MimeLoadData(wc_mime_attachment *Mime)
1681 /* TODO: is there a chance the content type is different from the one we know? */
1683 serv_printf("DLAT %ld|%s", Mime->msgnum, ChrPtr(Mime->PartNum));
1685 StrBuf_ServGetln(Buf);
1686 if (GetServerStatus(Buf, NULL) == 6) {
1687 Ptr = &(ChrPtr(Buf)[4]);
1688 bytes = StrBufExtractNext_long(Buf, &Ptr, '|');
1689 StrBufSkip_NTokenS(Buf, &Ptr, '|', 3); /* filename, cbtype, mimetype */
1690 if (Mime->Charset == NULL) Mime->Charset = NewStrBuf();
1691 StrBufExtract_NextToken(Mime->Charset, Buf, &Ptr, '|');
1693 if (Mime->Data == NULL)
1694 Mime->Data = NewStrBufPlain(NULL, bytes);
1695 StrBuf_ServGetBLOBBuffered(Mime->Data, bytes);
1698 FlushStrBuf(Mime->Data);
1699 /* TODO XImportant message */
1705 void view_mimepart(void) {
1709 void download_mimepart(void) {
1713 void view_postpart(void) {
1714 StrBuf *filename = NewStrBuf();
1715 StrBuf *partnum = NewStrBuf();
1717 StrBufExtract_token(partnum, WC->Hdr->HR.ReqLine, 0, '/');
1718 StrBufExtract_token(filename, WC->Hdr->HR.ReqLine, 1, '/');
1720 postpart(partnum, filename, 0);
1722 FreeStrBuf(&filename);
1723 FreeStrBuf(&partnum);
1726 void download_postpart(void) {
1727 StrBuf *filename = NewStrBuf();
1728 StrBuf *partnum = NewStrBuf();
1730 StrBufExtract_token(partnum, WC->Hdr->HR.ReqLine, 0, '/');
1731 StrBufExtract_token(filename, WC->Hdr->HR.ReqLine, 1, '/');
1733 postpart(partnum, filename, 1);
1735 FreeStrBuf(&filename);
1736 FreeStrBuf(&partnum);
1741 void show_num_attachments(void) {
1742 wc_printf("%d", GetCount(WC->attachments));
1746 void h_readnew(void) { readloop(readnew, eUseDefault);}
1747 void h_readold(void) { readloop(readold, eUseDefault);}
1748 void h_readfwd(void) { readloop(readfwd, eUseDefault);}
1749 void h_headers(void) { readloop(headers, eUseDefault);}
1750 void h_do_search(void) { readloop(do_search, eUseDefault);}
1751 void h_readgt(void) { readloop(readgt, eUseDefault);}
1752 void h_readlt(void) { readloop(readlt, eUseDefault);}
1754 void jsonMessageListHdr(void)
1756 /* TODO: make a generic function */
1757 hprintf("HTTP/1.1 200 OK\r\n");
1758 hprintf("Content-type: application/json; charset=utf-8\r\n");
1759 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
1760 hprintf("Connection: close\r\n");
1761 hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
1766 /* Output message list in JSON format */
1767 void jsonMessageList(void) {
1768 const StrBuf *room = sbstr("room");
1769 long oper = (havebstr("query")) ? do_search : readnew;
1772 readloop(oper, eUseDefault);
1776 void RegisterReadLoopHandlerset(
1778 GetParamsGetServerCall_func GetParamsGetServerCall,
1779 PrintViewHeader_func PrintViewHeader,
1780 load_msg_ptrs_detailheaders LH,
1781 LoadMsgFromServer_func LoadMsgFromServer,
1782 RenderView_or_Tail_func RenderView_or_Tail,
1783 View_Cleanup_func ViewCleanup
1786 RoomRenderer *Handler;
1788 Handler = (RoomRenderer*) malloc(sizeof(RoomRenderer));
1790 Handler->RoomType = RoomType;
1791 Handler->GetParamsGetServerCall = GetParamsGetServerCall;
1792 Handler->PrintViewHeader = PrintViewHeader;
1793 Handler->LoadMsgFromServer = LoadMsgFromServer;
1794 Handler->RenderView_or_Tail = RenderView_or_Tail;
1795 Handler->ViewCleanup = ViewCleanup;
1796 Handler->LHParse = LH;
1798 Put(ReadLoopHandler, IKEY(RoomType), Handler, NULL);
1805 RegisterPreference("use_sig",
1806 _("Attach signature to email messages?"),
1809 RegisterPreference("signature", _("Use this signature:"), PRF_QP_STRING, NULL);
1810 RegisterPreference("default_header_charset",
1811 _("Default character set for email headers:"),
1814 RegisterPreference("defaultfrom", _("Preferred email address"), PRF_STRING, NULL);
1815 RegisterPreference("defaultname",
1816 _("Preferred display name for email messages"),
1819 RegisterPreference("defaulthandle",
1820 _("Preferred display name for bulletin board posts"),
1823 RegisterPreference("mailbox",_("Mailbox view mode"), PRF_STRING, NULL);
1825 WebcitAddUrlHandler(HKEY("readnew"), "", 0, h_readnew, ANONYMOUS|NEED_URL);
1826 WebcitAddUrlHandler(HKEY("readold"), "", 0, h_readold, ANONYMOUS|NEED_URL);
1827 WebcitAddUrlHandler(HKEY("readfwd"), "", 0, h_readfwd, ANONYMOUS|NEED_URL);
1828 WebcitAddUrlHandler(HKEY("headers"), "", 0, h_headers, NEED_URL);
1829 WebcitAddUrlHandler(HKEY("readgt"), "", 0, h_readgt, ANONYMOUS|NEED_URL);
1830 WebcitAddUrlHandler(HKEY("readlt"), "", 0, h_readlt, ANONYMOUS|NEED_URL);
1831 WebcitAddUrlHandler(HKEY("do_search"), "", 0, h_do_search, 0);
1832 WebcitAddUrlHandler(HKEY("display_enter"), "", 0, display_enter, 0);
1833 WebcitAddUrlHandler(HKEY("post"), "", 0, post_message, PROHIBIT_STARTPAGE);
1834 WebcitAddUrlHandler(HKEY("move_msg"), "", 0, move_msg, PROHIBIT_STARTPAGE);
1835 WebcitAddUrlHandler(HKEY("delete_msg"), "", 0, delete_msg, PROHIBIT_STARTPAGE);
1836 WebcitAddUrlHandler(HKEY("confirm_move_msg"), "", 0, confirm_move_msg, PROHIBIT_STARTPAGE);
1837 WebcitAddUrlHandler(HKEY("msg"), "", 0, embed_message, NEED_URL);
1838 WebcitAddUrlHandler(HKEY("message"), "", 0, handle_one_message, NEED_URL|XHTTP_COMMANDS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
1839 WebcitAddUrlHandler(HKEY("printmsg"), "", 0, print_message, NEED_URL);
1840 WebcitAddUrlHandler(HKEY("msgheaders"), "", 0, display_headers, NEED_URL);
1842 WebcitAddUrlHandler(HKEY("mimepart"), "", 0, view_mimepart, NEED_URL);
1843 WebcitAddUrlHandler(HKEY("mimepart_download"), "", 0, download_mimepart, NEED_URL);
1844 WebcitAddUrlHandler(HKEY("postpart"), "", 0, view_postpart, NEED_URL|PROHIBIT_STARTPAGE);
1845 WebcitAddUrlHandler(HKEY("postpart_download"), "", 0, download_postpart, NEED_URL|PROHIBIT_STARTPAGE);
1846 WebcitAddUrlHandler(HKEY("upload_attachment"), "", 0, upload_attachment, AJAX);
1847 WebcitAddUrlHandler(HKEY("remove_attachment"), "", 0, remove_attachment, AJAX);
1848 WebcitAddUrlHandler(HKEY("show_num_attachments"), "", 0, show_num_attachments, AJAX);
1851 WebcitAddUrlHandler(HKEY("roommsgs"), "", 0, jsonMessageList,0);
1856 SessionDetachModule_MSG
1859 DeleteHash(&sess->summ);