X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fmessages.c;h=c362b2f6369cca696c1b44dfb3d5aa239138b255;hb=3841dfefb6b086720b6d5d9af39aaf8b19730e6d;hp=560e031f425022bec7dc0e2251cff59a08d03a7f;hpb=814d4bec141c8374ef72a60aeeded0d696483c5e;p=citadel.git diff --git a/webcit/messages.c b/webcit/messages.c index 560e031f4..c362b2f63 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -1,26 +1,20 @@ /* * Functions which deal with the fetching and displaying of messages. * - * Copyright (c) 1996-2011 by the citadel.org team + * 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 as - * published by the Free Software Foundation; either version 3 of the - * License, or (at your option) any later version. + * 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. - * - * 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; @@ -43,6 +37,15 @@ 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) @@ -235,10 +238,11 @@ int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, co evaluate_mime_part(Msg, Mime); } DeleteHashPos(&it); - memset(&SubTP, 0, sizeof(WCTemplputParams)); - SubTP.Filter.ContextType = CTX_MAILSUM; - SubTP.Context = Msg; - *OutMime = DoTemplate(tmpl, tmpllen, Target, &SubTP); + StackContext(NULL, &SubTP, Msg, CTX_MAILSUM, 0, NULL); + { + *OutMime = DoTemplate(tmpl, tmpllen, Target, &SubTP); + } + UnStackContext(&SubTP); DestroyMessageSummary(Msg); FreeStrBuf(&FoundCharset); @@ -362,9 +366,7 @@ void handle_one_message(void) serv_printf("MOVE %ld|_TRASH_|0", msgnum); } StrBuf_ServGetln(CmdBuf); - FlushStrBuf(WCC->ImportantMsg); - StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4); - GetServerStatus(CmdBuf, &CitStatus); + GetServerStatusMsg(CmdBuf, &CitStatus, 1, 0); HttpStatus(CitStatus); break; case eCOPY: @@ -375,8 +377,7 @@ void handle_one_message(void) Destination = (StrBuf*) vLine; serv_printf("MOVE %ld|%s|%d", msgnum, ChrPtr(Destination), CopyMessage); StrBuf_ServGetln(CmdBuf); - FlushStrBuf(WCC->ImportantMsg); - StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4); + GetServerStatusMsg(CmdBuf, NULL, 1, 0); GetServerStatus(CmdBuf, &CitStatus); HttpStatus(CitStatus); } @@ -402,6 +403,8 @@ void embed_message(void) { StrBuf *CmdBuf = NULL; msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/'); + if (msgnum <= 0) return; + switch (WCC->Hdr->HR.eReqType) { case eGET: @@ -422,8 +425,7 @@ void embed_message(void) { serv_printf("MOVE %ld|_TRASH_|0", msgnum); } StrBuf_ServGetln(CmdBuf); - FlushStrBuf(WCC->ImportantMsg); - StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4); + GetServerStatusMsg(CmdBuf, NULL, 1, 0); break; default: break; @@ -531,7 +533,8 @@ message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSu * * servcmd: the citadel command to send to the citserver */ -int load_msg_ptrs(const char *servcmd, +int load_msg_ptrs(const char *servcmd, + const char *filter, SharedMessageStatus *Stat, load_msg_ptrs_detailheaders LH) { @@ -542,6 +545,7 @@ int load_msg_ptrs(const char *servcmd, int n; int skipit; const char *Ptr = NULL; + int StatMajor; Stat->lowest_found = LONG_MAX; Stat->highest_found = LONG_MIN; @@ -554,7 +558,21 @@ int load_msg_ptrs(const char *servcmd, Buf = NewStrBuf(); serv_puts(servcmd); StrBuf_ServGetln(Buf); - if (GetServerStatus(Buf, NULL) != 1) { + StatMajor = GetServerStatus(Buf, NULL); + switch (StatMajor) { + case 1: + break; + case 8: + if (filter != NULL) { + serv_puts(filter); + serv_puts("000"); + break; + } + /* fall back to empty filter in case of we were fooled... */ + serv_puts(""); + serv_puts("000"); + break; + default: FreeStrBuf(&Buf); return (Stat->nummsgs); } @@ -674,6 +692,8 @@ typedef struct _RoomRenderer{ int RoomType; GetParamsGetServerCall_func GetParamsGetServerCall; + + PrintViewHeader_func PrintPageHeader; PrintViewHeader_func PrintViewHeader; LoadMsgFromServer_func LoadMsgFromServer; RenderView_or_Tail_func RenderView_or_Tail; @@ -694,6 +714,7 @@ void readloop(long oper, eCustomRoomRenderer ForceRenderer) void *vMsg; message_summary *Msg; char cmd[256] = ""; + char filter[256] = ""; int i, r; wcsession *WCC = WC; HashPos *at; @@ -707,18 +728,8 @@ void readloop(long oper, eCustomRoomRenderer ForceRenderer) WCC->CurRoom.view = VIEW_MAILBOX; } - if (havebstr("is_ajax") && (1 == (ibstr("is_ajax")))) { - WCC->is_ajax = 1; - } - - if ((oper == do_search) && (WCC->CurRoom.view == VIEW_WIKI)) { - display_wiki_pagelist(); - return; - } - - if (WCC->CurRoom.view == VIEW_WIKI) { - http_redirect("wiki?page=home"); - return; + if (havebstr("view")) { + WCC->CurRoom.view = ibstr("view"); } memset(&Stat, 0, sizeof(SharedMessageStatus)); @@ -738,22 +749,23 @@ void readloop(long oper, eCustomRoomRenderer ForceRenderer) } ViewMsg = (RoomRenderer*) vViewMsg; - if (!WCC->is_ajax) { + if (ViewMsg->PrintPageHeader == NULL) output_headers(1, 1, 1, 0, 0, 0); - } else if (WCC->CurRoom.view == VIEW_MAILBOX) { - jsonMessageListHdr(); - } + else + ViewMsg->PrintPageHeader(&Stat, ViewSpecific); if (ViewMsg->GetParamsGetServerCall != NULL) { r = ViewMsg->GetParamsGetServerCall( &Stat, &ViewSpecific, oper, - cmd, sizeof(cmd) + cmd, sizeof(cmd), + filter, sizeof(filter) ); } else { r = 0; } + switch(r) { case 400: @@ -766,16 +778,23 @@ void readloop(long oper, eCustomRoomRenderer ForceRenderer) default: break; } - if (!IsEmptyStr(cmd)) - Stat.nummsgs = load_msg_ptrs(cmd, &Stat, ViewMsg->LHParse); + if (!IsEmptyStr(cmd)) { + const char *p = NULL; + if (!IsEmptyStr(filter)) + p = filter; + Stat.nummsgs = load_msg_ptrs(cmd, p, &Stat, ViewMsg->LHParse); + } if (Stat.sortit) { CompareFunc SortIt; - memset(&SubTP, 0, sizeof(WCTemplputParams)); - SubTP.Filter.ContextType = CTX_MAILSUM; - SubTP.Context = NULL; - SortIt = RetrieveSort(&SubTP, NULL, 0, - HKEY("date"), Stat.defaultsortorder); + StackContext(NULL, &SubTP, NULL, CTX_MAILSUM, 0, NULL); + { + SortIt = RetrieveSort(&SubTP, + NULL, 0, + HKEY("date"), + Stat.defaultsortorder); + } + UnStackContext(&SubTP); if (SortIt != NULL) SortByPayload(WCC->summ, SortIt); } @@ -1005,26 +1024,24 @@ void post_message(void) StrBuf *Recp = NULL; StrBuf *Cc = NULL; StrBuf *Bcc = NULL; - const StrBuf *Wikipage = NULL; + char *wikipage = NULL; const StrBuf *my_email_addr = NULL; StrBuf *CmdBuf = NULL; StrBuf *references = NULL; - int save_to_drafts; - long HeaderLen; + int saving_to_drafts = 0; + long HeaderLen = 0; - save_to_drafts = !strcasecmp(bstr("submit_action"), "drafts"); + saving_to_drafts = !strcasecmp(bstr("submit_action"), "draft"); Buf = NewStrBuf(); - if (save_to_drafts) { + if (saving_to_drafts) { /* temporarily change to the drafts room */ serv_puts("GOTO _DRAFTS_"); StrBuf_ServGetln(Buf); - if (GetServerStatus(Buf, NULL) != 2) { + if (GetServerStatusMsg(Buf, NULL, 1, 2) != 2) { /* You probably don't even have a dumb Drafts folder */ - StrBufCutLeft(Buf, 4); - syslog(9, "%s:%d: server save to drafts error: %s\n", __FILE__, __LINE__, ChrPtr(Buf)); - StrBufAppendBufPlain(WCC->ImportantMsg, _("Saved to Drafts failed: "), -1, 0); - StrBufAppendBuf(WCC->ImportantMsg, Buf, 0); + syslog(9, "%s:%d: server save to drafts error: %s\n", __FILE__, __LINE__, ChrPtr(Buf) + 4); + AppendImportantMessage(_("Saved to Drafts failed: "), -1); display_enter(); FreeStrBuf(&Buf); return; @@ -1062,34 +1079,36 @@ void post_message(void) FreeStrBuf(&EmailAddress); FreeStrBuf(&EncBuf); - Wikipage = sbstr("page"); + wikipage = strdup(bstr("page")); + str_wiki_index(wikipage); my_email_addr = sbstr("my_email_addr"); HeaderLen = StrLength(Recp) + StrLength(encoded_subject) + StrLength(Cc) + StrLength(Bcc) + - StrLength(Wikipage) + + strlen(wikipage) + StrLength(my_email_addr) + StrLength(references); CmdBuf = NewStrBufPlain(NULL, sizeof (CMD) + HeaderLen); StrBufPrintf(CmdBuf, CMD, - save_to_drafts?"":ChrPtr(Recp), + saving_to_drafts?"":ChrPtr(Recp), is_anonymous, ChrPtr(encoded_subject), ChrPtr(display_name), - save_to_drafts?"":ChrPtr(Cc), - save_to_drafts?"":ChrPtr(Bcc), - ChrPtr(Wikipage), + saving_to_drafts?"":ChrPtr(Cc), + saving_to_drafts?"":ChrPtr(Bcc), + wikipage, ChrPtr(my_email_addr), ChrPtr(references)); FreeStrBuf(&references); FreeStrBuf(&encoded_subject); + free(wikipage); if ((HeaderLen + StrLength(sbstr("msgtext")) < 10) && (GetCount(WCC->attachments) == 0)){ - StrBufAppendBufPlain(WCC->ImportantMsg, _("Refusing to post empty message.\n"), -1, 0); + AppendImportantMessage(_("Refusing to post empty message.\n"), -1); FreeStrBuf(&CmdBuf); } @@ -1101,7 +1120,7 @@ void post_message(void) StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 4) { - if (save_to_drafts) { + if (saving_to_drafts) { if ( (havebstr("recp")) || (havebstr("cc" )) || (havebstr("bcc" )) ) { @@ -1114,29 +1133,29 @@ void post_message(void) } } post_mime_to_server(); - if (save_to_drafts) { - StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been saved to Drafts.\n"), -1, 0); + if (saving_to_drafts) { + AppendImportantMessage(_("Message has been saved to Drafts.\n"), -1); gotoroom(WCC->CurRoom.name); - display_enter(); + fixview(); + readloop(readnew, eUseDefault); FreeStrBuf(&Buf); return; } else if ( (havebstr("recp")) || (havebstr("cc" )) || (havebstr("bcc" )) ) { - StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been sent.\n"), -1, 0); + AppendImportantMessage(_("Message has been sent.\n"), -1); } else { - StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been posted.\n"), -1, 0); + AppendImportantMessage(_("Message has been posted.\n"), -1); } dont_post = lbstr("postseq"); } else { - StrBufCutLeft(Buf, 4); - - syslog(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, ChrPtr(Buf)); - StrBufAppendBuf(WCC->ImportantMsg, Buf, 0); - if (save_to_drafts) gotoroom(WCC->CurRoom.name); + syslog(9, "%s:%d: server post error: %s", __FILE__, __LINE__, ChrPtr(Buf) + 4); + AppendImportantMessage(ChrPtr(Buf) + 4, StrLength(Buf) - 4); display_enter(); + if (saving_to_drafts) gotoroom(WCC->CurRoom.name); + FreeStrBuf(&Recp); FreeStrBuf(&Buf); FreeStrBuf(&Cc); FreeStrBuf(&Bcc); @@ -1169,6 +1188,7 @@ void post_message(void) * Otherwise, just go to the "read messages" loop. */ else { + fixview(); readloop(readnew, eUseDefault); } } @@ -1312,7 +1332,6 @@ void display_enter(void) const StrBuf *display_name = NULL; int recipient_required = 0; int subject_required = 0; - int recipient_bad = 0; int is_anonymous = 0; wcsession *WCC = WC; int i = 0; @@ -1328,7 +1347,9 @@ void display_enter(void) is_anonymous = 1; } - /* First test to see whether this is a room that requires recipients to be entered */ + /* + * First, do we have permission to enter messages in this room at all? + */ Line = NewStrBuf(); serv_puts("ENT0 0"); StrBuf_ServGetln(Line); @@ -1339,6 +1360,7 @@ void display_enter(void) } else if (rc != 2) { /* Any other error means that we cannot continue */ rc = GetServerStatusMsg(Line, &Result, 0, 2); + fixview(); readloop(readnew, eUseDefault); FreeStrBuf(&Line); return; @@ -1405,12 +1427,14 @@ void display_enter(void) { long which = 0; if ((StrLength(Line) > 4) && - (ChrPtr(Line)[5] == '=')) + (ChrPtr(Line)[4] == '=')) which = FourHash(ChrPtr(Line), 4); if (which == l_subj) { StrBuf *subj = NewStrBuf(); + StrBuf *FlatSubject; + if (!strcasecmp(bstr("replying_mode"), "forward")) { if (strncasecmp(ChrPtr(Line) + 5, "Fw:", 3)) { StrBufAppendBufPlain(subj, HKEY("Fw: "), 0); @@ -1424,7 +1448,10 @@ void display_enter(void) StrBufAppendBufPlain(subj, ChrPtr(Line) + 5, StrLength(Line) - 5, 0); - PutBstr(HKEY("subject"), subj); + FlatSubject = NewStrBufPlain(NULL, StrLength(subj)); + StrBuf_RFC822_to_Utf8(FlatSubject, subj, NULL, NULL); + + PutBstr(HKEY("subject"), FlatSubject); } else if (which == l_wefw) @@ -1449,7 +1476,12 @@ void display_enter(void) } else if (which == l_from) { + StrBuf *FlatFrom; from = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5); + FlatFrom = NewStrBufPlain(NULL, StrLength(from)); + StrBuf_RFC822_to_Utf8(FlatFrom, from, NULL, NULL); + FreeStrBuf(&from); + from = FlatFrom; for (i=0; i%s
\n", ChrPtr(CmdBuf) +4); /* TODO -> important message */ + AppendImportantMessage(ChrPtr(CmdBuf) + 4, StrLength(CmdBuf) - 4); FreeStrBuf(&CmdBuf); + fixview(); + readloop(readnew, eUseDefault); return; } FreeStrBuf(&CmdBuf); @@ -1631,6 +1671,8 @@ void delete_msg(void) StrBuf_ServGetln(Line); GetServerStatusMsg(Line, NULL, 1, 0); + fixview(); + readloop(readnew, eUseDefault); } @@ -1655,6 +1697,7 @@ void move_msg(void) AppendImportantMessage(_("The message was not moved."), -1); } + fixview(); readloop(readnew, eUseDefault); } @@ -1711,6 +1754,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; @@ -1724,7 +1768,7 @@ 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) { @@ -1748,7 +1792,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(); @@ -1867,31 +1927,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, @@ -1905,6 +1957,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;