Permalink
Browse files

Fixed #159: parsing error on invalid FETCH BODYSTRUCTURE response.

  • Loading branch information...
1 parent f29edeb commit ec5f4370b69de4ca4b8c5e3b3d2bc43e8fb4da7f @vincent-richard vincent-richard committed Jan 18, 2017
Showing with 48 additions and 1 deletion.
  1. +14 −1 src/vmime/net/imap/IMAPParser.hpp
  2. +34 −0 tests/net/imap/IMAPParserTest.cpp
@@ -3324,7 +3324,20 @@ class VMIME_EXPORT IMAPParser : public object
}
VIMAP_PARSER_CHECK(SPACE);
- VIMAP_PARSER_GET(xstring, m_string2);
+
+ if (!parser.isStrict())
+ {
+ // In non-strict mode, allow NIL in value
+ shared_ptr <nstring> nstr;
+ VIMAP_PARSER_GET_PTR(nstring, nstr);
+
+ m_string2 = new xstring();
+ m_string2->setValue(nstr->value());
+ }
+ else
+ {
+ VIMAP_PARSER_GET(xstring, m_string2);
+ }
DEBUG_FOUND("body_fld_param_item", "<" << m_string1->value() << ", " << m_string2->value() << ">");
@@ -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 <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>();
+
+ // ...("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 <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

0 comments on commit ec5f437

Please sign in to comment.