#!/bin/sh
# Under GPL v. 2.0
# Read it on http://www.gnu.org/licenses/gpl2.txt
# A little script to extract into file
# information about vpopmail domains, the emails containing every domain and the email count for every domain.
# Created by hip0

vpopmail_domains_dir='/var/vpopmail/domains';
arg1="$1";
PWD=`pwd`;

if [ ${arg1} ]; then

for line in $(ls -1 ${vpopmail_domains_dir}); do
if [ -d ${vpopmail_domains_dir}/$line ]; then
echo -e "Domain ${line}\n" >> ${PWD}/${arg1};
echo "Available Mails:" >> ${PWD}/${arg1};
for i in $(ls ${vpopmail_domains_dir}/${line}/|grep -v vpasswd|sed -e "s#/# #g"); do
echo "$i@$line" >> ${PWD}/${arg1};
done 
echo >> ${PWD}/${arg1};
echo "Mail count: $(ls ${vpopmail_domains_dir}/$line/|grep -v vpasswd|sed -e "s#/# #g"|wc -l)" >> ${PWD}/${arg1};
echo >> ${PWD}/${arg1};
fi
done 
else
echo "Enter the name of a file to output to";
exit 1;
fi

