diff --git a/lib/message/mu-message.cc b/lib/message/mu-message.cc index 69d1b942..efaf0fd0 100644 --- a/lib/message/mu-message.cc +++ b/lib/message/mu-message.cc @@ -129,13 +129,28 @@ Message::Message(Message::Options opts, const std::string& text, const std::stri fill_document(*priv_); } -Message::Message(Message&& msg) = default; -Message::Message(Document& doc): + +Message::Message(Message&& other) noexcept +{ + *this = std::move(other); +} + +Message& +Message::operator=(Message&& other) noexcept +{ + if (this != &other) + priv_ = std::move(other.priv_); + + return *this; +} + +Message::Message(Document&& doc): priv_{std::make_unique()} { - priv_->doc = doc; + priv_->doc = std::move(doc); } + Message::~Message() = default; const Mu::Document& diff --git a/lib/message/mu-message.hh b/lib/message/mu-message.hh index 9ac49086..315d7edc 100644 --- a/lib/message/mu-message.hh +++ b/lib/message/mu-message.hh @@ -52,7 +52,17 @@ public: * * @param some other message */ - Message(Message&& msg); + Message(Message&& other) noexcept; + + + /** + * operator= + * + * @param other move some object object + * + * @return + */ + Message& operator=(Message&& other) noexcept; /** * Construct a message based on a path. The maildir is optional; however @@ -85,14 +95,15 @@ public: * * @return a message or an error */ - static Result make_from_document(Document& doc) try { - return Ok(Message{doc}); + static Result make_from_document(Xapian::Document&& doc) try { + return Ok(Message{Mu::Document{std::move(doc)}}); } catch (Error& err) { return Err(err); } catch (...) { return Err(Mu::Error(Error::Code::Message, "failed to create message")); } + /** * Construct a message from a string. This is mostly useful for testing. * @@ -340,13 +351,12 @@ public: */ bool has_mime_message() const; - struct Private; private: Message(Options opts, const std::string& path, const std::string& mdir); Message(Options opts, const std::string& str, const std::string& path, const std::string& mdir); - Message(Document& doc); + Message(Document&& doc); std::unique_ptr priv_; }; // Message