Merge pull request #879 from glacjay/attachment-names

parse attachments' name and filename
This commit is contained in:
Aleksandar Fabijanic
2015-07-15 13:26:54 -05:00
3 changed files with 41 additions and 5 deletions

View File

@@ -98,28 +98,27 @@ namespace
NameValueCollection::ConstIterator end = header.end();
PartSource* pPS = _pMsg->createPartStore(tmp,
header[MailMessage::HEADER_CONTENT_TYPE],
getFileNameFromDisp(it->second));
getAttrFromHeader(header[MailMessage::HEADER_CONTENT_DISPOSITION], "filename"));
poco_check_ptr (pPS);
for (; it != end; ++it)
{
if (MailMessage::HEADER_CONTENT_DISPOSITION == it->first)
{
if (it->second == "inline") _pMsg->addContent(pPS, cte);
else _pMsg->addAttachment("", pPS, cte);
else _pMsg->addAttachment(getAttrFromHeader(header[MailMessage::HEADER_CONTENT_TYPE], "name"), pPS, cte);
}
pPS->headers().set(it->first, it->second);
}
}
}
private:
std::string getFileNameFromDisp(const std::string& str)
std::string getAttrFromHeader(const std::string& str, const std::string& attrName)
{
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 == "filename") break; }
for (; it != end; ++it) { if (*it == attrName) break; }
if (it != end)
{
++it;