From fbc432aace071b774ebfc62be5d17f3b070fc22e Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 28 May 2019 17:27:09 +0200 Subject: [PATCH] fix parsing of NIL hierarchy delimiters in IMAP LIST responses a server which does not support hierarchical mailboxes (e.g., seznam.cz as of oct 2018) can legitimately send NIL (rather than an empty string). --- src/drv_imap.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/drv_imap.c b/src/drv_imap.c index 361d01c..0f72c1a 100644 --- a/src/drv_imap.c +++ b/src/drv_imap.c @@ -1197,17 +1197,16 @@ parse_response_code( imap_store_t *ctx, imap_cmd_t *cmd, char *s ) return RESP_OK; } +static int parse_list_rsp_p1( imap_store_t *, list_t *, char * ); static int parse_list_rsp_p2( imap_store_t *, list_t *, char * ); static int parse_list_rsp( imap_store_t *ctx, list_t *list, char *cmd ) { - char *arg; list_t *lp; if (!is_list( list )) { free_list( list ); - bad_list: error( "IMAP error: malformed LIST response\n" ); return LIST_BAD; } @@ -1217,10 +1216,19 @@ parse_list_rsp( imap_store_t *ctx, list_t *list, char *cmd ) return LIST_OK; } free_list( list ); - if (!(arg = next_arg( &cmd ))) - goto bad_list; - if (!ctx->delimiter[0]) - ctx->delimiter[0] = arg[0]; + return parse_list( ctx, cmd, parse_list_rsp_p1 ); +} + +static int +parse_list_rsp_p1( imap_store_t *ctx, list_t *list, char *cmd ATTR_UNUSED ) +{ + if (!is_opt_atom( list )) { + error( "IMAP error: malformed LIST response\n" ); + free_list( list ); + return LIST_BAD; + } + if (!ctx->delimiter[0] && is_atom( list )) + ctx->delimiter[0] = list->val[0]; return parse_list( ctx, cmd, parse_list_rsp_p2 ); }