commit 5fcf7594f23183d359226cff96c34f0d7773b943
Author: Oswald Buddenhagen <o...@users.sf.net>
Date:   Mon Nov 11 13:41:32 2019 +0100

    fully decompose NAMESPACE response early on
    
    that way the code becomes clearer, and we don't keep useless nodes in
    memory.

 src/drv_imap.c | 65 +++++++++++++++++++++++---------------------------
 1 file changed, 30 insertions(+), 35 deletions(-)

diff --git a/src/drv_imap.c b/src/drv_imap.c
index 36226b2..e76b091 100644
--- a/src/drv_imap.c
+++ b/src/drv_imap.c
@@ -106,7 +106,7 @@ struct imap_store {
        enum { TrashUnknown, TrashChecking, TrashKnown } trashnc;
        uint got_namespace:1;
        char delimiter[2]; /* hierarchy delimiter */
-       list_t *ns_personal; /* NAMESPACE info */
+       char *ns_prefix, ns_delimiter; /* NAMESPACE info */
        string_list_t *boxes; // _list results
        char listed; // was _list already run with these flags?
        // note that the message counts do _not_ reflect stats from msgs,
@@ -897,34 +897,37 @@ static int parse_namespace_rsp_p2( imap_store_t *, list_t 
*, char * );
 static int parse_namespace_rsp_p3( imap_store_t *, list_t *, char * );
 
 static int
-parse_namespace_check( list_t *list )
+parse_namespace_rsp( imap_store_t *ctx, list_t *list, char *s )
 {
-       if (!list)
-               goto bad;
-       if (list->val == NIL)
-               return 0;
-       if (list->val != LIST)
-               goto bad;
-       for (list = list->child; list; list = list->next) {
+       // We use only the 1st personal namespace. Making this configurable
+       // would not add value over just specifying Path.
+
+       if (!list) {
+         bad:
+               error( "IMAP error: malformed NAMESPACE response\n" );
+               free_list( list );
+               return LIST_BAD;
+       }
+       if (list->val != NIL) {
                if (list->val != LIST)
                        goto bad;
-               if (!is_atom( list->child ))
+               list_t *nsp_1st = list->child;
+               if (nsp_1st->val != LIST)
                        goto bad;
-               if (!is_opt_atom( list->child->next ))
+               list_t *nsp_1st_ns = nsp_1st->child;
+               if (!is_atom( nsp_1st_ns ))
                        goto bad;
-               /* Namespace response extensions may follow here; we don't 
care. */
+               ctx->ns_prefix = nsp_1st_ns->val;
+               nsp_1st_ns->val = NULL;
+               list_t *nsp_1st_dl = nsp_1st_ns->next;
+               if (!is_opt_atom( nsp_1st_dl ))
+                       goto bad;
+               if (is_atom( nsp_1st_dl ))
+                       ctx->ns_delimiter = nsp_1st_dl->val[0];
+               // Namespace response extensions may follow here; we don't care.
        }
-       return 0;
-  bad:
-       error( "IMAP error: malformed NAMESPACE response\n" );
-       return -1;
-}
+       free_list( list );
 
-static int
-parse_namespace_rsp( imap_store_t *ctx, list_t *list, char *s )
-{
-       if (parse_namespace_check( (ctx->ns_personal = list) ))
-               return LIST_BAD;
        return parse_list( ctx, s, parse_namespace_rsp_p2 );
 }
 
@@ -1579,7 +1582,7 @@ imap_cancel_store( store_t *gctx )
        socket_close( &ctx->conn );
        cancel_sent_imap_cmds( ctx );
        cancel_pending_imap_cmds( ctx );
-       free_list( ctx->ns_personal );
+       free( ctx->ns_prefix );
        free_string_list( ctx->auth_mechs );
        imap_cleanup_store( ctx );
        imap_deref( ctx );
@@ -2303,19 +2306,11 @@ static void
 imap_open_store_namespace2( imap_store_t *ctx )
 {
        imap_store_conf_t *cfg = (imap_store_conf_t *)ctx->gen.conf;
-       list_t *nsp, *nsp_1st;
 
-       /* XXX for now assume 1st personal namespace */
-       if (is_list( (nsp = ctx->ns_personal) ) &&
-           is_list( (nsp_1st = nsp->child) ))
-       {
-               list_t *nsp_1st_ns = nsp_1st->child;
-               list_t *nsp_1st_dl = nsp_1st_ns->next;
-               if (!ctx->prefix && cfg->use_namespace)
-                       ctx->prefix = nsp_1st_ns->val;
-               if (!ctx->delimiter[0] && is_atom( nsp_1st_dl ))
-                       ctx->delimiter[0] = nsp_1st_dl->val[0];
-       }
+       if (!ctx->prefix && cfg->use_namespace)
+               ctx->prefix = ctx->ns_prefix;
+       if (!ctx->delimiter[0])
+               ctx->delimiter[0] = ctx->ns_delimiter;
        imap_open_store_finalize( ctx );
 }
 


_______________________________________________
isync-devel mailing list
isync-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/isync-devel

Reply via email to