From: Mark Walters Date: Sun, 18 Nov 2012 17:24:46 +0000 (+0000) Subject: Re: [PATCH 16/18] insert: add --create-folder option X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=8eb9bcfefd0aa9f9ff6d91ac127cfefe819ca527;p=notmuch-archives.git Re: [PATCH 16/18] insert: add --create-folder option --- diff --git a/91/283f6fda5faeb817ebda2e463030d63d53cb80 b/91/283f6fda5faeb817ebda2e463030d63d53cb80 new file mode 100644 index 000000000..7b2ddd8d2 --- /dev/null +++ b/91/283f6fda5faeb817ebda2e463030d63d53cb80 @@ -0,0 +1,202 @@ +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 B5038431FB6 + for ; Sun, 18 Nov 2012 09:24:50 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -1.098 +X-Spam-Level: +X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5 + tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, + NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 Q+jWC5sKd53e for ; + Sun, 18 Nov 2012 09:24:50 -0800 (PST) +Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 0929D431FAF + for ; Sun, 18 Nov 2012 09:24:50 -0800 (PST) +Received: from smtp.qmul.ac.uk ([138.37.6.40]) + by mail2.qmul.ac.uk with esmtp (Exim 4.71) + (envelope-from ) + id 1Ta8bw-0002od-3D; Sun, 18 Nov 2012 17:24:48 +0000 +Received: from 93-97-24-31.zone5.bethere.co.uk ([93.97.24.31] helo=localhost) + by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) + (envelope-from ) + id 1Ta8bv-0003lN-O6; Sun, 18 Nov 2012 17:24:47 +0000 +From: Mark Walters +To: Peter Wang , notmuch@notmuchmail.org +Subject: Re: [PATCH 16/18] insert: add --create-folder option +In-Reply-To: <1343223767-9812-16-git-send-email-novalazy@gmail.com> +References: <1343223767-9812-1-git-send-email-novalazy@gmail.com> + <1343223767-9812-16-git-send-email-novalazy@gmail.com> +User-Agent: Notmuch/0.14+81~g9730584 (http://notmuchmail.org) Emacs/23.4.1 + (x86_64-pc-linux-gnu) +Date: Sun, 18 Nov 2012 17:24:46 +0000 +Message-ID: <87lidyq0wx.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Sender-Host-Address: 93.97.24.31 +X-QM-SPAM-Info: Sender has good ham record. :) +X-QM-Body-MD5: f571e8dfa76fd17203e32a90cd027b42 (of first 20000 bytes) +X-SpamAssassin-Score: -1.8 +X-SpamAssassin-SpamBar: - +X-SpamAssassin-Report: The QM spam filters have analysed this message to + determine if it is + spam. We require at least 5.0 points to mark a message as spam. + This message scored -1.8 points. + Summary of the scoring: + * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, + * medium trust + * [138.37.6.40 listed in list.dnswl.org] + * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail + provider * (markwalters1009[at]gmail.com) + * 0.5 AWL AWL: From: address is in the auto white-list +X-QM-Scan-Virus: ClamAV says the message is clean +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: Sun, 18 Nov 2012 17:24:50 -0000 + + +Hi + +On Wed, 25 Jul 2012, Peter Wang wrote: +> Support an option to create a new folder in the maildir. +> --- +> notmuch-insert.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ +> 1 files changed, 71 insertions(+), 0 deletions(-) +> +> diff --git a/notmuch-insert.c b/notmuch-insert.c +> index a69dfe6..380c520 100644 +> --- a/notmuch-insert.c +> +++ b/notmuch-insert.c +> @@ -48,6 +48,70 @@ check_folder_name (const char *folder) +> } +> } +> +> +static int +> +mkdir_parents (void *ctx, const char *path, int mode) +> +{ +> + struct stat st; +> + char *pathcopy; +> + char *start; +> + char *end; +> + int ret; +> + +> + /* First check the common case: directory already exists. */ +> + if (stat (path, &st) == 0) { +> + return (S_ISDIR (st.st_mode)) ? 0 : -1; +> + } +> + +> + pathcopy = talloc_strdup (ctx, path); +> + ret = 0; +> + +> + for (start = pathcopy; *start != '\0'; start = end + 1) { +> + end = strchr (start + 1, '/'); +> + if (!end) { +> + ret = mkdir (path, mode); +> + break; +> + } +> + *end = '\0'; +> + ret = mkdir (pathcopy, mode); +> + if (ret != 0 && errno != EEXIST) { +> + break; +> + } +> + *end = '/'; +> + } +I am a little confused by this: why is there a +1 in the start = end + 1 +line and in the end = strchr line? I believe it doesn't matter but it +makes me wonder if I am missing something. + +Best wishes + +Mark + + + +> + +> + talloc_free (pathcopy); +> + +> + return ret; +> +} +> + +> +static notmuch_bool_t +> +maildir_create (void *ctx, const char *dir) +> +{ +> + const int mode = 0755; +> + char *subdir; +> + char *end; +> + +> + /* Create 'cur' directory, including parent directories. */ +> + subdir = talloc_asprintf (ctx, "%s/cur", dir); +> + if (mkdir_parents (ctx, subdir, mode) != 0) +> + return FALSE; +> + +> + end = subdir + strlen (subdir); +> + +> + /* Create 'new' directory. */ +> + strcpy (end - 3, "new"); +> + if (mkdir (subdir, mode) != 0 && errno != EEXIST) +> + return FALSE; +> + +> + /* Create 'tmp' directory. */ +> + strcpy (end - 3, "tmp"); +> + if (mkdir (subdir, mode) != 0 && errno != EEXIST) +> + return FALSE; +> + +> + talloc_free (subdir); +> + return TRUE; +> +} +> + +> static notmuch_bool_t +> safe_gethostname (char *hostname, size_t hostname_size) +> { +> @@ -253,6 +317,7 @@ notmuch_insert_command (void *ctx, int argc, char *argv[]) +> const char **new_tags; +> size_t new_tags_length; +> const char *folder = NULL; +> + notmuch_bool_t create_folder = FALSE; +> tag_operation_t *tag_ops; +> int tag_ops_count = 0; +> char *maildir; +> @@ -262,6 +327,7 @@ notmuch_insert_command (void *ctx, int argc, char *argv[]) +> +> notmuch_opt_desc_t options[] = { +> { NOTMUCH_OPT_STRING, &folder, "folder", 0, 0 }, +> + { NOTMUCH_OPT_BOOLEAN, &create_folder, "create-folder", 0, 0 }, +> { NOTMUCH_OPT_END, 0, 0, 0, 0 } +> }; +> +> @@ -328,6 +394,11 @@ notmuch_insert_command (void *ctx, int argc, char *argv[]) +> return 1; +> } +> maildir = talloc_asprintf (ctx, "%s/%s", db_path, folder); +> + if (create_folder && ! maildir_create (ctx, maildir)) { +> + fprintf (stderr, "Error: creating maildir %s: %s\n", +> + maildir, strerror (errno)); +> + return 1; +> + } +> } else { +> maildir = talloc_asprintf (ctx, "%s", db_path); +> } +> -- +> 1.7.4.4 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch