mirror of https://github.com/djcb/mu.git
message/document: allow updating flags
Some flags (such as 'personal') can only be set just before storing; so allow for update the flags.
This commit is contained in:
parent
fea596ae3b
commit
a4f39819ee
|
@ -198,12 +198,18 @@ void
|
|||
Document::add(Flags flags)
|
||||
{
|
||||
constexpr auto field{field_from_id(Field::Id::Flags)};
|
||||
const auto old_flags{flags_value()};
|
||||
|
||||
xdoc_.add_value(field.value_no(), to_lexnum(static_cast<int64_t>(flags)));
|
||||
flag_infos_for_each([&](auto&& flag_info) {
|
||||
auto term=[&](){return field.xapian_term(flag_info.shortcut_lower());};
|
||||
if (any_of(flag_info.flag & flags))
|
||||
xdoc_.add_boolean_term(field.xapian_term(
|
||||
flag_info.shortcut_lower()));
|
||||
xdoc_.add_boolean_term(term());
|
||||
else if(any_of(flag_info.flag & old_flags)) {
|
||||
/* field can be _updated_, so clear out any removed flags */
|
||||
xdoc_.remove_term(term());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -198,6 +198,14 @@ Message::set_maildir(const std::string& maildir)
|
|||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
Message::set_flags(Flags flags)
|
||||
{
|
||||
priv_->doc.add(flags);
|
||||
}
|
||||
|
||||
bool
|
||||
Message::load_mime_message(bool reload) const
|
||||
{
|
||||
|
|
|
@ -251,6 +251,16 @@ public:
|
|||
*/
|
||||
Flags flags() const { return document().flags_value(); }
|
||||
|
||||
|
||||
/**
|
||||
* Update the flags for this message. This is useful for flags
|
||||
* that can only be determined after the message has been created already,
|
||||
* such as the 'personal' flag.
|
||||
*
|
||||
* @param flags new flags.
|
||||
*/
|
||||
void set_flags(Flags flags);
|
||||
|
||||
/**
|
||||
* get the message priority for this message. The X-Priority, X-MSMailPriority,
|
||||
* Importance and Precedence header are checked, in that order. if no known or
|
||||
|
|
Loading…
Reference in New Issue