# HG changeset patch # User František Kučera # Date 1612639495 -3600 # Node ID dd8ff58fb29b067fb451f4d22418f283646c39f5 # Parent e2d61907e75fafd4c1a161f90fcd43926e31630c add body/part content as CDATA diff -r e2d61907e75f -r dd8ff58fb29b src/XMLDocumentConstructor.h --- a/src/XMLDocumentConstructor.h Sun Jan 31 10:14:12 2021 +0100 +++ b/src/XMLDocumentConstructor.h Sat Feb 06 20:24:55 2021 +0100 @@ -55,11 +55,29 @@ return contentType.getType() + "/" + contentType.getSubType(); } + std::string fetchBody(std::shared_ptr body) { + std::stringstream result; + vmime::utility::outputStreamAdapter resultAdapter(result); + + const vmime::charset targetEncoding = vmime::charset("utf-8"); + const vmime::charset sourceEncoding = body->getCharset(); + + vmime::shared_ptr charsetConverter = vmime::charsetConverter::create(sourceEncoding, targetEncoding); + vmime::shared_ptr resultConverter = charsetConverter->getFilteredOutputStream(resultAdapter); + + body->getContents()->extract(*resultConverter); + resultConverter->flush(); + + return result.str(); + } + void appendBody(xmlpp::Element* element, std::shared_ptr body) { element->set_attribute("content-type", format(body->getContentType())); + // element->set_attribute("content-type-charset", body->getCharset().getName()); + // element->set_attribute("content-transfer-encoding", body->getEncoding().getName()); if (body->getPartCount() == 0) { - element->add_child_cdata("TODO: here will be body/part content"); + element->add_child_cdata(fetchBody(body)); } else { for (auto part : body->getPartList()) { xmlpp::Element* partElement = element->add_child("part");