--- /dev/null
+Return-Path: <m.walters@qmul.ac.uk>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 7B34B431FD2\r
+ for <notmuch@notmuchmail.org>; Sun, 1 Jul 2012 12:55:26 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.098\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
+ tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+ NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id vjij9oEEoSi7 for <notmuch@notmuchmail.org>;\r
+ Sun, 1 Jul 2012 12:55:23 -0700 (PDT)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id AEC99431FAF\r
+ for <notmuch@notmuchmail.org>; Sun, 1 Jul 2012 12:55:22 -0700 (PDT)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+ by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1SlQEl-0005oT-UC; Sun, 01 Jul 2012 20:55:21 +0100\r
+Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223]\r
+ helo=localhost)\r
+ by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1SlQEl-0002Yp-8p; Sun, 01 Jul 2012 20:55:15 +0100\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Ethan Glasser-Camp <ethan.glasser.camp@gmail.com>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v2 5/8] notmuch-new: pull out useful bits of\r
+ add_files_recursive\r
+In-Reply-To: <1341160790-14525-6-git-send-email-ethan@betacantrips.com>\r
+References:\r
+ <CAOJ+Ob0MSOez2MvD2fCgF7t32kFPk4g2+xCud88QmBLt_b5pOA@mail.gmail.com>\r
+ <1341160790-14525-1-git-send-email-ethan@betacantrips.com>\r
+ <1341160790-14525-6-git-send-email-ethan@betacantrips.com>\r
+User-Agent: Notmuch/0.13.2+70~gb6a56e7 (http://notmuchmail.org) Emacs/23.4.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Sun, 01 Jul 2012 20:55:11 +0100\r
+Message-ID: <87ehov2r4w.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 94.192.233.223\r
+X-QM-SPAM-Info: Sender has good ham record. :)\r
+X-QM-Body-MD5: 5107d4a02d45af8f7cec3abc1d9625a6 (of first 20000 bytes)\r
+X-SpamAssassin-Score: -1.8\r
+X-SpamAssassin-SpamBar: -\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+ determine if it is\r
+ spam. We require at least 5.0 points to mark a message as spam.\r
+ This message scored -1.8 points.\r
+ Summary of the scoring: \r
+ * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
+ * medium trust\r
+ * [138.37.6.40 listed in list.dnswl.org]\r
+ * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+ provider * (markwalters1009[at]gmail.com)\r
+ * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
+ * domain\r
+ * 0.5 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\r
+Cc: Ethan Glasser-Camp <ethan@betacantrips.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 01 Jul 2012 19:55:26 -0000\r
+\r
+On Sun, 01 Jul 2012, Ethan Glasser-Camp <ethan.glasser.camp@gmail.com> wrote:\r
+> This patch pulls some bits out of add_files_recursive which will be\r
+> useful for other backends: two reporting functions\r
+> _report_before_adding_file and _report_added_file, as well as\r
+> _add_message, which actually does the message adding.\r
+>\r
+> No functional changes.\r
+\r
+This looks fine. Personally, I would split it into two or three bits so\r
+it is easier to see that it is just code movement.\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+>\r
+> Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com>\r
+> ---\r
+> notmuch-new.c | 192 +++++++++++++++++++++++++++++++++++----------------------\r
+> 1 file changed, 119 insertions(+), 73 deletions(-)\r
+>\r
+> diff --git a/notmuch-new.c b/notmuch-new.c\r
+> index 8377750..5250562 100644\r
+> --- a/notmuch-new.c\r
+> +++ b/notmuch-new.c\r
+> @@ -239,6 +239,122 @@ _entry_in_ignore_list (const char *entry, add_files_state_t *state)\r
+> return FALSE;\r
+> }\r
+> \r
+> +/* Progress-reporting function.\r
+> + *\r
+> + * Can be used by any mailstore-crawling function that wants to alert\r
+> + * users what message it's about to add. Subsequent errors will be due\r
+> + * to this message ;)\r
+> + */\r
+> +static void\r
+> +_report_before_adding_file (add_files_state_t *state, const char *filename)\r
+> +{\r
+> + state->processed_files++;\r
+> +\r
+> + if (state->verbose) {\r
+> + if (state->output_is_a_tty)\r
+> + printf("\r\033[K");\r
+> +\r
+> + printf ("%i/%i: %s",\r
+> + state->processed_files,\r
+> + state->total_files,\r
+> + filename);\r
+> +\r
+> + putchar((state->output_is_a_tty) ? '\r' : '\n');\r
+> + fflush (stdout);\r
+> + }\r
+> +}\r
+> +\r
+> +/* Progress-reporting function.\r
+> + *\r
+> + * Call this to respond to the signal handler for SIGALRM.\r
+> + */\r
+> +static void\r
+> +_report_added_file (add_files_state_t *state)\r
+> +{\r
+> + if (do_print_progress) {\r
+> + do_print_progress = 0;\r
+> + generic_print_progress ("Processed", "files", state->tv_start,\r
+> + state->processed_files, state->total_files);\r
+> + }\r
+> +}\r
+> +\r
+> +\r
+> +/* Atomically handles adding a message to the database.\r
+> + *\r
+> + * Should be used by any mailstore-crawling function that finds a new\r
+> + * message to add.\r
+> + */\r
+> +static notmuch_status_t\r
+> +_add_message (add_files_state_t *state, notmuch_database_t *notmuch,\r
+> + const char *filename)\r
+> +{\r
+> + notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;\r
+> + notmuch_message_t *message;\r
+> + const char **tag;\r
+> +\r
+> + status = notmuch_database_begin_atomic (notmuch);\r
+> + if (status) {\r
+> + ret = status;\r
+> + goto DONE;\r
+> + }\r
+> +\r
+> + status = notmuch_database_add_message (notmuch, filename, &message);\r
+> +\r
+> + switch (status) {\r
+> + /* success */\r
+> + case NOTMUCH_STATUS_SUCCESS:\r
+> + state->added_messages++;\r
+> + notmuch_message_freeze (message);\r
+> + for (tag=state->new_tags; *tag != NULL; tag++)\r
+> + notmuch_message_add_tag (message, *tag);\r
+> + if (state->synchronize_flags == TRUE)\r
+> + notmuch_message_maildir_flags_to_tags (message);\r
+> + notmuch_message_thaw (message);\r
+> + break;\r
+> + /* Non-fatal issues (go on to next file) */\r
+> + case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:\r
+> + if (state->synchronize_flags == TRUE)\r
+> + notmuch_message_maildir_flags_to_tags (message);\r
+> + break;\r
+> + case NOTMUCH_STATUS_FILE_NOT_EMAIL:\r
+> + fprintf (stderr, "Note: Ignoring non-mail file: %s\n",\r
+> + filename);\r
+> + break;\r
+> + /* Fatal issues. Don't process anymore. */\r
+> + case NOTMUCH_STATUS_READ_ONLY_DATABASE:\r
+> + case NOTMUCH_STATUS_XAPIAN_EXCEPTION:\r
+> + case NOTMUCH_STATUS_OUT_OF_MEMORY:\r
+> + fprintf (stderr, "Error: %s. Halting processing.\n",\r
+> + notmuch_status_to_string (status));\r
+> + ret = status;\r
+> + goto DONE;\r
+> + default:\r
+> + case NOTMUCH_STATUS_FILE_ERROR:\r
+> + case NOTMUCH_STATUS_NULL_POINTER:\r
+> + case NOTMUCH_STATUS_TAG_TOO_LONG:\r
+> + case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:\r
+> + case NOTMUCH_STATUS_UNBALANCED_ATOMIC:\r
+> + case NOTMUCH_STATUS_LAST_STATUS:\r
+> + INTERNAL_ERROR ("add_message returned unexpected value: %d", status);\r
+> + ret = status;\r
+> + goto DONE;\r
+> + }\r
+> +\r
+> + status = notmuch_database_end_atomic (notmuch);\r
+> + if (status) {\r
+> + ret = status;\r
+> + goto DONE;\r
+> + }\r
+> +\r
+> + DONE:\r
+> + if (message) {\r
+> + notmuch_message_destroy (message);\r
+> + message = NULL;\r
+> + }\r
+> +\r
+> + return ret;\r
+> +}\r
+> +\r
+> /* Examine 'path' recursively as follows:\r
+> *\r
+> * o Ask the filesystem for the mtime of 'path' (fs_mtime)\r
+> @@ -290,7 +406,6 @@ add_files (notmuch_database_t *notmuch,\r
+> char *next = NULL;\r
+> time_t fs_mtime, db_mtime;\r
+> notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;\r
+> - notmuch_message_t *message = NULL;\r
+> struct dirent **fs_entries = NULL;\r
+> int i, num_fs_entries = 0, entry_type;\r
+> notmuch_directory_t *directory;\r
+> @@ -299,7 +414,6 @@ add_files (notmuch_database_t *notmuch,\r
+> time_t stat_time;\r
+> struct stat st;\r
+> notmuch_bool_t is_maildir;\r
+> - const char **tag;\r
+> \r
+> if (stat (path, &st)) {\r
+> fprintf (stderr, "Error reading directory %s: %s\n",\r
+> @@ -469,83 +583,15 @@ add_files (notmuch_database_t *notmuch,\r
+> * in the database, so add it. */\r
+> next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);\r
+> \r
+> - state->processed_files++;\r
+> -\r
+> - if (state->verbose) {\r
+> - if (state->output_is_a_tty)\r
+> - printf("\r\033[K");\r
+> -\r
+> - printf ("%i/%i: %s",\r
+> - state->processed_files,\r
+> - state->total_files,\r
+> - next);\r
+> -\r
+> - putchar((state->output_is_a_tty) ? '\r' : '\n');\r
+> - fflush (stdout);\r
+> - }\r
+> + _report_before_adding_file (state, next);\r
+> \r
+> - status = notmuch_database_begin_atomic (notmuch);\r
+> + status = _add_message (state, notmuch, next);\r
+> if (status) {\r
+> ret = status;\r
+> goto DONE;\r
+> }\r
+> \r
+> - status = notmuch_database_add_message (notmuch, next, &message);\r
+> - switch (status) {\r
+> - /* success */\r
+> - case NOTMUCH_STATUS_SUCCESS:\r
+> - state->added_messages++;\r
+> - notmuch_message_freeze (message);\r
+> - for (tag=state->new_tags; *tag != NULL; tag++)\r
+> - notmuch_message_add_tag (message, *tag);\r
+> - if (state->synchronize_flags == TRUE)\r
+> - notmuch_message_maildir_flags_to_tags (message);\r
+> - notmuch_message_thaw (message);\r
+> - break;\r
+> - /* Non-fatal issues (go on to next file) */\r
+> - case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:\r
+> - if (state->synchronize_flags == TRUE)\r
+> - notmuch_message_maildir_flags_to_tags (message);\r
+> - break;\r
+> - case NOTMUCH_STATUS_FILE_NOT_EMAIL:\r
+> - fprintf (stderr, "Note: Ignoring non-mail file: %s\n",\r
+> - next);\r
+> - break;\r
+> - /* Fatal issues. Don't process anymore. */\r
+> - case NOTMUCH_STATUS_READ_ONLY_DATABASE:\r
+> - case NOTMUCH_STATUS_XAPIAN_EXCEPTION:\r
+> - case NOTMUCH_STATUS_OUT_OF_MEMORY:\r
+> - fprintf (stderr, "Error: %s. Halting processing.\n",\r
+> - notmuch_status_to_string (status));\r
+> - ret = status;\r
+> - goto DONE;\r
+> - default:\r
+> - case NOTMUCH_STATUS_FILE_ERROR:\r
+> - case NOTMUCH_STATUS_NULL_POINTER:\r
+> - case NOTMUCH_STATUS_TAG_TOO_LONG:\r
+> - case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:\r
+> - case NOTMUCH_STATUS_UNBALANCED_ATOMIC:\r
+> - case NOTMUCH_STATUS_LAST_STATUS:\r
+> - INTERNAL_ERROR ("add_message returned unexpected value: %d", status);\r
+> - goto DONE;\r
+> - }\r
+> -\r
+> - status = notmuch_database_end_atomic (notmuch);\r
+> - if (status) {\r
+> - ret = status;\r
+> - goto DONE;\r
+> - }\r
+> -\r
+> - if (message) {\r
+> - notmuch_message_destroy (message);\r
+> - message = NULL;\r
+> - }\r
+> -\r
+> - if (do_print_progress) {\r
+> - do_print_progress = 0;\r
+> - generic_print_progress ("Processed", "files", state->tv_start,\r
+> - state->processed_files, state->total_files);\r
+> - }\r
+> + _report_added_file (state);\r
+> \r
+> talloc_free (next);\r
+> next = NULL;\r
+> -- \r
+> 1.7.9.5\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r