]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: test-message-address - add more and better organized tests
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 7 Jun 2017 10:19:40 +0000 (13:19 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 12 Jun 2017 14:05:32 +0000 (17:05 +0300)
src/lib-mail/test-message-address.c

index 4bcd3b65764aae3cdcf5eeadfadf0816de795043..18f5cb8f025da2d78ea08b5a1f58ac5e97d7349a 100644 (file)
@@ -22,34 +22,90 @@ static void test_message_address(void)
                const char *wanted_output;
                struct message_address addr;
        } tests[] = {
+               /* user@domain -> <user@domain> */
                { "user@domain", "<user@domain>",
                  { NULL, NULL, NULL, "user", "domain", FALSE } },
+               { "\"user\"@domain", "<user@domain>",
+                 { NULL, NULL, NULL, "user", "domain", FALSE } },
+               { "\"user name\"@domain", "<\"user name\"@domain>",
+                 { NULL, NULL, NULL, "user name", "domain", FALSE } },
+               { "\"user@na\\\\me\"@domain", "<\"user@na\\\\me\"@domain>",
+                 { NULL, NULL, NULL, "user@na\\me", "domain", FALSE } },
+               { "\"user\\\"name\"@domain", "<\"user\\\"name\"@domain>",
+                 { NULL, NULL, NULL, "user\"name", "domain", FALSE } },
+               { "\"\"@domain", "<\"\"@domain>",
+                 { NULL, NULL, NULL, "", "domain", FALSE } },
+               { "@domain", "<\"\"@domain>",
+                 { NULL, NULL, NULL, "", "domain", TRUE } },
+
+               /* <user@domain> -> <user@domain> */
                { "<user@domain>", NULL,
                  { NULL, NULL, NULL, "user", "domain", FALSE } },
+               { "<\"user\"@domain>", "<user@domain>",
+                 { NULL, NULL, NULL, "user", "domain", FALSE } },
+               { "<\"user name\"@domain>", NULL,
+                 { NULL, NULL, NULL, "user name", "domain", FALSE } },
+               { "<\"user@na\\\\me\"@domain>", NULL,
+                 { NULL, NULL, NULL, "user@na\\me", "domain", FALSE } },
+               { "<\"user\\\"name\"@domain>", NULL,
+                 { NULL, NULL, NULL, "user\"name", "domain", FALSE } },
+               { "<\"\"@domain>", NULL,
+                 { NULL, NULL, NULL, "", "domain", FALSE } },
                { "<@route>", "<@route:\"\">",
                  { NULL, NULL, "@route", "", "", TRUE } },
-               { "<\"\"@domain>", "<\"\"@domain>",
-                 { NULL, NULL, NULL, "", "domain", FALSE } },
-               { "foo bar <user@domain>", "\"foo bar\" <user@domain>",
-                 { NULL, "foo bar", NULL, "user", "domain", FALSE } },
-               { "\"foo bar\" <user@domain>", NULL,
-                 { NULL, "foo bar", NULL, "user", "domain", FALSE } },
-               { "\"foo: <a@b>;,\" <user@domain>", NULL,
-                 { NULL, "foo: <a@b>;,", NULL, "user", "domain", FALSE } },
+
+               /* user@domain (Display Name) -> "Display Name" <user@domain> */
+               { "user@domain (DisplayName)", "DisplayName <user@domain>",
+                 { NULL, "DisplayName", NULL, "user", "domain", FALSE } },
+               { "user@domain (Display Name)", "\"Display Name\" <user@domain>",
+                 { NULL, "Display Name", NULL, "user", "domain", FALSE } },
+               { "user@domain (Display\"Name)", "\"Display\\\"Name\" <user@domain>",
+                 { NULL, "Display\"Name", NULL, "user", "domain", FALSE } },
+               { "user (Display Name)", "\"Display Name\" <user>",
+                 { NULL, "Display Name", NULL, "user", "", TRUE } },
+               { "@domain (Display Name)", "\"Display Name\" <\"\"@domain>",
+                 { NULL, "Display Name", NULL, "", "domain", TRUE } },
+
+               /* Display Name <user@domain> -> "Display Name" <user@domain> */
+               { "DisplayName <user@domain>", NULL,
+                 { NULL, "DisplayName", NULL, "user", "domain", FALSE } },
+               { "Display Name <user@domain>", "\"Display Name\" <user@domain>",
+                 { NULL, "Display Name", NULL, "user", "domain", FALSE } },
+               { "\"Display Name\" <user@domain>", NULL,
+                 { NULL, "Display Name", NULL, "user", "domain", FALSE } },
+               { "\"Display\\\"Name\" <user@domain>", NULL,
+                 { NULL, "Display\"Name", NULL, "user", "domain", FALSE } },
+               { "Display Name <user>", "\"Display Name\" <user>",
+                 { NULL, "Display Name", NULL, "user", "", TRUE } },
+
+               /* <@route:user@domain> -> <@route:user@domain> */
                { "<@route:user@domain>", NULL,
                  { NULL, NULL, "@route", "user", "domain", FALSE } },
+               { "<@route,@route2:user@domain>", NULL,
+                 { NULL, NULL, "@route,@route2", "user", "domain", FALSE } },
                { "<@route@route2:user@domain>", "<@route,@route2:user@domain>",
                  { NULL, NULL, "@route,@route2", "user", "domain", FALSE } },
-               { "hello <@route ,@route2:user@domain>", "hello <@route,@route2:user@domain>",
-                 { NULL, "hello", "@route,@route2", "user", "domain", FALSE } },
-               { "hello", "hello",
-                 { NULL, "hello", NULL, "", "", TRUE } },
-               { "user (hello)", "hello <user>",
-                 { NULL, "hello", NULL, "user", "", TRUE } },
-               { "hello <user>", "hello <user>",
-                 { NULL, "hello", NULL, "user", "", TRUE } },
-               { "@domain", "<\"\"@domain>",
-                 { NULL, NULL, NULL, "", "domain", TRUE } },
+               { "<@route@route2:user>", "<@route,@route2:user>",
+                 { NULL, NULL, "@route,@route2", "user", "", TRUE } },
+               { "<@route@route2:\"\"@domain>", "<@route,@route2:\"\"@domain>",
+                 { NULL, NULL, "@route,@route2", "", "domain", FALSE } },
+
+               /* Display Name <@route:user@domain> ->
+                  "Display Name" <@route:user@domain> */
+               { "Display Name <@route:user@domain>", "\"Display Name\" <@route:user@domain>",
+                 { NULL, "Display Name", "@route", "user", "domain", FALSE } },
+               { "Display Name <@route,@route2:user@domain>", "\"Display Name\" <@route,@route2:user@domain>",
+                 { NULL, "Display Name", "@route,@route2", "user", "domain", FALSE } },
+               { "Display Name <@route@route2:user@domain>", "\"Display Name\" <@route,@route2:user@domain>",
+                 { NULL, "Display Name", "@route,@route2", "user", "domain", FALSE } },
+               { "Display Name <@route@route2:user>", "\"Display Name\" <@route,@route2:user>",
+                 { NULL, "Display Name", "@route,@route2", "user", "", TRUE } },
+               { "Display Name <@route@route2:\"\"@domain>", "\"Display Name\" <@route,@route2:\"\"@domain>",
+                 { NULL, "Display Name", "@route,@route2", "", "domain", FALSE } },
+
+               /* other tests: */
+               { "\"foo: <a@b>;,\" <user@domain>", NULL,
+                 { NULL, "foo: <a@b>;,", NULL, "user", "domain", FALSE } },
        };
        static struct message_address group_prefix = {
                NULL, NULL, NULL, "group", NULL, FALSE