Re: [PATCH] Fix typo in Message.maildir_flags_to_tags
[notmuch-archives.git] / b5 / a8fe0a47405ce290aaad6f8b6aa377e3086c9c
1 Return-Path: <dme@dme.org>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 143A740DBE7\r
6         for <notmuch@notmuchmail.org>; Wed, 10 Nov 2010 01:24:50 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -1.9\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
12         tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=ham\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id LwaHdwAAYRD7 for <notmuch@notmuchmail.org>;\r
16         Wed, 10 Nov 2010 01:24:39 -0800 (PST)\r
17 Received: from mail-wy0-f181.google.com (mail-wy0-f181.google.com\r
18         [74.125.82.181])\r
19         by olra.theworths.org (Postfix) with ESMTP id 3810440DBC3\r
20         for <notmuch@notmuchmail.org>; Wed, 10 Nov 2010 01:24:39 -0800 (PST)\r
21 Received: by wyb40 with SMTP id 40so489533wyb.26\r
22         for <notmuch@notmuchmail.org>; Wed, 10 Nov 2010 01:24:38 -0800 (PST)\r
23 Received: by 10.227.154.7 with SMTP id m7mr7986568wbw.211.1289381077741;\r
24         Wed, 10 Nov 2010 01:24:37 -0800 (PST)\r
25 Received: from ut.hh.sledj.net (host81-149-164-25.in-addr.btopenworld.com\r
26         [81.149.164.25])\r
27         by mx.google.com with ESMTPS id f14sm404219wbe.14.2010.11.10.01.24.30\r
28         (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
29         Wed, 10 Nov 2010 01:24:32 -0800 (PST)\r
30 Received: by ut.hh.sledj.net (Postfix, from userid 1000)\r
31         id 8F7C259405B; Wed, 10 Nov 2010 09:23:08 +0000 (GMT)\r
32 From: David Edmondson <dme@dme.org>\r
33 To: notmuch@notmuchmail.org\r
34 Subject: [PATCH] emacs: Show cleaner addresses during message display.\r
35 Date: Wed, 10 Nov 2010 09:23:07 +0000\r
36 Message-Id: <1289380987-1206-1-git-send-email-dme@dme.org>\r
37 X-Mailer: git-send-email 1.7.2.3\r
38 In-Reply-To: <87d3qd1t43.fsf@ut.hh.sledj.net>\r
39 References: <87d3qd1t43.fsf@ut.hh.sledj.net>\r
40 X-BeenThere: notmuch@notmuchmail.org\r
41 X-Mailman-Version: 2.1.13\r
42 Precedence: list\r
43 List-Id: "Use and development of the notmuch mail system."\r
44         <notmuch.notmuchmail.org>\r
45 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
47 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
48 List-Post: <mailto:notmuch@notmuchmail.org>\r
49 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
50 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
52 X-List-Received-Date: Wed, 10 Nov 2010 09:24:50 -0000\r
53 \r
54 Simplify the display of addresses by setting\r
55 `notmuch-show-address-simplication' to:\r
56 \r
57 - 'full: Only the name component of the address, if present, is\r
58   shown (the default),\r
59 - 'partial: Addresses are stripped of redundant information,\r
60 - 'none: Addresses are shown as-is.\r
61 ---\r
62  emacs/notmuch-show.el |   55 +++++++++++++++++++++++++++++++++++++++++++++++-\r
63  1 files changed, 53 insertions(+), 2 deletions(-)\r
64 \r
65 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
66 index 9e5d72d..054aba1 100644\r
67 --- a/emacs/notmuch-show.el\r
68 +++ b/emacs/notmuch-show.el\r
69 @@ -26,6 +26,7 @@\r
70  (require 'message)\r
71  (require 'mm-decode)\r
72  (require 'mailcap)\r
73 +(require 'mail-parse)\r
74  \r
75  (require 'notmuch-lib)\r
76  (require 'notmuch-query)\r
77 @@ -82,6 +83,21 @@ any given message."\r
78              notmuch-wash-elide-blank-lines\r
79              notmuch-wash-excerpt-citations))\r
80  \r
81 +(defcustom notmuch-show-address-simplification 'full\r
82 +  "How should addresses be displayed?\r
83 +\r
84 +Set `notmuch-show-address-simplication' to:\r
85 +\r
86 +- 'full: Only the name component of the address, if present, is\r
87 +  shown,\r
88 +- 'partial: Addresses are stripped of redundant information,\r
89 +- 'none: Addresses are shown as-is."\r
90 +  :group 'notmuch\r
91 +  :type '(choice\r
92 +         (const :tag "Full simplification" full)\r
93 +         (const :tag "Partial simplification" partial)\r
94 +         (const :tag "No simplification" none)))\r
95 +\r
96  (defmacro with-current-notmuch-show-message (&rest body)\r
97    "Evaluate body with current buffer set to the text of current message"\r
98    `(save-excursion\r
99 @@ -198,12 +214,36 @@ any given message."\r
100                                              'face 'notmuch-tag-face)\r
101                                  ")"))))))\r
102  \r
103 +(defun notmuch-show-clean-address (parsed-address)\r
104 +  "Prepare a single email address for display."\r
105 +  (let* ((address (car parsed-address))\r
106 +        (name (cdr parsed-address))\r
107 +        (displayed-name name))\r
108 +\r
109 +    ;; If the address is 'foo@bar.com <foo@bar.com>' then show just\r
110 +    ;; 'foo@bar.com'.\r
111 +    (when (string= displayed-name address)\r
112 +      (setq displayed-name nil))\r
113 +\r
114 +    (cond\r
115 +     ((eq notmuch-show-address-simplification 'full)\r
116 +      (if displayed-name\r
117 +         (propertize displayed-name 'help-echo address)\r
118 +       address))\r
119 +\r
120 +     ((eq notmuch-show-address-simplification 'partial)\r
121 +      (mail-header-make-address displayed-name address))\r
122 +\r
123 +     (t ;; All other settings, but mostly 'none.\r
124 +      (mail-header-make-address name address)))))\r
125 +\r
126  (defun notmuch-show-insert-headerline (headers date tags depth)\r
127    "Insert a notmuch style headerline based on HEADERS for a\r
128  message at DEPTH in the current thread."\r
129    (let ((start (point)))\r
130      (insert (notmuch-show-spaces-n depth)\r
131 -           (plist-get headers :From)\r
132 +           (notmuch-show-clean-address\r
133 +            (mail-header-parse-address (plist-get headers :From)))\r
134             " ("\r
135             date\r
136             ") ("\r
137 @@ -214,7 +254,18 @@ message at DEPTH in the current thread."\r
138  \r
139  (defun notmuch-show-insert-header (header header-value)\r
140    "Insert a single header."\r
141 -  (insert header ": " header-value "\n"))\r
142 +  (insert header ": "\r
143 +         (cond\r
144 +          ((or (string= "To" header)\r
145 +               (string= "Cc" header)\r
146 +               (string= "Bcc" header)\r
147 +               (string= "From" header))\r
148 +           (mapconcat 'notmuch-show-clean-address\r
149 +                      (mail-header-parse-addresses header-value)\r
150 +                      ", "))\r
151 +          (t\r
152 +           header-value))\r
153 +         "\n"))\r
154  \r
155  (defun notmuch-show-insert-headers (headers)\r
156    "Insert the headers of the current message."\r
157 -- \r
158 1.7.2.3\r
159 \r