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 143A740DBE7 for ; Wed, 10 Nov 2010 01:24:50 -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 LwaHdwAAYRD7 for ; Wed, 10 Nov 2010 01:24:39 -0800 (PST) Received: from mail-wy0-f181.google.com (mail-wy0-f181.google.com [74.125.82.181]) by olra.theworths.org (Postfix) with ESMTP id 3810440DBC3 for ; Wed, 10 Nov 2010 01:24:39 -0800 (PST) Received: by wyb40 with SMTP id 40so489533wyb.26 for ; Wed, 10 Nov 2010 01:24:38 -0800 (PST) Received: by 10.227.154.7 with SMTP id m7mr7986568wbw.211.1289381077741; Wed, 10 Nov 2010 01:24:37 -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 f14sm404219wbe.14.2010.11.10.01.24.30 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 10 Nov 2010 01:24:32 -0800 (PST) Received: by ut.hh.sledj.net (Postfix, from userid 1000) id 8F7C259405B; Wed, 10 Nov 2010 09:23:08 +0000 (GMT) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH] emacs: Show cleaner addresses during message display. Date: Wed, 10 Nov 2010 09:23:07 +0000 Message-Id: <1289380987-1206-1-git-send-email-dme@dme.org> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <87d3qd1t43.fsf@ut.hh.sledj.net> References: <87d3qd1t43.fsf@ut.hh.sledj.net> 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: Wed, 10 Nov 2010 09:24:50 -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 (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@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) + (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