message: make maildir optional
This commit is contained in:
@ -66,7 +66,7 @@ struct Message::Private {
|
|||||||
|
|
||||||
static void fill_document(Message::Private& priv);
|
static void fill_document(Message::Private& priv);
|
||||||
|
|
||||||
Message::Message(const std::string& path, const std::string& mdir):
|
Message::Message(const std::string& path, Option<const std::string&> mdir):
|
||||||
priv_{std::make_unique<Private>()}
|
priv_{std::make_unique<Private>()}
|
||||||
{
|
{
|
||||||
if (!g_path_is_absolute(path.c_str()))
|
if (!g_path_is_absolute(path.c_str()))
|
||||||
@ -102,7 +102,6 @@ Message::Message(const std::string& text):
|
|||||||
priv_{std::make_unique<Private>()}
|
priv_{std::make_unique<Private>()}
|
||||||
{
|
{
|
||||||
priv_->doc.add(Field::Id::Size, static_cast<int64_t>(text.size()));
|
priv_->doc.add(Field::Id::Size, static_cast<int64_t>(text.size()));
|
||||||
priv_->doc.add(Field::Id::Path, "");
|
|
||||||
|
|
||||||
init_gmime();
|
init_gmime();
|
||||||
if (auto msg{MimeMessage::make_from_string(text)}; !msg)
|
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.
|
// if there are text parts, gather.
|
||||||
accumulate_text(part, info, *ctype);
|
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,
|
process_message(const MimeMessage& mime_msg, const std::string& path,
|
||||||
Message::Private& info)
|
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
|
/* pseudo-flag --> unread means either NEW or NOT SEEN, just
|
||||||
* for searching convenience */
|
* for searching convenience */
|
||||||
@ -324,6 +320,9 @@ process_message(const MimeMessage& mime_msg, const std::string& path,
|
|||||||
// parts
|
// parts
|
||||||
mime_msg.for_each([&](auto&& parent, auto&& part) {
|
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())
|
if (part.is_part())
|
||||||
process_part(part, info);
|
process_part(part, info);
|
||||||
|
|
||||||
@ -700,8 +699,7 @@ World!
|
|||||||
|
|
||||||
g_assert_true(message->bcc().empty());
|
g_assert_true(message->bcc().empty());
|
||||||
g_assert_true(!message->body_html());
|
g_assert_true(!message->body_html());
|
||||||
assert_equal(message->body_text().value_or(""),
|
assert_equal(message->body_text().value_or(""), R"(Hello,World!)");
|
||||||
R"(Hello,World!)");
|
|
||||||
|
|
||||||
g_assert_true(message->cc().empty());
|
g_assert_true(message->cc().empty());
|
||||||
g_assert_cmpuint(message->date(), ==, 1648145079);
|
g_assert_cmpuint(message->date(), ==, 1648145079);
|
||||||
|
|||||||
@ -23,7 +23,6 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "utils/mu-option.hh"
|
|
||||||
#include "mu-contact.hh"
|
#include "mu-contact.hh"
|
||||||
#include "mu-priority.hh"
|
#include "mu-priority.hh"
|
||||||
#include "mu-flags.hh"
|
#include "mu-flags.hh"
|
||||||
@ -31,6 +30,7 @@
|
|||||||
#include "mu-document.hh"
|
#include "mu-document.hh"
|
||||||
#include "mu-message-part.hh"
|
#include "mu-message-part.hh"
|
||||||
|
|
||||||
|
#include "utils/mu-option.hh"
|
||||||
#include "utils/mu-result.hh"
|
#include "utils/mu-result.hh"
|
||||||
|
|
||||||
namespace Mu {
|
namespace Mu {
|
||||||
@ -45,17 +45,21 @@ public:
|
|||||||
Message(Message&& msg);
|
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 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
|
* ~/Maildir/foo/bar/cur/msg, the maildir would be foo/bar; you can
|
||||||
* pass NULL for this parameter, in which case some maildir-specific
|
* pass NULL for this parameter, in which case some maildir-specific
|
||||||
* information is not available.
|
* information is not available.
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
* @return a message or an error
|
* @return a message or an error
|
||||||
*/
|
*/
|
||||||
static Result<Message> make_from_path(const std::string& path, const std::string& mdir) try {
|
static Result<Message> make_from_path(const std::string& path,
|
||||||
|
Option<const std::string&> mdir={}) try {
|
||||||
return Ok(Message{path, mdir});
|
return Ok(Message{path, mdir});
|
||||||
} catch (Error& err) {
|
} catch (Error& err) {
|
||||||
return Err(err);
|
return Err(err);
|
||||||
@ -296,7 +300,7 @@ public:
|
|||||||
|
|
||||||
struct Private;
|
struct Private;
|
||||||
private:
|
private:
|
||||||
Message(const std::string& path, const std::string& mdir);
|
Message(const std::string& path, Option<const std::string&> mdir);
|
||||||
Message(const std::string& str);
|
Message(const std::string& str);
|
||||||
Message(Document& doc);
|
Message(Document& doc);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user