From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id F165B431FC3 for ; Tue, 24 Nov 2009 14:10:34 -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 zap7gjCqN2Lq for ; Tue, 24 Nov 2009 14:10:34 -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 E631A431FBF for ; Tue, 24 Nov 2009 14:10:33 -0800 (PST) Received: by fxm6 with SMTP id 6so7397321fxm.0 for ; Tue, 24 Nov 2009 14:10:33 -0800 (PST) Received: by 10.103.81.12 with SMTP id i12mr3003622mul.37.1259100633033; 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 23sm740146mun.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 AB8E4440657; Tue, 24 Nov 2009 23:10:30 +0100 (CET) From: Jan Janak To: notmuch@notmuchmail.org Date: Tue, 24 Nov 2009 23:10:28 +0100 Message-Id: <1259100630-13673-3-git-send-email-jan@ryngle.com> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1259100630-13673-2-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> Subject: [PATCH 2/4] 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: Tue, 24 Nov 2009 22:10:35 -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 --- notmuch-client.h | 3 +++ notmuch-config.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ notmuch-new.c | 19 ++++++++++++++++++- 3 files changed, 65 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..7f62a80 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,41 @@ 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 len; + unsigned int i; + 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..10745e8 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; + unsigned int 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