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 8EABB429E34 for ; Fri, 2 May 2014 05:15:07 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0.379 X-Spam-Level: X-Spam-Status: No, score=0.379 tagged_above=-999 required=5 tests=[NO_DNS_FOR_FROM=0.379] autolearn=disabled 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 Bg4jBL8POnFQ for ; Fri, 2 May 2014 05:15:06 -0700 (PDT) Received: from disaster-area.hh.sledj.net (disaster-area.hh.sledj.net [81.149.164.25]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id AAAAF431FD6 for ; Fri, 2 May 2014 05:14:59 -0700 (PDT) Received: from hotblack-desiato.hh.sledj.net (hotblack-desiato.hh.sledj.net [172.16.100.105]) by disaster-area.hh.sledj.net (Postfix) with ESMTPSA id 10F1E5012F1; Fri, 2 May 2014 13:14:57 +0100 (BST) Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000) id A713910345B; Fri, 2 May 2014 13:14:56 +0100 (BST) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH 1/5] notmuch-new: Use tag_op_list_apply() rather than hand-coding the same. Date: Fri, 2 May 2014 13:14:43 +0100 Message-Id: <1399032887-25896-1-git-send-email-dme@dme.org> X-Mailer: git-send-email 1.9.2 In-Reply-To: References: X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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: Fri, 02 May 2014 12:15:07 -0000 Rather than hand-coding the application of tags to new messages, use the existing tag_op_list_apply(). fixup. --- notmuch-new.c | 31 ++++++++++++++++--------------- tag-util.c | 8 ++++++++ tag-util.h | 10 +++++++--- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index d269c7c..2c3d680 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -45,10 +45,9 @@ typedef struct { int output_is_a_tty; enum verbosity verbosity; notmuch_bool_t debug; - const char **new_tags; - size_t new_tags_length; const char **new_ignore; size_t new_ignore_length; + tag_op_list_t *tag_ops; int total_files; int processed_files; @@ -253,7 +252,6 @@ add_file (notmuch_database_t *notmuch, const char *filename, add_files_state_t *state) { notmuch_message_t *message = NULL; - const char **tag; notmuch_status_t status; status = notmuch_database_begin_atomic (notmuch); @@ -263,14 +261,13 @@ add_file (notmuch_database_t *notmuch, const char *filename, status = notmuch_database_add_message (notmuch, filename, &message); switch (status) { /* Success. */ - case NOTMUCH_STATUS_SUCCESS: - state->added_messages++; - notmuch_message_freeze (message); - for (tag = state->new_tags; *tag != NULL; tag++) - notmuch_message_add_tag (message, *tag); + case NOTMUCH_STATUS_SUCCESS:; + tag_op_flag_t flags = 0; + if (state->synchronize_flags) - notmuch_message_maildir_flags_to_tags (message); - notmuch_message_thaw (message); + flags |= TAG_FLAG_TAG_SYNC; + state->added_messages++; + (void) tag_op_list_apply (message, state->tag_ops, flags); break; /* Non-fatal issues (go on to next file). */ case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: @@ -923,6 +920,8 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) notmuch_bool_t timer_is_active = FALSE; notmuch_bool_t no_hooks = FALSE; notmuch_bool_t quiet = FALSE, verbose = FALSE; + const char **new_tags; + size_t new_tags_length; add_files_state.verbosity = VERBOSITY_NORMAL; add_files_state.debug = FALSE; @@ -946,20 +945,22 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) else if (verbose) add_files_state.verbosity = VERBOSITY_VERBOSE; - add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length); + new_tags = notmuch_config_get_new_tags (config, &new_tags_length); add_files_state.new_ignore = notmuch_config_get_new_ignore (config, &add_files_state.new_ignore_length); add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config); + add_files_state.tag_ops = tag_op_list_create (config); db_path = notmuch_config_get_database_path (config); - for (i = 0; i < add_files_state.new_tags_length; i++) { + for (i = 0; i < new_tags_length; i++) { const char *error_msg; - error_msg = illegal_tag (add_files_state.new_tags[i], FALSE); + error_msg = illegal_tag (new_tags[i], FALSE); if (error_msg) { - fprintf (stderr, "Error: tag '%s' in new.tags: %s\n", - add_files_state.new_tags[i], error_msg); + fprintf (stderr, "Error: tag '%s' in new.tags: %s\n", new_tags[i], error_msg); return EXIT_FAILURE; } + if (tag_op_list_append (add_files_state.tag_ops, new_tags[i], FALSE) != 0) + return EXIT_FAILURE; } if (!no_hooks) { diff --git a/tag-util.c b/tag-util.c index 343c161..1dee2f3 100644 --- a/tag-util.c +++ b/tag-util.c @@ -327,6 +327,14 @@ tag_op_list_apply (notmuch_message_t *message, } } + if (flags & TAG_FLAG_TAG_SYNC) { + status = notmuch_message_maildir_flags_to_tags (message); + if (status) { + message_error (message, status, "synching maildir to tags"); + return status; + } + } + return NOTMUCH_STATUS_SUCCESS; } diff --git a/tag-util.h b/tag-util.h index 8a4074c..512cfac 100644 --- a/tag-util.h +++ b/tag-util.h @@ -14,19 +14,23 @@ typedef enum { */ TAG_FLAG_MAILDIR_SYNC = (1 << 0), + /* Operations are synced from maildir, if possible. + */ + TAG_FLAG_TAG_SYNC = (1 << 1), + /* Remove all tags from message before applying list. */ - TAG_FLAG_REMOVE_ALL = (1 << 1), + TAG_FLAG_REMOVE_ALL = (1 << 2), /* Don't try to avoid database operations. Useful when we * know that message passed needs these operations. */ - TAG_FLAG_PRE_OPTIMIZED = (1 << 2), + TAG_FLAG_PRE_OPTIMIZED = (1 << 3), /* Accept strange tags that might be user error; * intended for use by notmuch-restore. */ - TAG_FLAG_BE_GENEROUS = (1 << 3) + TAG_FLAG_BE_GENEROUS = (1 << 4) } tag_op_flag_t; -- 1.9.2