--- /dev/null
+Return-Path: <jani@nikula.org>\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 76B48431FC4\r
+ for <notmuch@notmuchmail.org>; Sat, 27 Apr 2013 14:32:56 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 ro3eFkuwn6iX for <notmuch@notmuchmail.org>;\r
+ Sat, 27 Apr 2013 14:32:56 -0700 (PDT)\r
+Received: from mail-la0-f51.google.com (mail-la0-f51.google.com\r
+ [209.85.215.51]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id B9270431FC2\r
+ for <notmuch@notmuchmail.org>; Sat, 27 Apr 2013 14:32:55 -0700 (PDT)\r
+Received: by mail-la0-f51.google.com with SMTP id ep20so749738lab.24\r
+ for <notmuch@notmuchmail.org>; Sat, 27 Apr 2013 14:32:54 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=google.com; s=20120113;\r
+ h=x-received:from:to:subject:in-reply-to:references:user-agent:date\r
+ :message-id:mime-version:content-type:x-gm-message-state;\r
+ bh=gu24WgPMIHhGpC6Ex3Gjb0cGlNr/LYlLofm71iaNwp8=;\r
+ b=CDqJa+cUucUCDsuohboON0NmqSkcbH9MthdEmspIThseU2SOypPEFRMUNNuGyjrNT9\r
+ sx7WHWyo9EcAW23TLwCWJqnPxxz5wZnu0Ga/ayXQdc1oWNubNfHQhpt2gXFF//E0cee4\r
+ 7Qo8e1oqsCO2lCpo/zx1g7IFKUYAnpQdnW3RdvZ+mNbBINU7DgufkqcvjZ6i5ieza8LH\r
+ U9fCWHocMNaQPQfydy4ODENvEhz18HavsuArcsVxWsY0+yhuAtug7KdO5oWRrsff3Lk/\r
+ ZDaX4Su40Fjoqr0rheTS/4QSt6gbxWEBtNHxtyyjjva9K9GPf5r9qX+NV2S+XZ2GBwLK\r
+ S4pA==\r
+X-Received: by 10.152.4.100 with SMTP id j4mr24628255laj.14.1367098374307;\r
+ Sat, 27 Apr 2013 14:32:54 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw2-58c376-211.dhcp.inet.fi.\r
+ [88.195.118.211])\r
+ by mx.google.com with ESMTPSA id t20sm6783560lbi.5.2013.04.27.14.32.53\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Sat, 27 Apr 2013 14:32:53 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Peter Wang <novalazy@gmail.com>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v5 07/12] insert: add --folder option\r
+In-Reply-To: <1364942517-6982-8-git-send-email-novalazy@gmail.com>\r
+References: <1364942517-6982-1-git-send-email-novalazy@gmail.com>\r
+ <1364942517-6982-8-git-send-email-novalazy@gmail.com>\r
+User-Agent: Notmuch/0.15.2+70~g2eeb96a (http://notmuchmail.org) Emacs/24.2.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Sun, 28 Apr 2013 00:32:47 +0300\r
+Message-ID: <87zjwjpslc.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+X-Gm-Message-State:\r
+ ALoCoQk60lUsm6xCtoFT1TFNSC8fRbpBB1Mfgzim1qOTPt8iruQPZECubB2vDB/7Iehtz5XcESBw\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: Sat, 27 Apr 2013 21:32:56 -0000\r
+\r
+On Wed, 03 Apr 2013, Peter Wang <novalazy@gmail.com> wrote:\r
+> Allow the new message to be inserted into a folder within the Maildir\r
+> hierarchy instead of the top-level folder.\r
+> ---\r
+> notmuch-insert.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--\r
+> 1 file changed, 45 insertions(+), 2 deletions(-)\r
+>\r
+> diff --git a/notmuch-insert.c b/notmuch-insert.c\r
+> index 19b1cf9..778ac04 100644\r
+> --- a/notmuch-insert.c\r
+> +++ b/notmuch-insert.c\r
+> @@ -83,6 +83,23 @@ sync_dir (const char *dir)\r
+> return ret;\r
+> }\r
+> \r
+> +/* Check the specified folder name does not contain a directory\r
+> + * component ".." to prevent writes outside of the Maildir hierarchy. */\r
+> +static notmuch_bool_t\r
+> +check_folder_name (const char *folder)\r
+> +{\r
+> + const char *p = folder;\r
+> +\r
+> + for (;;) {\r
+> + if ((p[0] == '.') && (p[1] == '.') && (p[2] == '\0' || p[2] == '/'))\r
+> + return FALSE;\r
+> + p = strchr (p, '/');\r
+> + if (!p)\r
+> + return TRUE;\r
+> + p++;\r
+> + }\r
+> +}\r
+> +\r
+> /* Open a unique file in the Maildir 'tmp' directory.\r
+> * Returns the file descriptor on success, or -1 on failure.\r
+> * On success, file paths for the message in the 'tmp' and 'new'\r
+> @@ -287,11 +304,25 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
+> size_t new_tags_length;\r
+> tag_op_list_t *tag_ops;\r
+> char *query_string = NULL;\r
+> + const char *folder = NULL;\r
+> const char *maildir;\r
+> - int opt_index = 1;\r
+> + int opt_index;\r
+> unsigned int i;\r
+> notmuch_bool_t ret;\r
+> \r
+> + notmuch_opt_desc_t options[] = {\r
+> + { NOTMUCH_OPT_STRING, &folder, "folder", 0, 0 },\r
+> + { NOTMUCH_OPT_END, 0, 0, 0, 0 }\r
+> + };\r
+> +\r
+> + opt_index = parse_arguments (argc, argv, options, 1);\r
+> +\r
+> + if (opt_index < 0) {\r
+> + fprintf (stderr, "Error: bad argument to notmuch insert: %s\n",\r
+> + argv[-opt_index]);\r
+\r
+I'm too tired to check what's correct, but argv[-opt_index] isn't.\r
+\r
+J.\r
+\r
+\r
+> + return 1;\r
+> + }\r
+> +\r
+> db_path = notmuch_config_get_database_path (config);\r
+> new_tags = notmuch_config_get_new_tags (config, &new_tags_length);\r
+> \r
+> @@ -314,7 +345,19 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
+> return 1;\r
+> }\r
+> \r
+> - maildir = db_path;\r
+> + if (folder == NULL) {\r
+> + maildir = db_path;\r
+> + } else {\r
+> + if (! check_folder_name (folder)) {\r
+> + fprintf (stderr, "Error: bad folder name: %s\n", folder);\r
+> + return 1;\r
+> + }\r
+> + maildir = talloc_asprintf (config, "%s/%s", db_path, folder);\r
+> + if (! maildir) {\r
+> + fprintf (stderr, "Out of memory\n");\r
+> + return 1;\r
+> + }\r
+> + }\r
+> \r
+> /* Setup our handler for SIGINT. We do not set SA_RESTART so that copying\r
+> * from standard input may be interrupted. */\r
+> -- \r
+> 1.7.12.1\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r