Merge branch 'master' of https://git.jamestechnotes.com/r/james/home/home
[james-home.git] / bin / trimmail
blob964779f0c72b427f18c4f85c2cdd7cd1f6e567ac
1 #!/bin/bash -e
3 cd ~/mail/archive
5 date=$(date +%Y-%m)
7 for folder in $(find ~/Maildir ~/Maildir/.* -maxdepth 0 -type d -not -name .. -not -name .Drafts -not -name '.Gmail*' -not -name '.Technotes.Drafts') ~/Maildir/.Gmail.[Gmail].All_Mail; do
8 dest=$(basename $folder | sed 's/^\.//')
9 # Let's get rid of trash
10 if [[ $dest =~ rash$ ]]; then
11 archivemail -d30 --delete $folder
13 if [ "$dest" = "" ] || [ "$dest" = "Maildir" ]; then
14 dest=inbox
16 install -d $dest
17 #let's archive read mail over 7 days
18 archivemail -u -d8 -o $dest --archive-name=$date $folder
19 done
21 # let's delete mailing list mail that is older than 60 days. If I haven't read
22 # by then, I probably won't :)
23 for folder in $(find ~/Maildir ~/Maildir/.* -maxdepth 0 -type d -name '.debian.*' )
25 archivemail -d60 --delete $folder
26 done
28 for dir in $(find -maxdepth 1 -mindepth 1 -type d -not -name .git); do
29 # Compress mail not compressed by archivemail
30 find $dir -maxdepth 1 -type f -regex '.*/[0-9]*-[0-9]*$' -exec gzip -9 {} \;
32 # Either check in old archives, or delete them after a month.
33 if [ -n "$(git log -n 1 -- "$dir")" ]; then
34 git add -f $(find $dir -maxdepth 1 -type f -regex '.*/[0-9]*-[0-9]*.gz') 2>/dev/null || true
35 else
36 find $dir -maxdepth 1 -type f -mtime +31 -exec rm -f {} \; >&2
38 done
40 if ! git commit -q -a -m"autocommit"; then
41 echo "git commit failed" >&2
42 exit 1
43 elif ! git push 2>/dev/null ; then
44 echo "git push failed" >&2
45 exit 1