|
@@ -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 {
|