--- /dev/null
+Return-Path: <novalazy@gmail.com>\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 94A2D429E37\r
+ for <notmuch@notmuchmail.org>; Wed, 16 Apr 2014 06:00:45 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.099\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.099 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001] 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 XVBqombZ+Pgv for <notmuch@notmuchmail.org>;\r
+ Wed, 16 Apr 2014 06:00:40 -0700 (PDT)\r
+Received: from mail-pd0-f169.google.com (mail-pd0-f169.google.com\r
+ [209.85.192.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 26E41431FAE\r
+ for <notmuch@notmuchmail.org>; Wed, 16 Apr 2014 06:00:13 -0700 (PDT)\r
+Received: by mail-pd0-f169.google.com with SMTP id fp1so10780476pdb.0\r
+ for <notmuch@notmuchmail.org>; Wed, 16 Apr 2014 06:00:12 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id:in-reply-to:references;\r
+ bh=q8S0uIz/2t/fjxsh5T+/4TYA1Qp5sSDOxaIQGwwRb3Q=;\r
+ b=fUs0nYv7GbJklSB7pj5dVpsCvXra558t8RckqiFdGOnWNAeeaxxhOcLf4g53JUJ5ZJ\r
+ zozZqaod/BWvRQc7SEDzwbdfn1WrTQAHg8lCAHqc0P3K2BdKOw6tttt5xaMKhoZ3UNeX\r
+ xxEvWUV4C53jmJfZ5hydmpaSVSRKd6h/68WlcTpbs7BkWS94n4BYtVPxuole+x+7BUlW\r
+ YvMiHdcq/gL9NS/zS/TdE4R7i9svnRMYpKmSfpaWSNI7IosnKstZhuMYCd79cmm5uQNx\r
+ 8Er3jxV5N25yFzlJZApqQU7KHawPszIgX1bokL9mZv/oxPa6I7kkhdhj8p/B4dGUo1Gq\r
+ F+7g==\r
+X-Received: by 10.66.102.72 with SMTP id fm8mr2695390pab.86.1397653212449;\r
+ Wed, 16 Apr 2014 06:00:12 -0700 (PDT)\r
+Received: from localhost (215.42.233.220.static.exetel.com.au.\r
+ [220.233.42.215]) by mx.google.com with ESMTPSA id\r
+ nx12sm111066548pab.6.2014.04.16.06.00.10 for <multiple recipients>\r
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Wed, 16 Apr 2014 06:00:11 -0700 (PDT)\r
+From: Peter Wang <novalazy@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 07/10] cli: indicate insert failure mode in exit status\r
+Date: Wed, 16 Apr 2014 22:59:22 +1000\r
+Message-Id: <1397653165-15620-8-git-send-email-novalazy@gmail.com>\r
+X-Mailer: git-send-email 1.8.4\r
+In-Reply-To: <1397653165-15620-1-git-send-email-novalazy@gmail.com>\r
+References: <1397653165-15620-1-git-send-email-novalazy@gmail.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: Wed, 16 Apr 2014 13:00:45 -0000\r
+\r
+Make insert return a different exit code, 2, for failure to write the\r
+message file to disk, and exit code 1 for other errors.\r
+---\r
+ notmuch-insert.c | 30 ++++++++++++++++++------------\r
+ test/T070-insert.sh | 4 ++--\r
+ 2 files changed, 20 insertions(+), 14 deletions(-)\r
+\r
+diff --git a/notmuch-insert.c b/notmuch-insert.c\r
+index 7db4f73..29d82c9 100644\r
+--- a/notmuch-insert.c\r
++++ b/notmuch-insert.c\r
+@@ -28,6 +28,12 @@\r
+ #include <sys/stat.h>\r
+ #include <fcntl.h>\r
+ \r
++enum {\r
++ INSERT_EXIT_SUCCESS = 0,\r
++ INSERT_EXIT_FAILURE = 1,\r
++ INSERT_EXIT_FAILED_WRITE = 2\r
++};\r
++\r
+ static volatile sig_atomic_t interrupted;\r
+ \r
+ static void\r
+@@ -408,7 +414,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
+ \r
+ opt_index = parse_arguments (argc, argv, options, 1);\r
+ if (opt_index < 0)\r
+- return EXIT_FAILURE;\r
++ return INSERT_EXIT_FAILURE;\r
+ \r
+ db_path = notmuch_config_get_database_path (config);\r
+ new_tags = notmuch_config_get_new_tags (config, &new_tags_length);\r
+@@ -417,7 +423,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
+ tag_ops = tag_op_list_create (config);\r
+ if (tag_ops == NULL) {\r
+ fprintf (stderr, "Out of memory.\n");\r
+- return EXIT_FAILURE;\r
++ return INSERT_EXIT_FAILURE;\r
+ }\r
+ for (i = 0; i < new_tags_length; i++) {\r
+ const char *error_msg;\r
+@@ -426,20 +432,20 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
+ if (error_msg) {\r
+ fprintf (stderr, "Error: tag '%s' in new.tags: %s\n",\r
+ new_tags[i], error_msg);\r
+- return EXIT_FAILURE;\r
++ return INSERT_EXIT_FAILURE;\r
+ }\r
+ \r
+ if (tag_op_list_append (tag_ops, new_tags[i], FALSE))\r
+- return EXIT_FAILURE;\r
++ return INSERT_EXIT_FAILURE;\r
+ }\r
+ \r
+ if (parse_tag_command_line (config, argc - opt_index, argv + opt_index,\r
+ &query_string, tag_ops))\r
+- return EXIT_FAILURE;\r
++ return INSERT_EXIT_FAILURE;\r
+ \r
+ if (*query_string != '\0') {\r
+ fprintf (stderr, "Error: unexpected query string: %s\n", query_string);\r
+- return EXIT_FAILURE;\r
++ return INSERT_EXIT_FAILURE;\r
+ }\r
+ \r
+ if (folder == NULL) {\r
+@@ -447,17 +453,17 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
+ } else {\r
+ if (! check_folder_name (folder)) {\r
+ fprintf (stderr, "Error: bad folder name: %s\n", folder);\r
+- return EXIT_FAILURE;\r
++ return INSERT_EXIT_FAILURE;\r
+ }\r
+ maildir = talloc_asprintf (config, "%s/%s", db_path, folder);\r
+ if (! maildir) {\r
+ fprintf (stderr, "Out of memory\n");\r
+- return EXIT_FAILURE;\r
++ return INSERT_EXIT_FAILURE;\r
+ }\r
+ if (create_folder && ! maildir_create_folder (config, maildir)) {\r
+ fprintf (stderr, "Error: creating maildir %s: %s\n",\r
+ maildir, strerror (errno));\r
+- return EXIT_FAILURE;\r
++ return INSERT_EXIT_FAILURE;\r
+ }\r
+ }\r
+ \r
+@@ -471,12 +477,12 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
+ \r
+ if (notmuch_database_open (notmuch_config_get_database_path (config),\r
+ NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))\r
+- return EXIT_FAILURE;\r
++ return INSERT_EXIT_FAILURE;\r
+ \r
+ /* Write the message to the Maildir new directory. */\r
+ if (! write_message (config, STDIN_FILENO, maildir, &newpath)) {\r
+ notmuch_database_destroy (notmuch);\r
+- return EXIT_FAILURE;\r
++ return INSERT_EXIT_FAILED_WRITE;\r
+ }\r
+ \r
+ /* Add the message to the index.\r
+@@ -486,5 +492,5 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
+ synchronize_flags);\r
+ \r
+ notmuch_database_destroy (notmuch);\r
+- return EXIT_SUCCESS;\r
++ return INSERT_EXIT_SUCCESS;\r
+ }\r
+diff --git a/test/T070-insert.sh b/test/T070-insert.sh\r
+index ea9db07..c576efc 100755\r
+--- a/test/T070-insert.sh\r
++++ b/test/T070-insert.sh\r
+@@ -18,7 +18,7 @@ gen_insert_msg() {\r
+ "[body]=\"insert-message\""\r
+ }\r
+ \r
+-test_expect_code 1 "Insert zero-length file" \\r
++test_expect_code 2 "Insert zero-length file" \\r
+ "notmuch insert < /dev/null"\r
+ \r
+ # This test is a proxy for other errors that may occur while trying to\r
+@@ -137,7 +137,7 @@ output=$(notmuch search --output=messages path:Drafts/cur tag:draft NOT tag:unre\r
+ test_expect_equal "$output" "id:$gen_msg_id"\r
+ \r
+ gen_insert_msg\r
+-test_expect_code 1 "Insert message into non-existent folder" \\r
++test_expect_code 2 "Insert message into non-existent folder" \\r
+ "notmuch insert --folder=nonesuch < $gen_msg_filename"\r
+ \r
+ test_begin_subtest "Insert message, create folder"\r
+-- \r
+1.8.4\r
+\r