* mu4e: unify html2text
This commit is contained in:
@ -513,6 +513,39 @@ Also see `mu/flags-to-string'.
|
||||
((< size 1000) (format "%d" size))
|
||||
(t "<unknown>")))
|
||||
|
||||
|
||||
(defun mu4e-body-text (msg)
|
||||
"Get the body in text form for this message, which is either :body-txt,
|
||||
or if not available, :body-html converted to text. By default, it
|
||||
uses the emacs built-in `html2text'. Alternatively, if
|
||||
`mu4e-html2text-command' is non-nil, it will use that."
|
||||
(let ((txt (plist-get msg :body-txt))
|
||||
(html (plist-get msg :body-html)))
|
||||
;; show the html body if there is no text, or if the text body is super
|
||||
;; short compared to the html one -- ie., it's probably just some lame 'this
|
||||
;; message requires html' message
|
||||
(if (not html)
|
||||
(if (not txt) "" txt)
|
||||
;; there's an html part
|
||||
(if (or (not txt) (< (* 10 (length txt)) (length html)))
|
||||
;; there's no text part, or it's very small
|
||||
(with-temp-buffer
|
||||
(insert html) ;; FIXME somehow, the replace-regexp does not work
|
||||
(replace-regexp "[\r ]" " " nil (point-min) (point-max))
|
||||
(if mu4e-html2text-command ;; if defined, use the external tool
|
||||
(shell-command-on-region (point-min) (point-max) mu4e-html2text-command
|
||||
nil t)
|
||||
;; otherwise...
|
||||
(html2text))
|
||||
(buffer-string))
|
||||
;; there's a normal sized text part
|
||||
txt))))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(provide 'mu4e)
|
||||
|
||||
Reference in New Issue
Block a user