Re: [notmuch] Introducing notmuchsync
[notmuch-archives.git] / 07 / dadae44129a2dc0a1954c3cb5f21800d98c869
1 Return-Path: <aneesh.kumar@linux.vnet.ibm.com>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id E0A6F431FBF\r
6         for <notmuch@notmuchmail.org>; Sun, 22 Nov 2009 08:12:38 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 Received: from olra.theworths.org ([127.0.0.1])\r
9         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
10         with ESMTP id XvGv5+Ipgl4X for <notmuch@notmuchmail.org>;\r
11         Sun, 22 Nov 2009 08:12:38 -0800 (PST)\r
12 Received: from e23smtp05.au.ibm.com (e23smtp05.au.ibm.com [202.81.31.147])\r
13         by olra.theworths.org (Postfix) with ESMTP id B3F12431FBC\r
14         for <notmuch@notmuchmail.org>; Sun, 22 Nov 2009 08:12:37 -0800 (PST)\r
15 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246])\r
16         by e23smtp05.au.ibm.com (8.14.3/8.13.1) with ESMTP id nAMG9bHV012982\r
17         for <notmuch@notmuchmail.org>; Mon, 23 Nov 2009 03:09:37 +1100\r
18 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139])\r
19         by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id\r
20         nAMG9CxN1744906\r
21         for <notmuch@notmuchmail.org>; Mon, 23 Nov 2009 03:09:12 +1100\r
22 Received: from d23av04.au.ibm.com (loopback [127.0.0.1])\r
23         by d23av04.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id\r
24         nAMGCZLK014287\r
25         for <notmuch@notmuchmail.org>; Mon, 23 Nov 2009 03:12:35 +1100\r
26 Received: from localhost.localdomain ([9.124.218.229])\r
27         by d23av04.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id\r
28         nAMGCXsC014283; Mon, 23 Nov 2009 03:12:34 +1100\r
29 From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>\r
30 To: notmuch@notmuchmail.org\r
31 Date: Sun, 22 Nov 2009 21:42:30 +0530\r
32 Message-Id:\r
33  <1258906350-10896-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>\r
34 X-Mailer: git-send-email 1.6.5.2.74.g610f9\r
35 Subject: [notmuch] [RFC PATCH] notmuch: Add support for multiple maildirs\r
36 X-BeenThere: notmuch@notmuchmail.org\r
37 X-Mailman-Version: 2.1.12\r
38 Precedence: list\r
39 List-Id: "Use and development of the notmuch mail system."\r
40         <notmuch.notmuchmail.org>\r
41 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
42         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
44 List-Post: <mailto:notmuch@notmuchmail.org>\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
46 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
48 X-List-Received-Date: Sun, 22 Nov 2009 16:12:39 -0000\r
49 \r
50 This patch separate database path and maildir paths.\r
51 It also adds support for multiple maildir paths which\r
52 is represented by comma separated values. You need\r
53 to have in ~/.notmuch-config\r
54 \r
55 [maildirs]\r
56 path=path1,path2\r
57 \r
58 Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>\r
59 ---\r
60  notmuch-client.h |    8 ++++++++\r
61  notmuch-config.c |   43 +++++++++++++++++++++++++++++++++++++++++++\r
62  notmuch-new.c    |   24 +++++++++++++++++++++---\r
63  3 files changed, 72 insertions(+), 3 deletions(-)\r
64 \r
65 diff --git a/notmuch-client.h b/notmuch-client.h\r
66 index ea77686..128fd7f 100644\r
67 --- a/notmuch-client.h\r
68 +++ b/notmuch-client.h\r
69 @@ -83,6 +83,11 @@ typedef struct {\r
70      add_files_callback_t callback;\r
71  } add_files_state_t;\r
72  \r
73 +struct count_ele {\r
74 +       int count;\r
75 +       char ele[0];\r
76 +};\r
77 +\r
78  static inline void\r
79  chomp_newline (char *str)\r
80  {\r
81 @@ -182,4 +187,7 @@ notmuch_config_set_user_other_email (notmuch_config_t *config,\r
82  notmuch_bool_t\r
83  debugger_is_active (void);\r
84  \r
85 +const struct count_ele *\r
86 +notmuch_config_get_maildirs (notmuch_config_t *config);\r
87 +\r
88  #endif\r
89 diff --git a/notmuch-config.c b/notmuch-config.c\r
90 index aaa0372..12b0081 100644\r
91 --- a/notmuch-config.c\r
92 +++ b/notmuch-config.c\r
93 @@ -62,6 +62,7 @@ struct _notmuch_config {\r
94      char *user_primary_email;\r
95      char **user_other_email;\r
96      size_t user_other_email_length;\r
97 +    struct count_ele *maildirs;\r
98  };\r
99  \r
100  static int\r
101 @@ -334,6 +335,48 @@ notmuch_config_get_database_path (notmuch_config_t *config)\r
102      return config->database_path;\r
103  }\r
104  \r
105 +const struct count_ele *\r
106 +notmuch_config_get_maildirs (notmuch_config_t *config)\r
107 +{\r
108 +       int size;\r
109 +       char *cur_ptr;\r
110 +       char *dirs, *token, *saveptr;\r
111 +       struct count_ele *maildirs = NULL;\r
112 +       if (config->maildirs == NULL) {\r
113 +            dirs = g_key_file_get_string (config->key_file,\r
114 +                                    "maildirs", "path", NULL);\r
115 +               if (dirs) {\r
116 +                       size = sizeof(struct count_ele) + strlen(dirs) + 1;\r
117 +                       /* comma separated paths */\r
118 +                       maildirs = (struct count_ele *)malloc(size);\r
119 +                       maildirs->count = 0;\r
120 +                       cur_ptr = maildirs->ele;\r
121 +                       token = strtok_r(dirs, ",", &saveptr);\r
122 +                       if (token == NULL) {\r
123 +                               /* only one element */\r
124 +                               strcpy(maildirs->ele, dirs);\r
125 +                               maildirs->count = 1;\r
126 +                               free(dirs);\r
127 +                               config->maildirs = maildirs;\r
128 +                               return maildirs;\r
129 +                       }\r
130 +                       strcpy(maildirs->ele, token);\r
131 +                       maildirs->count++;\r
132 +                       cur_ptr += strlen(token) + 1;\r
133 +                       while ((token = strtok_r(NULL, ",", &saveptr))) {\r
134 +                               strcpy(cur_ptr, token);\r
135 +                               maildirs->count++;\r
136 +                               cur_ptr += strlen(token) + 1;\r
137 +                       }\r
138 +                       free (dirs);\r
139 +               }\r
140 +               config->maildirs = maildirs;\r
141 +       }\r
142 +       return config->maildirs;\r
143 +\r
144 +\r
145 +}\r
146 +\r
147  void\r
148  notmuch_config_set_database_path (notmuch_config_t *config,\r
149                                   const char *database_path)\r
150 diff --git a/notmuch-new.c b/notmuch-new.c\r
151 index 0dd2784..1a9406b 100644\r
152 --- a/notmuch-new.c\r
153 +++ b/notmuch-new.c\r
154 @@ -385,14 +385,16 @@ notmuch_new_command (void *ctx,\r
155  {\r
156      notmuch_config_t *config;\r
157      notmuch_database_t *notmuch;\r
158 +    const struct count_ele *maildirs;\r
159      add_files_state_t add_files_state;\r
160      double elapsed;\r
161      struct timeval tv_now;\r
162 -    int ret = 0;\r
163 +    int ret = 0, maildirs_count;\r
164      struct stat st;\r
165      const char *db_path;\r
166      char *dot_notmuch_path;\r
167      struct sigaction action;\r
168 +    const char *maildir_path;\r
169  \r
170      /* Setup our handler for SIGINT */\r
171      memset (&action, 0, sizeof (struct sigaction));\r
172 @@ -406,6 +408,9 @@ notmuch_new_command (void *ctx,\r
173         return 1;\r
174  \r
175      db_path = notmuch_config_get_database_path (config);\r
176 +    maildirs = notmuch_config_get_maildirs (config);\r
177 +    if (maildirs == NULL)\r
178 +           return 1;\r
179  \r
180      dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");\r
181  \r
182 @@ -413,7 +418,13 @@ notmuch_new_command (void *ctx,\r
183         int count;\r
184  \r
185         count = 0;\r
186 -       count_files (db_path, &count);\r
187 +       maildirs_count = maildirs->count;\r
188 +       maildir_path   = maildirs->ele;\r
189 +       while (maildirs_count) {\r
190 +               count_files (maildir_path, &count);\r
191 +               maildir_path += strlen(maildir_path) + 1;\r
192 +               maildirs_count--;\r
193 +       }\r
194         if (interrupted)\r
195             return 1;\r
196  \r
197 @@ -439,7 +450,14 @@ notmuch_new_command (void *ctx,\r
198      add_files_state.added_messages = 0;\r
199      gettimeofday (&add_files_state.tv_start, NULL);\r
200  \r
201 -    ret = add_files (notmuch, db_path, &add_files_state);\r
202 +    maildirs_count = maildirs->count;\r
203 +    maildir_path   = maildirs->ele;\r
204 +    while (maildirs_count) {\r
205 +           printf ("Processing maildir %s\n", maildir_path);\r
206 +           ret = add_files (notmuch, maildir_path, &add_files_state);\r
207 +           maildir_path += strlen(maildir_path) + 1;\r
208 +           maildirs_count--;\r
209 +    }\r
210  \r
211      gettimeofday (&tv_now, NULL);\r
212      elapsed = notmuch_time_elapsed (add_files_state.tv_start,\r
213 -- \r
214 1.6.5.2.74.g610f9\r
215 \r