1 Return-Path: <ethan.glasser.camp@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 02198431FB6
\r
6 for <notmuch@notmuchmail.org>; Mon, 25 Jun 2012 13:42:23 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=1.061 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_BL_SPAMCOP_NET=1.246,
\r
14 RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_SORBS_WEB=0.614] 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 HNCt9uOexQxJ for <notmuch@notmuchmail.org>;
\r
18 Mon, 25 Jun 2012 13:42:22 -0700 (PDT)
\r
19 Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com
\r
20 [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client
\r
21 certificate requested) by olra.theworths.org (Postfix) with ESMTPS id
\r
22 55CEA431FAF for <notmuch@notmuchmail.org>; Mon, 25 Jun 2012 13:42:22 -0700
\r
24 Received: by mail-wg0-f45.google.com with SMTP id dt14so3702167wgb.2
\r
25 for <notmuch@notmuchmail.org>; Mon, 25 Jun 2012 13:42:22 -0700 (PDT)
\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
\r
27 h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references
\r
28 :mime-version:content-type:content-transfer-encoding;
\r
29 bh=y2Aq3cuCvohCZpgJoMJlo6niZDIsTkvXjckBUhToqLo=;
\r
30 b=aMPsBYBAy1u9jtZt+kJhPkIkHsVBKj62Ye1ekrA23+1CFi3dhDlLjZMyP0KA+yQ0Ny
\r
31 2NMYDCwtuia1lEBgrf9YniVmJPe7EG+eXdPGyQaO5Y3mWrzMXk4cLY1wejvgPBOoUrj6
\r
32 8AVJPdH9OnYFFBYPQ441m8hZPLBl3nmfboiWbzJAS+gWINhOHMJiEN8tmFd8cZMNV3mo
\r
33 K7gNwgw8UB82JxgqhZJx4G+ukjUiqWrgWJYnL2CwnvYaesrmL1tx4BeCirnIDbZLZhXi
\r
34 ZLJI56xXx6NoxGDCdZQR6T2sX28405HEOh+x3vsoq3CbOqKANDGAMNm+zQverGjPwpa+
\r
36 Received: by 10.180.8.41 with SMTP id o9mr27141363wia.0.1340656941888;
\r
37 Mon, 25 Jun 2012 13:42:21 -0700 (PDT)
\r
38 Received: from localhost ([195.24.209.21])
\r
39 by mx.google.com with ESMTPS id bg10sm12236082wib.9.2012.06.25.13.42.13
\r
40 (version=TLSv1/SSLv3 cipher=OTHER);
\r
41 Mon, 25 Jun 2012 13:42:20 -0700 (PDT)
\r
42 From: Ethan Glasser-Camp <ethan.glasser.camp@gmail.com>
\r
43 To: notmuch@notmuchmail.org
\r
45 [RFC PATCH 01/14] All access to mail files goes through the mailstore module
\r
46 Date: Mon, 25 Jun 2012 16:41:26 -0400
\r
47 Message-Id: <1340656899-5644-2-git-send-email-ethan@betacantrips.com>
\r
48 X-Mailer: git-send-email 1.7.9.5
\r
49 In-Reply-To: <1340656899-5644-1-git-send-email-ethan@betacantrips.com>
\r
50 References: <1340656899-5644-1-git-send-email-ethan@betacantrips.com>
\r
52 Content-Type: text/plain; charset=UTF-8
\r
53 Content-Transfer-Encoding: 8bit
\r
54 X-Mailman-Approved-At: Tue, 26 Jun 2012 03:51:54 -0700
\r
55 X-BeenThere: notmuch@notmuchmail.org
\r
56 X-Mailman-Version: 2.1.13
\r
58 List-Id: "Use and development of the notmuch mail system."
\r
59 <notmuch.notmuchmail.org>
\r
60 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
61 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
62 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
63 List-Post: <mailto:notmuch@notmuchmail.org>
\r
64 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
65 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
66 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
67 X-List-Received-Date: Mon, 25 Jun 2012 20:42:24 -0000
\r
69 This commit introduces the mailstore module which provides two
\r
70 functions, notmuch_mailstore_open and notmuch_mailstore_close. These
\r
71 functions are currently just stub calls to fopen and fclose, but later
\r
72 can be made more complex in order to support mail storage systems
\r
73 where one message might not be one file.
\r
75 Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com>
\r
77 lib/Makefile.local | 1 +
\r
78 lib/database.cc | 2 +-
\r
80 lib/mailstore.c | 34 ++++++++++++++++++++++++
\r
81 lib/message-file.c | 6 ++---
\r
82 lib/notmuch-private.h | 3 +++
\r
83 lib/notmuch.h | 16 +++++++++++
\r
84 lib/sha1.c | 70 +++++++++++++++++++++++++++++++++++++------------
\r
86 notmuch-show.c | 12 ++++-----
\r
87 10 files changed, 120 insertions(+), 30 deletions(-)
\r
88 create mode 100644 lib/mailstore.c
\r
90 diff --git a/lib/Makefile.local b/lib/Makefile.local
\r
91 index 8a9aa28..cfc77bb 100644
\r
92 --- a/lib/Makefile.local
\r
93 +++ b/lib/Makefile.local
\r
94 @@ -51,6 +51,7 @@ libnotmuch_c_srcs = \
\r
95 $(dir)/filenames.c \
\r
96 $(dir)/string-list.c \
\r
98 + $(dir)/mailstore.c \
\r
99 $(dir)/message-file.c \
\r
100 $(dir)/messages.c \
\r
102 diff --git a/lib/database.cc b/lib/database.cc
\r
103 index 761dc1a..c035edc 100644
\r
104 --- a/lib/database.cc
\r
105 +++ b/lib/database.cc
\r
106 @@ -1773,7 +1773,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
\r
107 if (message_id == NULL ) {
\r
108 /* No message-id at all, let's generate one by taking a
\r
109 * hash over the file's contents. */
\r
110 - char *sha1 = notmuch_sha1_of_file (filename);
\r
111 + char *sha1 = notmuch_sha1_of_message (filename);
\r
113 /* If that failed too, something is really wrong. Give up. */
\r
114 if (sha1 == NULL) {
\r
115 diff --git a/lib/index.cc b/lib/index.cc
\r
116 index e377732..b607e82 100644
\r
119 @@ -441,7 +441,7 @@ _notmuch_message_index_file (notmuch_message_t *message,
\r
123 - file = fopen (filename, "r");
\r
124 + file = notmuch_mailstore_open (filename);
\r
126 fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno));
\r
127 ret = NOTMUCH_STATUS_FILE_ERROR;
\r
128 diff --git a/lib/mailstore.c b/lib/mailstore.c
\r
129 new file mode 100644
\r
130 index 0000000..48acd47
\r
132 +++ b/lib/mailstore.c
\r
134 +/* mailstore.c - code to access individual messages
\r
136 + * Copyright © 2009 Carl Worth
\r
138 + * This program is free software: you can redistribute it and/or modify
\r
139 + * it under the terms of the GNU General Public License as published by
\r
140 + * the Free Software Foundation, either version 3 of the License, or
\r
141 + * (at your option) any later version.
\r
143 + * This program is distributed in the hope that it will be useful,
\r
144 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
145 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
146 + * GNU General Public License for more details.
\r
148 + * You should have received a copy of the GNU General Public License
\r
149 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
151 + * Author: Carl Worth <cworth@cworth.org>
\r
153 +#include <stdio.h>
\r
155 +#include "notmuch-private.h"
\r
158 +notmuch_mailstore_open (const char *filename)
\r
160 + return fopen (filename, "r");
\r
164 +notmuch_mailstore_close (FILE *file)
\r
166 + return fclose (file);
\r
168 diff --git a/lib/message-file.c b/lib/message-file.c
\r
169 index 915aba8..271389c 100644
\r
170 --- a/lib/message-file.c
\r
171 +++ b/lib/message-file.c
\r
172 @@ -86,7 +86,7 @@ _notmuch_message_file_destructor (notmuch_message_file_t *message)
\r
173 g_hash_table_destroy (message->headers);
\r
176 - fclose (message->file);
\r
177 + notmuch_mailstore_close (message->file);
\r
181 @@ -104,7 +104,7 @@ _notmuch_message_file_open_ctx (void *ctx, const char *filename)
\r
183 talloc_set_destructor (message, _notmuch_message_file_destructor);
\r
185 - message->file = fopen (filename, "r");
\r
186 + message->file = notmuch_mailstore_open (filename);
\r
187 if (message->file == NULL)
\r
190 @@ -361,7 +361,7 @@ notmuch_message_file_get_header (notmuch_message_file_t *message,
\r
193 if (message->parsing_finished) {
\r
194 - fclose (message->file);
\r
195 + notmuch_mailstore_close (message->file);
\r
196 message->file = NULL;
\r
199 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
\r
200 index bfb4111..5dbe821 100644
\r
201 --- a/lib/notmuch-private.h
\r
202 +++ b/lib/notmuch-private.h
\r
203 @@ -468,6 +468,9 @@ notmuch_sha1_of_string (const char *str);
\r
205 notmuch_sha1_of_file (const char *filename);
\r
208 +notmuch_sha1_of_message (const char *filename);
\r
210 /* string-list.c */
\r
212 typedef struct _notmuch_string_node {
\r
213 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
214 index 3633bed..0ca367b 100644
\r
215 --- a/lib/notmuch.h
\r
216 +++ b/lib/notmuch.h
\r
217 @@ -1233,6 +1233,22 @@ notmuch_message_thaw (notmuch_message_t *message);
\r
219 notmuch_message_destroy (notmuch_message_t *message);
\r
221 +/* Get access to the underlying data of a message.
\r
223 + * Right now, all messages are simple files in maildirs, but this is
\r
224 + * hopefully subject to change.
\r
226 + * If the returned FILE* is not NULL, be sure to call
\r
227 + * notmuch_mailstore_close when you're done with it.
\r
230 +notmuch_mailstore_open (const char *filename);
\r
232 +/* Release any resources associated with this file.
\r
235 +notmuch_mailstore_close (FILE *file);
\r
237 /* Is the given 'tags' iterator pointing at a valid tag.
\r
239 * When this function returns TRUE, notmuch_tags_get will return a
\r
240 diff --git a/lib/sha1.c b/lib/sha1.c
\r
241 index cc48108..462c07e 100644
\r
244 @@ -64,19 +64,11 @@ notmuch_sha1_of_string (const char *str)
\r
245 return _hex_of_sha1_digest (digest);
\r
248 -/* Create a hexadecimal string version of the SHA-1 digest of the
\r
249 - * contents of the named file.
\r
251 - * This function returns a newly allocated string which the caller
\r
252 - * should free() when finished.
\r
254 - * If any error occurs while reading the file, (permission denied,
\r
255 - * file not found, etc.), this function returns NULL.
\r
256 +/* Internal function to feed the contents of a FILE * to the sha1 functions.
\r
259 -notmuch_sha1_of_file (const char *filename)
\r
264 +_notmuch_sha1_of_filep (FILE *file){
\r
265 #define BLOCK_SIZE 4096
\r
266 unsigned char block[BLOCK_SIZE];
\r
268 @@ -84,14 +76,10 @@ notmuch_sha1_of_file (const char *filename)
\r
269 unsigned char digest[SHA1_DIGEST_SIZE];
\r
272 - file = fopen (filename, "r");
\r
273 - if (file == NULL)
\r
276 sha1_begin (&sha1);
\r
279 - bytes_read = fread (block, 1, 4096, file);
\r
280 + bytes_read = fread (block, 1, BLOCK_SIZE, file);
\r
281 if (bytes_read == 0) {
\r
284 @@ -108,8 +96,56 @@ notmuch_sha1_of_file (const char *filename)
\r
286 result = _hex_of_sha1_digest (digest);
\r
291 +/* Create a hexadecimal string version of the SHA-1 digest of the
\r
292 + * contents of the named file.
\r
294 + * This function returns a newly allocated string which the caller
\r
295 + * should free() when finished.
\r
297 + * If any error occurs while reading the file, (permission denied,
\r
298 + * file not found, etc.), this function returns NULL.
\r
301 +notmuch_sha1_of_file (const char *filename)
\r
305 + file = fopen (filename, "r");
\r
306 + if (file == NULL)
\r
309 + result = _notmuch_sha1_of_filep (file);
\r
316 +/* Create a hexadecimal string version of the SHA-1 digest of the
\r
317 + * contents of the named message, which is accessed via a mailstore.
\r
319 + * This function returns a newly allocated string which the caller
\r
320 + * should free() when finished.
\r
322 + * If any error occurs while reading the file, (permission denied,
\r
323 + * file not found, etc.), this function returns NULL.
\r
326 +notmuch_sha1_of_message (const char *filename)
\r
331 + file = notmuch_mailstore_open (filename);
\r
332 + if (file == NULL)
\r
335 + result = _notmuch_sha1_of_filep (file);
\r
337 + notmuch_mailstore_close (file);
\r
341 diff --git a/mime-node.c b/mime-node.c
\r
342 index 97e8b48..a5c60d0 100644
\r
345 @@ -49,7 +49,7 @@ _mime_node_context_free (mime_node_context_t *res)
\r
346 g_object_unref (res->stream);
\r
349 - fclose (res->file);
\r
350 + notmuch_mailstore_close (res->file);
\r
354 @@ -79,7 +79,7 @@ mime_node_open (const void *ctx, notmuch_message_t *message,
\r
356 talloc_set_destructor (mctx, _mime_node_context_free);
\r
358 - mctx->file = fopen (filename, "r");
\r
359 + mctx->file = notmuch_mailstore_open (filename);
\r
360 if (! mctx->file) {
\r
361 fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno));
\r
362 status = NOTMUCH_STATUS_FILE_ERROR;
\r
363 diff --git a/notmuch-show.c b/notmuch-show.c
\r
364 index 8247f1d..2847d25 100644
\r
365 --- a/notmuch-show.c
\r
366 +++ b/notmuch-show.c
\r
367 @@ -692,7 +692,7 @@ format_part_mbox (const void *ctx, mime_node_t *node, unused (int indent),
\r
368 INTERNAL_ERROR ("format_part_mbox requires a root part");
\r
370 filename = notmuch_message_get_filename (message);
\r
371 - file = fopen (filename, "r");
\r
372 + file = notmuch_mailstore_open (filename);
\r
373 if (file == NULL) {
\r
374 fprintf (stderr, "Failed to open %s: %s\n",
\r
375 filename, strerror (errno));
\r
376 @@ -716,7 +716,7 @@ format_part_mbox (const void *ctx, mime_node_t *node, unused (int indent),
\r
381 + notmuch_mailstore_close (file);
\r
383 return NOTMUCH_STATUS_SUCCESS;
\r
385 @@ -739,7 +739,7 @@ format_part_raw (unused (const void *ctx), mime_node_t *node,
\r
386 return NOTMUCH_STATUS_FILE_ERROR;
\r
389 - file = fopen (filename, "r");
\r
390 + file = notmuch_mailstore_open (filename);
\r
391 if (file == NULL) {
\r
392 fprintf (stderr, "Error: Cannot open file %s: %s\n", filename, strerror (errno));
\r
393 return NOTMUCH_STATUS_FILE_ERROR;
\r
394 @@ -749,18 +749,18 @@ format_part_raw (unused (const void *ctx), mime_node_t *node,
\r
395 size = fread (buf, 1, sizeof (buf), file);
\r
396 if (ferror (file)) {
\r
397 fprintf (stderr, "Error: Read failed from %s\n", filename);
\r
399 + notmuch_mailstore_close (file);
\r
400 return NOTMUCH_STATUS_FILE_ERROR;
\r
403 if (fwrite (buf, size, 1, stdout) != 1) {
\r
404 fprintf (stderr, "Error: Write failed\n");
\r
406 + notmuch_mailstore_close (file);
\r
407 return NOTMUCH_STATUS_FILE_ERROR;
\r
412 + notmuch_mailstore_close (file);
\r
413 return NOTMUCH_STATUS_SUCCESS;
\r