1 Return-Path: <amthrax@drake.mit.edu>
\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 1A1A5429E2F
\r
6 for <notmuch@notmuchmail.org>; Sat, 11 Jun 2011 13:07:06 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 YTonp0oUlZXf for <notmuch@notmuchmail.org>;
\r
16 Sat, 11 Jun 2011 13:07:05 -0700 (PDT)
\r
17 Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id 66688429E2D
\r
20 for <notmuch@notmuchmail.org>; Sat, 11 Jun 2011 13:07:05 -0700 (PDT)
\r
21 X-AuditID: 12074425-b7b82ae000000a2a-92-4df3cad1dd38
\r
22 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])
\r
23 by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id 51.75.02602.1DAC3FD4; Sat, 11 Jun 2011 16:06:41 -0400 (EDT)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id p5BK74c8030852;
\r
27 Sat, 11 Jun 2011 16:07:04 -0400
\r
28 Received: from drake.mit.edu
\r
29 (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com
\r
30 [209.6.116.242]) (authenticated bits=0)
\r
31 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
32 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p5BK73aK006029
\r
33 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
34 Sat, 11 Jun 2011 16:07:04 -0400 (EDT)
\r
35 Received: from amthrax by drake.mit.edu with local (Exim 4.76)
\r
36 (envelope-from <amthrax@drake.mit.edu>)
\r
37 id 1QVUSV-0000IS-PX; Sat, 11 Jun 2011 16:07:03 -0400
\r
38 From: Austin Clements <amdragon@MIT.EDU>
\r
39 To: notmuch@notmuchmail.org
\r
40 Subject: [PATCH 11/17] lib: Add an API to find a message by filename.
\r
41 Date: Sat, 11 Jun 2011 16:04:37 -0400
\r
42 Message-Id: <1307822683-848-12-git-send-email-amdragon@mit.edu>
\r
43 X-Mailer: git-send-email 1.7.5.1
\r
44 In-Reply-To: <1307822683-848-1-git-send-email-amdragon@mit.edu>
\r
45 References: <87ei34rnc5.fsf@yoom.home.cworth.org>
\r
46 <1307822683-848-1-git-send-email-amdragon@mit.edu>
\r
47 X-Brightmail-Tracker:
\r
48 H4sIAAAAAAAAA+NgFtrPIsWRmVeSWpSXmKPExsUixG6nonvx1Gdfgy8zxSyu35zJ7MDo8WzV
\r
49 LeYAxigum5TUnMyy1CJ9uwSujEebD7MXXFeo+HHwI3MD4zPJLkZODgkBE4mD3x4yQ9hiEhfu
\r
50 rWfrYuTiEBLYxyhx6P85dghnA6PE5llzWSCc+0wSH05PYIRw5jNKfNm0khGkn01AQ2Lb/uVg
\r
51 toiAtMTOu7NZuxg5OJgF1CT+dKmAhIUFXCXefAVZwcnBIqAqcWzuVBYQm1fAXmLJ/ntQZyhI
\r
52 XLkyDyzOCRSfd/AqmC0kkCax5NZu9gmM/AsYGVYxyqbkVunmJmbmFKcm6xYnJ+blpRbpWujl
\r
53 ZpbopaaUbmIEh42L6g7GCYeUDjEKcDAq8fAqrv3sK8SaWFZcmXuIUZKDSUmUV+cEUIgvKT+l
\r
54 MiOxOCO+qDQntfgQowQHs5II7/r2T75CvCmJlVWpRfkwKWkOFiVx3vmS6r5CAumJJanZqakF
\r
55 qUUwWRkODiUJXklgfAgJFqWmp1akZeaUIKSZODhBhvMADT96EqiGt7ggMbc4Mx0if4pRl+Px
\r
56 hk2HGIVY8vLzUqXEee+DFAmAFGWU5sHNgcX7K0ZxoLeEeX+AVPEAUwXcpFdAS5iAlgiUgi0p
\r
57 SURISTUwrp9wr6lF48HbJDf+qc08tmV/Dj387j+rj+nqvHRBLe+VXgV/dJzXrA+a0PTohL/E
\r
58 ntmz3pimn1BjvMz/aZbvxe2SZq6JJRcufnT3Eqsze2rcbNO//FQl9+7W95VtDCs9ZvTvaDOY
\r
59 6jdj25+JzxNl/hRrBhxS/HsxanHv7riMH5N0nPZw5x/9pcRSnJFoqMVcVJwIAM6tA4rSAgAA
\r
60 Cc: Austin Clements <amdragon@mit.edu>
\r
61 X-BeenThere: notmuch@notmuchmail.org
\r
62 X-Mailman-Version: 2.1.13
\r
64 List-Id: "Use and development of the notmuch mail system."
\r
65 <notmuch.notmuchmail.org>
\r
66 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
67 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
68 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
69 List-Post: <mailto:notmuch@notmuchmail.org>
\r
70 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
71 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
72 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
73 X-List-Received-Date: Sat, 11 Jun 2011 20:07:06 -0000
\r
75 notmuch_database_find_message_by_filename is mostly stolen from
\r
76 notmuch_database_remove_message, so this patch also vastly simplfies
\r
77 the latter using the former.
\r
79 This API is also useful in its own right and will be used in a later
\r
80 patch for eager maildir flag synchronization.
\r
82 lib/database.cc | 49 ++++++++++++++++++++++++++-----------------------
\r
83 lib/notmuch.h | 16 ++++++++++++++++
\r
84 2 files changed, 42 insertions(+), 23 deletions(-)
\r
86 diff --git a/lib/database.cc b/lib/database.cc
\r
87 index 9886622..daa619d 100644
\r
88 --- a/lib/database.cc
\r
89 +++ b/lib/database.cc
\r
90 @@ -1747,57 +1747,60 @@ notmuch_status_t
\r
91 notmuch_database_remove_message (notmuch_database_t *notmuch,
\r
92 const char *filename)
\r
94 + notmuch_message_t *message =
\r
95 + notmuch_database_find_message_by_filename (notmuch, filename);
\r
96 + notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
\r
99 + status = _notmuch_message_remove_filename (message, filename);
\r
100 + if (status == NOTMUCH_STATUS_SUCCESS)
\r
101 + _notmuch_message_delete (message);
\r
102 + else if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
\r
103 + _notmuch_message_sync (message);
\r
109 +notmuch_message_t *
\r
110 +notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,
\r
111 + const char *filename)
\r
114 const char *prefix = _find_prefix ("file-direntry");
\r
115 char *direntry, *term;
\r
116 Xapian::PostingIterator i, end;
\r
117 - Xapian::Document document;
\r
118 + notmuch_message_t *message = NULL;
\r
119 notmuch_status_t status;
\r
121 - status = _notmuch_database_ensure_writable (notmuch);
\r
125 local = talloc_new (notmuch);
\r
129 status = _notmuch_database_filename_to_direntry (local, notmuch,
\r
130 filename, &direntry);
\r
135 term = talloc_asprintf (local, "%s%s", prefix, direntry);
\r
137 find_doc_ids_for_term (notmuch, term, &i, &end);
\r
139 - for ( ; i != end; i++) {
\r
140 - Xapian::TermIterator j;
\r
141 - notmuch_message_t *message;
\r
143 notmuch_private_status_t private_status;
\r
145 - message = _notmuch_message_create (local, notmuch,
\r
146 + message = _notmuch_message_create (notmuch, notmuch,
\r
147 *i, &private_status);
\r
148 - if (message == NULL)
\r
149 - return COERCE_STATUS (private_status,
\r
150 - "Inconsistent document ID in datbase.");
\r
152 - status = _notmuch_message_remove_filename (message, filename);
\r
153 - if (status == NOTMUCH_STATUS_SUCCESS)
\r
154 - _notmuch_message_delete (message);
\r
155 - else if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
\r
156 - _notmuch_message_sync (message);
\r
158 } catch (const Xapian::Error &error) {
\r
159 - fprintf (stderr, "Error: A Xapian exception occurred removing message: %s\n",
\r
160 + fprintf (stderr, "Error: A Xapian exception occurred finding message by filename: %s\n",
\r
161 error.get_msg().c_str());
\r
162 notmuch->exception_reported = TRUE;
\r
163 - status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
167 talloc_free (local);
\r
173 notmuch_string_list_t *
\r
174 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
175 index 830aa41..9ae260e 100644
\r
176 --- a/lib/notmuch.h
\r
177 +++ b/lib/notmuch.h
\r
178 @@ -356,6 +356,22 @@ notmuch_message_t *
\r
179 notmuch_database_find_message (notmuch_database_t *database,
\r
180 const char *message_id);
\r
182 +/* Find a message with the given filename.
\r
184 + * If the database contains a message with the given filename, then a
\r
185 + * new notmuch_message_t object is returned. The caller should call
\r
186 + * notmuch_message_destroy when done with the message.
\r
188 + * This function returns NULL in the following situations:
\r
190 + * * No message is found with the given filename
\r
191 + * * An out-of-memory situation occurs
\r
192 + * * A Xapian exception occurs
\r
194 +notmuch_message_t *
\r
195 +notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,
\r
196 + const char *filename);
\r
198 /* Return a list of all tags found in the database.
\r
200 * This function creates a list of all tags found in the database. The
\r