* mu4e: some improvements in get body parts
This commit is contained in:
@ -329,30 +329,29 @@ uses the emacs built-in `html2text'. Alternatively, if
|
|||||||
function prefers the text part, but this can be changed by setting
|
function prefers the text part, but this can be changed by setting
|
||||||
`mu4e-view-prefer-html'."
|
`mu4e-view-prefer-html'."
|
||||||
(let* ((txt (plist-get msg :body-txt))
|
(let* ((txt (plist-get msg :body-txt))
|
||||||
(html (plist-get msg :body-html))
|
(html (plist-get msg :body-html))
|
||||||
(body))
|
(body
|
||||||
;; is there an appropriate text body?
|
(cond
|
||||||
(when (and txt
|
;; does it look like some text? ie., 20x the length of the text
|
||||||
(not (and mu4e-view-prefer-html html))
|
;; should be longer than the html, an heuristic to guard against
|
||||||
(> (* 10 (length txt))
|
;; 'This messages requires html' text bodies.
|
||||||
(if html (length html) 0))) ;; real text part?
|
((and (> (* 20 (length txt)) (length html))
|
||||||
(setq body txt))
|
;; use html if it's prefered, unless there is no html
|
||||||
;; no body yet? try html
|
(or (not mu4e-view-prefer-html) (not html)))
|
||||||
(unless body
|
txt)
|
||||||
(when html
|
;; otherwise, it there some html?
|
||||||
(setq body
|
(html
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(insert html)
|
(insert html)
|
||||||
;; if defined, use the external tool
|
;; if defined, use the external tool
|
||||||
(if mu4e-html2text-command
|
(if mu4e-html2text-command
|
||||||
(shell-command-on-region (point-min) (point-max)
|
(shell-command-on-region (point-min) (point-max)
|
||||||
mu4e-html2text-command nil t)
|
mu4e-html2text-command nil t)
|
||||||
;; otherwise...
|
;; otherwise...
|
||||||
(html2text))
|
(html2text))
|
||||||
(buffer-string)))))
|
(buffer-string)))
|
||||||
;; still no body?
|
(t ;; otherwise, an empty body
|
||||||
(unless body
|
""))))
|
||||||
(setq body ""))
|
|
||||||
;; and finally, remove some crap from the remaining string.
|
;; and finally, remove some crap from the remaining string.
|
||||||
(replace-regexp-in-string "[
|
(replace-regexp-in-string "[
|
||||||
]" " " body nil nil nil)))
|
]" " " body nil nil nil)))
|
||||||
|
|||||||
Reference in New Issue
Block a user