mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-29 12:18:01 +01:00
backport MultipartSource for MailMessage from develop branch
This commit is contained in:
@@ -418,7 +418,7 @@ void MailMessage::writeMultipart(MessageHeader& header, std::ostream& ostr) cons
|
||||
}
|
||||
|
||||
|
||||
void MailMessage::writePart(MultipartWriter& writer, const Part& part) const
|
||||
void MailMessage::writePart(MultipartWriter& writer, const Part& part)
|
||||
{
|
||||
MessageHeader partHeader(part.pSource->headers());
|
||||
MediaType mediaType(part.pSource->mediaType());
|
||||
@@ -444,7 +444,7 @@ void MailMessage::writePart(MultipartWriter& writer, const Part& part) const
|
||||
}
|
||||
|
||||
|
||||
void MailMessage::writeEncoded(std::istream& istr, std::ostream& ostr, ContentTransferEncoding encoding) const
|
||||
void MailMessage::writeEncoded(std::istream& istr, std::ostream& ostr, ContentTransferEncoding encoding)
|
||||
{
|
||||
switch (encoding)
|
||||
{
|
||||
@@ -692,4 +692,57 @@ PartSource* MailMessage::createPartStore(const std::string& content, const std::
|
||||
}
|
||||
|
||||
|
||||
MultipartSource::MultipartSource(const std::string contentType):
|
||||
PartSource(contentTypeWithBoundary(contentType))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MultipartSource::~MultipartSource()
|
||||
{
|
||||
for (MailMessage::PartVec::iterator it = _parts.begin(); it != _parts.end(); ++it)
|
||||
{
|
||||
delete it->pSource;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MultipartSource::addPart(const std::string& name,
|
||||
PartSource* pSource,
|
||||
MailMessage::ContentDisposition disposition,
|
||||
MailMessage::ContentTransferEncoding encoding)
|
||||
{
|
||||
MailMessage::Part part;
|
||||
part.name = name;
|
||||
part.pSource = pSource;
|
||||
part.disposition = disposition;
|
||||
part.encoding = encoding;
|
||||
_parts.push_back(part);
|
||||
}
|
||||
|
||||
|
||||
std::istream& MultipartSource::stream()
|
||||
{
|
||||
MediaType mt(mediaType());
|
||||
std::string boundary = mt.getParameter("boundary");
|
||||
|
||||
MultipartWriter writer(_content, boundary);
|
||||
for (MailMessage::PartVec::const_iterator it = _parts.begin(); it != _parts.end(); ++it)
|
||||
{
|
||||
MailMessage::writePart(writer, *it);
|
||||
}
|
||||
writer.close();
|
||||
|
||||
return _content;
|
||||
}
|
||||
|
||||
|
||||
std::string MultipartSource::contentTypeWithBoundary(const std::string& contentType)
|
||||
{
|
||||
MediaType mediaType(contentType);
|
||||
mediaType.setParameter("boundary", MultipartWriter::createBoundary());
|
||||
return mediaType.toString();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
Reference in New Issue
Block a user