From e750b927c009c86df2ee10f273e2ad11e8b523ae Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Tue, 17 Feb 2009 22:02:27 +0000 Subject: [PATCH] * if the mail doesn't give us a mimetype (..or just application/octetstream) use xdgmime to try to find out. --- webcit/messages.c | 32 ++++++++++++++++++++------------ webcit/webcit.c | 9 ++++++--- webcit/webcit.h | 1 + 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/webcit/messages.c b/webcit/messages.c index db867fb12..a913b254d 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -1529,13 +1529,16 @@ void postpart(StrBuf *partnum, StrBuf *filename, int force_download) * partnum The MIME part to be output * force_download Nonzero to force set the Content-Type: header to "application/octet-stream" */ -void mimepart(const char *msgnum, const char *partnum, int force_download) +void mimepart(int force_download) { + wcsession *WCC = WC; + char buf[256]; off_t bytes; char content_type[256]; - - serv_printf("OPNA %s|%s", msgnum, partnum); + const char *ContentType = &content_type[0]; + + serv_printf("OPNA %s|%s", ChrPtr(WCC->UrlFragment2), ChrPtr(WCC->UrlFragment3)); serv_getln(buf, sizeof buf); if (buf[0] == '2') { bytes = extract_long(&buf[4], 0); @@ -1545,12 +1548,21 @@ void mimepart(const char *msgnum, const char *partnum, int force_download) else { extract_token(content_type, &buf[4], 3, '|', sizeof content_type); } - output_headers(0, 0, 0, 0, 0, 0); - read_server_binary(WC->WBuf, bytes); + read_server_binary(WCC->WBuf, bytes); serv_puts("CLOS"); serv_getln(buf, sizeof buf); - http_transmit_thing(content_type, 0); + + if (!force_download) { + if (!strcasecmp(ContentType, "application/octet-stream")) { + ContentType = GuessMimeByFilename(SKEY(WCC->UrlFragment4)); + } + if (!strcasecmp(ContentType, "application/octet-stream")) { + ContentType = GuessMimeType(SKEY(WCC->WBuf)); + } + } + output_headers(0, 0, 0, 0, 0, 0); + http_transmit_thing(ContentType, 0); } else { hprintf("HTTP/1.1 404 %s\n", &buf[4]); output_headers(0, 0, 0, 0, 0, 0); @@ -1616,15 +1628,11 @@ void MimeLoadData(wc_mime_attachment *Mime) void view_mimepart(void) { - mimepart(ChrPtr(WC->UrlFragment2), - ChrPtr(WC->UrlFragment3), - 0); + mimepart(0); } void download_mimepart(void) { - mimepart(ChrPtr(WC->UrlFragment2), - ChrPtr(WC->UrlFragment3), - 1); + mimepart(1); } void view_postpart(void) { diff --git a/webcit/webcit.c b/webcit/webcit.c index 74d3469bb..fdde5ef53 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -999,9 +999,12 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method WCC->UrlFragment2 = NewStrBuf(); if (WCC->UrlFragment3 == NULL) WCC->UrlFragment3 = NewStrBuf(); - StrBufPrintf(WCC->UrlFragment1, "%s", index[0]); - StrBufPrintf(WCC->UrlFragment2, "%s", index[1]); - StrBufPrintf(WCC->UrlFragment3, "%s", index[2]); + if (WCC->UrlFragment4 == NULL) + WCC->UrlFragment4 = NewStrBuf(); + StrBufPlain(WCC->UrlFragment1, index[0], -1); + StrBufPlain(WCC->UrlFragment2, index[1], -1); + StrBufPlain(WCC->UrlFragment3, index[2], -1); + StrBufPlain(WCC->UrlFragment4, index[3], -1); } if ((Handler->Flags & AJAX) != 0) begin_ajax_response(); diff --git a/webcit/webcit.h b/webcit/webcit.h index 34c3a4ad2..24a5fed86 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -350,6 +350,7 @@ struct wcsession { StrBuf *UrlFragment1; /**< first urlfragment, if NEED_URL is specified by the handler*/ StrBuf *UrlFragment2; /**< second urlfragment, if NEED_URL is specified by the handler*/ StrBuf *UrlFragment3; /**< third urlfragment, if NEED_URL is specified by the handler*/ + StrBuf *UrlFragment4; /**< fourth urlfragment, if NEED_URL is specified by the handler*/ StrBuf *WBuf; /**< Our output buffer */ StrBuf *HBuf; /**< Our HeaderBuffer */ StrBuf *this_page; /**< URL of current page */ -- 2.39.2