* mu4e: allow mu4e-html2text-command to be a function (thanks to tmalsburg)
This commit is contained in:
@ -34,18 +34,25 @@
|
|||||||
(require 'html2text)
|
(require 'html2text)
|
||||||
|
|
||||||
|
|
||||||
(defcustom mu4e-html2text-command nil
|
(defcustom mu4e-html2text-command 'html2text
|
||||||
"Shell command that converts from html to plain text.
|
"Either a shell command or a function that converts from html to plain text.
|
||||||
The command has to read html from stdin and output plain text on
|
|
||||||
stdout. If this is not defined, the emacs `html2text' tool will be
|
|
||||||
used when faced with html-only messages. If you use htmltext, it's
|
|
||||||
recommended you use \"html2text -utf8 -width 72\".
|
|
||||||
|
|
||||||
Alternatives are the python-based html2markdown, w3m and on MacOS
|
If it is a shell-command, the command has to read html from stdin
|
||||||
you may want to use textutil."
|
and output plain text on stdout. If this is not defined, the emacs
|
||||||
:type 'string
|
`html2text' tool will be used when faced with html-only
|
||||||
:group 'mu4e-view
|
messages. If you use htmltext, it's recommended you use \"html2text
|
||||||
:safe 'stringp)
|
-utf8 -width 72\". Alternatives are the python-based html2markdown,
|
||||||
|
w3m and on MacOS you may want to use textutil.
|
||||||
|
|
||||||
|
It can also be a function, which takes the current buffer in html
|
||||||
|
as input, and transforms it into html (like the `html2text'
|
||||||
|
function).
|
||||||
|
|
||||||
|
In both cases, the output is expected to be in utf-8 encoding.
|
||||||
|
|
||||||
|
The default is emacs' built-in `html2text' function."
|
||||||
|
:type '(choice string function)
|
||||||
|
:group 'mu4e-view)
|
||||||
|
|
||||||
(defcustom mu4e-view-prefer-html nil
|
(defcustom mu4e-view-prefer-html nil
|
||||||
"Whether to base the body display on the html-version.
|
"Whether to base the body display on the html-version.
|
||||||
@ -148,12 +155,10 @@ This is equivalent to:
|
|||||||
|
|
||||||
(defun mu4e-message-body-text (msg)
|
(defun mu4e-message-body-text (msg)
|
||||||
"Get the body in text form for this message.
|
"Get the body in text form for this message.
|
||||||
This is either :body-txt, or if not available, :body-html
|
This is either :body-txt, or if not available, :body-html converted
|
||||||
converted to text. By default, it uses the emacs built-in
|
to text, using `mu4e-html2text-command' is non-nil, it will use
|
||||||
`html2text'. Alternatively, if `mu4e-html2text-command' is
|
that. Normally, thiss function prefers the text part, but this can
|
||||||
non-nil, it will use that. Normally, function prefers the text
|
be changed by setting `mu4e-view-prefer-html'."
|
||||||
part, but this can be changed by setting
|
|
||||||
`mu4e-view-prefer-html'."
|
|
||||||
(let* ((txt (mu4e-message-field msg :body-txt))
|
(let* ((txt (mu4e-message-field msg :body-txt))
|
||||||
(html (mu4e-message-field msg :body-html))
|
(html (mu4e-message-field msg :body-html))
|
||||||
(body
|
(body
|
||||||
@ -172,12 +177,13 @@ part, but this can be changed by setting
|
|||||||
(html
|
(html
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(insert html)
|
(insert html)
|
||||||
;; if defined, use the external tool
|
(cond
|
||||||
(if mu4e-html2text-command
|
((stringp 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...
|
((functionp mu4e-html2text-command)
|
||||||
(html2text))
|
(funcall mu4e-html2text-command))
|
||||||
|
(t (mu4e-error "Invalid `mu4e-html2text-command'")))
|
||||||
(buffer-string)))
|
(buffer-string)))
|
||||||
(t ;; otherwise, an empty body
|
(t ;; otherwise, an empty body
|
||||||
""))))
|
""))))
|
||||||
|
|||||||
Reference in New Issue
Block a user