--- /dev/null
+Return-Path: <jan@ryngle.com>\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 568A6431FAE\r
+ for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 14:10:36 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\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 Amkgx8SNvhKo for <notmuch@notmuchmail.org>;\r
+ Tue, 24 Nov 2009 14:10:35 -0800 (PST)\r
+Received: from mail-fx0-f214.google.com (mail-fx0-f214.google.com\r
+ [209.85.220.214])\r
+ by olra.theworths.org (Postfix) with ESMTP id A4BA7431FBC\r
+ for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 14:10:34 -0800 (PST)\r
+Received: by fxm6 with SMTP id 6so7397332fxm.0\r
+ for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 14:10:33 -0800 (PST)\r
+Received: by 10.103.125.23 with SMTP id c23mr2961077mun.41.1259100633482;\r
+ Tue, 24 Nov 2009 14:10:33 -0800 (PST)\r
+Received: from x61s.janakj (r2c34.net.upc.cz [62.245.66.34])\r
+ by mx.google.com with ESMTPS id 23sm740148mun.41.2009.11.24.14.10.31\r
+ (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
+ Tue, 24 Nov 2009 14:10:32 -0800 (PST)\r
+Received: by x61s.janakj (Postfix, from userid 1000)\r
+ id B8CF7440659; Tue, 24 Nov 2009 23:10:30 +0100 (CET)\r
+From: Jan Janak <jan@ryngle.com>\r
+To: notmuch@notmuchmail.org\r
+Date: Tue, 24 Nov 2009 23:10:29 +0100\r
+Message-Id: <1259100630-13673-4-git-send-email-jan@ryngle.com>\r
+X-Mailer: git-send-email 1.6.3.3\r
+In-Reply-To: <1259100630-13673-3-git-send-email-jan@ryngle.com>\r
+References: <1259100630-13673-1-git-send-email-jan@ryngle.com>\r
+ <1259100630-13673-2-git-send-email-jan@ryngle.com>\r
+ <1259100630-13673-3-git-send-email-jan@ryngle.com>\r
+Subject: [notmuch] [PATCH 3/4] notmuch-setup: Copy/create the new section\r
+ with tags for 'notmuch-new'.\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.12\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: Tue, 24 Nov 2009 22:10:36 -0000\r
+\r
+If the user runs 'notmuch setup' and there is no configuration file yet\r
+then we also add the new section [new] to the configuration file and\r
+set the tags option as:\r
+\r
+ tags=inbox;unread\r
+\r
+This will be picked up by 'notmuch new' and all new mail added to the\r
+database will be tagged with the two tags as before.\r
+\r
+If the user already has a configuration file and runs 'notmuch setup'\r
+then we just copy whatever tags we find in the old configuration file\r
+to the new one. If there are no tags in the old configuration file then\r
+we assume that the user configured notmuch that way and the new config\r
+file would also have no tags in the section [new].\r
+\r
+We never ask the user interactively for the list of tags to be used by\r
+'notmuch new', it is assumed that beginners would want to stick to the\r
+defaults and advanced users can edit the configuration manually.\r
+\r
+Signed-off-by: Jan Janak <jan@ryngle.com>\r
+---\r
+ notmuch-client.h | 4 ++++\r
+ notmuch-config.c | 40 ++++++++++++++++++++++++++++++++++++++++\r
+ notmuch-setup.c | 14 ++++++++++++++\r
+ 3 files changed, 58 insertions(+), 0 deletions(-)\r
+\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index 0fb9c19..bb7d3d4 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -187,6 +187,10 @@ notmuch_config_set_user_other_email (notmuch_config_t *config,\r
+ char **\r
+ notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length);\r
+ \r
++void\r
++notmuch_config_set_new_tags (notmuch_config_t *config, const char *tags[],\r
++ size_t length);\r
++\r
+ notmuch_bool_t\r
+ debugger_is_active (void);\r
+ \r
+diff --git a/notmuch-config.c b/notmuch-config.c\r
+index 7f62a80..e884621 100644\r
+--- a/notmuch-config.c\r
++++ b/notmuch-config.c\r
+@@ -54,6 +54,16 @@ static const char user_config_comment[] =\r
+ " recipient list of replies, and will set the From address based on the\n"\r
+ " address to which the original email was addressed.\n";\r
+ \r
++static const char new_config_comment[] =\r
++ " Configuration section for 'notmuch new'\n"\r
++ "\n"\r
++ " The only supported value at the moment is 'tags. This option contains a\n"\r
++ " list of tags (separated by ';') that should be automatically applied to\n"\r
++ " newly added messages.\n"\r
++ "\n"\r
++ " Note that 'notmuch new' also has a command line option which can be used\n"\r
++ " to add additional tags to the ones configured here.\n";\r
++\r
+ struct _notmuch_config {\r
+ char *filename;\r
+ GKeyFile *key_file;\r
+@@ -174,6 +184,7 @@ notmuch_config_open (void *ctx,\r
+ GError *error = NULL;\r
+ int is_new = 0;\r
+ char *notmuch_config_env = NULL;\r
++ const char* def_new_tags[2] = {"inbox", "unread"};\r
+ \r
+ if (is_new_ret)\r
+ *is_new_ret = 0;\r
+@@ -270,6 +281,20 @@ notmuch_config_open (void *ctx,\r
+ }\r
+ }\r
+ \r
++ /* If we have no configuration file then we configure "inbox" and "unread"\r
++ * tags by default for 'notmuch new'. This ensures that the Emacs mode\r
++ * would still work as expected.\r
++ *\r
++ * We do not ask the user for tags to be used by 'notmuch new'. That's too\r
++ * much detail for beginners and others can edit the configuration file by\r
++ * hand.\r
++ */\r
++ if (is_new) {\r
++ notmuch_config_set_new_tags (config, def_new_tags,\r
++ sizeof(def_new_tags) /\r
++ sizeof(const char*));\r
++ }\r
++\r
+ /* When we create a new configuration file here, we add some\r
+ * comments to help the user understand what can be done. */\r
+ if (is_new) {\r
+@@ -279,6 +304,8 @@ notmuch_config_open (void *ctx,\r
+ database_config_comment, NULL);\r
+ g_key_file_set_comment (config->key_file, "user", NULL,\r
+ user_config_comment, NULL);\r
++ g_key_file_set_comment (config->key_file, "new", NULL,\r
++ new_config_comment, NULL);\r
+ }\r
+ \r
+ if (is_new_ret)\r
+@@ -494,3 +521,16 @@ notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length)\r
+ *length = config->new_tags_length;\r
+ return config->new_tags;\r
+ }\r
++\r
++void\r
++notmuch_config_set_new_tags (notmuch_config_t *config,\r
++ const char *tags[],\r
++ size_t length)\r
++{\r
++ g_key_file_set_string_list (config->key_file,\r
++ "new", "tags",\r
++ tags, length);\r
++\r
++ talloc_free (config->new_tags);\r
++ config->user_other_email = NULL;\r
++}\r
+diff --git a/notmuch-setup.c b/notmuch-setup.c\r
+index d06fbf8..c1406db 100644\r
+--- a/notmuch-setup.c\r
++++ b/notmuch-setup.c\r
+@@ -96,6 +96,8 @@ notmuch_setup_command (unused (void *ctx),\r
+ notmuch_config_t *config;\r
+ char **old_other_emails;\r
+ size_t old_other_emails_len;\r
++ char **new_tags;\r
++ unsigned int new_tags_len;\r
+ GPtrArray *other_emails;\r
+ unsigned int i;\r
+ int is_new;\r
+@@ -147,6 +149,18 @@ notmuch_setup_command (unused (void *ctx),\r
+ other_emails->len);\r
+ g_ptr_array_free (other_emails, TRUE);\r
+ \r
++ /* If we already have a configuration file then we preserve the tags\r
++ * configured there. If the original configuration file contains no tags\r
++ * then we assume that the user configured it that way and add no tags.\r
++ */\r
++ if (!is_new) {\r
++ new_tags = notmuch_config_get_new_tags (config, &new_tags_len);\r
++ if (new_tags) {\r
++ notmuch_config_set_new_tags (config, (const char**)new_tags,\r
++ new_tags_len);\r
++ }\r
++ }\r
++\r
+ prompt ("Top-level directory of your email archive [%s]: ",\r
+ notmuch_config_get_database_path (config));\r
+ if (strlen (response)) {\r
+-- \r
+1.6.3.3\r
+\r