* if the mail doesn't give us a mimetype (..or just application/octetstream) use...
authorWilfried Göesgens <willi@citadel.org>
Tue, 17 Feb 2009 22:02:27 +0000 (22:02 +0000)
committerWilfried Göesgens <willi@citadel.org>
Tue, 17 Feb 2009 22:02:27 +0000 (22:02 +0000)
webcit/messages.c
webcit/webcit.c
webcit/webcit.h

index db867fb1283b4b3f19c930a47ebc09c2c1271939..a913b254dd5842ca9f4c576b834e4c02285921bf 100644 (file)
@@ -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) {
index 74d3469bb8d93cb788d30f786a401343290e96d6..fdde5ef53de869668d7f243aefc24c420198f9d9 100644 (file)
@@ -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();
index 34c3a4ad28f4eaf933a924a01759af003b80d0b5..24a5fed86b8ff654fb6c4b76707fa86ca722827f 100644 (file)
@@ -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 */