unbreak handling of 'INBOX.' NAMESPACE again

INBOX matching must not prevent prefix (namespace) stripping, as INBOX
may be the namespace.

amends 04fc586e7.

REFMAIL: 186391612191752@vla1-ea7e194e8506.qloud-c.yandex.net
This commit is contained in:
Oswald Buddenhagen 2021-02-03 14:25:44 +01:00
parent c97e650c24
commit c8b73acad2

View File

@ -1268,13 +1268,14 @@ parse_list_rsp_p2( imap_store_t *ctx, list_t *list, char *cmd ATTR_UNUSED )
} }
arg = list->val; arg = list->val;
argl = list->len; argl = list->len;
if ((l = strlen( ctx->prefix ))) {
if (!starts_with( arg, argl, ctx->prefix, l )) {
if (is_inbox( ctx, arg, argl )) { if (is_inbox( ctx, arg, argl )) {
// The server might be weird and have a non-uppercase INBOX. It // INBOX and its subfolders bypass the namespace.
// may legitimately do so, but we need the canonical spelling. goto inbox;
memcpy( arg, "INBOX", 5 ); }
} else if ((l = strlen( ctx->prefix ))) {
if (!starts_with( arg, argl, ctx->prefix, l ))
goto skip; goto skip;
}
arg += l; arg += l;
argl -= l; argl -= l;
// A folder named "INBOX" would be indistinguishable from the // A folder named "INBOX" would be indistinguishable from the
@ -1286,6 +1287,14 @@ parse_list_rsp_p2( imap_store_t *ctx, list_t *list, char *cmd ATTR_UNUSED )
warn( "IMAP warning: ignoring INBOX in %s\n", ctx->prefix ); warn( "IMAP warning: ignoring INBOX in %s\n", ctx->prefix );
goto skip; goto skip;
} }
} else if (is_inbox( ctx, arg, argl )) {
inbox:
// The server might be weird and have a non-uppercase INBOX. It
// may legitimately do so, but we need the canonical spelling.
// Note that we do that only after prefix matching, under the
// assumption that the NAMESPACE (or Path) matches the
// capitalization of LIST.
memcpy( arg, "INBOX", 5 );
} }
if (argl >= 5 && !memcmp( arg + argl - 5, ".lock", 5 )) /* workaround broken servers */ if (argl >= 5 && !memcmp( arg + argl - 5, ".lock", 5 )) /* workaround broken servers */
goto skip; goto skip;