Skip to content

Commit

Permalink
lib-mail: message-address: Make the parser allow paths that omit `<' …
Browse files Browse the repository at this point in the history
…and `>'.

This is a syntax violation, but we allow it to account for a rather wide
selection of software that does not follow the standards.
  • Loading branch information
stephanbosch authored and sirainen committed Apr 19, 2018
1 parent 8580f2e commit 5c62b6e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
17 changes: 13 additions & 4 deletions src/lib-mail/message-address.c
Expand Up @@ -393,10 +393,19 @@ static int parse_path(struct message_address_parser_context *ctx)

if (rfc822_skip_lwsp(&ctx->parser) <= 0)
return -1;
if (*ctx->parser.data != '<')
return -1;
if ((ret=parse_angle_addr(ctx, TRUE)) < 0 ||
(ret=rfc822_skip_lwsp(&ctx->parser)) < 0 ||
if (*ctx->parser.data != '<') {
/* Cope with paths that omit < and >. This is a syntax
violation, but we allow it to account for a rather wide
selection of software that does not follow the standards.
*/
if ((ret=parse_local_part(ctx)) > 0 &&
*ctx->parser.data == '@') {
ret = parse_domain(ctx);
}
} else {
ret = parse_angle_addr(ctx, TRUE);
}
if (ret < 0 || (ret=rfc822_skip_lwsp(&ctx->parser)) < 0 ||
ctx->parser.data != ctx->parser.end ||
(ctx->addr.mailbox != NULL &&
(ctx->addr.domain == NULL || *ctx->addr.domain == '\0')) ||
Expand Down
11 changes: 9 additions & 2 deletions src/lib-mail/test-message-address.c
Expand Up @@ -355,6 +355,10 @@ static void test_message_address_path(void)
{ NULL, NULL, NULL, "user", "domain", FALSE } },
{ " <user@domain> ", "<user@domain>",
{ NULL, NULL, NULL, "user", "domain", FALSE } },
{ "user@domain", "<user@domain>",
{ NULL, NULL, NULL, "user", "domain", FALSE } },
{ " user@domain ", "<user@domain>",
{ NULL, NULL, NULL, "user", "domain", FALSE } },
{ "<\"user\"@domain>", "<user@domain>",
{ NULL, NULL, NULL, "user", "domain", FALSE } },
{ "<\"user name\"@domain>", NULL,
Expand Down Expand Up @@ -405,17 +409,20 @@ static void test_message_address_path_invalid(void)
" < ",
">",
" > ",
"user@domain",
" user@domain ",
"<user@domain",
" <user@domain ",
"user@domain>",
" user@domain> ",
"<user>",
"<@route@route2:user>",
"<@domain>",
"@domain",
" @domain ",
"<user@>",
"user@",
" user@ ",
"<user@domain>bladiebla",
"user@domain@"
};
const struct message_address *addr;
unsigned int i;
Expand Down

0 comments on commit 5c62b6e

Please sign in to comment.