blob: ba206343fb7941e4de0759e7a782a2500f2cd614 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
{ pkgs, config, lib, ... }:
{
accounts.email = {
maildirBasePath = "${config.home.homeDirectory}/.mail";
accounts = {
Fastmail = rec {
primary = true;
address = "franck@fcuny.net";
userName = address;
realName = "Franck Cuny";
aliases = [ "franck.cuny@gmail.com" ];
passwordCommand = "pass email/imap.fastmail.com";
imap.host = "imap.fastmail.com";
mbsync = {
enable = true;
create = "maildir";
expunge = "both";
};
notmuch.enable = true;
};
};
};
programs.mbsync.enable = true;
programs.notmuch = {
enable = true;
maildir.synchronizeFlags = true;
new.tags = [ "unread" "inbox" ];
new.ignore = [ "Trash" ];
search.excludeTags = [ "spam" "deleted" ];
};
xdg.configFile."notmuch/imap-sync.sh" = {
executable = true;
text = ''
#!${pkgs.stdenv.shell}
MAILDIR=$HOME/.mail/
# Strip UIDs from filenames when moving mails so that mbsync doesn't get confused.
mv_renamed() {
while IFS= read -r name; do
flags=$(echo "$name" | cut -d':' -f2)
new_name="$(basename $name | awk -F ',' '{print $1}')"
[ -f "$name" ] && mv -nv "$name" "$1/$new_name"
done
}
${pkgs.notmuch}/bin/notmuch search --output=files -- not tag:inbox and folder:Fastmail/Inbox | mv_renamed $MAILDIR/Fastmail/Archive/cur
'';
};
systemd.user.services.mbsync = {
Unit = {
Description = "mbsync synchronization";
};
Service = {
Type = "oneshot";
Environment = [
"PASSWORD_STORE_DIR=${config.programs.password-store.settings.PASSWORD_STORE_DIR}"
"NOTMUCH_CONFIG=${config.xdg.configHome}/notmuch/notmuchrc"
];
ExecStartPre = "${config.xdg.configHome}/notmuch/imap-sync.sh";
ExecStart = "${pkgs.isync}/bin/mbsync -a";
ExecStartPost = "${pkgs.notmuch}/bin/notmuch new --quiet";
};
};
systemd.user.timers.mbsync = {
Unit = { Description = "mbsync synchronization"; };
Timer = {
OnBootSec = "30";
OnUnitActiveSec = "5m";
};
Install = { WantedBy = [ "timers.target" ]; };
};
}
|