diff --git a/lib/mu-store.cc b/lib/mu-store.cc index be7694e3..896d2a7f 100644 --- a/lib/mu-store.cc +++ b/lib/mu-store.cc @@ -376,6 +376,27 @@ Store::set_dirstamp (const std::string& path, time_t tstamp) } +MuMsg* +Store::find_message (unsigned docid) const +{ + LOCKED; + + try { + Xapian::Document *doc{new Xapian::Document{priv_->db()->get_document (docid)}}; + GError *gerr{}; + auto msg{mu_msg_new_from_doc (reinterpret_cast(doc), &gerr)}; + if (!msg) { + g_warning ("could not create message: %s", gerr ? gerr->message : + "something went wrong"); + g_clear_error(&gerr); + } + + return msg; + + } MU_XAPIAN_CATCH_BLOCK_RETURN (nullptr); +} + + bool Store::contains_message (const std::string& path) const { @@ -633,6 +654,9 @@ mu_store_get_read_only_database (MuStore *store) return (XapianWritableDatabase*)self(store)->priv()->db().get(); } + + + gboolean mu_store_contains_message (const MuStore *store, const char* path) { @@ -709,13 +733,7 @@ mu_store_get_msg (const MuStore *store, unsigned docid, GError **err) g_return_val_if_fail (store, NULL); g_return_val_if_fail (docid != 0, NULL); - try { - Xapian::Document *doc = - new Xapian::Document - (self(store)->priv()->db()->get_document (docid)); - return mu_msg_new_from_doc ((XapianDocument*)doc, err); - - } MU_XAPIAN_CATCH_BLOCK_G_ERROR_RETURN (err, MU_ERROR_XAPIAN, 0); + return self(store)->find_message(docid); } @@ -1388,7 +1406,6 @@ mu_store_get_dirstamp (const MuStore *store, const char *dirpath, GError **err) } -} void mu_store_print_info (const MuStore *store, gboolean nocolor) @@ -1430,3 +1447,4 @@ mu_store_print_info (const MuStore *store, gboolean nocolor) g_strfreev(addrs); } +} diff --git a/lib/mu-store.hh b/lib/mu-store.hh index bab4c457..c2e4a5cf 100644 --- a/lib/mu-store.hh +++ b/lib/mu-store.hh @@ -20,6 +20,8 @@ #ifndef __MU_STORE_HH__ #define __MU_STORE_HH__ +#include + #ifdef __cplusplus #include "mu-contacts.hh" @@ -129,6 +131,14 @@ public: */ bool remove_message (const std::string& path); + /** + * Fina message in the store. + * + * @param docid doc id for the message to find + * + * @return a message (owned by caller), or nullptr + */ + MuMsg* find_message (unsigned docid) const; /** * does a certain message exist in the store already? @@ -215,7 +225,6 @@ private: #include #include -#include #include #include