aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorGravatar Carl Worth <cworth@cworth.org>2009-11-11 17:01:55 -0800
committerGravatar Carl Worth <cworth@cworth.org>2009-11-11 17:01:55 -0800
commit305e76bc0ab2e7f3bd1ff2580e8d5dac8b4a7164 (patch)
tree96760f7ac15b036af80f28f1ba53690cb7741410 /lib
parent69611e66a589881bf4de9786d3f6df991c604f3d (diff)
notmuch: Add a configuration system.
This will allow for things like the database path to be specified without any cheesy NOTMUCH_BASE environment variable. It also will allow "notmuch reply" to recognize the user's email address when constructing a reply in order to do the right thing, (that is, to use the user's address to which mail was sent as From:, and not to reply to the user's own addresses). With this change, the "notmuch setup" command is now strictly for changing the configuration of notmuch. It no longer creates the database, but instead instructs the user to call "notmuch new" to do that.
Diffstat (limited to 'lib')
-rw-r--r--lib/database.cc31
-rw-r--r--lib/notmuch.h25
2 files changed, 5 insertions, 51 deletions
diff --git a/lib/database.cc b/lib/database.cc
index 4524016b..6b7ad49d 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -391,22 +391,6 @@ parse_references (void *ctx,
}
}
-char *
-notmuch_database_default_path (void)
-{
- char *path;
-
- if (getenv ("NOTMUCH_BASE"))
- return strdup (getenv ("NOTMUCH_BASE"));
-
- if (asprintf (&path, "%s/mail", getenv ("HOME")) == -1) {
- fprintf (stderr, "Out of memory.\n");
- return xstrdup("");
- }
-
- return path;
-}
-
notmuch_database_t *
notmuch_database_create (const char *path)
{
@@ -414,10 +398,11 @@ notmuch_database_create (const char *path)
char *notmuch_path = NULL;
struct stat st;
int err;
- char *local_path = NULL;
- if (path == NULL)
- path = local_path = notmuch_database_default_path ();
+ if (path == NULL) {
+ fprintf (stderr, "Error: Cannot create a database for a NULL path.\n");
+ goto DONE;
+ }
err = stat (path, &st);
if (err) {
@@ -447,8 +432,6 @@ notmuch_database_create (const char *path)
DONE:
if (notmuch_path)
talloc_free (notmuch_path);
- if (local_path)
- free (local_path);
return notmuch;
}
@@ -460,12 +443,8 @@ notmuch_database_open (const char *path)
char *notmuch_path = NULL, *xapian_path = NULL;
struct stat st;
int err;
- char *local_path = NULL;
unsigned int i;
- if (path == NULL)
- path = local_path = notmuch_database_default_path ();
-
if (asprintf (&notmuch_path, "%s/%s", path, ".notmuch") == -1) {
notmuch_path = NULL;
fprintf (stderr, "Out of memory\n");
@@ -520,8 +499,6 @@ notmuch_database_open (const char *path)
}
DONE:
- if (local_path)
- free (local_path);
if (notmuch_path)
free (notmuch_path);
if (xapian_path)
diff --git a/lib/notmuch.h b/lib/notmuch.h
index bab573dd..c1c7980a 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -114,19 +114,6 @@ typedef struct _notmuch_messages notmuch_messages_t;
typedef struct _notmuch_message notmuch_message_t;
typedef struct _notmuch_tags notmuch_tags_t;
-/* Lookup the default database path.
- *
- * This is the path that will be used by notmuch_database_create and
- * notmuch_database_open if given a NULL path. Specifically it will be
- * the value of the NOTMUCH_BASE environment variable if set,
- * otherwise ${HOME}/mail
- *
- * Returns a newly allocated string which the caller should free()
- * when finished with it.
- */
-char *
-notmuch_database_default_path (void);
-
/* Create a new, empty notmuch database located at 'path'.
*
* The path should be a top-level directory to a collection of
@@ -134,11 +121,6 @@ notmuch_database_default_path (void);
* create a new ".notmuch" directory within 'path' where notmuch will
* store its data.
*
- * Passing a value of NULL for 'path' will cause notmuch to open the
- * default database. The default database path can be specified by the
- * NOTMUCH_BASE environment variable, and is equivalent to
- * ${HOME}/mail if NOTMUCH_BASE is not set.
- *
* After a successful call to notmuch_database_create, the returned
* database will be open so the caller should call
* notmuch_database_close when finished with it.
@@ -157,7 +139,7 @@ notmuch_database_create (const char *path);
/* XXX: I think I'd like this to take an extra argument of
* notmuch_status_t* for returning a status value on failure. */
-/* Open a an existing notmuch database located at 'path'.
+/* Open an existing notmuch database located at 'path'.
*
* The database should have been created at some time in the past,
* (not necessarily by this process), by calling
@@ -166,11 +148,6 @@ notmuch_database_create (const char *path);
* An existing notmuch database can be identified by the presence of a
* directory named ".notmuch" below 'path'.
*
- * Passing a value of NULL for 'path' will cause notmuch to open the
- * default database. The default database path can be specified by the
- * NOTMUCH_BASE environment variable, and is equivalent to
- * ${HOME}/mail if NOTMUCH_BASE is not set.
- *
* The caller should call notmuch_database_close when finished with
* this database.
*