1 Return-Path: <jani@nikula.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 87EF0431FB6
\r
6 for <notmuch@notmuchmail.org>; Sat, 12 May 2012 10:23:24 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\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 7Lisn6X46AHH for <notmuch@notmuchmail.org>;
\r
16 Sat, 12 May 2012 10:23:23 -0700 (PDT)
\r
17 Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com
\r
18 [209.85.217.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 1BA66431FAE
\r
21 for <notmuch@notmuchmail.org>; Sat, 12 May 2012 10:23:22 -0700 (PDT)
\r
22 Received: by lbbgk8 with SMTP id gk8so2797909lbb.26
\r
23 for <notmuch@notmuchmail.org>; Sat, 12 May 2012 10:23:20 -0700 (PDT)
\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
25 d=google.com; s=20120113;
\r
26 h=from:to:cc:subject:in-reply-to:references:user-agent:date
\r
27 :message-id:mime-version:content-type:x-gm-message-state;
\r
28 bh=Mm7vU5wOMu/hoWZTzXF8/5XrT2vHlc2iTkKtmFNi5Jw=;
\r
29 b=FwD2JnXEPgP/Nv7TCAq2hWw86aug0RULkPw+C6ajsYdXwFo0+/gDZVuWjSB+zGUqEG
\r
30 oe87wze+dT5z9w8/TvTLAnLFssoZo0swmxON0d/PpGR/2Z9SeN3uiHgzu6JGjmMMdJqV
\r
31 1r+wLR65k5VV2f5jjFdJ/q6NYW5euige/F5lJPl/WC+bOGvMLMP7DUzrHznla+fuLx5a
\r
32 E1/uhD0l2eSkyPW2a6Zwi5y/f9msoOBLUhTq2Wk0ZCJa5xgU1hFiGNqOxiMkpns20ECb
\r
33 9WnL/R7iSIBQ9a5bPWiDr6+bU7Q2I7/9IMi2ehvAGLR3lvm23ty3SXWpiTM+zt+KYBfr
\r
35 Received: by 10.112.98.137 with SMTP id ei9mr973937lbb.102.1336843400107;
\r
36 Sat, 12 May 2012 10:23:20 -0700 (PDT)
\r
37 Received: from localhost (dsl-hkibrasgw4-fe50dc00-68.dhcp.inet.fi.
\r
39 by mx.google.com with ESMTPS id i6sm16636115lbg.2.2012.05.12.10.23.17
\r
40 (version=SSLv3 cipher=OTHER); Sat, 12 May 2012 10:23:18 -0700 (PDT)
\r
41 From: Jani Nikula <jani@nikula.org>
\r
42 To: Austin Clements <amdragon@MIT.EDU>
\r
43 Subject: Re: [PATCH 2/2] cli: clean up user address matching code in
\r
44 guess_from_received_header()
\r
45 In-Reply-To: <20120512154746.GK11804@mit.edu>
\r
47 <bae496e6100a4e4d4a598dcf5c73d67b178f4128.1336746187.git.jani@nikula.org>
\r
48 <cd73ec6368b3743b0d84ed1696bfa00960124645.1336746187.git.jani@nikula.org>
\r
49 <20120512154746.GK11804@mit.edu>
\r
50 User-Agent: Notmuch/0.12+169~g45438b0 (http://notmuchmail.org) Emacs/23.3.1
\r
52 Date: Sat, 12 May 2012 20:23:16 +0300
\r
53 Message-ID: <87k40h1fgb.fsf@nikula.org>
\r
55 Content-Type: text/plain; charset=us-ascii
\r
57 ALoCoQnNgvbFzQ1bMidIifUj3dpwUmPRQlG1ShYbb5Pvt66IiFoKEJlxX2xkzfUqzpfd7WFJwkP0
\r
58 Cc: notmuch@notmuchmail.org
\r
59 X-BeenThere: notmuch@notmuchmail.org
\r
60 X-Mailman-Version: 2.1.13
\r
62 List-Id: "Use and development of the notmuch mail system."
\r
63 <notmuch.notmuchmail.org>
\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
65 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
67 List-Post: <mailto:notmuch@notmuchmail.org>
\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
70 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
71 X-List-Received-Date: Sat, 12 May 2012 17:23:24 -0000
\r
73 On Sat, 12 May 2012, Austin Clements <amdragon@MIT.EDU> wrote:
\r
74 > Series LGTM. This is a nice cleanup.
\r
76 Thanks for the review.
\r
78 > My one comment is that it seems like we should be stricter about
\r
79 > matching email address lists, since a naive substring match could
\r
80 > yield strange results. That's not something that should be changed in
\r
81 > this patch, though.
\r
83 Agreed. Especially the Received: header matching should be scrutinized,
\r
84 as *all* the Received: headers in a message are merged into one by
\r
85 notmuch_message_file_get_header(). But that should be another patch,
\r
88 > Does the context of this patch conflict with
\r
89 > id:"21a946917c5c8dd63295b7c87b7c2d1ebcb6e71e.1336746160.git.jani@nikula.org"
\r
90 > ? It seems like both have context that's changed by the other patch.
\r
92 Ooops, you're right. The two series do *merge* on top of each other in
\r
93 either order, but as patches they apply only on master. I wanted to keep
\r
94 the series separate. Once either gets pushed, I'll rebase the other.
\r
100 > Quoth Jani Nikula on May 11 at 5:33 pm:
\r
101 >> Get rid of user address matching code duplication in
\r
102 >> guess_from_received_header() by using the new address matching
\r
105 >> No functional changes.
\r
107 >> Signed-off-by: Jani Nikula <jani@nikula.org>
\r
109 >> notmuch-reply.c | 64 +++++++++++++++++--------------------------------------
\r
110 >> 1 file changed, 19 insertions(+), 45 deletions(-)
\r
112 >> diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
113 >> index 0c82755..51cb6de 100644
\r
114 >> --- a/notmuch-reply.c
\r
115 >> +++ b/notmuch-reply.c
\r
116 >> @@ -377,20 +377,15 @@ add_recipients_from_message (GMimeMessage *reply,
\r
117 >> static const char *
\r
118 >> guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message)
\r
120 >> - const char *received,*primary,*by;
\r
121 >> - const char **other;
\r
123 >> + const char *addr, *received, *by;
\r
124 >> char *mta,*ptr,*token;
\r
125 >> char *domain=NULL;
\r
127 >> const char *delim=". \t";
\r
128 >> - size_t i,j,other_len;
\r
131 >> const char *to_headers[] = {"Envelope-to", "X-Original-To"};
\r
133 >> - primary = notmuch_config_get_user_primary_email (config);
\r
134 >> - other = notmuch_config_get_user_other_email (config, &other_len);
\r
136 >> /* sadly, there is no standard way to find out to which email
\r
137 >> * address a mail was delivered - what is in the headers depends
\r
138 >> * on the MTAs used along the way. So we are trying a number of
\r
139 >> @@ -405,23 +400,13 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message
\r
140 >> * 'by' part of Received headers
\r
141 >> * If none of these work, we give up and return NULL
\r
143 >> - for (i = 0; i < sizeof(to_headers)/sizeof(*to_headers); i++) {
\r
144 >> - tohdr = xstrdup(notmuch_message_get_header (message, to_headers[i]));
\r
145 >> - if (tohdr && *tohdr) {
\r
146 >> - /* tohdr is potentialy a list of email addresses, so here we
\r
147 >> - * check if one of the email addresses is a substring of tohdr
\r
149 >> - if (strcasestr(tohdr, primary)) {
\r
151 >> - return primary;
\r
153 >> - for (j = 0; j < other_len; j++)
\r
154 >> - if (strcasestr (tohdr, other[j])) {
\r
156 >> - return other[j];
\r
160 >> + for (i = 0; i < ARRAY_SIZE (to_headers); i++) {
\r
161 >> + const char *tohdr = notmuch_message_get_header (message, to_headers[i]);
\r
163 >> + /* Note: tohdr potentially contains a list of email addresses. */
\r
164 >> + addr = user_address_in_string (tohdr, config);
\r
169 >> /* We get the concatenated Received: headers and search from the
\r
170 >> @@ -439,19 +424,12 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message
\r
173 >> ptr = strstr (received, " for ");
\r
175 >> - /* the text following is potentialy a list of email addresses,
\r
176 >> - * so again we check if one of the email addresses is a
\r
177 >> - * substring of ptr
\r
179 >> - if (strcasestr(ptr, primary)) {
\r
180 >> - return primary;
\r
182 >> - for (i = 0; i < other_len; i++)
\r
183 >> - if (strcasestr (ptr, other[i])) {
\r
184 >> - return other[i];
\r
188 >> + /* Note: ptr potentially contains a list of email addresses. */
\r
189 >> + addr = user_address_in_string (ptr, config);
\r
193 >> /* Finally, we parse all the " by MTA ..." headers to guess the
\r
194 >> * email address that this was originally delivered to.
\r
195 >> * We extract just the MTA here by removing leading whitespace and
\r
196 >> @@ -492,15 +470,11 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message
\r
200 >> - if (strcasestr(primary, domain)) {
\r
202 >> - return primary;
\r
203 >> + addr = string_in_user_address (domain, config);
\r
208 >> - for (i = 0; i < other_len; i++)
\r
209 >> - if (strcasestr (other[i],domain)) {
\r
211 >> - return other[i];
\r