#!/bin/bash
source /root/etc/config

# find mailboxes in /var/mail with mails
cd /var/mail
aFiles=`find -type f -and -not -size 0 | sed 's|\./||g'`

# backup these mailboxes
mkdir -p /home/trash/other
chmod 700 /home/trash/other
tar zcvf /home/trash/other/var-mail-`date +"%Y%m%d-%H%M"`.tar.gz $aFiles

# notify hostmasters
echo "$aFiles" | xargs -r ls -la | mail -e -s "$THIS_HIVE: found mails in /var/mail => remailing (chk-var-mails)" hostmaster@hostsharing.net

# resend these mails
for m in $aFiles; do 
	mv -f $m /root/tmp/$m
	formail -I Delivered-To: -s sendmail -i $m </root/tmp/$m
done

