mirror of https://github.com/djcb/mu.git
message: Don't assume there's a sub-message
Also add unit-test. Fixes: issue #2256.
This commit is contained in:
parent
9062b9d67f
commit
eb22ec450c
|
@ -67,7 +67,10 @@ MessagePart::cooked_filename() const noexcept
|
|||
// MimeMessagepart. Construct a name based on subject.
|
||||
if (mime_object().is_message_part()) {
|
||||
auto msg{MimeMessagePart{mime_object()}.get_message()};
|
||||
return msg.subject()
|
||||
if (!msg)
|
||||
return Nothing;
|
||||
else
|
||||
return msg->subject()
|
||||
.map(cleanup)
|
||||
.value_or("no-subject") + ".eml";
|
||||
}
|
||||
|
|
|
@ -417,7 +417,10 @@ process_message_part(const MimeMessagePart& msg_part,
|
|||
Message::Private& info)
|
||||
{
|
||||
auto submsg{msg_part.get_message()};
|
||||
submsg.for_each([&](auto&& parent, auto&& child_obj) {
|
||||
if (!submsg)
|
||||
return;
|
||||
|
||||
submsg->for_each([&](auto&& parent, auto&& child_obj) {
|
||||
|
||||
/* XXX: we only handle one level */
|
||||
|
||||
|
|
|
@ -1182,11 +1182,14 @@ public:
|
|||
/**
|
||||
* Get the MimeMessage for this MimeMessagePart.
|
||||
*
|
||||
* @return the MimeMessage
|
||||
* @return the MimeMessage or Nothing
|
||||
*/
|
||||
MimeMessage get_message() const {
|
||||
return MimeMessage(
|
||||
Object(G_OBJECT(g_mime_message_part_get_message(self()))));
|
||||
Option<MimeMessage> get_message() const {
|
||||
auto msg{g_mime_message_part_get_message(self())};
|
||||
if (msg)
|
||||
return MimeMessage(Object(G_OBJECT(msg)));
|
||||
else
|
||||
return Nothing;
|
||||
}
|
||||
private:
|
||||
GMimeMessagePart* self() const {
|
||||
|
|
|
@ -456,6 +456,22 @@ C0bdoCx44QVU8HaZ2x91h3GoM/0q5bqM/rvCauwbokiJgAUrznecNPY=
|
|||
g_assert_cmpuint(n, ==, 1);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_message_multipart_mixed_rfc822(void)
|
||||
{
|
||||
constexpr const char *msgtext =
|
||||
R"(Content-Type: multipart/mixed;
|
||||
boundary="Multipart_Tue_Sep__2_15:42:35_2014-1"
|
||||
|
||||
--Multipart_Tue_Sep__2_15:42:35_2014-1
|
||||
Content-Type: message/rfc822
|
||||
)";
|
||||
auto message{Message::make_from_text(msgtext)};
|
||||
g_assert_true(!!message);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
|
@ -469,6 +485,8 @@ main(int argc, char* argv[])
|
|||
test_message_signed);
|
||||
g_test_add_func("/message/message/signed-encrypted",
|
||||
test_message_signed_encrypted);
|
||||
g_test_add_func("/message/message/multipart-mixed-rfc822",
|
||||
test_message_multipart_mixed_rfc822);
|
||||
|
||||
return g_test_run();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue