This repository has no description
9.8 kB
314 lines
1{ lib, pkgs, ... }:
2
3let
4
5 msmtprc = pkgs.writeText "msmtprc" ''
6 defaults
7 logfile ~/.msmtp.log
8 account prism
9 host prism.r
10 account c-base
11 from lassulus@c-base.org
12 host c-mail.c-base.org
13 port 465
14 tls on
15 tls_starttls off
16 auth on
17 user lassulus
18 passwordeval pass show c-base/pass
19 account default: prism
20 '';
21
22 notmuch-config = pkgs.writeText "notmuch-config" ''
23 [database]
24 path=/home/lass/Maildir
25 mail_root=/home/lass/Maildir
26
27 [user]
28 name=lassulus
29 primary_email=lassulus@lassul.us
30 other_email=lass@mors.r;${lib.concatStringsSep ";" (lib.flatten (lib.attrValues mailboxes))}
31
32 [new]
33 tags=unread;inbox;
34 ignore=
35
36 [search]
37 exclude_tags=deleted;spam;
38
39 [maildir]
40 synchronize_flags=true
41 '';
42
43 msmtp = pkgs.writeBashBin "msmtp" ''
44 ${pkgs.coreutils}/bin/tee >(${pkgs.notmuch}/bin/notmuch insert +sent) | \
45 ${pkgs.msmtp}/bin/msmtp -C ${msmtprc} "$@"
46 '';
47
48 mailcap = pkgs.writeText "mailcap" ''
49 text/html; ${pkgs.elinks}/bin/elinks -dump ; copiousoutput;
50 '';
51
52 mailboxes = {
53 afra = [ "to:afra@afra-berlin.de" ];
54 c-base = [ "to:c-base.org" ];
55 coins = [
56 "to:btce@lassul.us"
57 "to:coinbase@lassul.us"
58 "to:polo@lassul.us"
59 "to:bitwala@lassul.us"
60 "to:payeer@lassul.us"
61 "to:gatehub@lassul.us"
62 "to:bitfinex@lassul.us"
63 "to:binance@lassul.us"
64 "to:bitcoin.de@lassul.us"
65 "to:robinhood@lassul.us"
66 ];
67 dezentrale = [ "to:dezentrale.space" ];
68 dhl = [ "to:dhl@lassul.us" ];
69 dn42 = [ "to:dn42@lists.nox.tf" ];
70 eloop = [ "to:eloop.org" ];
71 github = [ "to:github@lassul.us" ];
72 gmail = [
73 "to:gmail@lassul.us"
74 "to:lassulus@gmail.com"
75 "lassulus@googlemail.com"
76 ];
77 india = [
78 "to:hillhackers@lists.hillhacks.in"
79 "to:hackbeach@lists.hackbeach.in"
80 "to:hackbeach@mail.hackbeach.in"
81 ];
82 kaosstuff = [
83 "to:gearbest@lassul.us"
84 "to:banggood@lassul.us"
85 "to:tomtop@lassul.us"
86 ];
87 lugs = [ "to:lugs@lug-s.org" ];
88 meetup = [ "to:meetup@lassul.us" ];
89 nix = [
90 "to:nix-devel@googlegroups.com"
91 "to:nix@lassul.us"
92 ];
93 patreon = [ "to:patreon@lassul.us" ];
94 paypal = [ "to:paypal@lassul.us" ];
95 ptl = [ "to:ptl@posttenebraslab.ch" ];
96 retiolum = [ "to:lass@mors.r" ];
97 security = [
98 "to:seclists.org"
99 "to:bugtraq"
100 "to:securityfocus@lassul.us"
101 "to:security-announce@lists.apple.com"
102 ];
103 shack = [ "to:shackspace.de" ];
104 steam = [ "to:steam@lassul.us" ];
105 tinc = [
106 "to:tinc@tinc-vpn.org"
107 "to:tinc-devel@tinc-vpn.org"
108 ];
109 wireguard = [ "to:wireguard@lists.zx2c4" ];
110 zzz = [
111 "to:pizza@lassul.us"
112 "to:spam@krebsco.de"
113 ];
114 };
115
116 tag-new-mails = pkgs.writeDashBin "nm-tag-init" ''
117 ${pkgs.notmuch}/bin/notmuch new
118 ${lib.concatMapStringsSep "\n" (i: ''
119 mkdir -p "$HOME/Maildir/.${i.name}/cur"
120 for mail in $(${pkgs.notmuch}/bin/notmuch search --output=files 'tag:inbox and (${
121 lib.concatMapStringsSep " or " (f: "${f}") i.value
122 })'); do
123 if test -e "$mail"; then
124 mv "$mail" "$HOME/Maildir/.${i.name}/cur/"
125 else
126 echo "$mail does not exist"
127 fi
128 done
129 ${pkgs.notmuch}/bin/notmuch tag -inbox +${i.name} -- tag:inbox ${
130 lib.concatMapStringsSep " or " (f: "${f}") i.value
131 }
132 '') (lib.mapAttrsToList lib.nameValuePair mailboxes)}
133 ${pkgs.notmuch}/bin/notmuch new
134 ${pkgs.notmuch}/bin/notmuch dump > "$HOME/Maildir/notmuch.backup"
135 '';
136
137 tag-old-mails = pkgs.writeDashBin "nm-tag-old" ''
138 set -efux
139 ${lib.concatMapStringsSep "\n" (i: ''
140 ${pkgs.notmuch}/bin/notmuch tag -inbox -archive +${i.name} -- ${
141 lib.concatMapStringsSep " or " (f: "${f}") i.value
142 }
143 mkdir -p "$HOME/Maildir/.${i.name}/cur"
144 for mail in $(${pkgs.notmuch}/bin/notmuch search --output=files ${
145 lib.concatMapStringsSep " or " (f: "${f}") i.value
146 }); do
147 if test -e "$mail"; then
148 mv "$mail" "$HOME/Maildir/.${i.name}/cur/"
149 else
150 echo "$mail does not exist"
151 fi
152 done
153 '') (lib.mapAttrsToList lib.nameValuePair mailboxes)}
154 ${pkgs.notmuch}/bin/notmuch new --no-hooks
155 '';
156
157 muttrc = pkgs.writeText "muttrc" ''
158
159 # read html mails
160 auto_view text/html
161 set mailcap_path = ${mailcap}
162
163 # notmuch
164 set folder="$HOME/Maildir"
165 set nm_default_uri = "notmuch://$HOME/Maildir"
166 set nm_record = yes
167 set nm_record_tags = "-inbox me archive"
168 set spoolfile = +Inbox
169 set virtual_spoolfile = yes
170
171
172 set sendmail="${msmtp}/bin/msmtp" # enables parsing of outgoing mail
173 set from="lassulus@lassul.us"
174 alternates ^.*@lassul\.us$ ^.*@.*\.r$
175 unset envelope_from_address
176 set use_envelope_from
177 set reverse_name
178 set markers=no
179
180 set sort=threads
181
182 set index_format="%4C %Z %?GI?%GI& ? %[%y-%m-%d] %-20.20a %?M?(%3M)& ? %s %> %r %g"
183
184 virtual-mailboxes "Unread" "notmuch://?query=tag:unread"
185 virtual-mailboxes "INBOX" "notmuch://?query=tag:inbox"
186 ${lib.concatMapStringsSep "\n" (
187 i: ''${" "}virtual-mailboxes "${i.name}" "notmuch://?query=tag:${i.name}"''
188 ) (lib.mapAttrsToList lib.nameValuePair mailboxes)}
189 virtual-mailboxes "TODO" "notmuch://?query=tag:TODO"
190 virtual-mailboxes "Starred" "notmuch://?query=tag:*"
191 virtual-mailboxes "Archive" "notmuch://?query=tag:archive"
192 virtual-mailboxes "Sent" "notmuch://?query=tag:sent"
193 virtual-mailboxes "Junk" "notmuch://?query=tag:junk"
194 virtual-mailboxes "All" "notmuch://?query=*"
195
196 tag-transforms "junk" "k" \
197 "unread" "u" \
198 "replied" "↻" \
199 "TODO" "T" \
200
201 # notmuch bindings
202 macro index \\\\ "<vfolder-from-query>" # looks up a hand made query
203 macro index + "<modify-labels>+*\n<sync-mailbox>" # tag as starred
204 macro index - "<modify-labels>-*\n<sync-mailbox>" # tag as unstarred
205
206 # muchsync
207 bind index \Cr noop
208 macro index \Cr \
209 "<enter-command>unset wait_key<enter> \
210 <shell-escape>${pkgs.writeDash "muchsync" ''
211 set -efu
212 until ${pkgs.muchsync}/bin/muchsync -F lass@green.s; do
213 sleep 1
214 done
215 ''}<enter>
216
217 #killed
218 bind index d noop
219 bind pager d noop
220
221 bind index S noop
222 bind index s noop
223 bind pager S noop
224 bind pager s noop
225 macro index S "<modify-labels-then-hide>-inbox -unread +junk\n" # tag as Junk mail
226 macro index s "<modify-labels>-junk\n" # tag as Junk mail
227 macro pager S "<modify-labels-then-hide>-inbox -unread +junk\n" # tag as Junk mail
228 macro pager s "<modify-labels>-junk\n" # tag as Junk mail
229
230
231 bind index A noop
232 bind index a noop
233 bind pager A noop
234 bind pager a noop
235 macro index A "<modify-labels>+archive -unread -inbox\n" # tag as Archived
236 macro index a "<modify-labels>-archive\n" # tag as Archived
237 macro pager A "<modify-labels>+archive -unread -inbox\n" # tag as Archived
238 macro pager a "<modify-labels>-archive\n" # tag as Archived
239
240
241 bind index U noop
242 bind index u noop
243 bind pager U noop
244 bind pager u noop
245 macro index U "<modify-labels>+unread\n"
246 macro index u "<modify-labels>-unread\n"
247 macro pager U "<modify-labels>+unread\n"
248 macro pager u "<modify-labels>-unread\n"
249
250
251 bind index t noop
252 bind pager t noop
253 macro index t "<modify-labels>" # tag as Archived
254
255 # top index bar in email view
256 set pager_index_lines=7
257 # top_index_bar toggle
258 macro pager ,@1 "<enter-command> set pager_index_lines=0; macro pager ] ,@2 'Toggle indexbar<Enter>"
259 macro pager ,@2 "<enter-command> set pager_index_lines=3; macro pager ] ,@3 'Toggle indexbar<Enter>"
260 macro pager ,@3 "<enter-command> set pager_index_lines=7; macro pager ] ,@1 'Toggle indexbar<Enter>"
261 macro pager ] ,@1 'Toggle indexbar
262
263
264 # scan urls from emails
265 macro index,pager \cb "<pipe-message> ${lib.getExe pkgs.urlscan}<Enter>" "call urlscan to extract URLs out of a message"
266 macro attach,compose \cb "<pipe-entry> ${lib.getExe pkgs.urlscan}<Enter>" "call urlscan to extract URLs out of a message"
267
268 # sidebar
269 set sidebar_divider_char = '│'
270 set sidebar_delim_chars = "/"
271 set sidebar_short_path
272 set sidebar_folder_indent
273 set sidebar_visible = yes
274 set sidebar_format = '%D%?F? [%F]?%* %?N?%N/? %?S?%S?'
275 set sidebar_width = 20
276 color sidebar_new yellow red
277
278 # sidebar bindings
279 bind index <left> sidebar-prev # got to previous folder in sidebar
280 bind index <right> sidebar-next # got to next folder in sidebar
281 bind index <space> sidebar-open # open selected folder from sidebar
282 # sidebar toggle
283 macro index,pager ,@) "<enter-command> set sidebar_visible=no; macro index,pager [ ,@( 'Toggle sidebar'<Enter>"
284 macro index,pager ,@( "<enter-command> set sidebar_visible=yes; macro index,pager [ ,@) 'Toggle sidebar'<Enter>"
285 macro index,pager [ ,@( 'Toggle sidebar' # toggle the sidebar
286
287 # forward with attachment
288 # https://github.com/neomutt/neomutt/issues/1258#issuecomment-689522156
289 set mime_forward = no
290 set forward_attachments = yes
291 '';
292
293 mutt = pkgs.symlinkJoin {
294 name = "mutt";
295 paths = [
296 (pkgs.writeDashBin "mutt" ''
297 exec ${pkgs.neomutt}/bin/neomutt -F ${muttrc} "$@"
298 '')
299 pkgs.neomutt
300 ];
301 };
302
303in
304{
305 environment.variables.NOTMUCH_CONFIG = toString notmuch-config;
306 environment.systemPackages = [
307 msmtp
308 mutt
309 pkgs.notmuch
310 pkgs.muchsync
311 tag-new-mails
312 tag-old-mails
313 ];
314}