diff options
author | Vincent Richard <[email protected]> | 2019-04-18 09:28:48 +0000 |
---|---|---|
committer | Vincent Richard <[email protected]> | 2019-04-18 09:28:48 +0000 |
commit | b59e97d0a7cf97ed68a0071cd3e90ecfe0c04cc5 (patch) | |
tree | c334d9adf0ba593d49250f8b986675f9cd5c5433 | |
parent | #206 Initialize and delete pointers (diff) | |
download | vmime-b59e97d0a7cf97ed68a0071cd3e90ecfe0c04cc5.tar.gz vmime-b59e97d0a7cf97ed68a0071cd3e90ecfe0c04cc5.zip |
#213 Add support for invalid empty () in FETCH body structure (non-strict)
-rw-r--r-- | src/vmime/net/imap/IMAPParser.hpp | 19 | ||||
-rw-r--r-- | tests/net/imap/IMAPParserTest.cpp | 31 |
2 files changed, 47 insertions, 3 deletions
diff --git a/src/vmime/net/imap/IMAPParser.hpp b/src/vmime/net/imap/IMAPParser.hpp index 186ac23f..70781eae 100644 --- a/src/vmime/net/imap/IMAPParser.hpp +++ b/src/vmime/net/imap/IMAPParser.hpp @@ -3398,11 +3398,24 @@ public: if (VIMAP_PARSER_TRY_CHECK(one_char <'('> )) { - VIMAP_PARSER_GET_PUSHBACK(body_fld_param_item, m_items); + bool isNIL = false; + + if (!parser.isStrict()) { + + // In non-strict mode, allow "()" instead of "NIL" + if (VIMAP_PARSER_TRY_CHECK(one_char <')'> )) { + isNIL = true; + } + } + + if (!isNIL) { - while (!VIMAP_PARSER_TRY_CHECK(one_char <')'> )) { - VIMAP_PARSER_CHECK(SPACE); VIMAP_PARSER_GET_PUSHBACK(body_fld_param_item, m_items); + + while (!VIMAP_PARSER_TRY_CHECK(one_char <')'> )) { + VIMAP_PARSER_CHECK(SPACE); + VIMAP_PARSER_GET_PUSHBACK(body_fld_param_item, m_items); + } } } else { diff --git a/tests/net/imap/IMAPParserTest.cpp b/tests/net/imap/IMAPParserTest.cpp index 974dc241..ace4e2d9 100644 --- a/tests/net/imap/IMAPParserTest.cpp +++ b/tests/net/imap/IMAPParserTest.cpp @@ -35,6 +35,7 @@ VMIME_TEST_SUITE_BEGIN(IMAPParserTest) VMIME_TEST(testNILValueInBodyFldEnc) VMIME_TEST(testFETCHResponse_optional_body_fld_lang) VMIME_TEST(testFETCHBodyStructure_NIL_body_fld_param_value) + VMIME_TEST(testFETCHBodyStructure_empty_body_fld_param_instead_of_NIL) VMIME_TEST_LIST_END @@ -202,4 +203,34 @@ VMIME_TEST_SUITE_BEGIN(IMAPParserTest) VASSERT_THROW("strict mode", parser->readResponse(), vmime::exceptions::invalid_response); } + void testFETCHBodyStructure_empty_body_fld_param_instead_of_NIL() { + + vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>(); + vmime::shared_ptr <vmime::net::timeoutHandler> toh = vmime::make_shared <testTimeoutHandler>(); + + vmime::shared_ptr <vmime::net::imap::IMAPTag> tag = + vmime::make_shared <vmime::net::imap::IMAPTag>(); + + const char* resp = "* 1 FETCH (BODYSTRUCTURE ((\"text\" \"html\" (\"charset\" \"cp1251\") NIL NIL \"base64\" 84056 0 NIL (\"inline\" NIL) NIL NIL)(\"image\" \"gif\" () \"25b2b55b5d97f04e9ea939fe32a46a65.gif\" NIL \"base64\" 20776 NIL (\"inline\" NIL) NIL NIL) \"related\" (\"boundary\" NIL)))\r\na001 OK FETCH complete\r\n"; + + socket->localSend(resp); + + vmime::shared_ptr <vmime::net::imap::IMAPParser> parser = + vmime::make_shared <vmime::net::imap::IMAPParser>(); + + 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 |