Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / ff / 1e9baa9fafe2eb749de3b0e51b50594ac9b420
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 4A6BF431FBC\r
6         for <notmuch@notmuchmail.org>; Sun, 22 Nov 2009 10:28:54 -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 G-jVUhhvNMIK for <notmuch@notmuchmail.org>;\r
11         Sun, 22 Nov 2009 10:28:53 -0800 (PST)\r
12 Received: from e23smtp06.au.ibm.com (e23smtp06.au.ibm.com [202.81.31.148])\r
13         by olra.theworths.org (Postfix) with ESMTP id B0473431FAE\r
14         for <notmuch@notmuchmail.org>; Sun, 22 Nov 2009 10:28:52 -0800 (PST)\r
15 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246])\r
16         by e23smtp06.au.ibm.com (8.14.3/8.13.1) with ESMTP id nAMISmQq019424\r
17         for <notmuch@notmuchmail.org>; Mon, 23 Nov 2009 05:28:48 +1100\r
18 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138])\r
19         by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id\r
20         nAMIPRms1708146\r
21         for <notmuch@notmuchmail.org>; Mon, 23 Nov 2009 05:25:27 +1100\r
22 Received: from d23av02.au.ibm.com (loopback [127.0.0.1])\r
23         by d23av02.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id\r
24         nAMISoGV003536\r
25         for <notmuch@notmuchmail.org>; Mon, 23 Nov 2009 05:28:50 +1100\r
26 Received: from localhost.localdomain ([9.124.218.229])\r
27         by d23av02.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id\r
28         nAMISmlF003533; Mon, 23 Nov 2009 05:28:49 +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 23:58:46 +0530\r
32 Message-Id:\r
33  <1258914526-30984-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 -V2] 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 18:28:54 -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 |   12 ++++++++++++\r
61  notmuch-config.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
62  notmuch-new.c    |   24 +++++++++++++++++++++---\r
63  notmuch-setup.c  |   37 +++++++++++++++++++++++++++++++++++--\r
64  4 files changed, 122 insertions(+), 5 deletions(-)\r
65 \r
66 diff --git a/notmuch-client.h b/notmuch-client.h\r
67 index ea77686..f2fc19f 100644\r
68 --- a/notmuch-client.h\r
69 +++ b/notmuch-client.h\r
70 @@ -83,6 +83,11 @@ typedef struct {\r
71      add_files_callback_t callback;\r
72  } add_files_state_t;\r
73  \r
74 +struct count_ele {\r
75 +       int count;\r
76 +       char ele[0];\r
77 +};\r
78 +\r
79  static inline void\r
80  chomp_newline (char *str)\r
81  {\r
82 @@ -182,4 +187,11 @@ notmuch_config_set_user_other_email (notmuch_config_t *config,\r
83  notmuch_bool_t\r
84  debugger_is_active (void);\r
85  \r
86 +const struct count_ele *\r
87 +notmuch_config_get_maildirs (notmuch_config_t *config);\r
88 +\r
89 +void\r
90 +notmuch_config_set_maildirs (notmuch_config_t *config,\r
91 +                               const char *maildirs);\r
92 +\r
93  #endif\r
94 diff --git a/notmuch-config.c b/notmuch-config.c\r
95 index aaa0372..330da48 100644\r
96 --- a/notmuch-config.c\r
97 +++ b/notmuch-config.c\r
98 @@ -62,6 +62,7 @@ struct _notmuch_config {\r
99      char *user_primary_email;\r
100      char **user_other_email;\r
101      size_t user_other_email_length;\r
102 +    struct count_ele *maildirs;\r
103  };\r
104  \r
105  static int\r
106 @@ -345,6 +346,59 @@ notmuch_config_set_database_path (notmuch_config_t *config,\r
107      config->database_path = NULL;\r
108  }\r
109  \r
110 +const struct count_ele *\r
111 +notmuch_config_get_maildirs (notmuch_config_t *config)\r
112 +{\r
113 +       int size;\r
114 +       char *cur_ptr;\r
115 +       char *dirs, *token, *saveptr;\r
116 +       struct count_ele *maildirs = NULL;\r
117 +       if (config->maildirs == NULL) {\r
118 +            dirs = g_key_file_get_string (config->key_file,\r
119 +                                    "maildirs", "path", NULL);\r
120 +               if (dirs) {\r
121 +                       size = sizeof(struct count_ele) + strlen(dirs) + 1;\r
122 +                       /* comma separated paths */\r
123 +                       maildirs = (struct count_ele *)malloc(size);\r
124 +                       maildirs->count = 0;\r
125 +                       cur_ptr = maildirs->ele;\r
126 +                       token = strtok_r(dirs, ",", &saveptr);\r
127 +                       if (token == NULL) {\r
128 +                               /* only one element */\r
129 +                               strcpy(maildirs->ele, dirs);\r
130 +                               maildirs->count = 1;\r
131 +                               free(dirs);\r
132 +                               config->maildirs = maildirs;\r
133 +                               return maildirs;\r
134 +                       }\r
135 +                       strcpy(maildirs->ele, token);\r
136 +                       maildirs->count++;\r
137 +                       cur_ptr += strlen(token) + 1;\r
138 +                       while ((token = strtok_r(NULL, ",", &saveptr))) {\r
139 +                               strcpy(cur_ptr, token);\r
140 +                               maildirs->count++;\r
141 +                               cur_ptr += strlen(token) + 1;\r
142 +                       }\r
143 +                       free (dirs);\r
144 +               }\r
145 +               config->maildirs = maildirs;\r
146 +       }\r
147 +       return config->maildirs;\r
148 +\r
149 +\r
150 +}\r
151 +\r
152 +void\r
153 +notmuch_config_set_maildirs (notmuch_config_t *config,\r
154 +                                 const char *maildirs)\r
155 +{\r
156 +    g_key_file_set_string (config->key_file,\r
157 +                          "maildirs", "path", maildirs);\r
158 +\r
159 +    free (config->maildirs);\r
160 +    config->maildirs = NULL;\r
161 +}\r
162 +\r
163  const char *\r
164  notmuch_config_get_user_name (notmuch_config_t *config)\r
165  {\r
166 diff --git a/notmuch-new.c b/notmuch-new.c\r
167 index 0dd2784..1a9406b 100644\r
168 --- a/notmuch-new.c\r
169 +++ b/notmuch-new.c\r
170 @@ -385,14 +385,16 @@ notmuch_new_command (void *ctx,\r
171  {\r
172      notmuch_config_t *config;\r
173      notmuch_database_t *notmuch;\r
174 +    const struct count_ele *maildirs;\r
175      add_files_state_t add_files_state;\r
176      double elapsed;\r
177      struct timeval tv_now;\r
178 -    int ret = 0;\r
179 +    int ret = 0, maildirs_count;\r
180      struct stat st;\r
181      const char *db_path;\r
182      char *dot_notmuch_path;\r
183      struct sigaction action;\r
184 +    const char *maildir_path;\r
185  \r
186      /* Setup our handler for SIGINT */\r
187      memset (&action, 0, sizeof (struct sigaction));\r
188 @@ -406,6 +408,9 @@ notmuch_new_command (void *ctx,\r
189         return 1;\r
190  \r
191      db_path = notmuch_config_get_database_path (config);\r
192 +    maildirs = notmuch_config_get_maildirs (config);\r
193 +    if (maildirs == NULL)\r
194 +           return 1;\r
195  \r
196      dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");\r
197  \r
198 @@ -413,7 +418,13 @@ notmuch_new_command (void *ctx,\r
199         int count;\r
200  \r
201         count = 0;\r
202 -       count_files (db_path, &count);\r
203 +       maildirs_count = maildirs->count;\r
204 +       maildir_path   = maildirs->ele;\r
205 +       while (maildirs_count) {\r
206 +               count_files (maildir_path, &count);\r
207 +               maildir_path += strlen(maildir_path) + 1;\r
208 +               maildirs_count--;\r
209 +       }\r
210         if (interrupted)\r
211             return 1;\r
212  \r
213 @@ -439,7 +450,14 @@ notmuch_new_command (void *ctx,\r
214      add_files_state.added_messages = 0;\r
215      gettimeofday (&add_files_state.tv_start, NULL);\r
216  \r
217 -    ret = add_files (notmuch, db_path, &add_files_state);\r
218 +    maildirs_count = maildirs->count;\r
219 +    maildir_path   = maildirs->ele;\r
220 +    while (maildirs_count) {\r
221 +           printf ("Processing maildir %s\n", maildir_path);\r
222 +           ret = add_files (notmuch, maildir_path, &add_files_state);\r
223 +           maildir_path += strlen(maildir_path) + 1;\r
224 +           maildirs_count--;\r
225 +    }\r
226  \r
227      gettimeofday (&tv_now, NULL);\r
228      elapsed = notmuch_time_elapsed (add_files_state.tv_start,\r
229 diff --git a/notmuch-setup.c b/notmuch-setup.c\r
230 index 482efd2..e358c68 100644\r
231 --- a/notmuch-setup.c\r
232 +++ b/notmuch-setup.c\r
233 @@ -97,7 +97,10 @@ notmuch_setup_command (unused (void *ctx),\r
234      size_t old_other_emails_len;\r
235      GPtrArray *other_emails;\r
236      unsigned int i;\r
237 -    int is_new;\r
238 +    int is_new, maildirs_count, size = 0;\r
239 +    const struct count_ele *maildirs;\r
240 +    const char *maildir_path;\r
241 +    char *cmaildirs = NULL;;\r
242  \r
243  #define prompt(format, ...)                            \\r
244      do {                                               \\r
245 @@ -146,7 +149,7 @@ notmuch_setup_command (unused (void *ctx),\r
246                                              other_emails->len);\r
247      g_ptr_array_free (other_emails, TRUE);\r
248  \r
249 -    prompt ("Top-level directory of your email archive [%s]: ",\r
250 +    prompt ("Directory for notmuch database [%s]: ",\r
251             notmuch_config_get_database_path (config));\r
252      if (strlen (response)) {\r
253         const char *absolute_path;\r
254 @@ -155,6 +158,36 @@ notmuch_setup_command (unused (void *ctx),\r
255         notmuch_config_set_database_path (config, absolute_path);\r
256      }\r
257  \r
258 +    maildirs = notmuch_config_get_maildirs (config);\r
259 +    if (maildirs) {\r
260 +           /* build the comma separated value */\r
261 +           maildirs_count = maildirs->count;\r
262 +           maildir_path   = maildirs->ele;\r
263 +           while (maildirs_count) {\r
264 +                   size += strlen(maildir_path) + 1;\r
265 +                   maildir_path += strlen(maildir_path) + 1;\r
266 +                   maildirs_count--;\r
267 +           }\r
268 +           maildirs_count = maildirs->count;\r
269 +           cmaildirs      = malloc(size);\r
270 +           maildir_path   = maildirs->ele;\r
271 +           memset(cmaildirs, 0, size);\r
272 +           while(maildirs_count) {\r
273 +                   strncat(cmaildirs, maildir_path, size);\r
274 +                   maildirs_count--;\r
275 +                   if (maildirs_count == 0)\r
276 +                           break;\r
277 +                   strncat(cmaildirs, ",", size);\r
278 +                   maildir_path += strlen(maildir_path) + 1;\r
279 +\r
280 +           }\r
281 +    }\r
282 +\r
283 +    prompt ("Comma separated maildirs [%s]: ", cmaildirs);\r
284 +\r
285 +    if (strlen (response))\r
286 +       notmuch_config_set_maildirs (config, response);\r
287 +\r
288      notmuch_config_save (config);\r
289  \r
290      if (is_new)\r
291 -- \r
292 1.6.5.2.74.g610f9\r
293 \r