[PATCH] RFC: all deleting all properties with a given key
[notmuch-archives.git] / be / ba090fc24e087147be7265fba67840e97e3fd9
1 Return-Path: <novalazy@gmail.com>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 16D32429E39\r
6         for <notmuch@notmuchmail.org>; Sat, 19 Jan 2013 16:51:14 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.799\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id UTdZ4kgtBLYQ for <notmuch@notmuchmail.org>;\r
17         Sat, 19 Jan 2013 16:51:13 -0800 (PST)\r
18 Received: from mail-pa0-f54.google.com (mail-pa0-f54.google.com\r
19         [209.85.220.54]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 72C8C431FDB\r
22         for <notmuch@notmuchmail.org>; Sat, 19 Jan 2013 16:51:03 -0800 (PST)\r
23 Received: by mail-pa0-f54.google.com with SMTP id bi5so2777745pad.41\r
24         for <notmuch@notmuchmail.org>; Sat, 19 Jan 2013 16:51:02 -0800 (PST)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
26         h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to\r
27         :references; bh=RjbutPzmyzUeoD1puvjzd1o8i/3/XL32inmc8duqQ9o=;\r
28         b=cgVmWEWmJ5q+n6snkpoB0PU/DRYxoRWIZTs/X4kow88YmUB+UJS2W4Z2jh5uDxGy3n\r
29         mW8i7VZIn9wh7/S8Inz5r6PHyi10KaEzNwTLX1PUDJO7w6u5a2InoxZXXeih9Asi8K8e\r
30         GZeJEn1YVMZiwRH1VY8YIXZuzCkx39iCBTUS+PnCBmxIuDHOKAtMMpZTY5rgUfDzEyNF\r
31         LL8/QgAuA85N/wDsVJ70WbyQgjTs1BNg43jk8Prn/TNPkTF2inYC5+AtUuTpx1bzQh3v\r
32         VPB40kGmj5VM38M2Zbk/HqCJTPVBoUYX20UO0TqmfJUTAB1FCTb8ENi+C9b2VEajtf5q\r
33         2EAQ==\r
34 X-Received: by 10.66.89.199 with SMTP id bq7mr36431263pab.26.1358643062517;\r
35         Sat, 19 Jan 2013 16:51:02 -0800 (PST)\r
36 Received: from localhost (215.42.233.220.static.exetel.com.au.\r
37         [220.233.42.215])\r
38         by mx.google.com with ESMTPS id qo10sm5795676pbc.58.2013.01.19.16.51.00\r
39         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
40         Sat, 19 Jan 2013 16:51:01 -0800 (PST)\r
41 From: Peter Wang <novalazy@gmail.com>\r
42 To: notmuch@notmuchmail.org\r
43 Subject: [PATCH v3 06/20] insert: apply default tags to new message\r
44 Date: Sun, 20 Jan 2013 11:49:50 +1100\r
45 Message-Id: <1358643004-14522-7-git-send-email-novalazy@gmail.com>\r
46 X-Mailer: git-send-email 1.7.12.1\r
47 In-Reply-To: <1358643004-14522-1-git-send-email-novalazy@gmail.com>\r
48 References: <1358643004-14522-1-git-send-email-novalazy@gmail.com>\r
49 X-BeenThere: notmuch@notmuchmail.org\r
50 X-Mailman-Version: 2.1.13\r
51 Precedence: list\r
52 List-Id: "Use and development of the notmuch mail system."\r
53         <notmuch.notmuchmail.org>\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
57 List-Post: <mailto:notmuch@notmuchmail.org>\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
60         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
61 X-List-Received-Date: Sun, 20 Jan 2013 00:51:14 -0000\r
62 \r
63 Apply the new.tags to messages added by 'insert'.  This mirrors the\r
64 behaviour if the message were delivered by a separate tool followed by\r
65 'notmuch new'.\r
66 ---\r
67  notmuch-insert.c | 29 +++++++++++++++++++++++------\r
68  1 file changed, 23 insertions(+), 6 deletions(-)\r
69 \r
70 diff --git a/notmuch-insert.c b/notmuch-insert.c\r
71 index 498421d..8388d07 100644\r
72 --- a/notmuch-insert.c\r
73 +++ b/notmuch-insert.c\r
74 @@ -19,6 +19,7 @@\r
75   */\r
76  \r
77  #include "notmuch-client.h"\r
78 +#include "tag-util.h"\r
79  \r
80  #include <sys/types.h>\r
81  #include <sys/stat.h>\r
82 @@ -153,10 +154,11 @@ copy_stdin (int fdin, int fdout)\r
83      return TRUE;\r
84  }\r
85  \r
86 -/* Add the specified message file to the notmuch database.\r
87 +/* Add the specified message file to the notmuch database, applying tags.\r
88   * The file is renamed to encode notmuch tags as maildir flags. */\r
89  static notmuch_bool_t\r
90 -add_file_to_database (notmuch_database_t *notmuch, const char *path)\r
91 +add_file_to_database (notmuch_database_t *notmuch, const char *path,\r
92 +                     tag_op_list_t *tag_ops)\r
93  {\r
94      notmuch_message_t *message;\r
95      notmuch_status_t status;\r
96 @@ -184,7 +186,7 @@ add_file_to_database (notmuch_database_t *notmuch, const char *path)\r
97         return FALSE;\r
98      }\r
99  \r
100 -    notmuch_message_tags_to_maildir_flags (message);\r
101 +    tag_op_list_apply (message, tag_ops, TAG_FLAG_MAILDIR_SYNC);\r
102  \r
103      notmuch_message_destroy (message);\r
104  \r
105 @@ -193,7 +195,7 @@ add_file_to_database (notmuch_database_t *notmuch, const char *path)\r
106  \r
107  static notmuch_bool_t\r
108  insert_message (void *ctx, notmuch_database_t *notmuch, int fdin,\r
109 -               const char *dir)\r
110 +               const char *dir, tag_op_list_t *tag_ops)\r
111  {\r
112      char *tmppath;\r
113      char *newpath;\r
114 @@ -214,7 +216,7 @@ insert_message (void *ctx, notmuch_database_t *notmuch, int fdin,\r
115         return FALSE;\r
116      }\r
117  \r
118 -    ret = add_file_to_database (notmuch, newpath);\r
119 +    ret = add_file_to_database (notmuch, newpath, tag_ops);\r
120      if (!ret) {\r
121         /* XXX maybe there should be an option to keep the file in maildir? */\r
122         unlink (newpath);\r
123 @@ -230,7 +232,11 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])\r
124      notmuch_config_t *config;\r
125      notmuch_database_t *notmuch;\r
126      const char *db_path;\r
127 +    const char **new_tags;\r
128 +    size_t new_tags_length;\r
129 +    tag_op_list_t *tag_ops;\r
130      char *maildir;\r
131 +    unsigned int i;\r
132      notmuch_bool_t ret;\r
133  \r
134      config = notmuch_config_open (ctx, NULL, NULL);\r
135 @@ -238,6 +244,17 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])\r
136         return 1;\r
137  \r
138      db_path = notmuch_config_get_database_path (config);\r
139 +    new_tags = notmuch_config_get_new_tags (config, &new_tags_length);\r
140 +\r
141 +    tag_ops = tag_op_list_create (ctx);\r
142 +    if (tag_ops == NULL) {\r
143 +       fprintf (stderr, "Out of memory.\n");\r
144 +       return 1;\r
145 +    }\r
146 +    for (i = 0; i < new_tags_length; i++) {\r
147 +       if (tag_op_list_append (tag_ops, new_tags[i], FALSE))\r
148 +           return 1;\r
149 +    }\r
150  \r
151      maildir = talloc_asprintf (ctx, "%s", db_path);\r
152      if (! maildir) {\r
153 @@ -249,7 +266,7 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])\r
154                                NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))\r
155         return 1;\r
156  \r
157 -    ret = insert_message (ctx, notmuch, STDIN_FILENO, maildir);\r
158 +    ret = insert_message (ctx, notmuch, STDIN_FILENO, maildir, tag_ops);\r
159  \r
160      notmuch_database_destroy (notmuch);\r
161  \r
162 -- \r
163 1.7.12.1\r
164 \r