Re: notmuch-tree display
[notmuch-archives.git] / a9 / d8e4d6ed9068fa8e8591b84dac73769cbf2945
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 7E1F8429E39\r
6         for <notmuch@notmuchmail.org>; Wed, 25 Jan 2012 03:45:11 -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 BMX3sjcgbTJ6 for <notmuch@notmuchmail.org>;\r
16         Wed, 25 Jan 2012 03:45:10 -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 8D49B431FBC\r
21         for <notmuch@notmuchmail.org>; Wed, 25 Jan 2012 03:45:10 -0800 (PST)\r
22 Received: by wibhi8 with SMTP id hi8so2399685wib.26\r
23         for <notmuch@notmuchmail.org>; Wed, 25 Jan 2012 03:45:09 -0800 (PST)\r
24 MIME-Version: 1.0\r
25 Received: by 10.180.96.161 with SMTP id dt1mr10623483wib.13.1327491909329;\r
26         Wed, 25 Jan 2012 03:45:09 -0800 (PST)\r
27 Received: from hotblack-desiato.hh.sledj.net\r
28         (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25])\r
29         by mx.google.com with ESMTPS id t6sm23928063wid.1.2012.01.25.03.45.06\r
30         (version=TLSv1/SSLv3 cipher=OTHER);\r
31         Wed, 25 Jan 2012 03:45:07 -0800 (PST)\r
32 Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
33         id AAD739FE6A; Wed, 25 Jan 2012 11:45:05 +0000 (GMT)\r
34 From: David Edmondson <dme@dme.org>\r
35 To: notmuch@notmuchmail.org\r
36 Subject: [PATCH 1/2] emacs: Avoid `mail-header-parse-address' in\r
37         `notmuch-show-clean-address'.\r
38 Date: Wed, 25 Jan 2012 11:45:03 +0000\r
39 Message-Id: <1327491904-28416-2-git-send-email-dme@dme.org>\r
40 X-Mailer: git-send-email 1.7.8.3\r
41 In-Reply-To: <1327491904-28416-1-git-send-email-dme@dme.org>\r
42 References: <1327491904-28416-1-git-send-email-dme@dme.org>\r
43 X-Gm-Message-State:\r
44  ALoCoQnoGonyv2vaUcAhQOub5Giw7wk3E/JZc7rK6WMLp8LruZ538K3JjK+GdBX3JxphExMVeU/b\r
45 X-BeenThere: notmuch@notmuchmail.org\r
46 X-Mailman-Version: 2.1.13\r
47 Precedence: list\r
48 List-Id: "Use and development of the notmuch mail system."\r
49         <notmuch.notmuchmail.org>\r
50 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
52 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
53 List-Post: <mailto:notmuch@notmuchmail.org>\r
54 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
55 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
57 X-List-Received-Date: Wed, 25 Jan 2012 11:45:11 -0000\r
58 \r
59 `mail-header-parse-address' expects un-decoded mailbox parts, which is\r
60 not what we have at this point. Replace it with simple string\r
61 deconstruction.\r
62 \r
63 Mark the corresponding test as no longer broken.\r
64 \r
65 Minor whitespace cleanup.\r
66 ---\r
67  emacs/notmuch-show.el          |   50 ++++++++++++++++++++++++++++-----------\r
68  test/emacs-address-cleaning.sh |    1 -\r
69  2 files changed, 36 insertions(+), 15 deletions(-)\r
70 \r
71 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
72 index e6a5b31..1fd2524 100644\r
73 --- a/emacs/notmuch-show.el\r
74 +++ b/emacs/notmuch-show.el\r
75 @@ -289,21 +289,43 @@ operation on the contents of the current buffer."\r
76    "Try to clean a single email ADDRESS for display.  Return\r
77  unchanged ADDRESS if parsing fails."\r
78    (condition-case nil\r
79 -    (let* ((parsed (mail-header-parse-address address))\r
80 -          (address (car parsed))\r
81 -          (name (cdr parsed)))\r
82 -      ;; Remove double quotes. They might be required during transport,\r
83 -      ;; but we don't need to see them.\r
84 -      (when name\r
85 -        (setq name (replace-regexp-in-string "\"" "" name)))\r
86 +    (let (p-name p-address)\r
87 +      ;; It would be convenient to use `mail-header-parse-address',\r
88 +      ;; but that expects un-decoded mailbox parts, whereas our\r
89 +      ;; mailbox parts are already decoded (and hence may contain\r
90 +      ;; UTF-8). Given that notmuch should handle most of the awkward\r
91 +      ;; cases, some simple string deconstruction should be sufficient\r
92 +      ;; here.\r
93 +      (cond\r
94 +       ;; "User <user@dom.ain>" style.\r
95 +       ((string-match "\\(.*\\) <\\(.*\\)>" address)\r
96 +       (setq p-name (match-string 1 address)\r
97 +             p-address (match-string 2 address)))\r
98 +\r
99 +       ;; "<user@dom.ain>" style.\r
100 +       ((string-match "<\\(.*\\)>" address)\r
101 +       (setq p-address (match-string 1 address)))\r
102 +\r
103 +       ;; Everything else.\r
104 +       (t\r
105 +       (setq p-address address)))\r
106 +\r
107 +      ;; Remove outer double quotes. They might be required during\r
108 +      ;; transport, but we don't need to see them.\r
109 +      (when (and p-name\r
110 +                (string-match "^\"\\(.*\\)\"$" p-name))\r
111 +       (setq p-name (match-string 1 p-name)))\r
112 +\r
113        ;; If the address is 'foo@bar.com <foo@bar.com>' then show just\r
114        ;; 'foo@bar.com'.\r
115 -      (when (string= name address)\r
116 -        (setq name nil))\r
117 -\r
118 -      (if (not name)\r
119 -        address\r
120 -        (concat name " <" address ">")))\r
121 +      (when (string= p-name p-address)\r
122 +       (setq p-name nil))\r
123 +\r
124 +      ;; If no name results, return just the address.\r
125 +      (if (not p-name)\r
126 +         p-address\r
127 +       ;; Otherwise format the name and address together.\r
128 +       (concat p-name " <" p-address ">")))\r
129      (error address)))\r
130  \r
131  (defun notmuch-show-insert-headerline (headers date tags depth)\r
132 @@ -1417,7 +1439,7 @@ than only the current message."\r
133    (interactive "P\nsPipe message to command: ")\r
134    (let (shell-command)\r
135      (if entire-thread\r
136 -       (setq shell-command \r
137 +       (setq shell-command\r
138               (concat notmuch-command " show --format=mbox "\r
139                       (shell-quote-argument\r
140                        (mapconcat 'identity (notmuch-show-get-message-ids-for-open-messages) " OR "))\r
141 diff --git a/test/emacs-address-cleaning.sh b/test/emacs-address-cleaning.sh\r
142 index 0d85bdc..51018fe 100755\r
143 --- a/test/emacs-address-cleaning.sh\r
144 +++ b/test/emacs-address-cleaning.sh\r
145 @@ -12,7 +12,6 @@ test_emacs_expect_t \\r
146      '(load "emacs-address-cleaning.el") (notmuch-test-address-cleaning-2)'\r
147  \r
148  test_begin_subtest "notmuch-test-address-clean part 3"\r
149 -test_subtest_known_broken\r
150  test_emacs_expect_t \\r
151      '(load "emacs-address-cleaning.el") (notmuch-test-address-cleaning-3)'\r
152  \r
153 -- \r
154 1.7.8.3\r
155 \r