--- /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 C004D429E26\r
+ for <notmuch@notmuchmail.org>; Thu, 12 Jan 2012 13:59:06 -0800 (PST)\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 sJgCh8RfuvtR for <notmuch@notmuchmail.org>;\r
+ Thu, 12 Jan 2012 13:59:06 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU\r
+ [18.7.68.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id E0B69431FB6\r
+ for <notmuch@notmuchmail.org>; Thu, 12 Jan 2012 13:59:05 -0800 (PST)\r
+X-AuditID: 12074422-b7fd66d0000008f9-2d-4f0f57a9ebbc\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+ by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 8E.2D.02297.9A75F0F4; Thu, 12 Jan 2012 16:59:05 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+ by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q0CLx4jD026441; \r
+ Thu, 12 Jan 2012 16:59:04 -0500\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 q0CLx2Ih022355\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Thu, 12 Jan 2012 16:59:03 -0500 (EST)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1RlSfp-0006X8-PV; Thu, 12 Jan 2012 16:59:05 -0500\r
+Date: Thu, 12 Jan 2012 16:59:05 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Jani Nikula <jani@nikula.org>\r
+Subject: Re: [PATCH v4 1/5] cli: slightly refactor "notmuch reply" address\r
+ scanning functions\r
+Message-ID: <20120112215905.GF18625@mit.edu>\r
+References: <cover.1325794371.git.jani@nikula.org>\r
+ <cover.1326403905.git.jani@nikula.org>\r
+ <9935c31d8727331b442ce266ae22469243b85f36.1326403905.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
+ <9935c31d8727331b442ce266ae22469243b85f36.1326403905.git.jani@nikula.org>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFuplleLIzCtJLcpLzFFi42IR4hTV1l0Zzu9v8OKZhEXTdGeL1XN5LK7f\r
+ nMnswOyxc9Zddo9b91+zezxbdYs5gDmKyyYlNSezLLVI3y6BK+PeiUb2gpt6FY+v3WVsYLyi\r
+ 3MXIySEhYCKx9PYtRghbTOLCvfVsXYxcHEIC+xglFv5ewwjhbGCU6Niwkh3COckk0dO8lBXC\r
+ WcIocW3KeWaQfhYBVYndvy8xgdhsAhoS2/YvB5srIqAosfnkfjCbWcBMYuXU72A1wgLxEi3f\r
+ DoHFeQV0JO5/7IEaupxR4snZ7awQCUGJkzOfsEA0a0nc+PcSqJkDyJaWWP6PAyTMKRAmsXL9\r
+ AXYQW1RARWLKyW1sExiFZiHpnoWkexZC9wJG5lWMsim5Vbq5iZk5xanJusXJiXl5qUW6pnq5\r
+ mSV6qSmlmxhBoc7uorSD8edBpUOMAhyMSjy8L4X5/YVYE8uKK3MPMUpyMCmJ8ooCI0WILyk/\r
+ pTIjsTgjvqg0J7X4EKMEB7OSCG+MLlCONyWxsiq1KB8mJc3BoiTOq671zk9IID2xJDU7NbUg\r
+ tQgmK8PBoSTBuyAMqFGwKDU9tSItM6cEIc3EwQkynAdo+E2QGt7igsTc4sx0iPwpRkUpcd6X\r
+ IAkBkERGaR5cLywVvWIUB3pFmPcGSBUPMI3Bdb8CGswENLgshQ9kcEkiQkqqgdEl8x+/XuSh\r
+ DYfPti7hzij/0mienrlst+xhk+Uhb9csNNi6qv7ra+8uzVK5dv4MB+fPp8pSbnIr6ngvXe9t\r
+ eUK2eFqX3qEXt7nK/e6+tOjvlRP/q528wOzOI+MQHTXOCcYrbMItqg+UBn1umWXk+OzLeyap\r
+ Pc6BKTJu2wUEfm2ev6Pu8sOueUosxRmJhlrMRcWJAALDZKEgAwAA\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: Thu, 12 Jan 2012 21:59:06 -0000\r
+\r
+LGTM. One thing you could fix below (and a few comments), but not\r
+enough alone to warrant a new version.\r
+\r
+Quoth Jani Nikula on Jan 12 at 11:40 pm:\r
+> Slightly refactor "notmuch reply" recipient and user from address scanning\r
+> functions in preparation for reply-to-sender feature.\r
+> \r
+> Add support for not adding messages at all (just scan for user from\r
+> address), and returning the number of messages added.\r
+> \r
+> No externally visible functional changes.\r
+> \r
+> Signed-off-by: Jani Nikula <jani@nikula.org>\r
+> ---\r
+> notmuch-reply.c | 74 ++++++++++++++++++++++++++++--------------------------\r
+> 1 files changed, 38 insertions(+), 36 deletions(-)\r
+> \r
+> diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+> index 000f6da..4fae66f 100644\r
+> --- a/notmuch-reply.c\r
+> +++ b/notmuch-reply.c\r
+> @@ -168,22 +168,28 @@ address_is_users (const char *address, notmuch_config_t *config)\r
+> return 0;\r
+> }\r
+> \r
+> -/* For each address in 'list' that is not configured as one of the\r
+> - * user's addresses in 'config', add that address to 'message' as an\r
+> - * address of 'type'.\r
+> +/* Scan addresses in 'list'.\r
+> *\r
+> - * The first address encountered that *is* the user's address will be\r
+> - * returned, (otherwise NULL is returned).\r
+> + * If 'message' is non-NULL, then for each address in 'list' that is not\r
+> + * configured as one of the user's addresses in 'config', add that address to\r
+> + * 'message' as an address of 'type'.\r
+> + *\r
+> + * If 'user_from' is non-NULL and *user_from is NULL, the first address\r
+> + * encountered in 'list' that *is* the user's address will be set to *user_from.\r
+> + *\r
+> + * Return the number of addresses added to 'message'. (If 'message' is NULL, the\r
+> + * function returns 0 by definition.)\r
+\r
+Ah, I like the return value. Better than adding an umpteenth argument\r
+like I was suggesting.\r
+\r
+> */\r
+> -static const char *\r
+> -add_recipients_for_address_list (GMimeMessage *message,\r
+> - notmuch_config_t *config,\r
+> - GMimeRecipientType type,\r
+> - InternetAddressList *list)\r
+> +static unsigned int\r
+> +scan_address_list (InternetAddressList *list,\r
+> + notmuch_config_t *config,\r
+> + GMimeMessage *message,\r
+> + GMimeRecipientType type,\r
+> + const char **user_from)\r
+> {\r
+> InternetAddress *address;\r
+> int i;\r
+> - const char *ret = NULL;\r
+> + unsigned int n = 0;\r
+> \r
+> for (i = 0; i < internet_address_list_length (list); i++) {\r
+> address = internet_address_list_get_address (list, i);\r
+> @@ -196,8 +202,7 @@ add_recipients_for_address_list (GMimeMessage *message,\r
+> if (group_list == NULL)\r
+> continue;\r
+> \r
+> - add_recipients_for_address_list (message, config,\r
+> - type, group_list);\r
+> + n += scan_address_list (group_list, config, message, type, NULL);\r
+\r
+Should the NULL above be user_from? You're being compatible with the\r
+original code, which is the right thing to do in this patch, but the\r
+new-found explicitness made me wonder if this is actually a bug.\r
+\r
+> } else {\r
+> InternetAddressMailbox *mailbox;\r
+> const char *name;\r
+> @@ -209,40 +214,40 @@ add_recipients_for_address_list (GMimeMessage *message,\r
+> addr = internet_address_mailbox_get_addr (mailbox);\r
+> \r
+> if (address_is_users (addr, config)) {\r
+> - if (ret == NULL)\r
+> - ret = addr;\r
+> - } else {\r
+> + if (user_from && *user_from == NULL)\r
+> + *user_from = addr;\r
+> + } else if (message) {\r
+> g_mime_message_add_recipient (message, type, name, addr);\r
+> + n++;\r
+> }\r
+> }\r
+> }\r
+> \r
+> - return ret;\r
+> + return n;\r
+> }\r
+> \r
+> -/* For each address in 'recipients' that is not configured as one of\r
+> - * the user's addresses in 'config', add that address to 'message' as\r
+> - * an address of 'type'.\r
+> +/* Scan addresses in 'recipients'.\r
+> *\r
+> - * The first address encountered that *is* the user's address will be\r
+> - * returned, (otherwise NULL is returned).\r
+> + * See the documentation of scan_address_list() above. This function does\r
+> + * exactly the same, but converts 'recipients' to an InternetAddressList first.\r
+\r
+Just bikeshedding, but comments in the notmuch codebase almost\r
+universally wrap at 72 columns, not 80 (based on \r
+egrep '[ /]\* .{70}' *.[ch]*)\r
+\r
+> */\r
+> -static const char *\r
+> -add_recipients_for_string (GMimeMessage *message,\r
+> - notmuch_config_t *config,\r
+> - GMimeRecipientType type,\r
+> - const char *recipients)\r
+> +static unsigned int\r
+> +scan_address_string (const char *recipients,\r
+> + notmuch_config_t *config,\r
+> + GMimeMessage *message,\r
+> + GMimeRecipientType type,\r
+> + const char **user_from)\r
+> {\r
+> InternetAddressList *list;\r
+> \r
+> if (recipients == NULL)\r
+> - return NULL;\r
+> + return 0;\r
+> \r
+> list = internet_address_list_parse_string (recipients);\r
+> if (list == NULL)\r
+> - return NULL;\r
+> + return 0;\r
+> \r
+> - return add_recipients_for_address_list (message, config, type, list);\r
+> + return scan_address_list (list, config, message, type, user_from);\r
+> }\r
+> \r
+> /* Does the address in the Reply-To header of 'message' already appear\r
+> @@ -324,7 +329,7 @@ add_recipients_from_message (GMimeMessage *reply,\r
+> }\r
+> \r
+> for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {\r
+> - const char *addr, *recipients;\r
+> + const char *recipients;\r
+> \r
+> recipients = notmuch_message_get_header (message,\r
+> reply_to_map[i].header);\r
+> @@ -332,11 +337,8 @@ add_recipients_from_message (GMimeMessage *reply,\r
+> recipients = notmuch_message_get_header (message,\r
+> reply_to_map[i].fallback);\r
+> \r
+> - addr = add_recipients_for_string (reply, config,\r
+> - reply_to_map[i].recipient_type,\r
+> - recipients);\r
+> - if (from_addr == NULL)\r
+> - from_addr = addr;\r
+> + scan_address_string (recipients, config, reply,\r
+> + reply_to_map[i].recipient_type, &from_addr);\r
+> }\r
+> \r
+> return from_addr;\r