mirror of https://github.com/djcb/mu.git
* mu4e: support external html2text
This commit is contained in:
parent
947328e5c0
commit
5307a8411b
|
@ -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..."
|
||||||
(with-temp-buffer
|
(let ((txt (plist-get msg :body-txt))
|
||||||
(plist-get msg :body-html)
|
(html (plist-get msg :body-html)))
|
||||||
(html2text)
|
;; show the html body if there is no text, or if the text body is super
|
||||||
(buffer-string))
|
;; short compared to the html one -- ie., it's probably just some lame 'this
|
||||||
"No body found"))
|
;; 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)
|
(defun mu4e-view-header (key val &optional dont-propertize-val)
|
||||||
|
@ -209,7 +226,7 @@ or if not available, :body-html converted to text)."
|
||||||
(define-key map "j" 'mu4e-jump-to-maildir)
|
(define-key map "j" 'mu4e-jump-to-maildir)
|
||||||
|
|
||||||
(define-key map "g" 'mu4e-view-go-to-url)
|
(define-key map "g" 'mu4e-view-go-to-url)
|
||||||
|
|
||||||
(define-key map "F" 'mu4e-compose-forward)
|
(define-key map "F" 'mu4e-compose-forward)
|
||||||
(define-key map "R" 'mu4e-compose-reply)
|
(define-key map "R" 'mu4e-compose-reply)
|
||||||
(define-key map "C" 'mu4e-compose-new)
|
(define-key map "C" 'mu4e-compose-new)
|
||||||
|
@ -261,7 +278,7 @@ or if not available, :body-html converted to text)."
|
||||||
(define-key map "x" 'mu4e-view-marked-execute)
|
(define-key map "x" 'mu4e-view-marked-execute)
|
||||||
|
|
||||||
(define-key map "H" 'mu4e-display-manual)
|
(define-key map "H" 'mu4e-display-manual)
|
||||||
|
|
||||||
;; menu
|
;; menu
|
||||||
(define-key map [menu-bar] (make-sparse-keymap))
|
(define-key map [menu-bar] (make-sparse-keymap))
|
||||||
(let ((menumap (make-sparse-keymap "View")))
|
(let ((menumap (make-sparse-keymap "View")))
|
||||||
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue