From 016cd3d52ebb66867ee89024272300c8df8df6b5 Mon Sep 17 00:00:00 2001
From: Guillem Jover <guillem@hadrons.org>
Date: Sun, 6 Sep 2015 21:47:36 +0200
Subject: [PATCH 2/2] maildir: Fix Maildir++ support

---
 src/drv_maildir.c | 13 ++++++-------
 src/mbsync.1      |  2 +-
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/drv_maildir.c b/src/drv_maildir.c
index 74fdd81..a3a37fd 100644
--- a/src/drv_maildir.c
+++ b/src/drv_maildir.c
@@ -122,7 +122,7 @@ static char *
 maildir_join_path( maildir_store_conf_t *conf, const char *prefix, const char *box )
 {
 	char *out, *p;
-	int pl, bl, n, sub = 0;
+	int pl, bl, n;
 	char c;
 
 	info(" maildir join source = '%s'\n", box);
@@ -141,9 +141,11 @@ maildir_join_path( maildir_store_conf_t *conf, const char *prefix, const char *b
 			       conf->gen.name, box );
 			return 0;
 		}
-	out = nfmalloc( pl + bl + n + 1 );
+	out = nfmalloc( pl + bl + n + 2 );
 	memcpy( out, prefix, pl );
 	p = out + pl;
+	if (conf->sub_style == SUB_MAILDIRPP)
+		*p++ = '.';
 	while ((c = *box++)) {
 		if (c == '/') {
 			switch (conf->sub_style) {
@@ -151,10 +153,6 @@ maildir_join_path( maildir_store_conf_t *conf, const char *prefix, const char *b
 				*p++ = c;
 				break;
 			case SUB_MAILDIRPP:
-				if (!sub) {
-					sub = 1;
-					*p++ = c;
-				}
 				*p++ = '.';
 				break;
 			case SUB_LEGACY:
@@ -391,11 +389,12 @@ static int
 maildir_list_path( store_t *gctx, int flags, const char *inbox )
 {
 	char path[_POSIX_PATH_MAX], name[_POSIX_PATH_MAX];
+	int isBox = ((maildir_store_conf_t *)gctx->conf)->sub_style == SUB_MAILDIRPP;
 
 	if (maildir_ensure_path( (maildir_store_conf_t *)gctx->conf ) < 0)
 		return -1;
 	return maildir_list_recurse(
-	        gctx, 0, flags, inbox, inbox ? strlen( inbox ) : 0, 0, 0,
+	        gctx, isBox, flags, inbox, inbox ? strlen( inbox ) : 0, 0, 0,
 	        path, nfsnprintf( path, _POSIX_PATH_MAX, "%s", gctx->conf->path ),
 	        name, 0 );
 }
diff --git a/src/mbsync.1 b/src/mbsync.1
index daa8d41..72adc64 100644
--- a/src/mbsync.1
+++ b/src/mbsync.1
@@ -267,7 +267,7 @@ the styles will yield the following on-disk paths:
 \fBVerbatim\fR - \fItop/sub/subsub\fR
 (this is the style you probably want to use)
 .br
-\fBMaildir++\fR - \fItop/.sub.subsub\fR
+\fBMaildir++\fR - \fI.top.sub.subsub\fR
 (this style is compatible with Courier and Dovecot - but note that
 the mailbox metadata format is \fInot\fR compatible)
 .br
-- 
2.5.1

