--- /dev/null
+Return-Path: <jani@nikula.org>\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 8D990421167\r
+ for <notmuch@notmuchmail.org>; Sat, 14 Jan 2012 06:46:39 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\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 5sJjWHjz2tsI for <notmuch@notmuchmail.org>;\r
+ Sat, 14 Jan 2012 06:46:35 -0800 (PST)\r
+Received: from mail-ey0-f181.google.com (mail-ey0-f181.google.com\r
+ [209.85.215.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id ECE6C429E4E\r
+ for <notmuch@notmuchmail.org>; Sat, 14 Jan 2012 06:46:28 -0800 (PST)\r
+Received: by eaah10 with SMTP id h10so716669eaa.26\r
+ for <notmuch@notmuchmail.org>; Sat, 14 Jan 2012 06:46:27 -0800 (PST)\r
+Received: by 10.213.11.12 with SMTP id r12mr752498ebr.87.1326552387256;\r
+ Sat, 14 Jan 2012 06:46:27 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
+ [80.220.92.23])\r
+ by mx.google.com with ESMTPS id y12sm44609338eeb.11.2012.01.14.06.46.25\r
+ (version=SSLv3 cipher=OTHER); Sat, 14 Jan 2012 06:46:26 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v5 1/5] cli: slightly refactor "notmuch reply" address\r
+ scanning functions\r
+Date: Sat, 14 Jan 2012 16:46:15 +0200\r
+Message-Id:\r
+ <f994789d065d898911bbf127a7453137a9ba8e27.1326551350.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <cover.1326551350.git.jani@nikula.org>\r
+References: <cover.1326551350.git.jani@nikula.org>\r
+In-Reply-To: <cover.1326551350.git.jani@nikula.org>\r
+References: <cover.1325794371.git.jani@nikula.org>\r
+ <cover.1326551350.git.jani@nikula.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, 14 Jan 2012 14:46:40 -0000\r
+\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 recipients at all (just scan for user from\r
+address), and returning the number of recipients added.\r
+\r
+No externally visible functional changes.\r
+\r
+Signed-off-by: Jani Nikula <jani@nikula.org>\r
+---\r
+ notmuch-reply.c | 76 +++++++++++++++++++++++++++++--------------------------\r
+ 1 files changed, 40 insertions(+), 36 deletions(-)\r
+\r
+diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+index 000f6da..a8d6a94 100644\r
+--- a/notmuch-reply.c\r
++++ b/notmuch-reply.c\r
+@@ -168,22 +168,29 @@ 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\r
++ * not configured as one of the user's addresses in 'config', add that\r
++ * address to 'message' as an address of 'type'.\r
++ *\r
++ * If 'user_from' is non-NULL and *user_from is NULL, *user_from will\r
++ * be set to the first address encountered in 'list' that is the\r
++ * user's address.\r
++ *\r
++ * Return the number of addresses added to 'message'. (If 'message' is\r
++ * NULL, the function returns 0 by definition.)\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 +203,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
+ } else {\r
+ InternetAddressMailbox *mailbox;\r
+ const char *name;\r
+@@ -209,40 +215,41 @@ 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\r
++ * does exactly the same, but converts 'recipients' to an\r
++ * InternetAddressList first.\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 +331,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 +339,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
+-- \r
+1.7.5.4\r
+\r