]> git.notmuchmail.org Git - notmuch/blobdiff - emacs/notmuch-show.el
emacs: Show cleaner `From:' addresses in the summary line.
[notmuch] / emacs / notmuch-show.el
index 2ce3ebf82a1dceb8f9827c5d3525a4445c9219d1..ed7037a15983437819d40055653e597fa9ffd7a4 100644 (file)
@@ -64,6 +64,12 @@ any given message."
   :group 'notmuch
   :type 'boolean)
 
+(defcustom notmuch-show-elide-same-subject nil
+  "Do not show the subject of a collapsed message if it is the
+same as that of the previous message."
+  :group 'notmuch
+  :type 'boolean)
+
 (defcustom notmuch-show-always-show-subject t
   "Should a collapsed message show the `Subject:' line?"
   :group 'notmuch
@@ -216,12 +222,30 @@ any given message."
                                             'face 'notmuch-tag-face)
                                 ")"))))))
 
+(defun notmuch-show-clean-address (address)
+  "Clean a single email address for display."
+  (let* ((parsed (mail-header-parse-address address))
+        (address (car parsed))
+        (name (cdr parsed)))
+    ;; Remove double quotes. They might be required during transport,
+    ;; but we don't need to see them.
+    (when name
+      (setq name (replace-regexp-in-string "\"" "" name)))
+    ;; If the address is 'foo@bar.com <foo@bar.com>' then show just
+    ;; 'foo@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 (plist-get headers :From))
            " ("
            date
            ") ("
@@ -626,9 +650,9 @@ current buffer, if possible."
       ;; If the subject of this message is the same as that of the
       ;; previous message, don't display it when this message is
       ;; collapsed.
-      (when (or notmuch-show-always-show-subject
-                (not (string= notmuch-show-previous-subject
-                              bare-subject)))
+      (when (and notmuch-show-elide-same-subject
+                (not (string= notmuch-show-previous-subject
+                              bare-subject)))
        (forward-line 1))
       (setq headers-start (point-marker)))
     (setq headers-end (point-marker))