RE: Reply all - issue
[notmuch-archives.git] / ba / 1ba25a640ae9d4756f796b4fb88cb20ae26408
1 Return-Path: <ethan.glasser.camp@gmail.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 8E8FF431FBC\r
6         for <notmuch@notmuchmail.org>; Sun,  1 Jul 2012 09:46:26 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 1.061\r
10 X-Spam-Level: *\r
11 X-Spam-Status: No, score=1.061 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_FROM=0.001, RCVD_IN_BL_SPAMCOP_NET=1.246,\r
14         RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_SORBS_WEB=0.614] autolearn=disabled\r
15 Received: from olra.theworths.org ([127.0.0.1])\r
16         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
17         with ESMTP id I+E0g9gaJq2d for <notmuch@notmuchmail.org>;\r
18         Sun,  1 Jul 2012 09:46:25 -0700 (PDT)\r
19 Received: from mail-wg0-f41.google.com (mail-wg0-f41.google.com\r
20  [74.125.82.41])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
21  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
22  16B1F431FAF    for <notmuch@notmuchmail.org>; Sun,  1 Jul 2012 09:46:24 -0700\r
23  (PDT)\r
24 Received: by wgbds1 with SMTP id ds1so2232210wgb.2\r
25         for <notmuch@notmuchmail.org>; Sun, 01 Jul 2012 09:46:23 -0700 (PDT)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
27         h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
28         bh=kVMM807Ap9n6I8OuylbnndHJh8sh447voBoKA/GofhM=;\r
29         b=rhHYaX62pp+1q6eXlC0g4xQysh8skL23Aua3WJF9iPGOWTSu9MSLoz2QYELtvLCOUk\r
30         wM3BtIWacfEfx2tqCLhiGO2EamNIYd23GKTxSX3khuc/B1NBbd6B/fMyxiBOHzVO5x0a\r
31         Y3GqDh+nF9wx+xvAglJwEZmtpmNJL6kOMUXq5X2UJD+v3xffmThb2Q8n+YjMgU5AhMpT\r
32         3666EAInl3UzFL45vWT7nuIH/+d/1PXzohBlI1OaHzHbN0r3RVFEn77E5YwAiQCZ78GP\r
33         e9lzV1G2dYg43YLbA8KhjyrLDTR9q3baP5ee2bUnX4kKmljD8k4EdFItgwzn1Fija4Ba\r
34         fE/w==\r
35 Received: by 10.180.109.129 with SMTP id hs1mr11249730wib.0.1341161183713;\r
36         Sun, 01 Jul 2012 09:46:23 -0700 (PDT)\r
37 Received: from localhost ([195.24.209.21])\r
38         by mx.google.com with ESMTPS id ch9sm35160214wib.8.2012.07.01.09.46.16\r
39         (version=TLSv1/SSLv3 cipher=OTHER);\r
40         Sun, 01 Jul 2012 09:46:22 -0700 (PDT)\r
41 From: Ethan Glasser-Camp <ethan.glasser.camp@gmail.com>\r
42 To: notmuch@notmuchmail.org\r
43 Subject: [PATCH v2 5/8] notmuch-new: pull out useful bits of\r
44         add_files_recursive\r
45 Date: Sun,  1 Jul 2012 12:39:47 -0400\r
46 Message-Id: <1341160790-14525-6-git-send-email-ethan@betacantrips.com>\r
47 X-Mailer: git-send-email 1.7.9.5\r
48 In-Reply-To: <1341160790-14525-1-git-send-email-ethan@betacantrips.com>\r
49 References:\r
50  <CAOJ+Ob0MSOez2MvD2fCgF7t32kFPk4g2+xCud88QmBLt_b5pOA@mail.gmail.com>\r
51         <1341160790-14525-1-git-send-email-ethan@betacantrips.com>\r
52 Cc: Ethan Glasser-Camp <ethan@betacantrips.com>\r
53 X-BeenThere: notmuch@notmuchmail.org\r
54 X-Mailman-Version: 2.1.13\r
55 Precedence: list\r
56 List-Id: "Use and development of the notmuch mail system."\r
57         <notmuch.notmuchmail.org>\r
58 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
59         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
60 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
61 List-Post: <mailto:notmuch@notmuchmail.org>\r
62 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
63 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
64         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
65 X-List-Received-Date: Sun, 01 Jul 2012 16:46:26 -0000\r
66 \r
67 This patch pulls some bits out of add_files_recursive which will be\r
68 useful for other backends: two reporting functions\r
69 _report_before_adding_file and _report_added_file, as well as\r
70 _add_message, which actually does the message adding.\r
71 \r
72 No functional changes.\r
73 \r
74 Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com>\r
75 ---\r
76  notmuch-new.c |  192 +++++++++++++++++++++++++++++++++++----------------------\r
77  1 file changed, 119 insertions(+), 73 deletions(-)\r
78 \r
79 diff --git a/notmuch-new.c b/notmuch-new.c\r
80 index 8377750..5250562 100644\r
81 --- a/notmuch-new.c\r
82 +++ b/notmuch-new.c\r
83 @@ -239,6 +239,122 @@ _entry_in_ignore_list (const char *entry, add_files_state_t *state)\r
84      return FALSE;\r
85  }\r
86  \r
87 +/* Progress-reporting function.\r
88 + *\r
89 + * Can be used by any mailstore-crawling function that wants to alert\r
90 + * users what message it's about to add. Subsequent errors will be due\r
91 + * to this message ;)\r
92 + */\r
93 +static void\r
94 +_report_before_adding_file (add_files_state_t *state, const char *filename)\r
95 +{\r
96 +    state->processed_files++;\r
97 +\r
98 +    if (state->verbose) {\r
99 +       if (state->output_is_a_tty)\r
100 +           printf("\r\033[K");\r
101 +\r
102 +       printf ("%i/%i: %s",\r
103 +               state->processed_files,\r
104 +               state->total_files,\r
105 +               filename);\r
106 +\r
107 +       putchar((state->output_is_a_tty) ? '\r' : '\n');\r
108 +       fflush (stdout);\r
109 +    }\r
110 +}\r
111 +\r
112 +/* Progress-reporting function.\r
113 + *\r
114 + * Call this to respond to the signal handler for SIGALRM.\r
115 + */\r
116 +static void\r
117 +_report_added_file (add_files_state_t *state)\r
118 +{\r
119 +    if (do_print_progress) {\r
120 +       do_print_progress = 0;\r
121 +       generic_print_progress ("Processed", "files", state->tv_start,\r
122 +                               state->processed_files, state->total_files);\r
123 +    }\r
124 +}\r
125 +\r
126 +\r
127 +/* Atomically handles adding a message to the database.\r
128 + *\r
129 + * Should be used by any mailstore-crawling function that finds a new\r
130 + * message to add.\r
131 + */\r
132 +static notmuch_status_t\r
133 +_add_message (add_files_state_t *state, notmuch_database_t *notmuch,\r
134 +             const char *filename)\r
135 +{\r
136 +    notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;\r
137 +    notmuch_message_t *message;\r
138 +    const char **tag;\r
139 +\r
140 +    status = notmuch_database_begin_atomic (notmuch);\r
141 +    if (status) {\r
142 +       ret = status;\r
143 +       goto DONE;\r
144 +    }\r
145 +\r
146 +    status = notmuch_database_add_message (notmuch, filename, &message);\r
147 +\r
148 +    switch (status) {\r
149 +    /* success */\r
150 +    case NOTMUCH_STATUS_SUCCESS:\r
151 +       state->added_messages++;\r
152 +       notmuch_message_freeze (message);\r
153 +       for (tag=state->new_tags; *tag != NULL; tag++)\r
154 +           notmuch_message_add_tag (message, *tag);\r
155 +       if (state->synchronize_flags == TRUE)\r
156 +           notmuch_message_maildir_flags_to_tags (message);\r
157 +       notmuch_message_thaw (message);\r
158 +       break;\r
159 +    /* Non-fatal issues (go on to next file) */\r
160 +    case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:\r
161 +       if (state->synchronize_flags == TRUE)\r
162 +           notmuch_message_maildir_flags_to_tags (message);\r
163 +       break;\r
164 +    case NOTMUCH_STATUS_FILE_NOT_EMAIL:\r
165 +       fprintf (stderr, "Note: Ignoring non-mail file: %s\n",\r
166 +                filename);\r
167 +       break;\r
168 +    /* Fatal issues. Don't process anymore. */\r
169 +    case NOTMUCH_STATUS_READ_ONLY_DATABASE:\r
170 +    case NOTMUCH_STATUS_XAPIAN_EXCEPTION:\r
171 +    case NOTMUCH_STATUS_OUT_OF_MEMORY:\r
172 +       fprintf (stderr, "Error: %s. Halting processing.\n",\r
173 +                notmuch_status_to_string (status));\r
174 +       ret = status;\r
175 +       goto DONE;\r
176 +    default:\r
177 +    case NOTMUCH_STATUS_FILE_ERROR:\r
178 +    case NOTMUCH_STATUS_NULL_POINTER:\r
179 +    case NOTMUCH_STATUS_TAG_TOO_LONG:\r
180 +    case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:\r
181 +    case NOTMUCH_STATUS_UNBALANCED_ATOMIC:\r
182 +    case NOTMUCH_STATUS_LAST_STATUS:\r
183 +       INTERNAL_ERROR ("add_message returned unexpected value: %d",  status);\r
184 +       ret = status;\r
185 +       goto DONE;\r
186 +    }\r
187 +\r
188 +    status = notmuch_database_end_atomic (notmuch);\r
189 +    if (status) {\r
190 +       ret = status;\r
191 +       goto DONE;\r
192 +    }\r
193 +\r
194 +  DONE:\r
195 +    if (message) {\r
196 +       notmuch_message_destroy (message);\r
197 +       message = NULL;\r
198 +    }\r
199 +\r
200 +    return ret;\r
201 +}\r
202 +\r
203  /* Examine 'path' recursively as follows:\r
204   *\r
205   *   o Ask the filesystem for the mtime of 'path' (fs_mtime)\r
206 @@ -290,7 +406,6 @@ add_files (notmuch_database_t *notmuch,\r
207      char *next = NULL;\r
208      time_t fs_mtime, db_mtime;\r
209      notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;\r
210 -    notmuch_message_t *message = NULL;\r
211      struct dirent **fs_entries = NULL;\r
212      int i, num_fs_entries = 0, entry_type;\r
213      notmuch_directory_t *directory;\r
214 @@ -299,7 +414,6 @@ add_files (notmuch_database_t *notmuch,\r
215      time_t stat_time;\r
216      struct stat st;\r
217      notmuch_bool_t is_maildir;\r
218 -    const char **tag;\r
219  \r
220      if (stat (path, &st)) {\r
221         fprintf (stderr, "Error reading directory %s: %s\n",\r
222 @@ -469,83 +583,15 @@ add_files (notmuch_database_t *notmuch,\r
223          * in the database, so add it. */\r
224         next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);\r
225  \r
226 -       state->processed_files++;\r
227 -\r
228 -       if (state->verbose) {\r
229 -           if (state->output_is_a_tty)\r
230 -               printf("\r\033[K");\r
231 -\r
232 -           printf ("%i/%i: %s",\r
233 -                   state->processed_files,\r
234 -                   state->total_files,\r
235 -                   next);\r
236 -\r
237 -           putchar((state->output_is_a_tty) ? '\r' : '\n');\r
238 -           fflush (stdout);\r
239 -       }\r
240 +       _report_before_adding_file (state, next);\r
241  \r
242 -       status = notmuch_database_begin_atomic (notmuch);\r
243 +       status = _add_message (state, notmuch, next);\r
244         if (status) {\r
245             ret = status;\r
246             goto DONE;\r
247         }\r
248  \r
249 -       status = notmuch_database_add_message (notmuch, next, &message);\r
250 -       switch (status) {\r
251 -       /* success */\r
252 -       case NOTMUCH_STATUS_SUCCESS:\r
253 -           state->added_messages++;\r
254 -           notmuch_message_freeze (message);\r
255 -           for (tag=state->new_tags; *tag != NULL; tag++)\r
256 -               notmuch_message_add_tag (message, *tag);\r
257 -           if (state->synchronize_flags == TRUE)\r
258 -               notmuch_message_maildir_flags_to_tags (message);\r
259 -           notmuch_message_thaw (message);\r
260 -           break;\r
261 -       /* Non-fatal issues (go on to next file) */\r
262 -       case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:\r
263 -           if (state->synchronize_flags == TRUE)\r
264 -               notmuch_message_maildir_flags_to_tags (message);\r
265 -           break;\r
266 -       case NOTMUCH_STATUS_FILE_NOT_EMAIL:\r
267 -           fprintf (stderr, "Note: Ignoring non-mail file: %s\n",\r
268 -                    next);\r
269 -           break;\r
270 -       /* Fatal issues. Don't process anymore. */\r
271 -       case NOTMUCH_STATUS_READ_ONLY_DATABASE:\r
272 -       case NOTMUCH_STATUS_XAPIAN_EXCEPTION:\r
273 -       case NOTMUCH_STATUS_OUT_OF_MEMORY:\r
274 -           fprintf (stderr, "Error: %s. Halting processing.\n",\r
275 -                    notmuch_status_to_string (status));\r
276 -           ret = status;\r
277 -           goto DONE;\r
278 -       default:\r
279 -       case NOTMUCH_STATUS_FILE_ERROR:\r
280 -       case NOTMUCH_STATUS_NULL_POINTER:\r
281 -       case NOTMUCH_STATUS_TAG_TOO_LONG:\r
282 -       case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:\r
283 -       case NOTMUCH_STATUS_UNBALANCED_ATOMIC:\r
284 -       case NOTMUCH_STATUS_LAST_STATUS:\r
285 -           INTERNAL_ERROR ("add_message returned unexpected value: %d",  status);\r
286 -           goto DONE;\r
287 -       }\r
288 -\r
289 -       status = notmuch_database_end_atomic (notmuch);\r
290 -       if (status) {\r
291 -           ret = status;\r
292 -           goto DONE;\r
293 -       }\r
294 -\r
295 -       if (message) {\r
296 -           notmuch_message_destroy (message);\r
297 -           message = NULL;\r
298 -       }\r
299 -\r
300 -       if (do_print_progress) {\r
301 -           do_print_progress = 0;\r
302 -           generic_print_progress ("Processed", "files", state->tv_start,\r
303 -                                   state->processed_files, state->total_files);\r
304 -       }\r
305 +       _report_added_file (state);\r
306  \r
307         talloc_free (next);\r
308         next = NULL;\r
309 -- \r
310 1.7.9.5\r
311 \r