From 956efaf35011986c71481e69fd27d00a2bc013f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Sun, 27 Sep 2020 19:28:11 +0200 Subject: [PATCH] feat(mail): use afew as initial tagging script --- configs/mail.nix | 63 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/configs/mail.nix b/configs/mail.nix index 39eaf93..04047f2 100644 --- a/configs/mail.nix +++ b/configs/mail.nix @@ -1,5 +1,26 @@ { config, pkgs, lib, ... }: let + tagRules = [ + { + query = "to:miaengiadina-pwa@noreply.github.com AND subject:\"PR run failed\""; + tags = [ "-new" "+deleted" ]; + } + { + query = lib.concatStringsSep " OR " [ + "from:noreply-local-guides@google.com" + "from:google-maps-noreply@google.com" + "subject:fd-noti" + "from:nebenan.de" + "to:miaengiadina-pwa@noreply.github.com" + ]; + tags = [ "-new" ]; + } + { + query = "tag:new"; + tags = [ "-new" "+inbox" ]; + } + ]; + pass_ = file: "echo ${lib.escapeShellArg (lib.strings.fileContents file)}"; generateTaggingScript = filters: @@ -68,24 +89,32 @@ in { programs.notmuch = { enable = true; - new.tags = [ "unread" "inbox" ]; + new.tags = [ "new" ]; search.excludeTags = [ "deleted" "spam" ]; - hooks.postNew = generateTaggingScript [ - { - query = "to:miaengiadina-pwa@noreply.github.com AND subject:\"PR run failed\""; - tags = [ "+deleted" ]; - } - { - query = lib.concatStringsSep " OR " [ - "from:noreply-local-guides@google.com" - "from:google-maps-noreply@google.com" - "subject:fd-noti" - "from:nebenan.de" - "to:miaengiadina-pwa@noreply.github.com" - ]; - tags = [ "-inbox -unread" ]; - } - ]; + hooks.postNew = "${pkgs.afew}/bin/afew --tag --new"; + }; + + programs.afew = let + generateFilters = rules: + lib.concatStringsSep "\n" (lib.lists.imap1 + (index: {message ? null, query, tags}: '' + [Filter.${toString index}] + query = ${query} + tags = ${lib.concatStringsSep ";" tags} + ${lib.optionalString (message != null) "message = ${message}"} + '') + rules + ); + in { + enable = true; + extraConfig = '' + [SpamFilter] + [ArchiveSentMailsFilter] + + ${generateFilters tagRules} + + [InboxFilter] + ''; }; accounts.email.maildirBasePath = "${config.users.users.me.home}/mail";