diff --git a/mu4e/mu4e-message.el b/mu4e/mu4e-message.el index ab13b90b..7b851f0b 100644 --- a/mu4e/mu4e-message.el +++ b/mu4e/mu4e-message.el @@ -194,17 +194,18 @@ unless PREFER-HTML is non-nil." (setq mu4e~message-body-html (mu4e~message-use-html-p msg prefer-html)) (let ((body (if mu4e~message-body-html - ;; use an HTML body - (cond - ((stringp mu4e-html2text-command) - (mu4e-html2text-shell msg mu4e-html2text-command)) - ((functionp mu4e-html2text-command) - (if (help-function-arglist mu4e-html2text-command) - (funcall mu4e-html2text-command msg) - (mu4e~html2text-wrapper mu4e-html2text-command msg))) - (t (mu4e-error "Invalid `mu4e-html2text-command'"))) - (setq mu4e~message-body-html t) - (buffer-string) + (progn + ;; use an HTML body + (cond + ((stringp mu4e-html2text-command) + (mu4e-html2text-shell msg mu4e-html2text-command)) + ((functionp mu4e-html2text-command) + (if (help-function-arglist mu4e-html2text-command) + (funcall mu4e-html2text-command msg) + ;; oldskool parameterless mu4e-html2text-command + (mu4e~html2text-wrapper mu4e-html2text-command msg))) + (t (mu4e-error "Invalid `mu4e-html2text-command'")) + (setq mu4e~message-body-html t))) ;; use a text body (or (mu4e-message-field msg :body-txt) "")))) ;; and finally, remove some crap from the remaining string; it seems @@ -219,7 +220,7 @@ unless PREFER-HTML is non-nil." (cond ((string= (match-string 0) "’") "'") (t "")))) - (buffer-string)))) + (buffer-string)))) (defun mu4e-message-contact-field-matches (msg cfield rx) "Checks whether any of the of the contacts in field @@ -275,12 +276,22 @@ point in eiter the headers buffer or the view buffer." (plist-get (mu4e-message-at-point) field)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defun mu4e-shr2text () - "Html to text using the shr engine; this can be used in -`mu4e-html2text-command' in a new enough emacs. Based on code by -Titus von der Malsburg." - (interactive) - (let ( +(defun mu4e~html2text-wrapper (func msg) + "Fill a temporary buffer with html from MSG, then call +FUNC. Return the buffer contents." + (with-temp-buffer + (insert (or (mu4e-message-field msg :body-html) "")) + (funcall func) + (message "buffer string...") + (or (buffer-string) ""))) + +(defun mu4e-shr2text (msg) + "Convert html in MSG to text using the shr engine; this can be +used in `mu4e-html2text-command' in a new enough emacs. Based on +code by Titus von der Malsburg." + (mu4e~html2text-wrapper + (lambda () + (let ( ;; When HTML emails contain references to remote images, ;; retrieving these images leaks information. For example, ;; the sender can see when I openend the email and from which @@ -289,8 +300,7 @@ Titus von der Malsburg." ;; See this discussion on mu-discuss: ;; https://groups.google.com/forum/#!topic/mu-discuss/gr1cwNNZnXo (shr-inhibit-images t)) - (shr-render-region (point-min) (point-max)) - (goto-char (point-min)))) + (shr-render-region (point-min) (point-max)))) msg)) (defun mu4e~html2text-shell (msg cmd) "Convert html2 text using a shell function." @@ -302,12 +312,4 @@ Titus von der Malsburg." (call-process-shell-command mu4e-html2text-command tmp-file t t) (delete-file tmp-file))) msg)) -(defun mu4e~html2text-wrapper (func msg) - "Fill a temporary buffer with html from MSG, then call -FUNC. Return the buffer contents." - (with-temp-buffer - (insert (mu4e-message-field msg :body-html)) - (funcall func) - (buffer-string))) - (provide 'mu4e-message) diff --git a/mu4e/mu4e.texi b/mu4e/mu4e.texi index df6f5247..7301fd7c 100644 --- a/mu4e/mu4e.texi +++ b/mu4e/mu4e.texi @@ -1381,9 +1381,26 @@ alternative: @subsection Html2text functions @anchor{Html2text functions} -If @code{mu4e-html2text-command} refers to an elisp function, it is -expected to take the current buffer in html as input, and transform it -into text (just like the @code{html2text} function). +If @code{mu4e-html2text-command} refers to an elisp function, the +function is expected to take a message plist as its input, and returns +the transformed data. + + +You can easily create your own function, for instance: + +@lisp +(defun my-mu4e-html2text (msg) + "My html2text function; shows short message inline, show +longer functions in browser." + (let ((html (or (mu4e-message-field msg :body-html) ""))) + (if (> (length html) 1000) + (progn + (mu4e-action-view-in-browser msg) + "[Viewing message in external browser]") + (mu4e-shr2text msg)))) + +(setq mu4e-html2text-command 'my-mu4e-html2text) +@end lisp @subsection Privacy aspects @anchor{Privacy aspects}