# HG changeset patch # User František Kučera # Date 1612696556 -3600 # Node ID 04aa5591eee34ef1bd54e65739a4b2a4fd497eff # Parent 15d9b0ca161a8530795195852f7a3829e82047aa 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) diff -r 15d9b0ca161a -r 04aa5591eee3 src/XMLDocumentConstructor.h --- 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 body) { + std::string fetchBodyText(std::shared_ptr 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 body) { + std::string fetchBodyBinary(std::shared_ptr 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 {