btw i use nix
1{
2 pkgs,
3 config,
4 lib,
5 ...
6}:
7
8let
9 address-book = pkgs.writeScriptBin "address-book" ''
10 #!/usr/bin/env bash
11 ${pkgs.mu}/bin/mu cfind "$1" | sed -E 's/(.*) (.*@.*)/\2\t\1/'
12 ${pkgs.ugrep}/bin/ugrep -jPh -m 100 --color=never "$1" cat ${config.accounts.email.maildirBasePath}/addressbook/cam-ldap)
13 '';
14 sync-mail = pkgs.writeScriptBin "sync-mail" ''
15 #!/usr/bin/env bash
16 ${pkgs.isync}/bin/mbsync "$1" || exit 1
17 ${pkgs.procps}/bin/pkill -2 -x mu
18 sleep 1
19 ${pkgs.mu}/bin/mu index
20 '';
21 cfg = config.custom.mail;
22in
23{
24 options.custom.mail.enable = lib.mkEnableOption "mail";
25
26 config = lib.mkIf cfg.enable {
27 home.packages = with pkgs; [
28 (pkgs.writeScriptBin "cam-ldap-addr" ''
29 ${pkgs.openldap}/bin/ldapsearch -xZ -H ldaps://ldap.lookup.cam.ac.uk -b "ou=people,o=University of Cambridge,dc=cam,dc=ac,dc=uk" displayName mail\
30 | ${pkgs.gawk}/bin/awk '/^dn:/{displayName=""; mail=""; next} /^displayName:/{displayName=$2; for(i=3;i<=NF;i++) displayName=displayName " " $i; next} /^mail:/{mail=$2; next} /^$/{if(displayName!="" && mail!="") print mail "\t" displayName}'\
31 > ${config.accounts.email.maildirBasePath}/addressbook/cam-ldap
32 '')
33 address-book
34 sync-mail
35 ];
36
37 programs = {
38 password-store.enable = true;
39 gpg.enable = true;
40 mbsync.enable = true;
41 mu.enable = true;
42 msmtp.enable = true;
43 aerc = {
44 enable = true;
45 extraConfig = {
46 general.unsafe-accounts-conf = true;
47 general.default-save-path = "~/downloads";
48 ui.mouse-enabled = true;
49 compose.address-book-cmd = "${address-book}/bin/address-book '%s'";
50 compose.file-picker-cmd = "${pkgs.ranger}/bin/ranger --choosefiles=%f";
51 compose.format-flowed = true;
52 ui.index-columns = "date<=,name<50,flags>=,subject<*";
53 ui.column-name = "{{index (.From | persons) 0}}";
54 "ui:folder=Sent".index-columns = "date<=,to<50,flags>=,subject<*";
55 "ui:folder=Sent".column-to = "{{index (.To | persons) 0}}";
56 openers."text/html" = "firefox --new-window";
57 hooks.mail-recieved = ''notify-send "[$AERC_ACCOUNT/$AERC_FOLDER] mail from $AERC_FROM_NAME" "$AERC_SUBJECT"'';
58 filters = {
59 "text/plain" = "wrap -w 90 | colorize";
60 "text/calendar" = "calendar";
61 "application/ics" = "calendar";
62 "message/delivery-status" = "colorize";
63 "message/rfc822" = "colorize";
64 "text/html" = "html | colorize";
65 };
66 };
67 extraBinds = import ./aerc-binds.nix { inherit pkgs; };
68 };
69 neomutt = {
70 enable = true;
71 extraConfig = ''
72 # Macro to switch accounts
73 macro index,pager <F1> '"<change-folder> ${config.accounts.email.maildirBasePath}/ryan@freumh.org/Inbox<enter>"'
74 macro index,pager <F2> '"<change-folder> ${config.accounts.email.maildirBasePath}/ryangibb321@gmail.com/Inbox<enter>"'
75 macro index,pager <F3> '"<change-folder> ${config.accounts.email.maildirBasePath}/ryan.gibb@cl.cam.ac.uk/Inbox<enter>"'
76
77 # mutt macros for mu
78 macro index <F8> "<shell-escape>mu find --clearlinks --format=links --linksdir=${config.accounts.email.maildirBasePath}/search " \
79 "mu find"
80 macro index <F9> "<change-folder-readonly>˜/Maildir/search" \
81 "mu find results"
82 '';
83 };
84 notmuch.enable = true;
85 };
86
87 services = {
88 imapnotify.enable = true;
89 gpg-agent.enable = true;
90 };
91
92 accounts.email = {
93 maildirBasePath = "mail";
94 accounts = {
95 "ryan@freumh.org" = rec {
96 primary = true;
97 realName = "Ryan Gibb";
98 userName = "ryan@freumh.org";
99 address = "ryan@freumh.org";
100 passwordCommand = "${pkgs.pass}/bin/pass show email/ryan@freumh.org";
101 imap.host = "mail.freumh.org";
102 smtp = {
103 host = "mail.freumh.org";
104 port = 465;
105 };
106 folders = {
107 drafts = "Drafts";
108 inbox = "Inbox";
109 sent = "Sent";
110 trash = "Trash";
111 };
112 imapnotify = {
113 enable = true;
114 boxes = [ "Inbox" ];
115 onNotify = "${sync-mail}/bin/mbsync ryan@freumh.org";
116 };
117 mbsync = {
118 enable = true;
119 create = "both";
120 expunge = "both";
121 remove = "both";
122 };
123 msmtp = {
124 enable = true;
125 };
126 aerc = {
127 enable = true;
128 extraAccounts = {
129 check-mail-cmd = "${sync-mail}/bin/mbsync ryan@freumh.org";
130 check-mail-timeout = "1m";
131 check-mail = "1h";
132 folders-sort = [
133 "Inbox"
134 "Sent"
135 "Drafts"
136 "Archive"
137 "Spam"
138 "Trash"
139 ];
140 folder-map = "${pkgs.writeText "folder-map" ''
141 Spam = Junk
142 Bin = Trash
143 ''}";
144 };
145 };
146 neomutt = {
147 enable = true;
148 extraConfig = ''
149 bind index g noop
150 macro index gi "<change-folder>=${folders.inbox}<enter>"
151 macro index gs "<change-folder>=${folders.sent}<enter>"
152 macro index gd "<change-folder>=${folders.drafts}<enter>"
153 macro index gt "<change-folder>=${folders.trash}<enter>"
154 '';
155 };
156 notmuch.enable = true;
157 };
158 "misc@freumh.org" = rec {
159 userName = "misc@freumh.org";
160 address = "misc@freumh.org";
161 realName = "Misc";
162 passwordCommand = "${pkgs.pass}/bin/pass show email/misc@freumh.org";
163 imap.host = "mail.freumh.org";
164 smtp = {
165 host = "mail.freumh.org";
166 port = 465;
167 };
168 folders = {
169 drafts = "Drafts";
170 inbox = "Inbox";
171 sent = "Sent";
172 trash = "Bin";
173 };
174 imapnotify = {
175 enable = true;
176 boxes = [ "Inbox" ];
177 onNotify = "${sync-mail}/bin/mbsync misc@freumh.org";
178 };
179 mbsync = {
180 enable = true;
181 create = "both";
182 expunge = "both";
183 remove = "both";
184 };
185 msmtp = {
186 enable = true;
187 };
188 neomutt = {
189 enable = true;
190 extraConfig = ''
191 bind index g noop
192 macro index gi "<change-folder>=${folders.inbox}<enter>"
193 macro index gs "<change-folder>=${folders.sent}<enter>"
194 macro index gd "<change-folder>=${folders.drafts}<enter>"
195 macro index gt "<change-folder>=${folders.trash}<enter>"
196 '';
197 };
198 notmuch.enable = true;
199 };
200 "ryan.gibb@cl.cam.ac.uk" = rec {
201 userName = "rtg24@fm.cl.cam.ac.uk";
202 address = "ryan.gibb@cl.cam.ac.uk";
203 realName = "Ryan Gibb";
204 passwordCommand = "${pkgs.pass}/bin/pass show email/ryan.gibb@cl.cam.ac.uk";
205 flavor = "fastmail.com";
206 folders = {
207 drafts = "Drafts";
208 inbox = "Inbox";
209 sent = "Sent";
210 trash = "Trash";
211 };
212 imapnotify = {
213 enable = true;
214 boxes = [ "Inbox" ];
215 onNotify = "${sync-mail}/bin/mbsync ryan.gibb@cl.cam.ac.uk";
216 };
217 mbsync = {
218 enable = true;
219 create = "both";
220 expunge = "both";
221 remove = "both";
222 };
223 msmtp = {
224 enable = true;
225 };
226 aerc = {
227 enable = true;
228 extraAccounts = {
229 check-mail-cmd = "${sync-mail}/bin/mbsync ryan.gibb@cl.cam.ac.uk";
230 check-mail-timeout = "1m";
231 check-mail = "1h";
232 aliases = "rtg24@cam.ac.uk";
233 folders-sort = [
234 "Inbox"
235 "Sidebox"
236 "Sent"
237 "Drafts"
238 "Archive"
239 "Spam"
240 "Trash"
241 ];
242 folder-map = "${pkgs.writeText "folder-map" ''
243 Bin = Trash
244 ''}";
245 };
246 };
247 neomutt = {
248 enable = true;
249 extraConfig = ''
250 bind index g noop
251 macro index gi "<change-folder>=${folders.inbox}<enter>"
252 macro index gs "<change-folder>=${folders.sent}<enter>"
253 macro index gd "<change-folder>=${folders.drafts}<enter>"
254 macro index gt "<change-folder>=${folders.trash}<enter>"
255 '';
256 };
257 notmuch.enable = true;
258 };
259 "ryangibb321@gmail.com" = rec {
260 userName = "ryangibb321@gmail.com";
261 address = "ryangibb321@gmail.com";
262 realName = "Ryan Gibb";
263 passwordCommand = "${pkgs.pass}/bin/pass show email/ryangibb321@gmail.com";
264 flavor = "gmail.com";
265 folders = {
266 drafts = "Drafts";
267 inbox = "Inbox";
268 sent = "Sent Mail";
269 trash = "Bin";
270 };
271 imapnotify = {
272 enable = true;
273 boxes = [ "Inbox" ];
274 onNotify = "${sync-mail}/bin/mbsync ryangibb321@gmail.com";
275 };
276 mbsync = {
277 enable = true;
278 create = "both";
279 expunge = "both";
280 remove = "both";
281 };
282 msmtp = {
283 enable = true;
284 };
285 aerc = {
286 enable = true;
287 extraAccounts = {
288 check-mail-cmd = "${sync-mail}/bin/mbsync ryangibb321@gmail.com";
289 check-mail-timeout = "1m";
290 check-mail = "1h";
291 folders-sort = [
292 "Inbox"
293 "Sidebox"
294 "[Gmail]/Sent Mail"
295 "[Gmail]/Drafts"
296 "[Gmail]/All Mail"
297 "[Gmail]/Spam"
298 "[Gmail]/Trash"
299 ];
300 copy-to = "'[Gmail]/Sent Mail'";
301 archive = "'[Gmail]/All Mail'";
302 postpone = "[Gmail]/Drafts";
303 };
304 };
305 neomutt = {
306 enable = true;
307 extraConfig = ''
308 bind index g noop
309 macro index gi "<change-folder>=${folders.inbox}<enter>"
310 macro index gs "<change-folder>=${folders.sent}<enter>"
311 macro index gd "<change-folder>=${folders.drafts}<enter>"
312 macro index gt "<change-folder>=${folders.trash}<enter>"
313 '';
314 };
315 notmuch.enable = true;
316 };
317 search = {
318 maildir.path = "search";
319 realName = "Search Index";
320 address = "search@local";
321 aerc.enable = true;
322 aerc.extraAccounts = {
323 source = "maildir://~/mail/search";
324 };
325 aerc.extraConfig = {
326 ui = {
327 index-columns = "flags>4,date<*,to<30,name<30,subject<*";
328 column-to = "{{(index .To 0).Address}}";
329 };
330 };
331 };
332 };
333 };
334 };
335}