This repository has no description
9.5 kB
308 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
179 set sort=threads
180
181 set index_format="%4C %Z %?GI?%GI& ? %[%y-%m-%d] %-20.20a %?M?(%3M)& ? %s %> %r %g"
182
183 virtual-mailboxes "Unread" "notmuch://?query=tag:unread"
184 virtual-mailboxes "INBOX" "notmuch://?query=tag:inbox"
185 ${lib.concatMapStringsSep "\n" (
186 i: ''${" "}virtual-mailboxes "${i.name}" "notmuch://?query=tag:${i.name}"''
187 ) (lib.mapAttrsToList lib.nameValuePair mailboxes)}
188 virtual-mailboxes "TODO" "notmuch://?query=tag:TODO"
189 virtual-mailboxes "Starred" "notmuch://?query=tag:*"
190 virtual-mailboxes "Archive" "notmuch://?query=tag:archive"
191 virtual-mailboxes "Sent" "notmuch://?query=tag:sent"
192 virtual-mailboxes "Junk" "notmuch://?query=tag:junk"
193 virtual-mailboxes "All" "notmuch://?query=*"
194
195 tag-transforms "junk" "k" \
196 "unread" "u" \
197 "replied" "↻" \
198 "TODO" "T" \
199
200 # notmuch bindings
201 macro index \\\\ "<vfolder-from-query>" # looks up a hand made query
202 macro index + "<modify-labels>+*\n<sync-mailbox>" # tag as starred
203 macro index - "<modify-labels>-*\n<sync-mailbox>" # tag as unstarred
204
205 # muchsync
206 bind index \Cr noop
207 macro index \Cr \
208 "<enter-command>unset wait_key<enter> \
209 <shell-escape>${pkgs.writeDash "muchsync" ''
210 set -efu
211 until ${pkgs.muchsync}/bin/muchsync -F lass@green.s; do
212 sleep 1
213 done
214 ''}<enter>
215
216 #killed
217 bind index d noop
218 bind pager d noop
219
220 bind index S noop
221 bind index s noop
222 bind pager S noop
223 bind pager s noop
224 macro index S "<modify-labels-then-hide>-inbox -unread +junk\n" # tag as Junk mail
225 macro index s "<modify-labels>-junk\n" # tag as Junk mail
226 macro pager S "<modify-labels-then-hide>-inbox -unread +junk\n" # tag as Junk mail
227 macro pager s "<modify-labels>-junk\n" # tag as Junk mail
228
229
230 bind index A noop
231 bind index a noop
232 bind pager A noop
233 bind pager a noop
234 macro index A "<modify-labels>+archive -unread -inbox\n" # tag as Archived
235 macro index a "<modify-labels>-archive\n" # tag as Archived
236 macro pager A "<modify-labels>+archive -unread -inbox\n" # tag as Archived
237 macro pager a "<modify-labels>-archive\n" # tag as Archived
238
239
240 bind index U noop
241 bind index u noop
242 bind pager U noop
243 bind pager u noop
244 macro index U "<modify-labels>+unread\n"
245 macro index u "<modify-labels>-unread\n"
246 macro pager U "<modify-labels>+unread\n"
247 macro pager u "<modify-labels>-unread\n"
248
249
250 bind index t noop
251 bind pager t noop
252 macro index t "<modify-labels>" # tag as Archived
253
254 # top index bar in email view
255 set pager_index_lines=7
256 # top_index_bar toggle
257 macro pager ,@1 "<enter-command> set pager_index_lines=0; macro pager ] ,@2 'Toggle indexbar<Enter>"
258 macro pager ,@2 "<enter-command> set pager_index_lines=3; macro pager ] ,@3 'Toggle indexbar<Enter>"
259 macro pager ,@3 "<enter-command> set pager_index_lines=7; macro pager ] ,@1 'Toggle indexbar<Enter>"
260 macro pager ] ,@1 'Toggle indexbar
261
262 # sidebar
263 set sidebar_divider_char = '│'
264 set sidebar_delim_chars = "/"
265 set sidebar_short_path
266 set sidebar_folder_indent
267 set sidebar_visible = yes
268 set sidebar_format = '%D%?F? [%F]?%* %?N?%N/? %?S?%S?'
269 set sidebar_width = 20
270 color sidebar_new yellow red
271
272 # sidebar bindings
273 bind index <left> sidebar-prev # got to previous folder in sidebar
274 bind index <right> sidebar-next # got to next folder in sidebar
275 bind index <space> sidebar-open # open selected folder from sidebar
276 # sidebar toggle
277 macro index,pager ,@) "<enter-command> set sidebar_visible=no; macro index,pager [ ,@( 'Toggle sidebar'<Enter>"
278 macro index,pager ,@( "<enter-command> set sidebar_visible=yes; macro index,pager [ ,@) 'Toggle sidebar'<Enter>"
279 macro index,pager [ ,@( 'Toggle sidebar' # toggle the sidebar
280
281 # forward with attachment
282 # https://github.com/neomutt/neomutt/issues/1258#issuecomment-689522156
283 set mime_forward = no
284 set forward_attachments = yes
285 '';
286
287 mutt = pkgs.symlinkJoin {
288 name = "mutt";
289 paths = [
290 (pkgs.writeDashBin "mutt" ''
291 exec ${pkgs.neomutt}/bin/neomutt -F ${muttrc} "$@"
292 '')
293 pkgs.neomutt
294 ];
295 };
296
297in
298{
299 environment.variables.NOTMUCH_CONFIG = toString notmuch-config;
300 environment.systemPackages = [
301 msmtp
302 mutt
303 pkgs.notmuch
304 pkgs.muchsync
305 tag-new-mails
306 tag-old-mails
307 ];
308}