From: Wilfried Goesgens Date: Sat, 14 Jan 2012 15:51:47 +0000 (+0100) Subject: Merge branch 'master' of ssh://git.citadel.org/appl/gitroot/citadel X-Git-Tag: v8.11~265 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=e513f41d4e9fe894313bb9c7f8dc9938fc6db2c9;hp=57b37d4ed168b176d594bc149e5d16a1b9f0517a Merge branch 'master' of ssh://git.citadel.org/appl/gitroot/citadel --- diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 2609d1d1d..824b51bd3 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -1084,26 +1084,37 @@ void mime_download(char *name, char *filename, char *partnum, char *disp, char *encoding, char *cbid, void *cbuserdata) { int rv = 0; + CitContext *CCC = MyContext(); /* Silently go away if there's already a download open. */ - if (CC->download_fp != NULL) + if (CCC->download_fp != NULL) return; if ( - (!IsEmptyStr(partnum) && (!strcasecmp(CC->download_desired_section, partnum))) - || (!IsEmptyStr(cbid) && (!strcasecmp(CC->download_desired_section, cbid))) + (!IsEmptyStr(partnum) && (!strcasecmp(CCC->download_desired_section, partnum))) + || (!IsEmptyStr(cbid) && (!strcasecmp(CCC->download_desired_section, cbid))) ) { - CC->download_fp = tmpfile(); - if (CC->download_fp == NULL) + CCC->download_fp = tmpfile(); + if (CCC->download_fp == NULL) { + syslog(LOG_EMERG, "mime_download(): Couldn't write: %s\n", + strerror(errno)); + cprintf("%d cannot open temporary file: %s\n", + ERROR + INTERNAL_ERROR, strerror(errno)); return; + } rv = fwrite(content, length, 1, CC->download_fp); - if (rv == -1) { + if (rv <= 0) { syslog(LOG_EMERG, "mime_download(): Couldn't write: %s\n", strerror(errno)); + cprintf("%d unable to write tempfile.\n", + ERROR + TOO_BIG); + fclose(CCC->download_fp); + CCC->download_fp = NULL; + return; } - fflush(CC->download_fp); - rewind(CC->download_fp); + fflush(CCC->download_fp); + rewind(CCC->download_fp); OpenCmdResult(filename, cbtype); } diff --git a/webcit/messages.c b/webcit/messages.c index 5ae3eb0d4..2915ce148 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -1721,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; @@ -1734,7 +1735,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) { @@ -1758,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();