Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 7866140DBF6 for ; Fri, 12 Nov 2010 00:00:30 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.9 X-Spam-Level: X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=ham Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id e7SjRNBoEMlC for ; Fri, 12 Nov 2010 00:00:18 -0800 (PST) Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com [74.125.82.45]) by olra.theworths.org (Postfix) with ESMTP id 1B2E240DBC8 for ; Fri, 12 Nov 2010 00:00:17 -0800 (PST) Received: by wwb39 with SMTP id 39so1166998wwb.2 for ; Fri, 12 Nov 2010 00:00:14 -0800 (PST) Received: by 10.216.164.134 with SMTP id c6mr3211161wel.48.1289548811597; Fri, 12 Nov 2010 00:00:11 -0800 (PST) Received: from ut.hh.sledj.net (host81-149-164-25.in-addr.btopenworld.com [81.149.164.25]) by mx.google.com with ESMTPS id l14sm1918860weq.11.2010.11.12.00.00.08 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 12 Nov 2010 00:00:08 -0800 (PST) Received: by ut.hh.sledj.net (Postfix, from userid 1000) id 0BDED59405B; Fri, 12 Nov 2010 07:58:25 +0000 (GMT) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH] emacs: Show cleaner addresses during message display. Date: Fri, 12 Nov 2010 07:58:24 +0000 Message-Id: <1289548704-8071-1-git-send-email-dme@dme.org> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <87mxpfmjh8.fsf@yoom.home.cworth.org> References: <87mxpfmjh8.fsf@yoom.home.cworth.org> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Nov 2010 08:00:30 -0000 Simplify the display of addresses by setting `notmuch-show-address-simplication' to: - 'full: Only the name component of the address, if present, is shown, - 'partial: Addresses are stripped of redundant information (the default), - 'none: Addresses are shown as-is. `mail-header-parse-address' fails for some addresses, in particular "undisclosed-recipients:;". Accommodate this by returning the original address if the parser fails. Adjust the test results accordingly. --- Default is now 'partial (most similar to the old behaviour). Allow for un-parseable addresses. Don't add unnecessary quotes. Oh, and, fix the test suite. Carl: You can ignore the notmuch-lkml.el chunk, as you don't have that yet. emacs/notmuch-lkml.el | 4 +- emacs/notmuch-show.el | 65 +++++++++++++++++++- .../notmuch-show-thread-maildir-storage | 6 +- 3 files changed, 68 insertions(+), 7 deletions(-) diff --git a/emacs/notmuch-lkml.el b/emacs/notmuch-lkml.el index 750370b..fc04be6 100644 --- a/emacs/notmuch-lkml.el +++ b/emacs/notmuch-lkml.el @@ -29,7 +29,7 @@ (declare-function notmuch-call-notmuch-process "notmuch" (&rest args)) (declare-function notmuch-show "notmuch-show" (&rest args)) (declare-function notmuch-show-strip-re "notmuch-show" (subject)) -(declare-function notmuch-show-clean-address "notmuch-show" (parsed-address)) +(declare-function notmuch-show-clean-address "notmuch-show" (address)) (declare-function notmuch-show-spaces-n "notmuch-show" (n)) (defcustom notmuch-lkml-author-width 30 @@ -71,7 +71,7 @@ (notmuch-lkml-string-width (concat (notmuch-show-spaces-n depth) (notmuch-show-clean-address - (mail-header-parse-address (plist-get headers :From)))) + (plist-get headers :From))) notmuch-lkml-author-width) " " (if (string= notmuch-lkml-previous-subject diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index d8773e6..aa89cfd 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 'partial + "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,46 @@ any given message." 'face 'notmuch-tag-face) ")")))))) +(defun notmuch-show-clean-address (original-address) + "Prepare a single email address for display." + (let* ((parsed-address (mail-header-parse-address original-address)) + (address (car parsed-address)) + (name (cdr parsed-address)) + (displayed-name name)) + + ;; If the parser failed, use the original string. + (if (not parsed-address) + original-address + + ;; If the address is 'foo@bar.com ' then show just + ;; 'foo@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) + (if displayed-name + ;; `mail-header-make-address' is enthusiastic about + ;; quoting the displayed name if it contains spaces (which + ;; is visually unappealing) so generate the displayed + ;; string directly here. + (concat displayed-name " <" address ">") + address)) + + (t ;; All other settings, but mostly 'none. + original-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 ") (" @@ -214,7 +264,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) + ", ")) + (t + header-value)) + "\n")) (defun notmuch-show-insert-headers (headers) "Insert the headers of the current message." diff --git a/test/emacs.expected-output/notmuch-show-thread-maildir-storage b/test/emacs.expected-output/notmuch-show-thread-maildir-storage index 086f874..2f18924 100644 --- a/test/emacs.expected-output/notmuch-show-thread-maildir-storage +++ b/test/emacs.expected-output/notmuch-show-thread-maildir-storage @@ -92,7 +92,7 @@ http://notmuchmail.org/mailman/listinfo/notmuch notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch - "Mikhail Gusarov" (2009-11-17) (inbox unread) + Mikhail Gusarov (2009-11-17) (inbox unread) Subject: [notmuch] Working with Maildir storage? To: notmuch@notmuchmail.org Date: Wed, 18 Nov 2009 02:50:48 +0600 @@ -120,7 +120,7 @@ http://notmuchmail.org/mailman/listinfo/notmuch Desc: not available URL: - "Keith Packard" (2009-11-17) (inbox unread) + Keith Packard (2009-11-17) (inbox unread) Subject: [notmuch] Working with Maildir storage? To: notmuch@notmuchmail.org Date: Tue, 17 Nov 2009 13:24:13 -0800 @@ -167,7 +167,7 @@ http://notmuchmail.org/mailman/listinfo/notmuch notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch - "Carl Worth" (2009-11-18) (inbox unread) + Carl Worth (2009-11-18) (inbox unread) Subject: [notmuch] Working with Maildir storage? To: notmuch@notmuchmail.org Date: Wed, 18 Nov 2009 02:08:10 -0800 -- 1.7.2.3