Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / 0a / 3a3c335d4bd9382a9985365b2221825303cdc6
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 C9835431FAF\r
6         for <notmuch@notmuchmail.org>; Thu, 24 Jan 2013 04:10:05 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.799\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.799 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_LOW=-0.7] 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 e6OqYqgOBJu9 for <notmuch@notmuchmail.org>;\r
17         Thu, 24 Jan 2013 04:10:04 -0800 (PST)\r
18 Received: from mail-da0-f47.google.com (mail-da0-f47.google.com\r
19         [209.85.210.47]) (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 38F23431FD2\r
22         for <notmuch@notmuchmail.org>; Thu, 24 Jan 2013 04:09:50 -0800 (PST)\r
23 Received: by mail-da0-f47.google.com with SMTP id s35so4226763dak.34\r
24         for <notmuch@notmuchmail.org>; Thu, 24 Jan 2013 04:09:49 -0800 (PST)\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=0gqOSG5ReP1lmZQUKsuerhTRTl7TyEHFiACf41gWRLA=;\r
28         b=rVwQTS3slb7L4aRBUdEjUpEAJDjrO0DUrfZrTDK6x7GlI4tNt5eI2eLRRKmKG5DLc3\r
29         7yuLGyr8WsQeHIKyxklDvVJLN5fbSOkEPF+R9Ceb+cLW4m+Dm0Z8fF8pdSUoo06Z81v2\r
30         paC5YKpEM//phDUo5TOr1pE1bP3ktvGlg9sgo6Pj3ZHRQk5EBlN5S92fDFjT3LfHuxgl\r
31         tnqjcvMR7lyY5TlnHMl1pe52aiKI1Moc81cVnHU6c5dWTr8cHBVW0C72r0uXMWEpNboo\r
32         xCdkmJmkf/rpoFYnA++4MSrJcZqsiINW5c1hu2Z7A0nqCZiwZS6CyAeYtx5z+udOA6Tg\r
33         yqaA==\r
34 X-Received: by 10.68.248.70 with SMTP id yk6mr4051044pbc.160.1359029389452;\r
35         Thu, 24 Jan 2013 04:09:49 -0800 (PST)\r
36 Received: from localhost (215.42.233.220.static.exetel.com.au.\r
37         [220.233.42.215])\r
38         by mx.google.com with ESMTPS id rs7sm14790445pbc.2.2013.01.24.04.09.47\r
39         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
40         Thu, 24 Jan 2013 04:09:48 -0800 (PST)\r
41 From: Peter Wang <novalazy@gmail.com>\r
42 To: notmuch@notmuchmail.org\r
43 Subject: [PATCH v4 07/12] insert: add --folder option\r
44 Date: Thu, 24 Jan 2013 23:08:03 +1100\r
45 Message-Id: <1359029288-12132-8-git-send-email-novalazy@gmail.com>\r
46 X-Mailer: git-send-email 1.7.12.1\r
47 In-Reply-To: <1359029288-12132-1-git-send-email-novalazy@gmail.com>\r
48 References: <1359029288-12132-1-git-send-email-novalazy@gmail.com>\r
49 X-BeenThere: notmuch@notmuchmail.org\r
50 X-Mailman-Version: 2.1.13\r
51 Precedence: list\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: Thu, 24 Jan 2013 12:10:06 -0000\r
62 \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
65 ---\r
66  notmuch-insert.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--\r
67  1 file changed, 45 insertions(+), 2 deletions(-)\r
68 \r
69 diff --git a/notmuch-insert.c b/notmuch-insert.c\r
70 index 31c1152..bc848ff 100644\r
71 --- a/notmuch-insert.c\r
72 +++ b/notmuch-insert.c\r
73 @@ -85,6 +85,23 @@ sync_dir (const char *dir)\r
74      return ret;\r
75  }\r
76  \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
81 +{\r
82 +    const char *p = folder;\r
83 +\r
84 +    for (;;) {\r
85 +       if ((p[0] == '.') && (p[1] == '.') && (p[2] == '\0' || p[2] == '/'))\r
86 +           return FALSE;\r
87 +       p = strchr (p, '/');\r
88 +       if (!p)\r
89 +           return TRUE;\r
90 +       p++;\r
91 +    }\r
92 +}\r
93 +\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 @@ -288,11 +305,25 @@ notmuch_insert_command (void *ctx, 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
104 +    int opt_index;\r
105      unsigned int i;\r
106      notmuch_bool_t ret;\r
107  \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
111 +    };\r
112 +\r
113 +    opt_index = parse_arguments (argc, argv, options, 1);\r
114 +\r
115 +    if (opt_index < 0) {\r
116 +       fprintf (stderr, "Error: bad argument to notmuch insert: %s\n",\r
117 +                argv[-opt_index]);\r
118 +       return 1;\r
119 +    }\r
120 +\r
121      config = notmuch_config_open (ctx, NULL, NULL);\r
122      if (config == NULL)\r
123         return 1;\r
124 @@ -319,7 +350,19 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])\r
125         return 1;\r
126      }\r
127  \r
128 -    maildir = db_path;\r
129 +    if (folder == NULL) {\r
130 +       maildir = db_path;\r
131 +    } else {\r
132 +       if (! check_folder_name (folder)) {\r
133 +           fprintf (stderr, "Error: bad folder name: %s\n", folder);\r
134 +           return 1;\r
135 +       }\r
136 +       maildir = talloc_asprintf (ctx, "%s/%s", db_path, folder);\r
137 +       if (! maildir) {\r
138 +           fprintf (stderr, "Out of memory\n");\r
139 +           return 1;\r
140 +       }\r
141 +    }\r
142  \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
145 -- \r
146 1.7.12.1\r
147 \r