Prechádzať zdrojové kódy

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.
Oswald Buddenhagen 10 rokov pred
rodič
commit
98bd2b115d
1 zmenil súbory, kde vykonal 18 pridanie a 11 odobranie
  1. 18 11
      src/drv_maildir.c

+ 18 - 11
src/drv_maildir.c

@@ -228,10 +228,12 @@ maildir_invoke_bad_callback( store_t *ctx )
 	ctx->bad_callback( ctx->bad_callback_aux );
 	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
 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 )
                       char *path, int pathLen, char *name, int nameLen )
 {
 {
 	DIR *dir;
 	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 );
 		pl = pathLen + nfsnprintf( path + pathLen, _POSIX_PATH_MAX - pathLen, "%s", ent );
 		if (inbox && equals( path, pl, inbox, inboxLen )) {
 		if (inbox && equals( path, pl, inbox, inboxLen )) {
 			/* Inbox nested into Path. List now if it won't be listed separately anyway. */
 			/* 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 );
 				closedir( dir );
 				return -1;
 				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 );
 			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 );
 				closedir( dir );
 				return -1;
 				return -1;
 			}
 			}
@@ -291,26 +299,25 @@ maildir_list_recurse( store_t *gctx, int isBox, int flags, const char *inbox, in
 }
 }
 
 
 static int
 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];
 	char path[_POSIX_PATH_MAX], name[_POSIX_PATH_MAX];
 
 
 	return maildir_list_recurse(
 	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 ),
 	        path, nfsnprintf( path, _POSIX_PATH_MAX, "%s", ((maildir_store_conf_t *)gctx->conf)->inbox ),
 	        name, nfsnprintf( name, _POSIX_PATH_MAX, "INBOX" ) );
 	        name, nfsnprintf( name, _POSIX_PATH_MAX, "INBOX" ) );
 }
 }
 
 
 static int
 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];
 	char path[_POSIX_PATH_MAX], name[_POSIX_PATH_MAX];
 
 
 	if (maildir_validate_path( gctx->conf ) < 0)
 	if (maildir_validate_path( gctx->conf ) < 0)
 		return -1;
 		return -1;
 	return maildir_list_recurse(
 	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 ),
 	        path, nfsnprintf( path, _POSIX_PATH_MAX, "%s", gctx->conf->path ),
 	        name, 0 );
 	        name, 0 );
 }
 }
@@ -319,8 +326,8 @@ static void
 maildir_list_store( store_t *gctx, int flags,
 maildir_list_store( store_t *gctx, int flags,
                     void (*cb)( int sts, void *aux ), void *aux )
                     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 );
 		maildir_invoke_bad_callback( gctx );
 		cb( DRV_CANCELED, aux );
 		cb( DRV_CANCELED, aux );
 	} else {
 	} else {