1 Return-Path: <glasse@cs.rpi.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 B360D431E82
\r
6 for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 14:11:56 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.54 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 RCVD_IN_BL_SPAMCOP_NET=1.246, RCVD_IN_DNSWL_MED=-2.3,
\r
14 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 eK-aKk33EcIa for <notmuch@notmuchmail.org>;
\r
18 Wed, 15 Feb 2012 14:11:53 -0800 (PST)
\r
19 Received: from cliffclavin.cs.rpi.edu (cliffclavin.cs.rpi.edu
\r
20 [128.113.126.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
\r
21 (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS
\r
22 id 2A8A4431E62 for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 14:11:53 -0800
\r
25 S|75b965240be746bfacad19b205d46a22056d0830|9287a5b72cd81bc1c234f87490ac0ac1
\r
26 X-Countries: Cameroon, United States
\r
27 X-SMTP-From: accepted <glasse@cs.rpi.edu> [195.24.209.20] [195.24.209.20]
\r
28 (localhost) {Cameroon}
\r
29 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=cs.rpi.edu; h=from
\r
30 :to:cc:subject:date:message-id:in-reply-to:references; s=
\r
31 default; i=glasse@cs.rpi.edu; t=1329343910; x=1329948710; l=3964;
\r
32 bh=zz4yDRJU3jsojgqGz6/yGpSO8F4=; b=Qq9w/32EsKCnPttzA5YFswj
\r
33 Pap4mbRruDvOKA9sWjqbS+rswyKUdcJuvixRyyY4F85+EwfnQ7GV6+C84KMuKJIM
\r
34 RKbHele65+P09gK+ewgUUZnsUlqEi/N5EmW4kcfF1nZVIbrQIrBGK5slexVfl1yo
\r
35 +AQTkxrUzrFqC3ZJ2Luo=
\r
36 DomainKey-Signature: a=rsa-sha1; c=nofws; d=cs.rpi.edu; h=from:to:cc
\r
37 :subject:date:message-id:in-reply-to:references; q=dns; s=
\r
38 default; b=E3Ea6resbxDmqh0AwLVJUYC5bPXuDMf9DkqY2iHGTNYz+a0J8xKCL
\r
39 B/Qd8MyPuJFr4Akl0+2X4lsE2RMycJA5diXwOUzuDEC3Tdr4nS+hXUFCNT2hiVhL
\r
40 aAvEFLwkuaGvxa32zSLvFrCTKebA5qugNptYWHTW98KDsryog7CSys=
\r
41 X-Spam-Info: -2.7; ALL_TRUSTED,AWL,BAYES_00
\r
42 X-Spam-Scanned-By: cliffclavin.cs.rpi.edu using SpamAssassin 3.2.5 (hard limit
\r
44 Authentication-Results: cliffclavin.cs.rpi.edu;
\r
45 DKIM=neutral (none) header.from=glasse@cs.rpi.edu;
\r
47 Mechanism '?all' matched) smtp.mail=glasse@cs.rpi.edu
\r
48 X-Auth-Passed: cliffclavin.cs.rpi.edu:q1FMBOCB008859 Auth:glasse
\r
49 X-Virus-Scanned-By: cliffclavin.cs.rpi.edu
\r
50 Received: from localhost ([195.24.209.20]) (authenticated bits=0)
\r
51 by cliffclavin.cs.rpi.edu (8.14.3/8.14.3) with ESMTP id q1FMBOCB008859
\r
52 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO);
\r
53 Wed, 15 Feb 2012 17:11:37 -0500 (EST)
\r
54 (envelope-from glasse@cs.rpi.edu)
\r
55 From: Ethan Glasser-Camp <glasse@cs.rpi.edu>
\r
56 To: notmuch@notmuchmail.org
\r
57 Subject: [RFC PATCH 10/13] Introduce concept of mailstore "constructor"
\r
58 Date: Wed, 15 Feb 2012 17:02:03 -0500
\r
59 Message-Id: <1329343326-16410-11-git-send-email-glasse@cs.rpi.edu>
\r
60 X-Mailer: git-send-email 1.7.5.4
\r
61 In-Reply-To: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu>
\r
62 References: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu>
\r
63 X-Scanned-By: MIMEDefang 2.67 on 128.113.126.25
\r
64 Cc: Ethan Glasser-Camp <ethan@betacantrips.com>
\r
65 X-BeenThere: notmuch@notmuchmail.org
\r
66 X-Mailman-Version: 2.1.13
\r
68 List-Id: "Use and development of the notmuch mail system."
\r
69 <notmuch.notmuchmail.org>
\r
70 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
71 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
72 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
73 List-Post: <mailto:notmuch@notmuchmail.org>
\r
74 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
75 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
76 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
77 X-List-Received-Date: Wed, 15 Feb 2012 22:11:56 -0000
\r
79 From: Ethan Glasser-Camp <ethan@betacantrips.com>
\r
81 Right now this is a fancy no-op because maildir doesn't need any
\r
82 special data, but getting the API right is good. A constructor can
\r
83 fail, so return a notmuch_status_t.
\r
85 Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com>
\r
87 lib/mailstore.c | 36 +++++++++++++++++++++++++++++++++---
\r
88 lib/notmuch.h | 7 +++++++
\r
89 notmuch-config.c | 8 +++++++-
\r
90 3 files changed, 47 insertions(+), 4 deletions(-)
\r
92 diff --git a/lib/mailstore.c b/lib/mailstore.c
\r
93 index 2c6beab..b4d512d 100644
\r
94 --- a/lib/mailstore.c
\r
95 +++ b/lib/mailstore.c
\r
100 +#include <stdarg.h>
\r
102 #include "notmuch-private.h"
\r
104 typedef struct _notmuch_mailstore {
\r
105 + notmuch_status_t (*constructor) (void **data, va_list args);
\r
106 FILE *(*open) (struct _notmuch_mailstore *mailstore, const char *filename);
\r
107 int (*rename) (struct _notmuch_mailstore *mailstore, const char *old_filename,
\r
108 const char *new_filename);
\r
110 } _notmuch_mailstore;
\r
112 +static notmuch_status_t
\r
113 +_maildir_constructor (void **data, unused (va_list ap))
\r
116 + return NOTMUCH_STATUS_SUCCESS;
\r
120 _maildir_open_function (unused (notmuch_mailstore_t *mailstore),
\r
121 const char *filename)
\r
122 @@ -48,12 +58,18 @@ _maildir_rename_function (unused (notmuch_mailstore_t *mailstore),
\r
123 * - A function to "rename" a mail message, which is currently only
\r
124 * used in tags_to_maildir_flags.
\r
126 - * - TODO: A way to scan for new messages?
\r
127 + * - A "constructor" that creates a mailstore object of the requisite
\r
128 + * type. Arguments are passed via va_args.
\r
130 - * - TODO: A "constructor"?
\r
131 + * A mailstore also has a "data" field that can be used to store
\r
132 + * instance-specific information about this mailstore -- for example,
\r
133 + * a CouchDB URL or a path. FIXME: mailstores are all statically
\r
134 + * allocated, so maybe we shouldn't do this.
\r
137 -notmuch_mailstore_maildir = { _maildir_open_function, _maildir_rename_function };
\r
138 +notmuch_mailstore_maildir = { _maildir_constructor,
\r
139 + _maildir_open_function, _maildir_rename_function,
\r
142 _notmuch_mailstore *
\r
143 notmuch_mailstore_get_by_name (const char *name)
\r
144 @@ -76,3 +92,17 @@ notmuch_mailstore_rename (notmuch_mailstore_t *mailstore, const char *old_filena
\r
146 return mailstore->rename (mailstore, old_filename, new_filename);
\r
150 +notmuch_mailstore_construct (notmuch_mailstore_t *mailstore, ...)
\r
153 + notmuch_status_t status;
\r
155 + va_start (va_args, mailstore);
\r
157 + status = mailstore->constructor (&mailstore->data, va_args);
\r
159 + va_end (va_args);
\r
162 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
163 index b6e66a9..7f48507 100644
\r
164 --- a/lib/notmuch.h
\r
165 +++ b/lib/notmuch.h
\r
166 @@ -430,6 +430,13 @@ int
\r
167 notmuch_mailstore_rename (notmuch_mailstore_t *mailstore, const char *old_filename,
\r
168 const char *new_filename);
\r
170 +/* Initialize the mailstore.
\r
172 + * Arguments are dependent on the mailstore.
\r
175 +notmuch_mailstore_construct (notmuch_mailstore_t *mailstore, ...);
\r
177 /* Create a new query for 'database'.
\r
179 * Here, 'database' should be an open database, (see
\r
180 diff --git a/notmuch-config.c b/notmuch-config.c
\r
181 index f611b26..99f872d 100644
\r
182 --- a/notmuch-config.c
\r
183 +++ b/notmuch-config.c
\r
184 @@ -592,8 +592,14 @@ notmuch_config_get_mailstore (notmuch_config_t *config)
\r
185 * When there are multiple mailstore types and "constructors" for
\r
186 * them, this may have to be much more complicated.
\r
188 + notmuch_status_t status;
\r
189 const char *type = notmuch_config_get_database_type (config);
\r
190 - return notmuch_mailstore_get_by_name (type);
\r
191 + notmuch_mailstore_t *mailstore = notmuch_mailstore_get_by_name (type);
\r
192 + status = notmuch_mailstore_construct (mailstore);
\r
193 + if (status != NOTMUCH_STATUS_SUCCESS) {
\r
194 + /* abort messily? */
\r
196 + return mailstore;
\r