aboutsummaryrefslogblamecommitdiff
path: root/home/mail/accounts/default.nix
blob: 97a5bbd14e4fdccd63f895cca186e8433c51ee77 (plain) (tree)
1
2
3
4

                              

  





























                                                           





                                                                  
                     











                                                         





                                      
                                    












                                                                                            















                                                                  
{ config, lib, pkgs, ... }:
let cfg = config.my.home.mail;
in
{
  config = lib.mkIf cfg.enable {
    accounts.email = {
      accounts = {
        Fastmail = rec {
          primary = true;
          address = "franck@fcuny.net";
          userName = address;
          realName = "Franck Cuny";
          aliases = [ "franck.cuny@gmail.com" ];
          passwordCommand = "pass email/imap.fastmail.com";
          imap.host = "imap.fastmail.com";
          mbsync = {
            enable = true;
            create = "maildir";
            expunge = "both";
            extraConfig.channel.CopyArrivalDate = "yes";
          };
          notmuch.enable = true;
        };
      };
    };

    programs.mbsync.enable = true;

    programs.afew = {
      enable = true;
      extraConfig = ''
        [SpamFilter]
        [KillThreadsFilter]
        [ArchiveSentMailsFilter]

        [FolderNameFilter]
        maildir_separator = /
        folder_transforms = Archive:archive Drafts:draft Sent:sent
        folder_lowercases = true

        [InboxFilter]
        [Filter.1]
        query = path:Fastmail/Archive/**
        tags = +archive;-new;-inbox
        message = Tag archived messages

        [MailMover]
        folders = Fastmail/Inbox
        rename = True
        max_age = 30

        # rules
        Fastmail/Inbox = 'NOT tag:inbox':Fastmail/Archive
      '';
    };

    programs.notmuch = {
      enable = true;
      maildir.synchronizeFlags = true;
      new.tags = [ "unread" "new" ];
      new.ignore = [ "Trash" ];
      search.excludeTags = [ "spam" "deleted" ];
      hooks = {
        postNew = "${config.home.profileDirectory}/bin/afew -v --tag --new";
      };
    };

    systemd.user.services.mbsync = {
      Unit = { Description = "mbsync synchronization"; };
      Service = {
        Type = "oneshot";
        Environment = [
          "PASSWORD_STORE_DIR=${config.programs.password-store.settings.PASSWORD_STORE_DIR}"
        ];
        ExecStart = "${pkgs.isync}/bin/mbsync -a";
        ExecStartPost = "${pkgs.notmuch}/bin/notmuch new --quiet";
      };
    };

    systemd.user.timers.mbsync = {
      Unit = { Description = "mbsync synchronization"; };
      Timer = {
        OnBootSec = "30";
        OnUnitActiveSec = "5m";
      };
      Install = { WantedBy = [ "timers.target" ]; };
    };
  };
}