X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fmessages.c;h=6af7002b58a4d29288e74584395559587b5bae67;hb=4b4dc864ede7c5d8d956febe4a0afb422b78e7c4;hp=acb2afee2669d971775b3d4db86473853d4857a9;hpb=307b5bacf88ba19b6d0ab6e0d647fd581b2c0058;p=citadel.git diff --git a/webcit/messages.c b/webcit/messages.c index acb2afee2..6af7002b5 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -20,7 +20,7 @@ #include "webcit.h" #include "webserver.h" -#include "groupdav.h" +#include "dav.h" #include "calendar.h" HashList *MsgHeaderHandler = NULL; @@ -529,7 +529,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) { @@ -540,6 +541,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; @@ -552,7 +554,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); } @@ -672,6 +688,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; @@ -692,6 +710,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; @@ -705,18 +724,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)); @@ -736,22 +745,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: @@ -764,8 +774,12 @@ 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; @@ -1007,10 +1021,10 @@ void post_message(void) const StrBuf *my_email_addr = NULL; StrBuf *CmdBuf = NULL; StrBuf *references = NULL; - int saving_to_drafts; - long HeaderLen; + int saving_to_drafts = 0; + long HeaderLen = 0; - saving_to_drafts = !strcasecmp(bstr("submit_action"), "drafts"); + saving_to_drafts = !strcasecmp(bstr("submit_action"), "draft"); Buf = NewStrBuf(); if (saving_to_drafts) { @@ -1113,7 +1127,7 @@ void post_message(void) if (saving_to_drafts) { AppendImportantMessage(_("Message has been saved to Drafts.\n"), -1); gotoroom(WCC->CurRoom.name); - display_enter(); + readloop(readnew, eUseDefault); FreeStrBuf(&Buf); return; } else if ( (havebstr("recp")) @@ -1127,8 +1141,7 @@ void post_message(void) } dont_post = lbstr("postseq"); } else { - /* FIXME */ - syslog(9, "\033[31m%s:%d: server post error: %s\033[0m", __FILE__, __LINE__, ChrPtr(Buf) + 4); + 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); @@ -1308,7 +1321,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; @@ -1324,7 +1336,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); @@ -1595,16 +1609,15 @@ void display_enter(void) rc = GetServerStatusMsg(CmdBuf, &Result, 0, 0); - if (Result == 570) { /* 570 means we have an invalid recipient listed */ - if (havebstr("recp") && - havebstr("cc" ) && - havebstr("bcc" )) { - recipient_bad = 1; /* TODO: and now????? */ - } + 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 (rc != 2) { /* Any other error means that we cannot continue */ - wc_printf("%s
\n", ChrPtr(CmdBuf) +4); /* TODO -> important message */ + AppendImportantMessage(ChrPtr(CmdBuf) + 4, StrLength(CmdBuf) - 4); FreeStrBuf(&CmdBuf); + readloop(readnew, eUseDefault); return; } FreeStrBuf(&CmdBuf); @@ -1722,6 +1735,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; @@ -1735,7 +1749,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) { @@ -1759,7 +1773,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(); @@ -1878,31 +1908,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, @@ -1916,6 +1938,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;