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