Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / 63 / 4783670fd89f3837f539b06b34145433f56146
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 2E9A8429E5A\r
6         for <notmuch@notmuchmail.org>; Tue, 17 Jan 2012 04:52:48 -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: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\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 5M6FxTgZsDDO for <notmuch@notmuchmail.org>;\r
16         Tue, 17 Jan 2012 04:52:47 -0800 (PST)\r
17 Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com\r
18         [209.85.212.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 6BF00429E3B\r
21         for <notmuch@notmuchmail.org>; Tue, 17 Jan 2012 04:52:47 -0800 (PST)\r
22 Received: by wibhr12 with SMTP id hr12so3405338wib.26\r
23         for <notmuch@notmuchmail.org>; Tue, 17 Jan 2012 04:52:46 -0800 (PST)\r
24 Received: by 10.180.84.133 with SMTP id z5mr22717168wiy.10.1326804766277;\r
25         Tue, 17 Jan 2012 04:52:46 -0800 (PST)\r
26 Received: from hotblack-desiato.hh.sledj.net\r
27         (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25])\r
28         by mx.google.com with ESMTPS id g12sm43726534wiw.10.2012.01.17.04.52.43\r
29         (version=TLSv1/SSLv3 cipher=OTHER);\r
30         Tue, 17 Jan 2012 04:52:44 -0800 (PST)\r
31 Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
32         id 06C7FA051F; Tue, 17 Jan 2012 12:52:42 +0000 (GMT)\r
33 From: David Edmondson <dme@dme.org>\r
34 To: notmuch@notmuchmail.org\r
35 Subject: [PATCH 3/4] emacs: Avoid `mail-header-parse-address' in\r
36         `notmuch-show-clean-address'.\r
37 Date: Tue, 17 Jan 2012 12:52:27 +0000\r
38 Message-Id: <1326804748-8989-4-git-send-email-dme@dme.org>\r
39 X-Mailer: git-send-email 1.7.7.3\r
40 In-Reply-To: <1326804748-8989-1-git-send-email-dme@dme.org>\r
41 References: <1326804748-8989-1-git-send-email-dme@dme.org>\r
42 X-BeenThere: notmuch@notmuchmail.org\r
43 X-Mailman-Version: 2.1.13\r
44 Precedence: list\r
45 List-Id: "Use and development of the notmuch mail system."\r
46         <notmuch.notmuchmail.org>\r
47 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
48         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
49 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
50 List-Post: <mailto:notmuch@notmuchmail.org>\r
51 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
52 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
54 X-List-Received-Date: Tue, 17 Jan 2012 12:52:48 -0000\r
55 \r
56 `mail-header-parse-address' expects un-decoded mailbox parts, which is\r
57 not what we have at this point. Replace it with simple string\r
58 deconstruction.\r
59 ---\r
60  emacs/notmuch-show.el |   48 +++++++++++++++++++++++++++++++++++-------------\r
61  1 files changed, 35 insertions(+), 13 deletions(-)\r
62 \r
63 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
64 index 797f94b..8b2fbb3 100644\r
65 --- a/emacs/notmuch-show.el\r
66 +++ b/emacs/notmuch-show.el\r
67 @@ -227,21 +227,43 @@ indentation."\r
68    "Try to clean a single email ADDRESS for display.  Return\r
69  unchanged ADDRESS if parsing fails."\r
70    (condition-case nil\r
71 -    (let* ((parsed (mail-header-parse-address address))\r
72 -          (address (car parsed))\r
73 -          (name (cdr parsed)))\r
74 -      ;; Remove double quotes. They might be required during transport,\r
75 -      ;; but we don't need to see them.\r
76 -      (when name\r
77 -        (setq name (replace-regexp-in-string "\"" "" name)))\r
78 +    (let (p-name p-address)\r
79 +      ;; It would be convenient to use `mail-header-parse-address',\r
80 +      ;; but that expects un-decoded mailbox parts, whereas our\r
81 +      ;; mailbox parts are already decoded (and hence may contain\r
82 +      ;; UTF-8). Given that notmuch should handle most of the awkward\r
83 +      ;; cases, some simple string deconstruction should be sufficient\r
84 +      ;; here.\r
85 +      (cond\r
86 +       ;; "User <user@dom.ain>" style.\r
87 +       ((string-match "\\(.*\\) <\\(.*\\)>" address)\r
88 +       (setq p-name (match-string 1 address)\r
89 +             p-address (match-string 2 address)))\r
90 +\r
91 +       ;; "<user@dom.ain>" style.\r
92 +       ((string-match "<\\(.*\\)>" address)\r
93 +       (setq p-address (match-string 1 address)))\r
94 +\r
95 +       ;; Everything else.\r
96 +       (t\r
97 +       (setq p-address address)))\r
98 +      \r
99 +      ;; Remove outer double quotes. They might be required during\r
100 +      ;; transport, but we don't need to see them.\r
101 +      (when (and p-name\r
102 +                (string-match "^\"\\(.*\\)\"$" p-name))\r
103 +        (setq p-name (match-string 1 p-name)))\r
104 +\r
105        ;; If the address is 'foo@bar.com <foo@bar.com>' then show just\r
106        ;; 'foo@bar.com'.\r
107 -      (when (string= name address)\r
108 -        (setq name nil))\r
109 -\r
110 -      (if (not name)\r
111 -        address\r
112 -        (concat name " <" address ">")))\r
113 +      (when (string= p-name p-address)\r
114 +        (setq p-name nil))\r
115 +\r
116 +      ;; If no name results, return just the address.\r
117 +      (if (not p-name)\r
118 +         p-address\r
119 +       ;; Otherwise format the name and address together.\r
120 +       (concat p-name " <" p-address ">")))\r
121      (error address)))\r
122  \r
123  (defun notmuch-show-insert-headerline (headers date tags depth)\r
124 -- \r
125 1.7.7.3\r
126 \r