* mu4e: support external html2text
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
;; mu4e-view.el -- part of mm, the mu mail user agent
|
;; mu4e-view.el -- part of mu4e, the mu mail user agent
|
||||||
;;
|
;;
|
||||||
;; Copyright (C) 2011 Dirk-Jan C. Binnema
|
;; Copyright (C) 2011 Dirk-Jan C. Binnema
|
||||||
|
|
||||||
@ -124,13 +124,30 @@ marking if it still had that."
|
|||||||
|
|
||||||
(defun mu4e-view-body (msg)
|
(defun mu4e-view-body (msg)
|
||||||
"Get the body for this message, which is either :body-txt,
|
"Get the body for this message, which is either :body-txt,
|
||||||
or if not available, :body-html converted to text)."
|
or if not available, :body-html converted to text. Sadly, html2text
|
||||||
(or (plist-get msg :body-txt)
|
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
|
(with-temp-buffer
|
||||||
(plist-get msg :body-html)
|
(insert html)
|
||||||
(html2text)
|
(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))
|
(buffer-string))
|
||||||
"No body found"))
|
;; there's a normal sized text part
|
||||||
|
txt))))
|
||||||
|
|
||||||
|
|
||||||
(defun mu4e-view-header (key val &optional dont-propertize-val)
|
(defun mu4e-view-header (key val &optional dont-propertize-val)
|
||||||
@ -375,8 +392,8 @@ removing '^M' etc."
|
|||||||
(when p
|
(when p
|
||||||
(add-text-properties p (point-max) '(face mu4e-view-footer-face))))
|
(add-text-properties p (point-max) '(face mu4e-view-footer-face))))
|
||||||
;; this is fairly simplistic...
|
;; this is fairly simplistic...
|
||||||
(goto-char (point-min))
|
(goto-char (point-min)) ;; FIXME: breaks with URLs ending in (e.g.) '='
|
||||||
(while (re-search-forward "\\(https?://[-a-zA-Z0-9?_.$%/=+&#@!~,:;]*\\)\\>"
|
(while (re-search-forward "\\(https?://[+-a-zA-Z0-9.?_$%/+&#@!~,:;=]*\\)\\>"
|
||||||
nil t)
|
nil t)
|
||||||
(let ((subst (propertize (match-string-no-properties 0)
|
(let ((subst (propertize (match-string-no-properties 0)
|
||||||
'face 'mu4e-view-link-face)))
|
'face 'mu4e-view-link-face)))
|
||||||
|
|||||||
@ -194,7 +194,16 @@ complete list of available headers, see `mu4e-header-names'."
|
|||||||
"Date format to use in the message view, in the format of
|
"Date format to use in the message view, in the format of
|
||||||
`format-time-string'."
|
`format-time-string'."
|
||||||
:type 'string
|
:type 'string
|
||||||
:group 'mu4e-headers)
|
:group 'mu4e-view)
|
||||||
|
|
||||||
|
(defcustom mu4e-html2text-command nil
|
||||||
|
"Shel command that converts HTML from stdin into plain text on
|
||||||
|
stdout. If this is not defined, the emacs `html2text' tool will be
|
||||||
|
used when faced with html-only message."
|
||||||
|
:type 'string
|
||||||
|
:group 'mu4e-view
|
||||||
|
:safe 'stringp)
|
||||||
|
|
||||||
|
|
||||||
;; Composing / Sending messages
|
;; Composing / Sending messages
|
||||||
(defgroup mu4e-compose nil
|
(defgroup mu4e-compose nil
|
||||||
|
|||||||
Reference in New Issue
Block a user