From 83a2669a515ff9f9e8566b7fc0d9f4da182863a5 Mon Sep 17 00:00:00 2001 From: 0xd34df00d <0xd34df00d@gmail.com> Date: Sat, 8 Aug 2020 12:44:03 -0400 Subject: [PATCH 1/3] Refactor out getPartName() --- src/vmime/net/imap/IMAPMessagePart.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/vmime/net/imap/IMAPMessagePart.cpp b/src/vmime/net/imap/IMAPMessagePart.cpp index 746fe9a4..ddb4dd47 100644 --- a/src/vmime/net/imap/IMAPMessagePart.cpp +++ b/src/vmime/net/imap/IMAPMessagePart.cpp @@ -52,6 +52,21 @@ IMAPMessagePart::IMAPMessagePart( ); } +namespace { + template + 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 & parent, @@ -88,13 +103,7 @@ 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(); From 1806e0be0ef5fcb776ae115675255762c01dbacc Mon Sep 17 00:00:00 2001 From: 0xd34df00d <0xd34df00d@gmail.com> Date: Sat, 8 Aug 2020 12:50:53 -0400 Subject: [PATCH 2/3] Text body part can also have a name --- src/vmime/net/imap/IMAPMessagePart.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/vmime/net/imap/IMAPMessagePart.cpp b/src/vmime/net/imap/IMAPMessagePart.cpp index ddb4dd47..1cf662de 100644 --- a/src/vmime/net/imap/IMAPMessagePart.cpp +++ b/src/vmime/net/imap/IMAPMessagePart.cpp @@ -87,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( From c137bc55af7629cd00467c59ab31a2024860cf45 Mon Sep 17 00:00:00 2001 From: 0xd34df00d <0xd34df00d@gmail.com> Date: Sat, 8 Aug 2020 14:46:19 -0400 Subject: [PATCH 3/3] Try obtaining content disposition for all body parts types --- src/vmime/net/imap/IMAPMessagePart.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/vmime/net/imap/IMAPMessagePart.cpp b/src/vmime/net/imap/IMAPMessagePart.cpp index 1cf662de..ed2c0bd2 100644 --- a/src/vmime/net/imap/IMAPMessagePart.cpp +++ b/src/vmime/net/imap/IMAPMessagePart.cpp @@ -106,12 +106,12 @@ IMAPMessagePart::IMAPMessagePart( m_size = part->body_type_basic->body_fields->body_fld_octets->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); } }