92 return result.str(); |
92 return result.str(); |
93 } |
93 } |
94 |
94 |
95 std::string fetchBodyBinary(std::shared_ptr<vmime::body> body) { |
95 std::string fetchBodyBinary(std::shared_ptr<vmime::body> body) { |
96 std::stringstream result; |
96 std::stringstream result; |
97 vmime::utility::outputStreamAdapter binaryResultAdapter(result); |
97 vmime::utility::outputStreamAdapter resultAdapter(result); |
98 body->getContents()->extract(binaryResultAdapter); |
98 body->getContents()->extract(resultAdapter); |
99 binaryResultAdapter.flush(); |
99 resultAdapter.flush(); |
100 return toHex(result.str()); |
100 return toHex(result.str()); |
101 } |
101 } |
102 |
102 |
103 void appendBody(xmlpp::Element* element, std::shared_ptr<vmime::body> body) { |
103 void appendBody(xmlpp::Element* element, std::shared_ptr<vmime::body> body) { |
104 element->set_attribute("content-type", format(body->getContentType())); |
104 element->set_attribute("content-type", format(body->getContentType())); |
105 // element->set_attribute("content-type-charset", body->getCharset().getName()); |
105 // element->set_attribute("content-type-charset", body->getCharset().getName()); |
106 // element->set_attribute("content-transfer-encoding", body->getEncoding().getName()); |
106 // element->set_attribute("content-transfer-encoding", body->getEncoding().getName()); |
|
107 // TODO: size of raw data |
107 |
108 |
108 if (body->getPartCount() == 0) { |
109 if (body->getPartCount() == 0) { |
109 if (body->getContentType().getType() == "text") element->add_child_cdata(fetchBodyText(body)); |
110 if (body->getContentType().getType() == "text") element->add_child_cdata(fetchBodyText(body)); |
110 else element->add_child_text(fetchBodyBinary(body)); |
111 else element->add_child_text(fetchBodyBinary(body)); |
111 // TODO: if content is valid XML, import it in the DOM tree instead of pasting as a nested text/cdata |
112 // TODO: if content is valid XML, import it in the DOM tree instead of pasting as a nested text/cdata |
189 // TODO: encoding from the "Content-Type: text/plain; charset=us-ascii" type header? |
190 // TODO: encoding from the "Content-Type: text/plain; charset=us-ascii" type header? |
190 } else if (auto value = mimeField->getValue<vmime::messageId>()) { |
191 } else if (auto value = mimeField->getValue<vmime::messageId>()) { |
191 field->add_child_text(value->getId()); |
192 field->add_child_text(value->getId()); |
192 } else if (auto value = mimeField->getValue<vmime::messageIdSequence>()) { |
193 } else if (auto value = mimeField->getValue<vmime::messageIdSequence>()) { |
193 for (auto messageId : value->getMessageIdList()) { |
194 for (auto messageId : value->getMessageIdList()) { |
194 xmlpp::Element* messageIdField = field->add_child("Mssage-ID"); // TODO: lower case? |
195 xmlpp::Element* messageIdField = field->add_child("message-id"); |
195 messageIdField->add_child_text(messageId->getId()); |
196 messageIdField->add_child_text(messageId->getId()); |
196 } |
197 } |
197 } else if (auto value = mimeField->getValue<vmime::contentDisposition>()) { |
198 } else if (auto value = mimeField->getValue<vmime::contentDisposition>()) { |
198 field->add_child_text(value->getName()); |
199 field->add_child_text(value->getName()); |
199 } else if (auto value = mimeField->getValue<vmime::relay>()) { |
200 } else if (auto value = mimeField->getValue<vmime::relay>()) { |