From ec5f4370b69de4ca4b8c5e3b3d2bc43e8fb4da7f Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Wed, 18 Jan 2017 21:10:10 +0100 Subject: Fixed #159: parsing error on invalid FETCH BODYSTRUCTURE response. --- tests/net/imap/IMAPParserTest.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'tests') diff --git a/tests/net/imap/IMAPParserTest.cpp b/tests/net/imap/IMAPParserTest.cpp index 8dd40fcb..5d810a8f 100644 --- a/tests/net/imap/IMAPParserTest.cpp +++ b/tests/net/imap/IMAPParserTest.cpp @@ -34,6 +34,7 @@ VMIME_TEST_SUITE_BEGIN(IMAPParserTest) VMIME_TEST(testContinueReqWithoutSpace) VMIME_TEST(testNILValueInBodyFldEnc) VMIME_TEST(testFETCHResponse_optional_body_fld_lang) + VMIME_TEST(testFETCHBodyStructure_NIL_body_fld_param_value) VMIME_TEST_LIST_END @@ -166,4 +167,37 @@ VMIME_TEST_SUITE_BEGIN(IMAPParserTest) VASSERT_NO_THROW("parse", parser->readResponse()); } + // Support for NIL boundary, for mail.ru IMAP server: + // https://www.ietf.org/mail-archive/web/imapext/current/msg05442.html + void testFETCHBodyStructure_NIL_body_fld_param_value() + { + vmime::shared_ptr socket = vmime::make_shared (); + vmime::shared_ptr toh = vmime::make_shared (); + + vmime::shared_ptr tag = + vmime::make_shared (); + + // ...("boundary" NIL)))... is an invalid syntax for a "body_fld_param_item" + const char* resp = "* 1 FETCH (BODYSTRUCTURE ((\"text\" \"plain\" (\"charset\" \"utf-8\") NIL NIL \"8bit\" 536 0 NIL NIL NIL NIL)(\"text\" \"html\" (\"charset\" \"utf-8\") NIL NIL \"8bit\" 7130 0 NIL NIL NIL NIL) \"alternative\" (\"boundary\" NIL)))\r\na001 OK FETCH complete\r\n"; + + socket->localSend(resp); + + vmime::shared_ptr parser = + vmime::make_shared (); + + parser->setTag(tag); + parser->setSocket(socket); + parser->setTimeoutHandler(toh); + + parser->setStrict(false); + VASSERT_NO_THROW("non-strict mode", parser->readResponse()); + + ++(*tag); + + socket->localSend(resp); + + parser->setStrict(true); + VASSERT_THROW("strict mode", parser->readResponse(), vmime::exceptions::invalid_response); + } + VMIME_TEST_SUITE_END -- cgit v1.2.3