--- /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 AADE5431FC2\r
+ for <notmuch@notmuchmail.org>; Fri, 11 May 2012 07:33:11 -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 MG+GfKjqnVDV for <notmuch@notmuchmail.org>;\r
+ Fri, 11 May 2012 07:33:11 -0700 (PDT)\r
+Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com\r
+ [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id D8F01431FAE\r
+ for <notmuch@notmuchmail.org>; Fri, 11 May 2012 07:33:10 -0700 (PDT)\r
+Received: by lbbgk8 with SMTP id gk8so2103376lbb.26\r
+ for <notmuch@notmuchmail.org>; Fri, 11 May 2012 07:33:09 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=google.com; s=20120113;\r
+ h=from:to:subject:date:message-id:x-mailer:x-gm-message-state;\r
+ bh=M2f2d5cmAPw4V4gj0YK3vSVhSNrLGgKTEfzeTx+q9Eg=;\r
+ b=V8q+6g/Uik4CQwtaCnJJ9sR28ipd5JkP9n/U210+c2snAm0RzgcRdNVOVxiN38Hdz6\r
+ /BYqiVp0L7uEtBPj6NkwA1I+EV45Yns17pw8/ode9GdiupZrrt5veQfsETJJobq/5Thv\r
+ avHYUU0+n0ehia0x7Y2CdJMAWS5JIFY6k5dhVJTlByZxXB8t+NOlNQXy60i8s4b3tryD\r
+ q/5yHqHKGKIVTA0FG9AonbSl1m1EF8TcqojjgnSGPgiv2xr+85hB+1F4PL3aDbKgVU8a\r
+ lqegBJs+IfDUJR5QB55c9ftg9AS4nNa6TnpAofG/UqC41KOAQwleQIpTQ0W+X1RlHDKg\r
+ Bjlw==\r
+Received: by 10.112.47.161 with SMTP id e1mr1913440lbn.42.1336746789256;\r
+ Fri, 11 May 2012 07:33:09 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw4-fe50dc00-68.dhcp.inet.fi.\r
+ [80.220.80.68])\r
+ by mx.google.com with ESMTPS id pb13sm9590340lab.16.2012.05.11.07.33.07\r
+ (version=SSLv3 cipher=OTHER); Fri, 11 May 2012 07:33:08 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/2] cli: add user address matching helpers for notmuch reply\r
+Date: Fri, 11 May 2012 17:33:04 +0300\r
+Message-Id:\r
+ <bae496e6100a4e4d4a598dcf5c73d67b178f4128.1336746187.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.9.5\r
+X-Gm-Message-State:\r
+ ALoCoQnRNmuvxBP3pSN8oQ7osmZ/MqoMGaSLF7eHMwdAgCVGtQw3fjOBYE+8rx6BepcrAheO9ZG/\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: Fri, 11 May 2012 14:33:11 -0000\r
+\r
+Add a multi-purpose address_match() function for matching strings\r
+against user's configured primary and other email addresses. Add thin\r
+wrappers user_address_in_string() and string_in_user_address() for\r
+ease of use, and also convert existing address_is_users() to wrapper\r
+for the same.\r
+\r
+No functional changes.\r
+\r
+Signed-off-by: Jani Nikula <jani@nikula.org>\r
+---\r
+ notmuch-reply.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++--------\r
+ 1 file changed, 62 insertions(+), 10 deletions(-)\r
+\r
+diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+index 7184a5d..0c82755 100644\r
+--- a/notmuch-reply.c\r
++++ b/notmuch-reply.c\r
+@@ -98,25 +98,77 @@ format_part_reply (mime_node_t *node)\r
+ format_part_reply (mime_node_child (node, i));\r
+ }\r
+ \r
+-/* Is the given address configured as one of the user's "personal" or\r
+- * "other" addresses. */\r
+-static int\r
+-address_is_users (const char *address, notmuch_config_t *config)\r
++typedef enum {\r
++ USER_ADDRESS_IN_STRING,\r
++ STRING_IN_USER_ADDRESS,\r
++ STRING_IS_USER_ADDRESS,\r
++} address_match_t;\r
++\r
++/* Match given string against given address according to mode. */\r
++static notmuch_bool_t\r
++match_address (const char *str, const char *address, address_match_t mode)\r
++{\r
++ switch (mode) {\r
++ case USER_ADDRESS_IN_STRING:\r
++ return strcasestr (str, address) != NULL;\r
++ case STRING_IN_USER_ADDRESS:\r
++ return strcasestr (address, str) != NULL;\r
++ case STRING_IS_USER_ADDRESS:\r
++ return strcasecmp (address, str) == 0;\r
++ }\r
++\r
++ return FALSE;\r
++}\r
++\r
++/* Match given string against user's configured "primary" and "other"\r
++ * addresses according to mode. */\r
++static const char *\r
++address_match (const char *str, notmuch_config_t *config, address_match_t mode)\r
+ {\r
+ const char *primary;\r
+ const char **other;\r
+ size_t i, other_len;\r
+ \r
++ if (!str || *str == '\0')\r
++ return NULL;\r
++\r
+ primary = notmuch_config_get_user_primary_email (config);\r
+- if (strcasecmp (primary, address) == 0)\r
+- return 1;\r
++ if (match_address (str, primary, mode))\r
++ return primary;\r
+ \r
+ other = notmuch_config_get_user_other_email (config, &other_len);\r
+- for (i = 0; i < other_len; i++)\r
+- if (strcasecmp (other[i], address) == 0)\r
+- return 1;\r
++ for (i = 0; i < other_len; i++) {\r
++ if (match_address (str, other[i], mode))\r
++ return other[i];\r
++ }\r
+ \r
+- return 0;\r
++ return NULL;\r
++}\r
++\r
++/* Does the given string contain an address configured as one of the\r
++ * user's "primary" or "other" addresses. If so, return the matching\r
++ * address, NULL otherwise. */\r
++static const char *\r
++user_address_in_string (const char *str, notmuch_config_t *config)\r
++{\r
++ return address_match (str, config, USER_ADDRESS_IN_STRING);\r
++}\r
++\r
++/* Do any of the addresses configured as one of the user's "primary"\r
++ * or "other" addresses contain the given string. If so, return the\r
++ * matching address, NULL otherwise. */\r
++static const char *\r
++string_in_user_address (const char *str, notmuch_config_t *config)\r
++{\r
++ return address_match (str, config, STRING_IN_USER_ADDRESS);\r
++}\r
++\r
++/* Is the given address configured as one of the user's "primary" or\r
++ * "other" addresses. */\r
++static notmuch_bool_t\r
++address_is_users (const char *address, notmuch_config_t *config)\r
++{\r
++ return address_match (address, config, STRING_IS_USER_ADDRESS) != NULL;\r
+ }\r
+ \r
+ /* Scan addresses in 'list'.\r
+-- \r
+1.7.9.5\r
+\r