Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 1C9F6431FB6 for ; Sat, 12 May 2012 08:48:18 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vcR2mj+3UAoQ for ; Sat, 12 May 2012 08:48:17 -0700 (PDT) Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU [18.7.68.37]) by olra.theworths.org (Postfix) with ESMTP id 3AEAD431FAE for ; Sat, 12 May 2012 08:48:17 -0700 (PDT) X-AuditID: 12074425-b7f966d0000008b6-dc-4fae863eea01 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP id 1B.2C.02230.E368EAF4; Sat, 12 May 2012 11:48:14 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q4CFmDrt003547; Sat, 12 May 2012 11:48:14 -0400 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q4CFmC8W015892 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sat, 12 May 2012 11:48:13 -0400 (EDT) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) (envelope-from ) id 1STEYG-0000nn-5L; Sat, 12 May 2012 11:48:12 -0400 Date: Sat, 12 May 2012 11:48:12 -0400 From: Austin Clements To: Jani Nikula Subject: Re: [PATCH 2/2] cli: clean up user address matching code in guess_from_received_header() Message-ID: <20120512154746.GK11804@mit.edu> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmphleLIzCtJLcpLzFFi42IRYrdT17VrW+dvMGmarkXTdGeL6zdnMjsw edy6/5rd49mqW8wBTFFcNimpOZllqUX6dglcGdOffmcq+K1csWd5L1MD4yepLkZODgkBE4lX x6YxQthiEhfurWfrYuTiEBLYxyixcOcOVghnA6PEqf75LBDOSSaJ3ZevskM4Sxgl7q1uYAHp ZxFQlbgwZz2YzSagIbFt/3KwuSICihKbT+4Hs5kFpCW+/W5mArGFBZIlGhZ9ZAexeQV0JHb1 fmeGGLqQUeLs8XssEAlBiZMzn7BANGtJ3Pj3EqiZA2zQ8n8cIGFOgTCJNZ1LwOaLCqhITDm5 jW0Co9AsJN2zkHTPQuhewMi8ilE2JbdKNzcxM6c4NVm3ODkxLy+1SNdCLzezRC81pXQTIziw XVR3ME44pHSIUYCDUYmH98TBtf5CrIllxZW5hxglOZiURHlrGtf5C/El5adUZiQWZ8QXleak Fh9ilOBgVhLhjW8FyvGmJFZWpRblw6SkOViUxHk1td75CQmkJ5akZqemFqQWwWRlODiUJHi7 QRoFi1LTUyvSMnNKENJMHJwgw3mAhmeBDS8uSMwtzkyHyJ9iVJQS5y0ESQiAJDJK8+B6YYnn FaM40CvCvDkgVTzApAXX/QpoMBPQYH4BsMEliQgpqQZGiZmGvz7tYcyIuVJ74ubn3ZYVu8T/ cs8v455uNEPX4NFMn8kKx7vSBe/e9so3lZi0eumFPge/ph0XDZIO+6QfP8I2sVy+ZWJwdDfP 0b9bf+6qLgpWXLDq6fcCttNrAoxSbFqXVm9fujhp3caDLpbKu761Ps+wnXx4noTZ0XvxjIX6 rdV3FZPKlViKMxINtZiLihMBCuW9QhcDAAA= Cc: notmuch@notmuchmail.org X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 May 2012 15:48:18 -0000 Series LGTM. This is a nice cleanup. My one comment is that it seems like we should be stricter about matching email address lists, since a naive substring match could yield strange results. That's not something that should be changed in this patch, though. Does the context of this patch conflict with id:"21a946917c5c8dd63295b7c87b7c2d1ebcb6e71e.1336746160.git.jani@nikula.org" ? It seems like both have context that's changed by the other patch. Quoth Jani Nikula on May 11 at 5:33 pm: > Get rid of user address matching code duplication in > guess_from_received_header() by using the new address matching > helpers. > > No functional changes. > > Signed-off-by: Jani Nikula > --- > notmuch-reply.c | 64 +++++++++++++++++-------------------------------------- > 1 file changed, 19 insertions(+), 45 deletions(-) > > diff --git a/notmuch-reply.c b/notmuch-reply.c > index 0c82755..51cb6de 100644 > --- a/notmuch-reply.c > +++ b/notmuch-reply.c > @@ -377,20 +377,15 @@ add_recipients_from_message (GMimeMessage *reply, > static const char * > guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message) > { > - const char *received,*primary,*by; > - const char **other; > - char *tohdr; > + const char *addr, *received, *by; > char *mta,*ptr,*token; > char *domain=NULL; > char *tld=NULL; > const char *delim=". \t"; > - size_t i,j,other_len; > + size_t i; > > const char *to_headers[] = {"Envelope-to", "X-Original-To"}; > > - primary = notmuch_config_get_user_primary_email (config); > - other = notmuch_config_get_user_other_email (config, &other_len); > - > /* sadly, there is no standard way to find out to which email > * address a mail was delivered - what is in the headers depends > * on the MTAs used along the way. So we are trying a number of > @@ -405,23 +400,13 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message > * 'by' part of Received headers > * If none of these work, we give up and return NULL > */ > - for (i = 0; i < sizeof(to_headers)/sizeof(*to_headers); i++) { > - tohdr = xstrdup(notmuch_message_get_header (message, to_headers[i])); > - if (tohdr && *tohdr) { > - /* tohdr is potentialy a list of email addresses, so here we > - * check if one of the email addresses is a substring of tohdr > - */ > - if (strcasestr(tohdr, primary)) { > - free(tohdr); > - return primary; > - } > - for (j = 0; j < other_len; j++) > - if (strcasestr (tohdr, other[j])) { > - free(tohdr); > - return other[j]; > - } > - free(tohdr); > - } > + for (i = 0; i < ARRAY_SIZE (to_headers); i++) { > + const char *tohdr = notmuch_message_get_header (message, to_headers[i]); > + > + /* Note: tohdr potentially contains a list of email addresses. */ > + addr = user_address_in_string (tohdr, config); > + if (addr) > + return addr; > } > > /* We get the concatenated Received: headers and search from the > @@ -439,19 +424,12 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message > * header > */ > ptr = strstr (received, " for "); > - if (ptr) { > - /* the text following is potentialy a list of email addresses, > - * so again we check if one of the email addresses is a > - * substring of ptr > - */ > - if (strcasestr(ptr, primary)) { > - return primary; > - } > - for (i = 0; i < other_len; i++) > - if (strcasestr (ptr, other[i])) { > - return other[i]; > - } > - } > + > + /* Note: ptr potentially contains a list of email addresses. */ > + addr = user_address_in_string (ptr, config); > + if (addr) > + return addr; > + > /* Finally, we parse all the " by MTA ..." headers to guess the > * email address that this was originally delivered to. > * We extract just the MTA here by removing leading whitespace and > @@ -492,15 +470,11 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message > */ > *(tld-1) = '.'; > > - if (strcasestr(primary, domain)) { > - free(mta); > - return primary; > + addr = string_in_user_address (domain, config); > + if (addr) { > + free (mta); > + return addr; > } > - for (i = 0; i < other_len; i++) > - if (strcasestr (other[i],domain)) { > - free(mta); > - return other[i]; > - } > } > free (mta); > }