1 Return-Path: <glasse@cs.rpi.edu>
\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 AB64D431E62
\r
6 for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 14:09:45 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.54 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 RCVD_IN_BL_SPAMCOP_NET=1.246, RCVD_IN_DNSWL_MED=-2.3,
\r
14 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 JYgxVZaFZw+r for <notmuch@notmuchmail.org>;
\r
18 Wed, 15 Feb 2012 14:09:44 -0800 (PST)
\r
19 Received: from cliffclavin.cs.rpi.edu (cliffclavin.cs.rpi.edu
\r
20 [128.113.126.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
\r
21 (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS
\r
22 id 89E9941EB90 for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 14:09:44 -0800
\r
25 S|1e6fe4067216137514005175a8428c8dbfb39661|ccff6b3b9d4b3c6d4682b599774abdc5
\r
26 X-Countries: Cameroon, United States
\r
27 X-SMTP-From: accepted <glasse@cs.rpi.edu> [195.24.209.20] [195.24.209.20]
\r
28 (localhost) {Cameroon}
\r
29 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=cs.rpi.edu; h=from
\r
30 :to:cc:subject:date:message-id:in-reply-to:references; s=
\r
31 default; i=glasse@cs.rpi.edu; t=1329343782; x=1329948582; l=7459;
\r
32 bh=8Cc1hoc5j0AGxRBD+Gl5gEhg5BE=; b=oz09gGRXEWGVjSqcmGq9Tew
\r
33 SQLBvC1fQTydWumrdxMFTgBAXRDhTAZotLp/7co0a818olWbiIhsXmjvIioVh9Ys
\r
34 Cq3y5SCZ+i3a8AZCuXJDj8d0HS2JYm/0p4dovv6eZnTKiQVnYoiFVrKcyuUYiIfC
\r
35 Z3OLXYZYcWvZp+Rwdc7g=
\r
36 DomainKey-Signature: a=rsa-sha1; c=nofws; d=cs.rpi.edu; h=from:to:cc
\r
37 :subject:date:message-id:in-reply-to:references; q=dns; s=
\r
38 default; b=B5tH8TFV4j4s5tN9wbaaaLGaOYa2qn/cRAHl2hnHLnYdMwM1qZAUj
\r
39 EIc606a0CA6j1M4K6jB3Zqywl6BwydEXQABE96dotp4Ymka59dh1Lxhhtlnv5X+m
\r
40 ZdFFpXTWBMGc22WFqCHZ6AIgaDancPN/+z4+Usq8EwfxVqG6NZ9X2s=
\r
41 X-Spam-Info: -2.7; ALL_TRUSTED,AWL,BAYES_00
\r
42 X-Spam-Scanned-By: cliffclavin.cs.rpi.edu using SpamAssassin 3.2.5 (hard limit
\r
44 Authentication-Results: cliffclavin.cs.rpi.edu;
\r
45 DKIM=neutral (none) header.from=glasse@cs.rpi.edu;
\r
47 Mechanism '?all' matched) smtp.mail=glasse@cs.rpi.edu
\r
48 X-Auth-Passed: cliffclavin.cs.rpi.edu:q1FM9Dkb008829 Auth:glasse
\r
49 X-Virus-Scanned-By: cliffclavin.cs.rpi.edu
\r
50 Received: from localhost ([195.24.209.20]) (authenticated bits=0)
\r
51 by cliffclavin.cs.rpi.edu (8.14.3/8.14.3) with ESMTP id q1FM9Dkb008829
\r
52 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO);
\r
53 Wed, 15 Feb 2012 17:09:30 -0500 (EST)
\r
54 (envelope-from glasse@cs.rpi.edu)
\r
55 From: Ethan Glasser-Camp <glasse@cs.rpi.edu>
\r
56 To: notmuch@notmuchmail.org
\r
57 Subject: [RFC PATCH 07/13] notmuch-new: pull out useful bits of
\r
59 Date: Wed, 15 Feb 2012 17:02:00 -0500
\r
60 Message-Id: <1329343326-16410-8-git-send-email-glasse@cs.rpi.edu>
\r
61 X-Mailer: git-send-email 1.7.5.4
\r
62 In-Reply-To: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu>
\r
63 References: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu>
\r
64 X-Scanned-By: MIMEDefang 2.67 on 128.113.126.25
\r
65 Cc: Ethan Glasser-Camp <ethan@betacantrips.com>
\r
66 X-BeenThere: notmuch@notmuchmail.org
\r
67 X-Mailman-Version: 2.1.13
\r
69 List-Id: "Use and development of the notmuch mail system."
\r
70 <notmuch.notmuchmail.org>
\r
71 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
72 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
73 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
74 List-Post: <mailto:notmuch@notmuchmail.org>
\r
75 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
76 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
77 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
78 X-List-Received-Date: Wed, 15 Feb 2012 22:09:45 -0000
\r
80 From: Ethan Glasser-Camp <ethan@betacantrips.com>
\r
82 This is part of notmuch-new refactor phase 1: make add_files stuff
\r
83 safe for other backends. add_files_recursive is essentially a
\r
84 maildir-crawling function that periodically adds files to the database
\r
85 or adds filenames to remove_files or remove_directory lists. I don't
\r
86 see an easy way to adapt add_files_recursive for other backends who
\r
87 might not have concepts of directories with other directories inside
\r
88 of them, so instead just provide an add_files method for each backend.
\r
90 This patch pulls some bits out of add_files_recursive which will be
\r
91 useful for other backends: two reporting functions
\r
92 _report_before_adding_file and _report_added_file, as well as
\r
93 _add_message, which actually does the message adding.
\r
95 Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com>
\r
97 notmuch-new.c | 193 +++++++++++++++++++++++++++++++++++----------------------
\r
98 1 files changed, 120 insertions(+), 73 deletions(-)
\r
100 diff --git a/notmuch-new.c b/notmuch-new.c
\r
101 index 355dde4..dbdfbb6 100644
\r
102 --- a/notmuch-new.c
\r
103 +++ b/notmuch-new.c
\r
104 @@ -181,6 +181,123 @@ _entries_resemble_maildir (struct dirent **entries, int count)
\r
108 +/* Progress-reporting function.
\r
110 + * Can be used by any mailstore-crawling function that wants to alert
\r
111 + * users what message it's about to add. Subsequent errors will be due
\r
112 + * to this message ;)
\r
115 +_report_before_adding_file (add_files_state_t *state, const char *filename)
\r
117 + state->processed_files++;
\r
119 + if (state->verbose) {
\r
120 + if (state->output_is_a_tty)
\r
121 + printf("\r\033[K");
\r
123 + printf ("%i/%i: %s",
\r
124 + state->processed_files,
\r
125 + state->total_files,
\r
128 + putchar((state->output_is_a_tty) ? '\r' : '\n');
\r
133 +/* Progress-reporting function.
\r
135 + * Call this to respond to the signal handler for SIGALRM.
\r
138 +_report_added_file (add_files_state_t *state)
\r
140 + if (do_print_progress) {
\r
141 + do_print_progress = 0;
\r
142 + generic_print_progress ("Processed", "files", state->tv_start,
\r
143 + state->processed_files, state->total_files);
\r
148 +/* Atomically handles adding a message to the database.
\r
150 + * Should be used by any mailstore-crawling function that finds a new
\r
151 + * message to add.
\r
153 +static notmuch_status_t
\r
154 +_add_message (add_files_state_t *state, notmuch_database_t *notmuch,
\r
155 + const char *filename)
\r
157 + notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;
\r
158 + notmuch_message_t *message;
\r
159 + const char **tag;
\r
161 + status = notmuch_database_begin_atomic (notmuch);
\r
167 + status = notmuch_database_add_message (notmuch, filename, &message);
\r
169 + switch (status) {
\r
171 + case NOTMUCH_STATUS_SUCCESS:
\r
172 + state->added_messages++;
\r
173 + notmuch_message_freeze (message);
\r
174 + for (tag=state->new_tags; *tag != NULL; tag++)
\r
175 + notmuch_message_add_tag (message, *tag);
\r
176 + if (state->synchronize_flags == TRUE)
\r
177 + notmuch_message_maildir_flags_to_tags (message);
\r
178 + notmuch_message_thaw (message);
\r
180 + /* Non-fatal issues (go on to next file) */
\r
181 + case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
\r
182 + if (state->synchronize_flags == TRUE)
\r
183 + notmuch_message_maildir_flags_to_tags (message);
\r
185 + case NOTMUCH_STATUS_FILE_NOT_EMAIL:
\r
186 + fprintf (stderr, "Note: Ignoring non-mail file: %s\n",
\r
189 + /* Fatal issues. Don't process anymore. */
\r
190 + case NOTMUCH_STATUS_READ_ONLY_DATABASE:
\r
191 + case NOTMUCH_STATUS_XAPIAN_EXCEPTION:
\r
192 + case NOTMUCH_STATUS_OUT_OF_MEMORY:
\r
193 + fprintf (stderr, "Error: %s. Halting processing.\n",
\r
194 + notmuch_status_to_string (status));
\r
198 + case NOTMUCH_STATUS_FILE_ERROR:
\r
199 + case NOTMUCH_STATUS_NULL_POINTER:
\r
200 + case NOTMUCH_STATUS_TAG_TOO_LONG:
\r
201 + case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:
\r
202 + case NOTMUCH_STATUS_UNBALANCED_ATOMIC:
\r
203 + case NOTMUCH_STATUS_LAST_STATUS:
\r
204 + INTERNAL_ERROR ("add_message returned unexpected value: %d", status);
\r
209 + status = notmuch_database_end_atomic (notmuch);
\r
217 + notmuch_message_destroy (message);
\r
225 /* Examine 'path' recursively as follows:
\r
227 * o Ask the filesystem for the mtime of 'path' (fs_mtime)
\r
228 @@ -232,7 +349,6 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
230 time_t fs_mtime, db_mtime;
\r
231 notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;
\r
232 - notmuch_message_t *message = NULL;
\r
233 struct dirent **fs_entries = NULL;
\r
234 int i, num_fs_entries;
\r
235 notmuch_directory_t *directory;
\r
236 @@ -241,7 +357,6 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
239 notmuch_bool_t is_maildir, new_directory;
\r
240 - const char **tag;
\r
242 if (stat (path, &st)) {
\r
243 fprintf (stderr, "Error reading directory %s: %s\n",
\r
244 @@ -439,83 +554,15 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
245 * in the database, so add it. */
\r
246 next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
\r
248 - state->processed_files++;
\r
250 - if (state->verbose) {
\r
251 - if (state->output_is_a_tty)
\r
252 - printf("\r\033[K");
\r
253 + _report_before_adding_file (state, next);
\r
255 - printf ("%i/%i: %s",
\r
256 - state->processed_files,
\r
257 - state->total_files,
\r
260 - putchar((state->output_is_a_tty) ? '\r' : '\n');
\r
264 - status = notmuch_database_begin_atomic (notmuch);
\r
265 + status = _add_message (state, notmuch, next);
\r
271 - status = notmuch_database_add_message (notmuch, next, &message);
\r
272 - switch (status) {
\r
274 - case NOTMUCH_STATUS_SUCCESS:
\r
275 - state->added_messages++;
\r
276 - notmuch_message_freeze (message);
\r
277 - for (tag=state->new_tags; *tag != NULL; tag++)
\r
278 - notmuch_message_add_tag (message, *tag);
\r
279 - if (state->synchronize_flags == TRUE)
\r
280 - notmuch_message_maildir_flags_to_tags (message);
\r
281 - notmuch_message_thaw (message);
\r
283 - /* Non-fatal issues (go on to next file) */
\r
284 - case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
\r
285 - if (state->synchronize_flags == TRUE)
\r
286 - notmuch_message_maildir_flags_to_tags (message);
\r
288 - case NOTMUCH_STATUS_FILE_NOT_EMAIL:
\r
289 - fprintf (stderr, "Note: Ignoring non-mail file: %s\n",
\r
292 - /* Fatal issues. Don't process anymore. */
\r
293 - case NOTMUCH_STATUS_READ_ONLY_DATABASE:
\r
294 - case NOTMUCH_STATUS_XAPIAN_EXCEPTION:
\r
295 - case NOTMUCH_STATUS_OUT_OF_MEMORY:
\r
296 - fprintf (stderr, "Error: %s. Halting processing.\n",
\r
297 - notmuch_status_to_string (status));
\r
301 - case NOTMUCH_STATUS_FILE_ERROR:
\r
302 - case NOTMUCH_STATUS_NULL_POINTER:
\r
303 - case NOTMUCH_STATUS_TAG_TOO_LONG:
\r
304 - case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:
\r
305 - case NOTMUCH_STATUS_UNBALANCED_ATOMIC:
\r
306 - case NOTMUCH_STATUS_LAST_STATUS:
\r
307 - INTERNAL_ERROR ("add_message returned unexpected value: %d", status);
\r
311 - status = notmuch_database_end_atomic (notmuch);
\r
318 - notmuch_message_destroy (message);
\r
322 - if (do_print_progress) {
\r
323 - do_print_progress = 0;
\r
324 - generic_print_progress ("Processed", "files", state->tv_start,
\r
325 - state->processed_files, state->total_files);
\r
327 + _report_added_file (state);
\r
329 talloc_free (next);
\r