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);
103 /* look up one of the examine_* functions to parse the content */
104 if (GetHash(MsgHeaderHandler, SKEY(HdrToken), &vHdr) &&
106 Hdr = (headereval*)vHdr;
107 Hdr->evaluator(Msg, Buf, FoundCharset);
108 if (Hdr->Type == 1) {
112 else LogError(Target,
114 "don't know how to handle message header[%s]\n",
118 case 1:/* Message Mime Header */
119 if (StrLength(Buf) == 0) {
121 if (Msg->MsgBody->ContentType == NULL)
122 /* end of header or no header? */
123 Msg->MsgBody->ContentType = NewStrBufPlain(HKEY("text/plain"));
124 /* usual end of mime header */
128 StrBufExtract_token(HdrToken, Buf, 0, ':');
129 if (StrLength(HdrToken) > 0) {
130 StrBufCutLeft(Buf, StrLength(HdrToken) + 1);
131 /* the examine*'s know how to do with mime headers too... */
132 if (GetHash(MsgHeaderHandler, SKEY(HdrToken), &vHdr) &&
134 Hdr = (headereval*)vHdr;
135 Hdr->evaluator(Msg, Buf, FoundCharset);
140 case 2: /* Message Body */
142 if (Msg->MsgBody->size_known > 0) {
143 StrBuf_ServGetBLOBBuffered(Msg->MsgBody->Data, Msg->MsgBody->length);
145 /*/ todo: check next line, if not 000, append following lines */
148 if (StrLength(Msg->MsgBody->Data) > 0)
149 StrBufAppendBufPlain(Msg->MsgBody->Data, "\n", 1, 0);
150 StrBufAppendBuf(Msg->MsgBody->Data, Buf, 0);
154 StrBufAppendBuf(Msg->MsgBody->Data, Buf, 0);
159 if (Msg->AllAttach == NULL)
160 Msg->AllAttach = NewHash(1,NULL);
161 /* now we put the body mimepart we read above into the mimelist */
162 Put(Msg->AllAttach, SKEY(Msg->MsgBody->PartNum), Msg->MsgBody, DestroyMime);
164 /* Generate a reply-to address */
165 if (StrLength(Msg->Rfca) > 0) {
166 if (Msg->reply_to == NULL)
167 Msg->reply_to = NewStrBuf();
168 if (StrLength(Msg->from) > 0) {
169 StrBufPrintf(Msg->reply_to, "%s <%s>", ChrPtr(Msg->from), ChrPtr(Msg->Rfca));
172 FlushStrBuf(Msg->reply_to);
173 StrBufAppendBuf(Msg->reply_to, Msg->Rfca, 0);
178 if ((StrLength(Msg->OtherNode)>0) &&
179 (strcasecmp(ChrPtr(Msg->OtherNode), ChrPtr(WCC->serv_info->serv_nodename))) &&
180 (strcasecmp(ChrPtr(Msg->OtherNode), ChrPtr(WCC->serv_info->serv_humannode)) ))
182 if (Msg->reply_to == NULL)
183 Msg->reply_to = NewStrBuf();
184 StrBufPrintf(Msg->reply_to,
187 ChrPtr(Msg->OtherNode));
190 if (Msg->reply_to == NULL)
191 Msg->reply_to = NewStrBuf();
192 FlushStrBuf(Msg->reply_to);
193 StrBufAppendBuf(Msg->reply_to, Msg->from, 0);
197 FreeStrBuf(&HdrToken);
204 * I wanna SEE that message!
206 * msgnum Message number to display
207 * printable_view Nonzero to display a printable view
208 * section Optional for encapsulated message/rfc822 submessage
210 int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, const StrBuf *PartNum, const StrBuf **OutMime)
213 StrBuf *FoundCharset;
216 message_summary *Msg = NULL;
220 WCTemplputParams SubTP;
221 StrBuf *Error = NULL;
224 FoundCharset = NewStrBuf();
225 Msg = (message_summary *)malloc(sizeof(message_summary));
226 memset(Msg, 0, sizeof(message_summary));
227 Msg->msgnum = msgnum;
228 Msg->PartNum = PartNum;
229 Msg->MsgBody = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
230 memset(Msg->MsgBody, 0, sizeof(wc_mime_attachment));
231 Msg->MsgBody->msgnum = msgnum;
233 if (!load_message(Msg, FoundCharset, &Error)) {
234 StrBufAppendBuf(Target, Error, 0);
238 /* Extract just the content-type (omit attributes such as "charset") */
239 StrBufExtract_token(Buf, Msg->MsgBody->ContentType, 0, ';');
241 StrBufLowerCase(Buf);
243 /* Locate a renderer capable of converting this MIME part into HTML */
244 if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
246 RenderMimeFuncStruct *Render;
247 Render = (RenderMimeFuncStruct*)vHdr;
248 Render->f(Msg->MsgBody, NULL, FoundCharset);
251 if (StrLength(Msg->reply_references)> 0) {
252 /* Trim down excessively long lists of thread references. We eliminate the
253 * second one in the list so that the thread root remains intact.
255 int rrtok = num_tokens(ChrPtr(Msg->reply_references), '|');
256 int rrlen = StrLength(Msg->reply_references);
257 if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
258 StrBufRemove_token(Msg->reply_references, 1, '|');
262 /* now check if we need to translate some mimeparts, and remove the duplicate */
263 it = GetNewHashPos(Msg->AllAttach, 0);
264 while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) &&
266 wc_mime_attachment *Mime = (wc_mime_attachment*) vMime;
267 evaluate_mime_part(Msg, Mime);
270 memset(&SubTP, 0, sizeof(WCTemplputParams));
271 SubTP.Filter.ContextType = CTX_MAILSUM;
273 *OutMime = DoTemplate(tmpl, tmpllen, Target, &SubTP);
275 DestroyMessageSummary(Msg);
276 FreeStrBuf(&FoundCharset);
283 HttpStatus(long CitadelStatus)
285 long httpstatus = 502;
287 switch (MAJORCODE(CitadelStatus))
289 case LISTING_FOLLOWS:
294 switch (MINORCODE(CitadelStatus))
302 case HIGHER_ACCESS_REQUIRED:
303 case MAX_SESSIONS_EXCEEDED:
305 case RESOURCE_NOT_OPEN:
307 case INVALID_FLOOR_OPERATION:
313 case MESSAGE_NOT_FOUND:
323 case CMD_NOT_SUPPORTED:
324 case PASSWORD_REQUIRED:
325 case ALREADY_LOGGED_IN:
326 case USERNAME_REQUIRED:
328 case SERVER_SHUTTING_DOWN:
339 case START_CHAT_MODE:
343 httpstatus = 502; /* aeh... whut? */
351 * Unadorned HTML output of an individual message, suitable
352 * for placing in a hidden iframe, for printing, or whatever
354 void handle_one_message(void)
358 const StrBuf *Destination;
364 StrBuf *CmdBuf = NULL;
368 pMsg = strchr(ChrPtr(WCC->Hdr->HR.ReqLine), '/');
370 HttpStatus(CitStatus);
374 msgnum = atol(pMsg + 1);
375 StrBufCutAt(WCC->Hdr->HR.ReqLine, 0, pMsg);
376 gotoroom(WCC->Hdr->HR.ReqLine);
377 switch (WCC->Hdr->HR.eReqType)
381 Tmpl = sbstr("template");
382 if (StrLength(Tmpl) > 0)
383 read_message(WCC->WBuf, SKEY(Tmpl), msgnum, NULL, &Mime);
385 read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
386 http_transmit_thing(ChrPtr(Mime), 0);
389 CmdBuf = NewStrBuf ();
390 if ((WCC->CurRoom.RAFlags & UA_ISTRASH) != 0) { /* Delete from Trash is a real delete */
391 serv_printf("DELE %ld", msgnum);
393 else { /* Otherwise move it to Trash */
394 serv_printf("MOVE %ld|_TRASH_|0", msgnum);
396 StrBuf_ServGetln(CmdBuf);
397 FlushStrBuf(WCC->ImportantMsg);
398 StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
399 GetServerStatus(CmdBuf, &CitStatus);
400 HttpStatus(CitStatus);
405 if (GetHash(WCC->Hdr->HTTPHeaders, HKEY("DESTINATION"), &vLine) &&
407 Destination = (StrBuf*) vLine;
408 serv_printf("MOVE %ld|%s|%d", msgnum, ChrPtr(Destination), CopyMessage);
409 StrBuf_ServGetln(CmdBuf);
410 FlushStrBuf(WCC->ImportantMsg);
411 StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
412 GetServerStatus(CmdBuf, &CitStatus);
413 HttpStatus(CitStatus);
426 * Unadorned HTML output of an individual message, suitable
427 * for placing in a hidden iframe, for printing, or whatever
429 void embed_message(void) {
434 StrBuf *CmdBuf = NULL;
436 msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/');
437 switch (WCC->Hdr->HR.eReqType)
441 Tmpl = sbstr("template");
442 if (StrLength(Tmpl) > 0)
443 read_message(WCC->WBuf, SKEY(Tmpl), msgnum, NULL, &Mime);
445 read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
446 http_transmit_thing(ChrPtr(Mime), 0);
449 CmdBuf = NewStrBuf ();
450 if ((WCC->CurRoom.RAFlags & UA_ISTRASH) != 0) { /* Delete from Trash is a real delete */
451 serv_printf("DELE %ld", msgnum);
453 else { /* Otherwise move it to Trash */
454 serv_printf("MOVE %ld|_TRASH_|0", msgnum);
456 StrBuf_ServGetln(CmdBuf);
457 FlushStrBuf(WCC->ImportantMsg);
458 StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
468 * Printable view of a message
470 void print_message(void) {
474 msgnum = StrBufExtract_long(WC->Hdr->HR.ReqLine, 0, '/');
475 output_headers(0, 0, 0, 0, 0, 0);
477 hprintf("Content-type: text/html\r\n"
478 "Server: " PACKAGE_STRING "\r\n"
479 "Connection: close\r\n");
483 read_message(WC->WBuf, HKEY("view_message_print"), msgnum, NULL, &Mime);
489 * Display a message's headers
491 void display_headers(void) {
495 msgnum = StrBufExtract_long(WC->Hdr->HR.ReqLine, 0, '/');
496 output_headers(0, 0, 0, 0, 0, 0);
498 hprintf("Content-type: text/plain\r\n"
500 "Connection: close\r\n",
504 serv_printf("MSG2 %ld|3", msgnum);
505 serv_getln(buf, sizeof buf);
507 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
508 wc_printf("%s\n", buf);
516 message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSubject, long MsgNum)
519 MsgPartEvaluatorStruct *Eval;
520 message_summary *Msg;
529 serv_printf("MSG0 %ld|1", MsgNum); /* ask for headers only */
531 StrBuf_ServGetln(Buf);
532 if (GetServerStatus(Buf, NULL) == 1) {
537 Msg = (message_summary*)malloc(sizeof(message_summary));
538 memset(Msg, 0, sizeof(message_summary));
539 while (len = StrBuf_ServGetln(Buf),
541 strcmp(ChrPtr(Buf), "000")== 0)){
543 ebuf = strchr(ChrPtr(Buf), '=');
545 if (GetHash(MsgEvaluators, buf, nBuf, &vEval) && vEval != NULL) {
546 Eval = (MsgPartEvaluatorStruct*) vEval;
547 StrBufCutLeft(Buf, nBuf + 1);
550 else lprintf(1, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
560 * load message pointers from the server for a "read messages" operation
562 * servcmd: the citadel command to send to the citserver
564 int load_msg_ptrs(const char *servcmd,
565 SharedMessageStatus *Stat,
566 load_msg_ptrs_detailheaders LH)
569 message_summary *Msg;
574 const char *Ptr = NULL;
576 Stat->lowest_found = LONG_MAX;
577 Stat->highest_found = LONG_MIN;
579 if (WCC->summ != NULL) {
580 DeleteHash(&WCC->summ);
582 WCC->summ = NewHash(1, Flathash);
586 StrBuf_ServGetln(Buf);
587 if (GetServerStatus(Buf, NULL) != 1) {
589 return (Stat->nummsgs);
592 while (len = StrBuf_ServGetln(Buf), ((len != 3) || strcmp(ChrPtr(Buf), "000")!= 0))
594 if (Stat->nummsgs < Stat->maxload) {
597 Msg = (message_summary*)malloc(sizeof(message_summary));
598 memset(Msg, 0, sizeof(message_summary));
600 Msg->msgnum = StrBufExtractNext_long(Buf, &Ptr, '|');
601 Msg->date = StrBufExtractNext_long(Buf, &Ptr, '|');
603 if (Stat->nummsgs == 0) {
604 if (Msg->msgnum < Stat->lowest_found) {
605 Stat->lowest_found = Msg->msgnum;
607 if (Msg->msgnum > Stat->highest_found) {
608 Stat->highest_found = Msg->msgnum;
612 if ((Msg->msgnum == 0) && (StrLength(Buf) < 32)) {
618 * as citserver probably gives us messages in forward date sorting
619 * nummsgs should be the same order as the message date.
621 if (Msg->date == 0) {
622 Msg->date = Stat->nummsgs;
623 if (StrLength(Buf) < 32)
626 if ((!skipit) && (LH != NULL)) {
627 if (!LH(Buf, &Ptr, Msg, Buf2)){
633 Put(WCC->summ, (const char *)&n, sizeof(n), Msg, DestroyMessageSummary);
639 return (Stat->nummsgs);
645 * \brief sets FlagToSet for each of ScanMe that appears in MatchMSet
646 * \param ScanMe List of BasicMsgStruct to be searched it MatchSet
647 * \param MatchMSet MSet we want to flag
648 * \param FlagToSet Flag to set on each BasicMsgStruct->Flags if in MSet
650 void SetFlagsFromMSet(HashList *ScanMe, MSet *MatchMSet, int FlagToSet, int Reverse)
656 message_summary *Msg;
658 at = GetNewHashPos(ScanMe, 0);
659 while (GetNextHashPos(ScanMe, at, &HKLen, &HashKey, &vMsg)) {
660 /* Are you a new message, or an old message? */
661 Msg = (message_summary*) vMsg;
662 if (Reverse && IsInMSetList(MatchMSet, Msg->msgnum)) {
663 Msg->Flags = Msg->Flags | FlagToSet;
665 else if (!Reverse && !IsInMSetList(MatchMSet, Msg->msgnum)) {
666 Msg->Flags = Msg->Flags | FlagToSet;
673 void load_seen_flags(void)
679 OldMsg = NewStrBuf();
681 StrBuf_ServGetln(OldMsg);
682 if (GetServerStatus(OldMsg, NULL) == 2) {
683 StrBufCutLeft(OldMsg, 4);
690 if (ParseMSet(&MatchMSet, OldMsg))
692 SetFlagsFromMSet(WCC->summ, MatchMSet, MSGFLAG_READ, 0);
694 DeleteMSet(&MatchMSet);
698 extern readloop_struct rlid[];
700 typedef struct _RoomRenderer{
703 GetParamsGetServerCall_func GetParamsGetServerCall;
704 PrintViewHeader_func PrintViewHeader;
705 LoadMsgFromServer_func LoadMsgFromServer;
706 RenderView_or_Tail_func RenderView_or_Tail;
707 View_Cleanup_func ViewCleanup;
708 load_msg_ptrs_detailheaders LHParse;
713 * command loop for reading messages
715 * Set oper to "readnew" or "readold" or "readfwd" or "headers" or "readgt" or "readlt" or "do_search"
717 void readloop(long oper, eCustomRoomRenderer ForceRenderer)
719 RoomRenderer *ViewMsg;
722 message_summary *Msg;
729 WCTemplputParams SubTP;
730 SharedMessageStatus Stat;
733 if (havebstr("is_summary") && (1 == (ibstr("is_summary")))) {
734 WCC->CurRoom.view = VIEW_MAILBOX;
737 if (havebstr("is_ajax") && (1 == (ibstr("is_ajax")))) {
741 if ((oper == do_search) && (WCC->CurRoom.view == VIEW_WIKI)) {
742 display_wiki_pagelist();
746 if (WCC->CurRoom.view == VIEW_WIKI) {
747 http_redirect("wiki?page=home");
751 memset(&Stat, 0, sizeof(SharedMessageStatus));
752 Stat.maxload = 10000;
753 Stat.lowest_found = (-1);
754 Stat.highest_found = (-1);
755 if (ForceRenderer == eUseDefault)
756 GetHash(ReadLoopHandler, IKEY(WCC->CurRoom.view), &vViewMsg);
758 GetHash(ReadLoopHandler, IKEY(ForceRenderer), &vViewMsg);
759 if (vViewMsg == NULL) {
760 WCC->CurRoom.view = VIEW_BBS;
761 GetHash(ReadLoopHandler, IKEY(WCC->CurRoom.view), &vViewMsg);
763 if (vViewMsg == NULL) {
764 return; // TODO: print message
767 ViewMsg = (RoomRenderer*) vViewMsg;
769 output_headers(1, 1, 1, 0, 0, 0);
770 } else if (WCC->CurRoom.view == VIEW_MAILBOX) {
771 jsonMessageListHdr();
774 if (ViewMsg->GetParamsGetServerCall != NULL) {
775 r = ViewMsg->GetParamsGetServerCall(
790 case 300: /* the callback hook should do the work for us here, since he knows what to do. */
796 if (!IsEmptyStr(cmd))
797 Stat.nummsgs = load_msg_ptrs(cmd, &Stat, ViewMsg->LHParse);
801 memset(&SubTP, 0, sizeof(WCTemplputParams));
802 SubTP.Filter.ContextType = CTX_MAILSUM;
803 SubTP.Context = NULL;
804 SortIt = RetrieveSort(&SubTP, NULL, 0,
805 HKEY("date"), Stat.defaultsortorder);
807 SortByPayload(WCC->summ, SortIt);
809 if (Stat.startmsg < 0) {
813 if (Stat.load_seen) load_seen_flags();
816 * Print any inforation above the message list...
818 if (ViewMsg->PrintViewHeader != NULL)
819 ViewMsg->PrintViewHeader(&Stat, &ViewSpecific);
821 WCC->startmsg = Stat.startmsg;
822 WCC->maxmsgs = Stat.maxmsgs;
823 WCC->num_displayed = 0;
825 /* Put some helpful data in vars for mailsummary_json */
830 StrBufPrintf(Foo, "%ld", Stat.nummsgs);
831 PutBstr(HKEY("__READLOOP:TOTALMSGS"), NewStrBufDup(Foo));
832 StrBufPrintf(Foo, "%ld", Stat.startmsg);
833 PutBstr(HKEY("__READLOOP:STARTMSG"), Foo);
837 * iterate over each message. if we need to load an attachment, do it here.
840 if ((ViewMsg->LoadMsgFromServer != NULL) &&
843 at = GetNewHashPos(WCC->summ, 0);
844 Stat.num_displayed = i = 0;
845 while ( GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
846 Msg = (message_summary*) vMsg;
847 if ((Msg->msgnum >= Stat.startmsg) && (Stat.num_displayed <= Stat.maxmsgs)) {
848 ViewMsg->LoadMsgFromServer(&Stat,
851 (Msg->Flags & MSGFLAG_READ) != 0,
860 * Done iterating the message list. now tasks we want to do after.
862 if (ViewMsg->RenderView_or_Tail != NULL)
863 ViewMsg->RenderView_or_Tail(&Stat, &ViewSpecific, oper);
865 if (ViewMsg->ViewCleanup != NULL)
866 ViewMsg->ViewCleanup(&ViewSpecific);
870 if (WCC->summ != NULL) {
871 DeleteHash(&WCC->summ);
877 * Back end for post_message()
878 * ... this is where the actual message gets transmitted to the server.
880 void post_mime_to_server(void) {
882 char top_boundary[SIZ];
883 char alt_boundary[SIZ];
884 int is_multipart = 0;
886 wc_mime_attachment *att;
888 size_t encoded_length;
889 size_t encoded_strlen;
890 char *txtmail = NULL;
891 int include_text_alt = 0; /* Set to nonzero to include multipart/alternative text/plain */
893 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
894 ChrPtr(WCC->serv_info->serv_fqdn),
898 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
899 ChrPtr(WCC->serv_info->serv_fqdn),
904 /* RFC2045 requires this, and some clients look for it... */
905 serv_puts("MIME-Version: 1.0");
906 serv_puts("X-Mailer: " PACKAGE_STRING);
908 /* If there are attachments, we have to do multipart/mixed */
909 if (GetCount(WCC->attachments) > 0) {
913 /* Only do multipart/alternative for mailboxes. BBS and Wiki rooms don't need it. */
914 if (WC->CurRoom.view == VIEW_MAILBOX) {
915 include_text_alt = 1;
919 /* Remember, serv_printf() appends an extra newline */
920 serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
921 serv_printf("This is a multipart message in MIME format.\n");
922 serv_printf("--%s", top_boundary);
925 /* Remember, serv_printf() appends an extra newline */
926 if (include_text_alt) {
927 serv_printf("Content-type: multipart/alternative; "
928 "boundary=\"%s\"\n", alt_boundary);
929 serv_printf("This is a multipart message in MIME format.\n");
930 serv_printf("--%s", alt_boundary);
932 serv_puts("Content-type: text/plain; charset=utf-8");
933 serv_puts("Content-Transfer-Encoding: quoted-printable");
935 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
936 text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */
939 serv_printf("--%s", alt_boundary);
942 serv_puts("Content-type: text/html; charset=utf-8");
943 serv_puts("Content-Transfer-Encoding: quoted-printable");
945 serv_puts("<html><body>\r\n");
946 text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */
947 serv_puts("</body></html>\r\n");
949 if (include_text_alt) {
950 serv_printf("--%s--", alt_boundary);
959 /* Add in the attachments */
960 it = GetNewHashPos(WCC->attachments, 0);
961 while (GetNextHashPos(WCC->attachments, it, &len, &Key, &vAtt)) {
962 att = (wc_mime_attachment *)vAtt;
963 if (att->length == 0)
965 encoded_length = ((att->length * 150) / 100);
966 encoded = malloc(encoded_length);
967 if (encoded == NULL) break;
968 encoded_strlen = CtdlEncodeBase64(encoded, ChrPtr(att->Data), StrLength(att->Data), 1);
970 serv_printf("--%s", top_boundary);
971 serv_printf("Content-type: %s", ChrPtr(att->ContentType));
972 serv_printf("Content-disposition: attachment; filename=\"%s\"", ChrPtr(att->FileName));
973 serv_puts("Content-transfer-encoding: base64");
975 serv_write(encoded, encoded_strlen);
980 serv_printf("--%s--", top_boundary);
989 * Post message (or don't post message)
991 * Note regarding the "dont_post" variable:
992 * A random value (actually, it's just a timestamp) is inserted as a hidden
993 * field called "postseq" when the display_enter page is generated. This
994 * value is checked when posting, using the static variable dont_post. If a
995 * user attempts to post twice using the same dont_post value, the message is
996 * discarded. This prevents the accidental double-saving of the same message
997 * if the user happens to click the browser "back" button.
999 void post_message(void)
1002 StrBuf *EmailAddress;
1005 StrBuf *encoded_subject = NULL;
1006 static long dont_post = (-1L);
1007 int is_anonymous = 0;
1008 const StrBuf *display_name = NULL;
1009 wcsession *WCC = WC;
1012 if (havebstr("force_room")) {
1013 gotoroom(sbstr("force_room"));
1016 if (havebstr("display_name")) {
1017 display_name = sbstr("display_name");
1018 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
1019 display_name = NULL;
1024 if (!strcasecmp(bstr("submit_action"), "cancel")) {
1025 sprintf(WCC->ImportantMessage,
1026 _("Cancelled. Message was not posted."));
1027 } else if (lbstr("postseq") == dont_post) {
1028 sprintf(WCC->ImportantMessage,
1029 _("Automatically cancelled because you have already "
1030 "saved this message."));
1032 const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s";
1033 StrBuf *Recp = NULL;
1036 const StrBuf *Wikipage = NULL;
1037 const StrBuf *my_email_addr = NULL;
1038 StrBuf *CmdBuf = NULL;
1039 StrBuf *references = NULL;
1043 save_to_drafts = !strcasecmp(bstr("submit_action"), "drafts");
1046 if (save_to_drafts) {
1047 /* temporarily change to the drafts room */
1048 serv_puts("GOTO _DRAFTS_");
1049 StrBuf_ServGetln(Buf);
1050 if (GetServerStatus(Buf, NULL) != 2) {
1051 /* You probably don't even have a dumb Drafts folder */
1052 StrBufCutLeft(Buf, 4);
1053 lprintf(9, "%s:%d: server save to drafts error: %s\n", __FILE__, __LINE__, ChrPtr(Buf));
1054 StrBufAppendBufPlain(WCC->ImportantMsg, _("Saved to Drafts failed: "), -1, 0);
1055 StrBufAppendBuf(WCC->ImportantMsg, Buf, 0);
1062 if (havebstr("references"))
1064 const StrBuf *ref = sbstr("references");
1065 references = NewStrBufDup(ref);
1066 if (*ChrPtr(references) == '|') { /* remove leading '|' if present */
1067 StrBufCutLeft(references, 1);
1069 StrBufReplaceChars(references, '|', '!');
1071 if (havebstr("subject")) {
1074 * make enough room for the encoded string;
1075 * plus the QP header
1077 Subj = sbstr("subject");
1079 StrBufRFC2047encode(&encoded_subject, Subj);
1081 UserName = NewStrBuf();
1082 EmailAddress = NewStrBuf();
1083 EncBuf = NewStrBuf();
1085 Recp = StrBufSanitizeEmailRecipientVector(sbstr("recp"), UserName, EmailAddress, EncBuf);
1086 Cc = StrBufSanitizeEmailRecipientVector(sbstr("cc"), UserName, EmailAddress, EncBuf);
1087 Bcc = StrBufSanitizeEmailRecipientVector(sbstr("bcc"), UserName, EmailAddress, EncBuf);
1089 FreeStrBuf(&UserName);
1090 FreeStrBuf(&EmailAddress);
1091 FreeStrBuf(&EncBuf);
1093 Wikipage = sbstr("page");
1094 my_email_addr = sbstr("my_email_addr");
1096 HeaderLen = StrLength(Recp) +
1097 StrLength(encoded_subject) +
1100 StrLength(Wikipage) +
1101 StrLength(my_email_addr) +
1102 StrLength(references);
1103 CmdBuf = NewStrBufPlain(NULL, sizeof (CMD) + HeaderLen);
1104 StrBufPrintf(CmdBuf,
1106 save_to_drafts?"":ChrPtr(Recp),
1108 ChrPtr(encoded_subject),
1109 ChrPtr(display_name),
1110 save_to_drafts?"":ChrPtr(Cc),
1111 save_to_drafts?"":ChrPtr(Bcc),
1113 ChrPtr(my_email_addr),
1114 ChrPtr(references));
1115 FreeStrBuf(&references);
1116 FreeStrBuf(&encoded_subject);
1118 if ((HeaderLen + StrLength(sbstr("msgtext")) < 10) &&
1119 (GetCount(WCC->attachments) == 0)){
1120 StrBufAppendBufPlain(WCC->ImportantMsg, _("Refusing to post empty message.\n"), -1, 0);
1121 FreeStrBuf(&CmdBuf);
1126 lprintf(9, "%s\n", ChrPtr(CmdBuf));
1127 serv_puts(ChrPtr(CmdBuf));
1128 FreeStrBuf(&CmdBuf);
1130 StrBuf_ServGetln(Buf);
1131 if (GetServerStatus(Buf, NULL) == 4) {
1132 if (save_to_drafts) {
1133 if ( (havebstr("recp"))
1134 || (havebstr("cc" ))
1135 || (havebstr("bcc" )) ) {
1136 /* save recipient headers or room to post to */
1137 serv_printf("To: %s", ChrPtr(Recp));
1138 serv_printf("Cc: %s", ChrPtr(Cc));
1139 serv_printf("Bcc: %s", ChrPtr(Bcc));
1141 serv_printf("X-Citadel-Room: %s", ChrPtr(WC->CurRoom.name));
1144 post_mime_to_server();
1145 if (save_to_drafts) {
1146 StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been saved to Drafts.\n"), -1, 0);
1147 gotoroom(WCC->CurRoom.name);
1151 } else if ( (havebstr("recp"))
1152 || (havebstr("cc" ))
1153 || (havebstr("bcc" ))
1155 StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been sent.\n"), -1, 0);
1158 StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been posted.\n"), -1, 0);
1160 dont_post = lbstr("postseq");
1162 StrBufCutLeft(Buf, 4);
1164 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, ChrPtr(Buf));
1165 StrBufAppendBuf(WCC->ImportantMsg, Buf, 0);
1166 if (save_to_drafts) gotoroom(WCC->CurRoom.name);
1180 DeleteHash(&WCC->attachments);
1183 * We may have been supplied with instructions regarding the location
1184 * to which we must return after posting. If found, go there.
1186 if (havebstr("return_to")) {
1187 http_redirect(bstr("return_to"));
1190 * If we were editing a page in a wiki room, go to that page now.
1192 else if (havebstr("page")) {
1193 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("page"));
1197 * Otherwise, just go to the "read messages" loop.
1200 readloop(readnew, eUseDefault);
1206 * Client is uploading an attachment
1208 void upload_attachment(void) {
1209 wcsession *WCC = WC;
1215 wc_mime_attachment *att;
1217 lprintf(9, "upload_attachment()\n");
1218 wc_printf("upload_attachment()<br>\n");
1220 if (WCC->upload_length <= 0) {
1221 lprintf(9, "ERROR no attachment was uploaded\n");
1222 wc_printf("ERROR no attachment was uploaded<br>\n");
1226 lprintf(9, "Client is uploading %d bytes\n", WCC->upload_length);
1227 wc_printf("Client is uploading %d bytes<br>\n", WCC->upload_length);
1228 att = malloc(sizeof(wc_mime_attachment));
1229 memset(att, 0, sizeof(wc_mime_attachment ));
1230 att->length = WCC->upload_length;
1231 att->ContentType = NewStrBufPlain(WCC->upload_content_type, -1);
1232 att->FileName = NewStrBufDup(WCC->upload_filename);
1234 if (WCC->attachments == NULL) {
1235 WCC->attachments = NewHash(1, Flathash);
1238 /* And add it to the list. */
1240 if ((GetCount(WCC->attachments) > 0) &&
1241 GetHashAt(WCC->attachments,
1242 GetCount(WCC->attachments) -1,
1243 &newnlen, &newn, &v))
1244 n = *((int*) newn) + 1;
1245 Put(WCC->attachments, IKEY(n), att, DestroyMime);
1248 * Mozilla sends a simple filename, which is what we want,
1249 * but Satan's Browser sends an entire pathname. Reduce
1250 * the path to just a filename if we need to.
1252 pch = strrchr(ChrPtr(att->FileName), '/');
1254 StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1);
1256 pch = strrchr(ChrPtr(att->FileName), '\\');
1258 StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1);
1262 * Transfer control of this memory from the upload struct
1263 * to the attachment struct.
1265 att->Data = WCC->upload;
1267 WCC->upload_length = 0;
1272 * Remove an attachment from the message currently being composed.
1274 * Currently we identify the attachment to be removed by its filename.
1275 * There is probably a better way to do this.
1277 void remove_attachment(void) {
1278 wcsession *WCC = WC;
1279 wc_mime_attachment *att;
1281 StrBuf *WhichAttachment;
1286 WhichAttachment = NewStrBufDup(sbstr("which_attachment"));
1287 StrBufUnescape(WhichAttachment, 0);
1288 at = GetNewHashPos(WCC->attachments, 0);
1290 GetHashPos(WCC->attachments, at, &len, &key, &vAtt);
1292 att = (wc_mime_attachment*) vAtt;
1293 if ((att != NULL) &&
1294 (strcmp(ChrPtr(WhichAttachment),
1295 ChrPtr(att->FileName) ) == 0))
1297 DeleteEntryFromHash(WCC->attachments, at);
1301 while (NextHashPos(WCC->attachments, at));
1302 FreeStrBuf(&WhichAttachment);
1303 wc_printf("remove_attachment() completed\n");
1308 * display the message entry screen
1310 void display_enter(void)
1314 const StrBuf *display_name = NULL;
1315 int recipient_required = 0;
1316 int subject_required = 0;
1317 int recipient_bad = 0;
1318 int is_anonymous = 0;
1319 wcsession *WCC = WC;
1323 if (havebstr("force_room")) {
1324 gotoroom(sbstr("force_room"));
1327 display_name = sbstr("display_name");
1328 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
1329 display_name = NULL;
1333 /* First test to see whether this is a room that requires recipients to be entered */
1334 serv_puts("ENT0 0");
1335 serv_getln(buf, sizeof buf);
1337 if (!strncmp(buf, "570", 3)) { /* 570 means that we need a recipient here */
1338 recipient_required = 1;
1340 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
1341 sprintf(WCC->ImportantMessage, "%s", &buf[4]);
1342 readloop(readnew, eUseDefault);
1346 /* Is the server strongly recommending that the user enter a message subject? */
1347 if ((buf[3] != '\0') && (buf[4] != '\0')) {
1348 subject_required = extract_int(&buf[4], 1);
1352 * Are we perhaps in an address book view? If so, then an "enter
1353 * message" command really means "add new entry."
1355 if (WCC->CurRoom.defview == VIEW_ADDRESSBOOK) {
1356 do_edit_vcard(-1, "", NULL, NULL, "", ChrPtr(WCC->CurRoom.name));
1361 * Are we perhaps in a calendar room? If so, then an "enter
1362 * message" command really means "add new calendar item."
1364 if (WCC->CurRoom.defview == VIEW_CALENDAR) {
1365 display_edit_event();
1370 * Are we perhaps in a tasks view? If so, then an "enter
1371 * message" command really means "add new task."
1373 if (WCC->CurRoom.defview == VIEW_TASKS) {
1374 display_edit_task();
1379 * Otherwise proceed normally.
1380 * Do a custom room banner with no navbar...
1383 if (recipient_required) {
1384 const StrBuf *Recp = NULL;
1385 const StrBuf *Cc = NULL;
1386 const StrBuf *Bcc = NULL;
1387 const StrBuf *Wikipage = NULL;
1388 StrBuf *CmdBuf = NULL;
1389 const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
1391 Recp = sbstr("recp");
1394 Wikipage = sbstr("page");
1396 CmdBuf = NewStrBufPlain(NULL,
1399 StrLength(display_name) +
1402 StrLength(Wikipage));
1404 StrBufPrintf(CmdBuf,
1408 ChrPtr(display_name),
1412 serv_puts(ChrPtr(CmdBuf));
1413 serv_getln(buf, sizeof buf);
1414 FreeStrBuf(&CmdBuf);
1416 if (!strncmp(buf, "570", 3)) { /* 570 means we have an invalid recipient listed */
1417 if (havebstr("recp") &&
1423 else if (buf[0] != '2') { /* Any other error means that we cannot continue */
1424 wc_printf("<em>%s</em><br>\n", &buf[4]); /* TODO -> important message */
1428 if (recipient_required)
1429 PutBstr(HKEY("__RCPTREQUIRED"), NewStrBufPlain(HKEY("1")));
1430 if (recipient_required || subject_required)
1431 PutBstr(HKEY("__SUBJREQUIRED"), NewStrBufPlain(HKEY("1")));
1434 output_headers(1, 0, 0, 0, 1, 0);
1435 DoTemplate(HKEY("edit_message"), NULL, &NoCtx);
1444 void delete_msg(void)
1449 msgid = lbstr("msgid");
1451 if ((WC->CurRoom.RAFlags & UA_ISTRASH) != 0) { /* Delete from Trash is a real delete */
1452 serv_printf("DELE %ld", msgid);
1454 else { /* Otherwise move it to Trash */
1455 serv_printf("MOVE %ld|_TRASH_|0", msgid);
1458 serv_getln(buf, sizeof buf);
1459 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1460 readloop(readnew, eUseDefault);
1465 * move a message to another room
1472 msgid = lbstr("msgid");
1474 if (havebstr("move_button")) {
1475 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
1477 serv_getln(buf, sizeof buf);
1478 sprintf(WC->ImportantMessage, "%s", &buf[4]);
1480 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
1483 readloop(readnew, eUseDefault);
1488 * Confirm move of a message
1490 void confirm_move_msg(void)
1496 msgid = lbstr("msgid");
1499 output_headers(1, 1, 2, 0, 0, 0);
1500 wc_printf("<div id=\"banner\">\n");
1502 wc_printf(_("Confirm move of message"));
1504 wc_printf("</div>\n");
1506 wc_printf("<div id=\"content\" class=\"service\">\n");
1508 wc_printf("<CENTER>");
1510 wc_printf(_("Move this message to:"));
1511 wc_printf("<br>\n");
1513 wc_printf("<form METHOD=\"POST\" action=\"move_msg\">\n");
1514 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1515 wc_printf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
1517 wc_printf("<SELECT NAME=\"target_room\" SIZE=5>\n");
1519 serv_getln(buf, sizeof buf);
1520 if (buf[0] == '1') {
1521 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1522 extract_token(targ, buf, 0, '|', sizeof targ);
1523 wc_printf("<OPTION>");
1528 wc_printf("</SELECT>\n");
1529 wc_printf("<br>\n");
1531 wc_printf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
1532 wc_printf(" ");
1533 wc_printf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
1534 wc_printf("</form></CENTER>\n");
1536 wc_printf("</CENTER>\n");
1542 * Generic function to output an arbitrary MIME attachment from
1543 * message being composed
1545 * partnum The MIME part to be output
1546 * filename Fake filename to give
1547 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
1549 void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
1552 StrBuf *content_type;
1553 wc_mime_attachment *part;
1556 i = StrToi(partnum);
1557 if (GetHash(WC->attachments, IKEY(i), &vPart) &&
1559 part = (wc_mime_attachment*) vPart;
1560 if (force_download) {
1561 content_type = NewStrBufPlain(HKEY("application/octet-stream"));
1564 content_type = NewStrBufDup(part->ContentType);
1566 StrBufAppendBuf(WC->WBuf, part->Data, 0);
1567 http_transmit_thing(ChrPtr(content_type), 0);
1569 hprintf("HTTP/1.1 404 %s\n", ChrPtr(partnum));
1570 output_headers(0, 0, 0, 0, 0, 0);
1571 hprintf("Content-Type: text/plain\r\n");
1573 wc_printf(_("An error occurred while retrieving this part: %s/%s\n"),
1574 ChrPtr(partnum), ChrPtr(filename));
1577 FreeStrBuf(&content_type);
1582 * Generic function to output an arbitrary MIME part from an arbitrary
1583 * message number on the server.
1585 * msgnum Number of the item on the citadel server
1586 * partnum The MIME part to be output
1587 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
1589 void mimepart(int force_download)
1593 wcsession *WCC = WC;
1596 StrBuf *ContentType = NewStrBufPlain(HKEY("application/octet-stream"));
1599 att = Buf = NewStrBuf();
1600 msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/');
1601 StrBufExtract_token(att, WCC->Hdr->HR.ReqLine, 1, '/');
1603 serv_printf("OPNA %ld|%s", msgnum, ChrPtr(att));
1604 StrBuf_ServGetln(Buf);
1605 if (GetServerStatus(Buf, NULL) == 2) {
1606 StrBufCutLeft(Buf, 4);
1607 bytes = StrBufExtract_long(Buf, 0, '|');
1608 if (!force_download) {
1609 StrBufExtract_token(ContentType, Buf, 3, '|');
1612 serv_read_binary(WCC->WBuf, bytes, Buf);
1614 StrBuf_ServGetln(Buf);
1615 CT = ChrPtr(ContentType);
1617 if (!force_download) {
1618 if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
1619 StrBufExtract_token(Buf, WCC->Hdr->HR.ReqLine, 2, '/');
1620 CT = GuessMimeByFilename(SKEY(Buf));
1622 if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
1623 CT = GuessMimeType(SKEY(WCC->WBuf));
1626 http_transmit_thing(CT, 0);
1628 StrBufCutLeft(Buf, 4);
1629 hprintf("HTTP/1.1 404 %s\n", ChrPtr(Buf));
1630 output_headers(0, 0, 0, 0, 0, 0);
1631 hprintf("Content-Type: text/plain\r\n");
1633 wc_printf(_("An error occurred while retrieving this part: %s\n"),
1637 FreeStrBuf(&ContentType);
1643 * Read any MIME part of a message, from the server, into memory.
1645 StrBuf *load_mimepart(long msgnum, char *partnum)
1651 serv_printf("DLAT %ld|%s", msgnum, partnum);
1652 StrBuf_ServGetln(Buf);
1653 if (GetServerStatus(Buf, NULL) == 6) {
1654 StrBufCutLeft(Buf, 4);
1655 bytes = StrBufExtract_long(Buf, 0, '|');
1658 StrBuf_ServGetBLOBBuffered(Buf, bytes);
1668 * Read any MIME part of a message, from the server, into memory.
1670 void MimeLoadData(wc_mime_attachment *Mime)
1675 /* TODO: is there a chance the content type is different from the one we know? */
1677 serv_printf("DLAT %ld|%s", Mime->msgnum, ChrPtr(Mime->PartNum));
1679 StrBuf_ServGetln(Buf);
1680 if (GetServerStatus(Buf, NULL) == 6) {
1681 Ptr = &(ChrPtr(Buf)[4]);
1682 bytes = StrBufExtractNext_long(Buf, &Ptr, '|');
1683 StrBufSkip_NTokenS(Buf, &Ptr, '|', 3); /* filename, cbtype, mimetype */
1684 if (Mime->Charset == NULL) Mime->Charset = NewStrBuf();
1685 StrBufExtract_NextToken(Mime->Charset, Buf, &Ptr, '|');
1687 if (Mime->Data == NULL)
1688 Mime->Data = NewStrBufPlain(NULL, bytes);
1689 StrBuf_ServGetBLOBBuffered(Mime->Data, bytes);
1692 FlushStrBuf(Mime->Data);
1693 /* TODO XImportant message */
1699 void view_mimepart(void) {
1703 void download_mimepart(void) {
1707 void view_postpart(void) {
1708 StrBuf *filename = NewStrBuf();
1709 StrBuf *partnum = NewStrBuf();
1711 StrBufExtract_token(partnum, WC->Hdr->HR.ReqLine, 0, '/');
1712 StrBufExtract_token(filename, WC->Hdr->HR.ReqLine, 1, '/');
1714 postpart(partnum, filename, 0);
1716 FreeStrBuf(&filename);
1717 FreeStrBuf(&partnum);
1720 void download_postpart(void) {
1721 StrBuf *filename = NewStrBuf();
1722 StrBuf *partnum = NewStrBuf();
1724 StrBufExtract_token(partnum, WC->Hdr->HR.ReqLine, 0, '/');
1725 StrBufExtract_token(filename, WC->Hdr->HR.ReqLine, 1, '/');
1727 postpart(partnum, filename, 1);
1729 FreeStrBuf(&filename);
1730 FreeStrBuf(&partnum);
1735 void show_num_attachments(void) {
1736 wc_printf("%d", GetCount(WC->attachments));
1740 void h_readnew(void) { readloop(readnew, eUseDefault);}
1741 void h_readold(void) { readloop(readold, eUseDefault);}
1742 void h_readfwd(void) { readloop(readfwd, eUseDefault);}
1743 void h_headers(void) { readloop(headers, eUseDefault);}
1744 void h_do_search(void) { readloop(do_search, eUseDefault);}
1745 void h_readgt(void) { readloop(readgt, eUseDefault);}
1746 void h_readlt(void) { readloop(readlt, eUseDefault);}
1748 void jsonMessageListHdr(void)
1750 /* TODO: make a generic function */
1751 hprintf("HTTP/1.1 200 OK\r\n");
1752 hprintf("Content-type: application/json; charset=utf-8\r\n");
1753 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
1754 hprintf("Connection: close\r\n");
1755 hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
1760 /* Output message list in JSON format */
1761 void jsonMessageList(void) {
1762 const StrBuf *room = sbstr("room");
1763 long oper = (havebstr("query")) ? do_search : readnew;
1766 readloop(oper, eUseDefault);
1770 void RegisterReadLoopHandlerset(
1772 GetParamsGetServerCall_func GetParamsGetServerCall,
1773 PrintViewHeader_func PrintViewHeader,
1774 load_msg_ptrs_detailheaders LH,
1775 LoadMsgFromServer_func LoadMsgFromServer,
1776 RenderView_or_Tail_func RenderView_or_Tail,
1777 View_Cleanup_func ViewCleanup
1780 RoomRenderer *Handler;
1782 Handler = (RoomRenderer*) malloc(sizeof(RoomRenderer));
1784 Handler->RoomType = RoomType;
1785 Handler->GetParamsGetServerCall = GetParamsGetServerCall;
1786 Handler->PrintViewHeader = PrintViewHeader;
1787 Handler->LoadMsgFromServer = LoadMsgFromServer;
1788 Handler->RenderView_or_Tail = RenderView_or_Tail;
1789 Handler->ViewCleanup = ViewCleanup;
1790 Handler->LHParse = LH;
1792 Put(ReadLoopHandler, IKEY(RoomType), Handler, NULL);
1799 RegisterPreference("use_sig",
1800 _("Attach signature to email messages?"),
1803 RegisterPreference("signature", _("Use this signature:"), PRF_QP_STRING, NULL);
1804 RegisterPreference("default_header_charset",
1805 _("Default character set for email headers:"),
1808 RegisterPreference("defaultfrom", _("Preferred email address"), PRF_STRING, NULL);
1809 RegisterPreference("defaultname",
1810 _("Preferred display name for email messages"),
1813 RegisterPreference("defaulthandle",
1814 _("Preferred display name for bulletin board posts"),
1817 RegisterPreference("mailbox",_("Mailbox view mode"), PRF_STRING, NULL);
1819 WebcitAddUrlHandler(HKEY("readnew"), "", 0, h_readnew, ANONYMOUS|NEED_URL);
1820 WebcitAddUrlHandler(HKEY("readold"), "", 0, h_readold, ANONYMOUS|NEED_URL);
1821 WebcitAddUrlHandler(HKEY("readfwd"), "", 0, h_readfwd, ANONYMOUS|NEED_URL);
1822 WebcitAddUrlHandler(HKEY("headers"), "", 0, h_headers, NEED_URL);
1823 WebcitAddUrlHandler(HKEY("readgt"), "", 0, h_readgt, ANONYMOUS|NEED_URL);
1824 WebcitAddUrlHandler(HKEY("readlt"), "", 0, h_readlt, ANONYMOUS|NEED_URL);
1825 WebcitAddUrlHandler(HKEY("do_search"), "", 0, h_do_search, 0);
1826 WebcitAddUrlHandler(HKEY("display_enter"), "", 0, display_enter, 0);
1827 WebcitAddUrlHandler(HKEY("post"), "", 0, post_message, PROHIBIT_STARTPAGE);
1828 WebcitAddUrlHandler(HKEY("move_msg"), "", 0, move_msg, PROHIBIT_STARTPAGE);
1829 WebcitAddUrlHandler(HKEY("delete_msg"), "", 0, delete_msg, PROHIBIT_STARTPAGE);
1830 WebcitAddUrlHandler(HKEY("confirm_move_msg"), "", 0, confirm_move_msg, PROHIBIT_STARTPAGE);
1831 WebcitAddUrlHandler(HKEY("msg"), "", 0, embed_message, NEED_URL);
1832 WebcitAddUrlHandler(HKEY("message"), "", 0, handle_one_message, NEED_URL|XHTTP_COMMANDS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
1833 WebcitAddUrlHandler(HKEY("printmsg"), "", 0, print_message, NEED_URL);
1834 WebcitAddUrlHandler(HKEY("msgheaders"), "", 0, display_headers, NEED_URL);
1836 WebcitAddUrlHandler(HKEY("mimepart"), "", 0, view_mimepart, NEED_URL);
1837 WebcitAddUrlHandler(HKEY("mimepart_download"), "", 0, download_mimepart, NEED_URL);
1838 WebcitAddUrlHandler(HKEY("postpart"), "", 0, view_postpart, NEED_URL|PROHIBIT_STARTPAGE);
1839 WebcitAddUrlHandler(HKEY("postpart_download"), "", 0, download_postpart, NEED_URL|PROHIBIT_STARTPAGE);
1840 WebcitAddUrlHandler(HKEY("upload_attachment"), "", 0, upload_attachment, AJAX);
1841 WebcitAddUrlHandler(HKEY("remove_attachment"), "", 0, remove_attachment, AJAX);
1842 WebcitAddUrlHandler(HKEY("show_num_attachments"), "", 0, show_num_attachments, AJAX);
1845 WebcitAddUrlHandler(HKEY("roommsgs"), "", 0, jsonMessageList,0);
1850 SessionDetachModule_MSG
1853 DeleteHash(&sess->summ);