Handle nested mime entries recursively.
authorRicardo Wurmus <rekado@elephly.net>
Sun, 11 Nov 2018 19:43:04 +0000 (20:43 +0100)
committerRicardo Wurmus <rekado@elephly.net>
Sun, 11 Nov 2018 19:43:04 +0000 (20:43 +0100)
* mumi/web/view/utils.scm (display-message-body): Apply
display-mime-entity recursively.

mumi/web/view/utils.scm

index 69df0c0..2c58467 100644 (file)
 (define (display-message-body bug-num message-number message)
   "Convenience procedure to render MESSAGE (part of bug with number
 BUG-NUM), even when it is a multipart message."
-  (define (display-multipart-chunk headers body path)
+  (define (display-multipart-chunk headers body path)
     (define (attachment-url)
       (string-append "/issue/"
                      (number->string bug-num)
@@ -147,22 +147,22 @@ BUG-NUM), even when it is a multipart message."
                    (a (@ (href ,(attachment-url)))
                       "Download"))
               ,(prettify body))))))
+  (define (display-mime-entity entity . path)
+    (match entity
+      (($ <mime-entity> headers (? string? body))
+       (apply display-multipart-chunk `(,headers ,body ,path)))
+      ;; Message parts can be nested.
+      (($ <mime-entity> headers sub-parts)
+       (map (lambda (part sub-part-num)
+              (apply display-mime-entity part
+                     (append path (list sub-part-num))))
+            sub-parts
+            (iota (length sub-parts))))))
   (cond
    ((multipart-message? message)
     (let ((parts (email-body message)))
       (map (lambda (part part-num)
-             (match part
-               (($ <mime-entity> headers (? string? body))
-                (display-multipart-chunk headers body part-num))
-               ;; Message parts can be nested.
-               (($ <mime-entity> headers sub-parts)
-                (map (lambda (part sub-part-num)
-                       (match part
-                         (($ <mime-entity> headers body)
-                          (display-multipart-chunk
-                           headers body part-num sub-part-num))))
-                     sub-parts
-                     (iota (length sub-parts))))))
+             (display-mime-entity part part-num))
            parts
            (iota (length parts)))))
    ;; Regular message with a simple body.