Commit a0653764 authored by Vitaly Lipatov's avatar Vitaly Lipatov

archive_spam.sh: improve to support users spambox too

parent 75f5f185
...@@ -15,13 +15,17 @@ archive_spamdir() ...@@ -15,13 +15,17 @@ archive_spamdir()
# skip empty spam dir # skip empty spam dir
[ "$SIZE" = 4 ] && return [ "$SIZE" = 4 ] && return
mkdir -p "$BACKUPDIR" mkdir -p "$BACKUPDIR"
# TODO: use eterremove
# Нужно удалять только старый spam!
#etertimemachine update $SPAMDIR $BACKUPDIR #etertimemachine update $SPAMDIR $BACKUPDIR
#etertimemachine rotate $BACKUPDIR #etertimemachine rotate $BACKUPDIR
rm -rf $SPAMDIR.copy rm -rf $SPAMDIR.copy
cp -al $SPAMDIR $SPAMDIR.copy cp -al $SPAMDIR $SPAMDIR.copy || exit
find $SPAMDIR -maxdepth 1 -name "*\." -delete
# Удаляем только старый спам (старее 3 месяцев)
#find $SPAMDIR -maxdepth 1 -name "*\." -delete
eterremove remove --depth 1 --exclude "cyrus.*" --days 30 --notest files $SPAMDIR
rm -f $SPAMDIR/cyrus.* rm -f $SPAMDIR/cyrus.*
/usr/lib/cyrus/reconstruct "$SPAMBOX" /usr/lib/cyrus/reconstruct "$SPAMBOX"
erc create "$BACKUPDIR/$(date -R).tar.gz" $SPAMDIR.copy erc create "$BACKUPDIR/$(date -R).tar.gz" $SPAMDIR.copy
...@@ -47,27 +51,37 @@ archive_spam() ...@@ -47,27 +51,37 @@ archive_spam()
remove_from_domain() remove_from_domain()
{ {
local DOMAIN="$1" local DOMAIN="$1"
local USER="$2"
local i local i
echo echo
echo $DOMAIN echo $DOMAIN
for i in $IMAPDIR/$(fletter $DOMAIN)/$DOMAIN/?/user/* ; do for i in $IMAPDIR/$(fletter $DOMAIN)/$DOMAIN/?/user/$USER ; do
USER=$(basename $i) USER=$(basename $i)
BOX=/spam BOX=/spam
test -f "$i$BOX/cyrus.index" || continue test -f "$i$BOX/cyrus.index" || continue
archive_spam $DOMAIN $USER $BOX archive_spam $DOMAIN $USER $BOX
# recal quota for the user
[ "$USER" != "*" ] && /usr/lib/cyrus/quota -f -d $DOMAIN user/$USER
done done
# recalc quotas # recalc quotas for all users
/usr/lib/cyrus/quota -f -d $DOMAIN || echo "You need fix this error!" if [ "$USER" = "*" ] ; then
/usr/lib/cyrus/quota -f -d $DOMAIN || echo "You need fix this error!"
fi
} }
# Uncomment after improve old spam removing # test
#for d in $IMAPDIR/?/* ; do #remove_from_domain office.etersoft.ru "arc"
# remove_from_domain $(basename $d) #exit
#done
for d in $IMAPDIR/?/* ; do
remove_from_domain $(basename $d) "*"
done
#exit
# main spam dir # main spam dir
DOMAIN=office.etersoft.ru DOMAIN=office.etersoft.ru
#user/spam@$DOMAIN #user/spam@$DOMAIN
archive_spam $DOMAIN spam "" USER=spam
# recalc quotas archive_spam $DOMAIN $USER ""
/usr/lib/cyrus/quota -f -d $DOMAIN user/spam || echo "You need fix this error!" # recalc quota for the spam user
/usr/lib/cyrus/quota -f -d $DOMAIN user/$USER || echo "You need fix this error!"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment