
2 changed files with 2 additions and 48 deletions
@ -1,46 +0,0 @@ |
|||||
#!/bin/bash |
|
||||
|
|
||||
if [[ -z $1 ]]; then |
|
||||
echo "Usage: $(basename $0) user" |
|
||||
exit 1 |
|
||||
else |
|
||||
user=$1 |
|
||||
fi |
|
||||
|
|
||||
cd /vol/mail |
|
||||
|
|
||||
# create an archive mailbox (and throw away error because |
|
||||
# we don't mind if it already exists) |
|
||||
doveadm mailbox create -u "$user" -s Archive 2> /dev/null |
|
||||
|
|
||||
# assume no messages in INBOX are older than this year |
|
||||
year=2010 |
|
||||
currentyear=$(date +%Y) |
|
||||
|
|
||||
while [[ $year -le $currentyear ]]; do |
|
||||
# create an Archive/$year mailbox |
|
||||
doveadm mailbox create -u $user -s Archive.$year 2> /dev/null |
|
||||
|
|
||||
# Get list of all subdirs of INBOX |
|
||||
mailboxes=$(doveadm mailbox list -u $user | grep -E '^INBOX\..*$' \ |
|
||||
| perl -pe 'chomp if eof' | perl -pe 's/^/MAILBOX /' \ |
|
||||
| perl -pe 's/\n/ OR /') |
|
||||
# add Sent and INBOX to our mailboxes list |
|
||||
mailboxes="MAILBOX Sent OR MAILBOX INBOX ${mailboxes:+OR} $mailboxes" |
|
||||
# move to the Archive/$year mailbox messages that: |
|
||||
# have been flagged as read, |
|
||||
# were received on or before $year, |
|
||||
# are older than 90 days, |
|
||||
# and are in our aforementioned mailboxes |
|
||||
doveadm move -u $user Archive.$year SEEN BEFORE 1-Jan-$(($year+1)) \ |
|
||||
BEFORE 90d \( $mailboxes \) |
|
||||
|
|
||||
# delete Archive/$year mailbox if it is empty |
|
||||
doveadm mailbox delete -u $user -e Archive.$year 2> /dev/null |
|
||||
|
|
||||
# increment year variable |
|
||||
year=$(($year+1)) |
|
||||
done |
|
||||
|
|
||||
# delete messages from Trash that have been there for more than 2 weeks |
|
||||
doveadm expunge -u $user SAVEDBEFORE 2w MAILBOX Trash |
|
@ -1,4 +1,4 @@ |
|||||
# m h dom mon dow command |
# m h dom mon dow command |
||||
|
|
||||
# Run daily mail maintenance |
# Do daily mail maintenance |
||||
11 1 * * * /usr/local/bin/maint |
11 1 * * * /bin/bash -c 'for f in /vol/data/cron.d/*; do $f; done' |
||||
|
Loading…
Reference in new issue