mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-24 10:59:23 +01:00
POP3 client fails to retrieve message if content-type is absent #806; add multi-part attachment name retrieval
This commit is contained in:
parent
36e2a11311
commit
ad1b75b30e
@ -92,7 +92,7 @@ namespace
|
||||
cte = MailMessage::ENCODING_BASE64;
|
||||
}
|
||||
|
||||
std::string contentType = header.get(MailMessage::HEADER_CONTENT_TYPE, "");
|
||||
std::string contentType = header.get(MailMessage::HEADER_CONTENT_TYPE, "text/plain; charset=us-ascii");
|
||||
std::string contentDisp = header.get(MailMessage::HEADER_CONTENT_DISPOSITION, "");
|
||||
std::string filename;
|
||||
if (!contentDisp.empty())
|
||||
@ -111,7 +111,7 @@ namespace
|
||||
if (it->second == "inline")
|
||||
_pMsg->addContent(pPS, cte);
|
||||
else
|
||||
_pMsg->addAttachment("", pPS, cte);
|
||||
_pMsg->addAttachment(getPartName(header), pPS, cte);
|
||||
added = true;
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ namespace
|
||||
StringTokenizer st(header, ";=", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
|
||||
StringTokenizer::Iterator it = st.begin();
|
||||
StringTokenizer::Iterator end = st.end();
|
||||
for (; it != end; ++it) { if (*it == param) break; }
|
||||
for (; it != end; ++it) { if (icompare(*it, param) == 0) break; }
|
||||
if (it != end)
|
||||
{
|
||||
++it;
|
||||
@ -144,6 +144,14 @@ namespace
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string getPartName(const MessageHeader& header)
|
||||
{
|
||||
std::string ct = MailMessage::HEADER_CONTENT_TYPE;
|
||||
if (header.has(ct))
|
||||
return getParamFromHeader(header[ct], "name");
|
||||
return "";
|
||||
}
|
||||
|
||||
MailMessage* _pMsg;
|
||||
};
|
||||
|
||||
|
@ -374,6 +374,28 @@ void MailMessageTest::testReadDefaultTransferEncoding()
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testReadDefaultContentType()
|
||||
{
|
||||
std::istringstream istr("Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
);
|
||||
|
||||
MailMessage message;
|
||||
message.read(istr);
|
||||
|
||||
assert (message.getSender() == "poco@appinf.com");
|
||||
assert (message.getContentType() == "text/plain");
|
||||
assert (message.getContent() == "Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testRead8Bit()
|
||||
{
|
||||
std::istringstream istr(
|
||||
@ -667,8 +689,10 @@ CppUnit::Test* MailMessageTest::suite()
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testWriteMultiPart);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testReadQP);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testReadDefaultTransferEncoding);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testReadDefaultContentType);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testRead8Bit);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testReadMultiPart);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testReadMultiPartWithAttachmentNames);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testReadMultiPartDefaultTransferEncoding);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testReadWriteMultiPart);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testReadWriteMultiPartStore);
|
||||
|
@ -32,6 +32,7 @@ public:
|
||||
void testReadWriteMultiPart();
|
||||
void testReadWriteMultiPartStore();
|
||||
void testReadDefaultTransferEncoding();
|
||||
void testReadDefaultContentType();
|
||||
void testReadQP();
|
||||
void testRead8Bit();
|
||||
void testReadMultiPart();
|
||||
|
Loading…
x
Reference in New Issue
Block a user