cli: support --ignored-address for init command

Allow for skipping unwanted addresses (such as 'noreply') from the
contacts cache.
This commit is contained in:
Dirk-Jan C. Binnema
2023-07-01 19:03:51 +03:00
parent 5dc41ed811
commit c4b5795328
7 changed files with 44 additions and 14 deletions

View File

@ -49,7 +49,6 @@ Mu::mu_cmd_info(const Mu::Store& store, const Options& opts)
return "never";
else
return time_to_string("%c", t);
};
Table info;
@ -61,8 +60,11 @@ Mu::mu_cmd_info(const Mu::Store& store, const Options& opts)
info.add_row({"max-message-size", format("%zu", conf.get<Config::Id::MaxMessageSize>())});
info.add_row({"batch-size", format("%zu", conf.get<Config::Id::BatchSize>())});
info.add_row({"created", tstamp(conf.get<Config::Id::Created>())});
for (auto&& c : conf.get<Config::Id::PersonalAddresses>())
info.add_row({"personal-address", c});
for (auto&& c : conf.get<Config::Id::IgnoredAddresses>())
info.add_row({"ignored-address", c});
info.add_row({"messages in store", format("%zu", store.size())});
info.add_row({"last-change", tstamp(store.statistics().last_change)});

View File

@ -46,10 +46,15 @@ Mu::mu_cmd_init(const Options& opts)
MemDb mdb;
Config conf{mdb};
if (opts.init.max_msg_size)
conf.set<Config::Id::MaxMessageSize>(*opts.init.max_msg_size);
if (opts.init.batch_size)
conf.set<Config::Id::MaxMessageSize>(*opts.init.batch_size);
if (!opts.init.my_addresses.empty())
conf.set<Config::Id::PersonalAddresses>(opts.init.my_addresses);
if (!opts.init.ignored_addresses.empty())
conf.set<Config::Id::IgnoredAddresses>(opts.init.ignored_addresses);
return Store::make_new(opts.runtime_path(RuntimePath::XapianDb),
opts.init.maildir, conf);
@ -67,4 +72,3 @@ Mu::mu_cmd_init(const Options& opts)
return Ok();
}

View File

@ -383,8 +383,12 @@ sub_init(CLI::App& sub, Options& opts)
"Top of the maildir")
->type_name("<maildir>");
sub.add_option("--my-address", opts.init.my_addresses,
"Personal e-mail addresses")
"Personal e-mail address or regexp")
->type_name("<address>");
sub.add_option("--ignored-address", opts.init.ignored_addresses,
"Ignored e-mail address or regexp")
->type_name("<address>");
sub.add_option("--max-message-size", opts.init.max_msg_size,
"Maximum allowed message size in bytes");
sub.add_option("--batch-size", opts.init.batch_size,
@ -393,6 +397,7 @@ sub_init(CLI::App& sub, Options& opts)
"Re-initialize database with current settings")
->excludes("--maildir")
->excludes("--my-address")
->excludes("--ignored-address")
->excludes("--max-message-size")
->excludes("--batch-size");
}

View File

@ -184,6 +184,8 @@ struct Options {
struct Init {
std::string maildir; /**< where the mails are */
StringVec my_addresses; /**< personal e-mail addresses */
StringVec ignored_addresses; /**< addresses to be ignored for
* the contacts-cache */
OptSize max_msg_size; /**< max size for message files */
OptSize batch_size; /**< db transaction batch size */
bool reinit; /**< re-initialize */