[PATCH] emacs: Show cleaner addresses during message display.

David Edmondson dme at dme.org
Wed Nov 10 01:23:07 PST 2010


Simplify the display of addresses by setting
`notmuch-show-address-simplication' to:

- 'full: Only the name component of the address, if present, is
  shown (the default),
- 'partial: Addresses are stripped of redundant information,
- 'none: Addresses are shown as-is.
---
 emacs/notmuch-show.el |   55 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 9e5d72d..054aba1 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -26,6 +26,7 @@
 (require 'message)
 (require 'mm-decode)
 (require 'mailcap)
+(require 'mail-parse)
 
 (require 'notmuch-lib)
 (require 'notmuch-query)
@@ -82,6 +83,21 @@ any given message."
 	     notmuch-wash-elide-blank-lines
 	     notmuch-wash-excerpt-citations))
 
+(defcustom notmuch-show-address-simplification 'full
+  "How should addresses be displayed?
+
+Set `notmuch-show-address-simplication' to:
+
+- 'full: Only the name component of the address, if present, is
+  shown,
+- 'partial: Addresses are stripped of redundant information,
+- 'none: Addresses are shown as-is."
+  :group 'notmuch
+  :type '(choice
+	  (const :tag "Full simplification" full)
+	  (const :tag "Partial simplification" partial)
+	  (const :tag "No simplification" none)))
+
 (defmacro with-current-notmuch-show-message (&rest body)
   "Evaluate body with current buffer set to the text of current message"
   `(save-excursion
@@ -198,12 +214,36 @@ any given message."
 					     'face 'notmuch-tag-face)
 				 ")"))))))
 
+(defun notmuch-show-clean-address (parsed-address)
+  "Prepare a single email address for display."
+  (let* ((address (car parsed-address))
+	 (name (cdr parsed-address))
+	 (displayed-name name))
+
+    ;; If the address is 'foo at bar.com <foo at bar.com>' then show just
+    ;; 'foo at bar.com'.
+    (when (string= displayed-name address)
+      (setq displayed-name nil))
+
+    (cond
+     ((eq notmuch-show-address-simplification 'full)
+      (if displayed-name
+	  (propertize displayed-name 'help-echo address)
+	address))
+
+     ((eq notmuch-show-address-simplification 'partial)
+      (mail-header-make-address displayed-name address))
+
+     (t ;; All other settings, but mostly 'none.
+      (mail-header-make-address name address)))))
+
 (defun notmuch-show-insert-headerline (headers date tags depth)
   "Insert a notmuch style headerline based on HEADERS for a
 message at DEPTH in the current thread."
   (let ((start (point)))
     (insert (notmuch-show-spaces-n depth)
-	    (plist-get headers :From)
+	    (notmuch-show-clean-address
+	     (mail-header-parse-address (plist-get headers :From)))
 	    " ("
 	    date
 	    ") ("
@@ -214,7 +254,18 @@ message at DEPTH in the current thread."
 
 (defun notmuch-show-insert-header (header header-value)
   "Insert a single header."
-  (insert header ": " header-value "\n"))
+  (insert header ": "
+	  (cond
+	   ((or (string= "To" header)
+		(string= "Cc" header)
+		(string= "Bcc" header)
+		(string= "From" header))
+	    (mapconcat 'notmuch-show-clean-address
+		       (mail-header-parse-addresses header-value)
+		       ", "))
+	   (t
+	    header-value))
+	  "\n"))
 
 (defun notmuch-show-insert-headers (headers)
   "Insert the headers of the current message."
-- 
1.7.2.3



More information about the notmuch mailing list