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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
|
# 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
];
options.communication.neomutt = {
enable = lib.mkEnableOption "Enables neomutt.";
};
config = lib.mkIf config.communication.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) -- unchanged defaults
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
(blank) - read, nothing else notable
Cryptography ($crypt_chars)
Verified - signed, and the signature checks out
Encrypted - PGP/SMIME encrypted
Signed - PGP/SMIME signed (unverified)
PGP key - message contains a PGP public key
(blank) - no cryptography info
Addressing ($to_chars)
To you only - sent to you and only you
To (with others) - you're in the To: list, among others
Cc only - you're only in the Cc: list
From you - sent by you
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 = ''
set menu_scroll = yes
# 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 = [
# --- sidebar navigation (vim: k=up, j=down) ---
{
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";
}
# --- open / go deeper (vim: l = right/forward) ---
{
map = [ "index" ];
key = "<Return>";
action = "display-message";
}
{
map = [ "index" ];
key = "l";
action = "display-message";
}
{
map = [ "browser" ];
key = "<Return>";
action = "select-entry";
}
{
map = [ "browser" ];
key = "l";
action = "select-entry";
}
{
map = [ "attach" ];
key = "<Return>";
action = "view-attach";
}
{
map = [ "attach" ];
key = "l";
action = "view-attach";
}
{
map = [
"alias"
"query"
];
key = "<Return>";
action = "select-entry";
}
# --- back / exit (vim: h = left/back) ---
{
map = [ "pager" ];
key = "h";
action = "exit";
}
{
map = [ "browser" ];
key = "h";
action = "exit";
}
{
map = [ "attach" ];
key = "h";
action = "exit";
}
{
map = [ "index" ];
key = "h";
action = "collapse-thread";
}
# --- pager line scrolling (vim: j/k move by line) ---
{
map = [ "pager" ];
key = "j";
action = "next-line";
}
{
map = [ "pager" ];
key = "k";
action = "previous-line";
}
{
# kept from before: jump straight to the next unread message,
# extends the h/l "back/forward" metaphor already in use
map = [ "pager" ];
key = "l";
action = "next-unread";
}
# --- top/bottom of buffer (vim: gg/G -- NOT 0/$, which mean
# start/end of *line* in vim and would be a false friend here) ---
{
map = [ "index" ];
key = "gg";
action = "first-entry";
}
{
map = [ "index" ];
key = "G";
action = "last-entry";
}
{
map = [ "pager" ];
key = "gg";
action = "top";
}
{
map = [ "pager" ];
key = "G";
action = "bottom";
}
{
map = [ "browser" ];
key = "gg";
action = "first-entry";
}
{
map = [ "browser" ];
key = "G";
action = "last-entry";
}
# --- page scrolling (vim: Ctrl-f/b full page, Ctrl-d/u half page) ---
{
map = [ "pager" ];
key = "\\Cf";
action = "next-page";
}
{
map = [ "pager" ];
key = "\\Cb";
action = "previous-page";
}
{
map = [ "pager" ];
key = "\\Cd";
action = "half-down";
}
{
map = [ "pager" ];
key = "\\Cu";
action = "half-up";
}
{
# index has no half-page concept, so Ctrl-d/u fall back to
# the same full-page scroll as Ctrl-f/b
map = [ "index" ];
key = "\\Cf";
action = "next-page";
}
{
map = [ "index" ];
key = "\\Cb";
action = "previous-page";
}
{
map = [ "index" ];
key = "\\Cd";
action = "half-down";
}
{
map = [ "index" ];
key = "\\Cu";
action = "half-up";
}
# --- search (vim: / forward, ? backward, n/N repeat) ---
{
map = [
"index"
"pager"
];
key = "/";
action = "search";
}
{
map = [
"index"
"pager"
];
key = "?";
action = "search-reverse";
}
{
map = [
"index"
"pager"
];
key = "n";
action = "search-next";
}
{
map = [
"index"
"pager"
];
key = "N";
action = "search-opposite";
}
{
map = [
"index"
"pager"
];
key = "u";
action = "undelete-message";
}
# --- copy (vim: yy yank -- non-destructive, unlike save-message
# which moves/deletes the original) ---
{
map = [ "index" ];
key = "y";
action = "noop";
}
{
map = [ "index" ];
key = "yy";
action = "copy-message";
}
# --- tagging (vim: v/V visual select single/whole block) ---
# NOTE: this overrides neomutt's default "v" (view-attachments).
# Attachments are still reachable from the pager/index via the
# mailcap auto-view or the attach menu, but if you want plain
# "v" back for view-attachments, just delete these two binds.
{
map = [ "index" ];
key = "v";
action = "tag-entry";
}
{
map = [ "index" ];
key = "V";
action = "tag-thread";
}
# --- mailbox switching (vim: gt = next tab) ---
{
map = [ "index" ];
key = "gt";
action = "next-unread-mailbox";
}
# --- filter/limit (vim: gf to 'find' or 'filter') ---
{
map = [ "index" ];
key = "gf";
action = "limit";
}
# --- filter/limit (vim: gf to 'find' or 'filter') ---
{
map = [ "index" ];
key = "gF";
action = "limit";
}
# --- help message to show functions and keybindings ---
{
map = [
"index"
"pager"
"browser"
"attach"
];
key = "g?";
action = "help";
}
];
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>";
}
{
# ZZ: save and quit, vim-style (sync mailbox, then quit)
map = [ "index" ];
key = "ZZ";
action = "<sync-mailbox><quit>";
}
];
};
};
}
|