forked from
lass.pds.lassul.us/superconfig
This repository has no description
8.7 kB
225 lines
1{ self, ... }:
2{
3 perSystem =
4 {
5 pkgs,
6 lib,
7 system,
8 ...
9 }:
10 {
11 packages.mutt =
12 let
13 # Mailboxes configuration from mail.nix
14 mailboxes = self.packages.${system}.notmuch.mailboxes;
15 notmuchConfig = self.packages.${system}.notmuch.passthru.config.configFile.path;
16
17 mailcap = pkgs.writeText "mailcap" ''
18 text/html; ${pkgs.elinks}/bin/elinks -dump ; copiousoutput;
19 '';
20
21 msmtprc = pkgs.writeText "msmtprc" ''
22 defaults
23 logfile ~/.msmtp.log
24 account prism
25 host prism.r
26 account c-base
27 from lassulus@c-base.org
28 host c-mail.c-base.org
29 port 465
30 tls on
31 tls_starttls off
32 auth on
33 user lassulus
34 passwordeval pass show c-base/pass
35 account default: prism
36 '';
37
38 msmtp = pkgs.writeShellScriptBin "msmtp" ''
39 # Check if using c-base account (either explicit -a c-base or via From: header)
40 using_cbase=0
41 for arg in "$@"; do
42 if [[ "$arg" == "c-base" ]] || [[ "$arg" =~ @c-base\.org ]]; then
43 using_cbase=1
44 break
45 fi
46 done
47
48 # For c-base account, always send directly (no Tor needed)
49 if [ "$using_cbase" -eq 1 ]; then
50 ${pkgs.coreutils}/bin/tee >(${pkgs.notmuch}/bin/notmuch insert +sent) | \
51 ${pkgs.msmtp}/bin/msmtp -C ${msmtprc} "$@"
52 # For prism account, check if prism.r is reachable
53 elif ping -W2 -c1 prism.r >/dev/null 2>&1; then
54 ${pkgs.coreutils}/bin/tee >(${pkgs.notmuch}/bin/notmuch insert +sent) | \
55 ${pkgs.msmtp}/bin/msmtp -C ${msmtprc} "$@"
56 else
57 echo "Error: prism.r is not reachable" >&2
58 exit 1
59 fi
60 '';
61
62 muttrc = pkgs.writeText "muttrc" ''
63 # read html mails
64 auto_view text/html
65 set mailcap_path = ${mailcap}
66
67 # notmuch
68 set folder="$HOME/Maildir"
69 set nm_default_uri = "notmuch://$HOME/Maildir"
70 set nm_record = yes
71 set nm_record_tags = "-inbox me archive"
72 set spoolfile = +Inbox
73 set virtual_spoolfile = yes
74
75 set sendmail="${msmtp}/bin/msmtp"
76 set from="lassulus@lassul.us"
77 alternates ^.*@lassul\.us$ ^.*@.*\.r$
78 unset envelope_from_address
79 set use_envelope_from
80 set reverse_name
81 set markers=no
82
83 set sort=threads
84
85 set index_format="%4C %Z %?GI?%GI& ? %[%y-%m-%d] %-20.20a %?M?(%3M)& ? %s %> %r %g"
86
87 virtual-mailboxes "Unread" "notmuch://?query=tag:unread"
88 virtual-mailboxes "INBOX" "notmuch://?query=tag:inbox"
89 ${lib.concatMapStringsSep "\n" (
90 i: ''${" "}virtual-mailboxes "${i.name}" "notmuch://?query=tag:${i.name}"''
91 ) (lib.mapAttrsToList lib.nameValuePair mailboxes)}
92 virtual-mailboxes "TODO" "notmuch://?query=tag:TODO"
93 virtual-mailboxes "Starred" "notmuch://?query=tag:*"
94 virtual-mailboxes "Archive" "notmuch://?query=tag:archive"
95 virtual-mailboxes "Sent" "notmuch://?query=tag:sent"
96 virtual-mailboxes "Junk" "notmuch://?query=tag:junk"
97 virtual-mailboxes "All" "notmuch://?query=*"
98
99 # clan.lol IMAP
100 set imap_user = "infra@clan.lol"
101 set imap_pass = "`SOPS_AGE_KEY=$(rbw get --folder clan.lol clan-infra --field age-key) nix develop git+https://git.clan.lol/clan/clan-infra -c clan vars get --flake git+https://git.clan.lol/clan/clan-infra web01 infra-mail/infra-password`"
102 named-mailboxes "clan-infra/INBOX" "imaps://mail.clan.lol/INBOX"
103 named-mailboxes "clan-infra/Sent" "imaps://mail.clan.lol/Sent"
104 named-mailboxes "clan-infra/Drafts" "imaps://mail.clan.lol/Drafts"
105 named-mailboxes "clan-infra/Trash" "imaps://mail.clan.lol/Trash"
106 named-mailboxes "clan-infra/Junk" "imaps://mail.clan.lol/Junk"
107
108 tag-transforms "junk" "k" \
109 "unread" "u" \
110 "replied" "↻" \
111 "TODO" "T" \
112
113 # notmuch bindings
114 macro index \\\\ "<vfolder-from-query>"
115 macro index + "<modify-labels>+*\n<sync-mailbox>"
116 macro index - "<modify-labels>-*\n<sync-mailbox>"
117
118 # muchsync
119 bind index \Cr noop
120 macro index \Cr \
121 "<enter-command>unset wait_key<enter> \
122 <sync-mailbox> \
123 <shell-escape>${self.packages.${pkgs.system}.muchsync}/bin/muchsync -vv<enter> \
124 <sync-mailbox>
125
126 #killed
127 bind index d noop
128 bind pager d noop
129
130 bind index S noop
131 bind index s noop
132 bind pager S noop
133 bind pager s noop
134 macro index S "<modify-labels-then-hide>-inbox -unread +junk\n"
135 macro index s "<modify-labels>-junk\n"
136 macro pager S "<modify-labels-then-hide>-inbox -unread +junk\n"
137 macro pager s "<modify-labels>-junk\n"
138
139 bind index A noop
140 bind index a noop
141 bind pager A noop
142 bind pager a noop
143 macro index A "<modify-labels>+archive -unread -inbox\n"
144 macro index a "<modify-labels>-archive\n"
145 macro pager A "<modify-labels>+archive -unread -inbox\n"
146 macro pager a "<modify-labels>-archive\n"
147
148 bind index U noop
149 bind index u noop
150 bind pager U noop
151 bind pager u noop
152 macro index U "<modify-labels>+unread\n"
153 macro index u "<modify-labels>-unread\n"
154 macro pager U "<modify-labels>+unread\n"
155 macro pager u "<modify-labels>-unread\n"
156
157 bind index t noop
158 bind pager t noop
159 macro index t "<modify-labels>"
160
161 # top index bar in email view
162 set pager_index_lines=7
163 # top_index_bar toggle
164 macro pager ,@1 "<enter-command> set pager_index_lines=0; macro pager ] ,@2 'Toggle indexbar<Enter>"
165 macro pager ,@2 "<enter-command> set pager_index_lines=3; macro pager ] ,@3 'Toggle indexbar<Enter>"
166 macro pager ,@3 "<enter-command> set pager_index_lines=7; macro pager ] ,@1 'Toggle indexbar<Enter>"
167 macro pager ] ,@1 'Toggle indexbar
168
169 # scan urls from emails
170 macro index,pager \cb "<pipe-message> ${lib.getExe pkgs.urlscan}<Enter>"
171 macro attach,compose \cb "<pipe-entry> ${lib.getExe pkgs.urlscan}<Enter>"
172
173 # sidebar
174 set sidebar_divider_char = '│'
175 set sidebar_delim_chars = "/"
176 set sidebar_short_path
177 set sidebar_folder_indent
178 set sidebar_visible = yes
179 set sidebar_format = '%D%?F? [%F]?%* %?N?%N/? %?S?%S?'
180 set sidebar_width = 20
181 color sidebar_new yellow red
182
183 # sidebar bindings
184 bind index <left> sidebar-prev
185 bind index <right> sidebar-next
186 bind index <space> sidebar-open
187 # sidebar toggle
188 macro index,pager ,@) "<enter-command> set sidebar_visible=no; macro index,pager [ ,@( 'Toggle sidebar'<Enter>"
189 macro index,pager ,@( "<enter-command> set sidebar_visible=yes; macro index,pager [ ,@) 'Toggle sidebar'<Enter>"
190 macro index,pager [ ,@( 'Toggle sidebar'
191
192 # forward with attachment
193 set mime_forward = no
194 set forward_attachments = yes
195
196 # better handling of long URLs
197 set wrap = 0 # don't wrap lines in the pager
198 set markers = no # don't show + markers for wrapped lines
199 set smart_wrap = yes # wrap at word boundaries when displaying
200 set pager_stop = yes # don't jump to next message at end of pager
201 '';
202
203 in
204 self.wrapLib.makeWrapper {
205 pkgs = pkgs;
206 package = pkgs.neomutt;
207 aliases = [ "mutt" ];
208 runtimeInputs = [
209 pkgs.elinks
210 pkgs.msmtp
211 pkgs.notmuch
212 pkgs.urlscan
213 ]
214 ++ lib.optionals pkgs.stdenv.isLinux [
215 pkgs.iputils
216 ];
217 env = {
218 NOTMUCH_CONFIG = notmuchConfig;
219 };
220 flags = {
221 "-F" = "${muttrc}";
222 };
223 };
224 };
225}