nixos-config/nixos/configs/workhorse/mail-fetcher.nix

661 lines
17 KiB
Nix
Raw Normal View History

2019-10-24 02:20:38 +02:00
# fetches mails for me
2020-03-16 15:31:13 +01:00
{ lib, pkgs, config, ... }:
let
2021-09-05 12:32:49 +02:00
junk_filter = [
"from:booking.com"
"from:brompton.com"
"from:circleci.com OR (from:noreply@github.com AND to:audio-overlay@googlegroups.com)"
"from:codepen.io"
"from:congstarnews.de"
2021-09-06 06:24:28 +02:00
"from:cronullasurfingacademy.com"
2021-09-05 12:32:49 +02:00
"from:cryptohopper.com"
"from:digitalo.de"
"from:facebook.com OR from:facebookmail.com"
"from:fitnessfirst.de"
"from:flixbus.de"
"from:getdigital.de"
"from:getpocket.com"
"from:ghostinspector.com"
2021-09-10 21:34:42 +02:00
"from:globetrotter.de"
2021-09-05 12:32:49 +02:00
"from:hackster.io"
2021-09-06 06:24:28 +02:00
"from:hostelworld.com"
2021-09-05 12:32:49 +02:00
"from:immobilienscout24.de"
2021-09-08 03:38:08 +02:00
"from:kvraudio.com"
2021-09-05 12:32:49 +02:00
"from:letterboxd.com"
2021-09-20 19:55:59 +02:00
"from:linkedin.com"
2021-09-05 12:32:49 +02:00
"from:magix.net"
"from:mailings.gmx.net"
"from:mailings.web.de"
"from:matrix.org"
"from:menospese.com"
"from:microsoftstoreemail.com"
"from:mixcloudmail.com AND subject:Weekly Update"
"from:oknotify2.com AND NOT subject:New message"
"from:paulaschoice.com"
"from:puppet.com"
"from:runtastic.com"
"from:samplemagic.com OR from:wavealchemy.co.uk OR from:creators.gumroad.com"
"from:ticketmaster.de"
"from:trade4less.de"
"from:tumblr.com"
"from:turners.co.nz"
"from:twitch.tv"
"from:vstbuzz.com"
];
2020-03-16 15:31:13 +01:00
filters = [
2021-09-20 20:02:53 +02:00
{
2021-09-20 20:03:23 +02:00
query = "from:hv-geelen.de";
2021-09-20 20:02:53 +02:00
tags = [ "+wohnung" ];
}
2020-03-16 15:31:13 +01:00
{
query = "from:computerfutures.com OR from:computerfutures.de";
tags = [ "+jobs" "-inbox" ];
}
{
query = "from:seek.com.au or from:seek.co.nz";
tags = [ "+jobs" ];
}
{
query = "from:xing.com";
tags = [ "+jobs" "-inbox" ];
}
{
2020-11-05 00:24:09 +01:00
query = "from:no-reply@backtrace.io OR to:sononym@noreply.github.com";
tags = [ "+sononym" "-inbox" ];
2020-03-16 15:31:13 +01:00
}
{
query = "from:ebay.com OR from:ebay.de OR from:ebay.net";
tags = [ "+ebay" "+shop" "+billing" ];
}
{
query = "from:bahn.de";
tags = [ "+billing" "+bahn" ];
}
{
query =
"from:fysitech.atlassian.net OR to:engiadina-pwa@noreply.github.com";
tags = [ "+mia" "+work" "-unread" "-inbox" ];
}
2020-08-25 22:31:45 +02:00
{
2021-04-18 09:45:49 +02:00
query =
2021-04-22 08:15:55 +02:00
"from:space-left.org OR to:space-left.org OR subject:/\\[space-left\\]/";
tags = [ "+spaceleft" "+space-left" ];
2020-08-25 22:31:45 +02:00
}
2020-03-16 15:31:13 +01:00
{
query = "from:landr.com";
tags = [ "+landr" "+music" ];
}
{
query = "tag:landr and tag:billing";
tags = [ "+billing" ];
}
{
query = "from:oknotify2.com";
tags = [ "+okcupid" ];
}
{
query = "from:taxback.de OR to:taxback.de";
tags = [ "+steuer" ];
}
{
query = "from:campact.de";
tags = [ "+campact" "+politics" ];
}
{
query = "from:aliexpress.com";
tags = [ "+shop" "+aliexpress" ];
}
{
query = "from:congstar.de";
tags = [ "+billing" "+congstar" "-inbox" "-unread" ];
}
{
query =
"from:steampowered.com AND NOT ( subject:purchase OR subject:received )";
tags = [ "-inbox" "-unread" ];
}
{
query =
"from:steampowered.com AND ( subject:purchase OR subject:received )";
tags = [ "+billing" "+steam" ];
}
{
query = "from:gog.com AND NOT subject:Bestellung";
tags = [ "-inbox" "-unread" ];
}
{
query = "from:gog.com AND subject:Bestellung";
tags = [ "+billing" "+gog" ];
}
2021-02-03 21:35:34 +01:00
{
query = "from:stadtmobil.de";
tags = [ "+billing" "+stadtmobil" "-inbox" "-unread" ];
}
2020-03-16 15:31:13 +01:00
{
query = "from:drive-now.com";
tags = [ "+billing" "+drivenow" "-inbox" "-unread" ];
}
2021-02-03 21:35:34 +01:00
{
query = "from:data-treuhand.de";
2021-03-15 08:28:27 +01:00
tags = [ "+mindcurv" "+work" "-inbox" "-unread" "-junk" ];
2021-02-03 21:35:34 +01:00
}
{
query = "from:immocation.de";
tags = [ "+immobilien" "-inbox" ];
}
2020-03-16 15:31:13 +01:00
{
query = "from:tinc-vpn.org";
tags = [ "+tinc" ];
}
{
query = "from:mindfactory.de";
tags = [ "+shop" "+billing" ];
}
{
query = "from:zalando.de";
tags = [ "+shop" "+billing" "+zalando" ];
}
{
query = "from:ing.de";
tags = [ "+bank" "+ingdiba" ];
}
{
query = "from:nab.com.au";
tags = [ "+bank" "+nab" "-inbox" "-unread" ];
}
{
query = "from:dkb.de";
tags = [ "+bank" "+dkb" ];
}
{
query = "from:o2online.de";
tags = [ "+billing" "+o2" ];
}
{
query = "from:betfair.com";
tags = [ "+work" "+betfair" ];
}
{
query = "from:notifications@github.com";
tags = [ "+github" ];
}
2020-11-05 00:24:09 +01:00
{
query = "to:NUR@noreply.github.com";
tags = [ "+nur" "+nixos" "+list" ];
}
{
query = "to:nixpkgs@noreply.github.com";
tags = [ "+nixpkgs" "+nixos" "+list" ];
}
2020-03-16 15:31:13 +01:00
{
query = "from:travis-ci.org AND subject:mrVanDalo/navi";
tags = [ "+development" "+navi" ];
}
{
query = "from:travis-ci.org AND subject:nur-packages";
tags = [ "+development" "+nixos" "+nur-packages" ];
}
{
query = "from:travis-ci.org AND subject:csv-to-qif";
tags = [ "+development" "+csv-to-qif" ];
}
{
query = "to:proaudio@lists.tuxfamily.org";
tags = [ "-inbox" "-unread" ];
}
{
query = "from:nixos1@discoursemail.com";
2020-11-05 00:24:09 +01:00
tags = [ "+nixos" "+discourse" "+list" ];
2020-03-16 15:31:13 +01:00
}
{
query = "from:nixos1@discoursemail.com AND subject:Development";
tags = [ "+nixos" "+discourse" "+development" ];
}
{
query = "from:nixos1@discoursemail.com AND subject:Français";
tags = [ "+nixos" "+discourse" "-inbox" "-unread" ];
}
{
query = "from:nixos1@discoursemail.com AND subject:Announcements";
tags = [ "+nixos" "+discourse" "+announcements" ];
}
{
query = "from:nixos1@discoursemail.com AND subject:Links";
tags = [ "+nixos" "+discourse" "+links" ];
}
{
query = "from:nixos1@discoursemail.com AND subject:Games";
tags = [ "+nixos" "+discourse" "+games" ];
}
{
query = "from:nixos1@discoursemail.com AND subject:Meta";
tags = [ "+nixos" "+discourse" "+meta" ];
}
{
query = "from:nixos1@discoursemail.com AND subject:Events";
tags = [ "+nixos" "+discourse" "+events" ];
}
{
query = "from:limebike.com AND (subject:Funds OR subject:Receipt)";
tags = [ "-inbox" "-unread" "+billing" "+limebike" ];
}
{
query = "from:freemusicarchive.org";
tags = [ "+FMA" ];
}
{
query = "from:namecheap.com and subject:auto-renewal";
tags = [ "+namecheap" "+billing" ];
}
{
query = "from:namecheap.com and subject:order";
tags = [ "+namecheap" "+billing" ];
}
{
query = "tag:namecheap.com and tag:billing and body:gaykraft.com";
tags = [ "+namecheap" "+billing" ];
}
{
query = "from:nintendo.com";
tags = [ "+nintendo" "+billing" ];
}
{
query = "from:oculus.com AND subject:receipt";
tags = [ "+oculus" "+billing" ];
}
{
query = "from:car2go.com";
tags = [ "-inbox" "-unread" ];
}
{
query = "from:sixt.de";
tags = [ "-inbox" "-unread" ];
}
{
query = "from:meetup.com";
tags = [ "-inbox" "-unread" "+meetup" ];
}
{
query = "from:slack.com";
tags = [ "+slack" ];
}
{
query = "from:keybase.io";
tags = [ "+keybase" ];
}
{
query = "from:jobs2web.com";
tags = [ "+newzealand" "+jobs" "-inbox" ];
}
{
query = "from:paypal.de AND subject:Bestätigung";
tags = [ "-unread" "+paypal" "+billing" ];
}
{
query = "to:c-base.org";
2020-11-05 00:24:09 +01:00
tags = [ "+cbase" "+list" ];
2020-03-16 15:31:13 +01:00
}
{
query = "to:c-base.org AND subject=[auto-report]";
tags = [ "-unread" "-inbox" ];
}
{
query = "from:browserstack.com";
tags = [ "+browserstack" ];
}
{
query =
"to:renoise@ingolf-wagner.de OR to:root@renoise.com OR from:renoise.com OR to:admin@renoise.com";
tags = [ "+renoise" ];
}
{
query = "from:amazon.de OR from:amazon.com AND NOT to:renoise.com";
tags = [ "+shop" "+amazon" "+billing" ];
}
{
query = "from:hetzner.com OR from:hetzner.de";
tags = [ "+hetzner" ];
}
{
query =
"to:renoise.com AND NOT ( from:renoise.com OR from:root OR from:hetzner.com OR from:hetzner.de OR from:amazon.com OR from:gmail.com )";
tags = [ "-inbox" "-unread" "+junk" "+renoise" ];
}
{
query = "tag:hetzner and subject:Invoice";
tags = [ "+billing" ];
}
# final rules to make imap sync stuff easier
# there can only be one output folder tag, and theses rules are prioritized
{
query = "tag:fraud";
tags = [ "-inbox" "-archive" "-junk" "-unread" ];
message = "clean up tag fraud";
}
{
query = "tag:junk";
tags = [ "-inbox" "-archive" "-fraud" "-unread" ];
message = "clean up tag junk";
}
{
query = "tag:archive";
tags = [ "-inbox" "-junk" "-fraud" "-unread" ];
message = "clean up tag archive";
}
{
query = "tag:inbox";
tags = [ "-archive" "-junk" "-fraud" ];
message = "clean up inbox";
}
{
query = "tag:killed";
tags = [ "-inbox" "-unread" ];
message = "clean up tag killed";
}
{
query = "tag:muted";
tags = [ "-inbox" "-unread" ];
}
# remove new tag at the end
{
query = "tag:new";
tags = [ "-new" ];
message = "remove new tag at the end";
}
];
2021-11-01 09:20:42 +01:00
notmuchTagging =
let
2021-09-05 12:32:49 +02:00
2021-11-01 09:20:42 +01:00
template = index:
{ tags, query, message ? "generic", ... }:
let
command = ''
${pkgs.notmuch}/bin/notmuch tag ${lib.concatStringsSep " " tags} -- "${query}"
'';
in
''
echo '${command}'
${command}
2020-03-16 15:31:13 +01:00
'';
2021-11-01 09:20:42 +01:00
junk_template = index: query:
template index {
tags = [ "+junk" "-unread" "-inbox" ];
query = query;
message = "generic junk filter";
};
2021-09-05 12:32:49 +02:00
2021-11-01 09:20:42 +01:00
in
pkgs.writers.writeBash "notmuch-tagging" (lib.concatStringsSep "\n"
((lib.imap0 junk_template junk_filter) ++ (lib.imap0 template filters)));
2020-03-16 15:31:13 +01:00
2021-11-01 09:20:42 +01:00
notmuchTaggingNew =
let
2021-09-10 21:34:42 +02:00
2021-11-01 09:20:42 +01:00
template = index:
{ tags, query, message ? "generic", ... }:
let
command = ''
${pkgs.notmuch}/bin/notmuch tag ${
lib.concatStringsSep " " tags
} -- "${query} AND tag:new"
'';
in
''
echo '${command}'
${command}
2020-03-16 15:31:13 +01:00
'';
2021-09-10 21:34:42 +02:00
2021-11-01 09:20:42 +01:00
junk_template = index: query:
template index {
tags = [ "+junk" "-unread" "-inbox" ];
query = query;
message = "generic junk filter";
};
in
pkgs.writers.writeBash "notmuch-tagging-new" (lib.concatStringsSep "\n"
((lib.imap0 junk_template junk_filter) ++ (lib.imap0 template filters)));
2020-03-16 15:31:13 +01:00
2021-11-01 09:20:42 +01:00
in
{
2020-01-16 09:42:57 +01:00
2020-09-04 00:49:35 +02:00
backup.dirs = [ "/home/mailfetcher" ];
2020-01-16 09:42:57 +01:00
2019-10-24 02:20:38 +02:00
users.users.mailUser = {
isNormalUser = true;
description = "collects mails for me";
hashedPassword = "!";
name = "mailfetcher";
2020-09-04 00:49:35 +02:00
home = "/home/mailfetcher";
2019-12-20 05:54:26 +01:00
openssh.authorizedKeys.keyFiles =
config.users.users.root.openssh.authorizedKeys.keyFiles;
2021-10-31 17:49:44 +01:00
group = "mailfetcher";
2019-10-24 02:20:38 +02:00
};
2021-10-31 17:49:44 +01:00
users.groups.mailUser = {
name = "mailfetcher";
2019-10-24 02:20:38 +02:00
};
2021-11-01 09:20:42 +01:00
sops.secrets.mail_terranix = {
owner = config.users.users.mailUser.name;
group = config.users.users.mailUser.group;
};
sops.secrets.mail_gmail = {
owner = config.users.users.mailUser.name;
group = config.users.users.mailUser.group;
};
sops.secrets.mail_gmx_palo = {
owner = config.users.users.mailUser.name;
group = config.users.users.mailUser.group;
};
sops.secrets.mail_gmx_ingolf = {
owner = config.users.users.mailUser.name;
group = config.users.users.mailUser.group;
};
sops.secrets.mail_web = {
owner = config.users.users.mailUser.name;
group = config.users.users.mailUser.group;
};
sops.secrets.mail_siteground = {
owner = config.users.users.mailUser.name;
group = config.users.users.mailUser.group;
};
2021-10-31 17:49:44 +01:00
2019-10-24 02:20:38 +02:00
environment.systemPackages = [ pkgs.muchsync ];
# configure accounts
home-manager.users.mailUser.accounts.email = {
accounts = {
2021-09-11 08:09:24 +02:00
2019-10-24 02:20:38 +02:00
palo_van_dalo-gmx = {
primary = false;
address = "palo_van_dalo@gmx.de";
aliases = [ ];
realName = "Ingolf Wagner";
userName = "palo_van_dalo@gmx.de";
2019-12-20 05:54:26 +01:00
passwordCommand =
2021-10-31 17:49:44 +01:00
"cat ${toString config.sops.secrets.mail_gmx_palo.path }";
2019-10-24 02:20:38 +02:00
imap = {
host = "imap.gmx.net";
2021-09-11 08:09:24 +02:00
tls.enable = true;
2019-10-24 02:20:38 +02:00
port = 993;
};
mbsync = {
enable = true;
create = "both";
};
notmuch.enable = true;
};
2021-09-11 08:09:24 +02:00
2019-10-24 02:20:38 +02:00
ingolf-wagner-gmx = {
primary = false;
address = "ingolf.wagner@gmx.de";
aliases = [ ];
realName = "Ingolf Wagner";
userName = "ingolf.wagner@gmx.de";
2019-12-20 05:54:26 +01:00
passwordCommand =
2021-10-31 17:49:44 +01:00
"cat ${toString config.sops.secrets.mail_gmx_ingolf.path }";
2019-10-24 02:20:38 +02:00
imap = {
host = "imap.gmx.net";
2021-09-11 08:09:24 +02:00
tls.enable = true;
2019-10-24 02:20:38 +02:00
port = 993;
};
mbsync = {
enable = true;
create = "both";
};
notmuch.enable = true;
};
2021-09-11 08:09:24 +02:00
2019-10-24 02:20:38 +02:00
pali_palo = {
primary = false;
address = "pali_palo@web.de";
aliases = [ ];
realName = "Ingolf Wagner";
userName = "pali_palo@web.de";
2019-12-20 05:54:26 +01:00
passwordCommand =
2021-10-31 17:49:44 +01:00
"cat ${toString config.sops.secrets.mail_web.path }";
2019-10-24 02:20:38 +02:00
imap = {
host = "imap.web.de";
2021-09-11 08:09:24 +02:00
tls.enable = true;
2019-10-24 02:20:38 +02:00
port = 993;
};
mbsync = {
enable = true;
create = "both";
};
notmuch.enable = true;
};
2021-09-11 08:09:24 +02:00
2019-10-24 02:20:38 +02:00
gmail = {
# for google accounts you have to allow 'less secure apps' in accounts.google.com
primary = true;
address = "palipalo9@googlemail.com";
aliases = [ ];
realName = "Ingolf Wagner";
userName = "palipalo9@googlemail.com";
2019-12-20 05:54:26 +01:00
passwordCommand =
2021-10-31 17:49:44 +01:00
"cat ${toString config.sops.secrets.mail_gmail.path }";
2019-10-24 02:20:38 +02:00
imap = {
host = "imap.gmail.com";
2021-09-11 08:09:24 +02:00
tls.enable = true;
2019-10-24 02:20:38 +02:00
port = 993;
};
mbsync = {
enable = true;
create = "both";
};
notmuch.enable = true;
};
2021-09-11 08:09:24 +02:00
2021-09-10 21:34:42 +02:00
terranix_org = {
2021-09-11 08:09:24 +02:00
primary = false;
2021-09-10 21:34:42 +02:00
address = "palo@terranix.org";
aliases = [ ];
realName = "Ingolf Wagner";
userName = "palo@terranix.org";
2021-10-31 17:49:44 +01:00
passwordCommand = "cat ${toString config.sops.secrets.mail_terranix.path }";
2021-09-10 21:34:42 +02:00
imap = {
host = "mail.privateemail.com";
2021-09-11 08:09:24 +02:00
tls.enable = true;
2021-09-10 21:34:42 +02:00
port = 993;
};
mbsync = {
enable = true;
create = "both";
};
notmuch.enable = true;
};
2021-09-11 08:09:24 +02:00
ingolf-wagner-de = {
2019-10-24 02:20:38 +02:00
primary = false;
address = "contact@ingolf-wagner.de";
aliases = [ ];
realName = "Ingolf Wagner";
userName = "contact@ingolf-wagner.de";
2019-12-20 05:54:26 +01:00
passwordCommand =
2021-10-31 17:49:44 +01:00
"cat ${toString config.sops.secrets.mail_siteground.path }";
2019-10-24 02:20:38 +02:00
imap = {
host = "securees5.sgcpanel.com";
2020-05-27 00:31:14 +02:00
port = 993;
2021-09-11 08:09:24 +02:00
tls.enable = true;
#tls.useStartTls = true;
2019-10-24 02:20:38 +02:00
};
# make sure the upstream mail is deleted
getmail = {
2019-10-24 02:20:38 +02:00
enable = true;
delete = true;
2019-12-06 22:09:09 +01:00
readAll = false;
mailboxes = [ "ALL" ];
2019-10-24 02:20:38 +02:00
};
notmuch.enable = true;
};
2021-09-11 08:09:24 +02:00
2019-10-24 02:20:38 +02:00
};
};
# configure mbsync
home-manager.users.mailUser.programs.mbsync.enable = true;
2020-01-23 11:07:28 +01:00
# re-tag everything once a day
systemd.services.retagmail = {
enable = true;
serviceConfig = { User = config.users.users.mailUser.name; };
environment.NOTMUCH_CONFIG =
"${config.users.users.mailUser.home}/.config/notmuch/notmuchrc";
2020-03-16 15:31:13 +01:00
script = "${notmuchTagging}";
2020-01-23 11:07:28 +01:00
};
systemd.timers.retagmail = {
enable = true;
timerConfig = {
OnCalendar = "daily";
Persistent = "true";
};
wantedBy = [ "multi-user.target" ];
};
# fetch mails every 10 minutes
2021-10-31 13:16:44 +01:00
systemd.services.fetchmail =
let
threadTag = tag: ''
2021-11-01 09:20:42 +01:00
echo "tag threads with ${tag}"
${pkgs.notmuch}/bin/notmuch tag +${tag} $(${pkgs.notmuch}/bin/notmuch search --output=threads tag:${tag})
2021-10-31 13:16:44 +01:00
'';
2021-11-01 09:20:42 +01:00
in
{
enable = true;
serviceConfig = { User = config.users.users.mailUser.name; };
environment.NOTMUCH_CONFIG =
"${config.users.users.mailUser.home}/.config/notmuch/notmuchrc";
script = ''
echo "run mbsync"
${pkgs.isync}/bin/mbsync \
--all
echo "run getmail"
${pkgs.getmail}/bin/getmail \
--quiet \
--rcfile getmailingolf-wagner-de
2021-11-01 09:20:42 +01:00
echo "run notmuch"
${pkgs.notmuch}/bin/notmuch new
${notmuchTaggingNew}
${threadTag "muted"}
${threadTag "wohnung"}
${threadTag "flagged"}
'';
};
2019-10-24 02:20:38 +02:00
systemd.timers.fetchmail = {
enable = true;
# timerConfig.OnCalendar = " *-*-* *:00:00";
timerConfig.OnCalendar = "*:0/10";
2019-12-20 05:54:26 +01:00
wantedBy = [ "multi-user.target" ];
2019-10-24 02:20:38 +02:00
};
# configure notmuch
home-manager.users.mailUser.programs.notmuch = {
enable = true;
new.tags = [ "unread" "inbox" "new" ];
};
}