Merge pull request #241 from 0xd34df00d/body_type_parsing

Body type parsing
This commit is contained in:
Vincent Richard 2020-08-09 11:02:53 +02:00 committed by GitHub
commit 4c330bc623
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -52,6 +52,21 @@ IMAPMessagePart::IMAPMessagePart(
);
}
namespace {
template<typename T>
vmime::string getPartName(const T& body_type) {
if (const auto* pparam = body_type->body_fields->body_fld_param.get()) {
for (const auto& param : pparam->items) {
if (param->string1->value == "NAME") {
return param->string2->value;
}
}
}
return {};
}
}
IMAPMessagePart::IMAPMessagePart(
const shared_ptr <IMAPMessagePart>& parent,
@ -72,6 +87,8 @@ IMAPMessagePart::IMAPMessagePart(
m_size = part->body_type_text->body_fields->body_fld_octets->value;
m_name = getPartName(part->body_type_text);
} else if (part->body_type_msg) {
m_mediaType = vmime::mediaType(
@ -88,19 +105,13 @@ IMAPMessagePart::IMAPMessagePart(
m_size = part->body_type_basic->body_fields->body_fld_octets->value;
if (const auto* pparam = part->body_type_basic->body_fields->body_fld_param.get()) {
for (const auto& param : pparam->items) {
if (param->string1->value == "NAME") {
m_name = param->string2->value;
}
}
}
m_name = getPartName(part->body_type_basic);
}
if (part->body_ext_1part && part->body_ext_1part->body_fld_dsp) {
auto *cdisp = part->body_ext_1part->body_fld_dsp->str();
if (cdisp) {
m_dispType = contentDisposition(cdisp->value);
}
if (part->body_ext_1part && part->body_ext_1part->body_fld_dsp) {
auto *cdisp = part->body_ext_1part->body_fld_dsp->str();
if (cdisp) {
m_dispType = contentDisposition(cdisp->value);
}
}