[RFC PATCH] notmuch: Add support for multiple maildirs

classic Classic list List threaded Threaded
1 message Options
Aneesh Kumar K.V Aneesh Kumar K.V
Reply | Threaded
Open this post in threaded view
|

[RFC PATCH] notmuch: Add support for multiple maildirs

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 <[hidden email]>
---
 notmuch-client.h |    8 ++++++++
 notmuch-config.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 notmuch-new.c    |   24 +++++++++++++++++++++---
 3 files changed, 72 insertions(+), 3 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index ea77686..128fd7f 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,7 @@ 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);
+
 #endif
diff --git a/notmuch-config.c b/notmuch-config.c
index aaa0372..12b0081 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
@@ -334,6 +335,48 @@ notmuch_config_get_database_path (notmuch_config_t *config)
     return config->database_path;
 }
 
+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_database_path (notmuch_config_t *config,
   const char *database_path)
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,
--
1.6.5.2.74.g610f9