From d1190b496faa754a757aba79f88dcd7e31d6d500 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Thu, 29 Nov 2018 21:25:47 +0100 Subject: Improve address parser for malformed mailbox specifications Spammers use "Name " to trick some parsers. My expectations as to what the outcome should be is presented in the updated mailboxTest.cpp. The DFA in mailbox::parseImpl is hereby redone so as to pick the rightmost address-looking portion as the address, rather than something in between. While doing so, it will also no longer mangle the name part anymore (it does this by keeping a "as_if_name" variable around until the end). --- tests/parser/mailboxTest.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tests/parser/mailboxTest.cpp') diff --git a/tests/parser/mailboxTest.cpp b/tests/parser/mailboxTest.cpp index a0d1b694..23d1b4ac 100644 --- a/tests/parser/mailboxTest.cpp +++ b/tests/parser/mailboxTest.cpp @@ -154,20 +154,20 @@ VMIME_TEST_SUITE_BEGIN(mailboxTest) VASSERT_EQ("email", "e@f.g", mbox.getEmail()); mbox.parse("a@b.c e@f.g "); - VASSERT_EQ("name", vmime::text("e@f.g"), mbox.getName()); + VASSERT_EQ("name", vmime::text("a@b.c e@f.g"), mbox.getName()); VASSERT_EQ("email", "h@i.j", mbox.getEmail()); mbox.parse("Foo "); - VASSERT_EQ("name", vmime::text("Foobar"), mbox.getName()); + VASSERT_EQ("name", vmime::text("Foo "); - VASSERT_EQ("name", vmime::text("Foo"), mbox.getName()); - VASSERT_EQ("email", "foo@x.com", mbox.getEmail()); + VASSERT_EQ("name", vmime::text("Foo "), mbox.getName()); + VASSERT_EQ("email", "bar@x.com", mbox.getEmail()); mbox.parse("Foo Bar "); - VASSERT_EQ("name", vmime::text("Foo"), mbox.getName()); - VASSERT_EQ("email", "foo@x.com", mbox.getEmail()); + VASSERT_EQ("name", vmime::text("Foo Bar"), mbox.getName()); + VASSERT_EQ("email", "bar@y.com", mbox.getEmail()); } VMIME_TEST_SUITE_END -- cgit v1.2.3