# HG changeset patch # User František Kučera # Date 1612084452 -3600 # Node ID e2d61907e75fafd4c1a161f90fcd43926e31630c # Parent d04d7713344c3b1f39ed488ba22162b08bcc370f process body/parts recursively diff -r d04d7713344c -r e2d61907e75f 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 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()); } };