aboutsummaryrefslogtreecommitdiffstats
path: root/modules/programs/neomutt/default.nix
blob: 818e9215181f2334fadd0835fa4c63dc2a61ae12 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# neomutt - Terminal email client
{
  config,
  lib,
  pkgs,
  ...
}:
let
  neomuttDesktopItem = pkgs.makeDesktopItem {
    name = "neomutt";
    desktopName = "NeoMutt";
    exec = "${lib.getExe config.programs.kitty.package} -e ${lib.getExe config.programs.neomutt.package}";
    icon = "kitty";
    categories = [
      "Network"
      "Email"
    ];
    comment = "Terminal email client";
    terminal = false;
    type = "Application";
  };
in
{
  imports = [
    ./assertions.nix
    ./theme.nix
  ];
  config = lib.mkIf config.programs.neomutt.enable {
    xdg.mimeApps.defaultApplications = {
      "x-scheme-handler/mailto" = "neomutt.desktop";
    };

    home.packages = [
      pkgs.urlscan
      pkgs.w3m
      neomuttDesktopItem
    ];

    xdg.configFile."neomutt/mailcap".text = ''
      text/html; w3m -dump -T text/html '%s'; copiousoutput; nametemplate=%s.html
      text/html; $BROWSER '%s'; nametemplate=%s.html
      image/*; xdg-open '%s' &
      application/pdf; xdg-open '%s'; nametemplate=%s.pdf
      video/*; xdg-open '%s' &
      audio/*; xdg-open '%s' &
      application/*; xdg-open '%s' &
    '';

    xdg.configFile."neomutt/flag_legend.txt".text = ''
      NeoMutt Index Flags
      ===================

      Message state ($flag_chars)
        N   New       - unread, arrived since you last checked
        O   Old       - unread, but seen in a previous session
        D   Deleted   - marked for deletion (pending expunge)
        d   Att-del   - has attachments marked for deletion
        !   Flagged   - important (toggle with F)
        *   Tagged    - selected for a bulk operation (toggle with t)
        r   Replied   - you've replied to this message
        S   Signed    - PGP/SMIME signed
        P   Encrypted - PGP/SMIME encrypted
        s   Cert      - contains a S/MIME certificate/key
        K   PGP key   - contains a PGP public key
        (blank)       - read, nothing else notable

      Addressing ($to_chars)
        +   To you only     - sent to you and only you
        T   To (with others) - you're in the To: list, among others
        C   Cc only          - you're only in the Cc: list
        F   From you         - sent by you
        L   Mailing list     - sent to a list you're subscribed to
        (blank)              - not in To/Cc (e.g. Bcc, unlisted)

      Press q to close.
    '';

    programs.neomutt = {
      sidebar.enable = true;
      sort = "reverse-threads";
      vimKeys = true;
      unmailboxes = true;
      checkStatsInterval = 20;

      extraConfig = ''
        # cancel any prompt/command-line entry with Esc, vim-style
        set abort_key = "<Esc>"

        # attachments: use our mailcap for dedicated openers,
        # and auto-render html/images inline where sensible
        set mailcap_path = "~/.config/neomutt/mailcap"
        auto_view text/html image/png image/jpeg image/gif application/pdf
      '';

      binds = [
        {
          map = [
            "index"
            "pager"
          ];
          key = "\\CK";
          action = "sidebar-prev";
        }
        {
          map = [
            "index"
            "pager"
          ];
          key = "\\CJ";
          action = "sidebar-next";
        }
        {
          # select the highlighted mailbox directly, no Ctrl+O needed
          map = [
            "index"
            "pager"
          ];
          key = "o";
          action = "sidebar-open";
        }

        {
          map = [ "index" ];
          key = "<Return>";
          action = "display-message";
        }
        {
          map = [ "browser" ];
          key = "<Return>";
          action = "select-entry";
        }
        {
          map = [ "attach" ];
          key = "<Return>";
          action = "view-attach";
        }
        {
          map = [
            "alias"
            "query"
          ];
          key = "<Return>";
          action = "select-entry";
        }
        {
          map = [ "pager" ];
          key = "<Return>";
          action = "next-page";
        }

        {
          map = [ "index" ];
          key = "l";
          action = "display-message";
        }
        {
          map = [ "pager" ];
          key = "h";
          action = "exit";
        }
        {
          map = [ "pager" ];
          key = "l";
          action = "next-unread";
        }
        {
          map = [ "index" ];
          key = "h";
          action = "collapse-thread";
        }

        {
          map = [ "pager" ];
          key = "0";
          action = "top";
        }
        {
          map = [ "pager" ];
          key = "$";
          action = "bottom";
        }
      ];

      macros = [
        {
          map = [
            "index"
            "pager"
          ];
          key = "O";
          action = "<sync-mailbox><shell-escape>mbsync -a<enter><sync-mailbox>";
        }
        {
          # gx: extract links from the current message and open one, vim-netrw style
          map = [
            "index"
            "pager"
          ];
          key = "gx";
          action = "<pipe-message>urlscan<Enter>";
        }
        {
          map = [
            "index"
            "pager"
          ];
          key = "gl";
          action = "<shell-escape>less ~/.config/neomutt/flag_legend.txt<enter>";
        }
      ];
    };
  };
}