add @length attribute: number of bytes of a binary part or a text part encoded in UTF-8 (i.e. not the original lenght in the MIME message)
--- a/src/XMLDocumentConstructor.h Sun Feb 07 00:51:08 2021 +0100
+++ b/src/XMLDocumentConstructor.h Sun Feb 07 12:15:56 2021 +0100
@@ -76,7 +76,7 @@
return result;
}
- std::string fetchBodyText(std::shared_ptr<vmime::body> body) {
+ std::string fetchBodyText(std::shared_ptr<vmime::body> body, size_t& bodyLength) {
std::stringstream result;
vmime::utility::outputStreamAdapter resultAdapter(result);
@@ -88,15 +88,17 @@
body->getContents()->extract(*resultConverter);
resultConverter->flush();
+ bodyLength = result.tellp();
return result.str();
}
- std::string fetchBodyBinary(std::shared_ptr<vmime::body> body) {
+ std::string fetchBodyBinary(std::shared_ptr<vmime::body> body, size_t& bodyLength) {
std::stringstream result;
vmime::utility::outputStreamAdapter resultAdapter(result);
body->getContents()->extract(resultAdapter);
resultAdapter.flush();
+ bodyLength = result.tellp();
return toHex(result.str());
}
@@ -107,8 +109,11 @@
// TODO: size of raw data
if (body->getPartCount() == 0) {
- if (body->getContentType().getType() == "text") element->add_child_cdata(fetchBodyText(body));
- else element->add_child_text(fetchBodyBinary(body));
+ size_t bodyLength = 0;
+ if (body->getContentType().getType() == "text") element->add_child_cdata(fetchBodyText(body, bodyLength));
+ else element->add_child_text(fetchBodyBinary(body, bodyLength));
+ element->set_attribute("length", std::to_string(bodyLength));
+
// TODO: if content is valid XML, import it in the DOM tree instead of pasting as a nested text/cdata
// TODO: optional trim of long data
} else {