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 16D32429E39 for ; Sat, 19 Jan 2013 16:51:14 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] 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 UTdZ4kgtBLYQ for ; Sat, 19 Jan 2013 16:51:13 -0800 (PST) Received: from mail-pa0-f54.google.com (mail-pa0-f54.google.com [209.85.220.54]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 72C8C431FDB for ; Sat, 19 Jan 2013 16:51:03 -0800 (PST) Received: by mail-pa0-f54.google.com with SMTP id bi5so2777745pad.41 for ; Sat, 19 Jan 2013 16:51:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=RjbutPzmyzUeoD1puvjzd1o8i/3/XL32inmc8duqQ9o=; b=cgVmWEWmJ5q+n6snkpoB0PU/DRYxoRWIZTs/X4kow88YmUB+UJS2W4Z2jh5uDxGy3n mW8i7VZIn9wh7/S8Inz5r6PHyi10KaEzNwTLX1PUDJO7w6u5a2InoxZXXeih9Asi8K8e GZeJEn1YVMZiwRH1VY8YIXZuzCkx39iCBTUS+PnCBmxIuDHOKAtMMpZTY5rgUfDzEyNF LL8/QgAuA85N/wDsVJ70WbyQgjTs1BNg43jk8Prn/TNPkTF2inYC5+AtUuTpx1bzQh3v VPB40kGmj5VM38M2Zbk/HqCJTPVBoUYX20UO0TqmfJUTAB1FCTb8ENi+C9b2VEajtf5q 2EAQ== X-Received: by 10.66.89.199 with SMTP id bq7mr36431263pab.26.1358643062517; Sat, 19 Jan 2013 16:51:02 -0800 (PST) Received: from localhost (215.42.233.220.static.exetel.com.au. [220.233.42.215]) by mx.google.com with ESMTPS id qo10sm5795676pbc.58.2013.01.19.16.51.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 19 Jan 2013 16:51:01 -0800 (PST) From: Peter Wang To: notmuch@notmuchmail.org Subject: [PATCH v3 06/20] insert: apply default tags to new message Date: Sun, 20 Jan 2013 11:49:50 +1100 Message-Id: <1358643004-14522-7-git-send-email-novalazy@gmail.com> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <1358643004-14522-1-git-send-email-novalazy@gmail.com> References: <1358643004-14522-1-git-send-email-novalazy@gmail.com> 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: Sun, 20 Jan 2013 00:51:14 -0000 Apply the new.tags to messages added by 'insert'. This mirrors the behaviour if the message were delivered by a separate tool followed by 'notmuch new'. --- notmuch-insert.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/notmuch-insert.c b/notmuch-insert.c index 498421d..8388d07 100644 --- a/notmuch-insert.c +++ b/notmuch-insert.c @@ -19,6 +19,7 @@ */ #include "notmuch-client.h" +#include "tag-util.h" #include #include @@ -153,10 +154,11 @@ copy_stdin (int fdin, int fdout) return TRUE; } -/* Add the specified message file to the notmuch database. +/* Add the specified message file to the notmuch database, applying tags. * The file is renamed to encode notmuch tags as maildir flags. */ static notmuch_bool_t -add_file_to_database (notmuch_database_t *notmuch, const char *path) +add_file_to_database (notmuch_database_t *notmuch, const char *path, + tag_op_list_t *tag_ops) { notmuch_message_t *message; notmuch_status_t status; @@ -184,7 +186,7 @@ add_file_to_database (notmuch_database_t *notmuch, const char *path) return FALSE; } - notmuch_message_tags_to_maildir_flags (message); + tag_op_list_apply (message, tag_ops, TAG_FLAG_MAILDIR_SYNC); notmuch_message_destroy (message); @@ -193,7 +195,7 @@ add_file_to_database (notmuch_database_t *notmuch, const char *path) static notmuch_bool_t insert_message (void *ctx, notmuch_database_t *notmuch, int fdin, - const char *dir) + const char *dir, tag_op_list_t *tag_ops) { char *tmppath; char *newpath; @@ -214,7 +216,7 @@ insert_message (void *ctx, notmuch_database_t *notmuch, int fdin, return FALSE; } - ret = add_file_to_database (notmuch, newpath); + ret = add_file_to_database (notmuch, newpath, tag_ops); if (!ret) { /* XXX maybe there should be an option to keep the file in maildir? */ unlink (newpath); @@ -230,7 +232,11 @@ notmuch_insert_command (void *ctx, int argc, char *argv[]) notmuch_config_t *config; notmuch_database_t *notmuch; const char *db_path; + const char **new_tags; + size_t new_tags_length; + tag_op_list_t *tag_ops; char *maildir; + unsigned int i; notmuch_bool_t ret; config = notmuch_config_open (ctx, NULL, NULL); @@ -238,6 +244,17 @@ notmuch_insert_command (void *ctx, int argc, char *argv[]) return 1; db_path = notmuch_config_get_database_path (config); + new_tags = notmuch_config_get_new_tags (config, &new_tags_length); + + tag_ops = tag_op_list_create (ctx); + if (tag_ops == NULL) { + fprintf (stderr, "Out of memory.\n"); + return 1; + } + for (i = 0; i < new_tags_length; i++) { + if (tag_op_list_append (tag_ops, new_tags[i], FALSE)) + return 1; + } maildir = talloc_asprintf (ctx, "%s", db_path); if (! maildir) { @@ -249,7 +266,7 @@ notmuch_insert_command (void *ctx, int argc, char *argv[]) NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much)) return 1; - ret = insert_message (ctx, notmuch, STDIN_FILENO, maildir); + ret = insert_message (ctx, notmuch, STDIN_FILENO, maildir, tag_ops); notmuch_database_destroy (notmuch); -- 1.7.12.1