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

David Edmondson dme at dme.org
Tue Nov 9 09:34:50 PST 2010


Remove double quotes and flatten "foo at bar.com <foo at bar.com>" to
"foo at bar.com". If the address is of the form "name <foo at bar.com>",
show only 'name' with a tooltip of the address.
---
More aggressive simplification and tooltips.

 emacs/notmuch-show.el |   29 +++++++++++++++++++++++++++--
 1 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 9e5d72d..098146b 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)
@@ -198,12 +199,25 @@ 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)))
+    ;; If the address is 'foo at bar.com <foo at bar.com>' then show just
+    ;; 'foo at bar.com'.
+    (when (string= name address)
+      (setq name nil))
+    (if name
+	(propertize name 'help-echo address)
+	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 +228,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