From: Peter Wang Date: Sun, 25 Nov 2012 01:16:38 +0000 (+1100) Subject: [PATCH v2 12/20] insert: apply command-line tag operations X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=d60c4e651a693b3687306e4d0f4624bb8daf0439;p=notmuch-archives.git [PATCH v2 12/20] insert: apply command-line tag operations --- diff --git a/85/76a8120f86821a1e2c1c06af1b35bf42521cea b/85/76a8120f86821a1e2c1c06af1b35bf42521cea new file mode 100644 index 000000000..6588a001e --- /dev/null +++ b/85/76a8120f86821a1e2c1c06af1b35bf42521cea @@ -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 B4CB2431FB6 + for ; Sat, 24 Nov 2012 17:18:13 -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 xexACAUHANPC for ; + Sat, 24 Nov 2012 17:18:12 -0800 (PST) +Received: from mail-pa0-f53.google.com (mail-pa0-f53.google.com + [209.85.220.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id BF89A431FAE + for ; Sat, 24 Nov 2012 17:18:12 -0800 (PST) +Received: by mail-pa0-f53.google.com with SMTP id hz1so3911431pad.26 + for ; Sat, 24 Nov 2012 17:18:12 -0800 (PST) +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=C/OKiYOj1R2YY88A/3izhtdqhpAObijV7xGH0v3i6zU=; + b=pI5XW9ikv4pp/7MqnklEzKCBeNk9zrjt/YDt05pNaaakKB2EMqMf8gbqC7XbQ64dIr + eH7kDLOijtf+07lxEPrBQBpRaVPHQX3DB5A9LooCYP7VBnbLb90AZWO6AjUUI9NMiFI8 + lKZi1VtnE2fyKUUN2QCmpacoblkbkTPAPaBdhtIwPwRrnEh3dK9S/q+n74N1qa6iMn6u + +s3O7V0mJ2ST9GCbcKPSQ2RpDCUSS7SSr3JH6SDeJPfLpq1xCVH3LwVAhqBXbeFNX8Ka + t0+Bt3IZZLcWvDJDFuVVlGB+TD8kzf+XQrmSrZ8zM15ANBEqmUk5eWT+nJCAaq4lpT93 + kIcg== +Received: by 10.69.1.35 with SMTP id bd3mr26639614pbd.141.1353806292536; + Sat, 24 Nov 2012 17:18:12 -0800 (PST) +Received: from localhost (215.42.233.220.static.exetel.com.au. + [220.233.42.215]) + by mx.google.com with ESMTPS id uk9sm6220363pbc.63.2012.11.24.17.18.09 + (version=TLSv1/SSLv3 cipher=OTHER); + Sat, 24 Nov 2012 17:18:11 -0800 (PST) +From: Peter Wang +To: notmuch@notmuchmail.org +Subject: [PATCH v2 12/20] insert: apply command-line tag operations +Date: Sun, 25 Nov 2012 12:16:38 +1100 +Message-Id: <1353806206-29133-13-git-send-email-novalazy@gmail.com> +X-Mailer: git-send-email 1.7.12.1 +In-Reply-To: <1353806206-29133-1-git-send-email-novalazy@gmail.com> +References: <1353806206-29133-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, 25 Nov 2012 01:18:14 -0000 + +Apply the +tag and -tag operations specified on the command-line. +--- + notmuch-insert.c | 19 +++++++++++++++---- + 1 file changed, 15 insertions(+), 4 deletions(-) + +diff --git a/notmuch-insert.c b/notmuch-insert.c +index e4631a2..81a528c 100644 +--- a/notmuch-insert.c ++++ b/notmuch-insert.c +@@ -174,7 +174,8 @@ copy_fd_data (int fdin, int fdout) + * 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, +- const char **new_tags) ++ const char **new_tags, ++ const notmuch_tag_operation_t *tag_ops) + { + notmuch_message_t *message; + notmuch_status_t status; +@@ -211,6 +212,14 @@ add_file_to_database (notmuch_database_t *notmuch, const char *path, + notmuch_message_add_tag (message, new_tags[i]); + } + ++ /* Apply the tags specified on the command-line. */ ++ 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); +@@ -222,7 +231,8 @@ 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 **new_tags) ++ const char *dir, const char **new_tags, ++ const notmuch_tag_operation_t *tag_ops) + { + char *tmppath; + char *newpath; +@@ -243,7 +253,7 @@ insert_message (void *ctx, notmuch_database_t *notmuch, int fdin, + return FALSE; + } + +- ret = add_file_to_database (notmuch, newpath, new_tags); ++ ret = add_file_to_database (notmuch, newpath, new_tags, tag_ops); + if (!ret) { + /* XXX maybe there should be an option to keep the file in maildir? */ + unlink (newpath); +@@ -327,7 +337,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.12.1 +