From c489482e86a7a485ee18dfa04806c39d51567ef5 Mon Sep 17 00:00:00 2001 From: djcb Date: Mon, 30 Apr 2012 17:48:37 +0300 Subject: [PATCH] * mu4e: some improvements in get body parts --- emacs/mu4e-utils.el | 47 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/emacs/mu4e-utils.el b/emacs/mu4e-utils.el index 42f84ec6..eaf89984 100644 --- a/emacs/mu4e-utils.el +++ b/emacs/mu4e-utils.el @@ -329,30 +329,29 @@ uses the emacs built-in `html2text'. Alternatively, if function prefers the text part, but this can be changed by setting `mu4e-view-prefer-html'." (let* ((txt (plist-get msg :body-txt)) - (html (plist-get msg :body-html)) - (body)) - ;; is there an appropriate text body? - (when (and txt - (not (and mu4e-view-prefer-html html)) - (> (* 10 (length txt)) - (if html (length html) 0))) ;; real text part? - (setq body txt)) - ;; no body yet? try html - (unless body - (when html - (setq body - (with-temp-buffer - (insert html) - ;; if defined, use the external tool - (if mu4e-html2text-command - (shell-command-on-region (point-min) (point-max) - mu4e-html2text-command nil t) - ;; otherwise... - (html2text)) - (buffer-string))))) - ;; still no body? - (unless body - (setq body "")) + (html (plist-get msg :body-html)) + (body + (cond + ;; does it look like some text? ie., 20x the length of the text + ;; should be longer than the html, an heuristic to guard against + ;; 'This messages requires html' text bodies. + ((and (> (* 20 (length txt)) (length html)) + ;; use html if it's prefered, unless there is no html + (or (not mu4e-view-prefer-html) (not html))) + txt) + ;; otherwise, it there some html? + (html + (with-temp-buffer + (insert html) + ;; if defined, use the external tool + (if mu4e-html2text-command + (shell-command-on-region (point-min) (point-max) + mu4e-html2text-command nil t) + ;; otherwise... + (html2text)) + (buffer-string))) + (t ;; otherwise, an empty body + "")))) ;; and finally, remove some crap from the remaining string. (replace-regexp-in-string "[  ]" " " body nil nil nil)))