Mercurial > dovecot > core-2.2
changeset 21639:47432a7ba9d1
lib-imap: imap-envelope: Added function for parsing ENVELOPE from string.
author | Stephan Bosch <stephan.bosch@dovecot.fi> |
---|---|
date | Thu, 29 Dec 2016 14:02:05 +0100 |
parents | c2e9f137a496 |
children | 16358228dd24 |
files | src/lib-imap/imap-envelope.c src/lib-imap/imap-envelope.h |
diffstat | 2 files changed, 46 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-imap/imap-envelope.c Wed Oct 26 23:44:47 2016 +0200 +++ b/src/lib-imap/imap-envelope.c Thu Dec 29 14:02:05 2016 +0100 @@ -214,3 +214,45 @@ *envlp_r = envlp; return TRUE; } + +bool imap_envelope_parse(const char *envelope, + pool_t pool, struct message_part_envelope **envlp_r, + const char **error_r) +{ + struct istream *input; + struct imap_parser *parser; + const struct imap_arg *args; + char *error; + int ret; + + input = i_stream_create_from_data(envelope, strlen(envelope)); + (void)i_stream_read(input); + + parser = imap_parser_create(input, NULL, (size_t)-1); + ret = imap_parser_finish_line(parser, 0, + IMAP_PARSE_FLAG_LITERAL_TYPE, &args); + if (ret < 0) { + *error_r = t_strdup_printf("IMAP parser failed: %s", + imap_parser_get_error(parser, NULL)); + } else if (ret == 0) { + *error_r = "Empty envelope"; + ret = -1; + } else { + T_BEGIN { + if (!imap_envelope_parse_args + (args, pool, envlp_r, error_r)) { + error = i_strdup(*error_r); + ret = -1; + } + } T_END; + + if (ret < 0) { + *error_r = t_strdup(error); + i_free(error); + } + } + + imap_parser_unref(&parser); + i_stream_destroy(&input); + return (ret >= 0); +} \ No newline at end of file
--- a/src/lib-imap/imap-envelope.h Wed Oct 26 23:44:47 2016 +0200 +++ b/src/lib-imap/imap-envelope.h Thu Dec 29 14:02:05 2016 +0100 @@ -12,5 +12,9 @@ bool imap_envelope_parse_args(const struct imap_arg *args, pool_t pool, struct message_part_envelope **envlp_r, const char **error_r); +/* Parse envelope from string */ +bool imap_envelope_parse(const char *envelope, + pool_t pool, struct message_part_envelope **envlp_r, + const char **error_r); #endif