mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-30 13:47:10 +01:00
fixed GH #696: bug in parsing name of attachment
This commit is contained in:
@@ -94,18 +94,25 @@ namespace
|
|||||||
cte = MailMessage::ENCODING_BASE64;
|
cte = MailMessage::ENCODING_BASE64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string contentType = header.get(MailMessage::HEADER_CONTENT_TYPE, "");
|
||||||
|
std::string contentDisp = header.get(MailMessage::HEADER_CONTENT_DISPOSITION, "");
|
||||||
|
std::string filename;
|
||||||
|
if (!contentDisp.empty())
|
||||||
|
filename = getFileNameFromContentDisposition(contentDisp);
|
||||||
|
if (filename.empty())
|
||||||
|
filename = getNameFromContentType(contentType);
|
||||||
|
PartSource* pPS = _pMsg->createPartStore(tmp, contentType, filename);
|
||||||
|
poco_check_ptr (pPS);
|
||||||
NameValueCollection::ConstIterator it = header.begin();
|
NameValueCollection::ConstIterator it = header.begin();
|
||||||
NameValueCollection::ConstIterator end = header.end();
|
NameValueCollection::ConstIterator end = header.end();
|
||||||
PartSource* pPS = _pMsg->createPartStore(tmp,
|
|
||||||
header[MailMessage::HEADER_CONTENT_TYPE],
|
|
||||||
getFileNameFromDisp(it->second));
|
|
||||||
poco_check_ptr (pPS);
|
|
||||||
for (; it != end; ++it)
|
for (; it != end; ++it)
|
||||||
{
|
{
|
||||||
if (MailMessage::HEADER_CONTENT_DISPOSITION == it->first)
|
if (MailMessage::HEADER_CONTENT_DISPOSITION == it->first)
|
||||||
{
|
{
|
||||||
if (it->second == "inline") _pMsg->addContent(pPS, cte);
|
if (it->second == "inline")
|
||||||
else _pMsg->addAttachment("", pPS, cte);
|
_pMsg->addContent(pPS, cte);
|
||||||
|
else
|
||||||
|
_pMsg->addAttachment("", pPS, cte);
|
||||||
}
|
}
|
||||||
|
|
||||||
pPS->headers().set(it->first, it->second);
|
pPS->headers().set(it->first, it->second);
|
||||||
@@ -114,7 +121,7 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string getFileNameFromDisp(const std::string& str)
|
std::string getFileNameFromContentDisposition(const std::string& str)
|
||||||
{
|
{
|
||||||
StringTokenizer st(str, ";=", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
|
StringTokenizer st(str, ";=", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
|
||||||
StringTokenizer::Iterator it = st.begin();
|
StringTokenizer::Iterator it = st.begin();
|
||||||
@@ -129,6 +136,21 @@ namespace
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string getNameFromContentType(const std::string& str)
|
||||||
|
{
|
||||||
|
StringTokenizer st(str, ";=", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
|
||||||
|
StringTokenizer::Iterator it = st.begin();
|
||||||
|
StringTokenizer::Iterator end = st.end();
|
||||||
|
for (; it != end; ++it) { if (*it == "name") break; }
|
||||||
|
if (it != end)
|
||||||
|
{
|
||||||
|
++it;
|
||||||
|
if (it == end) return "";
|
||||||
|
return *it;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
MailMessage* _pMsg;
|
MailMessage* _pMsg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user