Mercurial > dovecot > core-2.2
changeset 21618:9a06f17cf733
lib-imap: imap-bodystructure: Allow alternative syntax and omitted optional elements in parser input.
This makes the parser accept any RFC-compliant BODYSTRUCTURE syntax, instead of only what Dovecot itself produces.
This way the parser could reliably be used in the lib-imap-client if ever needed.
author | Stephan Bosch <stephan.bosch@dovecot.fi> |
---|---|
date | Mon, 09 Jan 2017 02:03:25 +0100 |
parents | 6d5ed8b735b0 |
children | ff9f4f603a16 |
files | src/lib-imap/imap-bodystructure.c |
diffstat | 1 files changed, 23 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-imap/imap-bodystructure.c Mon Jan 09 16:29:26 2017 +0100 +++ b/src/lib-imap/imap-bodystructure.c Mon Jan 09 02:03:25 2017 +0100 @@ -607,13 +607,19 @@ *value_r = NULL; return 0; } - if (!imap_arg_get_list_full(arg, &list_args, &list_count)) - return -1; - if ((list_count % divisible) != 0) - return -1; - - if (imap_write_nstring_list(list_args, tmpstr) < 0) - return -1; + if (arg->type == IMAP_ARG_STRING) { + if (divisible > 1) + return -1; + str_truncate(tmpstr, 0); + str_append_nstring(tmpstr, arg); + } else { + if (!imap_arg_get_list_full(arg, &list_args, &list_count)) + return -1; + if ((list_count % divisible) != 0) + return -1; + if (imap_write_nstring_list(list_args, tmpstr) < 0) + return -1; + } *value_r = p_strdup(pool, str_c(tmpstr)); return 0; } @@ -646,6 +652,8 @@ { const struct imap_arg *list_args; + if (args->type == IMAP_ARG_EOL) + return 0; if (args->type == IMAP_ARG_NIL) args++; else if (!imap_arg_get_list(args, &list_args)) { @@ -664,11 +672,15 @@ } args++; } + if (args->type == IMAP_ARG_EOL) + return 0; if (imap_write_params(args++, pool, tmpstr, 1, &data->content_language) < 0) { *error_r = "Invalid content-language"; return -1; } + if (args->type == IMAP_ARG_EOL) + return 0; if (!get_nstring(args++, pool, tmpstr, &data->content_location)) { *error_r = "Invalid content-location"; return -1; @@ -724,6 +736,8 @@ *error_r = "Invalid multipart content-type"; return -1; } + if (args->type == IMAP_ARG_EOL) + return 0; if (imap_write_params(args++, pool, tmpstr, 2, &data->content_type_params) < 0) { *error_r = "Invalid content params"; @@ -838,6 +852,8 @@ i_assert(part->children == NULL); } + if (args->type == IMAP_ARG_EOL) + return 0; if (!get_nstring(args++, pool, tmpstr, &data->content_md5)) { *error_r = "Invalid content-md5"; return -1;