Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id E0A6F431FBF for ; Sun, 22 Nov 2009 08:12:38 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XvGv5+Ipgl4X for ; Sun, 22 Nov 2009 08:12:38 -0800 (PST) Received: from e23smtp05.au.ibm.com (e23smtp05.au.ibm.com [202.81.31.147]) by olra.theworths.org (Postfix) with ESMTP id B3F12431FBC for ; Sun, 22 Nov 2009 08:12:37 -0800 (PST) Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246]) by e23smtp05.au.ibm.com (8.14.3/8.13.1) with ESMTP id nAMG9bHV012982 for ; Mon, 23 Nov 2009 03:09:37 +1100 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id nAMG9CxN1744906 for ; Mon, 23 Nov 2009 03:09:12 +1100 Received: from d23av04.au.ibm.com (loopback [127.0.0.1]) by d23av04.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id nAMGCZLK014287 for ; Mon, 23 Nov 2009 03:12:35 +1100 Received: from localhost.localdomain ([9.124.218.229]) by d23av04.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id nAMGCXsC014283; Mon, 23 Nov 2009 03:12:34 +1100 From: "Aneesh Kumar K.V" To: notmuch@notmuchmail.org Date: Sun, 22 Nov 2009 21:42:30 +0530 Message-Id: <1258906350-10896-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-Mailer: git-send-email 1.6.5.2.74.g610f9 Subject: [notmuch] [RFC PATCH] notmuch: Add support for multiple maildirs X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Nov 2009 16:12:39 -0000 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 --- 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