Re: search query "replytoid:<blah>"
[notmuch-archives.git] / 21 / 898f28f0c784d22f0f00c6f877119c70605389
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 7866140DBF6\r
6         for <notmuch@notmuchmail.org>; Fri, 12 Nov 2010 00:00:30 -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 e7SjRNBoEMlC for <notmuch@notmuchmail.org>;\r
16         Fri, 12 Nov 2010 00:00:18 -0800 (PST)\r
17 Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com\r
18  [74.125.82.45])        by olra.theworths.org (Postfix) with ESMTP id 1B2E240DBC8       for\r
19  <notmuch@notmuchmail.org>; Fri, 12 Nov 2010 00:00:17 -0800 (PST)\r
20 Received: by wwb39 with SMTP id 39so1166998wwb.2\r
21         for <notmuch@notmuchmail.org>; Fri, 12 Nov 2010 00:00:14 -0800 (PST)\r
22 Received: by 10.216.164.134 with SMTP id c6mr3211161wel.48.1289548811597;\r
23         Fri, 12 Nov 2010 00:00:11 -0800 (PST)\r
24 Received: from ut.hh.sledj.net (host81-149-164-25.in-addr.btopenworld.com\r
25         [81.149.164.25])\r
26         by mx.google.com with ESMTPS id l14sm1918860weq.11.2010.11.12.00.00.08\r
27         (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
28         Fri, 12 Nov 2010 00:00:08 -0800 (PST)\r
29 Received: by ut.hh.sledj.net (Postfix, from userid 1000)\r
30         id 0BDED59405B; Fri, 12 Nov 2010 07:58:25 +0000 (GMT)\r
31 From: David Edmondson <dme@dme.org>\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [PATCH] emacs: Show cleaner addresses during message display.\r
34 Date: Fri, 12 Nov 2010 07:58:24 +0000\r
35 Message-Id: <1289548704-8071-1-git-send-email-dme@dme.org>\r
36 X-Mailer: git-send-email 1.7.2.3\r
37 In-Reply-To: <87mxpfmjh8.fsf@yoom.home.cworth.org>\r
38 References: <87mxpfmjh8.fsf@yoom.home.cworth.org>\r
39 X-BeenThere: notmuch@notmuchmail.org\r
40 X-Mailman-Version: 2.1.13\r
41 Precedence: list\r
42 List-Id: "Use and development of the notmuch mail system."\r
43         <notmuch.notmuchmail.org>\r
44 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
45         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
47 List-Post: <mailto:notmuch@notmuchmail.org>\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
49 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
50         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
51 X-List-Received-Date: Fri, 12 Nov 2010 08:00:30 -0000\r
52 \r
53 Simplify the display of addresses by setting\r
54 `notmuch-show-address-simplication' to:\r
55 \r
56 - 'full: Only the name component of the address, if present, is\r
57   shown,\r
58 - 'partial: Addresses are stripped of redundant information (the\r
59   default),\r
60 - 'none: Addresses are shown as-is.\r
61 \r
62 `mail-header-parse-address' fails for some addresses, in particular\r
63 "undisclosed-recipients:;". Accommodate this by returning the original\r
64 address if the parser fails.\r
65 \r
66 Adjust the test results accordingly.\r
67 ---\r
68 \r
69 Default is now 'partial (most similar to the old behaviour). Allow for\r
70 un-parseable addresses. Don't add unnecessary quotes. Oh, and, fix the\r
71 test suite.\r
72 \r
73 Carl: You can ignore the notmuch-lkml.el chunk, as you don't have that\r
74 yet.\r
75 \r
76  emacs/notmuch-lkml.el                              |    4 +-\r
77  emacs/notmuch-show.el                              |   65 +++++++++++++++++++-\r
78  .../notmuch-show-thread-maildir-storage            |    6 +-\r
79  3 files changed, 68 insertions(+), 7 deletions(-)\r
80 \r
81 diff --git a/emacs/notmuch-lkml.el b/emacs/notmuch-lkml.el\r
82 index 750370b..fc04be6 100644\r
83 --- a/emacs/notmuch-lkml.el\r
84 +++ b/emacs/notmuch-lkml.el\r
85 @@ -29,7 +29,7 @@\r
86  (declare-function notmuch-call-notmuch-process "notmuch" (&rest args))\r
87  (declare-function notmuch-show "notmuch-show" (&rest args))\r
88  (declare-function notmuch-show-strip-re "notmuch-show" (subject))\r
89 -(declare-function notmuch-show-clean-address "notmuch-show" (parsed-address))\r
90 +(declare-function notmuch-show-clean-address "notmuch-show" (address))\r
91  (declare-function notmuch-show-spaces-n "notmuch-show" (n))\r
92  \r
93  (defcustom notmuch-lkml-author-width 30\r
94 @@ -71,7 +71,7 @@\r
95              (notmuch-lkml-string-width \r
96               (concat (notmuch-show-spaces-n depth)\r
97                       (notmuch-show-clean-address\r
98 -                      (mail-header-parse-address (plist-get headers :From))))\r
99 +                      (plist-get headers :From)))\r
100               notmuch-lkml-author-width)\r
101              " "\r
102              (if (string= notmuch-lkml-previous-subject\r
103 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
104 index d8773e6..aa89cfd 100644\r
105 --- a/emacs/notmuch-show.el\r
106 +++ b/emacs/notmuch-show.el\r
107 @@ -26,6 +26,7 @@\r
108  (require 'message)\r
109  (require 'mm-decode)\r
110  (require 'mailcap)\r
111 +(require 'mail-parse)\r
112  \r
113  (require 'notmuch-lib)\r
114  (require 'notmuch-query)\r
115 @@ -82,6 +83,21 @@ any given message."\r
116              notmuch-wash-elide-blank-lines\r
117              notmuch-wash-excerpt-citations))\r
118  \r
119 +(defcustom notmuch-show-address-simplification 'partial\r
120 +  "How should addresses be displayed?\r
121 +\r
122 +Set `notmuch-show-address-simplication' to:\r
123 +\r
124 +- 'full: Only the name component of the address, if present, is\r
125 +  shown,\r
126 +- 'partial: Addresses are stripped of redundant information,\r
127 +- 'none: Addresses are shown as-is."\r
128 +  :group 'notmuch\r
129 +  :type '(choice\r
130 +         (const :tag "Full simplification" full)\r
131 +         (const :tag "Partial simplification" partial)\r
132 +         (const :tag "No simplification" none)))\r
133 +\r
134  (defmacro with-current-notmuch-show-message (&rest body)\r
135    "Evaluate body with current buffer set to the text of current message"\r
136    `(save-excursion\r
137 @@ -198,12 +214,46 @@ any given message."\r
138                                              'face 'notmuch-tag-face)\r
139                                  ")"))))))\r
140  \r
141 +(defun notmuch-show-clean-address (original-address)\r
142 +  "Prepare a single email address for display."\r
143 +  (let* ((parsed-address (mail-header-parse-address original-address))\r
144 +        (address (car parsed-address))\r
145 +        (name (cdr parsed-address))\r
146 +        (displayed-name name))\r
147 +\r
148 +    ;; If the parser failed, use the original string.\r
149 +    (if (not parsed-address)\r
150 +       original-address\r
151 +\r
152 +      ;; If the address is 'foo@bar.com <foo@bar.com>' then show just\r
153 +      ;; 'foo@bar.com'.\r
154 +      (when (string= displayed-name address)\r
155 +       (setq displayed-name nil))\r
156 +\r
157 +      (cond\r
158 +       ((eq notmuch-show-address-simplification 'full)\r
159 +       (if displayed-name\r
160 +           (propertize displayed-name 'help-echo address)\r
161 +         address))\r
162 +\r
163 +       ((eq notmuch-show-address-simplification 'partial)\r
164 +       (if displayed-name\r
165 +           ;; `mail-header-make-address' is enthusiastic about\r
166 +           ;; quoting the displayed name if it contains spaces (which\r
167 +           ;; is visually unappealing) so generate the displayed\r
168 +           ;; string directly here.\r
169 +           (concat displayed-name " <" address ">")\r
170 +         address))\r
171 +\r
172 +       (t ;; All other settings, but mostly 'none.\r
173 +       original-address)))))\r
174 +\r
175  (defun notmuch-show-insert-headerline (headers date tags depth)\r
176    "Insert a notmuch style headerline based on HEADERS for a\r
177  message at DEPTH in the current thread."\r
178    (let ((start (point)))\r
179      (insert (notmuch-show-spaces-n depth)\r
180 -           (plist-get headers :From)\r
181 +           (notmuch-show-clean-address (plist-get headers :From))\r
182             " ("\r
183             date\r
184             ") ("\r
185 @@ -214,7 +264,18 @@ message at DEPTH in the current thread."\r
186  \r
187  (defun notmuch-show-insert-header (header header-value)\r
188    "Insert a single header."\r
189 -  (insert header ": " header-value "\n"))\r
190 +  (insert header ": "\r
191 +         (cond\r
192 +          ((or (string= "To" header)\r
193 +               (string= "Cc" header)\r
194 +               (string= "Bcc" header)\r
195 +               (string= "From" header))\r
196 +           (mapconcat 'notmuch-show-clean-address\r
197 +                      (mail-header-parse-addresses header-value t)\r
198 +                      ", "))\r
199 +          (t\r
200 +           header-value))\r
201 +         "\n"))\r
202  \r
203  (defun notmuch-show-insert-headers (headers)\r
204    "Insert the headers of the current message."\r
205 diff --git a/test/emacs.expected-output/notmuch-show-thread-maildir-storage b/test/emacs.expected-output/notmuch-show-thread-maildir-storage\r
206 index 086f874..2f18924 100644\r
207 --- a/test/emacs.expected-output/notmuch-show-thread-maildir-storage\r
208 +++ b/test/emacs.expected-output/notmuch-show-thread-maildir-storage\r
209 @@ -92,7 +92,7 @@ http://notmuchmail.org/mailman/listinfo/notmuch\r
210    notmuch mailing list\r
211    notmuch@notmuchmail.org\r
212    http://notmuchmail.org/mailman/listinfo/notmuch\r
213 -   "Mikhail Gusarov" <dottedmag@dottedmag.net> (2009-11-17) (inbox unread)\r
214 +   Mikhail Gusarov <dottedmag@dottedmag.net> (2009-11-17) (inbox unread)\r
215     Subject: [notmuch] Working with Maildir storage?\r
216     To: notmuch@notmuchmail.org\r
217     Date: Wed, 18 Nov 2009 02:50:48 +0600\r
218 @@ -120,7 +120,7 @@ http://notmuchmail.org/mailman/listinfo/notmuch\r
219     Desc: not available\r
220     URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20091118/0e33d964/attachment.pgp>\r
221  \r
222 -   "Keith Packard" <keithp@keithp.com> (2009-11-17) (inbox unread)\r
223 +   Keith Packard <keithp@keithp.com> (2009-11-17) (inbox unread)\r
224     Subject: [notmuch] Working with Maildir storage?\r
225     To: notmuch@notmuchmail.org\r
226     Date: Tue, 17 Nov 2009 13:24:13 -0800\r
227 @@ -167,7 +167,7 @@ http://notmuchmail.org/mailman/listinfo/notmuch\r
228      notmuch mailing list\r
229      notmuch@notmuchmail.org\r
230      http://notmuchmail.org/mailman/listinfo/notmuch\r
231 - "Carl Worth" <cworth@cworth.org> (2009-11-18) (inbox unread)\r
232 + Carl Worth <cworth@cworth.org> (2009-11-18) (inbox unread)\r
233   Subject: [notmuch] Working with Maildir storage?\r
234   To: notmuch@notmuchmail.org\r
235   Date: Wed, 18 Nov 2009 02:08:10 -0800\r
236 -- \r
237 1.7.2.3\r
238 \r