src/XMLDocumentConstructor.h
branchv_0
changeset 4 dd8ff58fb29b
parent 3 e2d61907e75f
child 5 a3794fe5ea4b
--- 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<vmime::body> 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 <vmime::charsetConverter> charsetConverter = vmime::charsetConverter::create(sourceEncoding, targetEncoding);
+		vmime::shared_ptr <vmime::utility::charsetFilteredOutputStream> resultConverter = charsetConverter->getFilteredOutputStream(resultAdapter);
+
+		body->getContents()->extract(*resultConverter);
+		resultConverter->flush();
+
+		return result.str();
+	}
+
 	void appendBody(xmlpp::Element* element, std::shared_ptr<vmime::body> 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");