On 2017-05-10, Magnus Therning wrote:
>
> I receive quite a lot of email in multipart/alternative format.
> Currently mu4e prefers to show the HTML part (when available), which
> results in the following questions:
>
> 1. How can I configure what part mu4e prefers? (I've so far had no
> luck with 'mm-discouraged-alternatives and 'mm-automatic-display, so
> I'm guessing mu4e has some other way of configuring this.)
(setq mu4e-view-prefer-html t)
(setq mu4e-view-prefer-html nil)
> 2. How can I switch between parts? (Some emails are sent with dodgy
> clients and the text part doesn't reflect the contents of the HTML
> part so I need to be able to switch between them.)
Usually, the HTML part is more complete. I use shr to display the HTML
part which is slow but the rendering is good (whatever the color
background). I use the following code:
(setq mu4e-html2text-command #'my/shr-mu4e-html2text-command)
(defadvice shr-colorize-region (before default-bg-color compile
activate)
"Use the default background color."
(setq bg nil))
(defun my/shr-mu4e-html2text-command (msg)
;; Use the (private) variable `mu4e~view-msg' for `msg'.
(let ((shr-color-visible-luminance-min 65)
;(shr-use-fonts nil)
(shr-blocked-images "https?://.*"); No web access
(shr-inhibit-images nil)
(shr-width nil)
(html (or (mu4e-message-field msg :body-html) ""))
(attachments (remove-if (lambda (part)
(or (null (plist-get
part :attachment))
(null (plist-get part :cid))))
(mu4e-message-field msg :parts)))
shr-content-function)
(when (and (display-images-p) mu4e-view-show-images)
(defun my/shr-content-function (cid)
(let* ((a (find cid attachments
:test (lambda(c a) (string= c (plist-get
a :cid)))))
(fname
(if (plist-get a :temp)
(plist-get a :temp)
(let ((tmp-attachment-name
(concat temporary-file-directory
(plist-get a :name))))
(if (plist-get a :index)
(progn
(mu4e~proc-extract 'save
(mu4e-message-field
msg :docid)
(plist-get a :index)
mu4e-decryption-policy
tmp-attachment-name)
(mu4e-remove-file-later tmp-attachment-name)
tmp-attachment-name)
(mu4e-message "cid %s does not exist" (mu4e~escape
cid))
))))
(ty (plist-get a :mime-type))
(img (ignore-errors
(with-temp-buffer
(mm-disable-multibyte)
(if fname
(insert-file-contents-literally fname))
(buffer-substring-no-properties
(point-min) (point-max))))))
(list img ty)))
(setq shr-content-function #'my/shr-content-function))
(let ((max-specpdl-size 3000))
;; FIXME: have a fallback when an error occurs
(with-temp-buffer
(insert html)
(shr-render-region (point-min) (point-max))
;; (mu4e-rewrite-cid-to-file-links msg)
;; (w3m-region (point-min) (point-max))
;; (w3m-toggle-inline-image t)
;;(whitespace-cleanup)
(delete-trailing-whitespace)
;;(shr-remove-trailing-whitespace (point-min) (point-max))
(or (buffer-string) "")))))
(when (eq mu4e-html2text-command 'my/shr-mu4e-html2text-command)
;;(define-key mu4e-view-mode-map [down-mouse-1] 'shr-browse-url)
(define-key mu4e-view-mode-map [down-mouse-1]
'mu4e~view-browse-url-from-binding)
(define-key mu4e-view-mode-map [mouse-1] nil)
(define-key mu4e-view-clickable-urls-keymap [mouse-1] nil))
Hope it helps,
C.