From: Alex Riesen Date: Mon, 21 May 2007 23:05:24 GMT Subject: [PATCH] Allow user to specify mailbox format for mailsplit Message-ID: <20070521230524.GC10890@steel.home> In-Reply-To: <20070521182052.GB4696@ferdyx.org> If the argument ends with a slash - assume it is a Maildir and try to create it. Otherwise - it is an mbox. Signed-off-by: Alex Riesen --- Documentation/git-mailsplit.txt | 4 +++- builtin-mailsplit.c | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletions(-) diff --git a/Documentation/git-mailsplit.txt b/Documentation/git-mailsplit.txt index abb0903..2c58e09 100644 --- a/Documentation/git-mailsplit.txt +++ b/Documentation/git-mailsplit.txt @@ -25,7 +25,9 @@ OPTIONS :: Root of the Maildir to split. This directory should contain the cur, tmp - and new subdirectories. + and new subdirectories. If the argument ends with a slash '/' + the directory and new, cur and tmp subdirectories will be + created automatically. :: Directory in which to place the individual messages. diff --git a/builtin-mailsplit.c b/builtin-mailsplit.c index 454f943..370f7fa 100644 --- a/builtin-mailsplit.c +++ b/builtin-mailsplit.c @@ -253,6 +253,7 @@ int cmd_mailsplit(int argc, const char **argv, const char *prefix) const char *arg = *argp++; struct stat argstat; int ret = 0; + size_t arglen = strlen(arg); if (arg[0] == '-' && arg[1] == 0) { ret = split_mbox(arg, dir, allow_bare, nr_prec, nr); @@ -264,6 +265,15 @@ int cmd_mailsplit(int argc, const char **argv, const char *prefix) continue; } + if (arglen && arg[arglen-1] == '/') { + char *dir = malloc(arglen + 5); + memcpy(dir, arg, arglen); + mkdir(arg, 0777); + mkdir(strcpy(dir + arglen, "new"), 0777); + mkdir(strcpy(dir + arglen, "cur"), 0777); + mkdir(strcpy(dir + arglen, "tmp"), 0777); + free(dir); + } if (stat(arg, &argstat) == -1) { error("cannot stat %s (%s)", arg, strerror(errno)); return 1; -- 1.5.2.rc3.112.gc1e43