More mail configuration

This commit is contained in:
Charlotte Van Petegem 2020-10-06 17:11:39 +02:00
parent 1e0ff42b1b
commit 487917c7cc
No known key found for this signature in database
GPG key ID: 019E764B7184435A

View file

@ -1,21 +1,58 @@
{ pkgs, ... }: { pkgs, lib, ... }:
let let
passwordScript = pkgs.writeScript "get_mail_password" '' passwordScript = pkgs.writeScript "get_mail_password" ''
#!${pkgs.bash}/bin/bash #!${pkgs.bash}/bin/bash
${pkgs.pass}/bin/pass show "$@" | head -n1 | tr -d "\n" ${pkgs.pass}/bin/pass show "$@" | head -n1 | tr -d "\n"
''; '';
baseAccount = { makeAccount = { name, address, host ? "", imapHost ? host, smtpHost ? host, useStartTls ? false, passFile, extraConfig ? { } }: (lib.recursiveUpdate
{
inherit address;
gpg = { gpg = {
key = "charlotte@vanpetegem.me"; key = "charlotte@vanpetegem.me";
signByDefault = true; signByDefault = true;
}; };
imap = {
host = imapHost;
port = 993;
tls.enable = true;
};
imapnotify = {
enable = true;
boxes = [ "INBOX" ];
onNotify = "${pkgs.offlineimap}/bin/offlineimap -a ${name} -f INBOX";
onNotifyPost = { mail = "${pkgs.libnotify}/bin/notify-send 'New ${name} mail arrived'"; };
};
msmtp.enable = true; msmtp.enable = true;
neomutt = {
enable = true;
sendMailCommand = "msmtpq --read-envelope-from --read-recipients --account ${name}";
};
offlineimap.enable = true; offlineimap.enable = true;
passwordCommand = "${passwordScript} ${passFile}";
realName = "Charlotte Van Petegem"; realName = "Charlotte Van Petegem";
signature = { signature = {
showSignature = "none"; showSignature = "none";
}; };
smtp = {
host = smtpHost;
port = if useStartTls then 587 else 465;
tls = {
enable = true;
inherit useStartTls;
};
};
userName = address;
}
extraConfig);
genNotifyImapPatch = account: {
name = "imapnotify-${account}";
value = {
Unit = {
After = "network-online.target";
Wants = "network-online.target";
};
};
}; };
in in
{ {
@ -24,112 +61,47 @@ in
{ path = ".local/share/offlineimap"; type = "data"; } { path = ".local/share/offlineimap"; type = "data"; }
]; ];
home-manager.users.charlotte = { ... }: { home-manager.users.charlotte = { ... }: {
home.file.".mailcap".text = ''
text/html; ${pkgs.firefox}/bin/firefox %s ; nametemplate=%s.html; needsterminal
text/html; ${pkgs.w3m}/bin/w3m -I %{charset} -T text/html ; copiousoutput; nametemplate=%s.html
'';
accounts.email = { accounts.email = {
maildirBasePath = "mail"; maildirBasePath = "mail";
accounts = { accounts = {
personal = baseAccount // { personal = makeAccount {
name = "personal";
address = "charlotte@vanpetegem.me"; address = "charlotte@vanpetegem.me";
folders = {
drafts = "Drafts";
inbox = "INBOX";
sent = "Sent";
trash = "Trash";
};
imap = {
host = "mail.vanpetegem.me"; host = "mail.vanpetegem.me";
port = 993; passFile = "mail/Personal";
tls.enable = true; extraConfig = {
}; folders = { drafts = "Drafts"; inbox = "INBOX"; sent = "Sent"; trash = "Trash"; };
imapnotify = {
enable = true;
boxes = [ "INBOX" ];
onNotify = "${pkgs.offlineimap}/bin/offlineimap -a personal -f INBOX";
onNotifyPost = { mail = "${pkgs.libnotify}/bin/notify-send 'New mail arrived'"; };
};
neomutt = {
enable = true;
sendMailCommand = "msmtpq --read-envelope-from --read-recipients --account personal";
};
passwordCommand = "${passwordScript} mail/Personal";
primary = true; primary = true;
smtp = {
host = "mail.vanpetegem.me";
port = 465;
tls.enable = true;
}; };
userName = "charlotte@vanpetegem.me";
}; };
work = baseAccount // { work = makeAccount {
name = "work";
address = "charlotte.vanpetegem@ugent.be"; address = "charlotte.vanpetegem@ugent.be";
folders = { imapHost = "outlook.office365.com";
drafts = "Drafts"; smtpHost = "smtp.office365.com";
inbox = "INBOX"; passFile = "work/UGentNet";
sent = "Sent Items";
trash = "Deleted Items";
};
imap = {
host = "outlook.office365.com";
port = 993;
tls.enable = true;
};
imapnotify = {
enable = true;
boxes = [ "INBOX" ];
onNotify = "${pkgs.offlineimap}/bin/offlineimap -a work -f INBOX";
onNotifyPost = { mail = "${pkgs.libnotify}/bin/notify-send 'New mail arrived'"; };
};
neomutt = {
enable = true;
sendMailCommand = "msmtpq --read-envelope-from --read-recipients --account work";
};
passwordCommand = "${passwordScript} work/UGentNet";
smtp = {
host = "smtp.office365.com";
port = 587;
tls = {
enable = true;
useStartTls = true; useStartTls = true;
extraConfig = {
folders = { drafts = "Drafts"; inbox = "INBOX"; sent = "Sent Items"; trash = "Deleted Items"; };
}; };
}; };
userName = "charlotte.vanpetegem@ugent.be"; posteo = makeAccount {
}; name = "posteo";
posteo = baseAccount // {
address = "chvp@posteo.net"; address = "chvp@posteo.net";
folders = {
drafts = "Drafts";
inbox = "INBOX";
sent = "Sent";
trash = "Trash";
};
imap = {
host = "posteo.de"; host = "posteo.de";
port = 993; passFile = "mail/Posteo";
tls.enable = true; extraConfig = {
folders = { drafts = "Drafts"; inbox = "INBOX"; sent = "Sent"; trash = "Trash"; };
}; };
imapnotify = {
enable = true;
boxes = [ "INBOX" ];
onNotify = "${pkgs.offlineimap}/bin/offlineimap -a work -f INBOX";
onNotifyPost = { mail = "${pkgs.libnotify}/bin/notify-send 'New mail arrived'"; };
}; };
neomutt = { jonggroen = makeAccount {
enable = true; name = "jonggroen";
sendMailCommand = "msmtpq --read-envelope-from --read-recipients --account posteo";
};
passwordCommand = "${passwordScript} mail/Posteo";
smtp = {
host = "posteo.de";
port = 465;
tls.enable = true;
};
userName = "chvp@posteo.net";
};
jonggroen = baseAccount // {
address = "charlotte@jonggroen.be"; address = "charlotte@jonggroen.be";
imapHost = "imap.gmail.com";
smtpHost = "smtp.gmail.com";
passFile = "jonggroen/GoogleAppMail";
useStartTls = true;
extraConfig = {
flavor = "gmail.com"; flavor = "gmail.com";
folders = { folders = {
drafts = "[Gmail].Drafts"; drafts = "[Gmail].Drafts";
@ -137,34 +109,32 @@ in
sent = "[Gmail].Sent Mail"; sent = "[Gmail].Sent Mail";
trash = "[Gmail].Bin"; trash = "[Gmail].Bin";
}; };
imap = {
host = "imap.gmail.com";
port = 993;
tls.enable = true;
};
imapnotify = {
enable = true;
boxes = [ "INBOX" ];
onNotify = "${pkgs.offlineimap}/bin/offlineimap -a jonggroen -f INBOX";
onNotifyPost = { mail = "${pkgs.libnotify}/bin/notify-send 'New mail arrived'"; };
};
neomutt = {
enable = true;
sendMailCommand = "msmtpq --read-envelope-from --read-recipients --account jonggroen";
};
passwordCommand = "${passwordScript} jonggroen/GoogleAppMail";
smtp = {
host = "smtp.gmail.com";
port = 587;
tls = {
enable = true;
useStartTls = true;
}; };
}; };
userName = "charlotte@jonggroen.be"; postbot = makeAccount {
name = "postbot";
address = "postbot@vanpetegem.me";
host = "mail.vanpetegem.me";
passFile = "mail/Postbot";
extraConfig = {
folders = { drafts = "Drafts"; inbox = "INBOX"; sent = "Sent"; trash = "Trash"; };
};
};
webmaster = makeAccount {
name = "webmaster";
address = "webmaster@vanpetegem.me";
host = "mail.vanpetegem.me";
passFile = "mail/Webmaster";
extraConfig = {
folders = { drafts = "Drafts"; inbox = "INBOX"; sent = "Sent"; trash = "Trash"; };
}; };
}; };
}; };
};
home.file.".mailcap".text = ''
text/html; ${pkgs.firefox}/bin/firefox %s ; nametemplate=%s.html; needsterminal
text/html; ${pkgs.w3m}/bin/w3m -I %{charset} -T text/html ; copiousoutput; nametemplate=%s.html
'';
programs = { programs = {
msmtp.enable = true; msmtp.enable = true;
neomutt = { neomutt = {
@ -182,5 +152,27 @@ in
services = { services = {
imapnotify.enable = true; imapnotify.enable = true;
}; };
systemd.user = {
services = {
offlineimap = {
Unit = {
Description = "OfflineIMAP email fetcher";
After = "network-online.target";
Wants = "network-online.target";
};
Service = { ExecStart = "${pkgs.offlineimap}/bin/offlineimap"; };
};
} // lib.listToAttrs (map genNotifyImapPatch [ "jonggroen" "personal" "postbot" "posteo" "webmaster" "work" ]);
timers = {
offlineimap = {
Unit = { Description = "OfflineIMAP email fetcher"; };
Timer = {
OnCalendar = "*:0/5";
Unit = "offlineimap.service";
};
Install = { WantedBy = [ "timers.target" ]; };
};
};
};
}; };
} }