X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fmessages.c;h=405656eab269ec22794ea6c7c5b5d080fc9726c1;hb=cb828090d054ae1c71447d06ab348b638cc5f938;hp=c190e0ff8df42183da279ca0c88472f6d811e065;hpb=e80761c6ece3fc4236987c8512ef9dbab163058b;p=citadel.git
diff --git a/webcit/messages.c b/webcit/messages.c
index c190e0ff8..405656eab 100644
--- a/webcit/messages.c
+++ b/webcit/messages.c
@@ -1,16 +1,23 @@
/*
- * $Id$
- *
* Functions which deal with the fetching and displaying of messages.
*
+ * Copyright (c) 1996-2012 by the citadel.org team
+ *
+ * This program is open source software. You can redistribute it and/or
+ * modify it under the terms of the GNU General Public License, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*/
#include "webcit.h"
#include "webserver.h"
-#include "groupdav.h"
+#include "dav.h"
+#include "calendar.h"
HashList *MsgHeaderHandler = NULL;
-HashList *MsgEvaluators = NULL;
HashList *MimeRenderHandler = NULL;
HashList *ReadLoopHandler = NULL;
int dbg_analyze_msg = 0;
@@ -23,17 +30,19 @@ void jsonMessageListHdr(void);
void display_enter(void);
-typedef void (*MsgPartEvaluatorFunc)(message_summary *Sum, StrBuf *Buf);
-
-typedef struct _MsgPartEvaluatorStruct {
- MsgPartEvaluatorFunc f;
-} MsgPartEvaluatorStruct;
-
+void fixview()
+{
+ /* workaround for json listview; its not useable directly */
+ if (WC->CurRoom.view == VIEW_JSON_LIST) {
+ StrBuf *View = NewStrBuf();
+ StrBufPrintf(View, "%d", VIEW_MAILBOX);
+ putbstr("view", View);;
+ }
+}
int load_message(message_summary *Msg,
StrBuf *FoundCharset,
StrBuf **Error)
{
- wcsession *WCC = WC;
StrBuf *Buf;
StrBuf *HdrToken;
headereval *Hdr;
@@ -43,7 +52,6 @@ int load_message(message_summary *Msg,
int state=0;
Buf = NewStrBuf();
- lprintf(9, "MSG4 %ld|%s\n", Msg->msgnum, ChrPtr(Msg->PartNum));
if (Msg->PartNum != NULL) {
serv_printf("MSG4 %ld|%s", Msg->msgnum, ChrPtr(Msg->PartNum));
}
@@ -56,7 +64,7 @@ int load_message(message_summary *Msg,
*Error = NewStrBuf();
StrBufAppendPrintf(*Error, "");
StrBufAppendPrintf(*Error, _("ERROR:"));
- StrBufAppendPrintf(*Error, " %s
\n", &buf[4]);
+ StrBufAppendPrintf(*Error, " %s
\n", &buf[4]);
FreeStrBuf(&Buf);
return 0;
}
@@ -74,7 +82,7 @@ int load_message(message_summary *Msg,
Msg->MsgBody->ContentType = NewStrBufPlain(HKEY("text/html"));
StrBufAppendPrintf(Msg->MsgBody->Data, "
0) {
+ StrBuf *refs = NewStrBuf();
+ if (StrLength(wefw) > 0) {
+ StrBufAppendBuf(refs, wefw, 0);
+ }
+ if ( (StrLength(wefw) > 0) &&
+ (StrLength(msgn) > 0) )
+ {
+ StrBufAppendBufPlain(refs, HKEY("|"), 0);
+ }
+ if (StrLength(msgn) > 0) {
+ StrBufAppendBuf(refs, msgn, 0);
+ }
+ PutBstr(HKEY("references"), refs);
+ }
+
+ /*
+ * If this is a Reply or a ReplyAll, copy the sender's email into the To: field
+ */
+ if ((ReplyMode == eReply) || (ReplyMode == eReplyAll))
+ {
+ StrBuf *to_rcpt;
+ if ((StrLength(replyto) > 0) && (ReplyMode == eReplyAll)) {
+ to_rcpt = NewStrBuf();
+ StrBufAppendBuf(to_rcpt, replyto, 0);
+ }
+ else if (StrLength(rfca) > 0) {
+ to_rcpt = NewStrBuf();
+ StrBufAppendBuf(to_rcpt, from, 0);
+ StrBufAppendBufPlain(to_rcpt, HKEY(" <"), 0);
+ StrBufAppendBuf(to_rcpt, rfca, 0);
+ StrBufAppendBufPlain(to_rcpt, HKEY(">"), 0);
+ }
+ else {
+ to_rcpt = from;
+ from = NULL;
+ if ( (StrLength(node) > 0)
+ && (strcasecmp(ChrPtr(node), ChrPtr(WCC->serv_info->serv_nodename)))
+ ) {
+ StrBufAppendBufPlain(to_rcpt, HKEY(" @ "), 0);
+ StrBufAppendBuf(to_rcpt, node, 0);
+ }
+ }
+ PutBstr(HKEY("recp"), to_rcpt);
+ }
+
+ /*
+ * Only if this is a ReplyAll, copy all recipients into the Cc: field
+ */
+ if (ReplyMode == eReplyAll)
+ {
+ StrBuf *cc_rcpt = rcpt;
+ rcpt = NULL;
+ if ((StrLength(cccc) > 0) && (StrLength(replyto) == 0))
+ {
+ if (cc_rcpt != NULL) {
+ StrBufAppendPrintf(cc_rcpt, ", ");
+ StrBufAppendBuf(cc_rcpt, cccc, 0);
+ } else {
+ cc_rcpt = cccc;
+ cccc = NULL;
+ }
+ }
+ if (cc_rcpt != NULL)
+ PutBstr(HKEY("cc"), cc_rcpt);
+ }
+ FreeStrBuf(&wefw);
+ FreeStrBuf(&msgn);
+ FreeStrBuf(&from);
+ FreeStrBuf(&node);
+ FreeStrBuf(&rfca);
+ FreeStrBuf(&rcpt);
+ FreeStrBuf(&cccc);
+ }
+ FreeStrBuf(&Line);
/*
* Otherwise proceed normally.
* Do a custom room banner with no navbar...
@@ -1345,14 +1641,15 @@ void display_enter(void)
const StrBuf *Recp = NULL;
const StrBuf *Cc = NULL;
const StrBuf *Bcc = NULL;
- const StrBuf *Wikipage = NULL;
+ char *wikipage = NULL;
StrBuf *CmdBuf = NULL;
const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
Recp = sbstr("recp");
Cc = sbstr("cc");
Bcc = sbstr("bcc");
- Wikipage = sbstr("page");
+ wikipage = strdup(bstr("page"));
+ str_wiki_index(wikipage);
CmdBuf = NewStrBufPlain(NULL,
sizeof (CMD) +
@@ -1360,7 +1657,7 @@ void display_enter(void)
StrLength(display_name) +
StrLength(Cc) +
StrLength(Bcc) +
- StrLength(Wikipage));
+ strlen(wikipage));
StrBufPrintf(CmdBuf,
CMD,
@@ -1369,29 +1666,39 @@ void display_enter(void)
ChrPtr(display_name),
ChrPtr(Cc),
ChrPtr(Bcc),
- ChrPtr(Wikipage));
+ wikipage
+ );
serv_puts(ChrPtr(CmdBuf));
- serv_getln(buf, sizeof buf);
- FreeStrBuf(&CmdBuf);
+ StrBuf_ServGetln(CmdBuf);
+ free(wikipage);
- if (!strncmp(buf, "570", 3)) { /* 570 means we have an invalid recipient listed */
- if (havebstr("recp") &&
- havebstr("cc" ) &&
- havebstr("bcc" )) {
- recipient_bad = 1;
- }
+ rc = GetServerStatusMsg(CmdBuf, &Result, 0, 0);
+
+ if ( (Result == 570) /* invalid or missing recipient(s) */
+ || (Result == 550) /* higher access required to send Internet mail */
+ ) {
+ /* These errors will have been displayed and are excusable */
}
- else if (buf[0] != '2') { /* Any other error means that we cannot continue */
- wc_printf("%s
\n", &buf[4]); /* TODO -> important message */
+ else if (rc != 2) { /* Any other error means that we cannot continue */
+ AppendImportantMessage(ChrPtr(CmdBuf) + 4, StrLength(CmdBuf) - 4);
+ FreeStrBuf(&CmdBuf);
+ fixview();
+ readloop(readnew, eUseDefault);
return;
}
+ FreeStrBuf(&CmdBuf);
}
- svputlong("RCPTREQUIRED", recipient_required);
- svputlong("SUBJREQUIRED", recipient_required || subject_required);
+ if (recipient_required)
+ PutBstr(HKEY("__RCPTREQUIRED"), NewStrBufPlain(HKEY("1")));
+ if (recipient_required || subject_required)
+ PutBstr(HKEY("__SUBJREQUIRED"), NewStrBufPlain(HKEY("1")));
begin_burst();
output_headers(1, 0, 0, 0, 1, 0);
- DoTemplate(HKEY("edit_message"), NULL, &NoCtx);
+ if (WCC->CurRoom.defview == VIEW_WIKIMD)
+ DoTemplate(HKEY("edit_markdown_epic"), NULL, &NoCtx);
+ else
+ DoTemplate(HKEY("edit_message"), NULL, &NoCtx);
end_burst();
return;
@@ -1403,10 +1710,10 @@ void display_enter(void)
void delete_msg(void)
{
long msgid;
- char buf[SIZ];
-
+ StrBuf *Line;
+
msgid = lbstr("msgid");
-
+ Line = NewStrBuf();
if ((WC->CurRoom.RAFlags & UA_ISTRASH) != 0) { /* Delete from Trash is a real delete */
serv_printf("DELE %ld", msgid);
}
@@ -1414,8 +1721,11 @@ void delete_msg(void)
serv_printf("MOVE %ld|_TRASH_|0", msgid);
}
- serv_getln(buf, sizeof buf);
- sprintf(WC->ImportantMessage, "%s", &buf[4]);
+ StrBuf_ServGetln(Line);
+ GetServerStatusMsg(Line, NULL, 1, 0);
+
+ fixview();
+
readloop(readnew, eUseDefault);
}
@@ -1426,76 +1736,25 @@ void delete_msg(void)
void move_msg(void)
{
long msgid;
- char buf[SIZ];
msgid = lbstr("msgid");
if (havebstr("move_button")) {
- sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
- serv_puts(buf);
- serv_getln(buf, sizeof buf);
- sprintf(WC->ImportantMessage, "%s", &buf[4]);
+ StrBuf *Line;
+ serv_printf("MOVE %ld|%s", msgid, bstr("target_room"));
+ Line = NewStrBuf();
+ StrBuf_ServGetln(Line);
+ GetServerStatusMsg(Line, NULL, 1, 0);
+ FreeStrBuf(&Line);
} else {
- sprintf(WC->ImportantMessage, (_("The message was not moved.")));
+ AppendImportantMessage(_("The message was not moved."), -1);
}
+ fixview();
readloop(readnew, eUseDefault);
}
-/*
- * Confirm move of a message
- */
-void confirm_move_msg(void)
-{
- long msgid;
- char buf[SIZ];
- char targ[SIZ];
-
- msgid = lbstr("msgid");
-
-
- output_headers(1, 1, 2, 0, 0, 0);
- wc_printf("\n");
- wc_printf("
");
- wc_printf(_("Confirm move of message"));
- wc_printf("
");
- wc_printf("\n");
-
- wc_printf("\n");
-
- wc_printf("
");
-
- wc_printf(_("Move this message to:"));
- wc_printf("
\n");
-
- wc_printf("\n");
-
- wc_printf("\n");
- wDumpContent(1);
-}
-
/*
* Generic function to output an arbitrary MIME attachment from
@@ -1547,7 +1806,9 @@ void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
*/
void mimepart(int force_download)
{
+ int detect_mime = 0;
long msgnum;
+ long ErrorDetail;
StrBuf *att;
wcsession *WCC = WC;
StrBuf *Buf;
@@ -1561,32 +1822,60 @@ void mimepart(int force_download)
serv_printf("OPNA %ld|%s", msgnum, ChrPtr(att));
StrBuf_ServGetln(Buf);
- if (GetServerStatus(Buf, NULL) == 2) {
+ if (GetServerStatus(Buf, &ErrorDetail) == 2) {
StrBufCutLeft(Buf, 4);
bytes = StrBufExtract_long(Buf, 0, '|');
- if (!force_download) {
- StrBufExtract_token(ContentType, Buf, 3, '|');
+ StrBufExtract_token(ContentType, Buf, 3, '|');
+ CheckGZipCompressionAllowed (SKEY(ContentType));
+ if (force_download)
+ {
+ FlushStrBuf(ContentType);
+ detect_mime = 0;
}
-
- serv_read_binary(WCC->WBuf, bytes, Buf);
- serv_puts("CLOS");
- StrBuf_ServGetln(Buf);
- CT = ChrPtr(ContentType);
-
- if (!force_download) {
- if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
+ else
+ {
+ if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream"))
+ {
StrBufExtract_token(Buf, WCC->Hdr->HR.ReqLine, 2, '/');
CT = GuessMimeByFilename(SKEY(Buf));
+ StrBufPlain(ContentType, CT, -1);
}
- if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
- CT = GuessMimeType(SKEY(WCC->WBuf));
+ if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream"))
+ {
+ detect_mime = 1;
}
}
- http_transmit_thing(CT, 0);
+ serv_read_binary_to_http(ContentType, bytes, 0, detect_mime);
+
+ serv_read_binary(WCC->WBuf, bytes, Buf);
+ serv_puts("CLOS");
+ StrBuf_ServGetln(Buf);
+ CT = ChrPtr(ContentType);
} else {
StrBufCutLeft(Buf, 4);
- hprintf("HTTP/1.1 404 %s\n", ChrPtr(Buf));
- output_headers(0, 0, 0, 0, 0, 0);
+ switch (ErrorDetail) {
+ default:
+ case ERROR + MESSAGE_NOT_FOUND:
+ hprintf("HTTP/1.1 404 %s\n", ChrPtr(Buf));
+ break;
+ case ERROR + NOT_LOGGED_IN:
+ hprintf("HTTP/1.1 401 %s\n", ChrPtr(Buf));
+ break;
+
+ case ERROR + HIGHER_ACCESS_REQUIRED:
+ hprintf("HTTP/1.1 403 %s\n", ChrPtr(Buf));
+ break;
+ case ERROR + INTERNAL_ERROR:
+ case ERROR + TOO_BIG:
+ hprintf("HTTP/1.1 500 %s\n", ChrPtr(Buf));
+ break;
+ }
+
+ hprintf("Pragma: no-cache\r\n"
+ "Cache-Control: no-store\r\n"
+ "Expires: -1\r\n"
+ );
+
hprintf("Content-Type: text/plain\r\n");
begin_burst();
wc_printf(_("An error occurred while retrieving this part: %s\n"),
@@ -1655,8 +1944,6 @@ void MimeLoadData(wc_mime_attachment *Mime)
}
-
-
void view_mimepart(void) {
mimepart(0);
}
@@ -1691,6 +1978,13 @@ void download_postpart(void) {
FreeStrBuf(&partnum);
}
+
+
+void show_num_attachments(void) {
+ wc_printf("%d", GetCount(WC->attachments));
+}
+
+
void h_readnew(void) { readloop(readnew, eUseDefault);}
void h_readold(void) { readloop(readold, eUseDefault);}
void h_readfwd(void) { readloop(readfwd, eUseDefault);}
@@ -1699,31 +1993,23 @@ void h_do_search(void) { readloop(do_search, eUseDefault);}
void h_readgt(void) { readloop(readgt, eUseDefault);}
void h_readlt(void) { readloop(readlt, eUseDefault);}
-void jsonMessageListHdr(void)
-{
- /* TODO: make a generic function */
- hprintf("HTTP/1.1 200 OK\r\n");
- hprintf("Content-type: application/json; charset=utf-8\r\n");
- hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
- hprintf("Connection: close\r\n");
- hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
- begin_burst();
-}
/* Output message list in JSON format */
void jsonMessageList(void) {
+ StrBuf *View = NewStrBuf();
const StrBuf *room = sbstr("room");
long oper = (havebstr("query")) ? do_search : readnew;
- WC->is_ajax = 1;
+ StrBufPrintf(View, "%d", VIEW_JSON_LIST);
+ putbstr("view", View);;
gotoroom(room);
readloop(oper, eUseDefault);
- WC->is_ajax = 0;
}
void RegisterReadLoopHandlerset(
int RoomType,
GetParamsGetServerCall_func GetParamsGetServerCall,
+ PrintViewHeader_func PrintPageHeader,
PrintViewHeader_func PrintViewHeader,
load_msg_ptrs_detailheaders LH,
LoadMsgFromServer_func LoadMsgFromServer,
@@ -1737,6 +2023,7 @@ void RegisterReadLoopHandlerset(
Handler->RoomType = RoomType;
Handler->GetParamsGetServerCall = GetParamsGetServerCall;
+ Handler->PrintPageHeader = PrintPageHeader;
Handler->PrintViewHeader = PrintViewHeader;
Handler->LoadMsgFromServer = LoadMsgFromServer;
Handler->RenderView_or_Tail = RenderView_or_Tail;
@@ -1770,31 +2057,44 @@ InitModule_MSG
NULL);
RegisterPreference("mailbox",_("Mailbox view mode"), PRF_STRING, NULL);
- WebcitAddUrlHandler(HKEY("readnew"), "", 0, h_readnew, NEED_URL);
- WebcitAddUrlHandler(HKEY("readold"), "", 0, h_readold, NEED_URL);
- WebcitAddUrlHandler(HKEY("readfwd"), "", 0, h_readfwd, NEED_URL);
+ WebcitAddUrlHandler(HKEY("readnew"), "", 0, h_readnew, ANONYMOUS|NEED_URL);
+ WebcitAddUrlHandler(HKEY("readold"), "", 0, h_readold, ANONYMOUS|NEED_URL);
+ WebcitAddUrlHandler(HKEY("readfwd"), "", 0, h_readfwd, ANONYMOUS|NEED_URL);
WebcitAddUrlHandler(HKEY("headers"), "", 0, h_headers, NEED_URL);
- WebcitAddUrlHandler(HKEY("readgt"), "", 0, h_readgt, NEED_URL);
- WebcitAddUrlHandler(HKEY("readlt"), "", 0, h_readlt, NEED_URL);
+ WebcitAddUrlHandler(HKEY("readgt"), "", 0, h_readgt, ANONYMOUS|NEED_URL);
+ WebcitAddUrlHandler(HKEY("readlt"), "", 0, h_readlt, ANONYMOUS|NEED_URL);
WebcitAddUrlHandler(HKEY("do_search"), "", 0, h_do_search, 0);
WebcitAddUrlHandler(HKEY("display_enter"), "", 0, display_enter, 0);
WebcitAddUrlHandler(HKEY("post"), "", 0, post_message, PROHIBIT_STARTPAGE);
WebcitAddUrlHandler(HKEY("move_msg"), "", 0, move_msg, PROHIBIT_STARTPAGE);
WebcitAddUrlHandler(HKEY("delete_msg"), "", 0, delete_msg, PROHIBIT_STARTPAGE);
- WebcitAddUrlHandler(HKEY("confirm_move_msg"), "", 0, confirm_move_msg, PROHIBIT_STARTPAGE);
WebcitAddUrlHandler(HKEY("msg"), "", 0, embed_message, NEED_URL);
WebcitAddUrlHandler(HKEY("message"), "", 0, handle_one_message, NEED_URL|XHTTP_COMMANDS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
WebcitAddUrlHandler(HKEY("printmsg"), "", 0, print_message, NEED_URL);
- WebcitAddUrlHandler(HKEY("mobilemsg"), "", 0, mobile_message_view, NEED_URL);
WebcitAddUrlHandler(HKEY("msgheaders"), "", 0, display_headers, NEED_URL);
WebcitAddUrlHandler(HKEY("mimepart"), "", 0, view_mimepart, NEED_URL);
WebcitAddUrlHandler(HKEY("mimepart_download"), "", 0, download_mimepart, NEED_URL);
WebcitAddUrlHandler(HKEY("postpart"), "", 0, view_postpart, NEED_URL|PROHIBIT_STARTPAGE);
WebcitAddUrlHandler(HKEY("postpart_download"), "", 0, download_postpart, NEED_URL|PROHIBIT_STARTPAGE);
+ WebcitAddUrlHandler(HKEY("upload_attachment"), "", 0, upload_attachment, AJAX);
+ WebcitAddUrlHandler(HKEY("remove_attachment"), "", 0, remove_attachment, AJAX);
+ WebcitAddUrlHandler(HKEY("show_num_attachments"), "", 0, show_num_attachments, AJAX);
/* json */
WebcitAddUrlHandler(HKEY("roommsgs"), "", 0, jsonMessageList,0);
+
+ l_subj = FourHash("subj", 4);
+ l_wefw = FourHash("wefw", 4);
+ l_msgn = FourHash("msgn", 4);
+ l_from = FourHash("from", 4);
+ l_rcpt = FourHash("rcpt", 4);
+ l_cccc = FourHash("cccc", 4);
+ l_replyto = FourHash("rep2", 4);
+ l_node = FourHash("node", 4);
+ l_rfca = FourHash("rfca", 4);
+ l_nvto = FourHash("nvto", 4);
+
return ;
}