unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [RFC PATCH -V2] notmuch: Add support for multiple maildirs
@ 2009-11-22 18:28 Aneesh Kumar K.V
  2009-11-23  3:51 ` Carl Worth
  0 siblings, 1 reply; 3+ messages in thread
From: Aneesh Kumar K.V @ 2009-11-22 18:28 UTC (permalink / raw)
  To: notmuch

This patch separate database path and maildir paths.
It also adds support for multiple maildir paths which
is represented by comma separated values. You need
to have in ~/.notmuch-config

[maildirs]
path=path1,path2

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 notmuch-client.h |   12 ++++++++++++
 notmuch-config.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 notmuch-new.c    |   24 +++++++++++++++++++++---
 notmuch-setup.c  |   37 +++++++++++++++++++++++++++++++++++--
 4 files changed, 122 insertions(+), 5 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index ea77686..f2fc19f 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -83,6 +83,11 @@ typedef struct {
     add_files_callback_t callback;
 } add_files_state_t;
 
+struct count_ele {
+	int count;
+	char ele[0];
+};
+
 static inline void
 chomp_newline (char *str)
 {
@@ -182,4 +187,11 @@ notmuch_config_set_user_other_email (notmuch_config_t *config,
 notmuch_bool_t
 debugger_is_active (void);
 
+const struct count_ele *
+notmuch_config_get_maildirs (notmuch_config_t *config);
+
+void
+notmuch_config_set_maildirs (notmuch_config_t *config,
+				const char *maildirs);
+
 #endif
diff --git a/notmuch-config.c b/notmuch-config.c
index aaa0372..330da48 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -62,6 +62,7 @@ struct _notmuch_config {
     char *user_primary_email;
     char **user_other_email;
     size_t user_other_email_length;
+    struct count_ele *maildirs;
 };
 
 static int
@@ -345,6 +346,59 @@ notmuch_config_set_database_path (notmuch_config_t *config,
     config->database_path = NULL;
 }
 
+const struct count_ele *
+notmuch_config_get_maildirs (notmuch_config_t *config)
+{
+	int size;
+	char *cur_ptr;
+	char *dirs, *token, *saveptr;
+	struct count_ele *maildirs = NULL;
+	if (config->maildirs == NULL) {
+	     dirs = g_key_file_get_string (config->key_file,
+				     "maildirs", "path", NULL);
+		if (dirs) {
+			size = sizeof(struct count_ele) + strlen(dirs) + 1;
+			/* comma separated paths */
+			maildirs = (struct count_ele *)malloc(size);
+			maildirs->count = 0;
+			cur_ptr = maildirs->ele;
+			token = strtok_r(dirs, ",", &saveptr);
+			if (token == NULL) {
+				/* only one element */
+				strcpy(maildirs->ele, dirs);
+				maildirs->count = 1;
+				free(dirs);
+				config->maildirs = maildirs;
+				return maildirs;
+			}
+			strcpy(maildirs->ele, token);
+			maildirs->count++;
+			cur_ptr += strlen(token) + 1;
+			while ((token = strtok_r(NULL, ",", &saveptr))) {
+				strcpy(cur_ptr, token);
+				maildirs->count++;
+				cur_ptr += strlen(token) + 1;
+			}
+			free (dirs);
+		}
+		config->maildirs = maildirs;
+	}
+	return config->maildirs;
+
+
+}
+
+void
+notmuch_config_set_maildirs (notmuch_config_t *config,
+				  const char *maildirs)
+{
+    g_key_file_set_string (config->key_file,
+			   "maildirs", "path", maildirs);
+
+    free (config->maildirs);
+    config->maildirs = NULL;
+}
+
 const char *
 notmuch_config_get_user_name (notmuch_config_t *config)
 {
diff --git a/notmuch-new.c b/notmuch-new.c
index 0dd2784..1a9406b 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -385,14 +385,16 @@ notmuch_new_command (void *ctx,
 {
     notmuch_config_t *config;
     notmuch_database_t *notmuch;
+    const struct count_ele *maildirs;
     add_files_state_t add_files_state;
     double elapsed;
     struct timeval tv_now;
-    int ret = 0;
+    int ret = 0, maildirs_count;
     struct stat st;
     const char *db_path;
     char *dot_notmuch_path;
     struct sigaction action;
+    const char *maildir_path;
 
     /* Setup our handler for SIGINT */
     memset (&action, 0, sizeof (struct sigaction));
@@ -406,6 +408,9 @@ notmuch_new_command (void *ctx,
 	return 1;
 
     db_path = notmuch_config_get_database_path (config);
+    maildirs = notmuch_config_get_maildirs (config);
+    if (maildirs == NULL)
+	    return 1;
 
     dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");
 
@@ -413,7 +418,13 @@ notmuch_new_command (void *ctx,
 	int count;
 
 	count = 0;
-	count_files (db_path, &count);
+	maildirs_count = maildirs->count;
+	maildir_path   = maildirs->ele;
+	while (maildirs_count) {
+		count_files (maildir_path, &count);
+		maildir_path += strlen(maildir_path) + 1;
+		maildirs_count--;
+	}
 	if (interrupted)
 	    return 1;
 
@@ -439,7 +450,14 @@ notmuch_new_command (void *ctx,
     add_files_state.added_messages = 0;
     gettimeofday (&add_files_state.tv_start, NULL);
 
-    ret = add_files (notmuch, db_path, &add_files_state);
+    maildirs_count = maildirs->count;
+    maildir_path   = maildirs->ele;
+    while (maildirs_count) {
+	    printf ("Processing maildir %s\n", maildir_path);
+	    ret = add_files (notmuch, maildir_path, &add_files_state);
+	    maildir_path += strlen(maildir_path) + 1;
+	    maildirs_count--;
+    }
 
     gettimeofday (&tv_now, NULL);
     elapsed = notmuch_time_elapsed (add_files_state.tv_start,
diff --git a/notmuch-setup.c b/notmuch-setup.c
index 482efd2..e358c68 100644
--- a/notmuch-setup.c
+++ b/notmuch-setup.c
@@ -97,7 +97,10 @@ notmuch_setup_command (unused (void *ctx),
     size_t old_other_emails_len;
     GPtrArray *other_emails;
     unsigned int i;
-    int is_new;
+    int is_new, maildirs_count, size = 0;
+    const struct count_ele *maildirs;
+    const char *maildir_path;
+    char *cmaildirs = NULL;;
 
 #define prompt(format, ...)				\
     do {						\
@@ -146,7 +149,7 @@ notmuch_setup_command (unused (void *ctx),
 					     other_emails->len);
     g_ptr_array_free (other_emails, TRUE);
 
-    prompt ("Top-level directory of your email archive [%s]: ",
+    prompt ("Directory for notmuch database [%s]: ",
 	    notmuch_config_get_database_path (config));
     if (strlen (response)) {
 	const char *absolute_path;
@@ -155,6 +158,36 @@ notmuch_setup_command (unused (void *ctx),
 	notmuch_config_set_database_path (config, absolute_path);
     }
 
+    maildirs = notmuch_config_get_maildirs (config);
+    if (maildirs) {
+	    /* build the comma separated value */
+	    maildirs_count = maildirs->count;
+	    maildir_path   = maildirs->ele;
+	    while (maildirs_count) {
+		    size += strlen(maildir_path) + 1;
+		    maildir_path += strlen(maildir_path) + 1;
+		    maildirs_count--;
+	    }
+	    maildirs_count = maildirs->count;
+	    cmaildirs      = malloc(size);
+	    maildir_path   = maildirs->ele;
+	    memset(cmaildirs, 0, size);
+	    while(maildirs_count) {
+		    strncat(cmaildirs, maildir_path, size);
+		    maildirs_count--;
+		    if (maildirs_count == 0)
+			    break;
+		    strncat(cmaildirs, ",", size);
+		    maildir_path += strlen(maildir_path) + 1;
+
+	    }
+    }
+
+    prompt ("Comma separated maildirs [%s]: ", cmaildirs);
+
+    if (strlen (response))
+	notmuch_config_set_maildirs (config, response);
+
     notmuch_config_save (config);
 
     if (is_new)
-- 
1.6.5.2.74.g610f9

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH -V2] notmuch: Add support for multiple maildirs
  2009-11-22 18:28 [RFC PATCH -V2] notmuch: Add support for multiple maildirs Aneesh Kumar K.V
@ 2009-11-23  3:51 ` Carl Worth
  2009-11-23  5:23   ` Aneesh Kumar K.V
  0 siblings, 1 reply; 3+ messages in thread
From: Carl Worth @ 2009-11-23  3:51 UTC (permalink / raw)
  To: Aneesh Kumar K.V, notmuch

On Sun, 22 Nov 2009 23:58:46 +0530, "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com> wrote:
> This patch separate database path and maildir paths.
> It also adds support for multiple maildir paths which
> is represented by comma separated values.

I have a running joke with my good friend Behdad that we should add a
git-hook to refuse any commit with the word "also" in the commit
message. It's often a sign that the commit is actually doing two
independent things, and that those two independent things should be
split into separate commits.

I think that's the case here.

> You need to have in ~/.notmuch-config
> [maildirs]
> path=path1,path2

Documentation in the commit message doesn't count. We need this
documentation to be inserted into the configuration file as a comment,
like with the other values.

> +	     dirs = g_key_file_get_string (config->key_file,
> +				     "maildirs", "path", NULL);
> +		if (dirs) {
> +			size = sizeof(struct count_ele) + strlen(dirs) + 1;
> +			/* comma separated paths */
> +			maildirs = (struct count_ele *)malloc(size);

There's a g_key_file_get_string_list function that will do all the
splitting of a multiple-valued configuration entry into multiple
strings. I suggest using that here instead of doing open-coded parsing.

> -    prompt ("Top-level directory of your email archive [%s]: ",
> +    prompt ("Directory for notmuch database [%s]: ",

Is there really a reason to prompt for this here, rather than just using
a default value (and letting the user know what it is?). One thing I'm
worried about is the user thinking they can run "notmuch setup", change
this value, and expect things to work, (which of course, they won't).

I'd be happier if the user understood that the database is relocatable
and they can just "mv" things around as they want to.

Of course, for that, then we'd actually need to *make* the database
relocatable. One thing that we get right now with the .notmuch directory
_inside_ the mail directory is that everything is relocatable.

If you just pull it out, like you do here, then suddenly the database
will be full of absolute paths to mail files, and things will break if
the top-level mail-directory is moved. And that's a regression compared
to the current case.

> +    prompt ("Comma separated maildirs [%s]: ", cmaildirs);

If we are going to support multiple directories for mail here, then we
should prompt separately for each (like we are doing for the email
addresses already).

Also, I'd prefer something like "Top-level directory of email archive"
like we had before. I certainly don't want to give the user the
impression that they need to type in a path to each individual maildir
that they have.

Finally, (and maybe I should have started with this), what's the actual
use case here? Is it difficult to just arrange all mail to be under one
top-level directory, (perhaps just using symlinks even).

-Carl

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH -V2] notmuch: Add support for multiple maildirs
  2009-11-23  3:51 ` Carl Worth
@ 2009-11-23  5:23   ` Aneesh Kumar K.V
  0 siblings, 0 replies; 3+ messages in thread
From: Aneesh Kumar K.V @ 2009-11-23  5:23 UTC (permalink / raw)
  To: Carl Worth; +Cc: notmuch

On Mon, Nov 23, 2009 at 04:51:34AM +0100, Carl Worth wrote:
> Finally, (and maybe I should have started with this), what's the actual
> use case here? Is it difficult to just arrange all mail to be under one
> top-level directory, (perhaps just using symlinks even).
> 

Ok i switched to using a separate directory for notmuch and symlink the
interested folders into that. So you can ignore the patch

-aneesh

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-11-23  5:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-22 18:28 [RFC PATCH -V2] notmuch: Add support for multiple maildirs Aneesh Kumar K.V
2009-11-23  3:51 ` Carl Worth
2009-11-23  5:23   ` Aneesh Kumar K.V

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).