From 349e7f62f19391fde6d67f31962bdf4ff708c43a Mon Sep 17 00:00:00 2001 From: Peter Wang Date: Sun, 25 Nov 2012 12:16:36 +1100 Subject: [PATCH] [PATCH v2 10/20] insert: apply default tags to new message --- a2/abae1a46f4942bb5f45b6739a0efeec1039e91 | 155 ++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 a2/abae1a46f4942bb5f45b6739a0efeec1039e91 diff --git a/a2/abae1a46f4942bb5f45b6739a0efeec1039e91 b/a2/abae1a46f4942bb5f45b6739a0efeec1039e91 new file mode 100644 index 000000000..4bf11106a --- /dev/null +++ b/a2/abae1a46f4942bb5f45b6739a0efeec1039e91 @@ -0,0 +1,155 @@ +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 CB093431FB6 + for ; Sat, 24 Nov 2012 17:18:01 -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 Pu1yIlq9t5Ev for ; + Sat, 24 Nov 2012 17:18:01 -0800 (PST) +Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com + [209.85.160.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 40F11431FAE + for ; Sat, 24 Nov 2012 17:18:01 -0800 (PST) +Received: by mail-pb0-f53.google.com with SMTP id jt11so7944513pbb.26 + for ; Sat, 24 Nov 2012 17:18:01 -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=ZT9+YIg5cNv68UbIeoNGgafS30PjYKVyTEEFf5LoN2g=; + b=aeLIJgoXuXuPUeUL8CEFvCCZXUIOn+2WgaOh2Brjn4P3YvwXcHxfvTkODAdkzb1pK2 + HTrquyiz/CGwJRpNAtS0jVQGA6BqIGYMuwLir3gUSoGHPOOlVL2E/c2MWiEky7L025Zv + 3TN3u3bss+V4cXuZIpjciZIXwUApLGaNOn5emLhaSDhWJvqWkqh8aP85vmPlP0B3Fi8l + 4cARU4FTaGvLmG93N/R5fiXcKvxARMv+VXrH/zz06erXKMF/ysKk2rKixBvrzA+Got3G + bCCfRea0UElVcOKk1BjUp5klV0veL2fsRTKA3dhRIGyh3yiG2/CqAME2ujCYf1a3+t+u + tXlg== +Received: by 10.68.244.135 with SMTP id xg7mr26289949pbc.87.1353806281013; + Sat, 24 Nov 2012 17:18:01 -0800 (PST) +Received: from localhost (215.42.233.220.static.exetel.com.au. + [220.233.42.215]) + by mx.google.com with ESMTPS id ot5sm6228075pbb.29.2012.11.24.17.17.58 + (version=TLSv1/SSLv3 cipher=OTHER); + Sat, 24 Nov 2012 17:18:00 -0800 (PST) +From: Peter Wang +To: notmuch@notmuchmail.org +Subject: [PATCH v2 10/20] insert: apply default tags to new message +Date: Sun, 25 Nov 2012 12:16:36 +1100 +Message-Id: <1353806206-29133-11-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:01 -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 | 25 ++++++++++++++++++++----- + 1 file changed, 20 insertions(+), 5 deletions(-) + +diff --git a/notmuch-insert.c b/notmuch-insert.c +index 022f7cd..362da66 100644 +--- a/notmuch-insert.c ++++ b/notmuch-insert.c +@@ -170,13 +170,15 @@ copy_fd_data (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, ++ const char **new_tags) + { + notmuch_message_t *message; + notmuch_status_t status; ++ int i; + + status = notmuch_database_add_message (notmuch, path, &message); + switch (status) { +@@ -201,6 +203,16 @@ add_file_to_database (notmuch_database_t *notmuch, const char *path) + return FALSE; + } + ++ notmuch_message_freeze (message); ++ ++ /* Apply the new.tags, as would happen were the message added by ++ * 'notmuch new'. */ ++ for (i = 0; new_tags[i]; i++) { ++ notmuch_message_add_tag (message, new_tags[i]); ++ } ++ ++ notmuch_message_thaw (message); ++ + notmuch_message_tags_to_maildir_flags (message); + + notmuch_message_destroy (message); +@@ -210,7 +222,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, const char **new_tags) + { + char *tmppath; + char *newpath; +@@ -231,7 +243,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, new_tags); + if (!ret) { + /* XXX maybe there should be an option to keep the file in maildir? */ + unlink (newpath); +@@ -247,6 +259,8 @@ 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; + const char *folder = NULL; + char *maildir; + int opt_index; +@@ -270,6 +284,7 @@ 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); + + if (folder != NULL) { + if (! check_folder_name (folder)) { +@@ -289,7 +304,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, new_tags); + + notmuch_database_destroy (notmuch); + +-- +1.7.12.1 + -- 2.26.2