Skip to content

Commit

Permalink
lib-imap: imap-envelope: Added function for parsing ENVELOPE from str…
Browse files Browse the repository at this point in the history
…ing.
  • Loading branch information
stephanbosch authored and GitLab committed Jan 30, 2017
1 parent 62306ad commit 3b17e4c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/lib-imap/imap-envelope.c
Expand Up @@ -214,3 +214,45 @@ bool imap_envelope_parse_args(const struct imap_arg *args,
*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);
}
4 changes: 4 additions & 0 deletions src/lib-imap/imap-envelope.h
Expand Up @@ -12,5 +12,9 @@ void imap_envelope_write(struct message_part_envelope *data,
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

0 comments on commit 3b17e4c

Please sign in to comment.