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 0657540D14C for ; Mon, 11 Oct 2010 06:27:50 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -2.6 X-Spam-Level: X-Spam-Status: No, score=-2.6 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7] autolearn=ham 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 pFpojjWdI5Y9 for ; Mon, 11 Oct 2010 06:27:36 -0700 (PDT) Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21]) by olra.theworths.org (Postfix) with ESMTP id 753FA40BFDE for ; Mon, 11 Oct 2010 06:27:19 -0700 (PDT) Received: from rocinante.cs.unb.ca (fctnnbsc30w-142167176217.pppoe-dynamic.High-Speed.nb.bellaliant.net [142.167.176.217]) (authenticated bits=0) by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id o9BDRIBb003871 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO); Mon, 11 Oct 2010 10:27:18 -0300 Received: from bremner by rocinante.cs.unb.ca with local (Exim 4.72) (envelope-from ) id 1P5IPO-0004cf-Kz; Mon, 11 Oct 2010 10:27:18 -0300 From: david@tethera.net To: notmuch@notmuchmail.org Subject: [PATCH 3/3] notmuch-tag.c: Add tag logging. Date: Mon, 11 Oct 2010 10:26:57 -0300 Message-Id: <1286803617-17328-4-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1286803617-17328-1-git-send-email-david@tethera.net> References: <1286803617-17328-1-git-send-email-david@tethera.net> Cc: David Bremner 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: Mon, 11 Oct 2010 13:27:50 -0000 From: David Bremner logging of tags is enabled by adding a stanza like [log] tags = /some/path/you/can/write/to to your notmuch config. Note that we intentionally do the logging after the database transaction is finished. --- notmuch-tag.c | 31 +++++++++++++++++++++++++++++++ 1 files changed, 31 insertions(+), 0 deletions(-) diff --git a/notmuch-tag.c b/notmuch-tag.c index fd54bc7..f24d1e4 100644 --- a/notmuch-tag.c +++ b/notmuch-tag.c @@ -46,6 +46,9 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[])) notmuch_message_t *message; struct sigaction action; int i; + int log_fd = -1; + notmuch_bool_t enable_log = FALSE; + const char *log_path; /* Setup our handler for SIGINT */ memset (&action, 0, sizeof (struct sigaction)); @@ -96,6 +99,17 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[])) if (config == NULL) return 1; + log_path = notmuch_config_get_log_path (config, "tags"); + + if (log_path != NULL) { + enable_log = TRUE; + + log_fd = notmuch_log_open(log_path); + + if (log_fd < 0) + return 1; + } + notmuch = notmuch_database_open (notmuch_config_get_database_path (config), NOTMUCH_DATABASE_MODE_READ_WRITE); if (notmuch == NULL) @@ -114,10 +128,15 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[])) notmuch_messages_valid (messages) && !interrupted; notmuch_messages_move_to_next (messages)) { + const char *message_id = NULL; message = notmuch_messages_get (messages); notmuch_message_freeze (message); + if (enable_log) + message_id = talloc_strdup (ctx, + notmuch_message_get_message_id (message)); + for (i = 0; i < remove_tags_count; i++) notmuch_message_remove_tag (message, argv[remove_tags[i]] + 1); @@ -128,6 +147,18 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[])) notmuch_message_thaw (message); notmuch_message_destroy (message); + + if (enable_log) { + for (i = 0; i < remove_tags_count; i++) + notmuch_log_string_pair (ctx, log_fd, + message_id, + argv[remove_tags[i]]); + + for (i = 0; i < add_tags_count; i++) + notmuch_log_string_pair (ctx, log_fd, + message_id, + argv[add_tags[i]]); + } } notmuch_query_destroy (query); -- 1.7.1