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
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
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
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
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
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
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
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
72 No functional changes.
\r
74 Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com>
\r
76 notmuch-new.c | 192 +++++++++++++++++++++++++++++++++++----------------------
\r
77 1 file changed, 119 insertions(+), 73 deletions(-)
\r
79 diff --git a/notmuch-new.c b/notmuch-new.c
\r
80 index 8377750..5250562 100644
\r
83 @@ -239,6 +239,122 @@ _entry_in_ignore_list (const char *entry, add_files_state_t *state)
\r
87 +/* Progress-reporting function.
\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
94 +_report_before_adding_file (add_files_state_t *state, const char *filename)
\r
96 + state->processed_files++;
\r
98 + if (state->verbose) {
\r
99 + if (state->output_is_a_tty)
\r
100 + printf("\r\033[K");
\r
102 + printf ("%i/%i: %s",
\r
103 + state->processed_files,
\r
104 + state->total_files,
\r
107 + putchar((state->output_is_a_tty) ? '\r' : '\n');
\r
112 +/* Progress-reporting function.
\r
114 + * Call this to respond to the signal handler for SIGALRM.
\r
117 +_report_added_file (add_files_state_t *state)
\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
127 +/* Atomically handles adding a message to the database.
\r
129 + * Should be used by any mailstore-crawling function that finds a new
\r
130 + * message to add.
\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
136 + notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;
\r
137 + notmuch_message_t *message;
\r
138 + const char **tag;
\r
140 + status = notmuch_database_begin_atomic (notmuch);
\r
146 + status = notmuch_database_add_message (notmuch, filename, &message);
\r
148 + switch (status) {
\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
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
164 + case NOTMUCH_STATUS_FILE_NOT_EMAIL:
\r
165 + fprintf (stderr, "Note: Ignoring non-mail file: %s\n",
\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
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
188 + status = notmuch_database_end_atomic (notmuch);
\r
196 + notmuch_message_destroy (message);
\r
203 /* Examine 'path' recursively as follows:
\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
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
217 notmuch_bool_t is_maildir;
\r
218 - const char **tag;
\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
226 - state->processed_files++;
\r
228 - if (state->verbose) {
\r
229 - if (state->output_is_a_tty)
\r
230 - printf("\r\033[K");
\r
232 - printf ("%i/%i: %s",
\r
233 - state->processed_files,
\r
234 - state->total_files,
\r
237 - putchar((state->output_is_a_tty) ? '\r' : '\n');
\r
240 + _report_before_adding_file (state, next);
\r
242 - status = notmuch_database_begin_atomic (notmuch);
\r
243 + status = _add_message (state, notmuch, next);
\r
249 - status = notmuch_database_add_message (notmuch, next, &message);
\r
250 - switch (status) {
\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
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
266 - case NOTMUCH_STATUS_FILE_NOT_EMAIL:
\r
267 - fprintf (stderr, "Note: Ignoring non-mail file: %s\n",
\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
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
289 - status = notmuch_database_end_atomic (notmuch);
\r
296 - notmuch_message_destroy (message);
\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
305 + _report_added_file (state);
\r
307 talloc_free (next);
\r