{ pkgs, ... }:

let
  homedir = builtins.getEnv "HOME";
  gpgid = "D09299626FA78AF8";
in
{
  accounts = {
    email = {
      maildirBasePath = "${homedir}/Mail";
      accounts = {
        "ben@bsima.me" = {
          primary = true;
          realName = "Ben Sima";
          address = "ben@bsima.me";
          userName = "ben@simatime.com";
          alot.sendMailCommand = "${homedir}/bin/sendmail";
          folders = {
            inbox = "INBOX";
          };
          imap = {
            host = "simatime.com";
            port = 993;
          };
          smtp = {
            host = "simatime.com";
            port = 587;
            tls = {
              enable = true;
              useStartTls = true;
            };
          };
          gpg = {
            key = gpgid;
            signByDefault = true;
            encryptByDefault = false;
          };
          mbsync = {
            enable = true;
            create = "both";
            expunge = "none";
          };
          notmuch.enable = true;
          msmtp.enable = true;
          passwordCommand = "cat ~/keybase/private/bsima/ben@bsima.me";
        };

        "ben@simatime.com" = {
          realName = "Ben Sima";
          address = "ben@simatime.com";
          userName = "ben@simatime.com";
          imap = {
            host = "simatime.com";
            port = 993;
          };
          smtp = {
            host = "simatime.com";
            port = 587;
            tls = {
              enable = true;
              useStartTls = true;
            };

          };
          mbsync = {
            enable = true;
            create = "both";
            expunge = "none";
          };
          notmuch.enable = true;
          passwordCommand = "cat ~/keybase/private/bsima/ben@simatime.com";
          msmtp.enable = true;
        };

        #"ben.sima@heroprojects.io" = {
        #  flavor = "gmail.com";
        #  realName = "Ben Sima";
        #  address = "ben.sima@heroprojects.io";
        #  userName = "ben.sima@heroprojects.io";
        #  mbsync = {
        #    enable = true;
        #    create = "both";
        #    expunge = "none";
        #  };
        #  notmuch.enable = true;
        #  msmtp.enable = true;
        #  passwordCommand = "pass work/hero/gmail";
        #};
      };
    };
  };

  programs = {
    notmuch = {
      enable = true;
      new.tags = [ "new" ];
      hooks = {};
      extraConfig = {
        search = {
          exclude_tags = "deleted;spam;";
        };
      };
    };

    afew = {
      enable = true;
      extraConfig = builtins.readFile ./afew.ini;
    };

    alot = {
      enable = true;
      extraConfig = ''
        theme = solarized_light
      '';
    };

    mbsync = {
      enable = true;
    };

    msmtp = {
      enable = true;
    };
  };
}