[RFC PATCH 01/13] Create configuration paramater database.type

Subject: [RFC PATCH 01/13] Create configuration paramater database.type

Date: Wed, 15 Feb 2012 17:01:54 -0500

To: notmuch@notmuchmail.org

Cc: Ethan Glasser-Camp

From: Ethan Glasser-Camp


From: Ethan Glasser-Camp <ethan@betacantrips.com>

This will be used to allow different backends to be developed to allow
access to mail that isn't stored in Maildirs.

Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com>
---
 notmuch-client.h |    7 ++++++
 notmuch-config.c |   57 +++++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 59 insertions(+), 5 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index 60828aa..4518cb0 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -220,6 +220,13 @@ notmuch_config_set_database_path (notmuch_config_t *config,
 				  const char *database_path);
 
 const char *
+notmuch_config_get_database_type (notmuch_config_t *config);
+
+void
+notmuch_config_set_database_type (notmuch_config_t *config,
+				  const char *database_type);
+
+const char *
 notmuch_config_get_user_name (notmuch_config_t *config);
 
 void
diff --git a/notmuch-config.c b/notmuch-config.c
index a124e34..b8bee69 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -32,11 +32,24 @@ static const char toplevel_config_comment[] =
 static const char database_config_comment[] =
     " Database configuration\n"
     "\n"
-    " The only value supported here is 'path' which should be the top-level\n"
-    " directory where your mail currently exists and to where mail will be\n"
-    " delivered in the future. Files should be individual email messages.\n"
-    " Notmuch will store its database within a sub-directory of the path\n"
-    " configured here named \".notmuch\".\n";
+    " Here is where you can tell notmuch where your mail currently exists\n"
+    " and where mail will be delivered in the future."
+    "\n"
+    " The following options are supported here:\n"
+    "\n"
+    "\ttype	The type of mail backend. The only currently supported\n"
+    "\t	value is \"maildir\".\n"
+    "\tpath	For the maildir backend, the top-level maildir directory.\n"
+    "\t	For all backends, the location where notmuch should store its\n"
+    "\t	database. Notmuch will store its database within a sub-directory\n"
+    "\t	of this path named \".notmuch\".\n"
+    "\n"
+    " Maildir backend\n"
+    "\n"
+    " This backend reads mail from a directory tree where files are\n"
+    " individual email messages.\n"
+    " The only configuration option is 'path' which should be the top-level\n"
+    " directory.\n";
 
 static const char new_config_comment[] =
     " Configuration for \"notmuch new\"\n"
@@ -99,6 +112,7 @@ struct _notmuch_config {
     GKeyFile *key_file;
 
     char *database_path;
+    char *database_type;
     char *user_name;
     char *user_primary_email;
     const char **user_other_email;
@@ -258,6 +272,7 @@ notmuch_config_open (void *ctx,
     config->key_file = g_key_file_new ();
 
     config->database_path = NULL;
+    config->database_type = NULL;
     config->user_name = NULL;
     config->user_primary_email = NULL;
     config->user_other_email = NULL;
@@ -320,6 +335,10 @@ notmuch_config_open (void *ctx,
 	talloc_free (path);
     }
 
+    if (notmuch_config_get_database_type (config) == NULL) {
+	notmuch_config_set_database_type (config, "maildir");
+    }
+
     if (notmuch_config_get_user_name (config) == NULL) {
 	char *name = get_name_from_passwd_file (config);
 	notmuch_config_set_user_name (config, name);
@@ -538,6 +557,34 @@ notmuch_config_set_database_path (notmuch_config_t *config,
 }
 
 const char *
+notmuch_config_get_database_type (notmuch_config_t *config)
+{
+    char *type;
+
+    if (config->database_type == NULL) {
+	type = g_key_file_get_string (config->key_file,
+				      "database", "type", NULL);
+	if (type) {
+	    config->database_type = talloc_strdup (config, type);
+	    free (type);
+	}
+    }
+
+    return config->database_type;
+}
+
+void
+notmuch_config_set_database_type (notmuch_config_t *config,
+				  const char *database_type)
+{
+    g_key_file_set_string (config->key_file,
+			   "database", "type", database_type);
+
+    talloc_free (config->database_type);
+    config->database_type = NULL;
+}
+
+const char *
 notmuch_config_get_user_name (notmuch_config_t *config)
 {
     char *name;
-- 
1.7.5.4


Thread: