Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / c9 / 78b191929910e40d9356b6c522e9252b8fd9a9
1 Return-Path: <jani@nikula.org>\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 2CA17431FC2\r
6         for <notmuch@notmuchmail.org>; Sun, 28 Sep 2014 07:41:11 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.7\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
13         tests=[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 bY31HXN5-c52 for <notmuch@notmuchmail.org>;\r
17         Sun, 28 Sep 2014 07:41:06 -0700 (PDT)\r
18 Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com\r
19         [209.85.212.180]) (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 8A0D4431FBF\r
22         for <notmuch@notmuchmail.org>; Sun, 28 Sep 2014 07:41:06 -0700 (PDT)\r
23 Received: by mail-wi0-f180.google.com with SMTP id q5so1818710wiv.13\r
24         for <notmuch@notmuchmail.org>; Sun, 28 Sep 2014 07:41:05 -0700 (PDT)\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
26         d=1e100.net; s=20130820;\r
27         h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
28         :references:in-reply-to:references;\r
29         bh=YW+Nxie2xerdBnEr05PSaMJt5Yq5ucTNH6q8mM0zOMg=;\r
30         b=hA6rRoWQaf+68Ig6iTZegZcfZBpWCLBQCiDtHXf4rwdCQ6IBE8DIi/f8NcSFh7/vG2\r
31         x4bDDsY8zyDHQ+Hyz4clft4kpTb+LIAMYpVt2S9ZZ7qvIvoXGLXr9OjGuptntwJ6WKJ3\r
32         aKlIS701wBp0S0M89iACDOhhUBb/KFB1fbBsAMXInpCQbZWE8FI3L5qKJD5MEZmKWNWv\r
33         HiBck72zRikXjGQ/ckaCGKRYMhND+geMzC3Hyer2h289GTNF3WlS5VLoa3K6kjWo5X6+\r
34         +pBjXAakSkC0RqsKI20bt1D641+CkeK13yTvmzb2uNQURmnestn0dgBtlDpaObUYljee\r
35         4ESg==\r
36 X-Gm-Message-State:\r
37  ALoCoQngQ53VPER3gS113meSHt7aB5H9knDKtLQ7qrZQCFB84O3Ozesozuu03GIo8IgWKyGQ5H8J\r
38 X-Received: by 10.194.62.107 with SMTP id x11mr4831597wjr.49.1411915265394;\r
39         Sun, 28 Sep 2014 07:41:05 -0700 (PDT)\r
40 Received: from localhost (dsl-hkibrasgw2-58c36c-245.dhcp.inet.fi.\r
41         [88.195.108.245])\r
42         by mx.google.com with ESMTPSA id g6sm12706034wjf.13.2014.09.28.07.41.04\r
43         for <multiple recipients>\r
44         (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
45         Sun, 28 Sep 2014 07:41:04 -0700 (PDT)\r
46 From: Jani Nikula <jani@nikula.org>\r
47 To: notmuch@notmuchmail.org\r
48 Subject: [PATCH v2 1/3] cli/insert: add fail path to add_file_to_database\r
49 Date: Sun, 28 Sep 2014 17:40:57 +0300\r
50 Message-Id:\r
51  <7b0d3b0e7357e2dd87ca48a559e6b7f661c1374c.1411914914.git.jani@nikula.org>\r
52 X-Mailer: git-send-email 2.1.0\r
53 In-Reply-To: <cover.1411914914.git.jani@nikula.org>\r
54 References: <cover.1411914914.git.jani@nikula.org>\r
55 In-Reply-To: <cover.1411914914.git.jani@nikula.org>\r
56 References: <cover.1411914914.git.jani@nikula.org>\r
57 X-BeenThere: notmuch@notmuchmail.org\r
58 X-Mailman-Version: 2.1.13\r
59 Precedence: list\r
60 List-Id: "Use and development of the notmuch mail system."\r
61         <notmuch.notmuchmail.org>\r
62 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
63         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
64 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
65 List-Post: <mailto:notmuch@notmuchmail.org>\r
66 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
67 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
68         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
69 X-List-Received-Date: Sun, 28 Sep 2014 14:41:11 -0000\r
70 \r
71 Handle failures gracefully in add_file_to_database, renamed simply\r
72 add_file while at it. Add keep option to not remove the message from\r
73 database if tagging or tag syncing to maildir flags fails. Expand the\r
74 function documentation to cover the changes.\r
75 ---\r
76  notmuch-insert.c | 99 ++++++++++++++++++++++++++++++++++++--------------------\r
77  1 file changed, 64 insertions(+), 35 deletions(-)\r
78 \r
79 diff --git a/notmuch-insert.c b/notmuch-insert.c\r
80 index 5ef6e66d86e2..0ea438015dbe 100644\r
81 --- a/notmuch-insert.c\r
82 +++ b/notmuch-insert.c\r
83 @@ -364,50 +364,80 @@ FAIL:\r
84      return NULL;\r
85  }\r
86  \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 void\r
90 -add_file_to_database (notmuch_database_t *notmuch, const char *path,\r
91 -                     tag_op_list_t *tag_ops, notmuch_bool_t synchronize_flags)\r
92 +/*\r
93 + * Add the specified message file to the notmuch database, applying\r
94 + * tags in tag_ops. If synchronize_flags is TRUE, the tags are\r
95 + * synchronized to maildir flags (which may result in message file\r
96 + * rename).\r
97 + *\r
98 + * Return NOTMUCH_STATUS_SUCCESS on success, errors otherwise. If keep\r
99 + * is TRUE, errors in tag changes and flag syncing are ignored and\r
100 + * success status is returned; otherwise such errors cause the message\r
101 + * to be removed from the database. Failure to add the message to the\r
102 + * database results in error status regardless of keep.\r
103 + */\r
104 +static notmuch_status_t\r
105 +add_file (notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops,\r
106 +         notmuch_bool_t synchronize_flags, notmuch_bool_t keep)\r
107  {\r
108      notmuch_message_t *message;\r
109      notmuch_status_t status;\r
110  \r
111      status = notmuch_database_add_message (notmuch, path, &message);\r
112 -    switch (status) {\r
113 -    case NOTMUCH_STATUS_SUCCESS:\r
114 -    case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:\r
115 -       break;\r
116 -    default:\r
117 -    case NOTMUCH_STATUS_FILE_NOT_EMAIL:\r
118 -    case NOTMUCH_STATUS_READ_ONLY_DATABASE:\r
119 -    case NOTMUCH_STATUS_XAPIAN_EXCEPTION:\r
120 -    case NOTMUCH_STATUS_OUT_OF_MEMORY:\r
121 -    case NOTMUCH_STATUS_FILE_ERROR:\r
122 -    case NOTMUCH_STATUS_NULL_POINTER:\r
123 -    case NOTMUCH_STATUS_TAG_TOO_LONG:\r
124 -    case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:\r
125 -    case NOTMUCH_STATUS_UNBALANCED_ATOMIC:\r
126 -    case NOTMUCH_STATUS_LAST_STATUS:\r
127 -       fprintf (stderr, "Error: failed to add `%s' to notmuch database: %s\n",\r
128 -                path, notmuch_status_to_string (status));\r
129 -       return;\r
130 -    }\r
131 -\r
132 -    if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {\r
133 -       /* Don't change tags of an existing message. */\r
134 -       if (synchronize_flags) {\r
135 -           status = notmuch_message_tags_to_maildir_flags (message);\r
136 -           if (status != NOTMUCH_STATUS_SUCCESS)\r
137 -               fprintf (stderr, "Error: failed to sync tags to maildir flags\n");\r
138 +    if (status == NOTMUCH_STATUS_SUCCESS) {\r
139 +       status = tag_op_list_apply (message, tag_ops, 0);\r
140 +       if (status) {\r
141 +           fprintf (stderr, "%s: failed to apply tags to file '%s': %s\n",\r
142 +                    keep ? "Warning" : "Error",\r
143 +                    path, notmuch_status_to_string (status));\r
144 +           goto DONE;\r
145         }\r
146 +    } else if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {\r
147 +       status = NOTMUCH_STATUS_SUCCESS;\r
148 +    } else if (status == NOTMUCH_STATUS_FILE_NOT_EMAIL) {\r
149 +       fprintf (stderr, "Error: delivery of non-mail file: '%s'\n", path);\r
150 +       goto FAIL;\r
151      } else {\r
152 -       tag_op_flag_t flags = synchronize_flags ? TAG_FLAG_MAILDIR_SYNC : 0;\r
153 +       fprintf (stderr, "Error: failed to add '%s' to notmuch database: %s\n",\r
154 +                path, notmuch_status_to_string (status));\r
155 +       goto FAIL;\r
156 +    }\r
157  \r
158 -       tag_op_list_apply (message, tag_ops, flags);\r
159 +    if (synchronize_flags) {\r
160 +       status = notmuch_message_tags_to_maildir_flags (message);\r
161 +       if (status != NOTMUCH_STATUS_SUCCESS)\r
162 +           fprintf (stderr, "%s: failed to sync tags to maildir flags for '%s': %s\n",\r
163 +                    keep ? "Warning" : "Error",\r
164 +                    path, notmuch_status_to_string (status));\r
165 +\r
166 +       /*\r
167 +        * Note: Unfortunately a failed maildir flag sync might\r
168 +        * already have renamed the file, in which case the cleanup\r
169 +        * path may fail.\r
170 +        */\r
171      }\r
172  \r
173 +  DONE:\r
174      notmuch_message_destroy (message);\r
175 +\r
176 +    if (status) {\r
177 +       if (keep) {\r
178 +           status = NOTMUCH_STATUS_SUCCESS;\r
179 +       } else {\r
180 +           notmuch_status_t cleanup_status;\r
181 +\r
182 +           cleanup_status = notmuch_database_remove_message (notmuch, path);\r
183 +           if (cleanup_status != NOTMUCH_STATUS_SUCCESS &&\r
184 +               cleanup_status != NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {\r
185 +               fprintf (stderr, "Warning: failed to remove '%s' from database "\r
186 +                        "after errors: %s. Please run 'notmuch new' to fix.\n",\r
187 +                        path, notmuch_status_to_string (cleanup_status));\r
188 +           }\r
189 +       }\r
190 +    }\r
191 +\r
192 +  FAIL:\r
193 +    return status;\r
194  }\r
195  \r
196  int\r
197 @@ -508,8 +538,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
198      /* Add the message to the index.\r
199       * Even if adding the message to the notmuch database fails,\r
200       * the message is on disk and we consider the delivery completed. */\r
201 -    add_file_to_database (notmuch, newpath, tag_ops,\r
202 -                                   synchronize_flags);\r
203 +    add_file (notmuch, newpath, tag_ops, synchronize_flags, TRUE);\r
204  \r
205      notmuch_database_destroy (notmuch);\r
206      return EXIT_SUCCESS;\r
207 -- \r
208 2.1.0\r
209 \r