--- /dev/null
+Return-Path: <glasse@cs.rpi.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id B360D431E82\r
+ for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 14:11:56 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.54\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.54 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ RCVD_IN_BL_SPAMCOP_NET=1.246, RCVD_IN_DNSWL_MED=-2.3,\r
+ RCVD_IN_SORBS_WEB=0.614] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id eK-aKk33EcIa for <notmuch@notmuchmail.org>;\r
+ Wed, 15 Feb 2012 14:11:53 -0800 (PST)\r
+Received: from cliffclavin.cs.rpi.edu (cliffclavin.cs.rpi.edu\r
+ [128.113.126.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS\r
+ id 2A8A4431E62 for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 14:11:53 -0800\r
+ (PST)\r
+X-Hash:\r
+ S|75b965240be746bfacad19b205d46a22056d0830|9287a5b72cd81bc1c234f87490ac0ac1\r
+X-Countries: Cameroon, United States\r
+X-SMTP-From: accepted <glasse@cs.rpi.edu> [195.24.209.20] [195.24.209.20]\r
+ (localhost) {Cameroon}\r
+DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=cs.rpi.edu; h=from\r
+ :to:cc:subject:date:message-id:in-reply-to:references; s=\r
+ default; i=glasse@cs.rpi.edu; t=1329343910; x=1329948710; l=3964;\r
+ bh=zz4yDRJU3jsojgqGz6/yGpSO8F4=; b=Qq9w/32EsKCnPttzA5YFswj\r
+ Pap4mbRruDvOKA9sWjqbS+rswyKUdcJuvixRyyY4F85+EwfnQ7GV6+C84KMuKJIM\r
+ RKbHele65+P09gK+ewgUUZnsUlqEi/N5EmW4kcfF1nZVIbrQIrBGK5slexVfl1yo\r
+ +AQTkxrUzrFqC3ZJ2Luo=\r
+DomainKey-Signature: a=rsa-sha1; c=nofws; d=cs.rpi.edu; h=from:to:cc\r
+ :subject:date:message-id:in-reply-to:references; q=dns; s=\r
+ default; b=E3Ea6resbxDmqh0AwLVJUYC5bPXuDMf9DkqY2iHGTNYz+a0J8xKCL\r
+ B/Qd8MyPuJFr4Akl0+2X4lsE2RMycJA5diXwOUzuDEC3Tdr4nS+hXUFCNT2hiVhL\r
+ aAvEFLwkuaGvxa32zSLvFrCTKebA5qugNptYWHTW98KDsryog7CSys=\r
+X-Spam-Info: -2.7; ALL_TRUSTED,AWL,BAYES_00\r
+X-Spam-Scanned-By: cliffclavin.cs.rpi.edu using SpamAssassin 3.2.5 (hard limit\r
+ 15)\r
+Authentication-Results: cliffclavin.cs.rpi.edu;\r
+ DKIM=neutral (none) header.from=glasse@cs.rpi.edu;\r
+ SPF=neutral (mfrom;\r
+ Mechanism '?all' matched) smtp.mail=glasse@cs.rpi.edu\r
+X-Auth-Passed: cliffclavin.cs.rpi.edu:q1FMBOCB008859 Auth:glasse\r
+X-Virus-Scanned-By: cliffclavin.cs.rpi.edu\r
+Received: from localhost ([195.24.209.20]) (authenticated bits=0)\r
+ by cliffclavin.cs.rpi.edu (8.14.3/8.14.3) with ESMTP id q1FMBOCB008859\r
+ (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO);\r
+ Wed, 15 Feb 2012 17:11:37 -0500 (EST)\r
+ (envelope-from glasse@cs.rpi.edu)\r
+From: Ethan Glasser-Camp <glasse@cs.rpi.edu>\r
+To: notmuch@notmuchmail.org\r
+Subject: [RFC PATCH 10/13] Introduce concept of mailstore "constructor"\r
+Date: Wed, 15 Feb 2012 17:02:03 -0500\r
+Message-Id: <1329343326-16410-11-git-send-email-glasse@cs.rpi.edu>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu>\r
+References: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu>\r
+X-Scanned-By: MIMEDefang 2.67 on 128.113.126.25\r
+Cc: Ethan Glasser-Camp <ethan@betacantrips.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Wed, 15 Feb 2012 22:11:56 -0000\r
+\r
+From: Ethan Glasser-Camp <ethan@betacantrips.com>\r
+\r
+Right now this is a fancy no-op because maildir doesn't need any\r
+special data, but getting the API right is good. A constructor can\r
+fail, so return a notmuch_status_t.\r
+\r
+Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com>\r
+---\r
+ lib/mailstore.c | 36 +++++++++++++++++++++++++++++++++---\r
+ lib/notmuch.h | 7 +++++++\r
+ notmuch-config.c | 8 +++++++-\r
+ 3 files changed, 47 insertions(+), 4 deletions(-)\r
+\r
+diff --git a/lib/mailstore.c b/lib/mailstore.c\r
+index 2c6beab..b4d512d 100644\r
+--- a/lib/mailstore.c\r
++++ b/lib/mailstore.c\r
+@@ -17,15 +17,25 @@\r
+ */\r
+ \r
+ #include <stdio.h>\r
++#include <stdarg.h>\r
+ \r
+ #include "notmuch-private.h"\r
+ \r
+ typedef struct _notmuch_mailstore {\r
++ notmuch_status_t (*constructor) (void **data, va_list args);\r
+ FILE *(*open) (struct _notmuch_mailstore *mailstore, const char *filename);\r
+ int (*rename) (struct _notmuch_mailstore *mailstore, const char *old_filename,\r
+ const char *new_filename);\r
++ void *data;\r
+ } _notmuch_mailstore;\r
+ \r
++static notmuch_status_t\r
++_maildir_constructor (void **data, unused (va_list ap))\r
++{\r
++ (*data) = NULL;\r
++ return NOTMUCH_STATUS_SUCCESS;\r
++}\r
++\r
+ static FILE *\r
+ _maildir_open_function (unused (notmuch_mailstore_t *mailstore),\r
+ const char *filename)\r
+@@ -48,12 +58,18 @@ _maildir_rename_function (unused (notmuch_mailstore_t *mailstore),\r
+ * - A function to "rename" a mail message, which is currently only\r
+ * used in tags_to_maildir_flags.\r
+ *\r
+- * - TODO: A way to scan for new messages?\r
++ * - A "constructor" that creates a mailstore object of the requisite\r
++ * type. Arguments are passed via va_args.\r
+ *\r
+- * - TODO: A "constructor"?\r
++ * A mailstore also has a "data" field that can be used to store\r
++ * instance-specific information about this mailstore -- for example,\r
++ * a CouchDB URL or a path. FIXME: mailstores are all statically\r
++ * allocated, so maybe we shouldn't do this.\r
+ */\r
+ _notmuch_mailstore\r
+-notmuch_mailstore_maildir = { _maildir_open_function, _maildir_rename_function };\r
++notmuch_mailstore_maildir = { _maildir_constructor,\r
++ _maildir_open_function, _maildir_rename_function,\r
++ NULL };\r
+ \r
+ _notmuch_mailstore *\r
+ notmuch_mailstore_get_by_name (const char *name)\r
+@@ -76,3 +92,17 @@ notmuch_mailstore_rename (notmuch_mailstore_t *mailstore, const char *old_filena\r
+ {\r
+ return mailstore->rename (mailstore, old_filename, new_filename);\r
+ }\r
++\r
++notmuch_status_t\r
++notmuch_mailstore_construct (notmuch_mailstore_t *mailstore, ...)\r
++{\r
++ va_list va_args;\r
++ notmuch_status_t status;\r
++\r
++ va_start (va_args, mailstore);\r
++\r
++ status = mailstore->constructor (&mailstore->data, va_args);\r
++\r
++ va_end (va_args);\r
++ return status;\r
++}\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index b6e66a9..7f48507 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -430,6 +430,13 @@ int\r
+ notmuch_mailstore_rename (notmuch_mailstore_t *mailstore, const char *old_filename,\r
+ const char *new_filename);\r
+ \r
++/* Initialize the mailstore.\r
++ *\r
++ * Arguments are dependent on the mailstore.\r
++ */\r
++notmuch_status_t\r
++notmuch_mailstore_construct (notmuch_mailstore_t *mailstore, ...);\r
++\r
+ /* Create a new query for 'database'.\r
+ *\r
+ * Here, 'database' should be an open database, (see\r
+diff --git a/notmuch-config.c b/notmuch-config.c\r
+index f611b26..99f872d 100644\r
+--- a/notmuch-config.c\r
++++ b/notmuch-config.c\r
+@@ -592,8 +592,14 @@ notmuch_config_get_mailstore (notmuch_config_t *config)\r
+ * When there are multiple mailstore types and "constructors" for\r
+ * them, this may have to be much more complicated.\r
+ */\r
++ notmuch_status_t status;\r
+ const char *type = notmuch_config_get_database_type (config);\r
+- return notmuch_mailstore_get_by_name (type);\r
++ notmuch_mailstore_t *mailstore = notmuch_mailstore_get_by_name (type);\r
++ status = notmuch_mailstore_construct (mailstore);\r
++ if (status != NOTMUCH_STATUS_SUCCESS) {\r
++ /* abort messily? */\r
++ }\r
++ return mailstore;\r
+ }\r
+ \r
+ const char *\r
+-- \r
+1.7.5.4\r
+\r