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,
58 if (Msg->PartNum != NULL) {
59 serv_printf("MSG4 %ld|%s", Msg->msgnum, ChrPtr(Msg->PartNum));
62 serv_printf("MSG4 %ld", Msg->msgnum);
65 StrBuf_ServGetln(Buf);
66 if (GetServerStatus(Buf, NULL) != 1) {
68 StrBufAppendPrintf(*Error, "<strong>");
69 StrBufAppendPrintf(*Error, _("ERROR:"));
70 StrBufAppendPrintf(*Error, "</strong> %s<br>\n", &buf[4]);
75 /* begin everythingamundo table */
76 HdrToken = NewStrBuf();
77 while (!Done && StrBuf_ServGetln(Buf)>=0) {
78 if ( (StrLength(Buf)==3) &&
79 !strcmp(ChrPtr(Buf), "000"))
83 if (Msg->MsgBody->Data == NULL)
84 Msg->MsgBody->Data = NewStrBuf();
85 Msg->MsgBody->ContentType = NewStrBufPlain(HKEY("text/html"));
86 StrBufAppendPrintf(Msg->MsgBody->Data, "<div><i>");
87 StrBufAppendPrintf(Msg->MsgBody->Data, _("Empty message"));
88 StrBufAppendPrintf(Msg->MsgBody->Data, "</i><br><br>\n");
89 StrBufAppendPrintf(Msg->MsgBody->Data, "</div>\n");
94 case 0:/* Citadel Message Headers */
95 if (StrLength(Buf) == 0) {
99 StrBufExtract_token(HdrToken, Buf, 0, '=');
100 StrBufCutLeft(Buf, StrLength(HdrToken) + 1);
102 /* look up one of the examine_* functions to parse the content */
103 if (GetHash(MsgHeaderHandler, SKEY(HdrToken), &vHdr) &&
105 Hdr = (headereval*)vHdr;
106 Hdr->evaluator(Msg, Buf, FoundCharset);
107 if (Hdr->Type == 1) {
111 else LogError(Target,
113 "don't know how to handle message header[%s]\n",
117 case 1:/* Message Mime Header */
118 if (StrLength(Buf) == 0) {
120 if (Msg->MsgBody->ContentType == NULL)
121 /* end of header or no header? */
122 Msg->MsgBody->ContentType = NewStrBufPlain(HKEY("text/plain"));
123 /* usual end of mime header */
127 StrBufExtract_token(HdrToken, Buf, 0, ':');
128 if (StrLength(HdrToken) > 0) {
129 StrBufCutLeft(Buf, StrLength(HdrToken) + 1);
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);
164 FreeStrBuf(&HdrToken);
171 * I wanna SEE that message!
173 * msgnum Message number to display
174 * printable_view Nonzero to display a printable view
175 * section Optional for encapsulated message/rfc822 submessage
177 int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, const StrBuf *PartNum, const StrBuf **OutMime)
180 StrBuf *FoundCharset;
183 message_summary *Msg = NULL;
187 WCTemplputParams SubTP;
188 StrBuf *Error = NULL;
191 FoundCharset = NewStrBuf();
192 Msg = (message_summary *)malloc(sizeof(message_summary));
193 memset(Msg, 0, sizeof(message_summary));
194 Msg->msgnum = msgnum;
195 Msg->PartNum = PartNum;
196 Msg->MsgBody = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
197 memset(Msg->MsgBody, 0, sizeof(wc_mime_attachment));
198 Msg->MsgBody->msgnum = msgnum;
200 if (!load_message(Msg, FoundCharset, &Error)) {
201 StrBufAppendBuf(Target, Error, 0);
205 /* Extract just the content-type (omit attributes such as "charset") */
206 StrBufExtract_token(Buf, Msg->MsgBody->ContentType, 0, ';');
208 StrBufLowerCase(Buf);
210 /* Locate a renderer capable of converting this MIME part into HTML */
211 if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
213 RenderMimeFuncStruct *Render;
214 Render = (RenderMimeFuncStruct*)vHdr;
215 Render->f(Msg->MsgBody, NULL, FoundCharset);
218 if (StrLength(Msg->reply_references)> 0) {
219 /* Trim down excessively long lists of thread references. We eliminate the
220 * second one in the list so that the thread root remains intact.
222 int rrtok = num_tokens(ChrPtr(Msg->reply_references), '|');
223 int rrlen = StrLength(Msg->reply_references);
224 if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
225 StrBufRemove_token(Msg->reply_references, 1, '|');
229 /* now check if we need to translate some mimeparts, and remove the duplicate */
230 it = GetNewHashPos(Msg->AllAttach, 0);
231 while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) &&
233 wc_mime_attachment *Mime = (wc_mime_attachment*) vMime;
234 evaluate_mime_part(Msg, Mime);
237 memset(&SubTP, 0, sizeof(WCTemplputParams));
238 SubTP.Filter.ContextType = CTX_MAILSUM;
240 *OutMime = DoTemplate(tmpl, tmpllen, Target, &SubTP);
242 DestroyMessageSummary(Msg);
243 FreeStrBuf(&FoundCharset);
250 HttpStatus(long CitadelStatus)
252 long httpstatus = 502;
254 switch (MAJORCODE(CitadelStatus))
256 case LISTING_FOLLOWS:
261 switch (MINORCODE(CitadelStatus))
269 case HIGHER_ACCESS_REQUIRED:
270 case MAX_SESSIONS_EXCEEDED:
272 case RESOURCE_NOT_OPEN:
274 case INVALID_FLOOR_OPERATION:
280 case MESSAGE_NOT_FOUND:
290 case CMD_NOT_SUPPORTED:
291 case PASSWORD_REQUIRED:
292 case ALREADY_LOGGED_IN:
293 case USERNAME_REQUIRED:
295 case SERVER_SHUTTING_DOWN:
306 case START_CHAT_MODE:
310 httpstatus = 502; /* aeh... whut? */
318 * Unadorned HTML output of an individual message, suitable
319 * for placing in a hidden iframe, for printing, or whatever
321 void handle_one_message(void)
325 const StrBuf *Destination;
331 StrBuf *CmdBuf = NULL;
335 pMsg = strchr(ChrPtr(WCC->Hdr->HR.ReqLine), '/');
337 HttpStatus(CitStatus);
341 msgnum = atol(pMsg + 1);
342 StrBufCutAt(WCC->Hdr->HR.ReqLine, 0, pMsg);
343 gotoroom(WCC->Hdr->HR.ReqLine);
344 switch (WCC->Hdr->HR.eReqType)
348 Tmpl = sbstr("template");
349 if (StrLength(Tmpl) > 0)
350 read_message(WCC->WBuf, SKEY(Tmpl), msgnum, NULL, &Mime);
352 read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
353 http_transmit_thing(ChrPtr(Mime), 0);
356 CmdBuf = NewStrBuf ();
357 if ((WCC->CurRoom.RAFlags & UA_ISTRASH) != 0) { /* Delete from Trash is a real delete */
358 serv_printf("DELE %ld", msgnum);
360 else { /* Otherwise move it to Trash */
361 serv_printf("MOVE %ld|_TRASH_|0", msgnum);
363 StrBuf_ServGetln(CmdBuf);
364 FlushStrBuf(WCC->ImportantMsg);
365 StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
366 GetServerStatus(CmdBuf, &CitStatus);
367 HttpStatus(CitStatus);
372 if (GetHash(WCC->Hdr->HTTPHeaders, HKEY("DESTINATION"), &vLine) &&
374 Destination = (StrBuf*) vLine;
375 serv_printf("MOVE %ld|%s|%d", msgnum, ChrPtr(Destination), CopyMessage);
376 StrBuf_ServGetln(CmdBuf);
377 FlushStrBuf(WCC->ImportantMsg);
378 StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
379 GetServerStatus(CmdBuf, &CitStatus);
380 HttpStatus(CitStatus);
393 * Unadorned HTML output of an individual message, suitable
394 * for placing in a hidden iframe, for printing, or whatever
396 void embed_message(void) {
401 StrBuf *CmdBuf = NULL;
403 msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/');
404 switch (WCC->Hdr->HR.eReqType)
408 Tmpl = sbstr("template");
409 if (StrLength(Tmpl) > 0)
410 read_message(WCC->WBuf, SKEY(Tmpl), msgnum, NULL, &Mime);
412 read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
413 http_transmit_thing(ChrPtr(Mime), 0);
416 CmdBuf = NewStrBuf ();
417 if ((WCC->CurRoom.RAFlags & UA_ISTRASH) != 0) { /* Delete from Trash is a real delete */
418 serv_printf("DELE %ld", msgnum);
420 else { /* Otherwise move it to Trash */
421 serv_printf("MOVE %ld|_TRASH_|0", msgnum);
423 StrBuf_ServGetln(CmdBuf);
424 FlushStrBuf(WCC->ImportantMsg);
425 StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
435 * Printable view of a message
437 void print_message(void) {
441 msgnum = StrBufExtract_long(WC->Hdr->HR.ReqLine, 0, '/');
442 output_headers(0, 0, 0, 0, 0, 0);
444 hprintf("Content-type: text/html\r\n"
445 "Server: " PACKAGE_STRING "\r\n"
446 "Connection: close\r\n");
450 read_message(WC->WBuf, HKEY("view_message_print"), msgnum, NULL, &Mime);
456 * Display a message's headers
458 void display_headers(void) {
462 msgnum = StrBufExtract_long(WC->Hdr->HR.ReqLine, 0, '/');
463 output_headers(0, 0, 0, 0, 0, 0);
465 hprintf("Content-type: text/plain\r\n"
467 "Connection: close\r\n",
471 serv_printf("MSG2 %ld|3", msgnum);
472 serv_getln(buf, sizeof buf);
474 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
475 wc_printf("%s\n", buf);
483 message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSubject, long MsgNum)
486 MsgPartEvaluatorStruct *Eval;
487 message_summary *Msg;
496 serv_printf("MSG0 %ld|1", MsgNum); /* ask for headers only */
498 StrBuf_ServGetln(Buf);
499 if (GetServerStatus(Buf, NULL) == 1) {
504 Msg = (message_summary*)malloc(sizeof(message_summary));
505 memset(Msg, 0, sizeof(message_summary));
506 while (len = StrBuf_ServGetln(Buf),
509 strcmp(ChrPtr(Buf), "000")))
512 ebuf = strchr(ChrPtr(Buf), '=');
514 if (GetHash(MsgEvaluators, buf, nBuf, &vEval) && vEval != NULL) {
515 Eval = (MsgPartEvaluatorStruct*) vEval;
516 StrBufCutLeft(Buf, nBuf + 1);
519 else syslog(1, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
529 * load message pointers from the server for a "read messages" operation
531 * servcmd: the citadel command to send to the citserver
533 int load_msg_ptrs(const char *servcmd,
534 SharedMessageStatus *Stat,
535 load_msg_ptrs_detailheaders LH)
538 message_summary *Msg;
543 const char *Ptr = NULL;
545 Stat->lowest_found = LONG_MAX;
546 Stat->highest_found = LONG_MIN;
548 if (WCC->summ != NULL) {
549 DeleteHash(&WCC->summ);
551 WCC->summ = NewHash(1, Flathash);
555 StrBuf_ServGetln(Buf);
556 if (GetServerStatus(Buf, NULL) != 1) {
558 return (Stat->nummsgs);
561 while (len = StrBuf_ServGetln(Buf),
564 strcmp(ChrPtr(Buf), "000")!= 0)))
566 if (Stat->nummsgs < Stat->maxload) {
569 Msg = (message_summary*)malloc(sizeof(message_summary));
570 memset(Msg, 0, sizeof(message_summary));
572 Msg->msgnum = StrBufExtractNext_long(Buf, &Ptr, '|');
573 Msg->date = StrBufExtractNext_long(Buf, &Ptr, '|');
575 if (Stat->nummsgs == 0) {
576 if (Msg->msgnum < Stat->lowest_found) {
577 Stat->lowest_found = Msg->msgnum;
579 if (Msg->msgnum > Stat->highest_found) {
580 Stat->highest_found = Msg->msgnum;
584 if ((Msg->msgnum == 0) && (StrLength(Buf) < 32)) {
590 * as citserver probably gives us messages in forward date sorting
591 * nummsgs should be the same order as the message date.
593 if (Msg->date == 0) {
594 Msg->date = Stat->nummsgs;
595 if (StrLength(Buf) < 32)
598 if ((!skipit) && (LH != NULL)) {
599 if (!LH(Buf, &Ptr, Msg, Buf2)){
605 Put(WCC->summ, (const char *)&n, sizeof(n), Msg, DestroyMessageSummary);
611 return (Stat->nummsgs);
617 * \brief sets FlagToSet for each of ScanMe that appears in MatchMSet
618 * \param ScanMe List of BasicMsgStruct to be searched it MatchSet
619 * \param MatchMSet MSet we want to flag
620 * \param FlagToSet Flag to set on each BasicMsgStruct->Flags if in MSet
622 void SetFlagsFromMSet(HashList *ScanMe, MSet *MatchMSet, int FlagToSet, int Reverse)
628 message_summary *Msg;
630 at = GetNewHashPos(ScanMe, 0);
631 while (GetNextHashPos(ScanMe, at, &HKLen, &HashKey, &vMsg)) {
632 /* Are you a new message, or an old message? */
633 Msg = (message_summary*) vMsg;
634 if (Reverse && IsInMSetList(MatchMSet, Msg->msgnum)) {
635 Msg->Flags = Msg->Flags | FlagToSet;
637 else if (!Reverse && !IsInMSetList(MatchMSet, Msg->msgnum)) {
638 Msg->Flags = Msg->Flags | FlagToSet;
645 void load_seen_flags(void)
651 OldMsg = NewStrBuf();
653 StrBuf_ServGetln(OldMsg);
654 if (GetServerStatus(OldMsg, NULL) == 2) {
655 StrBufCutLeft(OldMsg, 4);
662 if (ParseMSet(&MatchMSet, OldMsg))
664 SetFlagsFromMSet(WCC->summ, MatchMSet, MSGFLAG_READ, 0);
666 DeleteMSet(&MatchMSet);
670 extern readloop_struct rlid[];
672 typedef struct _RoomRenderer{
675 GetParamsGetServerCall_func GetParamsGetServerCall;
676 PrintViewHeader_func PrintViewHeader;
677 LoadMsgFromServer_func LoadMsgFromServer;
678 RenderView_or_Tail_func RenderView_or_Tail;
679 View_Cleanup_func ViewCleanup;
680 load_msg_ptrs_detailheaders LHParse;
685 * command loop for reading messages
687 * Set oper to "readnew" or "readold" or "readfwd" or "headers" or "readgt" or "readlt" or "do_search"
689 void readloop(long oper, eCustomRoomRenderer ForceRenderer)
691 RoomRenderer *ViewMsg;
694 message_summary *Msg;
701 WCTemplputParams SubTP;
702 SharedMessageStatus Stat;
705 if (havebstr("is_summary") && (1 == (ibstr("is_summary")))) {
706 WCC->CurRoom.view = VIEW_MAILBOX;
709 if (havebstr("is_ajax") && (1 == (ibstr("is_ajax")))) {
713 if ((oper == do_search) && (WCC->CurRoom.view == VIEW_WIKI)) {
714 display_wiki_pagelist();
718 if (WCC->CurRoom.view == VIEW_WIKI) {
719 http_redirect("wiki?page=home");
723 memset(&Stat, 0, sizeof(SharedMessageStatus));
724 Stat.maxload = 10000;
725 Stat.lowest_found = (-1);
726 Stat.highest_found = (-1);
727 if (ForceRenderer == eUseDefault)
728 GetHash(ReadLoopHandler, IKEY(WCC->CurRoom.view), &vViewMsg);
730 GetHash(ReadLoopHandler, IKEY(ForceRenderer), &vViewMsg);
731 if (vViewMsg == NULL) {
732 WCC->CurRoom.view = VIEW_BBS;
733 GetHash(ReadLoopHandler, IKEY(WCC->CurRoom.view), &vViewMsg);
735 if (vViewMsg == NULL) {
736 return; // TODO: print message
739 ViewMsg = (RoomRenderer*) vViewMsg;
741 output_headers(1, 1, 1, 0, 0, 0);
742 } else if (WCC->CurRoom.view == VIEW_MAILBOX) {
743 jsonMessageListHdr();
746 if (ViewMsg->GetParamsGetServerCall != NULL) {
747 r = ViewMsg->GetParamsGetServerCall(
762 case 300: /* the callback hook should do the work for us here, since he knows what to do. */
768 if (!IsEmptyStr(cmd))
769 Stat.nummsgs = load_msg_ptrs(cmd, &Stat, ViewMsg->LHParse);
773 memset(&SubTP, 0, sizeof(WCTemplputParams));
774 SubTP.Filter.ContextType = CTX_MAILSUM;
775 SubTP.Context = NULL;
776 SortIt = RetrieveSort(&SubTP, NULL, 0,
777 HKEY("date"), Stat.defaultsortorder);
779 SortByPayload(WCC->summ, SortIt);
781 if (Stat.startmsg < 0) {
785 if (Stat.load_seen) load_seen_flags();
788 * Print any inforation above the message list...
790 if (ViewMsg->PrintViewHeader != NULL)
791 ViewMsg->PrintViewHeader(&Stat, &ViewSpecific);
793 WCC->startmsg = Stat.startmsg;
794 WCC->maxmsgs = Stat.maxmsgs;
795 WCC->num_displayed = 0;
797 /* Put some helpful data in vars for mailsummary_json */
802 StrBufPrintf(Foo, "%ld", Stat.nummsgs);
803 PutBstr(HKEY("__READLOOP:TOTALMSGS"), NewStrBufDup(Foo));
804 StrBufPrintf(Foo, "%ld", Stat.startmsg);
805 PutBstr(HKEY("__READLOOP:STARTMSG"), Foo);
809 * iterate over each message. if we need to load an attachment, do it here.
812 if ((ViewMsg->LoadMsgFromServer != NULL) &&
815 at = GetNewHashPos(WCC->summ, 0);
816 Stat.num_displayed = i = 0;
817 while ( GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
818 Msg = (message_summary*) vMsg;
819 if ((Msg->msgnum >= Stat.startmsg) && (Stat.num_displayed <= Stat.maxmsgs)) {
820 ViewMsg->LoadMsgFromServer(&Stat,
823 (Msg->Flags & MSGFLAG_READ) != 0,
832 * Done iterating the message list. now tasks we want to do after.
834 if (ViewMsg->RenderView_or_Tail != NULL)
835 ViewMsg->RenderView_or_Tail(&Stat, &ViewSpecific, oper);
837 if (ViewMsg->ViewCleanup != NULL)
838 ViewMsg->ViewCleanup(&ViewSpecific);
842 if (WCC->summ != NULL) {
843 DeleteHash(&WCC->summ);
849 * Back end for post_message()
850 * ... this is where the actual message gets transmitted to the server.
852 void post_mime_to_server(void) {
854 char top_boundary[SIZ];
855 char alt_boundary[SIZ];
856 int is_multipart = 0;
858 wc_mime_attachment *att;
860 size_t encoded_length;
861 size_t encoded_strlen;
862 char *txtmail = NULL;
863 int include_text_alt = 0; /* Set to nonzero to include multipart/alternative text/plain */
865 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
866 ChrPtr(WCC->serv_info->serv_fqdn),
870 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
871 ChrPtr(WCC->serv_info->serv_fqdn),
876 /* RFC2045 requires this, and some clients look for it... */
877 serv_puts("MIME-Version: 1.0");
878 serv_puts("X-Mailer: " PACKAGE_STRING);
880 /* If there are attachments, we have to do multipart/mixed */
881 if (GetCount(WCC->attachments) > 0) {
885 /* Only do multipart/alternative for mailboxes. BBS and Wiki rooms don't need it. */
886 if (WC->CurRoom.view == VIEW_MAILBOX) {
887 include_text_alt = 1;
891 /* Remember, serv_printf() appends an extra newline */
892 serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
893 serv_printf("This is a multipart message in MIME format.\n");
894 serv_printf("--%s", top_boundary);
897 /* Remember, serv_printf() appends an extra newline */
898 if (include_text_alt) {
899 serv_printf("Content-type: multipart/alternative; "
900 "boundary=\"%s\"\n", alt_boundary);
901 serv_printf("This is a multipart message in MIME format.\n");
902 serv_printf("--%s", alt_boundary);
904 serv_puts("Content-type: text/plain; charset=utf-8");
905 serv_puts("Content-Transfer-Encoding: quoted-printable");
907 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
908 text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */
911 serv_printf("\n--%s", alt_boundary);
914 serv_puts("Content-type: text/html; charset=utf-8");
915 serv_puts("Content-Transfer-Encoding: quoted-printable");
917 serv_puts("<html><body>\r\n");
918 text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */
919 serv_puts("</body></html>\r\n");
921 if (include_text_alt) {
922 serv_printf("--%s--", alt_boundary);
931 /* Add in the attachments */
932 it = GetNewHashPos(WCC->attachments, 0);
933 while (GetNextHashPos(WCC->attachments, it, &len, &Key, &vAtt)) {
934 att = (wc_mime_attachment *)vAtt;
935 if (att->length == 0)
937 encoded_length = ((att->length * 150) / 100);
938 encoded = malloc(encoded_length);
939 if (encoded == NULL) break;
940 encoded_strlen = CtdlEncodeBase64(encoded, ChrPtr(att->Data), StrLength(att->Data), 1);
942 serv_printf("--%s", top_boundary);
943 serv_printf("Content-type: %s", ChrPtr(att->ContentType));
944 serv_printf("Content-disposition: attachment; filename=\"%s\"", ChrPtr(att->FileName));
945 serv_puts("Content-transfer-encoding: base64");
947 serv_write(encoded, encoded_strlen);
952 serv_printf("--%s--", top_boundary);
961 * Post message (or don't post message)
963 * Note regarding the "dont_post" variable:
964 * A random value (actually, it's just a timestamp) is inserted as a hidden
965 * field called "postseq" when the display_enter page is generated. This
966 * value is checked when posting, using the static variable dont_post. If a
967 * user attempts to post twice using the same dont_post value, the message is
968 * discarded. This prevents the accidental double-saving of the same message
969 * if the user happens to click the browser "back" button.
971 void post_message(void)
974 StrBuf *EmailAddress;
977 StrBuf *encoded_subject = NULL;
978 static long dont_post = (-1L);
979 int is_anonymous = 0;
980 const StrBuf *display_name = NULL;
984 if (havebstr("force_room")) {
985 gotoroom(sbstr("force_room"));
988 if (havebstr("display_name")) {
989 display_name = sbstr("display_name");
990 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
996 if (!strcasecmp(bstr("submit_action"), "cancel")) {
997 sprintf(WCC->ImportantMessage,
998 _("Cancelled. Message was not posted."));
999 } else if (lbstr("postseq") == dont_post) {
1000 sprintf(WCC->ImportantMessage,
1001 _("Automatically cancelled because you have already "
1002 "saved this message."));
1004 const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s";
1005 StrBuf *Recp = NULL;
1008 const StrBuf *Wikipage = NULL;
1009 const StrBuf *my_email_addr = NULL;
1010 StrBuf *CmdBuf = NULL;
1011 StrBuf *references = NULL;
1015 save_to_drafts = !strcasecmp(bstr("submit_action"), "drafts");
1018 if (save_to_drafts) {
1019 /* temporarily change to the drafts room */
1020 serv_puts("GOTO _DRAFTS_");
1021 StrBuf_ServGetln(Buf);
1022 if (GetServerStatus(Buf, NULL) != 2) {
1023 /* You probably don't even have a dumb Drafts folder */
1024 StrBufCutLeft(Buf, 4);
1025 syslog(9, "%s:%d: server save to drafts error: %s\n", __FILE__, __LINE__, ChrPtr(Buf));
1026 StrBufAppendBufPlain(WCC->ImportantMsg, _("Saved to Drafts failed: "), -1, 0);
1027 StrBufAppendBuf(WCC->ImportantMsg, Buf, 0);
1034 if (havebstr("references"))
1036 const StrBuf *ref = sbstr("references");
1037 references = NewStrBufDup(ref);
1038 if (*ChrPtr(references) == '|') { /* remove leading '|' if present */
1039 StrBufCutLeft(references, 1);
1041 StrBufReplaceChars(references, '|', '!');
1043 if (havebstr("subject")) {
1046 * make enough room for the encoded string;
1047 * plus the QP header
1049 Subj = sbstr("subject");
1051 StrBufRFC2047encode(&encoded_subject, Subj);
1053 UserName = NewStrBuf();
1054 EmailAddress = NewStrBuf();
1055 EncBuf = NewStrBuf();
1057 Recp = StrBufSanitizeEmailRecipientVector(sbstr("recp"), UserName, EmailAddress, EncBuf);
1058 Cc = StrBufSanitizeEmailRecipientVector(sbstr("cc"), UserName, EmailAddress, EncBuf);
1059 Bcc = StrBufSanitizeEmailRecipientVector(sbstr("bcc"), UserName, EmailAddress, EncBuf);
1061 FreeStrBuf(&UserName);
1062 FreeStrBuf(&EmailAddress);
1063 FreeStrBuf(&EncBuf);
1065 Wikipage = sbstr("page");
1066 my_email_addr = sbstr("my_email_addr");
1068 HeaderLen = StrLength(Recp) +
1069 StrLength(encoded_subject) +
1072 StrLength(Wikipage) +
1073 StrLength(my_email_addr) +
1074 StrLength(references);
1075 CmdBuf = NewStrBufPlain(NULL, sizeof (CMD) + HeaderLen);
1076 StrBufPrintf(CmdBuf,
1078 save_to_drafts?"":ChrPtr(Recp),
1080 ChrPtr(encoded_subject),
1081 ChrPtr(display_name),
1082 save_to_drafts?"":ChrPtr(Cc),
1083 save_to_drafts?"":ChrPtr(Bcc),
1085 ChrPtr(my_email_addr),
1086 ChrPtr(references));
1087 FreeStrBuf(&references);
1088 FreeStrBuf(&encoded_subject);
1090 if ((HeaderLen + StrLength(sbstr("msgtext")) < 10) &&
1091 (GetCount(WCC->attachments) == 0)){
1092 StrBufAppendBufPlain(WCC->ImportantMsg, _("Refusing to post empty message.\n"), -1, 0);
1093 FreeStrBuf(&CmdBuf);
1098 syslog(9, "%s\n", ChrPtr(CmdBuf));
1099 serv_puts(ChrPtr(CmdBuf));
1100 FreeStrBuf(&CmdBuf);
1102 StrBuf_ServGetln(Buf);
1103 if (GetServerStatus(Buf, NULL) == 4) {
1104 if (save_to_drafts) {
1105 if ( (havebstr("recp"))
1106 || (havebstr("cc" ))
1107 || (havebstr("bcc" )) ) {
1108 /* save recipient headers or room to post to */
1109 serv_printf("To: %s", ChrPtr(Recp));
1110 serv_printf("Cc: %s", ChrPtr(Cc));
1111 serv_printf("Bcc: %s", ChrPtr(Bcc));
1113 serv_printf("X-Citadel-Room: %s", ChrPtr(WC->CurRoom.name));
1116 post_mime_to_server();
1117 if (save_to_drafts) {
1118 StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been saved to Drafts.\n"), -1, 0);
1119 gotoroom(WCC->CurRoom.name);
1123 } else if ( (havebstr("recp"))
1124 || (havebstr("cc" ))
1125 || (havebstr("bcc" ))
1127 StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been sent.\n"), -1, 0);
1130 StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been posted.\n"), -1, 0);
1132 dont_post = lbstr("postseq");
1134 StrBufCutLeft(Buf, 4);
1136 syslog(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, ChrPtr(Buf));
1137 StrBufAppendBuf(WCC->ImportantMsg, Buf, 0);
1138 if (save_to_drafts) gotoroom(WCC->CurRoom.name);
1152 DeleteHash(&WCC->attachments);
1155 * We may have been supplied with instructions regarding the location
1156 * to which we must return after posting. If found, go there.
1158 if (havebstr("return_to")) {
1159 http_redirect(bstr("return_to"));
1162 * If we were editing a page in a wiki room, go to that page now.
1164 else if (havebstr("page")) {
1165 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("page"));
1169 * Otherwise, just go to the "read messages" loop.
1172 readloop(readnew, eUseDefault);
1178 * Client is uploading an attachment
1180 void upload_attachment(void) {
1181 wcsession *WCC = WC;
1187 wc_mime_attachment *att;
1189 syslog(9, "upload_attachment()\n");
1190 wc_printf("upload_attachment()<br>\n");
1192 if (WCC->upload_length <= 0) {
1193 syslog(9, "ERROR no attachment was uploaded\n");
1194 wc_printf("ERROR no attachment was uploaded<br>\n");
1198 syslog(9, "Client is uploading %d bytes\n", WCC->upload_length);
1199 wc_printf("Client is uploading %d bytes<br>\n", WCC->upload_length);
1200 att = malloc(sizeof(wc_mime_attachment));
1201 memset(att, 0, sizeof(wc_mime_attachment ));
1202 att->length = WCC->upload_length;
1203 att->ContentType = NewStrBufPlain(WCC->upload_content_type, -1);
1204 att->FileName = NewStrBufDup(WCC->upload_filename);
1206 if (WCC->attachments == NULL) {
1207 WCC->attachments = NewHash(1, Flathash);
1210 /* And add it to the list. */
1212 if ((GetCount(WCC->attachments) > 0) &&
1213 GetHashAt(WCC->attachments,
1214 GetCount(WCC->attachments) -1,
1215 &newnlen, &newn, &v))
1216 n = *((int*) newn) + 1;
1217 Put(WCC->attachments, IKEY(n), att, DestroyMime);
1220 * Mozilla sends a simple filename, which is what we want,
1221 * but Satan's Browser sends an entire pathname. Reduce
1222 * the path to just a filename if we need to.
1224 pch = strrchr(ChrPtr(att->FileName), '/');
1226 StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1);
1228 pch = strrchr(ChrPtr(att->FileName), '\\');
1230 StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1);
1234 * Transfer control of this memory from the upload struct
1235 * to the attachment struct.
1237 att->Data = WCC->upload;
1239 WCC->upload_length = 0;
1244 * Remove an attachment from the message currently being composed.
1246 * Currently we identify the attachment to be removed by its filename.
1247 * There is probably a better way to do this.
1249 void remove_attachment(void) {
1250 wcsession *WCC = WC;
1251 wc_mime_attachment *att;
1253 StrBuf *WhichAttachment;
1258 WhichAttachment = NewStrBufDup(sbstr("which_attachment"));
1259 StrBufUnescape(WhichAttachment, 0);
1260 at = GetNewHashPos(WCC->attachments, 0);
1262 GetHashPos(WCC->attachments, at, &len, &key, &vAtt);
1264 att = (wc_mime_attachment*) vAtt;
1265 if ((att != NULL) &&
1266 (strcmp(ChrPtr(WhichAttachment),
1267 ChrPtr(att->FileName) ) == 0))
1269 DeleteEntryFromHash(WCC->attachments, at);
1273 while (NextHashPos(WCC->attachments, at));
1274 FreeStrBuf(&WhichAttachment);
1275 wc_printf("remove_attachment() completed\n");
1280 * display the message entry screen
1282 void display_enter(void)
1286 const StrBuf *display_name = NULL;
1287 int recipient_required = 0;
1288 int subject_required = 0;
1289 int recipient_bad = 0;
1290 int is_anonymous = 0;
1291 wcsession *WCC = WC;
1295 if (havebstr("force_room")) {
1296 gotoroom(sbstr("force_room"));
1299 display_name = sbstr("display_name");
1300 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
1301 display_name = NULL;
1305 /* First test to see whether this is a room that requires recipients to be entered */
1306 serv_puts("ENT0 0");
1307 serv_getln(buf, sizeof buf);
1309 if (!strncmp(buf, "570", 3)) { /* 570 means that we need a recipient here */
1310 recipient_required = 1;
1312 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
1313 sprintf(WCC->ImportantMessage, "%s", &buf[4]);
1314 readloop(readnew, eUseDefault);
1318 /* Is the server strongly recommending that the user enter a message subject? */
1319 if ((buf[3] != '\0') && (buf[4] != '\0')) {
1320 subject_required = extract_int(&buf[4], 1);
1324 * Are we perhaps in an address book view? If so, then an "enter
1325 * message" command really means "add new entry."
1327 if (WCC->CurRoom.defview == VIEW_ADDRESSBOOK) {
1328 do_edit_vcard(-1, "", NULL, NULL, "", ChrPtr(WCC->CurRoom.name));
1333 * Are we perhaps in a calendar room? If so, then an "enter
1334 * message" command really means "add new calendar item."
1336 if (WCC->CurRoom.defview == VIEW_CALENDAR) {
1337 display_edit_event();
1342 * Are we perhaps in a tasks view? If so, then an "enter
1343 * message" command really means "add new task."
1345 if (WCC->CurRoom.defview == VIEW_TASKS) {
1346 display_edit_task();
1352 * If the "replying_to" variable is set, it refers to a message
1353 * number from which we must extract some header fields...
1355 long replying_to = lbstr("replying_to");
1356 if (replying_to > 0) {
1357 char wefw[1024] = "";
1358 char msgn[1024] = "";
1359 serv_printf("MSG0 %ld|1", replying_to);
1360 serv_getln(buf, sizeof buf);
1361 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1363 if ( (!strncasecmp(buf, "subj=", 5)) && (strlen(buf) > 5) ) {
1364 StrBuf *subj = NewStrBuf();
1365 if (strncasecmp(&buf[5], "Re:", 3)) {
1366 StrBufAppendBufPlain(subj, HKEY("Re: "), 0);
1368 StrBufAppendBufPlain(subj, &buf[5], -1, 0);
1369 PutBstr(HKEY("subject"), subj);
1372 else if (!strncasecmp(buf, "wefw=", 5)) {
1373 safestrncpy(wefw, &buf[5], sizeof wefw);
1375 /* Trim down excessively long lists of thread references. We eliminate the
1376 * second one in the list so that the thread root remains intact.
1378 int rrtok = num_tokens(wefw, '|');
1379 int rrlen = strlen(wefw);
1380 if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
1381 remove_token(wefw, 1, '|');
1385 else if (!strncasecmp(buf, "msgn=", 5)) {
1386 safestrncpy(msgn, &buf[5], sizeof msgn);
1391 if (strlen(wefw) + strlen(msgn) > 0) {
1392 StrBuf *refs = NewStrBuf();
1393 if (!IsEmptyStr(wefw)) {
1394 StrBufAppendBufPlain(refs, wefw, -1, 0);
1396 if ( (!IsEmptyStr(wefw)) && (!IsEmptyStr(msgn)) ) {
1397 StrBufAppendBufPlain(refs, HKEY("|"), 0);
1399 if (!IsEmptyStr(msgn)) {
1400 StrBufAppendBufPlain(refs, msgn, -1, 0);
1402 PutBstr(HKEY("references"), refs);
1407 * Otherwise proceed normally.
1408 * Do a custom room banner with no navbar...
1411 if (recipient_required) {
1412 const StrBuf *Recp = NULL;
1413 const StrBuf *Cc = NULL;
1414 const StrBuf *Bcc = NULL;
1415 const StrBuf *Wikipage = NULL;
1416 StrBuf *CmdBuf = NULL;
1417 const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
1419 Recp = sbstr("recp");
1422 Wikipage = sbstr("page");
1424 CmdBuf = NewStrBufPlain(NULL,
1427 StrLength(display_name) +
1430 StrLength(Wikipage));
1432 StrBufPrintf(CmdBuf,
1436 ChrPtr(display_name),
1440 serv_puts(ChrPtr(CmdBuf));
1441 serv_getln(buf, sizeof buf);
1442 FreeStrBuf(&CmdBuf);
1444 if (!strncmp(buf, "570", 3)) { /* 570 means we have an invalid recipient listed */
1445 if (havebstr("recp") &&
1451 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
1452 wc_printf("<em>%s</em><br>\n", &buf[4]); /* TODO -> important message */
1456 if (recipient_required)
1457 PutBstr(HKEY("__RCPTREQUIRED"), NewStrBufPlain(HKEY("1")));
1458 if (recipient_required || subject_required)
1459 PutBstr(HKEY("__SUBJREQUIRED"), NewStrBufPlain(HKEY("1")));
1462 output_headers(1, 0, 0, 0, 1, 0);
1463 DoTemplate(HKEY("edit_message"), NULL, &NoCtx);
1472 void delete_msg(void)
1477 msgid = lbstr("msgid");
1479 if ((WC->CurRoom.RAFlags & UA_ISTRASH) != 0) { /* Delete from Trash is a real delete */
1480 serv_printf("DELE %ld", msgid);
1482 else { /* Otherwise move it to Trash */
1483 serv_printf("MOVE %ld|_TRASH_|0", msgid);
1486 serv_getln(buf, sizeof buf);
1487 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1488 readloop(readnew, eUseDefault);
1493 * move a message to another room
1500 msgid = lbstr("msgid");
1502 if (havebstr("move_button")) {
1503 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
1505 serv_getln(buf, sizeof buf);
1506 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1508 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
1511 readloop(readnew, eUseDefault);
1516 * Confirm move of a message
1518 void confirm_move_msg(void)
1524 msgid = lbstr("msgid");
1527 output_headers(1, 1, 2, 0, 0, 0);
1528 wc_printf("<div id=\"banner\">\n");
1530 wc_printf(_("Confirm move of message"));
1532 wc_printf("</div>\n");
1534 wc_printf("<div id=\"content\" class=\"service\">\n");
1536 wc_printf("<CENTER>");
1538 wc_printf(_("Move this message to:"));
1539 wc_printf("<br>\n");
1541 wc_printf("<form METHOD=\"POST\" action=\"move_msg\">\n");
1542 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1543 wc_printf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
1545 wc_printf("<SELECT NAME=\"target_room\" SIZE=5>\n");
1547 serv_getln(buf, sizeof buf);
1548 if (buf[0] == '1') {
1549 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1550 extract_token(targ, buf, 0, '|', sizeof targ);
1551 wc_printf("<OPTION>");
1556 wc_printf("</SELECT>\n");
1557 wc_printf("<br>\n");
1559 wc_printf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
1560 wc_printf(" ");
1561 wc_printf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
1562 wc_printf("</form></CENTER>\n");
1564 wc_printf("</CENTER>\n");
1570 * Generic function to output an arbitrary MIME attachment from
1571 * message being composed
1573 * partnum The MIME part to be output
1574 * filename Fake filename to give
1575 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
1577 void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
1580 StrBuf *content_type;
1581 wc_mime_attachment *part;
1584 i = StrToi(partnum);
1585 if (GetHash(WC->attachments, IKEY(i), &vPart) &&
1587 part = (wc_mime_attachment*) vPart;
1588 if (force_download) {
1589 content_type = NewStrBufPlain(HKEY("application/octet-stream"));
1592 content_type = NewStrBufDup(part->ContentType);
1594 StrBufAppendBuf(WC->WBuf, part->Data, 0);
1595 http_transmit_thing(ChrPtr(content_type), 0);
1597 hprintf("HTTP/1.1 404 %s\n", ChrPtr(partnum));
1598 output_headers(0, 0, 0, 0, 0, 0);
1599 hprintf("Content-Type: text/plain\r\n");
1601 wc_printf(_("An error occurred while retrieving this part: %s/%s\n"),
1602 ChrPtr(partnum), ChrPtr(filename));
1605 FreeStrBuf(&content_type);
1610 * Generic function to output an arbitrary MIME part from an arbitrary
1611 * message number on the server.
1613 * msgnum Number of the item on the citadel server
1614 * partnum The MIME part to be output
1615 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
1617 void mimepart(int force_download)
1621 wcsession *WCC = WC;
1624 StrBuf *ContentType = NewStrBufPlain(HKEY("application/octet-stream"));
1627 att = Buf = NewStrBuf();
1628 msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/');
1629 StrBufExtract_token(att, WCC->Hdr->HR.ReqLine, 1, '/');
1631 serv_printf("OPNA %ld|%s", msgnum, ChrPtr(att));
1632 StrBuf_ServGetln(Buf);
1633 if (GetServerStatus(Buf, NULL) == 2) {
1634 StrBufCutLeft(Buf, 4);
1635 bytes = StrBufExtract_long(Buf, 0, '|');
1636 if (!force_download) {
1637 StrBufExtract_token(ContentType, Buf, 3, '|');
1640 serv_read_binary(WCC->WBuf, bytes, Buf);
1642 StrBuf_ServGetln(Buf);
1643 CT = ChrPtr(ContentType);
1645 if (!force_download) {
1646 if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
1647 StrBufExtract_token(Buf, WCC->Hdr->HR.ReqLine, 2, '/');
1648 CT = GuessMimeByFilename(SKEY(Buf));
1650 if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
1651 CT = GuessMimeType(SKEY(WCC->WBuf));
1654 http_transmit_thing(CT, 0);
1656 StrBufCutLeft(Buf, 4);
1657 hprintf("HTTP/1.1 404 %s\n", ChrPtr(Buf));
1658 output_headers(0, 0, 0, 0, 0, 0);
1659 hprintf("Content-Type: text/plain\r\n");
1661 wc_printf(_("An error occurred while retrieving this part: %s\n"),
1665 FreeStrBuf(&ContentType);
1671 * Read any MIME part of a message, from the server, into memory.
1673 StrBuf *load_mimepart(long msgnum, char *partnum)
1679 serv_printf("DLAT %ld|%s", msgnum, partnum);
1680 StrBuf_ServGetln(Buf);
1681 if (GetServerStatus(Buf, NULL) == 6) {
1682 StrBufCutLeft(Buf, 4);
1683 bytes = StrBufExtract_long(Buf, 0, '|');
1686 StrBuf_ServGetBLOBBuffered(Buf, bytes);
1696 * Read any MIME part of a message, from the server, into memory.
1698 void MimeLoadData(wc_mime_attachment *Mime)
1703 /* TODO: is there a chance the content type is different from the one we know? */
1705 serv_printf("DLAT %ld|%s", Mime->msgnum, ChrPtr(Mime->PartNum));
1707 StrBuf_ServGetln(Buf);
1708 if (GetServerStatus(Buf, NULL) == 6) {
1709 Ptr = &(ChrPtr(Buf)[4]);
1710 bytes = StrBufExtractNext_long(Buf, &Ptr, '|');
1711 StrBufSkip_NTokenS(Buf, &Ptr, '|', 3); /* filename, cbtype, mimetype */
1712 if (Mime->Charset == NULL) Mime->Charset = NewStrBuf();
1713 StrBufExtract_NextToken(Mime->Charset, Buf, &Ptr, '|');
1715 if (Mime->Data == NULL)
1716 Mime->Data = NewStrBufPlain(NULL, bytes);
1717 StrBuf_ServGetBLOBBuffered(Mime->Data, bytes);
1720 FlushStrBuf(Mime->Data);
1721 /* TODO XImportant message */
1727 void view_mimepart(void) {
1731 void download_mimepart(void) {
1735 void view_postpart(void) {
1736 StrBuf *filename = NewStrBuf();
1737 StrBuf *partnum = NewStrBuf();
1739 StrBufExtract_token(partnum, WC->Hdr->HR.ReqLine, 0, '/');
1740 StrBufExtract_token(filename, WC->Hdr->HR.ReqLine, 1, '/');
1742 postpart(partnum, filename, 0);
1744 FreeStrBuf(&filename);
1745 FreeStrBuf(&partnum);
1748 void download_postpart(void) {
1749 StrBuf *filename = NewStrBuf();
1750 StrBuf *partnum = NewStrBuf();
1752 StrBufExtract_token(partnum, WC->Hdr->HR.ReqLine, 0, '/');
1753 StrBufExtract_token(filename, WC->Hdr->HR.ReqLine, 1, '/');
1755 postpart(partnum, filename, 1);
1757 FreeStrBuf(&filename);
1758 FreeStrBuf(&partnum);
1763 void show_num_attachments(void) {
1764 wc_printf("%d", GetCount(WC->attachments));
1768 void h_readnew(void) { readloop(readnew, eUseDefault);}
1769 void h_readold(void) { readloop(readold, eUseDefault);}
1770 void h_readfwd(void) { readloop(readfwd, eUseDefault);}
1771 void h_headers(void) { readloop(headers, eUseDefault);}
1772 void h_do_search(void) { readloop(do_search, eUseDefault);}
1773 void h_readgt(void) { readloop(readgt, eUseDefault);}
1774 void h_readlt(void) { readloop(readlt, eUseDefault);}
1776 void jsonMessageListHdr(void)
1778 /* TODO: make a generic function */
1779 hprintf("HTTP/1.1 200 OK\r\n");
1780 hprintf("Content-type: application/json; charset=utf-8\r\n");
1781 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
1782 hprintf("Connection: close\r\n");
1783 hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
1788 /* Output message list in JSON format */
1789 void jsonMessageList(void) {
1790 const StrBuf *room = sbstr("room");
1791 long oper = (havebstr("query")) ? do_search : readnew;
1794 readloop(oper, eUseDefault);
1798 void RegisterReadLoopHandlerset(
1800 GetParamsGetServerCall_func GetParamsGetServerCall,
1801 PrintViewHeader_func PrintViewHeader,
1802 load_msg_ptrs_detailheaders LH,
1803 LoadMsgFromServer_func LoadMsgFromServer,
1804 RenderView_or_Tail_func RenderView_or_Tail,
1805 View_Cleanup_func ViewCleanup
1808 RoomRenderer *Handler;
1810 Handler = (RoomRenderer*) malloc(sizeof(RoomRenderer));
1812 Handler->RoomType = RoomType;
1813 Handler->GetParamsGetServerCall = GetParamsGetServerCall;
1814 Handler->PrintViewHeader = PrintViewHeader;
1815 Handler->LoadMsgFromServer = LoadMsgFromServer;
1816 Handler->RenderView_or_Tail = RenderView_or_Tail;
1817 Handler->ViewCleanup = ViewCleanup;
1818 Handler->LHParse = LH;
1820 Put(ReadLoopHandler, IKEY(RoomType), Handler, NULL);
1827 RegisterPreference("use_sig",
1828 _("Attach signature to email messages?"),
1831 RegisterPreference("signature", _("Use this signature:"), PRF_QP_STRING, NULL);
1832 RegisterPreference("default_header_charset",
1833 _("Default character set for email headers:"),
1836 RegisterPreference("defaultfrom", _("Preferred email address"), PRF_STRING, NULL);
1837 RegisterPreference("defaultname",
1838 _("Preferred display name for email messages"),
1841 RegisterPreference("defaulthandle",
1842 _("Preferred display name for bulletin board posts"),
1845 RegisterPreference("mailbox",_("Mailbox view mode"), PRF_STRING, NULL);
1847 WebcitAddUrlHandler(HKEY("readnew"), "", 0, h_readnew, ANONYMOUS|NEED_URL);
1848 WebcitAddUrlHandler(HKEY("readold"), "", 0, h_readold, ANONYMOUS|NEED_URL);
1849 WebcitAddUrlHandler(HKEY("readfwd"), "", 0, h_readfwd, ANONYMOUS|NEED_URL);
1850 WebcitAddUrlHandler(HKEY("headers"), "", 0, h_headers, NEED_URL);
1851 WebcitAddUrlHandler(HKEY("readgt"), "", 0, h_readgt, ANONYMOUS|NEED_URL);
1852 WebcitAddUrlHandler(HKEY("readlt"), "", 0, h_readlt, ANONYMOUS|NEED_URL);
1853 WebcitAddUrlHandler(HKEY("do_search"), "", 0, h_do_search, 0);
1854 WebcitAddUrlHandler(HKEY("display_enter"), "", 0, display_enter, 0);
1855 WebcitAddUrlHandler(HKEY("post"), "", 0, post_message, PROHIBIT_STARTPAGE);
1856 WebcitAddUrlHandler(HKEY("move_msg"), "", 0, move_msg, PROHIBIT_STARTPAGE);
1857 WebcitAddUrlHandler(HKEY("delete_msg"), "", 0, delete_msg, PROHIBIT_STARTPAGE);
1858 WebcitAddUrlHandler(HKEY("confirm_move_msg"), "", 0, confirm_move_msg, PROHIBIT_STARTPAGE);
1859 WebcitAddUrlHandler(HKEY("msg"), "", 0, embed_message, NEED_URL);
1860 WebcitAddUrlHandler(HKEY("message"), "", 0, handle_one_message, NEED_URL|XHTTP_COMMANDS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
1861 WebcitAddUrlHandler(HKEY("printmsg"), "", 0, print_message, NEED_URL);
1862 WebcitAddUrlHandler(HKEY("msgheaders"), "", 0, display_headers, NEED_URL);
1864 WebcitAddUrlHandler(HKEY("mimepart"), "", 0, view_mimepart, NEED_URL);
1865 WebcitAddUrlHandler(HKEY("mimepart_download"), "", 0, download_mimepart, NEED_URL);
1866 WebcitAddUrlHandler(HKEY("postpart"), "", 0, view_postpart, NEED_URL|PROHIBIT_STARTPAGE);
1867 WebcitAddUrlHandler(HKEY("postpart_download"), "", 0, download_postpart, NEED_URL|PROHIBIT_STARTPAGE);
1868 WebcitAddUrlHandler(HKEY("upload_attachment"), "", 0, upload_attachment, AJAX);
1869 WebcitAddUrlHandler(HKEY("remove_attachment"), "", 0, remove_attachment, AJAX);
1870 WebcitAddUrlHandler(HKEY("show_num_attachments"), "", 0, show_num_attachments, AJAX);
1873 WebcitAddUrlHandler(HKEY("roommsgs"), "", 0, jsonMessageList,0);
1878 SessionDetachModule_MSG
1881 DeleteHash(&sess->summ);