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