[PATCH v3 06/20] insert: apply default tags to new message
authorPeter Wang <novalazy@gmail.com>
Sun, 20 Jan 2013 00:49:50 +0000 (11:49 +1100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:53:13 +0000 (09:53 -0800)
be/ba090fc24e087147be7265fba67840e97e3fd9 [new file with mode: 0644]

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