mails: test notmuch setup
authorJulien Moutinho <julm+julm-nix@sourcephile.fr>
Sun, 17 Apr 2022 21:33:01 +0000 (23:33 +0200)
committerJulien Moutinho <julm+julm-nix@sourcephile.fr>
Mon, 25 Apr 2022 20:08:26 +0000 (22:08 +0200)
homes/julm/hosts/oignon.nix
homes/julm/mails.nix [new file with mode: 0644]

index 254ba51b3026571e0d062ad6512230cfbf6924b9..6712c4c7646e24cc8c6cbc738ca409a8713fc8de 100644 (file)
@@ -18,6 +18,8 @@ imports = [
   ../../../home-manager/profiles/xmonad.nix
   ../../../home-manager/profiles/ghc.nix
   ../../../home-manager/profiles/urxvt.nix
+
+  ../mails.nix
 ];
 programs.bash.shellAliases.riseup = "sudo ip netns exec riseup sudo -u $USER PULSE_SERVER=/run/user/$(id -u $USER)/pulse/native";
 programs.gpg.homedir = "${config.home.homeDirectory}/documents/sec/.gnupg";
diff --git a/homes/julm/mails.nix b/homes/julm/mails.nix
new file mode 100644 (file)
index 0000000..1faf866
--- /dev/null
@@ -0,0 +1,121 @@
+{ pkgs, lib, config, ... }:
+
+with lib;
+{
+config = mkMerge [
+  {
+    accounts.email = {
+      maildirBasePath = "mail/accounts";
+      accounts."testbox" = {
+        primary = true;
+        address = "testbox@sourcephile.fr";
+        userName = "testbox@sourcephile.fr";
+        realName = "Test Box";
+        passwordCommand = "${pkgs.coreutils}/bin/cat /home/julm/mail/accounts/testbox.pass";
+        #passwordCommand = "${pkgs.pass}/bin/pass sourcephile/mail/julm";
+        #passwordCommand = "${pkgs.gnupg}/bin/gpg -q --for-your-eyes-only --no-tty --exit-on-status-write-error --batch --passphrase-file ${config.home.homeDirectory}/sync/rh.pass -d ${config.home.homeDirectory}/desktop/documents/rh.pass.gpg";
+        imap.host = "mail.sourcephile.fr";
+        smtp.host = "mail.sourcephile.fr";
+        astroid.enable = true;
+        mbsync = {
+          enable = true;
+          create = "both";
+          expunge = "both";
+          patterns = [ "*" ];
+          extraConfig = {
+            channel = {
+              Sync = "All";
+            };
+            account = {
+              Timeout = 120;
+              PipelineDepth = 1;
+            };
+          };
+        };
+        msmtp.enable = true;
+        notmuch.enable = true;
+      };
+    };
+    home.file."bin/msmtp" = {
+      executable = true;
+      text = ''
+        #!${pkgs.stdenv.shell}
+        ${pkgs.libnotify}/bin/notify-send "Sending mail ✉️"
+        ${pkgs.msmtp}/bin/msmtp --read-envelope-from $@
+      '';
+    };
+    programs.msmtp.enable = true;
+    home.packages = [
+      pkgs.alot
+    ];
+  }
+
+  (mkIf true {
+    services.mbsync = {
+      enable = true;
+      preExec = "${config.xdg.configHome}/mbsync/preExec";
+      postExec = "${config.xdg.configHome}/mbsync/postExec";
+      frequency = "*:0/30";
+    };
+    xdg.configFile."mbsync/preExec".source = pkgs.writeShellScript "mbsync-preExec" ''
+      export NOTMUCH_PROFILE=default
+      export NOTMUCH_CONFIG=${config.xdg.configHome}/notmuch/$NOTMUCH_PROFILE/config
+      export NMBGIT=${config.xdg.dataHome}/notmuch/nmbug
+
+      set -x
+      ${pkgs.coreutils}/bin/mkdir -p ${config.home.homeDirectory}/mail/accounts
+      ${pkgs.afew}/bin/afew --move-mails --verbose
+    '';
+    xdg.configFile."mbsync/postExec".source = pkgs.writeShellScript "mbsync-postExec" ''
+      export NOTMUCH_PROFILE=default
+      export NOTMUCH_CONFIG=${config.xdg.configHome}/notmuch/$NOTMUCH_PROFILE/config
+      export NMBGIT=${config.xdg.dataHome}/notmuch/nmbug
+
+      set -x
+      ${pkgs.notmuch}/bin/notmuch new
+      ${pkgs.afew}/bin/afew --tag --new --verbose
+      # Remove inbox (lower-case)
+      #${pkgs.notmuch}/bin/notmuch tag -inbox -- tag:inbox
+      # Remove Inbox tagged message that are not in an Inbox
+      #${pkgs.notmuch}/bin/notmuch tag -Inbox -- not folder:perso/Inbox and tag:Inbox
+      ${pkgs.libnotify}/bin/notify-send "Mails synced 📬"
+    '';
+    home.file."bin/msync".source = pkgs.writeShellScript "msync" ''
+      ${pkgs.libnotify}/bin/notify-send "Syncing mails 📫️"
+      systemctl --user start mbsync
+    '';
+    programs.mbsync.enable = true;
+    programs.notmuch.enable = true;
+    programs.afew = {
+      enable = true;
+      extraConfig = ''
+        [SpamFilter]
+        [KillThreadsFilter]
+        [MeFilter]
+        [ListMailsFilter]
+        [ArchiveSentMailsFilter]
+        sent_tag = sent
+        [FolderNameFilter]
+        maildir_separator = /
+        [InboxFilter]
+
+        [MailMover]
+        folders = Junk
+        rename = true
+
+        Junk = 'NOT tag:spam':INBOX
+      '';
+    };
+    programs.astroid = {
+      enable = true;
+      externalEditor = "emacsclient -c";
+      extraConfig = {
+        startup.queries.new = "tag:new";
+        startup.queries.inbox = "tag:inbox";
+        startup.queries.testbox = "to:testbox";
+        startup.queries.mail = "folder:mail/accounts/testbox";
+      };
+    };
+  })
+];
+}