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 4EC304196F5
\r
6 for <notmuch@notmuchmail.org>; Thu, 8 Apr 2010 07:43:12 -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 dl2HlPiVMWYm for <notmuch@notmuchmail.org>;
\r
16 Thu, 8 Apr 2010 07:43:08 -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 834274196F0
\r
19 for <notmuch@notmuchmail.org>; Thu, 8 Apr 2010 07:43:07 -0700 (PDT)
\r
20 Received: from localhost (unknown [192.168.200.4])
\r
21 by max.feld.cvut.cz (Postfix) with ESMTP id E5C9719F33D8;
\r
22 Thu, 8 Apr 2010 16:43:06 +0200 (CEST)
\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 4g-PakWlGmXu; Thu, 8 Apr 2010 16:43:05 +0200 (CEST)
\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 165B519F3404;
\r
30 Thu, 8 Apr 2010 16:43:05 +0200 (CEST)
\r
31 Received: from steelpick.2x.cz (k335-30.felk.cvut.cz [147.32.86.30])
\r
32 (Authenticated sender: sojkam1)
\r
33 by imap.feld.cvut.cz (Postfix) with ESMTPSA id 12ACF15C062;
\r
34 Thu, 8 Apr 2010 16:43:05 +0200 (CEST)
\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 1Nzswi-0007cJ-Q0; Thu, 08 Apr 2010 16:43:04 +0200
\r
38 From: Michal Sojka <sojkam1@fel.cvut.cz>
\r
39 To: notmuch@notmuchmail.org
\r
40 Subject: [PATCH 3/4] Access messages through mail store interface
\r
41 Date: Thu, 8 Apr 2010 16:42:45 +0200
\r
42 Message-Id: <1270737766-29237-4-git-send-email-sojkam1@fel.cvut.cz>
\r
43 X-Mailer: git-send-email 1.7.0.2
\r
44 In-Reply-To: <1270737766-29237-1-git-send-email-sojkam1@fel.cvut.cz>
\r
45 References: <1270737766-29237-1-git-send-email-sojkam1@fel.cvut.cz>
\r
46 X-BeenThere: notmuch@notmuchmail.org
\r
47 X-Mailman-Version: 2.1.13
\r
49 List-Id: "Use and development of the notmuch mail system."
\r
50 <notmuch.notmuchmail.org>
\r
51 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
52 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
53 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
54 List-Post: <mailto:notmuch@notmuchmail.org>
\r
55 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
56 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
57 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
58 X-List-Received-Date: Thu, 08 Apr 2010 14:43:12 -0000
\r
60 This patch modifies notmuch binary to access the messages through mail
\r
61 store interface, so that non-file based mail stores can also be
\r
64 The API of notmuch library was changed. Now,
\r
65 notmuch_message_get_filename() returns relative file name with respect
\r
66 to the database path. As a result, notmuch show also outputs relative
\r
67 paths so that MUAs need to be changed.
\r
69 Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
\r
71 lib/database.cc | 14 +++++++++++---
\r
72 lib/index.cc | 8 ++++++--
\r
73 lib/mailstore-files.c | 18 +++++++++++++++++-
\r
74 lib/message-file.c | 8 ++++----
\r
75 lib/message.cc | 33 +++++++++++++++++++++++++--------
\r
76 lib/notmuch-private.h | 6 +++---
\r
77 lib/notmuch.h | 16 ++++++++++++++--
\r
78 lib/sha1.c | 6 +-----
\r
79 notmuch-client.h | 2 +-
\r
80 notmuch-reply.c | 10 +++++++++-
\r
81 notmuch-show.c | 14 ++++++++++++--
\r
82 show-message.c | 14 +-------------
\r
83 12 files changed, 104 insertions(+), 45 deletions(-)
\r
85 diff --git a/lib/database.cc b/lib/database.cc
\r
86 index 93c8d0f..bd64ed3 100644
\r
87 --- a/lib/database.cc
\r
88 +++ b/lib/database.cc
\r
89 @@ -1374,6 +1374,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
\r
90 notmuch_message_t *message = NULL;
\r
91 notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
\r
92 notmuch_private_status_t private_status;
\r
93 + const char *relative;
\r
95 const char *date, *header;
\r
96 const char *from, *to, *subject;
\r
97 @@ -1386,7 +1387,8 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
\r
101 - message_file = notmuch_message_file_open (filename);
\r
102 + relative = _notmuch_database_relative_path (notmuch, filename);
\r
103 + message_file = notmuch_message_file_open (notmuch->mailstore, relative);
\r
104 if (message_file == NULL)
\r
105 return NOTMUCH_STATUS_FILE_ERROR;
\r
107 @@ -1438,9 +1440,15 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
\r
110 if (message_id == NULL ) {
\r
112 + char *sha1 = NULL;
\r
113 /* No message-id at all, let's generate one by taking a
\r
114 * hash over the file's contents. */
\r
115 - char *sha1 = notmuch_sha1_of_file (filename);
\r
116 + file = notmuch_mailstore_open_file (notmuch->mailstore, relative);
\r
118 + sha1 = notmuch_sha1_of_file (file);
\r
122 /* If that failed too, something is really wrong. Give up. */
\r
123 if (sha1 == NULL) {
\r
124 @@ -1483,7 +1491,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
\r
125 date = notmuch_message_file_get_header (message_file, "date");
\r
126 _notmuch_message_set_date (message, date);
\r
128 - _notmuch_message_index_file (message, filename);
\r
129 + _notmuch_message_index_file (message, relative);
\r
131 ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
\r
133 diff --git a/lib/index.cc b/lib/index.cc
\r
134 index cf93025..4d8c4dd 100644
\r
137 @@ -425,15 +425,19 @@ _notmuch_message_index_file (notmuch_message_t *message,
\r
138 const char *from, *subject;
\r
139 notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
\r
140 static int initialized = 0;
\r
141 + notmuch_mailstore_t *mailstore;
\r
143 if (! initialized) {
\r
148 - file = fopen (filename, "r");
\r
149 + mailstore = notmuch_message_get_mailstore(message);
\r
150 + file = notmuch_mailstore_open_file (mailstore, filename);
\r
152 - fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno));
\r
153 + fprintf (stderr, "Error opening %s: %s\n",
\r
154 + notmuch_message_get_filename (message),
\r
155 + strerror (errno));
\r
156 ret = NOTMUCH_STATUS_FILE_ERROR;
\r
159 diff --git a/lib/mailstore-files.c b/lib/mailstore-files.c
\r
160 index 8b5e1d5..f2cb8d7 100644
\r
161 --- a/lib/mailstore-files.c
\r
162 +++ b/lib/mailstore-files.c
\r
163 @@ -602,11 +602,27 @@ index_new(notmuch_mailstore_t *mailstore, const char* path,
\r
168 +open_file(notmuch_mailstore_t *mailstore, const char *filename)
\r
170 + const char *db_path;
\r
171 + char *abs_filename;
\r
174 + db_path = notmuch_database_get_path(mailstore->notmuch);
\r
175 + abs_filename = talloc_asprintf(NULL, "%s/%s", db_path, filename);
\r
176 + if (unlikely(abs_filename == NULL))
\r
178 + file = fopen (abs_filename, "r");
\r
179 + talloc_free(abs_filename);
\r
183 /* Original notmuch mail store */
\r
184 struct _notmuch_mailstore mailstore_files = {
\r
186 .count_files = count_files,
\r
187 .index_new = index_new,
\r
188 .sync_tags = NULL, /* We cannot store tags in this mailstore. */
\r
189 - .open_file = NULL, /* Currently not implemented */
\r
190 + .open_file = open_file,
\r
192 diff --git a/lib/message-file.c b/lib/message-file.c
\r
193 index 0c152a3..13c9f4c 100644
\r
194 --- a/lib/message-file.c
\r
195 +++ b/lib/message-file.c
\r
196 @@ -94,7 +94,7 @@ _notmuch_message_file_destructor (notmuch_message_file_t *message)
\r
197 /* Create a new notmuch_message_file_t for 'filename' with 'ctx' as
\r
198 * the talloc owner. */
\r
199 notmuch_message_file_t *
\r
200 -_notmuch_message_file_open_ctx (void *ctx, const char *filename)
\r
201 +_notmuch_message_file_open_ctx (void *ctx, notmuch_mailstore_t *mailstore, const char *filename)
\r
203 notmuch_message_file_t *message;
\r
205 @@ -104,7 +104,7 @@ _notmuch_message_file_open_ctx (void *ctx, const char *filename)
\r
207 talloc_set_destructor (message, _notmuch_message_file_destructor);
\r
209 - message->file = fopen (filename, "r");
\r
210 + message->file = notmuch_mailstore_open_file(mailstore, filename);
\r
211 if (message->file == NULL)
\r
214 @@ -126,9 +126,9 @@ _notmuch_message_file_open_ctx (void *ctx, const char *filename)
\r
217 notmuch_message_file_t *
\r
218 -notmuch_message_file_open (const char *filename)
\r
219 +notmuch_message_file_open (notmuch_mailstore_t *mailstore, const char *filename)
\r
221 - return _notmuch_message_file_open_ctx (NULL, filename);
\r
222 + return _notmuch_message_file_open_ctx (NULL, mailstore, filename);
\r
226 diff --git a/lib/message.cc b/lib/message.cc
\r
227 index c32ee7d..c7eff7c 100644
\r
228 --- a/lib/message.cc
\r
229 +++ b/lib/message.cc
\r
230 @@ -247,6 +247,7 @@ static void
\r
231 _notmuch_message_ensure_message_file (notmuch_message_t *message)
\r
233 const char *filename;
\r
234 + notmuch_mailstore_t *mailstore;
\r
236 if (message->message_file)
\r
238 @@ -255,7 +256,9 @@ _notmuch_message_ensure_message_file (notmuch_message_t *message)
\r
239 if (unlikely (filename == NULL))
\r
242 - message->message_file = _notmuch_message_file_open_ctx (message, filename);
\r
243 + mailstore = notmuch_message_get_mailstore (message);
\r
245 + message->message_file = _notmuch_message_file_open_ctx (message, mailstore, filename);
\r
249 @@ -429,7 +432,7 @@ notmuch_message_get_filename (notmuch_message_t *message)
\r
250 int prefix_len = strlen (prefix);
\r
251 Xapian::TermIterator i;
\r
252 char *colon, *direntry = NULL;
\r
253 - const char *db_path, *directory, *basename;
\r
254 + const char *directory, *basename;
\r
255 unsigned int directory_id;
\r
256 void *local = talloc_new (message);
\r
258 @@ -474,18 +477,16 @@ notmuch_message_get_filename (notmuch_message_t *message)
\r
262 - db_path = notmuch_database_get_path (message->notmuch);
\r
264 directory = _notmuch_database_get_directory_path (local,
\r
268 if (strlen (directory))
\r
269 - message->filename = talloc_asprintf (message, "%s/%s/%s",
\r
270 - db_path, directory, basename);
\r
272 message->filename = talloc_asprintf (message, "%s/%s",
\r
273 - db_path, basename);
\r
274 + directory, basename);
\r
276 + message->filename = talloc_asprintf (message, "%s",
\r
278 talloc_free ((void *) directory);
\r
280 talloc_free (local);
\r
281 @@ -493,6 +494,22 @@ notmuch_message_get_filename (notmuch_message_t *message)
\r
282 return message->filename;
\r
286 +notmuch_message_fopen (notmuch_message_t *message)
\r
288 + const char *filename;
\r
289 + filename = notmuch_message_get_filename (message);
\r
290 + return notmuch_mailstore_open_file (message->notmuch->mailstore,
\r
294 +notmuch_mailstore_t *
\r
295 +notmuch_message_get_mailstore (notmuch_message_t *message)
\r
297 + return message->notmuch->mailstore;
\r
302 notmuch_message_get_flag (notmuch_message_t *message,
\r
303 notmuch_message_flag_t flag)
\r
304 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
\r
305 index d52d84d..bab2090 100644
\r
306 --- a/lib/notmuch-private.h
\r
307 +++ b/lib/notmuch-private.h
\r
308 @@ -295,11 +295,11 @@ typedef struct _notmuch_message_file notmuch_message_file_t;
\r
309 * Returns NULL if any error occurs.
\r
311 notmuch_message_file_t *
\r
312 -notmuch_message_file_open (const char *filename);
\r
313 +notmuch_message_file_open (notmuch_mailstore_t *mailstore, const char *filename);
\r
315 /* Like notmuch_message_file_open but with 'ctx' as the talloc owner. */
\r
316 notmuch_message_file_t *
\r
317 -_notmuch_message_file_open_ctx (void *ctx, const char *filename);
\r
318 +_notmuch_message_file_open_ctx (void *ctx, notmuch_mailstore_t *mailstore, const char *filename);
\r
320 /* Close a notmuch message previously opened with notmuch_message_open. */
\r
322 @@ -402,7 +402,7 @@ char *
\r
323 notmuch_sha1_of_string (const char *str);
\r
326 -notmuch_sha1_of_file (const char *filename);
\r
327 +notmuch_sha1_of_file (FILE *file);
\r
331 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
332 index 31e47a4..54de0bd 100644
\r
333 --- a/lib/notmuch.h
\r
334 +++ b/lib/notmuch.h
\r
335 @@ -739,8 +739,8 @@ notmuch_message_get_replies (notmuch_message_t *message);
\r
337 /* Get a filename for the email corresponding to 'message'.
\r
339 - * The returned filename is an absolute filename, (the initial
\r
340 - * component will match notmuch_database_get_path() ).
\r
341 + * The returned filename is an relative filename of the message within
\r
342 + * the mail store.
\r
344 * The returned string belongs to the message so should not be
\r
345 * modified or freed by the caller (nor should it be referenced after
\r
346 @@ -754,6 +754,18 @@ notmuch_message_get_replies (notmuch_message_t *message);
\r
348 notmuch_message_get_filename (notmuch_message_t *message);
\r
350 +/* Return file handle to read the content of the message.
\r
352 + * This is a helper function which determines message filename and
\r
353 + * calls notmuch_mailstore_open_file().
\r
356 +notmuch_message_fopen (notmuch_message_t *message);
\r
358 +/* Get a pointer to the mailstore where the message is stored */
\r
359 +notmuch_mailstore_t *
\r
360 +notmuch_message_get_mailstore (notmuch_message_t *message);
\r
362 /* Message flags */
\r
363 typedef enum _notmuch_message_flag {
\r
364 NOTMUCH_MESSAGE_FLAG_MATCH,
\r
365 diff --git a/lib/sha1.c b/lib/sha1.c
\r
366 index cc48108..a8991b1 100644
\r
369 @@ -74,9 +74,8 @@ notmuch_sha1_of_string (const char *str)
\r
370 * file not found, etc.), this function returns NULL.
\r
373 -notmuch_sha1_of_file (const char *filename)
\r
374 +notmuch_sha1_of_file (FILE *file)
\r
377 #define BLOCK_SIZE 4096
\r
378 unsigned char block[BLOCK_SIZE];
\r
380 @@ -84,7 +83,6 @@ notmuch_sha1_of_file (const char *filename)
\r
381 unsigned char digest[SHA1_DIGEST_SIZE];
\r
384 - file = fopen (filename, "r");
\r
388 @@ -108,8 +106,6 @@ notmuch_sha1_of_file (const char *filename)
\r
390 result = _hex_of_sha1_digest (digest);
\r
397 diff --git a/notmuch-client.h b/notmuch-client.h
\r
398 index d8c8df4..728e448 100644
\r
399 --- a/notmuch-client.h
\r
400 +++ b/notmuch-client.h
\r
401 @@ -126,7 +126,7 @@ char *
\r
402 query_string_from_args (void *ctx, int argc, char *argv[]);
\r
405 -show_message_body (const char *filename,
\r
406 +show_message_body (FILE *file,
\r
407 void (*show_part) (GMimeObject *part, int *part_count));
\r
410 diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
411 index 1ec28cd..32d17ef 100644
\r
412 --- a/notmuch-reply.c
\r
413 +++ b/notmuch-reply.c
\r
414 @@ -347,6 +347,7 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message
\r
416 notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query)
\r
419 GMimeMessage *reply;
\r
420 notmuch_messages_t *messages;
\r
421 notmuch_message_t *message;
\r
422 @@ -415,7 +416,14 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_
\r
423 notmuch_message_get_header (message, "date"),
\r
424 notmuch_message_get_header (message, "from"));
\r
426 - show_message_body (notmuch_message_get_filename (message), reply_part);
\r
427 + file = notmuch_message_fopen (message);
\r
429 + show_message_body (file, reply_part);
\r
432 + fprintf (stderr, "Error opening %s: %s\n",
\r
433 + notmuch_message_get_filename (message),
\r
434 + strerror (errno));
\r
436 notmuch_message_destroy (message);
\r
438 diff --git a/notmuch-show.c b/notmuch-show.c
\r
439 index 6dca672..66fd773 100644
\r
440 --- a/notmuch-show.c
\r
441 +++ b/notmuch-show.c
\r
442 @@ -339,6 +339,8 @@ format_part_json (GMimeObject *part, int *part_count)
\r
444 show_message (void *ctx, const show_format_t *format, notmuch_message_t *message, int indent)
\r
448 fputs (format->message_start, stdout);
\r
449 if (format->message)
\r
450 format->message(ctx, message, indent);
\r
451 @@ -349,8 +351,16 @@ show_message (void *ctx, const show_format_t *format, notmuch_message_t *message
\r
452 fputs (format->header_end, stdout);
\r
454 fputs (format->body_start, stdout);
\r
455 - if (format->part)
\r
456 - show_message_body (notmuch_message_get_filename (message), format->part);
\r
457 + if (format->part) {
\r
458 + file = notmuch_message_fopen (message);
\r
460 + show_message_body (file, format->part);
\r
463 + fprintf (stderr, "Error opening %s: %s\n",
\r
464 + notmuch_message_get_filename (message),
\r
465 + strerror (errno));
\r
467 fputs (format->body_end, stdout);
\r
469 fputs (format->message_end, stdout);
\r
470 diff --git a/show-message.c b/show-message.c
\r
471 index b1b61be..79911a7 100644
\r
472 --- a/show-message.c
\r
473 +++ b/show-message.c
\r
474 @@ -60,23 +60,15 @@ show_message_part (GMimeObject *part, int *part_count,
\r
478 -show_message_body (const char *filename,
\r
479 +show_message_body (FILE *file,
\r
480 void (*show_part) (GMimeObject *part, int *part_count))
\r
482 GMimeStream *stream = NULL;
\r
483 GMimeParser *parser = NULL;
\r
484 GMimeMessage *mime_message = NULL;
\r
485 notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
\r
486 - FILE *file = NULL;
\r
487 int part_count = 0;
\r
489 - file = fopen (filename, "r");
\r
491 - fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno));
\r
492 - ret = NOTMUCH_STATUS_FILE_ERROR;
\r
496 stream = g_mime_stream_file_new (file);
\r
497 g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream), FALSE);
\r
499 @@ -87,7 +79,6 @@ show_message_body (const char *filename,
\r
500 show_message_part (g_mime_message_get_mime_part (mime_message),
\r
501 &part_count, show_part);
\r
505 g_object_unref (mime_message);
\r
507 @@ -97,9 +88,6 @@ show_message_body (const char *filename,
\r
509 g_object_unref (stream);
\r