[notmuch] [RFC PATCH -V2] notmuch: Add support for multiple maildirs
authorAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Sun, 22 Nov 2009 18:28:46 +0000 (23:58 +0530)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:35:39 +0000 (09:35 -0800)
ff/1e9baa9fafe2eb749de3b0e51b50594ac9b420 [new file with mode: 0644]

diff --git a/ff/1e9baa9fafe2eb749de3b0e51b50594ac9b420 b/ff/1e9baa9fafe2eb749de3b0e51b50594ac9b420
new file mode 100644 (file)
index 0000000..6d725e7
--- /dev/null
@@ -0,0 +1,293 @@
+Return-Path: <aneesh.kumar@linux.vnet.ibm.com>\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 4A6BF431FBC\r
+       for <notmuch@notmuchmail.org>; Sun, 22 Nov 2009 10:28:54 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\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 G-jVUhhvNMIK for <notmuch@notmuchmail.org>;\r
+       Sun, 22 Nov 2009 10:28:53 -0800 (PST)\r
+Received: from e23smtp06.au.ibm.com (e23smtp06.au.ibm.com [202.81.31.148])\r
+       by olra.theworths.org (Postfix) with ESMTP id B0473431FAE\r
+       for <notmuch@notmuchmail.org>; Sun, 22 Nov 2009 10:28:52 -0800 (PST)\r
+Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246])\r
+       by e23smtp06.au.ibm.com (8.14.3/8.13.1) with ESMTP id nAMISmQq019424\r
+       for <notmuch@notmuchmail.org>; Mon, 23 Nov 2009 05:28:48 +1100\r
+Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138])\r
+       by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id\r
+       nAMIPRms1708146\r
+       for <notmuch@notmuchmail.org>; Mon, 23 Nov 2009 05:25:27 +1100\r
+Received: from d23av02.au.ibm.com (loopback [127.0.0.1])\r
+       by d23av02.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id\r
+       nAMISoGV003536\r
+       for <notmuch@notmuchmail.org>; Mon, 23 Nov 2009 05:28:50 +1100\r
+Received: from localhost.localdomain ([9.124.218.229])\r
+       by d23av02.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id\r
+       nAMISmlF003533; Mon, 23 Nov 2009 05:28:49 +1100\r
+From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>\r
+To: notmuch@notmuchmail.org\r
+Date: Sun, 22 Nov 2009 23:58:46 +0530\r
+Message-Id:\r
+ <1258914526-30984-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>\r
+X-Mailer: git-send-email 1.6.5.2.74.g610f9\r
+Subject: [notmuch] [RFC PATCH -V2] notmuch: Add support for multiple maildirs\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.12\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: Sun, 22 Nov 2009 18:28:54 -0000\r
+\r
+This patch separate database path and maildir paths.\r
+It also adds support for multiple maildir paths which\r
+is represented by comma separated values. You need\r
+to have in ~/.notmuch-config\r
+\r
+[maildirs]\r
+path=path1,path2\r
+\r
+Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>\r
+---\r
+ notmuch-client.h |   12 ++++++++++++\r
+ notmuch-config.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ notmuch-new.c    |   24 +++++++++++++++++++++---\r
+ notmuch-setup.c  |   37 +++++++++++++++++++++++++++++++++++--\r
+ 4 files changed, 122 insertions(+), 5 deletions(-)\r
+\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index ea77686..f2fc19f 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -83,6 +83,11 @@ typedef struct {\r
+     add_files_callback_t callback;\r
+ } add_files_state_t;\r
\r
++struct count_ele {\r
++      int count;\r
++      char ele[0];\r
++};\r
++\r
+ static inline void\r
+ chomp_newline (char *str)\r
+ {\r
+@@ -182,4 +187,11 @@ notmuch_config_set_user_other_email (notmuch_config_t *config,\r
+ notmuch_bool_t\r
+ debugger_is_active (void);\r
\r
++const struct count_ele *\r
++notmuch_config_get_maildirs (notmuch_config_t *config);\r
++\r
++void\r
++notmuch_config_set_maildirs (notmuch_config_t *config,\r
++                              const char *maildirs);\r
++\r
+ #endif\r
+diff --git a/notmuch-config.c b/notmuch-config.c\r
+index aaa0372..330da48 100644\r
+--- a/notmuch-config.c\r
++++ b/notmuch-config.c\r
+@@ -62,6 +62,7 @@ struct _notmuch_config {\r
+     char *user_primary_email;\r
+     char **user_other_email;\r
+     size_t user_other_email_length;\r
++    struct count_ele *maildirs;\r
+ };\r
\r
+ static int\r
+@@ -345,6 +346,59 @@ notmuch_config_set_database_path (notmuch_config_t *config,\r
+     config->database_path = NULL;\r
+ }\r
\r
++const struct count_ele *\r
++notmuch_config_get_maildirs (notmuch_config_t *config)\r
++{\r
++      int size;\r
++      char *cur_ptr;\r
++      char *dirs, *token, *saveptr;\r
++      struct count_ele *maildirs = NULL;\r
++      if (config->maildirs == NULL) {\r
++           dirs = g_key_file_get_string (config->key_file,\r
++                                   "maildirs", "path", NULL);\r
++              if (dirs) {\r
++                      size = sizeof(struct count_ele) + strlen(dirs) + 1;\r
++                      /* comma separated paths */\r
++                      maildirs = (struct count_ele *)malloc(size);\r
++                      maildirs->count = 0;\r
++                      cur_ptr = maildirs->ele;\r
++                      token = strtok_r(dirs, ",", &saveptr);\r
++                      if (token == NULL) {\r
++                              /* only one element */\r
++                              strcpy(maildirs->ele, dirs);\r
++                              maildirs->count = 1;\r
++                              free(dirs);\r
++                              config->maildirs = maildirs;\r
++                              return maildirs;\r
++                      }\r
++                      strcpy(maildirs->ele, token);\r
++                      maildirs->count++;\r
++                      cur_ptr += strlen(token) + 1;\r
++                      while ((token = strtok_r(NULL, ",", &saveptr))) {\r
++                              strcpy(cur_ptr, token);\r
++                              maildirs->count++;\r
++                              cur_ptr += strlen(token) + 1;\r
++                      }\r
++                      free (dirs);\r
++              }\r
++              config->maildirs = maildirs;\r
++      }\r
++      return config->maildirs;\r
++\r
++\r
++}\r
++\r
++void\r
++notmuch_config_set_maildirs (notmuch_config_t *config,\r
++                                const char *maildirs)\r
++{\r
++    g_key_file_set_string (config->key_file,\r
++                         "maildirs", "path", maildirs);\r
++\r
++    free (config->maildirs);\r
++    config->maildirs = NULL;\r
++}\r
++\r
+ const char *\r
+ notmuch_config_get_user_name (notmuch_config_t *config)\r
+ {\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index 0dd2784..1a9406b 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -385,14 +385,16 @@ notmuch_new_command (void *ctx,\r
+ {\r
+     notmuch_config_t *config;\r
+     notmuch_database_t *notmuch;\r
++    const struct count_ele *maildirs;\r
+     add_files_state_t add_files_state;\r
+     double elapsed;\r
+     struct timeval tv_now;\r
+-    int ret = 0;\r
++    int ret = 0, maildirs_count;\r
+     struct stat st;\r
+     const char *db_path;\r
+     char *dot_notmuch_path;\r
+     struct sigaction action;\r
++    const char *maildir_path;\r
\r
+     /* Setup our handler for SIGINT */\r
+     memset (&action, 0, sizeof (struct sigaction));\r
+@@ -406,6 +408,9 @@ notmuch_new_command (void *ctx,\r
+       return 1;\r
\r
+     db_path = notmuch_config_get_database_path (config);\r
++    maildirs = notmuch_config_get_maildirs (config);\r
++    if (maildirs == NULL)\r
++          return 1;\r
\r
+     dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");\r
\r
+@@ -413,7 +418,13 @@ notmuch_new_command (void *ctx,\r
+       int count;\r
\r
+       count = 0;\r
+-      count_files (db_path, &count);\r
++      maildirs_count = maildirs->count;\r
++      maildir_path   = maildirs->ele;\r
++      while (maildirs_count) {\r
++              count_files (maildir_path, &count);\r
++              maildir_path += strlen(maildir_path) + 1;\r
++              maildirs_count--;\r
++      }\r
+       if (interrupted)\r
+           return 1;\r
\r
+@@ -439,7 +450,14 @@ notmuch_new_command (void *ctx,\r
+     add_files_state.added_messages = 0;\r
+     gettimeofday (&add_files_state.tv_start, NULL);\r
\r
+-    ret = add_files (notmuch, db_path, &add_files_state);\r
++    maildirs_count = maildirs->count;\r
++    maildir_path   = maildirs->ele;\r
++    while (maildirs_count) {\r
++          printf ("Processing maildir %s\n", maildir_path);\r
++          ret = add_files (notmuch, maildir_path, &add_files_state);\r
++          maildir_path += strlen(maildir_path) + 1;\r
++          maildirs_count--;\r
++    }\r
\r
+     gettimeofday (&tv_now, NULL);\r
+     elapsed = notmuch_time_elapsed (add_files_state.tv_start,\r
+diff --git a/notmuch-setup.c b/notmuch-setup.c\r
+index 482efd2..e358c68 100644\r
+--- a/notmuch-setup.c\r
++++ b/notmuch-setup.c\r
+@@ -97,7 +97,10 @@ notmuch_setup_command (unused (void *ctx),\r
+     size_t old_other_emails_len;\r
+     GPtrArray *other_emails;\r
+     unsigned int i;\r
+-    int is_new;\r
++    int is_new, maildirs_count, size = 0;\r
++    const struct count_ele *maildirs;\r
++    const char *maildir_path;\r
++    char *cmaildirs = NULL;;\r
\r
+ #define prompt(format, ...)                           \\r
+     do {                                              \\r
+@@ -146,7 +149,7 @@ notmuch_setup_command (unused (void *ctx),\r
+                                            other_emails->len);\r
+     g_ptr_array_free (other_emails, TRUE);\r
\r
+-    prompt ("Top-level directory of your email archive [%s]: ",\r
++    prompt ("Directory for notmuch database [%s]: ",\r
+           notmuch_config_get_database_path (config));\r
+     if (strlen (response)) {\r
+       const char *absolute_path;\r
+@@ -155,6 +158,36 @@ notmuch_setup_command (unused (void *ctx),\r
+       notmuch_config_set_database_path (config, absolute_path);\r
+     }\r
\r
++    maildirs = notmuch_config_get_maildirs (config);\r
++    if (maildirs) {\r
++          /* build the comma separated value */\r
++          maildirs_count = maildirs->count;\r
++          maildir_path   = maildirs->ele;\r
++          while (maildirs_count) {\r
++                  size += strlen(maildir_path) + 1;\r
++                  maildir_path += strlen(maildir_path) + 1;\r
++                  maildirs_count--;\r
++          }\r
++          maildirs_count = maildirs->count;\r
++          cmaildirs      = malloc(size);\r
++          maildir_path   = maildirs->ele;\r
++          memset(cmaildirs, 0, size);\r
++          while(maildirs_count) {\r
++                  strncat(cmaildirs, maildir_path, size);\r
++                  maildirs_count--;\r
++                  if (maildirs_count == 0)\r
++                          break;\r
++                  strncat(cmaildirs, ",", size);\r
++                  maildir_path += strlen(maildir_path) + 1;\r
++\r
++          }\r
++    }\r
++\r
++    prompt ("Comma separated maildirs [%s]: ", cmaildirs);\r
++\r
++    if (strlen (response))\r
++      notmuch_config_set_maildirs (config, response);\r
++\r
+     notmuch_config_save (config);\r
\r
+     if (is_new)\r
+-- \r
+1.6.5.2.74.g610f9\r
+\r