src/XMLDocumentConstructor.h
branchv_0
changeset 4 dd8ff58fb29b
parent 3 e2d61907e75f
child 5 a3794fe5ea4b
equal deleted inserted replaced
3:e2d61907e75f 4:dd8ff58fb29b
    53 
    53 
    54 	std::string format(const vmime::mediaType& contentType) {
    54 	std::string format(const vmime::mediaType& contentType) {
    55 		return contentType.getType() + "/" + contentType.getSubType();
    55 		return contentType.getType() + "/" + contentType.getSubType();
    56 	}
    56 	}
    57 
    57 
       
    58 	std::string fetchBody(std::shared_ptr<vmime::body> body) {
       
    59 		std::stringstream result;
       
    60 		vmime::utility::outputStreamAdapter resultAdapter(result);
       
    61 
       
    62 		const vmime::charset targetEncoding = vmime::charset("utf-8");
       
    63 		const vmime::charset sourceEncoding = body->getCharset();
       
    64 
       
    65 		vmime::shared_ptr <vmime::charsetConverter> charsetConverter = vmime::charsetConverter::create(sourceEncoding, targetEncoding);
       
    66 		vmime::shared_ptr <vmime::utility::charsetFilteredOutputStream> resultConverter = charsetConverter->getFilteredOutputStream(resultAdapter);
       
    67 
       
    68 		body->getContents()->extract(*resultConverter);
       
    69 		resultConverter->flush();
       
    70 
       
    71 		return result.str();
       
    72 	}
       
    73 
    58 	void appendBody(xmlpp::Element* element, std::shared_ptr<vmime::body> body) {
    74 	void appendBody(xmlpp::Element* element, std::shared_ptr<vmime::body> body) {
    59 		element->set_attribute("content-type", format(body->getContentType()));
    75 		element->set_attribute("content-type", format(body->getContentType()));
       
    76 		// element->set_attribute("content-type-charset", body->getCharset().getName());
       
    77 		// element->set_attribute("content-transfer-encoding", body->getEncoding().getName());
    60 
    78 
    61 		if (body->getPartCount() == 0) {
    79 		if (body->getPartCount() == 0) {
    62 			element->add_child_cdata("TODO: here will be body/part content");
    80 			element->add_child_cdata(fetchBody(body));
    63 		} else {
    81 		} else {
    64 			for (auto part : body->getPartList()) {
    82 			for (auto part : body->getPartList()) {
    65 				xmlpp::Element* partElement = element->add_child("part");
    83 				xmlpp::Element* partElement = element->add_child("part");
    66 				appendBody(partElement, part->getBody());
    84 				appendBody(partElement, part->getBody());
    67 			}
    85 			}