From: Timo Sirainen Date: Sat, 2 Nov 2013 18:09:28 +0000 (+0200) Subject: lib-imap: Added IMAP_PARSE_FLAG_STOP_AT_LIST for stopping after '(' X-Git-Tag: 2.2.7~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d0c9d4332d437b32fa6d003e4b3360b51b60e255;p=thirdparty%2Fdovecot%2Fcore.git lib-imap: Added IMAP_PARSE_FLAG_STOP_AT_LIST for stopping after '(' --- diff --git a/src/lib-imap/imap-parser.c b/src/lib-imap/imap-parser.c index cd43ae00b9..19289abf5b 100644 --- a/src/lib-imap/imap-parser.c +++ b/src/lib-imap/imap-parser.c @@ -609,6 +609,10 @@ static int imap_parser_read_arg(struct imap_parser *parser) break; case '(': imap_parser_open_list(parser); + if ((parser->flags & IMAP_PARSE_FLAG_STOP_AT_LIST) != 0) { + i_stream_skip(parser->input, 1); + return FALSE; + } break; case ')': if (!imap_parser_close_list(parser)) @@ -690,7 +694,8 @@ static int imap_parser_read_arg(struct imap_parser *parser) /* ARG_PARSE_NONE checks that last argument isn't only partially parsed. */ #define IS_UNFINISHED(parser) \ ((parser)->cur_type != ARG_PARSE_NONE || \ - (parser)->cur_list != &parser->root_list) + ((parser)->cur_list != &parser->root_list && \ + ((parser)->flags & IMAP_PARSE_FLAG_STOP_AT_LIST) == 0)) static int finish_line(struct imap_parser *parser, unsigned int count, const struct imap_arg **args_r) @@ -703,7 +708,8 @@ static int finish_line(struct imap_parser *parser, unsigned int count, parser->cur_pos = 0; parser->cur_resp_text = FALSE; - if (parser->list_arg != NULL && !parser->literal_size_return) { + if (parser->list_arg != NULL && !parser->literal_size_return && + (parser->flags & IMAP_PARSE_FLAG_STOP_AT_LIST) == 0) { parser->error = "Missing ')'"; *args_r = NULL; return -1; diff --git a/src/lib-imap/imap-parser.h b/src/lib-imap/imap-parser.h index 623d3def8b..d0bc9710da 100644 --- a/src/lib-imap/imap-parser.h +++ b/src/lib-imap/imap-parser.h @@ -24,7 +24,9 @@ enum imap_parser_flags { /* We're parsing IMAP server replies. Parse the "text" after OK/NO/BAD/BYE replies as a single atom. We assume that the initial "*" or tag was already skipped over. */ - IMAP_PARSE_FLAG_SERVER_TEXT = 0x80 + IMAP_PARSE_FLAG_SERVER_TEXT = 0x80, + /* Parse until '(' and return it as an empty list */ + IMAP_PARSE_FLAG_STOP_AT_LIST = 0x100 }; struct imap_parser;