1 Return-Path: <amdragon@mit.edu>
\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 1C9F6431FB6
\r
6 for <notmuch@notmuchmail.org>; Sat, 12 May 2012 08:48:18 -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 vcR2mj+3UAoQ for <notmuch@notmuchmail.org>;
\r
16 Sat, 12 May 2012 08:48:17 -0700 (PDT)
\r
17 Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id 3AEAD431FAE
\r
20 for <notmuch@notmuchmail.org>; Sat, 12 May 2012 08:48:17 -0700 (PDT)
\r
21 X-AuditID: 12074425-b7f966d0000008b6-dc-4fae863eea01
\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])
\r
23 by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id 1B.2C.02230.E368EAF4; Sat, 12 May 2012 11:48:14 -0400 (EDT)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q4CFmDrt003547;
\r
27 Sat, 12 May 2012 11:48:14 -0400
\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])
\r
29 (authenticated bits=0)
\r
30 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
31 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q4CFmC8W015892
\r
32 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
33 Sat, 12 May 2012 11:48:13 -0400 (EDT)
\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)
\r
35 (envelope-from <amdragon@mit.edu>)
\r
36 id 1STEYG-0000nn-5L; Sat, 12 May 2012 11:48:12 -0400
\r
37 Date: Sat, 12 May 2012 11:48:12 -0400
\r
38 From: Austin Clements <amdragon@MIT.EDU>
\r
39 To: Jani Nikula <jani@nikula.org>
\r
40 Subject: Re: [PATCH 2/2] cli: clean up user address matching code in
\r
41 guess_from_received_header()
\r
42 Message-ID: <20120512154746.GK11804@mit.edu>
\r
44 <bae496e6100a4e4d4a598dcf5c73d67b178f4128.1336746187.git.jani@nikula.org>
\r
45 <cd73ec6368b3743b0d84ed1696bfa00960124645.1336746187.git.jani@nikula.org>
\r
47 Content-Type: text/plain; charset=us-ascii
\r
48 Content-Disposition: inline
\r
50 <cd73ec6368b3743b0d84ed1696bfa00960124645.1336746187.git.jani@nikula.org>
\r
51 User-Agent: Mutt/1.5.21 (2010-09-15)
\r
52 X-Brightmail-Tracker:
\r
53 H4sIAAAAAAAAA+NgFmphleLIzCtJLcpLzFFi42IRYrdT17VrW+dvMGmarkXTdGeL6zdnMjsw
\r
54 edy6/5rd49mqW8wBTFFcNimpOZllqUX6dglcGdOffmcq+K1csWd5L1MD4yepLkZODgkBE4lX
\r
55 x6YxQthiEhfurWfrYuTiEBLYxyixcOcOVghnA6PEqf75LBDOSSaJ3ZevskM4Sxgl7q1uYAHp
\r
56 ZxFQlbgwZz2YzSagIbFt/3KwuSICihKbT+4Hs5kFpCW+/W5mArGFBZIlGhZ9ZAexeQV0JHb1
\r
57 fmeGGLqQUeLs8XssEAlBiZMzn7BANGtJ3Pj3EqiZA2zQ8n8cIGFOgTCJNZ1LwOaLCqhITDm5
\r
58 jW0Co9AsJN2zkHTPQuhewMi8ilE2JbdKNzcxM6c4NVm3ODkxLy+1SNdCLzezRC81pXQTIziw
\r
59 XVR3ME44pHSIUYCDUYmH98TBtf5CrIllxZW5hxglOZiURHlrGtf5C/El5adUZiQWZ8QXleak
\r
60 Fh9ilOBgVhLhjW8FyvGmJFZWpRblw6SkOViUxHk1td75CQmkJ5akZqemFqQWwWRlODiUJHi7
\r
61 QRoFi1LTUyvSMnNKENJMHJwgw3mAhmeBDS8uSMwtzkyHyJ9iVJQS5y0ESQiAJDJK8+B6YYnn
\r
62 FaM40CvCvDkgVTzApAXX/QpoMBPQYH4BsMEliQgpqQZGiZmGvz7tYcyIuVJ74ubn3ZYVu8T/
\r
63 cs8v455uNEPX4NFMn8kKx7vSBe/e9so3lZi0eumFPge/ph0XDZIO+6QfP8I2sVy+ZWJwdDfP
\r
64 0b9bf+6qLgpWXLDq6fcCttNrAoxSbFqXVm9fujhp3caDLpbKu761Ps+wnXx4noTZ0XvxjIX6
\r
65 rdV3FZPKlViKMxINtZiLihMBCuW9QhcDAAA=
\r
66 Cc: notmuch@notmuchmail.org
\r
67 X-BeenThere: notmuch@notmuchmail.org
\r
68 X-Mailman-Version: 2.1.13
\r
70 List-Id: "Use and development of the notmuch mail system."
\r
71 <notmuch.notmuchmail.org>
\r
72 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
73 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
74 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
75 List-Post: <mailto:notmuch@notmuchmail.org>
\r
76 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
77 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
78 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
79 X-List-Received-Date: Sat, 12 May 2012 15:48:18 -0000
\r
81 Series LGTM. This is a nice cleanup.
\r
83 My one comment is that it seems like we should be stricter about
\r
84 matching email address lists, since a naive substring match could
\r
85 yield strange results. That's not something that should be changed in
\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 Quoth Jani Nikula on May 11 at 5:33 pm:
\r
93 > Get rid of user address matching code duplication in
\r
94 > guess_from_received_header() by using the new address matching
\r
97 > No functional changes.
\r
99 > Signed-off-by: Jani Nikula <jani@nikula.org>
\r
101 > notmuch-reply.c | 64 +++++++++++++++++--------------------------------------
\r
102 > 1 file changed, 19 insertions(+), 45 deletions(-)
\r
104 > diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
105 > index 0c82755..51cb6de 100644
\r
106 > --- a/notmuch-reply.c
\r
107 > +++ b/notmuch-reply.c
\r
108 > @@ -377,20 +377,15 @@ add_recipients_from_message (GMimeMessage *reply,
\r
109 > static const char *
\r
110 > guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message)
\r
112 > - const char *received,*primary,*by;
\r
113 > - const char **other;
\r
115 > + const char *addr, *received, *by;
\r
116 > char *mta,*ptr,*token;
\r
117 > char *domain=NULL;
\r
119 > const char *delim=". \t";
\r
120 > - size_t i,j,other_len;
\r
123 > const char *to_headers[] = {"Envelope-to", "X-Original-To"};
\r
125 > - primary = notmuch_config_get_user_primary_email (config);
\r
126 > - other = notmuch_config_get_user_other_email (config, &other_len);
\r
128 > /* sadly, there is no standard way to find out to which email
\r
129 > * address a mail was delivered - what is in the headers depends
\r
130 > * on the MTAs used along the way. So we are trying a number of
\r
131 > @@ -405,23 +400,13 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message
\r
132 > * 'by' part of Received headers
\r
133 > * If none of these work, we give up and return NULL
\r
135 > - for (i = 0; i < sizeof(to_headers)/sizeof(*to_headers); i++) {
\r
136 > - tohdr = xstrdup(notmuch_message_get_header (message, to_headers[i]));
\r
137 > - if (tohdr && *tohdr) {
\r
138 > - /* tohdr is potentialy a list of email addresses, so here we
\r
139 > - * check if one of the email addresses is a substring of tohdr
\r
141 > - if (strcasestr(tohdr, primary)) {
\r
143 > - return primary;
\r
145 > - for (j = 0; j < other_len; j++)
\r
146 > - if (strcasestr (tohdr, other[j])) {
\r
148 > - return other[j];
\r
152 > + for (i = 0; i < ARRAY_SIZE (to_headers); i++) {
\r
153 > + const char *tohdr = notmuch_message_get_header (message, to_headers[i]);
\r
155 > + /* Note: tohdr potentially contains a list of email addresses. */
\r
156 > + addr = user_address_in_string (tohdr, config);
\r
161 > /* We get the concatenated Received: headers and search from the
\r
162 > @@ -439,19 +424,12 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message
\r
165 > ptr = strstr (received, " for ");
\r
167 > - /* the text following is potentialy a list of email addresses,
\r
168 > - * so again we check if one of the email addresses is a
\r
169 > - * substring of ptr
\r
171 > - if (strcasestr(ptr, primary)) {
\r
172 > - return primary;
\r
174 > - for (i = 0; i < other_len; i++)
\r
175 > - if (strcasestr (ptr, other[i])) {
\r
176 > - return other[i];
\r
180 > + /* Note: ptr potentially contains a list of email addresses. */
\r
181 > + addr = user_address_in_string (ptr, config);
\r
185 > /* Finally, we parse all the " by MTA ..." headers to guess the
\r
186 > * email address that this was originally delivered to.
\r
187 > * We extract just the MTA here by removing leading whitespace and
\r
188 > @@ -492,15 +470,11 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message
\r
192 > - if (strcasestr(primary, domain)) {
\r
194 > - return primary;
\r
195 > + addr = string_in_user_address (domain, config);
\r
200 > - for (i = 0; i < other_len; i++)
\r
201 > - if (strcasestr (other[i],domain)) {
\r
203 > - return other[i];
\r