Commit 375eaaa3d538

Vincent Demeester <vincent@sbr.pm>
2025-12-03 15:10:16
feat: Add imapfilter service for automated email filtering
- Enable periodic IMAP filtering on athena every 15 minutes - Integrate with passage for secure iCloud credentials - Provide customizable Lua rules template for email organization Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent 72b3e7d
Changed files (3)
home
systems
athena
home/common/services/imapfilter-config.lua
@@ -0,0 +1,42 @@
+----------
+-- Options
+----------
+options.timeout = 120
+options.subscribe = true
+
+----------
+-- Accounts
+----------
+account = IMAP {
+  server = 'imap.mail.me.com',
+  username = 'vdemeester@icloud.com',
+  -- Password will be provided via command line or config file
+  -- Using ssl by default
+  ssl = 'tls1.2',
+}
+
+----------
+-- Example filtering rules
+-- Customize these based on your needs
+----------
+
+-- Get all messages in INBOX
+messages = account['INBOX']:select_all()
+
+-- Example 1: Move GitHub notifications to a GitHub folder
+-- Uncomment and customize as needed
+-- github = messages:contain_from('notifications@github.com')
+-- github:move_messages(account['GitHub'])
+
+-- Example 2: Move mailing list emails
+-- Uncomment and customize as needed
+-- lists = messages:contain_to('list@example.com')
+-- lists:move_messages(account['Lists'])
+
+-- Example 3: Filter by subject
+-- Uncomment and customize as needed
+-- spam = messages:contain_subject('[SPAM]')
+-- spam:move_messages(account['Junk'])
+
+-- Add your custom Lua rules below:
+-- TODO: Add custom filtering rules here
home/common/services/imapfilter.nix
@@ -0,0 +1,39 @@
+{ pkgs, ... }:
+{
+  # Enable imapfilter package
+  home.packages = [ pkgs.imapfilter ];
+
+  # Create a systemd user service for imapfilter
+  systemd.user.services.imapfilter = {
+    Unit = {
+      Description = "imapfilter - IMAP mail filtering utility";
+      After = [ "network-online.target" ];
+      Wants = [ "network-online.target" ];
+    };
+
+    Service = {
+      Type = "oneshot";
+      # Use passage to get the password
+      ExecStart = "${pkgs.bash}/bin/bash -c '${pkgs.imapfilter}/bin/imapfilter -c ${./imapfilter-config.lua} -p <(${pkgs.passage}/bin/passage show mails/icloud/vdemeester)'";
+      # Verbose mode for debugging - uncomment to enable
+      # ExecStart = "${pkgs.bash}/bin/bash -c '${pkgs.imapfilter}/bin/imapfilter -v -c ${./imapfilter-config.lua} -p <(${pkgs.passage}/bin/passage show mails/icloud/vdemeester)'";
+    };
+  };
+
+  # Create a systemd timer to run every 15 minutes
+  systemd.user.timers.imapfilter = {
+    Unit = {
+      Description = "imapfilter timer - runs every 15 minutes";
+    };
+
+    Timer = {
+      OnBootSec = "5min";
+      OnUnitActiveSec = "15min";
+      Unit = "imapfilter.service";
+    };
+
+    Install = {
+      WantedBy = [ "timers.target" ];
+    };
+  };
+}
systems/athena/home.nix
@@ -1,4 +1,8 @@
 { lib, ... }:
 {
+  imports = [
+    ../../home/common/services/imapfilter.nix
+  ];
+
   systemd.user.services.syncthing.Install.WantedBy = lib.mkForce [ "multi-user.target" ];
 }