view/utils: Show attachment size.
authorRicardo Wurmus <rekado@elephly.net>
Fri, 15 May 2020 11:02:58 +0000 (13:02 +0200)
committerRicardo Wurmus <rekado@elephly.net>
Fri, 15 May 2020 11:02:58 +0000 (13:02 +0200)
mumi/web/view/utils.scm

index 27cd2de9c51ce7ad4e574d42245d47d4e69ce42b..3c956441d51e7dfff2047d80164708d76a55aee0 100644 (file)
@@ -18,6 +18,7 @@
 ;;; <http://www.gnu.org/licenses/>.
 
 (define-module (mumi web view utils)
+  #:use-module (ice-9 format)
   #:use-module (ice-9 rdelim)
   #:use-module (ice-9 match)
   #:use-module (ice-9 regex)
@@ -250,7 +251,15 @@ BUG-NUM), even when it is a multipart message."
        ((or html? hide-attachment?)
         `(div (@ (class "attachment"))
               "Attachment: "
-              (a (@ (href ,(attachment-url))) ,attachment-name)))
+              (a (@ (href ,(attachment-url))) ,attachment-name)
+              ,(or (and=> (assoc-ref headers 'content-disposition)
+                          (lambda (disposition)
+                            (and=> (assoc-ref disposition 'size)
+                                   (lambda (bytes)
+                                     (format #f " (~1,2f MiB)"
+                                             (exact->inexact
+                                              (/ bytes 1024 1024)))))))
+                   "")))
        ((string-suffix? ".scm" attachment-name)
         `(div (@ (class "multipart scheme"))
               (div (@ (class "download-part"))