This repository has no description
11 kB
291 lines
1{ self, ... }:
2{
3 perSystem =
4 { pkgs, lib, ... }:
5 {
6 packages.mutt =
7 let
8 # Mailboxes configuration from mail.nix
9 mailboxes = {
10 afra = [ "to:afra@afra-berlin.de" ];
11 c-base = [ "to:c-base.org" ];
12 coins = [
13 "to:btce@lassul.us"
14 "to:coinbase@lassul.us"
15 "to:polo@lassul.us"
16 "to:bitwala@lassul.us"
17 "to:payeer@lassul.us"
18 "to:gatehub@lassul.us"
19 "to:bitfinex@lassul.us"
20 "to:binance@lassul.us"
21 "to:bitcoin.de@lassul.us"
22 "to:robinhood@lassul.us"
23 ];
24 dezentrale = [ "to:dezentrale.space" ];
25 dhl = [ "to:dhl@lassul.us" ];
26 dn42 = [ "to:dn42@lists.nox.tf" ];
27 eloop = [ "to:eloop.org" ];
28 github = [ "to:github@lassul.us" ];
29 gmail = [
30 "to:gmail@lassul.us"
31 "to:lassulus@gmail.com"
32 "lassulus@googlemail.com"
33 ];
34 india = [
35 "to:hillhackers@lists.hillhacks.in"
36 "to:hackbeach@lists.hackbeach.in"
37 "to:hackbeach@mail.hackbeach.in"
38 ];
39 kaosstuff = [
40 "to:gearbest@lassul.us"
41 "to:banggood@lassul.us"
42 "to:tomtop@lassul.us"
43 ];
44 lugs = [ "to:lugs@lug-s.org" ];
45 meetup = [ "to:meetup@lassul.us" ];
46 nix = [
47 "to:nix-devel@googlegroups.com"
48 "to:nix@lassul.us"
49 ];
50 patreon = [ "to:patreon@lassul.us" ];
51 paypal = [ "to:paypal@lassul.us" ];
52 ptl = [ "to:ptl@posttenebraslab.ch" ];
53 retiolum = [ "to:lass@mors.r" ];
54 security = [
55 "to:seclists.org"
56 "to:bugtraq"
57 "to:securityfocus@lassul.us"
58 "to:security-announce@lists.apple.com"
59 ];
60 shack = [ "to:shackspace.de" ];
61 steam = [ "to:steam@lassul.us" ];
62 tinc = [
63 "to:tinc@tinc-vpn.org"
64 "to:tinc-devel@tinc-vpn.org"
65 ];
66 wireguard = [ "to:wireguard@lists.zx2c4" ];
67 zzz = [
68 "to:pizza@lassul.us"
69 "to:spam@krebsco.de"
70 ];
71 };
72
73 notmuchConfig = ''
74 [database]
75 path=Maildir
76 mail_root=Maildir
77
78 [user]
79 name=lassulus
80 primary_email=lassulus@lassul.us
81 other_email=lass@mors.r;${lib.concatStringsSep ";" (lib.flatten (lib.attrValues mailboxes))}
82
83 [new]
84 tags=unread;inbox;
85 ignore=
86
87 [search]
88 exclude_tags=deleted;spam;
89
90 [maildir]
91 synchronize_flags=true
92 '';
93
94 mailcap = pkgs.writeText "mailcap" ''
95 text/html; ${pkgs.elinks}/bin/elinks -dump ; copiousoutput;
96 '';
97
98 msmtprc = pkgs.writeText "msmtprc" ''
99 defaults
100 logfile ~/.msmtp.log
101 account prism
102 host prism.r
103 account c-base
104 from lassulus@c-base.org
105 host c-mail.c-base.org
106 port 465
107 tls on
108 tls_starttls off
109 auth on
110 user lassulus
111 passwordeval pass show c-base/pass
112 account default: prism
113 '';
114
115 msmtp = pkgs.writeShellScriptBin "msmtp" ''
116 # Check if prism.r is reachable, fallback to Tor if not
117 if ping -W2 -c1 prism.r >/dev/null 2>&1; then
118 ${pkgs.coreutils}/bin/tee >(${pkgs.notmuch}/bin/notmuch insert +sent) | \
119 ${pkgs.msmtp}/bin/msmtp -C ${msmtprc} "$@"
120 else
121 # Build dependencies lazily for Tor fallback
122 echo "Building tornade and clan-cli for Tor fallback..." >&2
123 tornade_path=$(nix build --no-link --print-out-paths "${self}#tornade")
124 clan_path=$(nix build --no-link --print-out-paths "${self}#clan-cli")
125
126 # Get tor hostname using clan CLI
127 tor_hostname=$(CLAN_DIR="${self}" "$clan_path/bin/clan" vars get prism tor-ssh/tor-hostname)
128
129 # Use tornade to send via Tor
130 ${pkgs.coreutils}/bin/tee >(${pkgs.notmuch}/bin/notmuch insert +sent) | \
131 "$tornade_path/bin/tornade" ssh -T lass@"$tor_hostname" "cat | msmtp -C /etc/msmtprc $*"
132 fi
133 '';
134
135 muttrc = pkgs.writeText "muttrc" ''
136 # read html mails
137 auto_view text/html
138 set mailcap_path = ${mailcap}
139
140 # notmuch
141 set folder="$HOME/Maildir"
142 set nm_default_uri = "notmuch://$HOME/Maildir"
143 set nm_record = yes
144 set nm_record_tags = "-inbox me archive"
145 set spoolfile = +Inbox
146 set virtual_spoolfile = yes
147
148 set sendmail="${msmtp}/bin/msmtp"
149 set from="lassulus@lassul.us"
150 alternates ^.*@lassul\.us$ ^.*@.*\.r$
151 unset envelope_from_address
152 set use_envelope_from
153 set reverse_name
154 set markers=no
155
156 set sort=threads
157
158 set index_format="%4C %Z %?GI?%GI& ? %[%y-%m-%d] %-20.20a %?M?(%3M)& ? %s %> %r %g"
159
160 virtual-mailboxes "Unread" "notmuch://?query=tag:unread"
161 virtual-mailboxes "INBOX" "notmuch://?query=tag:inbox"
162 ${lib.concatMapStringsSep "\n" (
163 i: ''${" "}virtual-mailboxes "${i.name}" "notmuch://?query=tag:${i.name}"''
164 ) (lib.mapAttrsToList lib.nameValuePair mailboxes)}
165 virtual-mailboxes "TODO" "notmuch://?query=tag:TODO"
166 virtual-mailboxes "Starred" "notmuch://?query=tag:*"
167 virtual-mailboxes "Archive" "notmuch://?query=tag:archive"
168 virtual-mailboxes "Sent" "notmuch://?query=tag:sent"
169 virtual-mailboxes "Junk" "notmuch://?query=tag:junk"
170 virtual-mailboxes "All" "notmuch://?query=*"
171
172 tag-transforms "junk" "k" \
173 "unread" "u" \
174 "replied" "↻" \
175 "TODO" "T" \
176
177 # notmuch bindings
178 macro index \\\\ "<vfolder-from-query>"
179 macro index + "<modify-labels>+*\n<sync-mailbox>"
180 macro index - "<modify-labels>-*\n<sync-mailbox>"
181
182 # muchsync
183 bind index \Cr noop
184 macro index \Cr \
185 "<enter-command>unset wait_key<enter> \
186 <sync-mailbox> \
187 <shell-escape>${self.packages.${pkgs.system}.muchsync}/bin/muchsync -vv<enter> \
188 <sync-mailbox>
189
190 #killed
191 bind index d noop
192 bind pager d noop
193
194 bind index S noop
195 bind index s noop
196 bind pager S noop
197 bind pager s noop
198 macro index S "<modify-labels-then-hide>-inbox -unread +junk\n"
199 macro index s "<modify-labels>-junk\n"
200 macro pager S "<modify-labels-then-hide>-inbox -unread +junk\n"
201 macro pager s "<modify-labels>-junk\n"
202
203 bind index A noop
204 bind index a noop
205 bind pager A noop
206 bind pager a noop
207 macro index A "<modify-labels>+archive -unread -inbox\n"
208 macro index a "<modify-labels>-archive\n"
209 macro pager A "<modify-labels>+archive -unread -inbox\n"
210 macro pager a "<modify-labels>-archive\n"
211
212 bind index U noop
213 bind index u noop
214 bind pager U noop
215 bind pager u noop
216 macro index U "<modify-labels>+unread\n"
217 macro index u "<modify-labels>-unread\n"
218 macro pager U "<modify-labels>+unread\n"
219 macro pager u "<modify-labels>-unread\n"
220
221 bind index t noop
222 bind pager t noop
223 macro index t "<modify-labels>"
224
225 # top index bar in email view
226 set pager_index_lines=7
227 # top_index_bar toggle
228 macro pager ,@1 "<enter-command> set pager_index_lines=0; macro pager ] ,@2 'Toggle indexbar<Enter>"
229 macro pager ,@2 "<enter-command> set pager_index_lines=3; macro pager ] ,@3 'Toggle indexbar<Enter>"
230 macro pager ,@3 "<enter-command> set pager_index_lines=7; macro pager ] ,@1 'Toggle indexbar<Enter>"
231 macro pager ] ,@1 'Toggle indexbar
232
233 # scan urls from emails
234 macro index,pager \cb "<pipe-message> ${lib.getExe pkgs.urlscan}<Enter>"
235 macro attach,compose \cb "<pipe-entry> ${lib.getExe pkgs.urlscan}<Enter>"
236
237 # sidebar
238 set sidebar_divider_char = '│'
239 set sidebar_delim_chars = "/"
240 set sidebar_short_path
241 set sidebar_folder_indent
242 set sidebar_visible = yes
243 set sidebar_format = '%D%?F? [%F]?%* %?N?%N/? %?S?%S?'
244 set sidebar_width = 20
245 color sidebar_new yellow red
246
247 # sidebar bindings
248 bind index <left> sidebar-prev
249 bind index <right> sidebar-next
250 bind index <space> sidebar-open
251 # sidebar toggle
252 macro index,pager ,@) "<enter-command> set sidebar_visible=no; macro index,pager [ ,@( 'Toggle sidebar'<Enter>"
253 macro index,pager ,@( "<enter-command> set sidebar_visible=yes; macro index,pager [ ,@) 'Toggle sidebar'<Enter>"
254 macro index,pager [ ,@( 'Toggle sidebar'
255
256 # forward with attachment
257 set mime_forward = no
258 set forward_attachments = yes
259
260 # better handling of long URLs
261 set wrap = 0 # don't wrap lines in the pager
262 set markers = no # don't show + markers for wrapped lines
263 set smart_wrap = yes # wrap at word boundaries when displaying
264 set pager_stop = yes # don't jump to next message at end of pager
265 '';
266
267 in
268 (pkgs.writeShellApplication {
269 name = "mutt";
270 runtimeInputs =
271 [
272 pkgs.neomutt
273 pkgs.elinks
274 pkgs.msmtp
275 pkgs.notmuch
276 pkgs.urlscan
277 ]
278 ++ lib.optionals pkgs.stdenv.isLinux [
279 pkgs.iputils
280 ];
281 text = ''
282 export NOTMUCH_CONFIG_FILE=${pkgs.writeText "notmuch-config" notmuchConfig}
283 export MUTTRC=${muttrc}
284 ${builtins.readFile ./mutt.sh}
285 '';
286 })
287 // {
288 passthru.notmuchConfig = notmuchConfig;
289 };
290 };
291}