1 Return-Path: <sojkam1@fel.cvut.cz>
\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 213D541733F
\r
6 for <notmuch@notmuchmail.org>; Sat, 27 Mar 2010 13:44:42 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5
\r
12 tests=[BAYES_00=-1.9] autolearn=ham
\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 cGwBzSnYHH9O for <notmuch@notmuchmail.org>;
\r
16 Sat, 27 Mar 2010 13:44:38 -0700 (PDT)
\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])
\r
18 by olra.theworths.org (Postfix) with ESMTP id EA52B4196F5
\r
19 for <notmuch@notmuchmail.org>; Sat, 27 Mar 2010 13:44:33 -0700 (PDT)
\r
20 Received: from localhost (unknown [192.168.200.4])
\r
21 by max.feld.cvut.cz (Postfix) with ESMTP id 514A419F3419;
\r
22 Sat, 27 Mar 2010 21:44:33 +0100 (CET)
\r
23 X-Virus-Scanned: IMAP AMAVIS
\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])
\r
25 by localhost (styx.feld.cvut.cz [192.168.200.4]) (amavisd-new,
\r
27 with ESMTP id VRT1Ad0wrKIy; Sat, 27 Mar 2010 21:44:31 +0100 (CET)
\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])
\r
29 by max.feld.cvut.cz (Postfix) with ESMTP id 82D0519F341C;
\r
30 Sat, 27 Mar 2010 21:44:31 +0100 (CET)
\r
31 Received: from steelpick.2x.cz (r5da224.net.upc.cz [86.49.116.224])
\r
32 (Authenticated sender: sojkam1)
\r
33 by imap.feld.cvut.cz (Postfix) with ESMTPSA id 46B73FA006;
\r
34 Sat, 27 Mar 2010 21:44:31 +0100 (CET)
\r
35 Received: from wsh by steelpick.2x.cz with local (Exim 4.71)
\r
36 (envelope-from <sojkam1@fel.cvut.cz>)
\r
37 id 1Nvcru-0001ny-4U; Sat, 27 Mar 2010 21:44:30 +0100
\r
38 From: Michal Sojka <sojkam1@fel.cvut.cz>
\r
39 To: notmuch@notmuchmail.org
\r
40 Date: Sat, 27 Mar 2010 21:44:20 +0100
\r
41 Message-Id: <1269722661-6894-5-git-send-email-sojkam1@fel.cvut.cz>
\r
42 X-Mailer: git-send-email 1.7.0.2
\r
43 In-Reply-To: <8739zlijhp.fsf@steelpick.2x.cz>
\r
44 References: <8739zlijhp.fsf@steelpick.2x.cz>
\r
45 Subject: [notmuch] [PATCH v3 5/6] Access messages through mail store
\r
47 X-BeenThere: notmuch@notmuchmail.org
\r
48 X-Mailman-Version: 2.1.13
\r
50 List-Id: "Use and development of the notmuch mail system."
\r
51 <notmuch.notmuchmail.org>
\r
52 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
53 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
54 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
55 List-Post: <mailto:notmuch@notmuchmail.org>
\r
56 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
57 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
58 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
59 X-List-Received-Date: Sat, 27 Mar 2010 20:44:42 -0000
\r
61 This patch modifies notmuch binary to access the messages through mail
\r
62 store interface, so that non-file based mail stores can also be
\r
65 The API of notmuch library was changed. Now,
\r
66 notmuch_message_get_filename() returns relative file name with respect
\r
67 to the database path. As a result, notmuch show also outputs relative
\r
68 paths so that MUAs need to be changed.
\r
70 Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
\r
72 lib/database.cc | 14 +++++++++++---
\r
73 lib/index.cc | 8 ++++++--
\r
74 lib/mailstore-files.c | 24 +++++++++++++++++-------
\r
75 lib/message-file.c | 8 ++++----
\r
76 lib/message.cc | 33 +++++++++++++++++++++++++--------
\r
77 lib/notmuch-private.h | 6 +++---
\r
78 lib/notmuch.h | 16 ++++++++++++++--
\r
79 lib/sha1.c | 6 +-----
\r
80 notmuch-client.h | 2 +-
\r
81 notmuch-reply.c | 10 +++++++++-
\r
82 notmuch-show.c | 14 ++++++++++++--
\r
83 show-message.c | 14 +-------------
\r
84 12 files changed, 104 insertions(+), 51 deletions(-)
\r
86 diff --git a/lib/database.cc b/lib/database.cc
\r
87 index 33ef889..4f3ce88 100644
\r
88 --- a/lib/database.cc
\r
89 +++ b/lib/database.cc
\r
90 @@ -1374,6 +1374,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
\r
91 notmuch_message_t *message = NULL;
\r
92 notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
\r
93 notmuch_private_status_t private_status;
\r
94 + const char *relative;
\r
96 const char *date, *header;
\r
97 const char *from, *to, *subject;
\r
98 @@ -1386,7 +1387,8 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
\r
102 - message_file = notmuch_message_file_open (filename);
\r
103 + relative = _notmuch_database_relative_path (notmuch, filename);
\r
104 + message_file = notmuch_message_file_open (notmuch->mailstore, relative);
\r
105 if (message_file == NULL)
\r
106 return NOTMUCH_STATUS_FILE_ERROR;
\r
108 @@ -1438,9 +1440,15 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
\r
111 if (message_id == NULL ) {
\r
113 + char *sha1 = NULL;
\r
114 /* No message-id at all, let's generate one by taking a
\r
115 * hash over the file's contents. */
\r
116 - char *sha1 = notmuch_sha1_of_file (filename);
\r
117 + file = notmuch_mailstore_open_file (notmuch->mailstore, relative);
\r
119 + sha1 = notmuch_sha1_of_file (file);
\r
123 /* If that failed too, something is really wrong. Give up. */
\r
124 if (sha1 == NULL) {
\r
125 @@ -1490,7 +1498,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
\r
126 date = notmuch_message_file_get_header (message_file, "date");
\r
127 _notmuch_message_set_date (message, date);
\r
129 - _notmuch_message_index_file (message, filename);
\r
130 + _notmuch_message_index_file (message, relative);
\r
132 ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
\r
134 diff --git a/lib/index.cc b/lib/index.cc
\r
135 index cf93025..4d8c4dd 100644
\r
138 @@ -425,15 +425,19 @@ _notmuch_message_index_file (notmuch_message_t *message,
\r
139 const char *from, *subject;
\r
140 notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
\r
141 static int initialized = 0;
\r
142 + notmuch_mailstore_t *mailstore;
\r
144 if (! initialized) {
\r
149 - file = fopen (filename, "r");
\r
150 + mailstore = notmuch_message_get_mailstore(message);
\r
151 + file = notmuch_mailstore_open_file (mailstore, filename);
\r
153 - fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno));
\r
154 + fprintf (stderr, "Error opening %s: %s\n",
\r
155 + notmuch_message_get_filename (message),
\r
156 + strerror (errno));
\r
157 ret = NOTMUCH_STATUS_FILE_ERROR;
\r
160 diff --git a/lib/mailstore-files.c b/lib/mailstore-files.c
\r
161 index b4e6e42..0250dba 100644
\r
162 --- a/lib/mailstore-files.c
\r
163 +++ b/lib/mailstore-files.c
\r
164 @@ -246,9 +246,10 @@ maildir_sync_tags (notmuch_mailstore_t *mailstore,
\r
165 notmuch_message_t *message)
\r
167 char flags[ARRAY_SIZE(flag2tag)+1];
\r
168 - const char *filename, *p;
\r
169 + const char *filename, *p, *db_path;
\r
170 char *filename_new, *subdir = NULL;
\r
172 + char *abs1, *abs2;
\r
175 get_new_flags (message, flags);
\r
176 @@ -273,11 +274,16 @@ maildir_sync_tags (notmuch_mailstore_t *mailstore,
\r
177 strcpy (filename_new+(p-filename)+3, flags);
\r
179 if (strcmp (filename, filename_new) != 0) {
\r
180 - ret = rename (filename, filename_new);
\r
181 + db_path = notmuch_database_get_path (mailstore->notmuch);
\r
182 + asprintf(&abs1, "%s/%s", db_path, filename);
\r
183 + asprintf(&abs2, "%s/%s", db_path, filename_new);
\r
184 + ret = rename (abs1, abs2);
\r
186 - perror (talloc_asprintf (message, "rename of %s to %s failed", filename, filename_new));
\r
187 + perror (talloc_asprintf (message, "rename of %s to %s failed", abs1, abs2));
\r
192 return _notmuch_message_rename (message, filename_new);
\r
193 /* _notmuch_message_sync is our caller. Do not call it here. */
\r
195 @@ -782,13 +788,17 @@ index_new(notmuch_mailstore_t *mailstore, const char* path,
\r
197 open_file(notmuch_mailstore_t *mailstore, const char *filename)
\r
199 - const char *db_path, *abs_filename;
\r
201 + const char *db_path;
\r
202 + char *abs_filename;
\r
205 db_path = notmuch_database_get_path(mailstore->notmuch);
\r
206 - abs_filename = talloc_asprintf(mailstore, "%s/%s", db_path, filename);
\r
207 + abs_filename = talloc_asprintf(NULL, "%s/%s", db_path, filename);
\r
208 if (unlikely(abs_filename == NULL))
\r
210 - return fopen (abs_filename, "r");
\r
211 + file = fopen (abs_filename, "r");
\r
212 + talloc_free(abs_filename);
\r
216 struct mailstore_priv files_priv = {
\r
217 diff --git a/lib/message-file.c b/lib/message-file.c
\r
218 index 3a1a681..5752e69 100644
\r
219 --- a/lib/message-file.c
\r
220 +++ b/lib/message-file.c
\r
221 @@ -94,7 +94,7 @@ _notmuch_message_file_destructor (notmuch_message_file_t *message)
\r
222 /* Create a new notmuch_message_file_t for 'filename' with 'ctx' as
\r
223 * the talloc owner. */
\r
224 notmuch_message_file_t *
\r
225 -_notmuch_message_file_open_ctx (void *ctx, const char *filename)
\r
226 +_notmuch_message_file_open_ctx (void *ctx, notmuch_mailstore_t *mailstore, const char *filename)
\r
228 notmuch_message_file_t *message;
\r
230 @@ -104,7 +104,7 @@ _notmuch_message_file_open_ctx (void *ctx, const char *filename)
\r
232 talloc_set_destructor (message, _notmuch_message_file_destructor);
\r
234 - message->file = fopen (filename, "r");
\r
235 + message->file = notmuch_mailstore_open_file(mailstore, filename);
\r
236 if (message->file == NULL)
\r
239 @@ -126,9 +126,9 @@ _notmuch_message_file_open_ctx (void *ctx, const char *filename)
\r
242 notmuch_message_file_t *
\r
243 -notmuch_message_file_open (const char *filename)
\r
244 +notmuch_message_file_open (notmuch_mailstore_t *mailstore, const char *filename)
\r
246 - return _notmuch_message_file_open_ctx (NULL, filename);
\r
247 + return _notmuch_message_file_open_ctx (NULL, mailstore, filename);
\r
251 diff --git a/lib/message.cc b/lib/message.cc
\r
252 index 51208ba..292e95e 100644
\r
253 --- a/lib/message.cc
\r
254 +++ b/lib/message.cc
\r
255 @@ -247,6 +247,7 @@ static void
\r
256 _notmuch_message_ensure_message_file (notmuch_message_t *message)
\r
258 const char *filename;
\r
259 + notmuch_mailstore_t *mailstore;
\r
261 if (message->message_file)
\r
263 @@ -255,7 +256,9 @@ _notmuch_message_ensure_message_file (notmuch_message_t *message)
\r
264 if (unlikely (filename == NULL))
\r
267 - message->message_file = _notmuch_message_file_open_ctx (message, filename);
\r
268 + mailstore = notmuch_message_get_mailstore (message);
\r
270 + message->message_file = _notmuch_message_file_open_ctx (message, mailstore, filename);
\r
274 @@ -429,7 +432,7 @@ notmuch_message_get_filename (notmuch_message_t *message)
\r
275 int prefix_len = strlen (prefix);
\r
276 Xapian::TermIterator i;
\r
277 char *colon, *direntry = NULL;
\r
278 - const char *db_path, *directory, *basename;
\r
279 + const char *directory, *basename;
\r
280 unsigned int directory_id;
\r
281 void *local = talloc_new (message);
\r
283 @@ -474,18 +477,16 @@ notmuch_message_get_filename (notmuch_message_t *message)
\r
287 - db_path = notmuch_database_get_path (message->notmuch);
\r
289 directory = _notmuch_database_get_directory_path (local,
\r
293 if (strlen (directory))
\r
294 - message->filename = talloc_asprintf (message, "%s/%s/%s",
\r
295 - db_path, directory, basename);
\r
297 message->filename = talloc_asprintf (message, "%s/%s",
\r
298 - db_path, basename);
\r
299 + directory, basename);
\r
301 + message->filename = talloc_asprintf (message, "%s",
\r
303 talloc_free ((void *) directory);
\r
305 talloc_free (local);
\r
306 @@ -493,6 +494,22 @@ notmuch_message_get_filename (notmuch_message_t *message)
\r
307 return message->filename;
\r
311 +notmuch_message_fopen (notmuch_message_t *message)
\r
313 + const char *filename;
\r
314 + filename = notmuch_message_get_filename (message);
\r
315 + return notmuch_mailstore_open_file (message->notmuch->mailstore,
\r
319 +notmuch_mailstore_t *
\r
320 +notmuch_message_get_mailstore (notmuch_message_t *message)
\r
322 + return message->notmuch->mailstore;
\r
327 notmuch_message_get_flag (notmuch_message_t *message,
\r
328 notmuch_message_flag_t flag)
\r
329 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
\r
330 index 63e75ec..c257365 100644
\r
331 --- a/lib/notmuch-private.h
\r
332 +++ b/lib/notmuch-private.h
\r
333 @@ -299,11 +299,11 @@ typedef struct _notmuch_message_file notmuch_message_file_t;
\r
334 * Returns NULL if any error occurs.
\r
336 notmuch_message_file_t *
\r
337 -notmuch_message_file_open (const char *filename);
\r
338 +notmuch_message_file_open (notmuch_mailstore_t *mailstore, const char *filename);
\r
340 /* Like notmuch_message_file_open but with 'ctx' as the talloc owner. */
\r
341 notmuch_message_file_t *
\r
342 -_notmuch_message_file_open_ctx (void *ctx, const char *filename);
\r
343 +_notmuch_message_file_open_ctx (void *ctx, notmuch_mailstore_t *mailstore, const char *filename);
\r
345 /* Close a notmuch message previously opened with notmuch_message_open. */
\r
347 @@ -406,7 +406,7 @@ char *
\r
348 notmuch_sha1_of_string (const char *str);
\r
351 -notmuch_sha1_of_file (const char *filename);
\r
352 +notmuch_sha1_of_file (FILE *file);
\r
356 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
357 index c554f6d..76ac6fc 100644
\r
358 --- a/lib/notmuch.h
\r
359 +++ b/lib/notmuch.h
\r
360 @@ -742,8 +742,8 @@ notmuch_message_get_replies (notmuch_message_t *message);
\r
362 /* Get a filename for the email corresponding to 'message'.
\r
364 - * The returned filename is an absolute filename, (the initial
\r
365 - * component will match notmuch_database_get_path() ).
\r
366 + * The returned filename is an relative filename of the message within
\r
367 + * the mail store.
\r
369 * The returned string belongs to the message so should not be
\r
370 * modified or freed by the caller (nor should it be referenced after
\r
371 @@ -757,6 +757,18 @@ notmuch_message_get_replies (notmuch_message_t *message);
\r
373 notmuch_message_get_filename (notmuch_message_t *message);
\r
375 +/* Return file handle to read the content of the message.
\r
377 + * This is a helper function which determines message filename and
\r
378 + * calls notmuch_mailstore_open_file().
\r
381 +notmuch_message_fopen (notmuch_message_t *message);
\r
383 +/* Get a pointer to the mailstore where the message is stored */
\r
384 +notmuch_mailstore_t *
\r
385 +notmuch_message_get_mailstore (notmuch_message_t *message);
\r
387 /* Message flags */
\r
388 typedef enum _notmuch_message_flag {
\r
389 NOTMUCH_MESSAGE_FLAG_MATCH,
\r
390 diff --git a/lib/sha1.c b/lib/sha1.c
\r
391 index cc48108..a8991b1 100644
\r
394 @@ -74,9 +74,8 @@ notmuch_sha1_of_string (const char *str)
\r
395 * file not found, etc.), this function returns NULL.
\r
398 -notmuch_sha1_of_file (const char *filename)
\r
399 +notmuch_sha1_of_file (FILE *file)
\r
402 #define BLOCK_SIZE 4096
\r
403 unsigned char block[BLOCK_SIZE];
\r
405 @@ -84,7 +83,6 @@ notmuch_sha1_of_file (const char *filename)
\r
406 unsigned char digest[SHA1_DIGEST_SIZE];
\r
409 - file = fopen (filename, "r");
\r
413 @@ -108,8 +106,6 @@ notmuch_sha1_of_file (const char *filename)
\r
415 result = _hex_of_sha1_digest (digest);
\r
422 diff --git a/notmuch-client.h b/notmuch-client.h
\r
423 index 4794b8e..f5106cd 100644
\r
424 --- a/notmuch-client.h
\r
425 +++ b/notmuch-client.h
\r
426 @@ -120,7 +120,7 @@ char *
\r
427 query_string_from_args (void *ctx, int argc, char *argv[]);
\r
430 -show_message_body (const char *filename,
\r
431 +show_message_body (FILE *file,
\r
432 void (*show_part) (GMimeObject *part, int *part_count));
\r
435 diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
436 index 0d6b7cf..a471137 100644
\r
437 --- a/notmuch-reply.c
\r
438 +++ b/notmuch-reply.c
\r
439 @@ -285,6 +285,7 @@ add_recipients_from_message (GMimeMessage *reply,
\r
441 notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query)
\r
444 GMimeMessage *reply;
\r
445 notmuch_messages_t *messages;
\r
446 notmuch_message_t *message;
\r
447 @@ -350,7 +351,14 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_
\r
448 notmuch_message_get_header (message, "date"),
\r
449 notmuch_message_get_header (message, "from"));
\r
451 - show_message_body (notmuch_message_get_filename (message), reply_part);
\r
452 + file = notmuch_message_fopen (message);
\r
454 + show_message_body (file, reply_part);
\r
457 + fprintf (stderr, "Error opening %s: %s\n",
\r
458 + notmuch_message_get_filename (message),
\r
459 + strerror (errno));
\r
461 notmuch_message_destroy (message);
\r
463 diff --git a/notmuch-show.c b/notmuch-show.c
\r
464 index 26581c1..0fcaacf 100644
\r
465 --- a/notmuch-show.c
\r
466 +++ b/notmuch-show.c
\r
467 @@ -336,6 +336,8 @@ format_part_json (GMimeObject *part, int *part_count)
\r
469 show_message (void *ctx, const show_format_t *format, notmuch_message_t *message, int indent)
\r
473 fputs (format->message_start, stdout);
\r
474 if (format->message)
\r
475 format->message(ctx, message, indent);
\r
476 @@ -346,8 +348,16 @@ show_message (void *ctx, const show_format_t *format, notmuch_message_t *message
\r
477 fputs (format->header_end, stdout);
\r
479 fputs (format->body_start, stdout);
\r
480 - if (format->part)
\r
481 - show_message_body (notmuch_message_get_filename (message), format->part);
\r
482 + if (format->part) {
\r
483 + file = notmuch_message_fopen (message);
\r
485 + show_message_body (file, format->part);
\r
488 + fprintf (stderr, "Error opening %s: %s\n",
\r
489 + notmuch_message_get_filename (message),
\r
490 + strerror (errno));
\r
492 fputs (format->body_end, stdout);
\r
494 fputs (format->message_end, stdout);
\r
495 diff --git a/show-message.c b/show-message.c
\r
496 index 05ced9c..2df859a 100644
\r
497 --- a/show-message.c
\r
498 +++ b/show-message.c
\r
499 @@ -60,23 +60,15 @@ show_message_part (GMimeObject *part, int *part_count,
\r
503 -show_message_body (const char *filename,
\r
504 +show_message_body (FILE *file,
\r
505 void (*show_part) (GMimeObject *part, int *part_count))
\r
507 GMimeStream *stream = NULL;
\r
508 GMimeParser *parser = NULL;
\r
509 GMimeMessage *mime_message = NULL;
\r
510 notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
\r
511 - FILE *file = NULL;
\r
512 int part_count = 0;
\r
514 - file = fopen (filename, "r");
\r
516 - fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno));
\r
517 - ret = NOTMUCH_STATUS_FILE_ERROR;
\r
521 stream = g_mime_stream_file_new (file);
\r
522 g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream), FALSE);
\r
524 @@ -87,7 +79,6 @@ show_message_body (const char *filename,
\r
525 show_message_part (g_mime_message_get_mime_part (mime_message),
\r
526 &part_count, show_part);
\r
530 g_object_unref (mime_message);
\r
532 @@ -97,8 +88,5 @@ show_message_body (const char *filename,
\r
534 g_object_unref (stream);
\r