return ret;
}
+static void add_fixed_address(struct message_address_parser_context *ctx)
+{
+ if (ctx->addr.mailbox == NULL)
+ ctx->addr.mailbox = !ctx->fill_missing ? "" : "MISSING_MAILBOX";
+ if (ctx->addr.domain == NULL)
+ ctx->addr.domain = !ctx->fill_missing ? "" : "MISSING_DOMAIN";
+ add_address(ctx);
+}
+
static int parse_mailbox(struct message_address_parser_context *ctx)
{
const unsigned char *start;
return -1;
}
- if (ctx->addr.mailbox == NULL) {
- ctx->addr.mailbox = !ctx->fill_missing ? "" :
- p_strdup(ctx->pool, "MISSING_MAILBOX");
- }
- if (ctx->addr.domain == NULL) {
- ctx->addr.domain = !ctx->fill_missing ? "" :
- p_strdup(ctx->pool, "MISSING_DOMAIN");
- }
- add_address(ctx);
-
+ add_fixed_address(ctx);
return ret;
}
unsigned int max_addresses, bool fill_missing)
{
struct message_address_parser_context ctx;
+ int ret;
memset(&ctx, 0, sizeof(ctx));
ctx.str = t_str_new(128);
ctx.fill_missing = fill_missing;
- rfc822_skip_lwsp(&ctx.parser);
-
- if (parse_address_list(&ctx, max_addresses) < 0)
+ ret = rfc822_skip_lwsp(&ctx.parser);
+ if (ret == 0) {
+ /* no addresses */
+ return NULL;
+ }
+ if (ret < 0 || parse_address_list(&ctx, max_addresses) < 0) {
+ if (ctx.first_addr == NULL) {
+ /* we had some input - we'll have to return something
+ so that we can set invalid_syntax */
+ add_fixed_address(&ctx);
+ }
ctx.first_addr->invalid_syntax = TRUE;
+ }
return ctx.first_addr;
}