* mm-view.el, mm.el: view attachment size in view buffer, re-factor display size
This commit is contained in:
@ -129,12 +129,15 @@ or if not available, :body-html converted to text)."
|
|||||||
"No body found"))
|
"No body found"))
|
||||||
|
|
||||||
|
|
||||||
(defun mm/view-header (key val)
|
(defun mm/view-header (key val &optional dont-propertize-val)
|
||||||
"Show header FIELD for MSG with KEY. ie. <KEY>: value-of-FIELD."
|
"Show header FIELD for MSG with KEY. ie. <KEY>: value-of-FIELD."
|
||||||
(if val
|
(if val
|
||||||
(concat
|
(concat
|
||||||
(propertize key 'face 'mm/view-header-key-face) ": "
|
(propertize key 'face 'mm/view-header-key-face) ": "
|
||||||
(propertize val 'face 'mm/view-header-value-face) "\n")
|
(if dont-propertize-val
|
||||||
|
val
|
||||||
|
(propertize val 'face 'mm/view-header-value-face))
|
||||||
|
"\n")
|
||||||
""))
|
""))
|
||||||
|
|
||||||
|
|
||||||
@ -160,7 +163,8 @@ or if not available, :body-html converted to text)."
|
|||||||
|
|
||||||
(defun mm/view-attachments (msg)
|
(defun mm/view-attachments (msg)
|
||||||
"Display attachment information; the field looks like something like:
|
"Display attachment information; the field looks like something like:
|
||||||
:attachments ((4 \"statement Bray Eile.doc\" \"application/msword\"))."
|
:attachments ((:index 4 :name \"test123.doc\"
|
||||||
|
:mime-type \"application/msword\" :size 1234))."
|
||||||
(let ((atts (plist-get msg :attachments)))
|
(let ((atts (plist-get msg :attachments)))
|
||||||
(when atts
|
(when atts
|
||||||
(setq mm/attach-map
|
(setq mm/attach-map
|
||||||
@ -169,13 +173,23 @@ or if not available, :body-html converted to text)."
|
|||||||
(vals
|
(vals
|
||||||
(mapconcat
|
(mapconcat
|
||||||
(lambda (att)
|
(lambda (att)
|
||||||
|
(let ( (index (plist-get att :index))
|
||||||
|
(name (plist-get att :name))
|
||||||
|
(mime-type (plist-get att :mime-type))
|
||||||
|
(size (plist-get att :size)))
|
||||||
(incf id)
|
(incf id)
|
||||||
(puthash id att mm/attach-map)
|
(puthash id att mm/attach-map)
|
||||||
(concat
|
(concat
|
||||||
(propertize (nth 1 att) 'face 'mm/view-link-face)
|
(propertize (format "[%d]" id) 'face 'mm/view-attach-number-face)
|
||||||
(propertize (format "[%d]" id) 'face 'mm/view-attach-number-face)))
|
(propertize name 'face 'mm/view-link-face)
|
||||||
|
(if size
|
||||||
|
(concat
|
||||||
|
"(" (propertize (mm/display-size size) 'face 'mm/view-header-key-face)
|
||||||
|
")")
|
||||||
|
"")
|
||||||
|
)))
|
||||||
atts ", ")))
|
atts ", ")))
|
||||||
(mm/view-header (format "Attachments(%d):" id) vals)))))
|
(mm/view-header (format "Attachments(%d)" id) vals t)))))
|
||||||
|
|
||||||
(setq mm/view-mode-map nil)
|
(setq mm/view-mode-map nil)
|
||||||
(defvar mm/view-mode-map nil
|
(defvar mm/view-mode-map nil
|
||||||
@ -460,9 +474,10 @@ removing '^M' etc."
|
|||||||
(when (zerop (hash-table-count mm/attach-map))
|
(when (zerop (hash-table-count mm/attach-map))
|
||||||
(error "No attachments for this message"))
|
(error "No attachments for this message"))
|
||||||
(interactive "nAttachment to open:")
|
(interactive "nAttachment to open:")
|
||||||
(let* ((att (gethash attnum mm/attach-map)))
|
(let* ((att (gethash attnum mm/attach-map))
|
||||||
(unless att (error "Not a valid attachment number"))
|
(id (and att (plist-get att :index))))
|
||||||
(mm/proc-open (plist-get mm/current-msg :docid) (car att))))
|
(unless id (error "Not a valid attachment number"))
|
||||||
|
(mm/proc-open (plist-get mm/current-msg :docid) id)))
|
||||||
|
|
||||||
(defun mm/view-unmark ()
|
(defun mm/view-unmark ()
|
||||||
"Warn user that unmarking only works in the header list."
|
"Warn user that unmarking only works in the header list."
|
||||||
|
|||||||
@ -546,6 +546,17 @@ Also see `mu/flags-to-string'.
|
|||||||
(?T 'trashed))))
|
(?T 'trashed))))
|
||||||
(append (when flag (list flag))
|
(append (when flag (list flag))
|
||||||
(mm/string-to-flags-1 (substring str 1))))))
|
(mm/string-to-flags-1 (substring str 1))))))
|
||||||
|
|
||||||
|
|
||||||
|
(defun mm/display-size (size)
|
||||||
|
"Get a string representation of SIZE (in bytes)."
|
||||||
|
(cond
|
||||||
|
((>= size 1000000) (format "%2.1fM" (/ size 1000000.0)))
|
||||||
|
((and (>= size 1000) (< size 1000000))
|
||||||
|
(format "%2.1fK" (/ size 1000.0)))
|
||||||
|
((< size 1000) (format "%d" size))
|
||||||
|
(t "<unknown>")))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(provide 'mm)
|
(provide 'mm)
|
||||||
|
|||||||
Reference in New Issue
Block a user