From 3810964a38a9148bd0d46f9e91262167613a9805 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Mon, 28 Mar 2022 22:38:37 +0300 Subject: [PATCH] message: make maildir optional --- lib/message/mu-message.cc | 14 ++++++-------- lib/message/mu-message.hh | 14 +++++++++----- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/message/mu-message.cc b/lib/message/mu-message.cc index 3b325d4b..826ce9f4 100644 --- a/lib/message/mu-message.cc +++ b/lib/message/mu-message.cc @@ -66,7 +66,7 @@ struct Message::Private { static void fill_document(Message::Private& priv); -Message::Message(const std::string& path, const std::string& mdir): +Message::Message(const std::string& path, Option mdir): priv_{std::make_unique()} { if (!g_path_is_absolute(path.c_str())) @@ -102,7 +102,6 @@ Message::Message(const std::string& text): priv_{std::make_unique()} { priv_->doc.add(Field::Id::Size, static_cast(text.size())); - priv_->doc.add(Field::Id::Path, ""); init_gmime(); if (auto msg{MimeMessage::make_from_string(text)}; !msg) @@ -297,9 +296,6 @@ process_part(const MimePart& part, Message::Private& info) // if there are text parts, gather. accumulate_text(part, info, *ctype); - - //MimePart mypart(part); - info.parts.emplace_back(part); } /** @@ -314,7 +310,7 @@ static void process_message(const MimeMessage& mime_msg, const std::string& path, Message::Private& info) { - info.flags = Flags::None; //mu_maildir_flags_from_path(path).value_or(Flags::None); + info.flags = flags_from_path(path).value_or(Flags::None); /* pseudo-flag --> unread means either NEW or NOT SEEN, just * for searching convenience */ @@ -324,6 +320,9 @@ process_message(const MimeMessage& mime_msg, const std::string& path, // parts mime_msg.for_each([&](auto&& parent, auto&& part) { + if (part.is_part() || part.is_message_part()) + info.parts.emplace_back(part); + if (part.is_part()) process_part(part, info); @@ -700,8 +699,7 @@ World! g_assert_true(message->bcc().empty()); g_assert_true(!message->body_html()); - assert_equal(message->body_text().value_or(""), -R"(Hello,World!)"); + assert_equal(message->body_text().value_or(""), R"(Hello,World!)"); g_assert_true(message->cc().empty()); g_assert_cmpuint(message->date(), ==, 1648145079); diff --git a/lib/message/mu-message.hh b/lib/message/mu-message.hh index 72e44a95..47b4a29e 100644 --- a/lib/message/mu-message.hh +++ b/lib/message/mu-message.hh @@ -23,7 +23,6 @@ #include #include #include -#include "utils/mu-option.hh" #include "mu-contact.hh" #include "mu-priority.hh" #include "mu-flags.hh" @@ -31,6 +30,7 @@ #include "mu-document.hh" #include "mu-message-part.hh" +#include "utils/mu-option.hh" #include "utils/mu-result.hh" namespace Mu { @@ -45,17 +45,21 @@ public: Message(Message&& msg); /** - * Construct a message based on a path + * Construct a message based on a path. The maildir is optional; however + * messages without maildir cannot be stored in the database * * @param path path to message - * @param mdir the maildir for this message; ie, if the path is + * @param mdir the maildir for this message; i.e, if the path is * ~/Maildir/foo/bar/cur/msg, the maildir would be foo/bar; you can * pass NULL for this parameter, in which case some maildir-specific * information is not available. * + * + * * @return a message or an error */ - static Result make_from_path(const std::string& path, const std::string& mdir) try { + static Result make_from_path(const std::string& path, + Option mdir={}) try { return Ok(Message{path, mdir}); } catch (Error& err) { return Err(err); @@ -296,7 +300,7 @@ public: struct Private; private: - Message(const std::string& path, const std::string& mdir); + Message(const std::string& path, Option mdir); Message(const std::string& str); Message(Document& doc);