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

David Edmondson dme at dme.org
Fri Nov 5 08:04:16 PDT 2010


Remove double quotes and flatten "foo at bar.com <foo at bar.com>" to
"foo at bar.com".
---
 emacs/notmuch-show.el |   30 ++++++++++++++++++++++++++++--
 1 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 07cf846..2838968 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)
@@ -204,12 +205,26 @@ same as that of the previous message."
 					     'face 'notmuch-tag-face)
 				 ")"))))))
 
+(defun notmuch-show-clean-address (parsed-address)
+  "Clean 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 (not name)
+	address
+      (concat 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
 	    ") ("
@@ -220,7 +235,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