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 9721E431FB6
\r
6 for <notmuch@notmuchmail.org>; Wed, 25 Jul 2012 06:44:50 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\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 58KsLlYWi8tb for <notmuch@notmuchmail.org>;
\r
17 Wed, 25 Jul 2012 06:44:49 -0700 (PDT)
\r
18 Received: from mail-gg0-f181.google.com (mail-gg0-f181.google.com
\r
19 [209.85.161.181]) (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 ACCE5431FAE
\r
22 for <notmuch@notmuchmail.org>; Wed, 25 Jul 2012 06:44:49 -0700 (PDT)
\r
23 Received: by ggnv5 with SMTP id v5so884306ggn.26
\r
24 for <notmuch@notmuchmail.org>; Wed, 25 Jul 2012 06:44:49 -0700 (PDT)
\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
\r
26 h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;
\r
27 bh=7rnN/E5XAtJQxCnn8sc23jdqIk71FhaHAWCuDX+2vAs=;
\r
28 b=igq4KXvhdTjsQCA2yR/YRcfmfYggplcVgv3zoQnueDfYHPJEjS3lmNyZEPHhfGZ7OP
\r
29 0fzjFZW5zCOTfOiqecvpPDBJGjMPo1xhawn0aV7JppvSQTFLd7yq3c0gwqeBLJ9OX0bK
\r
30 /tvkST9nJ9QZHUJKqwntQof+maHjLA0IWi3kuQF984QbPubzP85vPkOPeV1E9HFECiSx
\r
31 tZ692xu3tbhUV//VGMO2dXDDZU0oy+lFugoAoJqspT36+f85dcqNrcrGYG9arFNR2vjv
\r
32 OAfIdwMapReLzAQ0OBE2DAqGNQy+H+ytfbiaMEFyOF2/lNnkm5yr9Acja5mf63dm4NAK
\r
34 Received: by 10.66.73.70 with SMTP id j6mr12832814pav.5.1343223888780;
\r
35 Wed, 25 Jul 2012 06:44:48 -0700 (PDT)
\r
36 Received: from localhost (215.42.233.220.static.exetel.com.au.
\r
37 [220.233.42.215]) by mx.google.com with ESMTPS id
\r
38 qd10sm14414282pbb.38.2012.07.25.06.44.46
\r
39 (version=TLSv1/SSLv3 cipher=OTHER);
\r
40 Wed, 25 Jul 2012 06:44:47 -0700 (PDT)
\r
41 From: Peter Wang <novalazy@gmail.com>
\r
42 To: notmuch@notmuchmail.org
\r
43 Subject: [PATCH 16/18] insert: add --create-folder option
\r
44 Date: Wed, 25 Jul 2012 23:42:45 +1000
\r
45 Message-Id: <1343223767-9812-16-git-send-email-novalazy@gmail.com>
\r
46 X-Mailer: git-send-email 1.7.4.4
\r
47 In-Reply-To: <1343223767-9812-1-git-send-email-novalazy@gmail.com>
\r
48 References: <1343223767-9812-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: Wed, 25 Jul 2012 13:44:50 -0000
\r
63 Support an option to create a new folder in the maildir.
\r
65 notmuch-insert.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
66 1 files changed, 71 insertions(+), 0 deletions(-)
\r
68 diff --git a/notmuch-insert.c b/notmuch-insert.c
\r
69 index a69dfe6..380c520 100644
\r
70 --- a/notmuch-insert.c
\r
71 +++ b/notmuch-insert.c
\r
72 @@ -48,6 +48,70 @@ check_folder_name (const char *folder)
\r
77 +mkdir_parents (void *ctx, const char *path, int mode)
\r
85 + /* First check the common case: directory already exists. */
\r
86 + if (stat (path, &st) == 0) {
\r
87 + return (S_ISDIR (st.st_mode)) ? 0 : -1;
\r
90 + pathcopy = talloc_strdup (ctx, path);
\r
93 + for (start = pathcopy; *start != '\0'; start = end + 1) {
\r
94 + end = strchr (start + 1, '/');
\r
96 + ret = mkdir (path, mode);
\r
100 + ret = mkdir (pathcopy, mode);
\r
101 + if (ret != 0 && errno != EEXIST) {
\r
107 + talloc_free (pathcopy);
\r
112 +static notmuch_bool_t
\r
113 +maildir_create (void *ctx, const char *dir)
\r
115 + const int mode = 0755;
\r
119 + /* Create 'cur' directory, including parent directories. */
\r
120 + subdir = talloc_asprintf (ctx, "%s/cur", dir);
\r
121 + if (mkdir_parents (ctx, subdir, mode) != 0)
\r
124 + end = subdir + strlen (subdir);
\r
126 + /* Create 'new' directory. */
\r
127 + strcpy (end - 3, "new");
\r
128 + if (mkdir (subdir, mode) != 0 && errno != EEXIST)
\r
131 + /* Create 'tmp' directory. */
\r
132 + strcpy (end - 3, "tmp");
\r
133 + if (mkdir (subdir, mode) != 0 && errno != EEXIST)
\r
136 + talloc_free (subdir);
\r
140 static notmuch_bool_t
\r
141 safe_gethostname (char *hostname, size_t hostname_size)
\r
143 @@ -253,6 +317,7 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])
\r
144 const char **new_tags;
\r
145 size_t new_tags_length;
\r
146 const char *folder = NULL;
\r
147 + notmuch_bool_t create_folder = FALSE;
\r
148 tag_operation_t *tag_ops;
\r
149 int tag_ops_count = 0;
\r
151 @@ -262,6 +327,7 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])
\r
153 notmuch_opt_desc_t options[] = {
\r
154 { NOTMUCH_OPT_STRING, &folder, "folder", 0, 0 },
\r
155 + { NOTMUCH_OPT_BOOLEAN, &create_folder, "create-folder", 0, 0 },
\r
156 { NOTMUCH_OPT_END, 0, 0, 0, 0 }
\r
159 @@ -328,6 +394,11 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])
\r
162 maildir = talloc_asprintf (ctx, "%s/%s", db_path, folder);
\r
163 + if (create_folder && ! maildir_create (ctx, maildir)) {
\r
164 + fprintf (stderr, "Error: creating maildir %s: %s\n",
\r
165 + maildir, strerror (errno));
\r
169 maildir = talloc_asprintf (ctx, "%s", db_path);
\r