* 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);
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);
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) {
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();
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 */