From a612f0ca23044f464120b659602f70070a708062 Mon Sep 17 00:00:00 2001 From: Peter Wang Date: Wed, 25 Jul 2012 23:42:40 +1000 Subject: [PATCH] [PATCH 11/18] insert: apply command-line tag operations --- be/04fea205c7231717429e1998a4cf98572f531f | 128 ++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 be/04fea205c7231717429e1998a4cf98572f531f diff --git a/be/04fea205c7231717429e1998a4cf98572f531f b/be/04fea205c7231717429e1998a4cf98572f531f new file mode 100644 index 000000000..5739d2afa --- /dev/null +++ b/be/04fea205c7231717429e1998a4cf98572f531f @@ -0,0 +1,128 @@ +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 B87DA431FD5 + for ; Wed, 25 Jul 2012 06:44:39 -0700 (PDT) +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 bMwLy+6nkyOi for ; + Wed, 25 Jul 2012 06:44:38 -0700 (PDT) +Received: from mail-gg0-f181.google.com (mail-gg0-f181.google.com + [209.85.161.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 45951431FD9 + for ; Wed, 25 Jul 2012 06:44:16 -0700 (PDT) +Received: by ggnv5 with SMTP id v5so883639ggn.26 + for ; Wed, 25 Jul 2012 06:44:15 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; + bh=j0lUFfrSEJ14+yeNmyCQqFdbH/kU+cbewfgsOnHhcZs=; + b=YHDPlfqWDAxHwoTfs+pniq6ljfrXYtlKsphCMyEE7K7wBCRSEMMndzrwaw2gzcPk6o + BcRB2lv3FS54VYsPabzn9QTuMfNl7d2NfqovbnrzBOLYSFppI3CUQretJ9aQEOuPvjOu + xrfhUMswYG85QHFXJOENmrkdR15vRn72lSDn3L8Wdn3PGlmvxLSVT5o4JVYORFYYhE+M + wBCJre1ocgceyQVPwQhHzRk7AambAudcCjoAqKKqT8QVWpI84wgZzrDmoerz0xvHZfz2 + qMoxf0l+luYPOqX1aBVKYkzRoC0yyX2TQLAWs5SBdPczUke+J0VwyjG2ATLJDCbmyzSc + CbBg== +Received: by 10.66.73.5 with SMTP id h5mr12788745pav.79.1343223855447; + Wed, 25 Jul 2012 06:44:15 -0700 (PDT) +Received: from localhost (215.42.233.220.static.exetel.com.au. + [220.233.42.215]) + by mx.google.com with ESMTPS id wi6sm14414420pbc.35.2012.07.25.06.44.12 + (version=TLSv1/SSLv3 cipher=OTHER); + Wed, 25 Jul 2012 06:44:14 -0700 (PDT) +From: Peter Wang +To: notmuch@notmuchmail.org +Subject: [PATCH 11/18] insert: apply command-line tag operations +Date: Wed, 25 Jul 2012 23:42:40 +1000 +Message-Id: <1343223767-9812-11-git-send-email-novalazy@gmail.com> +X-Mailer: git-send-email 1.7.4.4 +In-Reply-To: <1343223767-9812-1-git-send-email-novalazy@gmail.com> +References: <1343223767-9812-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: Wed, 25 Jul 2012 13:44:40 -0000 + +Apply the +tag and -tag operations which were specified on the +command-line. +--- + notmuch-insert.c | 18 ++++++++++++++---- + 1 files changed, 14 insertions(+), 4 deletions(-) + +diff --git a/notmuch-insert.c b/notmuch-insert.c +index 6db03e3..5fd79be 100644 +--- a/notmuch-insert.c ++++ b/notmuch-insert.c +@@ -151,7 +151,7 @@ copy_fd_data (int fdin, int fdout) + + static notmuch_bool_t + save_database (notmuch_database_t *notmuch, const char *path, +- const char **new_tags) ++ const char **new_tags, const tag_operation_t *tag_ops) + { + notmuch_message_t *message; + notmuch_status_t status; +@@ -186,6 +186,14 @@ save_database (notmuch_database_t *notmuch, const char *path, + notmuch_message_add_tag (message, new_tags[i]); + } + ++ for (i = 0; tag_ops[i].tag; i++) { ++ if (tag_ops[i].remove) { ++ notmuch_message_remove_tag (message, tag_ops[i].tag); ++ } else { ++ notmuch_message_add_tag (message, tag_ops[i].tag); ++ } ++ } ++ + notmuch_message_thaw (message); + + notmuch_message_tags_to_maildir_flags (message); +@@ -197,7 +205,8 @@ save_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 **new_tags) ++ const char *dir, const char **new_tags, ++ const tag_operation_t *tag_ops) + { + char *tmppath; + char *newpath; +@@ -222,7 +231,7 @@ insert_message (void *ctx, notmuch_database_t *notmuch, int fdin, + return FALSE; + } + +- ret = save_database (notmuch, newpath, new_tags); ++ ret = save_database (notmuch, newpath, new_tags, tag_ops); + + if (!ret) { + /* XXX maybe there should be an option to keep the file in maildir? */ +@@ -324,7 +333,8 @@ 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, new_tags); ++ ret = insert_message (ctx, notmuch, STDIN_FILENO, maildir, new_tags, ++ tag_ops); + + notmuch_database_destroy (notmuch); + +-- +1.7.4.4 + -- 2.26.2