Browse Source

added auto-archive script for mailsrv

feature/startup-from-labels
Mario Alegre 5 years ago
parent
commit
ec1b82f5d6
  1. 6
      src/mailsrv/Containerfile
  2. 39
      src/mailsrv/assets/bin/maint
  3. 4
      src/mailsrv/assets/crontab

6
src/mailsrv/Containerfile

@ -35,6 +35,12 @@ RUN addgroup --gid ${FILESUID:?} vmail && \
# copy our custom scripts
COPY assets/bin /usr/local/bin
# copy root's crontab
COPY assets/crontab /root/
# load root's crontab
RUN crontab /root/crontab
###
### mkvirtual
###

39
src/mailsrv/assets/bin/maint

@ -0,0 +1,39 @@
#!/bin/bash
cd /vol/mail
for user in *; do
# 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
# get current year
currentyear=$(date +%Y)
# assume no messages in INBOX are older than this year
#year=2000
year=$(($currentyear-1))
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 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 messages from Trash that have been there for more than 2 weeks
doveadm expunge -u $user SAVEDBEFORE 2w MAILBOX Trash
# step year variable
year=$(($year+1))
done
done

4
src/mailsrv/assets/crontab

@ -0,0 +1,4 @@
# m h dom mon dow command
# Run daily mail maintenance
11 1 * * * /usr/local/bin/maint
Loading…
Cancel
Save