From 5c11e0e843a4c8425c5d6ed7a5d43c8db155ce25 Mon Sep 17 00:00:00 2001 From: djcb Date: Tue, 14 Feb 2012 21:22:02 +0200 Subject: [PATCH] * mu4e: add `mu4e-view-prefer-html' (with obvious meaning), and document it. --- emacs/mu4e.el | 66 ++++++++++++++++++++++++++++++------------------- emacs/mu4e.texi | 27 +++++++++++++------- 2 files changed, 58 insertions(+), 35 deletions(-) diff --git a/emacs/mu4e.el b/emacs/mu4e.el index a691bcdc..044b89bb 100644 --- a/emacs/mu4e.el +++ b/emacs/mu4e.el @@ -188,15 +188,21 @@ complete list of available headers, see `mu4e-header-names'." :type 'string :group 'mu4e-view) +(defcustom mu4e-view-prefer-html nil + "Whether to base the body display on the HTML-version of the +e-mail message (if there is any." + :type 'boolean + :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." +used when faced with html-only message. If you use htmltext, it's +recommended you use \"html2text -utf8 -width 72\"." :type 'string :group 'mu4e-view :safe 'stringp) - ;; Composing / Sending messages (defgroup mu4e-compose nil "Customizations for composing/sending messages." @@ -438,7 +444,8 @@ maildirs under `mu4e-maildir." (lambda (item) (concat "[" - (propertize (make-string 1 (cdr item)) 'face 'mu4e-view-link-face) + (propertize (make-string 1 (cdr item)) + 'face 'mu4e-view-link-face) "]" (car item))) mlist ", ")) @@ -463,7 +470,9 @@ maildirs under `mu4e-maildir." (lambda (bm) (let ((query (nth 0 bm)) (title (nth 1 bm)) (key (nth 2 bm))) (concat - "[" (propertize (make-string 1 key) 'face 'mu4e-view-link-face) "]" + "[" (propertize (make-string 1 key) + 'face 'mu4e-view-link-face) + "]" title))) mu4e-bookmarks ", ")) (kar (read-char (concat prompt bmarks)))) (mu4e-get-bookmark-query kar))) @@ -559,36 +568,41 @@ Also see `mu/flags-to-string'. ((and (>= size 1000) (< size 1000000)) (format "%2.1fK" (/ size 1000.0))) ((< size 1000) (format "%d" size)) - (t ""))) + (t (propertize "?" 'face 'mu4e-system-face)))) (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." +`mu4e-html2text-command' is non-nil, it will use that. Normally, +function prefers the text part, but this can be changed by setting +`mu4e-view-prefer-html'." (let* ((txt (plist-get msg :body-txt)) (html (plist-get msg :body-html)) - ;; get 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 - (body (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) - ;; if defined, use the external tool - (if mu4e-html2text-command - (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)))) + (body)) + ;; is there an appropriate text body? + (when (and txt + (not (and mu4e-view-prefer-html html)) + (> (* 10 (length txt)) + (if html (length html) 0))) ;; real text part? + (setq body txt)) + ;; no body yet? try html + (unless body + (when html + (setq body + (with-temp-buffer + (insert html) + ;; if defined, use the external tool + (if mu4e-html2text-command + (shell-command-on-region (point-min) (point-max) + mu4e-html2text-command nil t) + ;; otherwise... + (html2text)) + (buffer-string))))) + ;; still no body? + (unless body + (setq body (propertize "No body" 'face 'mu4e-system-face))) ;; and finally, remove some crap from the remaining string. (replace-regexp-in-string "[  ]" " " body nil nil nil))) diff --git a/emacs/mu4e.texi b/emacs/mu4e.texi index 8b4f272d..52932a9f 100644 --- a/emacs/mu4e.texi +++ b/emacs/mu4e.texi @@ -426,7 +426,7 @@ This looks something like the following: @verbatim ------------------------------------------------------------------------------------------- +---------------------------------------------------------------------------------- Date Flgs From/To Subject 2011-12-16 18:38 uN To Edmund Dantès + Re: Extension security? 2011-12-16 21:44 uN Abbé Busoni + Re: Extension security? @@ -434,11 +434,11 @@ This looks something like the following: 2011-12-17 04:04 uN Jacopo + Re: Extension security? 2011-12-17 14:36 uN Mercédès + Re: Extension security? 2011-12-18 06:05 uN Beachamp \ Re: Extension security? - 2011-12-16 18:23 uN Eric Schulte + Re: [O] A presentation tool for org-mode - 2011-12-17 01:53 usaN Gaspard Caderousse \ Re: [O] A presentation tool for org-mode + 2011-12-16 18:23 uN Albert de Moncerf + Re: [O] A presentation tool + 2011-12-17 01:53 usaN Gaspard Caderousse \ Re: [O] A presentation tool 2011-12-16 16:31 uN Baron Danglars | [O] imaxima? End of search results ------------------------------------------------------------------------------------------- +---------------------------------------------------------------------------------- @end verbatim It should be fairly obvious what this means, but some notes: @@ -565,16 +565,25 @@ q@t{open} program. If you want to use another program, you specify this by setting the @t{MU_PLAY_PROGRAM} environment variable. For displaying messages, @t{mu4e} normally prefers the plain-text version for -messages consisting of both a plain-text and an html (rich-text_ version of +messages consisting of both a plain-text and an html (rich-text) version of its body-text. If there is only an html-version, or if the plaint-text version is too short in comparison with the html part, @t{mu4e} tries to convert the html into plain-text for display. The default way to do that is to use the Emacs built-in @code{html2text} function, but if you set the variable -@code{mu4e-html2text-command} to some external program, that will be +@code{mu4e-html2text-command} to some external program, that program will be used. This program is expected to take html from standard input and write -plain text on standard output. An obvious choice for this is the program that -is actually called -@t{html2text}@footnote{@url{http://www.mbayer.de/html2text/}}. +plain text in @t{utf-8} encoding on standard output. + +An obvious choice for this is the program that is actually @emph{called} +@t{html2text}@footnote{@url{http://www.mbayer.de/html2text/}}, which you could +set up with something like the following in your initialization files: + +@lisp +(setq mu4e-html2text-command "html2text -utf8 -width 72") +@end lisp + +Normally, @t{mu4e} prefers the text-version of an e-mail message to determine +the message body. You can change this by setting @code{mu4e-view-prefer-html}. @node Editor view @section Editor view