Hello,

I have patched isync-1.3.0 so that mbsync can use the IMAP command LSUB
(list subscribed folders) instead of LIST (list all folders), for IMAP
stores that have the boolean option "UseLSUBforLIST" set to true.

Originally, this is meant as a workaround for a weird bug in my
institution's Zimbra IMAP server: for a few users, including myself,
the LIST command stopped working and just returned "NO LIST failed"
after an update.  Until it gets sorted out, this patch allows me to
keep using mbsync, by subscribing to all my IMAP folders.

I don't know if this function will interest many people; I don't really
see a use case for it other than this kind of bugware.  But you never
know, so here's the patch.

                                        Best regards,
                                        Cedric Ware.
diff -ur isync-1.3.0.orig/src/drv_imap.c isync-1.3.0/src/drv_imap.c
--- isync-1.3.0.orig/src/drv_imap.c	2017-10-01 10:42:35.000000000 +0200
+++ isync-1.3.0/src/drv_imap.c	2019-03-30 16:24:55.929748260 +0100
@@ -66,6 +66,7 @@
 	imap_server_conf_t *server;
 	char delimiter;
 	char use_namespace;
+	char use_lsub;
 } imap_store_conf_t;
 
 typedef struct {
@@ -1391,7 +1392,8 @@
 				error( "Error from IMAP server: %s\n", cmd );
 			} else if (!strcmp( "CAPABILITY", arg )) {
 				parse_capability( ctx, cmd );
-			} else if (!strcmp( "LIST", arg )) {
+			} else if ((!strcmp( "LIST", arg )) ||
+				   (!strcmp( "LSUB", arg ))) {
 				resp = parse_list( ctx, cmd, parse_list_rsp );
 				goto listret;
 			} else if (!strcmp( "NAMESPACE", arg )) {
@@ -2966,6 +2968,7 @@
                  void (*cb)( int sts, string_list_t *boxes, void *aux ), void *aux )
 {
 	imap_store_t *ctx = (imap_store_t *)gctx;
+	imap_store_conf_t *cfg = (imap_store_conf_t *)ctx->gen.conf;
 	INIT_REFCOUNTED_STATE(imap_list_store_state_t, sts, cb, aux)
 
 	// ctx->prefix may be empty, "INBOX.", or something else.
@@ -2989,14 +2992,15 @@
 		if (pfx_is_empty)
 			ctx->listed |= LIST_INBOX;
 		imap_exec( ctx, imap_refcounted_new_cmd( &sts->gen ), imap_list_store_p2,
-		           "LIST \"\" \"%\\s*\"", ctx->prefix );
+		           (cfg->use_lsub)? "LSUB \"\" \"%\\s*\"" : "LIST \"\" \"%\\s*\"",
+			   ctx->prefix );
 	}
 	if (((flags & LIST_INBOX) || pfx_is_inbox) && !pfx_is_empty && !(ctx->listed & LIST_INBOX)) {
 		ctx->listed |= LIST_INBOX;
 		if (pfx_is_inbox)
 			ctx->listed |= LIST_PATH;
 		imap_exec( ctx, imap_refcounted_new_cmd( &sts->gen ), imap_list_store_p2,
-		           "LIST \"\" INBOX*" );
+		           (cfg->use_lsub)? "LSUB \"\" INBOX*" : "LIST \"\" INBOX*" );
 	}
 	imap_list_store_p3( ctx, sts );
 }
@@ -3092,6 +3096,7 @@
 		store->gen.driver = &imap_driver;
 		store->gen.name = nfstrdup( cfg->val );
 		store->use_namespace = 1;
+		store->use_lsub = 0;
 		*storep = &store->gen;
 		memset( &sserver, 0, sizeof(sserver) );
 		server = &sserver;
@@ -3248,6 +3253,8 @@
 				store->server = srv;
 			} else if (!strcasecmp( "UseNamespace", cfg->cmd ))
 				store->use_namespace = parse_bool( cfg );
+			else if (!strcasecmp( "UseLSUBforLIST", cfg->cmd ))
+				store->use_lsub = parse_bool( cfg );
 			else if (!strcasecmp( "Path", cfg->cmd ))
 				store->gen.path = nfstrdup( cfg->val );
 			else if (!strcasecmp( "PathDelimiter", cfg->cmd )) {
_______________________________________________
isync-devel mailing list
isync-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/isync-devel

Reply via email to