mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-31 14:39:53 +01:00
fix(MailMessage): read hangs on missing final multipart boundary #2401
This commit is contained in:
parent
1e3bc35717
commit
47f2c3573c
@ -108,7 +108,8 @@ void MessageHeader::read(std::istream& istr)
|
||||
add(name, decodeWord(value));
|
||||
++fields;
|
||||
}
|
||||
istr.putback(ch);
|
||||
if (istr.good() && ch != eof)
|
||||
istr.putback(ch);
|
||||
}
|
||||
|
||||
|
||||
|
@ -105,6 +105,7 @@ int MultipartStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
||||
*buffer++ = (char) buf.sbumpc(); ++n;
|
||||
ch = buf.sgetc();
|
||||
}
|
||||
if (ch == eof) _lastPart = true;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,9 @@
|
||||
#include "Poco/Timestamp.h"
|
||||
#include "Poco/FileStream.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/TemporaryFile.h"
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
@ -36,6 +38,7 @@ using Poco::Timestamp;
|
||||
using Poco::FileInputStream;
|
||||
using Poco::replaceInPlace;
|
||||
using Poco::icompare;
|
||||
using Poco::TemporaryFile;
|
||||
|
||||
|
||||
namespace
|
||||
@ -506,6 +509,54 @@ void MailMessageTest::testReadMultiPartDefaultTransferEncoding()
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testReadMultiPartNoFinalBoundaryFromFile()
|
||||
{
|
||||
std::string data(
|
||||
"Content-Type: multipart/mixed; boundary=MIME_boundary_01234567\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Mime-Version: 1.0\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"\r\n"
|
||||
"--MIME_boundary_01234567\r\n"
|
||||
"Content-Disposition: inline\r\n"
|
||||
"Content-Transfer-Encoding: 8bit\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"\r\n"
|
||||
"Hello World!\r\n"
|
||||
"\r\n"
|
||||
"--MIME_boundary_01234567\r\n"
|
||||
"Content-Disposition: attachment; filename=sample.dat\r\n"
|
||||
"Content-Transfer-Encoding: base64\r\n"
|
||||
"Content-Type: application/octet-stream; name=sample\r\n"
|
||||
"\r\n"
|
||||
"VGhpcyBpcyBzb21lIGJpbmFyeSBkYXRhLiBSZWFsbHku\r\n"
|
||||
);
|
||||
|
||||
// The problem occurs during reading message from file.
|
||||
// (For stringstreams it works fine.)
|
||||
// https://github.com/pocoproject/poco/issues/2401
|
||||
TemporaryFile file;
|
||||
std::ofstream(file.path()) << data;
|
||||
std::ifstream istr(file.path());
|
||||
|
||||
StringPartHandler handler;
|
||||
MailMessage message;
|
||||
message.read(istr, handler);
|
||||
|
||||
assertTrue (handler.data().size() == 2);
|
||||
assertTrue (handler.data()[0] == "Hello World!\r\n");
|
||||
assertTrue (handler.type()[0] == "text/plain");
|
||||
assertTrue (handler.disp()[0] == "inline");
|
||||
|
||||
assertTrue (handler.data()[1] == "This is some binary data. Really.");
|
||||
assertTrue (handler.type()[1] == "application/octet-stream; name=sample");
|
||||
assertTrue (handler.disp()[1] == "attachment; filename=sample.dat");
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testReadWriteMultiPart()
|
||||
{
|
||||
std::string msgin(
|
||||
@ -657,6 +708,7 @@ CppUnit::Test* MailMessageTest::suite()
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testRead8Bit);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testReadMultiPart);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testReadMultiPartDefaultTransferEncoding);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testReadMultiPartNoFinalBoundaryFromFile);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testReadWriteMultiPart);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testReadWriteMultiPartStore);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testEncodeWord);
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
void testReadMultiPart();
|
||||
void testReadMultiPartWithAttachmentNames();
|
||||
void testReadMultiPartDefaultTransferEncoding();
|
||||
void testReadMultiPartNoFinalBoundaryFromFile();
|
||||
void testEncodeWord();
|
||||
|
||||
void setUp();
|
||||
|
Loading…
x
Reference in New Issue
Block a user