diff options
| author | Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> | 2025-05-21 20:18:43 +0300 |
|---|---|---|
| committer | Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> | 2025-05-24 17:17:00 +0300 |
| commit | f75e1203d4ba94ac405aa4cf7dc405a4a263133e (patch) | |
| tree | 637927222df5682135e9fc4c811483ca5933bfbb /mu | |
| parent | ef71b5372f444777d40fcf6a5418c757755b1276 (diff) | |
mu: rename --my-address into --personal-address
This makes things a bit more uniform with all the places where we use
"personal".
--my-address remains as an alias for the command-line option.
Add unit test.
Resolves #2806.
Diffstat (limited to 'mu')
| -rw-r--r-- | mu/mu-cmd-init.cc | 39 | ||||
| -rw-r--r-- | mu/mu-options.cc | 6 | ||||
| -rw-r--r-- | mu/mu-options.hh | 2 |
3 files changed, 41 insertions, 6 deletions
diff --git a/mu/mu-cmd-init.cc b/mu/mu-cmd-init.cc index 26a9600..8463ce7 100644 --- a/mu/mu-cmd-init.cc +++ b/mu/mu-cmd-init.cc @@ -1,5 +1,5 @@ /* -** Copyright (C) 2023 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> +** Copyright (C) 2023-2025 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> ** ** This program is free software; you can redistribute it and/or modify it ** under the terms of the GNU General Public License as published by the @@ -56,8 +56,8 @@ Mu::mu_cmd_init(const Options& opts) conf.set<Config::Id::MaxMessageSize>(*opts.init.max_msg_size); if (opts.init.batch_size && *opts.init.batch_size != 0) conf.set<Config::Id::BatchSize>(*opts.init.batch_size); - if (!opts.init.my_addresses.empty()) - conf.set<Config::Id::PersonalAddresses>(opts.init.my_addresses); + if (!opts.init.personal_addresses.empty()) + conf.set<Config::Id::PersonalAddresses>(opts.init.personal_addresses); if (!opts.init.ignored_addresses.empty()) conf.set<Config::Id::IgnoredAddresses>(opts.init.ignored_addresses); if (opts.init.support_ngrams) @@ -130,6 +130,38 @@ test_mu_init_maildir() assert_equal(store.root_maildir(), MU_TESTMAILDIR2); } + +static void +test_mu_init_personal() +{ + TempDir temp_dir{}; + + const auto mu_home{temp_dir.path()}; + + g_setenv("MAILDIR", MU_TESTMAILDIR2, 1); + auto res1 = run_command({MU_PROGRAM, "--quiet", "init", + "--muhome", mu_home, "--personal-address", "foo@example.com", + "--my-address", "bar@example.com", // backward compat + "--personal-address", "/h.llo@example\\.com/"}); + assert_valid_command(res1); + + auto&& store = unwrap(Store::make(join_paths(temp_dir.path(), "xapian"))); + g_assert_true(store.empty()); + assert_equal(store.root_maildir(), MU_TESTMAILDIR2); + + const auto& ccache{store.contacts_cache()}; + + // just some basic tests to see the parameters made it through. + + g_assert_true(ccache.is_personal("foo@example.com")); + g_assert_true(ccache.is_personal("bar@example.com")); + g_assert_true(ccache.is_personal("hello@example.com")); + g_assert_true(ccache.is_personal("hallo@example.com")); + + g_assert_false(ccache.is_personal("faa@example.com")); + g_assert_false(ccache.is_personal("baa@example.com")); +} + int main(int argc, char* argv[]) { @@ -137,6 +169,7 @@ main(int argc, char* argv[]) g_test_add_func("/cmd/init/basic", test_mu_init_basic); g_test_add_func("/cmd/init/maildir", test_mu_init_maildir); + g_test_add_func("/cmd/init/personal", test_mu_init_personal); return g_test_run(); } diff --git a/mu/mu-options.cc b/mu/mu-options.cc index 1b58a28..2b96932 100644 --- a/mu/mu-options.cc +++ b/mu/mu-options.cc @@ -465,8 +465,9 @@ sub_init(CLI::App& sub, Options& opts) ->transform(ExpandPath, "expand maildir path"); // don't attempt to canonicalize; in bash this breaks together with // expand path. - sub.add_option("--my-address", opts.init.my_addresses, - "Personal e-mail address or regexp") + sub.add_option("--personal-address,--my-address", + opts.init.personal_addresses, + "Personal e-mail address or regexp (can be used multiple titmes)") ->type_name("<address>"); sub.add_option("--ignored-address", opts.init.ignored_addresses, "Ignored e-mail address or regexp") @@ -481,6 +482,7 @@ sub_init(CLI::App& sub, Options& opts) sub.add_flag("--reinit", opts.init.reinit, "Re-initialize database with current settings") ->excludes("--maildir") + ->excludes("--personal-address") ->excludes("--my-address") ->excludes("--ignored-address") ->excludes("--max-message-size") diff --git a/mu/mu-options.hh b/mu/mu-options.hh index 6439812..bd5799a 100644 --- a/mu/mu-options.hh +++ b/mu/mu-options.hh @@ -188,7 +188,7 @@ struct Options { */ struct Init { std::string maildir; /**< where the mails are */ - StringVec my_addresses; /**< personal e-mail addresses */ + StringVec personal_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 */ |
