]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: message-address: Make the parser allow paths that omit `<' and `>'.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Thu, 12 Apr 2018 14:13:08 +0000 (16:13 +0200)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Wed, 25 Apr 2018 08:12:06 +0000 (11:12 +0300)
This is a syntax violation, but we allow it to account for a rather wide
selection of software that does not follow the standards.

src/lib-mail/message-address.c
src/lib-mail/test-message-address.c

index f7b383468db23579b940367020182d932671aa79..a9456f613cd04c7771f83531b22357f76b895d7e 100644 (file)
@@ -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')) ||
index da0b0b23bf3e2b02635bb7a99e90e5983e0d8f72..c0adc5dc164e8297c62506eb84ac3a6c11805040 100644 (file)
@@ -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,
@@ -405,8 +409,6 @@ static void test_message_address_path_invalid(void)
                " < ",
                ">",
                " > ",
-               "user@domain",
-               "  user@domain  ",
                "<user@domain",
                "  <user@domain  ",
                "user@domain>",
@@ -414,8 +416,13 @@ static void test_message_address_path_invalid(void)
                "<user>",
                "<@route@route2:user>",
                "<@domain>",
+               "@domain",
+               "  @domain  ",
                "<user@>",
+               "user@",
+               "  user@  ",
                "<user@domain>bladiebla",
+               "user@domain@"
        };
        const struct message_address *addr;
        unsigned int i;