Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 2c / 8662e83bc386b55cc8810e6f847163ca6ca22c
1 Return-Path: <bremner@tesseract.cs.unb.ca>\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 1946C431FC7\r
6         for <notmuch@notmuchmail.org>; Fri,  3 Oct 2014 14:19:30 -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\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id J2W23DgTWYEF for <notmuch@notmuchmail.org>;\r
16         Fri,  3 Oct 2014 14:19:26 -0700 (PDT)\r
17 Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
18         (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id EE1EB431FBC\r
21         for <notmuch@notmuchmail.org>; Fri,  3 Oct 2014 14:19:25 -0700 (PDT)\r
22 Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
23         (envelope-from <bremner@tesseract.cs.unb.ca>)\r
24         id 1XaAG3-0000Kx-Ou; Fri, 03 Oct 2014 18:19:23 -0300\r
25 Received: (nullmailer pid 21179 invoked by uid 1000); Fri, 03 Oct 2014\r
26         21:19:08 -0000\r
27 From: David Bremner <david@tethera.net>\r
28 To: notmuch@notmuchmail.org\r
29 Subject: [Patch v2.5 3/4] cli/insert: require succesful message indexing for\r
30         success status\r
31 Date: Fri,  3 Oct 2014 23:18:59 +0200\r
32 Message-Id: <1412371140-21051-4-git-send-email-david@tethera.net>\r
33 X-Mailer: git-send-email 2.1.0\r
34 In-Reply-To: <1412371140-21051-1-git-send-email-david@tethera.net>\r
35 References: <1412371140-21051-1-git-send-email-david@tethera.net>\r
36 X-BeenThere: notmuch@notmuchmail.org\r
37 X-Mailman-Version: 2.1.13\r
38 Precedence: list\r
39 List-Id: "Use and development of the notmuch mail system."\r
40         <notmuch.notmuchmail.org>\r
41 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
42         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
44 List-Post: <mailto:notmuch@notmuchmail.org>\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
46 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
48 X-List-Received-Date: Fri, 03 Oct 2014 21:19:30 -0000\r
49 \r
50 From: Jani Nikula <jani@nikula.org>\r
51 \r
52 Add --keep option to keep any remaining stuff in index or file. We\r
53 could distinguish between failures to index and failures to apply tags\r
54 or maildir sync, but for simplicity just have one.\r
55 ---\r
56  doc/man1/notmuch-insert.rst | 19 ++++++++++++-------\r
57  notmuch-insert.c            | 36 ++++++++++++++++++++++++++++++------\r
58  test/T070-insert.sh         |  3 +--\r
59  3 files changed, 43 insertions(+), 15 deletions(-)\r
60 \r
61 diff --git a/doc/man1/notmuch-insert.rst b/doc/man1/notmuch-insert.rst\r
62 index 2be1a7b..e396f6c 100644\r
63 --- a/doc/man1/notmuch-insert.rst\r
64 +++ b/doc/man1/notmuch-insert.rst\r
65 @@ -38,16 +38,21 @@ Supported options for **insert** include\r
66          does not exist. Otherwise the folder must already exist for mail\r
67          delivery to succeed.\r
68  \r
69 +    ``--keep``\r
70 +        Keep the message file if indexing fails, and keep the message\r
71 +        indexed if applying tags or maildir flag synchronization\r
72 +        fails. Ignore these errors and return exit status 0 to\r
73 +        indicate succesful mail delivery.\r
74 +\r
75  EXIT STATUS\r
76  ===========\r
77  \r
78 -This command returns exit status 0 if the message was successfully added\r
79 -to the mail directory, even if the message could not be indexed and\r
80 -added to the notmuch database. In the latter case, a warning will be\r
81 -printed to standard error but the message file will be left on disk.\r
82 -\r
83 -If the message could not be written to disk then a non-zero exit status\r
84 -is returned.\r
85 +This command returns exit status 0 on succesful mail delivery,\r
86 +non-zero otherwise. The default is to indicate failed mail delivery on\r
87 +any errors, including message file delivery to the filesystem, message\r
88 +indexing to Notmuch database, changing tags, and synchronizing tags to\r
89 +maildir flags. The ``--keep`` option may be used to settle for\r
90 +successful message file delivery.\r
91  \r
92  SEE ALSO\r
93  ========\r
94 diff --git a/notmuch-insert.c b/notmuch-insert.c\r
95 index 0ea4380..7074077 100644\r
96 --- a/notmuch-insert.c\r
97 +++ b/notmuch-insert.c\r
98 @@ -443,6 +443,7 @@ add_file (notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops,\r
99  int\r
100  notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
101  {\r
102 +    notmuch_status_t status, close_status;\r
103      notmuch_database_t *notmuch;\r
104      struct sigaction action;\r
105      const char *db_path;\r
106 @@ -452,6 +453,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
107      char *query_string = NULL;\r
108      const char *folder = NULL;\r
109      notmuch_bool_t create_folder = FALSE;\r
110 +    notmuch_bool_t keep = FALSE;\r
111      notmuch_bool_t synchronize_flags;\r
112      const char *maildir;\r
113      char *newpath;\r
114 @@ -461,6 +463,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
115      notmuch_opt_desc_t options[] = {\r
116         { NOTMUCH_OPT_STRING, &folder, "folder", 0, 0 },\r
117         { NOTMUCH_OPT_BOOLEAN, &create_folder, "create-folder", 0, 0 },\r
118 +       { NOTMUCH_OPT_BOOLEAN, &keep, "keep", 0, 0 },\r
119         { NOTMUCH_OPT_END, 0, 0, 0, 0 }\r
120      };\r
121  \r
122 @@ -535,11 +538,32 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
123         return EXIT_FAILURE;\r
124      }\r
125  \r
126 -    /* Add the message to the index.\r
127 -     * Even if adding the message to the notmuch database fails,\r
128 -     * the message is on disk and we consider the delivery completed. */\r
129 -    add_file (notmuch, newpath, tag_ops, synchronize_flags, TRUE);\r
130 +    /* Index the message. */\r
131 +    status = add_file (notmuch, newpath, tag_ops, synchronize_flags, keep);\r
132 +\r
133 +    /* Commit changes. */\r
134 +    close_status = notmuch_database_destroy (notmuch);\r
135 +    if (close_status) {\r
136 +       /* Hold on to the first error, if any. */\r
137 +       if (! status)\r
138 +           status = close_status;\r
139 +       fprintf (stderr, "%s: failed to commit database changes: %s\n",\r
140 +                keep ? "Warning" : "Error",\r
141 +                notmuch_status_to_string (close_status));\r
142 +    }\r
143 +\r
144 +    if (status) {\r
145 +       if (keep) {\r
146 +           status = NOTMUCH_STATUS_SUCCESS;\r
147 +       } else {\r
148 +           /* If maildir flag sync failed, this might fail. */\r
149 +           if (unlink (newpath)) {\r
150 +               fprintf (stderr, "Warning: failed to remove '%s' from maildir "\r
151 +                        "after errors: %s. Please run 'notmuch new' to fix.\n",\r
152 +                        newpath, strerror (errno));\r
153 +           }\r
154 +       }\r
155 +    }\r
156  \r
157 -    notmuch_database_destroy (notmuch);\r
158 -    return EXIT_SUCCESS;\r
159 +    return status ? EXIT_FAILURE : EXIT_SUCCESS;\r
160  }\r
161 diff --git a/test/T070-insert.sh b/test/T070-insert.sh\r
162 index 40a7636..be8060e 100755\r
163 --- a/test/T070-insert.sh\r
164 +++ b/test/T070-insert.sh\r
165 @@ -23,7 +23,7 @@ test_expect_code 1 "Insert zero-length file" \\r
166  \r
167  # This test is a proxy for other errors that may occur while trying to\r
168  # add a message to the notmuch database, e.g. database locked.\r
169 -test_expect_code 0 "Insert non-message" \\r
170 +test_expect_code 1 "Insert non-message" \\r
171      "echo bad_message | notmuch insert"\r
172  \r
173  test_begin_subtest "Database empty so far"\r
174 @@ -199,7 +199,6 @@ end\r
175  run\r
176  EOF\r
177  test_begin_subtest "error exit when add_message returns $code"\r
178 -test_subtest_known_broken\r
179  gdb --batch-silent --return-child-result -x index-file-$code.gdb \\r
180      --args notmuch insert  < $gen_msg_filename\r
181  test_expect_equal $? 1\r
182 -- \r
183 2.1.0\r
184 \r