mirror of https://github.com/djcb/mu.git
* mu4e: unify html2text
This commit is contained in:
parent
4c52299449
commit
043945bc4b
|
@ -73,13 +73,7 @@ or if not available, :body-html converted to text)."
|
|||
prepending `mu4e-msg-citation-prefix' to each line. If there is
|
||||
no body in MSG, return nil."
|
||||
(let* ((from (plist-get msg :from))
|
||||
;; first try plain-text, then html
|
||||
(body (or (plist-get msg :body-txt)
|
||||
(with-temp-buffer
|
||||
(plist-get msg :body-html)
|
||||
(html2text)
|
||||
(buffer-string))))
|
||||
(body (and body (replace-regexp-in-string "[\r\240]" " " body))))
|
||||
(body (mu4e-body-text msg)))
|
||||
(when body
|
||||
(concat
|
||||
(format "On %s, %s wrote:"
|
||||
|
|
|
@ -102,7 +102,7 @@ marking if it still had that."
|
|||
(t (error "Unsupported field: %S" field)))))
|
||||
mu4e-view-fields "")
|
||||
"\n"
|
||||
(mu4e-view-body msg))
|
||||
(mu4e-body-text msg))
|
||||
|
||||
;; initialize view-mode
|
||||
(mu4e-view-mode)
|
||||
|
@ -121,35 +121,6 @@ marking if it still had that."
|
|||
(unless update
|
||||
(mu4e-view-mark-as-read-maybe)))))
|
||||
|
||||
|
||||
(defun mu4e-view-body (msg)
|
||||
"Get the body for this message, which is either :body-txt,
|
||||
or if not available, :body-html converted to text. Sadly, html2text
|
||||
does not really work all the time..."
|
||||
(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)
|
||||
(propertize "No body found for this message" 'face 'mu4e-system-face)
|
||||
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)
|
||||
(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))))
|
||||
|
||||
|
||||
(defun mu4e-view-header (key val &optional dont-propertize-val)
|
||||
"Show header FIELD for MSG with KEY. ie. <KEY>: value-of-FIELD."
|
||||
(if val
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue