commit 98bd2b115d465440d1f24e1b91269a6a334864f2
Author: Oswald Buddenhagen <o...@users.sf.net>
Date:   Sat Apr 18 11:46:36 2015 +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.

 src/drv_maildir.c |   29 ++++++++++++++++++-----------
 1 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/src/drv_maildir.c b/src/drv_maildir.c
index a54c17b..b96950c 100644
--- 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 {

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
isync-devel mailing list
isync-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/isync-devel

Reply via email to