message: Don't assume there's a sub-message

Also add unit-test.

Fixes: issue #2256.
This commit is contained in:
Dirk-Jan C. Binnema
2022-05-12 19:58:08 +03:00
parent 9062b9d67f
commit eb22ec450c
4 changed files with 35 additions and 8 deletions

View File

@ -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 {