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

This commit is contained in:
Vincent Richard 2017-01-18 21:10:10 +01:00
parent f29edeb887
commit ec5f4370b6
2 changed files with 48 additions and 1 deletions

View File

@ -3324,7 +3324,20 @@ public:
}
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() << ">");

View File

@ -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