*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
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