Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 9d / 6dae53fd5a278d2847773fb6ddeeda63674fb2
1 Return-Path: <polatel@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 8FF0B431FD0\r
6         for <notmuch@notmuchmail.org>; Thu, 29 Sep 2011 23:47:21 -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: 1.7\r
10 X-Spam-Level: *\r
11 X-Spam-Status: No, score=1.7 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, FREEMAIL_REPLY=2.499, RCVD_IN_DNSWL_LOW=-0.7]\r
14         autolearn=disabled\r
15 Received: from olra.theworths.org ([127.0.0.1])\r
16         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
17         with ESMTP id On99ozF7R-7T for <notmuch@notmuchmail.org>;\r
18         Thu, 29 Sep 2011 23:47:20 -0700 (PDT)\r
19 Received: from mail-fx0-f53.google.com (mail-fx0-f53.google.com\r
20         [209.85.161.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
21         (No client certificate requested)\r
22         by olra.theworths.org (Postfix) with ESMTPS id A2465431FB6\r
23         for <notmuch@notmuchmail.org>; Thu, 29 Sep 2011 23:47:19 -0700 (PDT)\r
24 Received: by fxh2 with SMTP id 2so2766800fxh.26\r
25         for <notmuch@notmuchmail.org>; Thu, 29 Sep 2011 23:47:17 -0700 (PDT)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
27         h=date:from:to:cc:subject:message-id:mail-followup-to:references\r
28         :mime-version:content-type:content-disposition:in-reply-to\r
29         :organization:user-agent;\r
30         bh=9ekuy4Vjd2tLYH+VlnBP5NtLtE+GLEf8HsViLiCTDP0=;\r
31         b=N/mCnz28IW14npGwgodLyDTcZM8SoX1VvK7zoDWzLQsDxo3RiwDhpHOtCI44cxUA2T\r
32         s4zzqtStdMCWG0u24SMg1UvDxbh46h8nZcKZm5C9bEL2KjpvUyvDDdTcX5YAYmzRDa64\r
33         bRArnfOHiGjtHhU/VzdXh22+CwQOYJTmdfFho=\r
34 Received: by 10.223.63.8 with SMTP id z8mr5144200fah.84.1317365237034;\r
35         Thu, 29 Sep 2011 23:47:17 -0700 (PDT)\r
36 Received: from localhost ([78.183.84.0])\r
37         by mx.google.com with ESMTPS id x22sm5423406faa.5.2011.09.29.23.47.14\r
38         (version=TLSv1/SSLv3 cipher=OTHER);\r
39         Thu, 29 Sep 2011 23:47:15 -0700 (PDT)\r
40 Date: Fri, 30 Sep 2011 09:47:12 +0300\r
41 From: Ali Polatel <polatel@gmail.com>\r
42 To: Austin Clements <amdragon@MIT.EDU>\r
43 Subject: Re: Concerns regarding some library functions\r
44 Message-ID: <20110930064712.GA30012@hayalet>\r
45 Mail-Followup-To: Austin Clements <amdragon@MIT.EDU>,\r
46         David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
47 References: <871uv2unfd.fsf@gmail.com> <87fwjhx6p5.fsf@convex-new.cs.unb.ca>\r
48         <20110927224622.GR17905@mit.edu> <877h4tyug1.fsf@gmail.com>\r
49         <20110929145129.GB17905@mit.edu>\r
50 MIME-Version: 1.0\r
51 Content-Type: multipart/signed; micalg=pgp-sha1;\r
52         protocol="application/pgp-signature"; boundary="mYCpIKhGyMATD0i+"\r
53 Content-Disposition: inline\r
54 In-Reply-To: <20110929145129.GB17905@mit.edu>\r
55 Organization: Pink Floyd\r
56 User-Agent: Mutt/1.5.21 (2010-09-15)\r
57 Cc: notmuch@notmuchmail.org\r
58 X-BeenThere: notmuch@notmuchmail.org\r
59 X-Mailman-Version: 2.1.13\r
60 Precedence: list\r
61 List-Id: "Use and development of the notmuch mail system."\r
62         <notmuch.notmuchmail.org>\r
63 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
64         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
65 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
66 List-Post: <mailto:notmuch@notmuchmail.org>\r
67 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
68 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
69         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
70 X-List-Received-Date: Fri, 30 Sep 2011 06:47:21 -0000\r
71 \r
72 \r
73 --mYCpIKhGyMATD0i+\r
74 Content-Type: text/plain; charset=utf-8; format=flowed\r
75 Content-Disposition: inline\r
76 Content-Transfer-Encoding: quoted-printable\r
77 \r
78 Austin Clements yazm=C4=B1=C5=9F:\r
79 >Quoth Ali Polatel on Sep 28 at 10:53 am:\r
80 >> On Tue, 27 Sep 2011 18:46:22 -0400, Austin Clements <amdragon@MIT.EDU> w=\r
81 rote:\r
82 >> > Quoth David Bremner on Sep 27 at  1:59 pm:\r
83 >> > > On Tue, 27 Sep 2011 16:25:58 +0300, Ali Polatel <polatel@gmail.com> =\r
84 wrote:\r
85 >> > >\r
86 >> > > > The problem with their design is NULL return may both mean an error\r
87 >> > > > condition and "message not found". However, we already have a simi=\r
88 lar\r
89 >> > > > function which does not have such a flaw, namely notmuch_database_=\r
90 add_message().\r
91 >> > >\r
92 >> > > So, I take there is no way to distinguish those two outcomes? That d=\r
93 oes\r
94 >> > > sound bad. Looking at the code for notmuch-new, it looks like the re=\r
95 turn\r
96 >> > > value of notmuch_database_find_message_by_filename is used without\r
97 >> > > checking it for NULL.  Austin, can you comment on that at all?\r
98 >> >\r
99 >> > I'd be happy to distinguish these outcomes.  I did\r
100 >> > notmuch_database_find_message_by_filename the way I did only to be\r
101 >> > consistent with notmuch_database_find_message.  Since ndfmbf isn't\r
102 >> > entrenched yet, now is a good time to change it.\r
103 >>\r
104 >> What about notmuch_database_find_message()? If we leave it as it is,\r
105 >> this will lead to inconsistency and if we change it, we need to think\r
106 >> about API breakage issues.\r
107 >\r
108 >Yes.  We could just deal with that (there aren't *that* many API\r
109 >consumers).  For binary compatibility, I suppose we could even use\r
110 >symbol versioning.\r
111 >\r
112 >> > The call in notmuch-new should check the return, though if it can't\r
113 >> > find the message at that point, something has gone terribly wrong.\r
114 >> > Segfaulting is never the answer, though.\r
115 >>\r
116 >> Indeed, just not to step on each other's feet, are you going to write a\r
117 >> patch or shall I start writing one?\r
118 >\r
119 >Please feel free to write a patch.\r
120 \r
121 Below is a quick patch, which compiles and passes tests.\r
122 Please comment.\r
123 \r
124          -alip\r
125 \r
126 -- >8 --\r
127 Subject: [PATCH] lib: make find_message{,by_filename) report errors\r
128 \r
129 Previously, the functions notmuch_database_find_message() and\r
130 notmuch_database_find_message_by_filename() functions did not properly\r
131 report error condition to the library user.\r
132 \r
133 For more information, read the thread on the notmuch mailing list\r
134 starting with my mail "id:871uv2unfd.fsf@gmail.com"\r
135 \r
136 Make these functions accept a pointer to 'notmuch_message_t' as argument\r
137 and return notmuch_status_t which may be used to check for any error\r
138 condition.\r
139 \r
140 restore: Modify for the new notmuch_database_find_message()\r
141 new: Modify for the new notmuch_database_find_message_by_filename()\r
142 ---\r
143   lib/database.cc   |   89 ++++++++++++++++++++++++++++++++++--------------=\r
144 ----\r
145   lib/message.cc    |    6 ++--\r
146   lib/notmuch.h     |   61 +++++++++++++++++++++++++-----------\r
147   notmuch-new.c     |    4 ++-\r
148   notmuch-restore.c |   11 ++++--\r
149   5 files changed, 114 insertions(+), 57 deletions(-)\r
150 \r
151 diff --git a/lib/database.cc b/lib/database.cc\r
152 index 9299c8d..6641aa5 100644\r
153 --- a/lib/database.cc\r
154 +++ b/lib/database.cc\r
155 @@ -360,13 +360,17 @@ _message_id_compressed (void *ctx, const char *messag=\r
156 e_id)\r
157       return compressed;\r
158   }\r
159  =20\r
160 -notmuch_message_t *\r
161 +notmuch_status_t\r
162   notmuch_database_find_message (notmuch_database_t *notmuch,\r
163 -                              const char *message_id)\r
164 +                              const char *message_id,\r
165 +                              notmuch_message_t **message)\r
166   {\r
167       notmuch_private_status_t status;\r
168       unsigned int doc_id;\r
169  =20\r
170 +    if (message =3D=3D NULL)\r
171 +           return NOTMUCH_STATUS_NULL_POINTER;\r
172 +\r
173       if (strlen (message_id) > NOTMUCH_MESSAGE_ID_MAX)\r
174         message_id =3D _message_id_compressed (notmuch, message_id);\r
175  =20\r
176 @@ -375,14 +379,20 @@ notmuch_database_find_message (notmuch_database_t *no=\r
177 tmuch,\r
178                                                        message_id, &doc_id);\r
179  =20\r
180         if (status =3D=3D NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND)\r
181 -           return NULL;\r
182 +           *message =3D NULL;\r
183 +       else {\r
184 +           *message =3D _notmuch_message_create (notmuch, notmuch, doc_id, NULL);\r
185 +           if (*message =3D=3D NULL)\r
186 +                   return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
187 +       }\r
188  =20\r
189 -       return _notmuch_message_create (notmuch, notmuch, doc_id, NULL);\r
190 +       return NOTMUCH_STATUS_SUCCESS;\r
191       } catch (const Xapian::Error &error) {\r
192         fprintf (stderr, "A Xapian exception occurred finding message: %s.\n",\r
193                  error.get_msg().c_str());\r
194         notmuch->exception_reported =3D TRUE;\r
195 -       return NULL;\r
196 +       *message =3D NULL;\r
197 +       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
198       }\r
199   }\r
200  =20\r
201 @@ -1311,7 +1321,8 @@ _get_metadata_thread_id_key (void *ctx, const char *m=\r
202 essage_id)\r
203  =20\r
204   /* Find the thread ID to which the message with 'message_id' belongs.\r
205    *\r
206 - * Always returns a newly talloced string belonging to 'ctx'.\r
207 + * Note: 'thread_id' must not be NULL!\r
208 + * On success '*thread_id' is set to a newly talloced string belonging to =\r
209 'ctx'.\r
210    *\r
211    * Note: If there is no message in the database with the given\r
212    * 'message_id' then a new thread_id will be allocated for this\r
213 @@ -1319,25 +1330,29 @@ _get_metadata_thread_id_key (void *ctx, const char =\r
214 *message_id)\r
215    * thread ID can be looked up if the message is added to the database\r
216    * later).\r
217    */\r
218 -static const char *\r
219 +static notmuch_status_t\r
220   _resolve_message_id_to_thread_id (notmuch_database_t *notmuch,\r
221                                   void *ctx,\r
222 -                                 const char *message_id)\r
223 +                                 const char *message_id,\r
224 +                                 const char **thread_id)\r
225   {\r
226 +    notmuch_status_t status;\r
227       notmuch_message_t *message;\r
228       string thread_id_string;\r
229 -    const char *thread_id;\r
230       char *metadata_key;\r
231       Xapian::WritableDatabase *db;\r
232  =20\r
233 -    message =3D notmuch_database_find_message (notmuch, message_id);\r
234 +    status =3D notmuch_database_find_message (notmuch, message_id, &messag=\r
235 e);\r
236 +\r
237 +    if (status)\r
238 +       return status;\r
239  =20\r
240       if (message) {\r
241 -       thread_id =3D talloc_steal (ctx, notmuch_message_get_thread_id (message));\r
242 +       *thread_id =3D talloc_steal (ctx, notmuch_message_get_thread_id (message)=\r
243 );\r
244  =20\r
245         notmuch_message_destroy (message);\r
246  =20\r
247 -       return thread_id;\r
248 +       return NOTMUCH_STATUS_SUCCESS;\r
249       }\r
250  =20\r
251       /* Message has not been seen yet.\r
252 @@ -1351,15 +1366,15 @@ _resolve_message_id_to_thread_id (notmuch_database_=\r
253 t *notmuch,\r
254       thread_id_string =3D notmuch->xapian_db->get_metadata (metadata_key);\r
255  =20\r
256       if (thread_id_string.empty()) {\r
257 -       thread_id =3D _notmuch_database_generate_thread_id (notmuch);\r
258 -       db->set_metadata (metadata_key, thread_id);\r
259 +       *thread_id =3D talloc_strdup(ctx, _notmuch_database_generate_thread_id (n=\r
260 otmuch));\r
261 +       db->set_metadata (metadata_key, *thread_id);\r
262       } else {\r
263 -       thread_id =3D thread_id_string.c_str();\r
264 +       *thread_id =3D talloc_strdup(ctx, thread_id_string.c_str());\r
265       }\r
266  =20\r
267       talloc_free (metadata_key);\r
268  =20\r
269 -    return talloc_strdup (ctx, thread_id);\r
270 +    return NOTMUCH_STATUS_SUCCESS;\r
271   }\r
272  =20\r
273   static notmuch_status_t\r
274 @@ -1446,9 +1461,12 @@ _notmuch_database_link_message_to_parents (notmuch_d=\r
275 atabase_t *notmuch,\r
276         _notmuch_message_add_term (message, "reference",\r
277                                    parent_message_id);\r
278  =20\r
279 -       parent_thread_id =3D _resolve_message_id_to_thread_id (notmuch,\r
280 -                                                            message,\r
281 -                                                            parent_message_id);\r
282 +       ret =3D _resolve_message_id_to_thread_id (notmuch,\r
283 +                                               message,\r
284 +                                               parent_message_id,\r
285 +                                               &parent_thread_id);\r
286 +       if (ret)\r
287 +           goto DONE;\r
288  =20\r
289         if (*thread_id =3D=3D NULL) {\r
290             *thread_id =3D talloc_strdup (message, parent_thread_id);\r
291 @@ -1759,11 +1777,12 @@ notmuch_status_t\r
292   notmuch_database_remove_message (notmuch_database_t *notmuch,\r
293                                  const char *filename)\r
294   {\r
295 -    notmuch_message_t *message =3D\r
296 -       notmuch_database_find_message_by_filename (notmuch, filename);\r
297 -    notmuch_status_t status =3D NOTMUCH_STATUS_SUCCESS;\r
298 +    notmuch_status_t status;\r
299 +    notmuch_message_t *message;\r
300  =20\r
301 -    if (message) {\r
302 +    status =3D notmuch_database_find_message_by_filename (notmuch, filenam=\r
303 e, &message);\r
304 +\r
305 +    if (status =3D=3D NOTMUCH_STATUS_SUCCESS && message) {\r
306             status =3D _notmuch_message_remove_filename (message, filename);\r
307             if (status =3D=3D NOTMUCH_STATUS_SUCCESS)\r
308                 _notmuch_message_delete (message);\r
309 @@ -1774,24 +1793,27 @@ notmuch_database_remove_message (notmuch_database_t=\r
310  *notmuch,\r
311       return status;\r
312   }\r
313  =20\r
314 -notmuch_message_t *\r
315 +notmuch_status_t\r
316   notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,\r
317 -                                          const char *filename)\r
318 +                                          const char *filename,\r
319 +                                          notmuch_message_t **message)\r
320   {\r
321       void *local;\r
322       const char *prefix =3D _find_prefix ("file-direntry");\r
323       char *direntry, *term;\r
324       Xapian::PostingIterator i, end;\r
325 -    notmuch_message_t *message =3D NULL;\r
326       notmuch_status_t status;\r
327  =20\r
328 +    if (message =3D=3D NULL)\r
329 +           return NOTMUCH_STATUS_NULL_POINTER;\r
330 +\r
331       local =3D talloc_new (notmuch);\r
332  =20\r
333       try {\r
334         status =3D _notmuch_database_filename_to_direntry (local, notmuch,\r
335                                                          filename, &direntry);\r
336         if (status)\r
337 -           return NULL;\r
338 +           goto DONE;\r
339  =20\r
340         term =3D talloc_asprintf (local, "%s%s", prefix, direntry);\r
341  =20\r
342 @@ -1800,19 +1822,24 @@ notmuch_database_find_message_by_filename (notmuch_=\r
343 database_t *notmuch,\r
344         if (i !=3D end) {\r
345             notmuch_private_status_t private_status;\r
346  =20\r
347 -           message =3D _notmuch_message_create (notmuch, notmuch,\r
348 -                                              *i, &private_status);\r
349 +           *message =3D _notmuch_message_create (notmuch, notmuch,\r
350 +                                               *i, &private_status);\r
351 +           if (*message =3D=3D NULL)\r
352 +                   status =3D NOTMUCH_STATUS_OUT_OF_MEMORY;\r
353         }\r
354       } catch (const Xapian::Error &error) {\r
355         fprintf (stderr, "Error: A Xapian exception occurred finding message by =\r
356 filename: %s\n",\r
357                  error.get_msg().c_str());\r
358         notmuch->exception_reported =3D TRUE;\r
359 -       message =3D NULL;\r
360 +       status =3D NOTMUCH_STATUS_OUT_OF_MEMORY;\r
361       }\r
362  =20\r
363 +  DONE:\r
364       talloc_free (local);\r
365  =20\r
366 -    return message;\r
367 +    if (status)\r
368 +           *message =3D NULL;\r
369 +    return status;\r
370   }\r
371  =20\r
372   notmuch_string_list_t *\r
373 diff --git a/lib/message.cc b/lib/message.cc\r
374 index 531d304..2a85744 100644\r
375 --- a/lib/message.cc\r
376 +++ b/lib/message.cc\r
377 @@ -216,11 +216,11 @@ _notmuch_message_create_for_message_id (notmuch_datab=\r
378 ase_t *notmuch,\r
379       unsigned int doc_id;\r
380       char *term;\r
381  =20\r
382 -    *status_ret =3D NOTMUCH_PRIVATE_STATUS_SUCCESS;\r
383 -\r
384 -    message =3D notmuch_database_find_message (notmuch, message_id);\r
385 +    *status_ret =3D (notmuch_private_status_t) notmuch_database_find_messa=\r
386 ge (notmuch, message_id, &message);\r
387       if (message)\r
388         return talloc_steal (notmuch, message);\r
389 +    else if (*status_ret)\r
390 +       return NULL;\r
391  =20\r
392       term =3D talloc_asprintf (NULL, "%s%s",\r
393                             _find_prefix ("id"), message_id);\r
394 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
395 index 6d7a99f..08b4ce2 100644\r
396 --- a/lib/notmuch.h\r
397 +++ b/lib/notmuch.h\r
398 @@ -347,35 +347,60 @@ notmuch_database_remove_message (notmuch_database_t *=\r
399 database,\r
400  =20\r
401   /* Find a message with the given message_id.\r
402    *\r
403 - * If the database contains a message with the given message_id, then\r
404 - * a new notmuch_message_t object is returned. The caller should call\r
405 - * notmuch_message_destroy when done with the message.\r
406 + * If message with the given message_id is found then, on successful return\r
407 + * (NOTMUCH_STATUS_SUCCESS) '*message' will be initialized to a message ob=\r
408 ject.\r
409 + * The user should call notmuch_message_destroy when done with the message.\r
410    *\r
411 - * This function returns NULL in the following situations:\r
412 + * On any failure or when the message is not found, this function initiali=\r
413 zes\r
414 + * '*message' to NULL. This means, when NOTMUCH_STATUS_SUCCESS is returned=\r
415 , the\r
416 + * user is supposed to check '*message' for NULL to find out whether the\r
417 + * message with the given message_id was found.\r
418    *\r
419 - *     * No message is found with the given message_id\r
420 - *     * An out-of-memory situation occurs\r
421 - *     * A Xapian exception occurs\r
422 + * Note: The argument 'message' must not be NULL!\r
423 + *\r
424 + * Return value:\r
425 + *\r
426 + * NOTMUCH_STATUS_SUCCESS: Successful return, check '*message'.\r
427 + *\r
428 + * NOTMUCH_STATUS_NULL_POINTER: The given 'message' argument is NULL\r
429 + *\r
430 + * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory, creating message object\r
431 + *\r
432 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred\r
433    */\r
434 -notmuch_message_t *\r
435 +notmuch_status_t\r
436   notmuch_database_find_message (notmuch_database_t *database,\r
437 -                              const char *message_id);\r
438 +                              const char *message_id,\r
439 +                              notmuch_message_t **message);\r
440  =20\r
441   /* Find a message with the given filename.\r
442    *\r
443 - * If the database contains a message with the given filename, then a\r
444 - * new notmuch_message_t object is returned.  The caller should call=20\r
445 - * notmuch_message_destroy when done with the message.\r
446 + * If the database contains a message with the given filename then, on\r
447 + * successful return (NOTMUCH_STATUS_SUCCESS) '*message' will be initializ=\r
448 ed to\r
449 + * a message object. The user should call notmuch_message_destroy when done\r
450 + * with the message.\r
451    *\r
452 - * This function returns NULL in the following situations:\r
453 + * On any failure or when the message is not found, this function initiali=\r
454 zes\r
455 + * '*message' to NULL. This means, when NOTMUCH_STATUS_SUCCESS is returned=\r
456 , the\r
457 + * user is supposed to check '*message' for NULL to find out whether the\r
458 + * message with the given filename is found.\r
459    *\r
460 - *     * No message is found with the given filename\r
461 - *     * An out-of-memory situation occurs\r
462 - *     * A Xapian exception occurs\r
463 + * Note: The argument 'message' must not be NULL!\r
464 + *\r
465 + * Return value:\r
466 + *\r
467 + * NOTMUCH_STATUS_SUCCESS: Successful return, check '*message'\r
468 + *\r
469 + * NOTMUCH_STATUS_NULL_POINTER: The given 'message' argument is NULL\r
470 + *\r
471 + * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory, creating the message object\r
472 + *\r
473 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred\r
474    */\r
475 -notmuch_message_t *\r
476 +notmuch_status_t\r
477   notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,\r
478 -                                          const char *filename);\r
479 +                                          const char *filename,\r
480 +                                          notmuch_message_t **message);\r
481  =20\r
482   /* Return a list of all tags found in the database.\r
483    *\r
484 diff --git a/notmuch-new.c b/notmuch-new.c\r
485 index e79593c..96a1e31 100644\r
486 --- a/notmuch-new.c\r
487 +++ b/notmuch-new.c\r
488 @@ -743,7 +743,9 @@ remove_filename (notmuch_database_t *notmuch,\r
489       status =3D notmuch_database_begin_atomic (notmuch);\r
490       if (status)\r
491         return status;\r
492 -    message =3D notmuch_database_find_message_by_filename (notmuch, path);\r
493 +    status =3D notmuch_database_find_message_by_filename (notmuch, path, &=\r
494 message);\r
495 +    if (status || message =3D=3D NULL)\r
496 +       return status;\r
497       status =3D notmuch_database_remove_message (notmuch, path);\r
498       if (status =3D=3D NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {\r
499         add_files_state->renamed_messages++;\r
500 diff --git a/notmuch-restore.c b/notmuch-restore.c\r
501 index f095f64..3b0ae71 100644\r
502 --- a/notmuch-restore.c\r
503 +++ b/notmuch-restore.c\r
504 @@ -87,10 +87,13 @@ notmuch_restore_command (unused (void *ctx), int argc, =\r
505 char *argv[])\r
506         file_tags =3D xstrndup (line + match[2].rm_so,\r
507                               match[2].rm_eo - match[2].rm_so);\r
508  =20\r
509 -       message =3D notmuch_database_find_message (notmuch, message_id);\r
510 -       if (message =3D=3D NULL) {\r
511 -           fprintf (stderr, "Warning: Cannot apply tags to missing message: %s\n=\r
512 ",\r
513 -                    message_id);\r
514 +       status =3D notmuch_database_find_message (notmuch, message_id, &message);\r
515 +       if (status || message =3D=3D NULL) {\r
516 +           fprintf (stderr, "Warning: Cannot apply tags to %smessage: %s\n",\r
517 +                    message ? "" : "missing ", message_id);\r
518 +           if (status)\r
519 +                   fprintf (stderr, "%s\n",\r
520 +                            notmuch_status_to_string(status));\r
521             goto NEXT_LINE;\r
522         }\r
523  =20\r
524 --=20\r
525 1.7.6.1\r
526 \r
527 --mYCpIKhGyMATD0i+\r
528 Content-Type: application/pgp-signature\r
529 \r
530 -----BEGIN PGP SIGNATURE-----\r
531 Version: GnuPG v2.0.18 (GNU/Linux)\r
532 \r
533 iEYEARECAAYFAk6FZfAACgkQQU4yORhF8iDwZACgroTylz80BdwAwFPMU27a7svv\r
534 IqEAoIBDNgFG5/DltzS29qIKUeJ+QWbs\r
535 =K7FZ\r
536 -----END PGP SIGNATURE-----\r
537 \r
538 --mYCpIKhGyMATD0i+--\r