--- 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<vmime::datetime>()) {
+ // 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<vmime::mediaType>()) {
- 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<vmime::messageId>()) {
- field->set_attribute("left", value->getLeft());
- field->set_attribute("right", value->getRight());
field->add_child_text(value->getId());
} else if (auto value = mimeField->getValue<vmime::messageIdSequence>()) {
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<vmime::contentDisposition>()) {
@@ -149,17 +146,26 @@
} else if (auto value = mimeField->getValue<vmime::path>()) {
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<vmime::encoding>()) {
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()));
+ }
+
}
};