--- /dev/null
+Return-Path: <bremner@tethera.net>\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 CF0C2429E25\r
+ for <notmuch@notmuchmail.org>; Sun, 11 Dec 2011 08:09:06 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_MED=-2.3] 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 LxrvtkzHCyyA for <notmuch@notmuchmail.org>;\r
+ Sun, 11 Dec 2011 08:09:06 -0800 (PST)\r
+Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 25609431FB6\r
+ for <notmuch@notmuchmail.org>; Sun, 11 Dec 2011 08:09:06 -0800 (PST)\r
+Received: from zancas.localnet\r
+ (fctnnbsc36w-156034079193.pppoe-dynamic.High-Speed.nb.bellaliant.net\r
+ [156.34.79.193]) (authenticated bits=0)\r
+ by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id pBBG91Mv019365\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO);\r
+ Sun, 11 Dec 2011 12:09:02 -0400\r
+Received: from bremner by zancas.localnet with local (Exim 4.77)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1RZlxV-0003g9-0W; Sun, 11 Dec 2011 12:09:01 -0400\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] cli: factor out config handling code to get/set lists.\r
+Date: Sun, 11 Dec 2011 12:07:51 -0400\r
+Message-Id: <1323619671-14111-1-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 1.7.7.3\r
+In-Reply-To: <87sjkstbiu.fsf@zancas.localnet>\r
+References: <87sjkstbiu.fsf@zancas.localnet>\r
+Cc: David Bremner <bremner@debian.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: Sun, 11 Dec 2011 16:09:06 -0000\r
+\r
+From: David Bremner <bremner@debian.org>\r
+\r
+Two new internal routines are created _config_get_list and\r
+_config_set_list; the notmuch_config_get_* functions that deal with\r
+lists are simply wrappers for these functions.\r
+---\r
+ notmuch-config.c | 130 +++++++++++++++++++++++++++--------------------------\r
+ 1 files changed, 66 insertions(+), 64 deletions(-)\r
+\r
+diff --git a/notmuch-config.c b/notmuch-config.c\r
+index 1a7ed58..e98b6a3 100644\r
+--- a/notmuch-config.c\r
++++ b/notmuch-config.c\r
+@@ -520,92 +520,94 @@ notmuch_config_set_user_primary_email (notmuch_config_t *config,\r
+ config->user_primary_email = NULL;\r
+ }\r
+ \r
+-const char **\r
+-notmuch_config_get_user_other_email (notmuch_config_t *config,\r
+- size_t *length)\r
++static const char **\r
++_config_get_list (notmuch_config_t *config,\r
++ const char *section, const char *key,\r
++ const char ***outlist, size_t *list_length, size_t *ret_length)\r
+ {\r
+- char **emails;\r
+- size_t emails_length;\r
++ char **inlist;\r
+ unsigned int i;\r
+ \r
+- if (config->user_other_email == NULL) {\r
+- emails = g_key_file_get_string_list (config->key_file,\r
+- "user", "other_email",\r
+- &emails_length, NULL);\r
+- if (emails) {\r
+- config->user_other_email = talloc_size (config,\r
+- sizeof (char *) *\r
+- (emails_length + 1));\r
+- for (i = 0; i < emails_length; i++)\r
+- config->user_other_email[i] = talloc_strdup (config->user_other_email,\r
+- emails[i]);\r
+- config->user_other_email[i] = NULL;\r
+-\r
+- g_strfreev (emails);\r
+-\r
+- config->user_other_email_length = emails_length;\r
++ if (*outlist == NULL) {\r
++ inlist = g_key_file_get_string_list (config->key_file,\r
++ section, key,\r
++ list_length, NULL);\r
++ if (inlist) {\r
++ *outlist = talloc_size (config, sizeof (char *) *\r
++ (*list_length + 1));\r
++ for (i = 0; i < *list_length; i++)\r
++ (*outlist)[i] = talloc_strdup (*outlist, inlist[i]);\r
++ (*outlist)[i] = NULL;\r
++\r
++ g_strfreev (inlist);\r
+ }\r
+ }\r
+ \r
+- *length = config->user_other_email_length;\r
+- return config->user_other_email;\r
++ if (ret_length) *ret_length = *list_length;\r
++ return *outlist;\r
+ }\r
+ \r
+-void\r
+-notmuch_config_set_user_other_email (notmuch_config_t *config,\r
+- const char *other_email[],\r
+- size_t length)\r
++const char **\r
++notmuch_config_get_user_other_email (notmuch_config_t *config, size_t *length)\r
+ {\r
+- g_key_file_set_string_list (config->key_file,\r
+- "user", "other_email",\r
+- other_email, length);\r
++ return _config_get_list (config, "user", "other_email",\r
++ &(config->user_other_email),\r
++ &(config->user_other_email_length), length);\r
++}\r
+ \r
+- talloc_free (config->user_other_email);\r
+- config->user_other_email = NULL;\r
++const char **\r
++notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length)\r
++{\r
++ return _config_get_list (config, "new", "tags",\r
++ &(config->new_tags),\r
++ &(config->new_tags_length), length);\r
+ }\r
+ \r
+ const char **\r
+-notmuch_config_get_new_tags (notmuch_config_t *config,\r
+- size_t *length)\r
++notmuch_config_get_log_subscribers (notmuch_config_t *config, size_t *length)\r
+ {\r
+- char **tags;\r
+- size_t tags_length;\r
+- unsigned int i;\r
++ return _config_get_list (config, "log", "subscribers",\r
++ &(config->new_tags),\r
++ &(config->new_tags_length), length);\r
++}\r
+ \r
+- if (config->new_tags == NULL) {\r
+- tags = g_key_file_get_string_list (config->key_file,\r
+- "new", "tags",\r
+- &tags_length, NULL);\r
+- if (tags) {\r
+- config->new_tags = talloc_size (config,\r
+- sizeof (char *) *\r
+- (tags_length + 1));\r
+- for (i = 0; i < tags_length; i++)\r
+- config->new_tags[i] = talloc_strdup (config->new_tags,\r
+- tags[i]);\r
+- config->new_tags[i] = NULL;\r
+-\r
+- g_strfreev (tags);\r
+-\r
+- config->new_tags_length = tags_length;\r
+- }\r
+- }\r
+ \r
+- *length = config->new_tags_length;\r
+- return config->new_tags;\r
++static void\r
++_config_set_list (notmuch_config_t *config,\r
++ const char *group, const char *name,\r
++ const char *list[],\r
++ size_t length, const char ***config_var )\r
++{\r
++ g_key_file_set_string_list (config->key_file, group, name, list, length);\r
++ talloc_free (*config_var);\r
++ *config_var = NULL;\r
++}\r
++\r
++void\r
++notmuch_config_set_user_other_email (notmuch_config_t *config,\r
++ const char *list[],\r
++ size_t length)\r
++{\r
++ _config_set_list (config, "user", "other_email", list, length,\r
++ &(config->user_other_email));\r
+ }\r
+ \r
+ void\r
+ notmuch_config_set_new_tags (notmuch_config_t *config,\r
+- const char *new_tags[],\r
+- size_t length)\r
++ const char *list[],\r
++ size_t length)\r
+ {\r
+- g_key_file_set_string_list (config->key_file,\r
+- "new", "tags",\r
+- new_tags, length);\r
++ _config_set_list (config, "new", "tags", list, length,\r
++ &(config->new_tags));\r
++}\r
+ \r
+- talloc_free (config->new_tags);\r
+- config->new_tags = NULL;\r
++void\r
++notmuch_config_set_log_subscribers (notmuch_config_t *config,\r
++ const char *list[],\r
++ size_t length)\r
++{\r
++ _config_set_list (config, "log", "subscribers", list, length,\r
++ &(config->log_subscribers));\r
+ }\r
+ \r
+ /* Given a configuration item of the form <group>.<key> return the\r
+-- \r
+1.7.7.3\r
+\r