1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2024-12-14 11:57:55 +00:00

accounts/email: provide realName option for alias

This commit is contained in:
eum3l 2024-11-18 20:58:31 +01:00
parent f3a2ff6958
commit 04f1430140
3 changed files with 36 additions and 12 deletions

View file

@ -267,10 +267,26 @@ let
};
aliases = mkOption {
type = types.listOf (types.strMatching ".*@.*");
description = "Alternative identities of this account.";
default = [ ];
example = [ "webmaster@example.org" "admin@example.org" ];
description = "Alternative email addresses of this account.";
type = types.listOf (types.oneOf [
(types.strMatching ".*@.*")
(types.submodule {
options = {
realName = mkOption {
type = types.str;
example = "Jane Doe";
description = "Name displayed when sending mails.";
};
address = mkOption {
type = types.strMatching ".*@.*";
example = "jane.doe@example.org";
description = "The email address of this identity.";
};
};
})
]);
};
realName = mkOption {

View file

@ -19,7 +19,8 @@ let
# Construct list of lists containing email aliases, and flatten
aliases = flatten (map (a: a.aliases) muAccounts);
# Prefix --my-address= to each account's address AND all defined aliases
addMyAddress = map (addr: "--my-address=" + addr) (addrs ++ aliases);
addMyAddress = map (addr: "--my-address=" + addr) (addrs
++ (map (a: if (builtins.isString a) then a else a.address) aliases));
in concatStringsSep " " addMyAddress;
in {

View file

@ -43,16 +43,25 @@ let
};
}));
getId = account: address:
if address == account.address then
account.id
else
(builtins.hashString "sha256" (if (builtins.isString address) then
address
else
(address.address + address.realName)));
toThunderbirdIdentity = account: address:
# For backwards compatibility, the primary address reuses the account ID.
let
id = if address == account.address then
account.id
else
builtins.hashString "sha256" address;
id = getId account address;
addressIsString = builtins.isString address;
in {
"mail.identity.id_${id}.fullName" = account.realName;
"mail.identity.id_${id}.useremail" = address;
"mail.identity.id_${id}.fullName" =
if addressIsString then account.realName else address.realName;
"mail.identity.id_${id}.useremail" =
if addressIsString then address else address.address;
"mail.identity.id_${id}.valid" = true;
"mail.identity.id_${id}.htmlSigText" =
if account.signature.showSignature == "none" then
@ -79,9 +88,7 @@ let
addresses = [ account.address ] ++ account.aliases;
in {
"mail.account.account_${id}.identities" = concatStringsSep ","
([ "id_${id}" ]
++ map (address: "id_${builtins.hashString "sha256" address}")
account.aliases);
(map (address: "id_${getId account address}") addresses);
"mail.account.account_${id}.server" = "server_${id}";
} // optionalAttrs account.primary {
"mail.accountmanager.defaultaccount" = "account_${id}";