X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fmessages.c;h=2915ce1480d5b623c2320395ee8e7cad63830c56;hb=7ba7f73f95cad7f4ecd7f986e12095e9bb546126;hp=f2b1e1c11c0f334ef1835687ffd0bb5df03ba008;hpb=8e165dd308679f195af8614d62dbdb4e43238495;p=citadel.git
diff --git a/webcit/messages.c b/webcit/messages.c
index f2b1e1c11..2915ce148 100644
--- a/webcit/messages.c
+++ b/webcit/messages.c
@@ -1,13 +1,27 @@
/*
- * $Id$
- *
* Functions which deal with the fetching and displaying of messages.
*
+ * Copyright (c) 1996-2011 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 as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "webcit.h"
#include "webserver.h"
-#include "groupdav.h"
+#include "dav.h"
+#include "calendar.h"
HashList *MsgHeaderHandler = NULL;
HashList *MsgEvaluators = NULL;
@@ -33,7 +47,6 @@ int load_message(message_summary *Msg,
StrBuf *FoundCharset,
StrBuf **Error)
{
- wcsession *WCC = WC;
StrBuf *Buf;
StrBuf *HdrToken;
headereval *Hdr;
@@ -43,7 +56,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,26 +68,25 @@ 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;
}
/* begin everythingamundo table */
HdrToken = NewStrBuf();
- while ((StrBuf_ServGetln(Buf)>=0) && !Done) {
+ while (!Done && StrBuf_ServGetln(Buf)>=0) {
if ( (StrLength(Buf)==3) &&
!strcmp(ChrPtr(Buf), "000"))
{
Done = 1;
if (state < 2) {
- lprintf(1, _("unexpected end of message"));
if (Msg->MsgBody->Data == NULL)
Msg->MsgBody->Data = NewStrBuf();
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 ( (!strcasecmp(bstr("replying_mode"), "reply"))
+ || (!strcasecmp(bstr("replying_mode"), "replyall"))
+ ) {
+ StrBuf *to_rcpt;
+ 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(WC->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 ( (!strcasecmp(bstr("replying_mode"), "replyall"))
+ ) {
+ StrBuf *cc_rcpt = rcpt;
+ rcpt = NULL;
+ if (StrLength(cccc) > 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...
@@ -1324,7 +1572,7 @@ void display_enter(void)
Recp = sbstr("recp");
Cc = sbstr("cc");
Bcc = sbstr("bcc");
- Wikipage = sbstr("wikipage");
+ Wikipage = sbstr("page");
CmdBuf = NewStrBufPlain(NULL,
sizeof (CMD) +
@@ -1343,23 +1591,27 @@ void display_enter(void)
ChrPtr(Bcc),
ChrPtr(Wikipage));
serv_puts(ChrPtr(CmdBuf));
- serv_getln(buf, sizeof buf);
- FreeStrBuf(&CmdBuf);
+ StrBuf_ServGetln(CmdBuf);
- 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);
+ 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);
@@ -1375,20 +1627,21 @@ void display_enter(void)
void delete_msg(void)
{
long msgid;
- char buf[SIZ];
-
+ StrBuf *Line;
+
msgid = lbstr("msgid");
-
- if (WC->wc_is_trash) { /* Delete from Trash is a real delete */
+ Line = NewStrBuf();
+ if ((WC->CurRoom.RAFlags & UA_ISTRASH) != 0) { /* Delete from Trash is a real delete */
serv_printf("DELE %ld", msgid);
}
else { /* Otherwise move it to Trash */
serv_printf("MOVE %ld|_TRASH_|0", msgid);
}
- serv_getln(buf, sizeof buf);
- sprintf(WC->ImportantMessage, "%s", &buf[4]);
- readloop(readnew);
+ StrBuf_ServGetln(Line);
+ GetServerStatusMsg(Line, NULL, 1, 0);
+
+ readloop(readnew, eUseDefault);
}
@@ -1398,76 +1651,24 @@ 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);
}
- readloop(readnew);
+ 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
@@ -1482,8 +1683,10 @@ void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
void *vPart;
StrBuf *content_type;
wc_mime_attachment *part;
-
- if (GetHash(WC->attachments, SKEY(partnum), &vPart) &&
+ int i;
+
+ i = StrToi(partnum);
+ if (GetHash(WC->attachments, IKEY(i), &vPart) &&
(vPart != NULL)) {
part = (wc_mime_attachment*) vPart;
if (force_download) {
@@ -1518,6 +1721,7 @@ void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
void mimepart(int force_download)
{
long msgnum;
+ long ErrorDetail;
StrBuf *att;
wcsession *WCC = WC;
StrBuf *Buf;
@@ -1531,14 +1735,14 @@ 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, '|');
}
- read_server_binary(WCC->WBuf, bytes, Buf);
+ serv_read_binary(WCC->WBuf, bytes, Buf);
serv_puts("CLOS");
StrBuf_ServGetln(Buf);
CT = ChrPtr(ContentType);
@@ -1555,7 +1759,23 @@ void mimepart(int force_download)
http_transmit_thing(CT, 0);
} else {
StrBufCutLeft(Buf, 4);
- hprintf("HTTP/1.1 404 %s\n", ChrPtr(Buf));
+ 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;
+ }
output_headers(0, 0, 0, 0, 0, 0);
hprintf("Content-Type: text/plain\r\n");
begin_burst();
@@ -1599,14 +1819,20 @@ StrBuf *load_mimepart(long msgnum, char *partnum)
void MimeLoadData(wc_mime_attachment *Mime)
{
StrBuf *Buf;
+ const char *Ptr;
off_t bytes;
/* TODO: is there a chance the content type is different from the one we know? */
+
serv_printf("DLAT %ld|%s", Mime->msgnum, ChrPtr(Mime->PartNum));
Buf = NewStrBuf();
StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) == 6) {
- bytes = extract_long(&(ChrPtr(Buf)[4]), 0);
-
+ Ptr = &(ChrPtr(Buf)[4]);
+ bytes = StrBufExtractNext_long(Buf, &Ptr, '|');
+ StrBufSkip_NTokenS(Buf, &Ptr, '|', 3); /* filename, cbtype, mimetype */
+ if (Mime->Charset == NULL) Mime->Charset = NewStrBuf();
+ StrBufExtract_NextToken(Mime->Charset, Buf, &Ptr, '|');
+
if (Mime->Data == NULL)
Mime->Data = NewStrBufPlain(NULL, bytes);
StrBuf_ServGetBLOBBuffered(Mime->Data, bytes);
@@ -1619,8 +1845,6 @@ void MimeLoadData(wc_mime_attachment *Mime)
}
-
-
void view_mimepart(void) {
mimepart(0);
}
@@ -1655,12 +1879,20 @@ void download_postpart(void) {
FreeStrBuf(&partnum);
}
-void h_readnew(void) { readloop(readnew);}
-void h_readold(void) { readloop(readold);}
-void h_readfwd(void) { readloop(readfwd);}
-void h_headers(void) { readloop(headers);}
-void h_do_search(void) { readloop(do_search);}
-void h_readgt(void) { readloop(readgt);}
+
+
+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);}
+void h_headers(void) { readloop(headers, eUseDefault);}
+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)
{
@@ -1680,7 +1912,7 @@ void jsonMessageList(void) {
long oper = (havebstr("query")) ? do_search : readnew;
WC->is_ajax = 1;
gotoroom(room);
- readloop(oper);
+ readloop(oper, eUseDefault);
WC->is_ajax = 0;
}
@@ -1688,6 +1920,7 @@ void RegisterReadLoopHandlerset(
int RoomType,
GetParamsGetServerCall_func GetParamsGetServerCall,
PrintViewHeader_func PrintViewHeader,
+ load_msg_ptrs_detailheaders LH,
LoadMsgFromServer_func LoadMsgFromServer,
RenderView_or_Tail_func RenderView_or_Tail,
View_Cleanup_func ViewCleanup
@@ -1703,6 +1936,7 @@ void RegisterReadLoopHandlerset(
Handler->LoadMsgFromServer = LoadMsgFromServer;
Handler->RenderView_or_Tail = RenderView_or_Tail;
Handler->ViewCleanup = ViewCleanup;
+ Handler->LHParse = LH;
Put(ReadLoopHandler, IKEY(RoomType), Handler, NULL);
}
@@ -1731,30 +1965,42 @@ 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("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, 0);
- WebcitAddUrlHandler(HKEY("move_msg"), "", 0, move_msg, 0);
- WebcitAddUrlHandler(HKEY("delete_msg"), "", 0, delete_msg, 0);
- WebcitAddUrlHandler(HKEY("confirm_move_msg"), "", 0, confirm_move_msg, 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("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);
- WebcitAddUrlHandler(HKEY("postpart_download"), "", 0, download_postpart, 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_node = FourHash("node", 4);
+ l_rfca = FourHash("rfca", 4);
+
return ;
}