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 8AD43431FC2 for ; Wed, 25 Nov 2009 15:30:26 -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 EJqQK++v6YOu for ; Wed, 25 Nov 2009 15:30:25 -0800 (PST) Received: from mail-ew0-f213.google.com (mail-ew0-f213.google.com [209.85.219.213]) by olra.theworths.org (Postfix) with ESMTP id 710D3431FC0 for ; Wed, 25 Nov 2009 15:30:24 -0800 (PST) Received: by ewy5 with SMTP id 5so257222ewy.30 for ; Wed, 25 Nov 2009 15:30:23 -0800 (PST) Received: by 10.213.0.144 with SMTP id 16mr1690605ebb.38.1259191823446; Wed, 25 Nov 2009 15:30:23 -0800 (PST) Received: from x61s.janakj ([213.192.30.141]) by mx.google.com with ESMTPS id 28sm333998eyg.36.2009.11.25.15.30.18 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 25 Nov 2009 15:30:22 -0800 (PST) Received: by x61s.janakj (Postfix, from userid 1000) id AEC83440374; Thu, 26 Nov 2009 00:30:16 +0100 (CET) From: Jan Janak To: notmuch@notmuchmail.org Date: Thu, 26 Nov 2009 00:30:13 +0100 Message-Id: <1259191816-1982-2-git-send-email-jan@ryngle.com> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1259191816-1982-1-git-send-email-jan@ryngle.com> References: <1259100630-13673-1-git-send-email-jan@ryngle.com> <1259191816-1982-1-git-send-email-jan@ryngle.com> Subject: [notmuch] [PATCH 2/5] notmuch: Config option to specify tags to be applied by '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: Wed, 25 Nov 2009 23:30:26 -0000 Add support for section [new] in the configuration file. This section is supposed to contain options for 'notmuch new'. Currently there is only one option called tags. The tags option can be used to configure a set of tags to be applied by 'notmuch new'. Individual tags are separated by semicolon. 'notmuch new' is modified not to apply 'inbox' and 'unread' by default, but instead it obtains the set of tags to be applied from the new configuration file option. Signed-off-by: Jan Janak This revision of the patch includes suggestions from Bart Trojanowski. --- notmuch-client.h | 3 +++ notmuch-config.c | 43 +++++++++++++++++++++++++++++++++++++++++++ notmuch-new.c | 19 ++++++++++++++++++- 3 files changed, 64 insertions(+), 1 deletions(-) diff --git a/notmuch-client.h b/notmuch-client.h index c04eaeb..0fb9c19 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -184,6 +184,9 @@ notmuch_config_set_user_other_email (notmuch_config_t *config, const char *other_email[], size_t length); +char ** +notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length); + notmuch_bool_t debugger_is_active (void); diff --git a/notmuch-config.c b/notmuch-config.c index fc65d6b..57072ce 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -22,6 +22,7 @@ #include #include +#include static const char toplevel_config_comment[] = " .notmuch-config - Configuration file for the notmuch mail system\n" @@ -62,6 +63,9 @@ struct _notmuch_config { char *user_primary_email; char **user_other_email; size_t user_other_email_length; + + char **new_tags; + size_t new_tags_length; }; static int @@ -199,6 +203,8 @@ notmuch_config_open (void *ctx, config->user_primary_email = NULL; config->user_other_email = NULL; config->user_other_email_length = 0; + config->new_tags = NULL; + config->new_tags_length = 0; if (! g_key_file_load_from_file (config->key_file, config->filename, @@ -450,3 +456,40 @@ notmuch_config_set_user_other_email (notmuch_config_t *config, talloc_free (config->user_other_email); config->user_other_email = NULL; } + +char ** +notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length) +{ + char **tags; + size_t i, len; + char *start, *end; + + if (config->new_tags == NULL) { + config->new_tags_length = 0; + tags = g_key_file_get_string_list (config->key_file, "new", "tags", + &len, NULL); + + if (tags) { + config->new_tags = talloc_size (config, sizeof(char*) * + (len + 1)); + for (i = 0; i < len; i++) { + /* Remove leading and trailing white space around the tag and + * filter out empty tags. */ + start = tags[i]; + end = start + strlen (start) - 1; + while (isspace (*start)) start++; + while (end > start && isspace (*end)) end--; + if (end >= start) { + config->new_tags[config->new_tags_length++] = + talloc_strndup (config->new_tags, start, + end - start + 1); + } + } + config->new_tags[config->new_tags_length] = NULL; + g_strfreev (tags); + } + } + + *length = config->new_tags_length; + return config->new_tags; +} diff --git a/notmuch-new.c b/notmuch-new.c index 9970407..af717b7 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -24,6 +24,8 @@ static volatile sig_atomic_t do_add_files_print_progress = 0; +static notmuch_config_t *config = NULL; + static void handle_sigalrm (unused (int signal)) { @@ -68,6 +70,21 @@ add_files_print_progress (add_files_state_t *state) fflush (stdout); } +static void +apply_tags (notmuch_message_t *message) +{ + char** tags; + size_t count, i; + + if ((tags = notmuch_config_get_new_tags (config, &count)) == NULL) + return; + + for (i = 0; i < count; i++) { + if (tags[i]) + notmuch_message_add_tag (message, tags[i]); + } +} + static int ino_cmp(const struct dirent **a, const struct dirent **b) { return ((*a)->d_ino < (*b)->d_ino) ? -1 : 1; @@ -191,6 +208,7 @@ add_files_recursive (notmuch_database_t *notmuch, /* success */ case NOTMUCH_STATUS_SUCCESS: state->added_messages++; + apply_tags (message); break; /* Non-fatal issues (go on to next file) */ case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: @@ -388,7 +406,6 @@ count_files (const char *path, int *count) int notmuch_new_command (void *ctx, int argc, char *argv[]) { - notmuch_config_t *config; notmuch_database_t *notmuch; add_files_state_t add_files_state; double elapsed; -- 1.6.3.3