nixos/home/accounts/email.nix

167 lines
4.9 KiB
Nix

{
config,
lib,
pkgs,
hostName,
...
}: {
home.packages = with pkgs; [davmail];
accounts.email = {
maildirBasePath = "Mail";
accounts = let
realName = "Evie Litherland-Smith";
in {
proton = let
host = "127.0.0.1";
tls.enable = false;
accountEnabled = true;
in rec {
inherit realName;
primary = lib.mkDefault true;
maildir.path = "Proton";
imap = {
inherit host tls;
port = 1143;
};
smtp = {
inherit host tls;
port = 1025;
};
address = "e.litherlandsmith@proton.me";
aliases = ["evie@xenia.me.uk" "evie@litherlandsmith.slmail.me"];
userName = address;
passwordCommand = "${pkgs.pass}/bin/pass show mbsync/${hostName}/proton | head -n1";
mbsync = {
enable = lib.mkDefault accountEnabled;
create = "both";
expunge = "both";
remove = "both";
patterns = ["*" "!All Mail" "!Labels*" "!Starred" "!Recovered Messages"];
subFolders = "Verbatim";
extraConfig.account.AuthMechs = "LOGIN";
};
msmtp = {
enable = lib.mkDefault accountEnabled;
extraConfig = {
tls = "off";
auth = "login";
};
};
mu.enable = lib.mkDefault accountEnabled;
};
icloud = let
accountEnabled = true;
in rec {
inherit realName;
primary = lib.mkDefault false;
maildir.path = "iCloud";
imap.host = "imap.mail.me.com";
smtp.host = "smtp.mail.me.com";
address = "e.litherlandsmith@icloud.com";
userName = address;
passwordCommand = "${pkgs.pass}/bin/pass show mbsync/${hostName}/icloud | head -n1";
mbsync = {
enable = lib.mkDefault accountEnabled;
create = "both";
expunge = "both";
remove = "both";
patterns = ["*" "!Notes"];
subFolders = "Verbatim";
};
msmtp.enable = lib.mkDefault accountEnabled;
mu.enable = lib.mkDefault accountEnabled;
};
outlook = let
host = "127.0.0.1";
tls.enable = false;
accountEnabled = true;
in rec {
inherit realName;
primary = lib.mkDefault false;
maildir.path = "Outlook";
imap = {
inherit host tls;
port = 1144;
};
smtp = {
inherit host tls;
port = 1026;
};
address = "evie.litherland-smith@ukaea.uk";
aliases = ["elitherl@jet.uk"];
userName = address;
passwordCommand = "${pkgs.pass}/bin/pass show mbsync/${hostName}/outlook | head -n1";
mbsync = {
enable = lib.mkDefault accountEnabled;
create = "both";
expunge = "both";
remove = "both";
patterns = [
"*"
"!Conversation History"
"!Snoozed"
"!Social Activity Notifications"
"!Sync Issues*"
"!Unsent Messages"
];
subFolders = "Verbatim";
extraConfig.account.AuthMechs = "LOGIN";
};
msmtp = {
enable = lib.mkDefault accountEnabled;
extraConfig = {
tls = "off";
auth = "login";
};
};
mu.enable = lib.mkDefault accountEnabled;
};
};
};
programs = {
mu.enable = true;
msmtp.enable = true;
mbsync = {
enable = true;
groups.inboxes = {
proton = ["INBOX"];
icloud = ["INBOX"];
outlook = ["INBOX"];
};
};
};
systemd.user.services = let
emailAccounts = config.accounts.email.accounts;
in {
protonmail-bridge = lib.mkIf emailAccounts.proton.mbsync.enable {
Unit = {
Description = "Proton Mail Bridge";
Wants = ["network-online.target"];
After = ["network-online.target"];
};
Service = {
Environment = ["PATH=/run/current-system/sw/bin/:$PATH"];
Restart = "always";
ExecStart = "${pkgs.protonmail-bridge}/bin/protonmail-bridge -n";
};
Install.WantedBy = ["default.target"];
};
davmail = lib.mkIf emailAccounts.outlook.mbsync.enable {
Unit = {
Description = "Davmail server";
Wants = ["network-online.target"];
After = ["network-online.target"];
};
Service = {
Environment = ["PATH=/run/current-system/sw/bin/:$PATH"];
Restart = "always";
ExecStartPre = with config.home; ''
/bin/sh -c "if [ ! -f ${homeDirectory}/.davmail.properties ]; then cp ${./.davmail.properties} ${homeDirectory}/.davmail.properties; fi; chmod 644 ${homeDirectory}/.davmail.properties"
'';
ExecStart = "${pkgs.davmail}/bin/davmail -notray ${config.home.homeDirectory}/.davmail.properties";
};
Install.WantedBy = ["default.target"];
};
};
}