[notmuch] [RFC PATCH] notmuch: Add support for multiple maildirs
authorAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Sun, 22 Nov 2009 16:12:30 +0000 (21:42 +0530)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:35:39 +0000 (09:35 -0800)
07/dadae44129a2dc0a1954c3cb5f21800d98c869 [new file with mode: 0644]

diff --git a/07/dadae44129a2dc0a1954c3cb5f21800d98c869 b/07/dadae44129a2dc0a1954c3cb5f21800d98c869
new file mode 100644 (file)
index 0000000..35de00d
--- /dev/null
@@ -0,0 +1,215 @@
+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 E0A6F431FBF\r
+       for <notmuch@notmuchmail.org>; Sun, 22 Nov 2009 08:12:38 -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 XvGv5+Ipgl4X for <notmuch@notmuchmail.org>;\r
+       Sun, 22 Nov 2009 08:12:38 -0800 (PST)\r
+Received: from e23smtp05.au.ibm.com (e23smtp05.au.ibm.com [202.81.31.147])\r
+       by olra.theworths.org (Postfix) with ESMTP id B3F12431FBC\r
+       for <notmuch@notmuchmail.org>; Sun, 22 Nov 2009 08:12:37 -0800 (PST)\r
+Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246])\r
+       by e23smtp05.au.ibm.com (8.14.3/8.13.1) with ESMTP id nAMG9bHV012982\r
+       for <notmuch@notmuchmail.org>; Mon, 23 Nov 2009 03:09:37 +1100\r
+Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139])\r
+       by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id\r
+       nAMG9CxN1744906\r
+       for <notmuch@notmuchmail.org>; Mon, 23 Nov 2009 03:09:12 +1100\r
+Received: from d23av04.au.ibm.com (loopback [127.0.0.1])\r
+       by d23av04.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id\r
+       nAMGCZLK014287\r
+       for <notmuch@notmuchmail.org>; Mon, 23 Nov 2009 03:12:35 +1100\r
+Received: from localhost.localdomain ([9.124.218.229])\r
+       by d23av04.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id\r
+       nAMGCXsC014283; Mon, 23 Nov 2009 03:12:34 +1100\r
+From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>\r
+To: notmuch@notmuchmail.org\r
+Date: Sun, 22 Nov 2009 21:42:30 +0530\r
+Message-Id:\r
+ <1258906350-10896-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] 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 16:12:39 -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 |    8 ++++++++\r
+ notmuch-config.c |   43 +++++++++++++++++++++++++++++++++++++++++++\r
+ notmuch-new.c    |   24 +++++++++++++++++++++---\r
+ 3 files changed, 72 insertions(+), 3 deletions(-)\r
+\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index ea77686..128fd7f 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,7 @@ 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
+ #endif\r
+diff --git a/notmuch-config.c b/notmuch-config.c\r
+index aaa0372..12b0081 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
+@@ -334,6 +335,48 @@ notmuch_config_get_database_path (notmuch_config_t *config)\r
+     return config->database_path;\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_database_path (notmuch_config_t *config,\r
+                                 const char *database_path)\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
+-- \r
+1.6.5.2.74.g610f9\r
+\r