parse attachments' name and filename

This commit is contained in:
GlacJAY
2015-07-10 09:56:48 +08:00
parent 51a8292649
commit 596edc5385

View File

@@ -98,28 +98,27 @@ namespace
NameValueCollection::ConstIterator end = header.end(); NameValueCollection::ConstIterator end = header.end();
PartSource* pPS = _pMsg->createPartStore(tmp, PartSource* pPS = _pMsg->createPartStore(tmp,
header[MailMessage::HEADER_CONTENT_TYPE], header[MailMessage::HEADER_CONTENT_TYPE],
getFileNameFromDisp(it->second)); getAttrFromHeader(header[MailMessage::HEADER_CONTENT_DISPOSITION], "filename"));
poco_check_ptr (pPS); 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") _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); pPS->headers().set(it->first, it->second);
} }
} }
} }
private: 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 st(str, ";=", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
StringTokenizer::Iterator it = st.begin(); StringTokenizer::Iterator it = st.begin();
StringTokenizer::Iterator end = st.end(); StringTokenizer::Iterator end = st.end();
for (; it != end; ++it) { if (*it == "filename") break; } for (; it != end; ++it) { if (*it == attrName) break; }
if (it != end) if (it != end)
{ {
++it; ++it;