Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / 27 / 719d2199da82f0dfade8482de06dc4684941f0
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 1E52D431FCB\r
6         for <notmuch@notmuchmail.org>; Wed, 16 Apr 2014 06:00:51 -0700 (PDT)\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 dltdtOkg6xEz for <notmuch@notmuchmail.org>;\r
17         Wed, 16 Apr 2014 06:00:45 -0700 (PDT)\r
18 Received: from mail-pb0-f42.google.com (mail-pb0-f42.google.com\r
19         [209.85.160.42]) (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 5E3A6431FBF\r
22         for <notmuch@notmuchmail.org>; Wed, 16 Apr 2014 06:00:18 -0700 (PDT)\r
23 Received: by mail-pb0-f42.google.com with SMTP id rr13so10952745pbb.1\r
24         for <notmuch@notmuchmail.org>; Wed, 16 Apr 2014 06:00:17 -0700 (PDT)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
26         h=from:to:cc:subject:date:message-id:in-reply-to:references;\r
27         bh=2nfJSnS2AN9Bu8cnvUWtOuFvcuU+svUvdOi7ZrvXAU4=;\r
28         b=GaNY3R7ByqpLBS/mVLV94PxkbUWev4Txz/L/ZnEWpiRHNuTYZ6ktvUuUUVAz0lKRPq\r
29         25j356mEaMpu7j+Gbe6+iAzZqDb0tincEXAemXlvKr0FwErYFEKfUIJGuMgRaVegI/wP\r
30         ZE0TvTB6WbgvHlUyNgWMf+nS0QdoYnjqr5Dw32WOmR1vhP091EThyPOgQ5Wb1lKRuuZ2\r
31         Ek1h7y1mji4wIdhEznqJzJ52iuOTK1IGFWHawMKW4Lrhwd84EjUWRgf6T9DQiVRyy0ul\r
32         YXmplnKZp2j2c0ktOPsxuu4r5CF/Xx2Y2+OVrbGSLU86LDF9Bktq+AGxDEfOmoKIql1l\r
33         Et0Q==\r
34 X-Received: by 10.68.240.5 with SMTP id vw5mr8230493pbc.113.1397653217736;\r
35         Wed, 16 Apr 2014 06:00:17 -0700 (PDT)\r
36 Received: from localhost (215.42.233.220.static.exetel.com.au.\r
37         [220.233.42.215]) by mx.google.com with ESMTPSA id\r
38         dy7sm111054220pad.9.2014.04.16.06.00.15 for <multiple recipients>\r
39         (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
40         Wed, 16 Apr 2014 06:00:16 -0700 (PDT)\r
41 From: Peter Wang <novalazy@gmail.com>\r
42 To: notmuch@notmuchmail.org\r
43 Subject: [PATCH v2 08/10] cli: add insert --must-index option\r
44 Date: Wed, 16 Apr 2014 22:59:23 +1000\r
45 Message-Id: <1397653165-15620-9-git-send-email-novalazy@gmail.com>\r
46 X-Mailer: git-send-email 1.8.4\r
47 In-Reply-To: <1397653165-15620-1-git-send-email-novalazy@gmail.com>\r
48 References: <1397653165-15620-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: Wed, 16 Apr 2014 13:00:51 -0000\r
62 \r
63 This option causes notmuch insert to fail (with exit code 3) on failure\r
64 to index the message, or failure to set the tags on the message, or if\r
65 closing (flushing) the database fails.  Failure to sync tags to flags\r
66 has no effect.\r
67 ---\r
68  notmuch-insert.c | 57 +++++++++++++++++++++++++++++++++++++++-----------------\r
69  1 file changed, 40 insertions(+), 17 deletions(-)\r
70 \r
71 diff --git a/notmuch-insert.c b/notmuch-insert.c\r
72 index 29d82c9..83257f4 100644\r
73 --- a/notmuch-insert.c\r
74 +++ b/notmuch-insert.c\r
75 @@ -31,7 +31,8 @@\r
76  enum {\r
77      INSERT_EXIT_SUCCESS = 0,\r
78      INSERT_EXIT_FAILURE = 1,\r
79 -    INSERT_EXIT_FAILED_WRITE = 2\r
80 +    INSERT_EXIT_FAILED_WRITE = 2,\r
81 +    INSERT_EXIT_FAILED_INDEX = 3\r
82  };\r
83  \r
84  static volatile sig_atomic_t interrupted;\r
85 @@ -298,13 +299,15 @@ copy_stdin (int fdin, int fdout)\r
86  }\r
87  \r
88  /* Add the specified message file to the notmuch database, applying tags.\r
89 - * The file is renamed to encode notmuch tags as maildir flags. */\r
90 -static void\r
91 + * If synchronize_flags is set then file is renamed to encode notmuch tags as\r
92 + * maildir flags. */\r
93 +static notmuch_bool_t\r
94  add_file_to_database (notmuch_database_t *notmuch, const char *path,\r
95                       tag_op_list_t *tag_ops, notmuch_bool_t synchronize_flags)\r
96  {\r
97      notmuch_message_t *message;\r
98      notmuch_status_t status;\r
99 +    notmuch_status_t sync;\r
100  \r
101      status = notmuch_database_add_message (notmuch, path, &message);\r
102      switch (status) {\r
103 @@ -324,23 +327,28 @@ add_file_to_database (notmuch_database_t *notmuch, const char *path,\r
104      case NOTMUCH_STATUS_LAST_STATUS:\r
105         fprintf (stderr, "Error: failed to add `%s' to notmuch database: %s\n",\r
106                  path, notmuch_status_to_string (status));\r
107 -       return;\r
108 +       return FALSE;\r
109      }\r
110  \r
111      if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {\r
112         /* Don't change tags of an existing message. */\r
113 -       if (synchronize_flags) {\r
114 -           status = notmuch_message_tags_to_maildir_flags (message);\r
115 -           if (status != NOTMUCH_STATUS_SUCCESS)\r
116 -               fprintf (stderr, "Error: failed to sync tags to maildir flags\n");\r
117 -       }\r
118 +       status = NOTMUCH_STATUS_SUCCESS;\r
119      } else {\r
120 -       tag_op_flag_t flags = synchronize_flags ? TAG_FLAG_MAILDIR_SYNC : 0;\r
121 +       status = tag_op_list_apply (message, tag_ops, 0);\r
122 +    }\r
123  \r
124 -       tag_op_list_apply (message, tag_ops, flags);\r
125 +    /* Call notmuch_message_tags_to_maildir_flags directly instead of doing it\r
126 +     * as part of tag_op_list_apply. For --must-index we want to succeed if\r
127 +     * tagging succeeds, but disregard whether synchronizing flags fails. */\r
128 +    if (status == NOTMUCH_STATUS_SUCCESS && synchronize_flags) {\r
129 +       sync = notmuch_message_tags_to_maildir_flags (message);\r
130 +       if (sync != NOTMUCH_STATUS_SUCCESS)\r
131 +           fprintf (stderr, "Error: failed to sync tags to maildir flags\n");\r
132      }\r
133  \r
134      notmuch_message_destroy (message);\r
135 +\r
136 +    return (status == NOTMUCH_STATUS_SUCCESS);\r
137  }\r
138  \r
139  static notmuch_bool_t\r
140 @@ -400,15 +408,19 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
141      char *query_string = NULL;\r
142      const char *folder = NULL;\r
143      notmuch_bool_t create_folder = FALSE;\r
144 +    notmuch_bool_t must_index = FALSE;\r
145      notmuch_bool_t synchronize_flags;\r
146      const char *maildir;\r
147      char *newpath;\r
148      int opt_index;\r
149      unsigned int i;\r
150 +    notmuch_bool_t indexed;\r
151 +    notmuch_status_t status;\r
152  \r
153      notmuch_opt_desc_t options[] = {\r
154         { NOTMUCH_OPT_STRING, &folder, "folder", 0, 0 },\r
155         { NOTMUCH_OPT_BOOLEAN, &create_folder, "create-folder", 0, 0 },\r
156 +       { NOTMUCH_OPT_BOOLEAN, &must_index, "must-index", 0, 0 },\r
157         { NOTMUCH_OPT_END, 0, 0, 0, 0 }\r
158      };\r
159  \r
160 @@ -485,12 +497,23 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
161         return INSERT_EXIT_FAILED_WRITE;\r
162      }\r
163  \r
164 -    /* Add the message to the index.\r
165 -     * Even if adding the message to the notmuch database fails,\r
166 -     * the message is on disk and we consider the delivery completed. */\r
167 -    add_file_to_database (notmuch, newpath, tag_ops,\r
168 +    /* Add the message to the index. */\r
169 +    indexed = add_file_to_database (notmuch, newpath, tag_ops,\r
170                                     synchronize_flags);\r
171  \r
172 -    notmuch_database_destroy (notmuch);\r
173 -    return INSERT_EXIT_SUCCESS;\r
174 +    /* If must_index is FALSE then succeed as the message is on disk.\r
175 +     * Otherwise message indexing and tagging must succeed, and the database\r
176 +     * must be flushed. Don't flush the database if there was an earlier\r
177 +     * error, so as to abandon the transaction (is there a better way?) */\r
178 +    if (! must_index) {\r
179 +       notmuch_database_destroy (notmuch);\r
180 +       return INSERT_EXIT_SUCCESS;\r
181 +    }\r
182 +    if (indexed) {\r
183 +       status = notmuch_database_destroy (notmuch);\r
184 +       if (status == NOTMUCH_STATUS_SUCCESS)\r
185 +           return INSERT_EXIT_SUCCESS;\r
186 +    }\r
187 +    unlink (newpath);\r
188 +    return INSERT_EXIT_FAILED_INDEX;\r
189  }\r
190 -- \r
191 1.8.4\r
192 \r