unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jani Nikula <jani@nikula.org>
To: Peter Wang <novalazy@gmail.com>, notmuch@notmuchmail.org
Subject: Re: [PATCH v5 07/12] insert: add --folder option
Date: Sun, 28 Apr 2013 00:32:47 +0300	[thread overview]
Message-ID: <87zjwjpslc.fsf@nikula.org> (raw)
In-Reply-To: <1364942517-6982-8-git-send-email-novalazy@gmail.com>

On Wed, 03 Apr 2013, Peter Wang <novalazy@gmail.com> 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

  reply	other threads:[~2013-04-27 21:32 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-02 22:41 [PATCH v5 00/12] insert command Peter Wang
2013-04-02 22:41 ` [PATCH v5 01/12] tag-util: move out 'tag' command-line checks Peter Wang
2013-04-02 22:41 ` [PATCH v5 02/12] tag-util: do not reset list in parse_tag_command_line Peter Wang
2013-04-02 22:41 ` [PATCH v5 03/12] cli: add insert command Peter Wang
2013-04-27 21:24   ` Jani Nikula
2013-05-28 13:58     ` Peter Wang
2013-04-02 22:41 ` [PATCH v5 04/12] man: document 'insert' command Peter Wang
2013-04-27 21:27   ` Jani Nikula
2013-04-02 22:41 ` [PATCH v5 05/12] man: reference notmuch-insert.1 Peter Wang
2013-04-02 22:41 ` [PATCH v5 06/12] test: add tests for insert Peter Wang
2013-04-02 22:41 ` [PATCH v5 07/12] insert: add --folder option Peter Wang
2013-04-27 21:32   ` Jani Nikula [this message]
2013-04-28  2:00     ` Peter Wang
2013-04-02 22:41 ` [PATCH v5 08/12] man: document insert " Peter Wang
2013-04-02 22:41 ` [PATCH v5 09/12] test: test " Peter Wang
2013-04-02 22:41 ` [PATCH v5 10/12] insert: add --create-folder option Peter Wang
2013-04-02 22:41 ` [PATCH v5 11/12] man: document insert --create-folder Peter Wang
2013-04-02 22:41 ` [PATCH v5 12/12] test: test insert --create-folder option Peter Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zjwjpslc.fsf@nikula.org \
    --to=jani@nikula.org \
    --cc=notmuch@notmuchmail.org \
    --cc=novalazy@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).