nixos/home/accounts/email.nix

253 lines
7.7 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, hostName, ... }:
{
home.packages = with pkgs; [ davmail ];
programs = {
msmtp.enable = true;
mbsync = {
enable = true;
groups.inboxes = {
proton = [ "INBOX" ];
icloud = [ "INBOX" ];
2023-10-15 10:02:16 +01:00
outlook = [ "INBOX" ];
};
};
notmuch = {
enable = true;
maildir.synchronizeFlags = true;
new.tags = [ "new" ];
hooks.postNew = ''
if [ $(${pkgs.notmuch}/bin/notmuch count is:new) -gt 0 ]; then
${pkgs.libnotify}/bin/notify-send "Notmuch Email" "Unread emails in inbox"
fi
${pkgs.afew}/bin/afew --new --tag
2023-10-24 22:41:38 +01:00
${pkgs.afew}/bin/afew --move-mail
'';
};
afew = {
enable = true;
extraConfig = builtins.readFile ./afew/config;
};
};
2023-10-01 09:17:45 +01:00
services = {
mbsync = {
enable = true;
2023-10-25 09:12:01 +01:00
frequency = "*:0/15";
postExec = "${pkgs.notmuch}/bin/notmuch new";
2023-10-01 09:17:45 +01:00
};
imapnotify.enable = true;
};
accounts.email = {
2023-10-23 23:55:52 +01:00
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.libsecret}/bin/secret-tool lookup email ${userName}";
imapnotify = {
enable = lib.mkDefault accountEnabled;
boxes = [ "INBOX" ];
onNotify = "${pkgs.isync}/bin/mbsync proton";
onNotifyPost = "${pkgs.notmuch}/bin/notmuch new";
extraConfig = {
2023-09-30 10:11:58 +01:00
wait = 300;
tls = false;
tlsOptions.rejectUnauthorized = false;
};
};
mbsync = {
enable = lib.mkDefault accountEnabled;
create = "both";
expunge = "both";
remove = "both";
2023-09-26 10:49:13 +01:00
patterns = [ "*" "!All Mail" "!Spam" "!Labels*" "!Starred" ];
subFolders = "Verbatim";
extraConfig.account.AuthMechs = "LOGIN";
};
msmtp = {
enable = lib.mkDefault accountEnabled;
extraConfig = {
tls = "off";
auth = "login";
};
};
notmuch.enable = lib.mkDefault accountEnabled;
};
icloud = let accountEnabled = true;
in rec {
inherit realName;
2023-10-15 10:02:16 +01:00
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.libsecret}/bin/secret-tool lookup email ${userName}";
imapnotify = {
enable = lib.mkDefault accountEnabled;
boxes = [ "INBOX" ];
onNotify = "${pkgs.isync}/bin/mbsync icloud";
onNotifyPost = "${pkgs.notmuch}/bin/notmuch new";
2023-09-30 10:11:58 +01:00
extraConfig.wait = 300;
};
mbsync = {
enable = lib.mkDefault accountEnabled;
create = "both";
expunge = "both";
remove = "both";
patterns = [ "*" "!Junk" ];
subFolders = "Verbatim";
};
msmtp.enable = lib.mkDefault accountEnabled;
notmuch.enable = lib.mkDefault accountEnabled;
};
2023-10-15 10:02:16 +01:00
outlook = let
host = "127.0.0.1";
tls.enable = false;
accountEnabled = true;
in rec {
inherit realName;
primary = lib.mkDefault false;
2023-10-15 10:02:16 +01:00
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.libsecret}/bin/secret-tool lookup email ${userName}";
imapnotify = {
enable = lib.mkDefault accountEnabled;
boxes = [ "INBOX" ];
onNotify = "${pkgs.isync}/bin/mbsync outlook";
onNotifyPost = "${pkgs.notmuch}/bin/notmuch new";
extraConfig = {
2023-09-30 10:11:58 +01:00
wait = 300;
tls = false;
tlsOptions.rejectUnauthorized = false;
};
};
mbsync = {
enable = lib.mkDefault accountEnabled;
create = "both";
expunge = "both";
remove = "both";
patterns = [
"*"
"!Conversation History"
"!Junk"
"!Snoozed"
"!Social Activity Notifications"
"!Sync Issues"
"!Unsent Messages"
];
subFolders = "Verbatim";
extraConfig.account.AuthMechs = "LOGIN";
};
2023-10-03 09:24:43 +01:00
msmtp = {
enable = lib.mkDefault accountEnabled;
2023-10-03 09:24:43 +01:00
extraConfig = {
tls = "off";
auth = "login";
};
};
notmuch.enable = lib.mkDefault accountEnabled;
};
};
};
systemd.user.services = let emailAccounts = config.accounts.email.accounts;
in {
imapnotify-proton.Unit = lib.mkIf emailAccounts.proton.imapnotify.enable {
2023-10-02 06:26:54 +01:00
Wants = [ "protonmail-bridge.service" ];
After = [ "protonmail-bridge.service" ];
};
2023-10-15 10:02:16 +01:00
imapnotify-outlook.Unit = lib.mkIf emailAccounts.outlook.imapnotify.enable {
2023-10-02 06:26:54 +01:00
Wants = [ "davmail.service" ];
After = [ "davmail.service" ];
};
protonmail-bridge = lib.mkIf emailAccounts.proton.mbsync.enable {
Unit = {
Description = "Podman container-protonmail-bridge.service";
Documentation = [ "man:podman-generate-systemd(1)" ];
Wants = [ "network-online.target" ];
After = [ "network-online.target" ];
RequiresMountsFor = "%t/containers";
2023-10-01 09:17:45 +01:00
};
Service = {
Environment =
[ "PODMAN_SYSTEMD_UNIT=%n" "PATH=/run/wrappers/bin/:$PATH" ];
Restart = "always";
TimeoutStopSec = 70;
ExecStart = ''
${pkgs.podman}/bin/podman run \
--cidfile=%t/%n.ctr-id \
--cgroups=no-conmon \
--rm \
--sdnotify=conmon \
--replace \
-d \
--name=protonmail-bridge \
-v protonmail:/root \
-p 127.0.0.1:1025:25/tcp \
-p 127.0.0.1:1143:143/tcp shenxn/protonmail-bridge'';
ExecStop = ''
${pkgs.podman}/bin/podman stop \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id'';
ExecStopPost = ''
${pkgs.podman}/bin/podman rm \
-f \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id'';
Type = "notify";
NotifyAccess = "all";
};
Install.WantedBy = [ "default.target" ];
};
2023-10-15 10:02:16 +01:00
davmail = lib.mkIf emailAccounts.outlook.mbsync.enable {
2023-10-01 09:17:45 +01:00
Unit = {
Description = "Davmail server";
Wants = [ "network-online.target" ];
After = [ "network-online.target" ];
2023-10-01 09:17:45 +01:00
};
Service = {
Environment = [ "PATH=/run/current-system/sw/bin/:$PATH" ];
2023-10-01 09:17:45 +01:00
Restart = "always";
ExecStartPre = with config.home; ''
/bin/sh -c "if [ ! -f ${homeDirectory}/.davmail.properties ]; then cp ${
./.davmail.properties
2023-10-08 09:53:09 +01:00
} ${homeDirectory}/.davmail.properties; fi; chmod 644 ${homeDirectory}/.davmail.properties"
'';
ExecStart =
"${pkgs.davmail}/bin/davmail -notray ${config.home.homeDirectory}/.davmail.properties";
2023-10-01 09:17:45 +01:00
};
2023-10-02 06:26:54 +01:00
Install.WantedBy = [ "default.target" ];
2023-10-01 09:17:45 +01:00
};
};
}