# HG changeset patch # User František Kučera # Date 1611962503 -3600 # Node ID d04d7713344c3b1f39ed488ba22162b08bcc370f # Parent 356d0b024abf3760e622145e122d3479fe318191 simplify XML structure + list body parts diff -r 356d0b024abf -r d04d7713344c src/XMLDocumentConstructor.h --- a/src/XMLDocumentConstructor.h Mon Jan 25 22:43:37 2021 +0100 +++ b/src/XMLDocumentConstructor.h Sat Jan 30 00:21:43 2021 +0100 @@ -51,6 +51,10 @@ return timestamp.str(); } + std::string format(const vmime::mediaType& contentType) { + return contentType.getType() + "/" + contentType.getSubType(); + } + public: XMLDocumentConstructor(std::istream* input, xmlpp::DomParser* parser) : input(input), parser(parser) { @@ -110,6 +114,7 @@ } } } else if (auto value = mimeField->getValue()) { + // TODO: keep particular timestamp bits attributes or not? field->set_attribute("year", std::to_string(value->getYear())); field->set_attribute("month", std::to_string(value->getMonth())); field->set_attribute("day", std::to_string(value->getDay())); @@ -119,21 +124,13 @@ field->set_attribute("zone", std::to_string(value->getZone())); // timezone is in minutes field->add_child_text(format(value)); } else if (auto value = mimeField->getValue()) { - std::string type = value->getType(); - std::string subType = value->getSubType(); - if (type.size()) field->set_attribute("type", type); - if (subType.size()) field->set_attribute("subType", subType); - if (type.size() && subType.size()) field->add_child_text(type + "/" + subType); + if (value) field->add_child_text(format(*value)); // TODO: encoding from the "Content-Type: text/plain; charset=us-ascii" type header? } else if (auto value = mimeField->getValue()) { - field->set_attribute("left", value->getLeft()); - field->set_attribute("right", value->getRight()); field->add_child_text(value->getId()); } else if (auto value = mimeField->getValue()) { for (auto messageId : value->getMessageIdList()) { xmlpp::Element* messageIdField = field->add_child("Mssage-ID"); // TODO: lower case? - messageIdField->set_attribute("left", messageId->getLeft()); - messageIdField->set_attribute("right", messageId->getRight()); messageIdField->add_child_text(messageId->getId()); } } else if (auto value = mimeField->getValue()) { @@ -149,17 +146,26 @@ } else if (auto value = mimeField->getValue()) { std::string local = value->getLocalPart(); std::string domain = value->getDomain(); - if (local.size()) field->set_attribute("local", local); - if (domain.size()) field->set_attribute("domain", domain); if (local.size() && domain.size()) field->add_child_text(local + "@" + domain); + else field->add_child_text(local + domain); } else if (auto value = mimeField->getValue()) { field->add_child_text(value->getName()); } else { 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())); + } + } };