process body/parts recursively v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 31 Jan 2021 10:14:12 +0100
branchv_0
changeset 3 e2d61907e75f
parent 2 d04d7713344c
child 4 dd8ff58fb29b
process body/parts recursively
src/XMLDocumentConstructor.h
--- a/src/XMLDocumentConstructor.h	Sat Jan 30 00:21:43 2021 +0100
+++ b/src/XMLDocumentConstructor.h	Sun Jan 31 10:14:12 2021 +0100
@@ -55,6 +55,19 @@
 		return contentType.getType() + "/" + contentType.getSubType();
 	}
 
+	void appendBody(xmlpp::Element* element, std::shared_ptr<vmime::body> body) {
+		element->set_attribute("content-type", format(body->getContentType()));
+
+		if (body->getPartCount() == 0) {
+			element->add_child_cdata("TODO: here will be body/part content");
+		} else {
+			for (auto part : body->getPartList()) {
+				xmlpp::Element* partElement = element->add_child("part");
+				appendBody(partElement, part->getBody());
+			}
+		}
+	}
+
 public:
 
 	XMLDocumentConstructor(std::istream* input, xmlpp::DomParser* parser) : input(input), parser(parser) {
@@ -154,17 +167,11 @@
 				field->add_child_text("TODO: unknown header type"); // TODO: generic conversion as fallback?
 			}
 		}
-		
+
 		// TODO: check null pointers
 
 		xmlpp::Element* body = root->add_child("body");
-
-		body->set_attribute("content-type", format(m.getBody()->getContentType()));
-
-		for (auto part : m.getBody()->getPartList()) {
-			xmlpp::Element* partElement = body->add_child("part");
-			partElement->set_attribute("content-type", format(part->getBody()->getContentType()));
-		}
+		appendBody(body, m.getBody());
 
 	}
 };