isync

mailbox synchronization program
git clone https://git.code.sf.net/p/isync/isync
Log | Files | Refs | README | LICENSE

commit 98bd2b115d465440d1f24e1b91269a6a334864f2
parent 2d4ce72a8b164f04c059ca4a446e340f2919f086
Author: Oswald Buddenhagen <ossi@users.sf.net>
Date:   Sat, 18 Apr 2015 11:46:36 +0200

make it possible to nest maildir Path under Inbox

simply make the code symmetrical to the inverse case.

note that the result will be sort of awkward, as the folders under Path
(and thus the subfolders of Inbox) don't start with a dot, while the
subfolders of these folders do. this needs to be addressed separately.

Diffstat:
Msrc/drv_maildir.c | 29++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/src/drv_maildir.c b/src/drv_maildir.c @@ -228,10 +228,12 @@ maildir_invoke_bad_callback( store_t *ctx ) ctx->bad_callback( ctx->bad_callback_aux ); } -static int maildir_list_inbox( store_t *gctx, int flags ); +static int maildir_list_inbox( store_t *gctx, int flags, const char *basePath ); +static int maildir_list_path( store_t *gctx, int flags, const char *inbox ); static int -maildir_list_recurse( store_t *gctx, int isBox, int flags, const char *inbox, int inboxLen, +maildir_list_recurse( store_t *gctx, int isBox, int flags, + const char *inbox, int inboxLen, const char *basePath, int basePathLen, char *path, int pathLen, char *name, int nameLen ) { DIR *dir; @@ -259,7 +261,13 @@ maildir_list_recurse( store_t *gctx, int isBox, int flags, const char *inbox, in pl = pathLen + nfsnprintf( path + pathLen, _POSIX_PATH_MAX - pathLen, "%s", ent ); if (inbox && equals( path, pl, inbox, inboxLen )) { /* Inbox nested into Path. List now if it won't be listed separately anyway. */ - if (!(flags & LIST_INBOX) && maildir_list_inbox( gctx, flags ) < 0) { + if (!(flags & LIST_INBOX) && maildir_list_inbox( gctx, flags, 0 ) < 0) { + closedir( dir ); + return -1; + } + } else if (basePath && equals( path, pl, basePath, basePathLen )) { + /* Path nested into Inbox. List now if it won't be listed separately anyway. */ + if (!(flags & LIST_PATH) && maildir_list_path( gctx, flags, 0 ) < 0) { closedir( dir ); return -1; } @@ -280,7 +288,7 @@ maildir_list_recurse( store_t *gctx, int isBox, int flags, const char *inbox, in } } nl = nameLen + nfsnprintf( name + nameLen, _POSIX_PATH_MAX - nameLen, "%s", ent ); - if (maildir_list_recurse( gctx, 1, flags, inbox, inboxLen, path, pl, name, nl ) < 0) { + if (maildir_list_recurse( gctx, 1, flags, inbox, inboxLen, basePath, basePathLen, path, pl, name, nl ) < 0) { closedir( dir ); return -1; } @@ -291,26 +299,25 @@ maildir_list_recurse( store_t *gctx, int isBox, int flags, const char *inbox, in } static int -maildir_list_inbox( store_t *gctx, int flags ) +maildir_list_inbox( store_t *gctx, int flags, const char *basePath ) { char path[_POSIX_PATH_MAX], name[_POSIX_PATH_MAX]; return maildir_list_recurse( - gctx, 2, flags, 0, 0, + gctx, 2, flags, 0, 0, basePath, basePath ? strlen( basePath ) - 1 : 0, path, nfsnprintf( path, _POSIX_PATH_MAX, "%s", ((maildir_store_conf_t *)gctx->conf)->inbox ), name, nfsnprintf( name, _POSIX_PATH_MAX, "INBOX" ) ); } static int -maildir_list_path( store_t *gctx, int flags ) +maildir_list_path( store_t *gctx, int flags, const char *inbox ) { - const char *inbox = ((maildir_store_conf_t *)gctx->conf)->inbox; char path[_POSIX_PATH_MAX], name[_POSIX_PATH_MAX]; if (maildir_validate_path( gctx->conf ) < 0) return -1; return maildir_list_recurse( - gctx, 0, flags, inbox, strlen( inbox ), + gctx, 0, flags, inbox, inbox ? strlen( inbox ) : 0, 0, 0, path, nfsnprintf( path, _POSIX_PATH_MAX, "%s", gctx->conf->path ), name, 0 ); } @@ -319,8 +326,8 @@ static void maildir_list_store( store_t *gctx, int flags, void (*cb)( int sts, void *aux ), void *aux ) { - if (((flags & LIST_PATH) && maildir_list_path( gctx, flags ) < 0) || - ((flags & LIST_INBOX) && maildir_list_inbox( gctx, flags ) < 0)) { + if (((flags & LIST_PATH) && maildir_list_path( gctx, flags, ((maildir_store_conf_t *)gctx->conf)->inbox ) < 0) || + ((flags & LIST_INBOX) && maildir_list_inbox( gctx, flags, gctx->conf->path ) < 0)) { maildir_invoke_bad_callback( gctx ); cb( DRV_CANCELED, aux ); } else {