2022-05-23 15:49:49 -07:00
#!/bin/bash
#
# vmail-stack
# https://git.stack-source.com/msb/vmail-stack
2022-08-22 13:34:20 -07:00
# Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
2022-05-23 15:49:49 -07:00
# load include file
source $( dirname $0 ) /vmail.sh
help( )
{
thisfilename = $( basename -- " $0 " )
echo " $thisfilename "
echo "Get email autresonder data from vmail database."
echo ""
echo " usage: $thisfilename -e email|-d domain [-c] [-t] [-h] "
echo ""
echo " -h Print this help."
echo " -e <email> Email address to get autresonder for."
echo " -d <domain> Domain to get all autoresponders for."
echo " -c Output in cvs format."
echo " -t Use tabs instead of tables for output, do not display column headers."
echo ""
echo " Search term is optional. If nothing specified all forwards for all email acccounts for all domains will be returned."
echo " Enter email address to get forward info for that email address."
echo " Enter forwarding address (in full email address format) with the -f option to get address(es) that forward to specified address."
echo " Enter domain name to get all forwards for all email addresses under that domain."
exit
}
vmail:getoptions " $@ "
# check for domain (which will aslo be set if email is specified)
if [ [ -z $domain ] ] ; then
echo "Domian Name or Email is required."
exit 1
fi
# set initial db query data
dbcmd = " mysql --defaults-extra-file= $MYSQL_CONNECTION_INFO_FILE "
dbcmdopts = "-e"
if [ [ -n $tab ] ] ; then
dbcmdopts = " -s -N $dbcmdopts "
fi
2022-05-24 15:26:09 -07:00
dbquery = " SELECT vm_mboxes.mbox, vm_domains.domain, QUOTE(vm_autoresponders.subject) AS subject, QUOTE(REPLACE(REPLACE(vm_autoresponders.body,'\r\n','\n'),'\n','\\n')) AS body, vm_autoresponders.mode, vm_autoresponders.status FROM vm_autoresponders, vm_mboxes, vm_domains WHERE vm_autoresponders.mbox_id = vm_mboxes.id AND vm_mboxes.domain_id = vm_domains.id AND vm_domains.domain=' $domain ' "
2022-05-23 15:49:49 -07:00
# build query
if [ [ -n $email ] ] ; then
# search for specific autoresponder
dbquery = " $dbquery AND vm_mboxes.mbox=' $mbox ' ORDER BY vm_mboxes.mbox "
fi
# execute mysql query
eval $dbcmd $dbcmdopts " \" $dbquery \" " $cvs