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 8DBDB431FAF
\r
6 for <notmuch@notmuchmail.org>; Mon, 25 Jun 2012 13:54: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 DGKHb36IH1Pn for <notmuch@notmuchmail.org>;
\r
18 Mon, 25 Jun 2012 13:54:23 -0700 (PDT)
\r
19 Received: from mail-we0-f181.google.com (mail-we0-f181.google.com
\r
20 [74.125.82.181]) (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 D2450431FB6
\r
23 for <notmuch@notmuchmail.org>; Mon, 25 Jun 2012 13:54:22 -0700 (PDT)
\r
24 Received: by mail-we0-f181.google.com with SMTP id j55so3649559wer.26
\r
25 for <notmuch@notmuchmail.org>; Mon, 25 Jun 2012 13:54: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 bh=qFV8lIM0wUbaJb3QQa15HFk6nHSx8wYDwaZm03WSkbI=;
\r
29 b=iat6tx0LAge9nov/ohkNvdcU945bed9EnVRVIbB3SXGqSTMTF6XhiuXN2DOZfMxOoK
\r
30 v++QNoItw+0LQokxxMzx1+6b81GICc+yGrF58xlMp6ppycZ5mEdN2Cp1pSOuVZaHrXmE
\r
31 /bs520PzcPESReLwYku88QS788/Ms6/gXmdhUNFstZwvaeMBmRoHBjXw8n4OoOhjCvG2
\r
32 a7b9Z0HqHK4CvBy8usrCAcYKU/FD+pZBmeyhpQjAjEf/PObcLk662IyDeeY0fLA7wBq7
\r
33 kpryupytyemu0AZQFd/5OU4YI5ksaTtmDEi1jppHxSTdv5di//+7XPs7aaelvID6fNev
\r
35 Received: by 10.180.96.4 with SMTP id do4mr27121547wib.18.1340657662442;
\r
36 Mon, 25 Jun 2012 13:54:22 -0700 (PDT)
\r
37 Received: from localhost ([195.24.209.21])
\r
38 by mx.google.com with ESMTPS id t8sm35405wiy.3.2012.06.25.13.54.16
\r
39 (version=TLSv1/SSLv3 cipher=OTHER);
\r
40 Mon, 25 Jun 2012 13:54:21 -0700 (PDT)
\r
41 From: Ethan Glasser-Camp <ethan.glasser.camp@gmail.com>
\r
42 To: notmuch@notmuchmail.org
\r
43 Subject: [RFC PATCH 12/14] mailstore: support for mbox:// URIs
\r
44 Date: Mon, 25 Jun 2012 16:51:55 -0400
\r
45 Message-Id: <1340657517-6539-8-git-send-email-ethan@betacantrips.com>
\r
46 X-Mailer: git-send-email 1.7.9.5
\r
47 In-Reply-To: <1340657517-6539-1-git-send-email-ethan@betacantrips.com>
\r
48 References: <1340657517-6539-1-git-send-email-ethan@betacantrips.com>
\r
49 X-Mailman-Approved-At: Tue, 26 Jun 2012 03:51:54 -0700
\r
50 X-BeenThere: notmuch@notmuchmail.org
\r
51 X-Mailman-Version: 2.1.13
\r
53 List-Id: "Use and development of the notmuch mail system."
\r
54 <notmuch.notmuchmail.org>
\r
55 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
56 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
57 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
58 List-Post: <mailto:notmuch@notmuchmail.org>
\r
59 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
60 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
61 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
62 X-List-Received-Date: Mon, 25 Jun 2012 20:54:23 -0000
\r
65 Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com>
\r
67 lib/mailstore.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
68 1 file changed, 85 insertions(+)
\r
70 diff --git a/lib/mailstore.c b/lib/mailstore.c
\r
71 index ae02c12..e8d9bc1 100644
\r
72 --- a/lib/mailstore.c
\r
73 +++ b/lib/mailstore.c
\r
76 #include <uriparser/Uri.h>
\r
80 #include "notmuch-private.h"
\r
82 @@ -28,6 +29,74 @@ notmuch_mailstore_basic_open (const char *filename)
\r
83 return fopen (filename, "r");
\r
86 +/* Since we have to return a FILE*, we use fmemopen to turn buffers
\r
87 + * into FILE* streams. But when we close these streams, we have to
\r
88 + * free() the buffers. Use a hash to associate the two.
\r
90 +static GHashTable *_mbox_files_to_strings = NULL;
\r
93 +_ensure_mbox_files_to_strings () {
\r
94 + if (_mbox_files_to_strings == NULL)
\r
95 + _mbox_files_to_strings = g_hash_table_new (NULL, NULL);
\r
99 +notmuch_mailstore_mbox_open (UriUriA *uri)
\r
101 + FILE *ret = NULL, *mbox = NULL;
\r
102 + char *filename, *message, *length_s;
\r
103 + const char *error;
\r
104 + long int offset, length, this_read;
\r
105 + _ensure_mbox_files_to_strings ();
\r
107 + offset = strtol (uri->fragment.first, &length_s, 10);
\r
108 + length = strtol (length_s+1, NULL, 10);
\r
110 + filename = talloc_strndup (NULL, uri->pathHead->text.first-1,
\r
111 + uri->pathTail->text.afterLast-uri->pathHead->text.first+1);
\r
113 + if (filename == NULL)
\r
116 + mbox = fopen (filename, "r");
\r
117 + if (mbox == NULL) {
\r
118 + fprintf (stderr, "Couldn't open message %s: %s.\n", uri->scheme.first,
\r
119 + strerror (errno));
\r
123 + message = talloc_array (NULL, char, length);
\r
124 + fseek (mbox, offset, SEEK_SET);
\r
126 + this_read = fread (message, sizeof(char), length, mbox);
\r
127 + if (this_read != length) {
\r
129 + error = "end of file reached";
\r
130 + if (ferror (mbox))
\r
131 + error = strerror (ferror (mbox));
\r
133 + fprintf (stderr, "Couldn't read message %s: %s.\n", uri->scheme.first, error);
\r
137 + ret = fmemopen (message, length, "r");
\r
138 + if (ret == NULL) {
\r
139 + /* No fclose will ever be called, so let's free message now */
\r
140 + talloc_free (message);
\r
144 + g_hash_table_insert (_mbox_files_to_strings, ret, message);
\r
147 + talloc_free (filename);
\r
155 notmuch_mailstore_open (const char *filename)
\r
157 @@ -57,6 +126,14 @@ notmuch_mailstore_open (const char *filename)
\r
161 + if (0 == strncmp (parsed.scheme.first, "mbox",
\r
162 + parsed.scheme.afterLast-parsed.scheme.first)) {
\r
163 + /* mbox URI of the form mbox:///path/to/file#offset+length.
\r
164 + * Just pass the parsed URI. */
\r
165 + ret = notmuch_mailstore_mbox_open (&parsed);
\r
170 uriFreeUriMembersA (&parsed);
\r
172 @@ -65,5 +142,13 @@ DONE:
\r
174 notmuch_mailstore_close (FILE *file)
\r
176 + char *file_buffer;
\r
177 + if (_mbox_files_to_strings != NULL) {
\r
178 + file_buffer = g_hash_table_lookup (_mbox_files_to_strings, file);
\r
179 + if (file_buffer != NULL) {
\r
180 + talloc_free (file_buffer);
\r
182 + g_hash_table_remove (_mbox_files_to_strings, file);
\r
184 return fclose (file);
\r