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