#!/bin/sh
# In memoriam of Nikolay Dobromirov Paskalev, a.k.a. skype name: lunarstill, known in the net
# under the nickname Sha`Nar.
# I hope I'll see you in heaven dear friend! 
# You'll be in my heart and mind.
#
# Licensed under GPL2 license

domain='cadiainsurance.com';
vpopmail_dir='/var/vpopmail/domains';
log_file=/root/$domain
cur_date=`date +%d_%m_%Y|sed -e 's/^ *//'`;


cd $vpopmail_dir/$domain;
for i in $(ls -1 $vpopmail_dir/$domain); do 
email=$(echo $(echo $(echo $i|grep -v vpasswd |sed -e "s#/# #g"))); 
echo $email;
if [ "$email" = "0" ] || [ "$email" == "1" ] || [ "$email" == "2" ] || [ "$email" == "3" ]; then
unset email
fi

if [ "$email" ]; then
echo $email@$domain >>"$log_file"-"$cur_date";
fi

done

if [ -f "$log_file"-"$cur_date" ]; then
echo "Mail list creted in $log_file-$cur_date";
else
echo "Some kind of error occured";
fi
