Support download of single part messages.
authorArun Isaac <arunisaac@systemreboot.net>
Sun, 27 Jan 2019 10:49:11 +0000 (16:19 +0530)
committerRicardo Wurmus <rekado@elephly.net>
Sun, 27 Jan 2019 11:55:42 +0000 (12:55 +0100)
* mumi/messages.scm (extract-attachment): Return <email> record for
single part messages.
* mumi/web/download.scm (handle-download): Handle <email> record type.

mumi/messages.scm
mumi/web/download.scm

index e4222e90a01ee29fb96eaf50ff49fab97f1bdc94..5cf3390cfcd09bc773c06549281535221b31d267 100644 (file)
@@ -1,6 +1,6 @@
 ;;; mumi -- Mediocre, uh, mail interface
 ;;; Copyright © 2017, 2018 Ricardo Wurmus <rekado@elephly.net>
-;;; Copyright © 2018 Arun Isaac <arunisaac@systemreboot.net>
+;;; Copyright © 2018, 2019 Arun Isaac <arunisaac@systemreboot.net>
 ;;;
 ;;; This program is free software: you can redistribute it and/or
 ;;; modify it under the terms of the GNU Affero General Public License
@@ -122,8 +122,13 @@ we have to do this in a very convoluted way."
          (lambda (bug)
            (and=> (nth msg-num (patch-messages id))
                   (lambda (msg)
-                    (and (multipart-message? msg)
-                         (traverse path (email-body msg))))))))
+                    (cond
+                     ((multipart-message? msg)
+                      (traverse path (email-body msg)))
+                     (else
+                      (match path
+                        (() msg)
+                        (_ #f)))))))))
 
 \f
 (define-public (patch-messages id)
index 9037b641de77f08eef75c4371835ae297667763f..91a8bc35eee7bba9abd5a7d9136e2b209b495ec6 100644 (file)
   "Handle download of an attachment for bug ID, message number
 MSG-NUM, in the possibly nested message part identified by the list
 PATH."
+  (define (html-response headers body)
+    (list (filter-map (match-lambda
+                        (('content-type . vals)
+                         (list 'content-type
+                               (or (assoc-ref vals 'type) 'text)))
+                        (('content-disposition . vals)
+                         (list 'content-disposition
+                               (assoc-ref vals 'type)
+                               `(filename . ,(or (assoc-ref vals 'filename)
+                                                 "attachment"))))
+                        (_ #f))
+                      headers)
+          body))
+
   (or (and=> (extract-attachment id msg-num path)
              (match-lambda
                ((? mime-entity? entry)
-                (let ((headers (mime-entity-headers entry))
-                      (body (mime-entity-body entry)))
-                  (list (filter-map (match-lambda
-                                      (('content-type . vals)
-                                       (list 'content-type
-                                             (or (assoc-ref vals 'type) 'text)))
-                                      (('content-disposition . vals)
-                                       (list 'content-disposition
-                                             (assoc-ref vals 'type)
-                                             `(filename . ,(or (assoc-ref vals 'filename)
-                                                               "attachment"))))
-                                      (_ #f))
-                                    headers)
-                        body)))
+                (html-response (mime-entity-headers entry) (mime-entity-body entry)))
+               ((? email? entry)
+                (html-response (email-headers entry) (email-body entry)))
                (_ #f)))
       (apply render-html (unknown id))))