diff --git a/lib/message/mu-mime-object.cc b/lib/message/mu-mime-object.cc index d0fceaf6..a8960b7e 100644 --- a/lib/message/mu-mime-object.cc +++ b/lib/message/mu-mime-object.cc @@ -98,6 +98,34 @@ MimeObject::header(const std::string& hdr) const noexcept } +std::vector> +MimeObject::headers() const noexcept +{ + GMimeHeaderList *lst; + + lst = g_mime_object_get_header_list(self()); /* _not_ owned */ + if (!lst) + return {}; + + std::vector> hdrs; + const auto hdr_num{g_mime_header_list_get_count(lst)}; + + for (int i = 0; i != hdr_num; ++i) { + GMimeHeader *hdr{g_mime_header_list_get_header_at(lst, i)}; + if (!hdr) /* ^^^ _not_ owned */ + continue; + const auto name{g_mime_header_get_name(hdr)}; + const auto val{g_mime_header_get_value(hdr)}; + if (!name || !val) + continue; + hdrs.emplace_back(name, val); + } + + return hdrs; +} + + + Result MimeObject::write_to_stream(const MimeFormatOptions& f_opts, MimeStream& stream) const @@ -379,8 +407,7 @@ MimeMessage::references() const noexcept // is ref already in the list? auto is_dup = [](auto&& seq, const std::string& ref) { - return seq_find_if(seq, [&](auto&& str) { return ref == str; }) - != seq.cend(); + return seq_some(seq, [&](auto&& str) { return ref == str; }); }; std::vector refs; diff --git a/lib/message/mu-mime-object.hh b/lib/message/mu-mime-object.hh index a966855f..1eee7567 100644 --- a/lib/message/mu-mime-object.hh +++ b/lib/message/mu-mime-object.hh @@ -771,6 +771,15 @@ public: */ Option header(const std::string& header) const noexcept; + + /** + * Get all headers as pairs of name, value + * + * @return all headers + */ + std::vector> headers() const noexcept; + + /** * Get the content type *