2020-06-23 14:56:20 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.mu;
|
|
|
|
|
|
|
|
# Used to generate command line arguments that mu can operate with.
|
|
|
|
genCmdMaildir = path: "--maildir=" + path;
|
|
|
|
|
|
|
|
# Takes the list of accounts with mu.enable = true, and generates a
|
|
|
|
# command-line flag for initializing the mu database.
|
|
|
|
myAddresses = let
|
|
|
|
# List of account sets where mu.enable = true.
|
|
|
|
muAccounts =
|
|
|
|
filter (a: a.mu.enable) (attrValues config.accounts.email.accounts);
|
|
|
|
addrs = map (a: a.address) muAccounts;
|
|
|
|
# Prefix --my-address= to each account's address with mu.enable.
|
|
|
|
addMyAddress = map (addr: "--my-address=" + addr) addrs;
|
|
|
|
in concatStringsSep " " addMyAddress;
|
|
|
|
|
|
|
|
in {
|
|
|
|
meta.maintainers = [ maintainers.KarlJoad ];
|
|
|
|
|
|
|
|
options = {
|
|
|
|
programs.mu = {
|
|
|
|
enable = mkEnableOption "mu, a maildir indexer and searcher";
|
|
|
|
|
|
|
|
# No options/config file present for mu, and program author will not be
|
|
|
|
# adding one soon. See https://github.com/djcb/mu/issues/882 for more
|
|
|
|
# information about this.
|
|
|
|
};
|
|
|
|
|
|
|
|
accounts.email.accounts = mkOption {
|
|
|
|
type = with types;
|
|
|
|
attrsOf
|
|
|
|
(submodule { options.mu.enable = mkEnableOption "mu indexing"; });
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
home.packages = [ pkgs.mu ];
|
|
|
|
|
|
|
|
home.activation.runMuInit = let
|
|
|
|
maildirOption = genCmdMaildir config.accounts.email.maildirBasePath;
|
|
|
|
dbLocation = config.xdg.cacheHome + "/mu";
|
|
|
|
in hm.dag.entryAfter [ "writeBoundary" ] ''
|
|
|
|
# If the database directory exists, then `mu init` should NOT be run.
|
|
|
|
# In theory, mu is the only thing that creates that directory, and it is
|
|
|
|
# only created during the initial index.
|
|
|
|
if [[ ! -d "${dbLocation}" ]]; then
|
mu: fix command (#1623)
mu-cfind is meant to search for contacts within your contacts database and the emails that you have sent/received. The use of the --personal flag in that command is meant to filter for only emails that use your email addresses (which are all the ones you specify with the ${myAddresses} variable. Disregard what I said in #1623 (comment).
--my-address=<my-email-address>
specifies that some e-mail addresses are 'my-address' (--my-address can be used multiple times).
This is used by mu cfind -- any e-mail address found in the address fields of a message which also
has <my-email-address> in one of its address fields is considered a personal e-mail address. This
allows you, for example, to filter out (mu cfind --personal) addresses which were merely seen in
mailing list messages.
To initialize the database with mu init, the ${myAddresses} is not required to be passed to successfully initialize the database, but it is heavily recommended to do so.
To see the difference, in a safe location, run mu init --maildir=<path>, then mu index. You'll notice that "personal addresses" returns <none>, although the database will still work. However, mu cfind --personal will fail (as the personal contacts don't exist). Then run mu init --maildir=<path> --my-address=<address>, then mu index. Then you'll be able to search for contacts using mu cfind --personal.
2021-01-19 19:36:31 +01:00
|
|
|
$DRY_RUN_CMD mu init ${maildirOption} ${myAddresses} $VERBOSE_ARG;
|
2020-06-23 14:56:20 +02:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|