automatic mail sync

This commit is contained in:
Grigory Shipunov 2022-08-12 00:31:42 +02:00
parent 7f1bcf1f26
commit ed2a896cff
Signed by: 0xa
GPG key ID: 91FA5E5BF9AA901C
5 changed files with 169 additions and 15 deletions

88
modules/mail/default.nix Normal file
View file

@ -0,0 +1,88 @@
{ config, pkgs, ... }:
let
mbsyncConf = ./mbsyncrc;
in
{
environment.systemPackages = with pkgs; [
isync
msmtp
neomutt
notmuch
pass
w3m
];
sops.secrets = {
"mail/oxapentane.com" = {
owner = config.users.users.grue.name;
};
"mail/shipunov.xyz" = {
owner = config.users.users.grue.name;
};
"mail/dvb.solutions" = {
owner = config.users.users.grue.name;
};
};
programs.msmtp = {
enable = true;
setSendmail = true;
defaults = {
tls_trust_file = "/etc/ssl/certs/ca-certificates.crt";
logfile = "/tmp/msmtp.log";
};
accounts = {
"mail@oxapentane.com" = {
host = "smtp.migadu.com";
port = 578;
from = "*@oxapentane.com";
user = "mail@oxapentane.com";
passwordeval = "cat ${config.sops.secrets."mail/oxapentane.com".path}";
auth = "on";
tls = "on";
};
"grigory@shipunov.xyz" = {
host = "smtp.migadu.com";
port = 578;
from = "*@shipunov.xyz";
user = "mail@oxapentane.com";
passwordeval = "cat ${config.sops.secrets."mail/shipunov.xyz".path}";
auth = "on";
tls = "on";
};
"dump@dvb.solutions" = {
host = "smtp.migadu.com";
port = 578;
from = "dump@dvb.solutions";
user = "dump@dvb.solutions";
passwordeval = "cat ${config.sops.secrets."mail/dvb.solutions".path}";
auth = "on";
tls = "on";
};
};
};
systemd.user = {
services.mbsync = {
enable = true;
after = [ "graphical.target" "network-online.target" ];
script = ''
${pkgs.isync}/bin/mbsync -a --config=${mbsyncConf}
'';
serviceConfig = {
Type = "oneshot";
};
};
timers.mbsync = {
enable = true;
wantedBy = [ "timers.target" ];
timerConfig = {
Unit = "mbsync.service";
OnUnitInactiveSec = "11m";
Persistent = true;
};
};
};
}

74
modules/mail/mbsyncrc Normal file
View file

@ -0,0 +1,74 @@
IMAPStore mail@oxapentane.com-remote
Host imap.migadu.com
Port 993
User mail@oxapentane.com
PassCmd "cat /run/secrets/mail/oxapentane.com"
AuthMechs LOGIN
SSLType IMAPS
MaildirStore mail@oxapentane.com-local
Subfolders Verbatim
Path /home/grue/mail/mail@oxapentane.com/
Inbox /home/grue/mail/mail@oxapentane.com/INBOX
Channel mail@oxapentane.com
Expunge Both
Master :mail@oxapentane.com-remote:
Slave :mail@oxapentane.com-local:
Create Both
SyncState *
Patterns *
MaxMessages 0
ExpireUnread no
# End profile
IMAPStore grigory@shipunov.xyz-remote
Host imap.migadu.com
Port 993
User grigory@shipunov.xyz
PassCmd "cat /run/secrets/mail/shipunov.xyz"
AuthMechs LOGIN
SSLType IMAPS
MaildirStore grigory@shipunov.xyz-local
Subfolders Verbatim
Path /home/grue/mail/grigory@shipunov.xyz/
Inbox /home/grue/mail/grigory@shipunov.xyz/INBOX
Channel grigory@shipunov.xyz
Expunge Both
Master :grigory@shipunov.xyz-remote:
Slave :grigory@shipunov.xyz-local:
Create Both
SyncState *
Patterns *
MaxMessages 0
ExpireUnread no
# End profile
IMAPStore dump@dvb.solutions-remote
Host imap.migadu.com
Port 993
User dump@dvb.solutions
PassCmd "cat /run/secrets/mail/dvb.solutions"
AuthMechs LOGIN
SSLType IMAPS
MaildirStore dump@dvb.solutions-local
Subfolders Verbatim
Path /home/grue/mail/dump@dvb.solutions/
Inbox /home/grue/mail/dump@dvb.solutions/INBOX
Channel dump@dvb.solutions
Expunge Both
Master :dump@dvb.solutions-remote:
Slave :dump@dvb.solutions-local:
Create Both
SyncState *
Patterns *
MaxMessages 0
ExpireUnread no
# End profile