aboutsummaryrefslogtreecommitdiff
path: root/users/tdback/modules/email/default.nix
blob: 37534dbed22cee74f0cad034727ac954ca7c239c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
{
  config,
  lib,
  pkgs,
  ...
}:
let
  username = config.home.username;
  email = "tyler@tdback.net";
  provider = "fastmail.com";
  mailboxes = lib.attrValues config.accounts.email.accounts.${username}.folders;
in
{
  accounts.email.maildirBasePath = "mail";
  accounts.email.accounts = {
    ${username} = {
      primary = true;
      address = email;
      userName = email;
      realName = "Tyler Dunneback";
      passwordCommand = "${lib.getExe pkgs.age} -d -i ~/.ssh/mail ~/.mail.age";

      imap = {
        host = "imap.${provider}";
        port = 993;
        tls.enable = true;
      };

      smtp = {
        host = "smtp.${provider}";
        port = 465;
        tls.enable = true;
      };

      mbsync = {
        enable = true;
        create = "both";
      };

      msmtp = {
        enable = true;
        extraConfig.logfile = "~/.cache/msmtp/msmtp.log";
      };

      neomutt = {
        enable = true;
        sendMailCommand = lib.getExe pkgs.msmtp;
        extraMailboxes = mailboxes;
      };
    };
  };

  services.mbsync.enable = true;

  programs.neomutt =
    let
      mkAction =
        {
          key,
          action,
          map ? [
            "index"
            "pager"
          ],
        }:
        {
          inherit key action map;
        };
    in
    {
      enable = true;
      package = pkgs.unstable.neomutt;
      vimKeys = true;
      sort = "reverse-date";
      checkStatsInterval = 60;
      sidebar.enable = true;
      binds = [
        (mkAction {
          key = "\\Cp";
          action = "sidebar-prev";
        })
        (mkAction {
          key = "\\Cn";
          action = "sidebar-next";
        })
        (mkAction {
          key = "\\Cy";
          action = "sidebar-open";
        })
      ];
      macros = [
        (mkAction {
          key = "gi";
          action = "<change-folder>=Inbox<enter>";
        })
        (mkAction {
          key = "gs";
          action = "<change-folder>=Sent<enter>";
        })
        (mkAction {
          key = "gd";
          action = "<change-folder>=Drafts<enter>";
        })
        (mkAction {
          key = "gt";
          action = "<change-folder>=Trash<enter>";
        })
        (mkAction {
          key = "ga";
          action = "<change-folder>=Archive<enter>";
        })
        (mkAction {
          map = [ "index" ];
          key = "S";
          action = "<shell-escape>${lib.getExe pkgs.isync} -a<enter>";
        })
      ];
    };
}