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 4A6BF431FBC for ; Sun, 22 Nov 2009 10:28:54 -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 G-jVUhhvNMIK for ; Sun, 22 Nov 2009 10:28:53 -0800 (PST) Received: from e23smtp06.au.ibm.com (e23smtp06.au.ibm.com [202.81.31.148]) by olra.theworths.org (Postfix) with ESMTP id B0473431FAE for ; Sun, 22 Nov 2009 10:28:52 -0800 (PST) Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246]) by e23smtp06.au.ibm.com (8.14.3/8.13.1) with ESMTP id nAMISmQq019424 for ; Mon, 23 Nov 2009 05:28:48 +1100 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id nAMIPRms1708146 for ; Mon, 23 Nov 2009 05:25:27 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id nAMISoGV003536 for ; Mon, 23 Nov 2009 05:28:50 +1100 Received: from localhost.localdomain ([9.124.218.229]) by d23av02.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id nAMISmlF003533; Mon, 23 Nov 2009 05:28:49 +1100 From: "Aneesh Kumar K.V" To: notmuch@notmuchmail.org Date: Sun, 22 Nov 2009 23:58:46 +0530 Message-Id: <1258914526-30984-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 -V2] 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 18:28:54 -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 | 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