--- /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 C996C431FBF\r
+ for <notmuch@notmuchmail.org>; Sun, 21 Jul 2013 01:31:39 -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 akDLPjnenOgg for <notmuch@notmuchmail.org>;\r
+ Sun, 21 Jul 2013 01:31:32 -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 B84E4431FB6\r
+ for <notmuch@notmuchmail.org>; Sun, 21 Jul 2013 01:31:31 -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 1V0p3B-0004q6-Uw; Sun, 21 Jul 2013 09:31:30 +0100\r
+Received: from 93-97-24-31.zone5.bethere.co.uk ([93.97.24.31] helo=localhost)\r
+ by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1V0p3B-0001p5-Gz; Sun, 21 Jul 2013 09:31:29 +0100\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Peter Wang <novalazy@gmail.com>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 1/3] cli: add insert --must-index option\r
+In-Reply-To: <1374365254-13227-1-git-send-email-novalazy@gmail.com>\r
+References: <1374365254-13227-1-git-send-email-novalazy@gmail.com>\r
+User-Agent: Notmuch/0.15.2+192~g8222af3 (http://notmuchmail.org) Emacs/23.4.1\r
+ (i486-pc-linux-gnu)\r
+Date: Sun, 21 Jul 2013 09:31:28 +0100\r
+Message-ID: <87ip048gbj.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 93.97.24.31\r
+X-QM-SPAM-Info: Sender has good ham record. :)\r
+X-QM-Body-MD5: 751478499e78726c76f7a8c9290d1a63 (of first 20000 bytes)\r
+X-SpamAssassin-Score: 0.0\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 0.0 points. Summary of the scoring: \r
+ * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+ provider * (markwalters1009[at]gmail.com)\r
+ * 0.0 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\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, 21 Jul 2013 08:31:40 -0000\r
+\r
+\r
+Do you have a particular use case where indexing is required but tagging\r
+is not? For my uses I would prefer failing if either indexing or tagging\r
+failed. (My use being postponing messages; If they don't get the\r
+postponed tag they could be hard to find)\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+\r
+\r
+Peter Wang <novalazy@gmail.com> writes:\r
+\r
+> This option causes notmuch insert to fail as a whole if the message\r
+> failed to be added to the notmuch database. The new message file\r
+> will be deleted from disk, and a distinct status code (2) returned.\r
+> ---\r
+> notmuch-insert.c | 76 ++++++++++++++++++++++++++++++++++----------------------\r
+> 1 file changed, 46 insertions(+), 30 deletions(-)\r
+>\r
+> diff --git a/notmuch-insert.c b/notmuch-insert.c\r
+> index 2207b1e..505b647 100644\r
+> --- a/notmuch-insert.c\r
+> +++ b/notmuch-insert.c\r
+> @@ -28,6 +28,10 @@\r
+> #include <sys/stat.h>\r
+> #include <fcntl.h>\r
+> \r
+> +#define INSERT_EXIT_SUCCESS 0\r
+> +#define INSERT_EXIT_FAIL_WRITE 1\r
+> +#define INSERT_EXIT_FAIL_INDEX 2\r
+> +\r
+> static volatile sig_atomic_t interrupted;\r
+> \r
+> static void\r
+> @@ -293,12 +297,13 @@ copy_stdin (int fdin, int fdout)\r
+> \r
+> /* Add the specified message file to the notmuch database, applying tags.\r
+> * The file is renamed to encode notmuch tags as maildir flags. */\r
+> -static void\r
+> +static notmuch_status_t\r
+> add_file_to_database (notmuch_database_t *notmuch, const char *path,\r
+> tag_op_list_t *tag_ops)\r
+> {\r
+> notmuch_message_t *message;\r
+> notmuch_status_t status;\r
+> + notmuch_status_t sync;\r
+> \r
+> status = notmuch_database_add_message (notmuch, path, &message);\r
+> switch (status) {\r
+> @@ -318,47 +323,52 @@ add_file_to_database (notmuch_database_t *notmuch, const char *path,\r
+> case NOTMUCH_STATUS_LAST_STATUS:\r
+> fprintf (stderr, "Error: failed to add `%s' to notmuch database: %s\n",\r
+> path, notmuch_status_to_string (status));\r
+> - return;\r
+> + return status;\r
+> }\r
+> \r
+> if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {\r
+> /* Don't change tags of an existing message. */\r
+> - status = notmuch_message_tags_to_maildir_flags (message);\r
+> - if (status != NOTMUCH_STATUS_SUCCESS)\r
+> + sync = notmuch_message_tags_to_maildir_flags (message);\r
+> + if (sync != NOTMUCH_STATUS_SUCCESS)\r
+> fprintf (stderr, "Error: failed to sync tags to maildir flags\n");\r
+> } else {\r
+> tag_op_list_apply (message, tag_ops, TAG_FLAG_MAILDIR_SYNC);\r
+> }\r
+> \r
+> notmuch_message_destroy (message);\r
+> +\r
+> + return status;\r
+> }\r
+> \r
+> -static notmuch_bool_t\r
+> +static int\r
+> insert_message (void *ctx, notmuch_database_t *notmuch, int fdin,\r
+> - const char *dir, tag_op_list_t *tag_ops)\r
+> + const char *dir, tag_op_list_t *tag_ops,\r
+> + notmuch_bool_t must_index)\r
+> {\r
+> char *tmppath;\r
+> char *newpath;\r
+> char *newdir;\r
+> int fdout;\r
+> - char *cleanup_path;\r
+> + notmuch_status_t status;\r
+> \r
+> fdout = maildir_open_tmp_file (ctx, dir, &tmppath, &newpath, &newdir);\r
+> if (fdout < 0)\r
+> - return FALSE;\r
+> + return INSERT_EXIT_FAIL_WRITE;\r
+> \r
+> - cleanup_path = tmppath;\r
+> -\r
+> - if (! copy_stdin (fdin, fdout))\r
+> - goto FAIL;\r
+> + if (! copy_stdin (fdin, fdout)) {\r
+> + close (fdout);\r
+> + unlink (tmppath);\r
+> + return INSERT_EXIT_FAIL_WRITE;\r
+> + }\r
+> \r
+> if (fsync (fdout) != 0) {\r
+> fprintf (stderr, "Error: fsync failed: %s\n", strerror (errno));\r
+> - goto FAIL;\r
+> + close (fdout);\r
+> + unlink (tmppath);\r
+> + return INSERT_EXIT_FAIL_WRITE;\r
+> }\r
+> \r
+> close (fdout);\r
+> - fdout = -1;\r
+> \r
+> /* Atomically move the new message file from the Maildir 'tmp' directory\r
+> * to the 'new' directory. We follow the Dovecot recommendation to\r
+> @@ -367,25 +377,28 @@ insert_message (void *ctx, notmuch_database_t *notmuch, int fdin,\r
+> */\r
+> if (rename (tmppath, newpath) != 0) {\r
+> fprintf (stderr, "Error: rename() failed: %s\n", strerror (errno));\r
+> - goto FAIL;\r
+> + unlink (tmppath);\r
+> + return INSERT_EXIT_FAIL_WRITE;\r
+> }\r
+> \r
+> - cleanup_path = newpath;\r
+> -\r
+> - if (! sync_dir (newdir))\r
+> - goto FAIL;\r
+> + if (! sync_dir (newdir)) {\r
+> + unlink (newpath);\r
+> + return INSERT_EXIT_FAIL_WRITE;\r
+> + }\r
+> \r
+> - /* Even if adding the message to the notmuch database fails,\r
+> - * the message is on disk and we consider the delivery completed. */\r
+> - add_file_to_database (notmuch, newpath, tag_ops);\r
+> + status = add_file_to_database (notmuch, newpath, tag_ops);\r
+> \r
+> - return TRUE;\r
+> + /* If must_index is TRUE, then indexing must succeed. Otherwise, we\r
+> + * consider the delivery completed as long as the message is on disk. */\r
+> + if (must_index &&\r
+> + status != NOTMUCH_STATUS_SUCCESS &&\r
+> + status != NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)\r
+> + {\r
+> + unlink (newpath);\r
+> + return INSERT_EXIT_FAIL_INDEX;\r
+> + }\r
+> \r
+> - FAIL:\r
+> - if (fdout >= 0)\r
+> - close (fdout);\r
+> - unlink (cleanup_path);\r
+> - return FALSE;\r
+> + return INSERT_EXIT_SUCCESS;\r
+> }\r
+> \r
+> int\r
+> @@ -400,6 +413,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
+> char *query_string = NULL;\r
+> const char *folder = NULL;\r
+> notmuch_bool_t create_folder = FALSE;\r
+> + notmuch_bool_t must_index = FALSE;\r
+> const char *maildir;\r
+> int opt_index;\r
+> unsigned int i;\r
+> @@ -408,6 +422,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
+> notmuch_opt_desc_t options[] = {\r
+> { NOTMUCH_OPT_STRING, &folder, "folder", 0, 0 },\r
+> { NOTMUCH_OPT_BOOLEAN, &create_folder, "create-folder", 0, 0 },\r
+> + { NOTMUCH_OPT_BOOLEAN, &must_index, "must-index", 0, 0 },\r
+> { NOTMUCH_OPT_END, 0, 0, 0, 0 }\r
+> };\r
+> \r
+> @@ -471,9 +486,10 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
+> NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))\r
+> return 1;\r
+> \r
+> - ret = insert_message (config, notmuch, STDIN_FILENO, maildir, tag_ops);\r
+> + ret = insert_message (config, notmuch, STDIN_FILENO, maildir, tag_ops,\r
+> + must_index);\r
+> \r
+> notmuch_database_destroy (notmuch);\r
+> \r
+> - return (ret) ? 0 : 1;\r
+> + return ret;\r
+> }\r
+> -- \r
+> 1.7.12.1\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r