diff --git a/lib/message/mu-message-part.cc b/lib/message/mu-message-part.cc index c96e1ef1..94f914bd 100644 --- a/lib/message/mu-message-part.cc +++ b/lib/message/mu-message-part.cc @@ -35,6 +35,14 @@ MessagePart::MessagePart(const MessagePart& other): MessagePart::~MessagePart() = default; +const MimeObject& +MessagePart::mime_object() const noexcept +{ + return *mime_obj; +} + + + Option MessagePart::cooked_filename() const noexcept @@ -55,12 +63,12 @@ MessagePart::cooked_filename() const noexcept }; // a MimePart... use the name if there is one. - if (mime_obj->is_part()) - return MimePart(*mime_obj).filename().map(cleanup); + if (mime_object().is_part()) + return MimePart{mime_object()}.filename().map(cleanup); // MimeMessagepart. Construct a name based on subject. - if (mime_obj->is_message_part()) { - auto msg{MimeMessagePart(*mime_obj).get_message()}; + if (mime_object().is_message_part()) { + auto msg{MimeMessagePart{mime_object()}.get_message()}; return msg.subject() .map(cleanup) .value_or("no-subject") + ".eml"; @@ -73,10 +81,10 @@ return Nothing; Option MessagePart::raw_filename() const noexcept { - if (!mime_obj->is_part()) + if (!mime_object().is_part()) return Nothing; else - return MimePart(*mime_obj).filename(); + return MimePart{mime_object()}.filename(); } @@ -84,7 +92,7 @@ MessagePart::raw_filename() const noexcept Option MessagePart::mime_type() const noexcept { - if (const auto ctype{mime_obj->content_type()}; ctype) + if (const auto ctype{mime_object().content_type()}; ctype) return ctype->media_type() + "/" + ctype->media_subtype(); else return Nothing; @@ -93,29 +101,29 @@ MessagePart::mime_type() const noexcept size_t MessagePart::size() const noexcept { - if (!mime_obj->is_part()) + if (!mime_object().is_part()) return 0; else - return MimePart(*mime_obj).size(); + return MimePart{mime_object()}.size(); } bool MessagePart::is_attachment() const noexcept { - if (!mime_obj->is_part()) + if (!mime_object().is_part()) return false; else - return MimePart(*mime_obj).is_attachment(); + return MimePart{mime_object()}.is_attachment(); } Option MessagePart::to_string() const noexcept { - if (mime_obj->is_part()) - return MimePart(*mime_obj).to_string(); + if (mime_object().is_part()) + return MimePart{mime_object()}.to_string(); else - return mime_obj->object_to_string(); + return mime_object().object_to_string(); } @@ -123,9 +131,15 @@ MessagePart::to_string() const noexcept Result MessagePart::to_file(const std::string& path, bool overwrite) const noexcept { - if (!mime_obj->is_part()) + if (!mime_object().is_part()) return Err(Error::Code::InvalidArgument, "not a part"); else - return MimePart(*mime_obj).to_file(path, overwrite); + return MimePart{mime_object()}.to_file(path, overwrite); +} + +bool +MessagePart::is_signed() const noexcept +{ + return mime_object().is_multipart_signed(); } diff --git a/lib/message/mu-message-part.hh b/lib/message/mu-message-part.hh index 61a30eb3..8d54375c 100644 --- a/lib/message/mu-message-part.hh +++ b/lib/message/mu-message-part.hh @@ -28,7 +28,8 @@ namespace Mu { -class MimeObject; // forward declaration +class MimeObject; // forward declaration; don't want to include for build-time + // reasons. class MessagePart { public: @@ -52,6 +53,15 @@ public: */ ~MessagePart(); + + /** + * Get the underlying MimeObject; you need to include mu-mime-object.hh + * to do anything useful with it. + * + * @return reference to the mime-object + */ + const MimeObject& mime_object() const noexcept; + /** * Filename for the mime-part file. This is a "cooked" filename with * unallowed characters removed. If there's no filename specified, @@ -70,7 +80,6 @@ public: */ Option raw_filename() const noexcept; - /** * Mime-type for the mime-part (e.g. "text/plain") * @@ -94,6 +103,14 @@ public: */ bool is_attachment() const noexcept; + + /** + * Is this part signed? + * + * @return true or false + */ + bool is_signed() const noexcept; + /** * Write (decoded) mime-part contents to string * @@ -113,7 +130,7 @@ public: struct Private; private: - std::unique_ptr mime_obj; + const std::unique_ptr mime_obj; }; } // namespace Mu