add pull support, untested
[distro-setup] / offlineimap-sync
1 #!/bin/bash
2
3 set -eE -o pipefail
4 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
5
6 # mail-route can get messed up a bit randomly, I don't know why.
7 #/b/ds/mail-route up | /b/log-quiet/log-once -1 mail-route
8
9 offlineimap -u quiet
10 shopt -s nullglob
11
12 omv() { # offlineimap mv. move mail files within $src_base/$1 to /m/md/$2
13 src="$1"
14 dst="$2"
15 found_files=false
16 for x in new cur; do
17 files=($src_base/"$src"/$x/*)
18 if [[ $files ]]; then
19 found_files=true
20 mv "${files[@]}" /m/md/"$dst"/$x
21 fi
22 done
23 }
24
25 src_base=/m/offlineimap
26 omv "Sent Items" "Sent"
27 omv INBOX offlineimaptmp
28 src_base=/m/md
29 if $found_files; then
30 sieve-filter -eW ~/sieve/main.sieve offlineimaptmp &>/dev/null
31 # the default folder is INBOX for anything leftover
32 omv offlineimaptmp INBOX
33 # remove messages from remote host
34 offlineimap -u quiet
35 # this makes us sit and wait when we want to use mu and this is running in a cronjob.
36 # todo: emacs updates the index much faster. what command is it running? I'd like
37 # to just run that
38 # looks like it might be mu index --lazy-check, but that still takes like 10 seconds,
39 # figure out if that is the same speed, or if we can make it faster.
40 #mu index &>/dev/null ||:
41 fi
42
43
44 # qemu-devel is our biggest list by far, so occasionally
45 # I want to hop into conversations about our mailing
46 # systems there, but I don't need many old messages.
47 find /nocow/user/fsfmd/l/qemu-devel/new -type f -mtime +14 -execdir rm -- '{}' +
48
49 find /nocow/user/fsfmd/{sec,Spam,Drafts,{rtcc,sysadmin,l/outreachy-mentors}/new} -type f -mtime +100 -execdir rm -- '{}' +
50
51 find /nocow/user/fsfmd/log -type f -mtime +300 -execdir rm -- '{}' +
52
53
54 # delete based on http://deflexion.com/2006/05/imap-way-of-deleting-message
55 sieve-filter -eW -o mail_location=maildir:/nocow/user/fsfmd:LAYOUT=fs:INBOX=/nocow/user/fsfmd/INBOX ~/sieve/fsf.sieve INBOX delete &>>/tmp/fsfsieve.log
56
57 # to test new rules, update fsf-test.sieve, run these commands, then copy new fsf-test.sieve to fsf.sieve
58 # sieve-filter -o mail_location=maildir:/nocow/user/fsfmd:LAYOUT=fs:INBOX=/nocow/user/fsfmd/INBOX ~/sieve/fsf-test.sieve INBOX &>/tmp/testfsfsieve.log
59 # sed -rn '/^Performed actions:/{n;n;p}' /tmp/testfsfsieve.log | sort -u