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