From 52042b2b5b8682eab93786e4337bd0cff6e0ab10 Mon Sep 17 00:00:00 2001 From: 0xd34df00d <0xd34df00d@gmail.com> Date: Wed, 4 Jul 2018 16:03:49 -0400 Subject: [PATCH] Added net::message::getName() + the IMAP implementation. --- src/vmime/net/imap/IMAPMessagePart.cpp | 10 ++++++++++ src/vmime/net/imap/IMAPMessagePart.hpp | 2 ++ src/vmime/net/message.cpp | 5 +++++ src/vmime/net/message.hpp | 10 ++++++++++ 4 files changed, 27 insertions(+) diff --git a/src/vmime/net/imap/IMAPMessagePart.cpp b/src/vmime/net/imap/IMAPMessagePart.cpp index 1539f2ca..54c29a9e 100644 --- a/src/vmime/net/imap/IMAPMessagePart.cpp +++ b/src/vmime/net/imap/IMAPMessagePart.cpp @@ -68,6 +68,11 @@ IMAPMessagePart::IMAPMessagePart(shared_ptr parent, const size part->body_type_basic()->media_basic()->media_subtype()->value()); 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()) + for (const auto& param : pparam->items()) + if (param->string1()->value() == "NAME") + m_name = param->string2()->value(); } m_structure = null; @@ -115,6 +120,11 @@ size_t IMAPMessagePart::getNumber() const return m_number; } +string IMAPMessagePart::getName() const +{ + return m_name; +} + shared_ptr IMAPMessagePart::getHeader() const { diff --git a/src/vmime/net/imap/IMAPMessagePart.hpp b/src/vmime/net/imap/IMAPMessagePart.hpp index 3b00887b..2e19f551 100644 --- a/src/vmime/net/imap/IMAPMessagePart.hpp +++ b/src/vmime/net/imap/IMAPMessagePart.hpp @@ -59,6 +59,7 @@ public: const mediaType& getType() const; size_t getSize() const; size_t getNumber() const; + string getName() const; shared_ptr getHeader() const; @@ -77,6 +78,7 @@ private: size_t m_number; size_t m_size; + string m_name; mediaType m_mediaType; }; diff --git a/src/vmime/net/message.cpp b/src/vmime/net/message.cpp index 6765e73c..1a0c8c2c 100644 --- a/src/vmime/net/message.cpp +++ b/src/vmime/net/message.cpp @@ -36,6 +36,11 @@ namespace vmime { namespace net { +string messagePart::getName() const +{ + return {}; +} + shared_ptr messagePart::getPartAt(const size_t pos) const { return getStructure()->getPartAt(pos); diff --git a/src/vmime/net/message.hpp b/src/vmime/net/message.hpp index 4c64a1cf..ae21f2dd 100644 --- a/src/vmime/net/message.hpp +++ b/src/vmime/net/message.hpp @@ -99,6 +99,16 @@ public: */ virtual size_t getNumber() const = 0; + /** Return the name of this part. In particular, this corresponds to + * the attachment file name for attachment parts. + * + * The part name may be empty if the part does not advertise it or + * if the underlying protocol does not support it. + * + * @return part name + */ + virtual string getName() const; + /** Return the sub-part at the specified position (zero is the * first part). *