1 Return-Path: <novalazy@gmail.com>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 76EA2431FAF
\r
6 for <notmuch@notmuchmail.org>; Tue, 2 Apr 2013 15:42:59 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.099 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id 2-63gk4Sy69I for <notmuch@notmuchmail.org>;
\r
17 Tue, 2 Apr 2013 15:42:58 -0700 (PDT)
\r
18 Received: from mail-pd0-f180.google.com (mail-pd0-f180.google.com
\r
19 [209.85.192.180]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 345E2431FB6
\r
22 for <notmuch@notmuchmail.org>; Tue, 2 Apr 2013 15:42:51 -0700 (PDT)
\r
23 Received: by mail-pd0-f180.google.com with SMTP id q11so488555pdj.39
\r
24 for <notmuch@notmuchmail.org>; Tue, 02 Apr 2013 15:42:50 -0700 (PDT)
\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
\r
26 h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to
\r
27 :references; bh=jV//+uBvocbFAKz2inXvoDkxaR0m4vsBVApXE8uXQxc=;
\r
28 b=nIjDz9IFgbJzDGbE+x5//bJwtXdL9ed0GGuu2FsGCCgKoBnEqq/DcIens3izPJsEk5
\r
29 lSAjujXHxyfjYXmb1mXl6JEhzpm8yTWpcQUhnVS1oAeFH0DrzkDJsPJlbRRhsRxWdn5g
\r
30 e2PC6GyBD8SV8hlQCBkQj4DcMQJMWH+pYZOvZhHhO0LD7/q7u6dTA33X5xHTUpvpwQ6W
\r
31 o6y8NmKkbPJEUtkiKEWnrE3e4fj0aacf8WQhrc6KDaFk2/qQxJPPciAMUzhmKx4LTMhB
\r
32 x/aa2zR2H+KF/rs+YUYH6kgIy4NyxTa3x3XiYNhShC5EO0pqyzz+8UM46AoG4moORyiM
\r
34 X-Received: by 10.68.253.68 with SMTP id zy4mr26830147pbc.38.1364942570501;
\r
35 Tue, 02 Apr 2013 15:42:50 -0700 (PDT)
\r
36 Received: from localhost (215.42.233.220.static.exetel.com.au.
\r
38 by mx.google.com with ESMTPS id sl9sm3272125pbc.17.2013.04.02.15.42.48
\r
39 (version=TLSv1.2 cipher=RC4-SHA bits=128/128);
\r
40 Tue, 02 Apr 2013 15:42:49 -0700 (PDT)
\r
41 From: Peter Wang <novalazy@gmail.com>
\r
42 To: notmuch@notmuchmail.org
\r
43 Subject: [PATCH v5 07/12] insert: add --folder option
\r
44 Date: Wed, 3 Apr 2013 09:41:52 +1100
\r
45 Message-Id: <1364942517-6982-8-git-send-email-novalazy@gmail.com>
\r
46 X-Mailer: git-send-email 1.7.12.1
\r
47 In-Reply-To: <1364942517-6982-1-git-send-email-novalazy@gmail.com>
\r
48 References: <1364942517-6982-1-git-send-email-novalazy@gmail.com>
\r
49 X-BeenThere: notmuch@notmuchmail.org
\r
50 X-Mailman-Version: 2.1.13
\r
52 List-Id: "Use and development of the notmuch mail system."
\r
53 <notmuch.notmuchmail.org>
\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
55 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
57 List-Post: <mailto:notmuch@notmuchmail.org>
\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
60 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
61 X-List-Received-Date: Tue, 02 Apr 2013 22:43:00 -0000
\r
63 Allow the new message to be inserted into a folder within the Maildir
\r
64 hierarchy instead of the top-level folder.
\r
66 notmuch-insert.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
\r
67 1 file changed, 45 insertions(+), 2 deletions(-)
\r
69 diff --git a/notmuch-insert.c b/notmuch-insert.c
\r
70 index 19b1cf9..778ac04 100644
\r
71 --- a/notmuch-insert.c
\r
72 +++ b/notmuch-insert.c
\r
73 @@ -83,6 +83,23 @@ sync_dir (const char *dir)
\r
77 +/* Check the specified folder name does not contain a directory
\r
78 + * component ".." to prevent writes outside of the Maildir hierarchy. */
\r
79 +static notmuch_bool_t
\r
80 +check_folder_name (const char *folder)
\r
82 + const char *p = folder;
\r
85 + if ((p[0] == '.') && (p[1] == '.') && (p[2] == '\0' || p[2] == '/'))
\r
87 + p = strchr (p, '/');
\r
94 /* Open a unique file in the Maildir 'tmp' directory.
\r
95 * Returns the file descriptor on success, or -1 on failure.
\r
96 * On success, file paths for the message in the 'tmp' and 'new'
\r
97 @@ -287,11 +304,25 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
\r
98 size_t new_tags_length;
\r
99 tag_op_list_t *tag_ops;
\r
100 char *query_string = NULL;
\r
101 + const char *folder = NULL;
\r
102 const char *maildir;
\r
103 - int opt_index = 1;
\r
106 notmuch_bool_t ret;
\r
108 + notmuch_opt_desc_t options[] = {
\r
109 + { NOTMUCH_OPT_STRING, &folder, "folder", 0, 0 },
\r
110 + { NOTMUCH_OPT_END, 0, 0, 0, 0 }
\r
113 + opt_index = parse_arguments (argc, argv, options, 1);
\r
115 + if (opt_index < 0) {
\r
116 + fprintf (stderr, "Error: bad argument to notmuch insert: %s\n",
\r
117 + argv[-opt_index]);
\r
121 db_path = notmuch_config_get_database_path (config);
\r
122 new_tags = notmuch_config_get_new_tags (config, &new_tags_length);
\r
124 @@ -314,7 +345,19 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
\r
128 - maildir = db_path;
\r
129 + if (folder == NULL) {
\r
130 + maildir = db_path;
\r
132 + if (! check_folder_name (folder)) {
\r
133 + fprintf (stderr, "Error: bad folder name: %s\n", folder);
\r
136 + maildir = talloc_asprintf (config, "%s/%s", db_path, folder);
\r
138 + fprintf (stderr, "Out of memory\n");
\r
143 /* Setup our handler for SIGINT. We do not set SA_RESTART so that copying
\r
144 * from standard input may be interrupted. */
\r