57 lines
2.2 KiB
Bash
Executable File
57 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# vmail-stack
|
|
# https://git.stack-source.com/msb/vmail-stack
|
|
# MIT License Copyright (c) 2021 Matthew Saunders Brown
|
|
|
|
# load include file
|
|
source $(dirname $0)/vmail.sh
|
|
|
|
help()
|
|
{
|
|
thisfilename=$(basename -- "$0")
|
|
echo "$thisfilename"
|
|
echo "Get email forwards data from vmail database."
|
|
echo ""
|
|
echo "usage: $thisfilename [-e email|-f forward|-f domain] [OPTIONS]"
|
|
echo ""
|
|
echo " -h Print this help."
|
|
echo " -e <email> Email address to remove forwarding from."
|
|
echo " -f <forward> Return info for specific forward."
|
|
echo " -d <domain> Domain to be modified."
|
|
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 "$@"
|
|
|
|
# set initial db query data
|
|
dbcmd="mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE"
|
|
dbcmdopts="-e"
|
|
dbquery="SELECT vm_mboxes.mbox, vm_domains.domain, vm_forwards.forward_to, vm_forwards.save_local FROM vm_forwards, vm_mboxes, vm_domains WHERE vm_forwards.mbox_id = vm_mboxes.id AND vm_mboxes.domain_id = vm_domains.id"
|
|
# AND vm_forwards.forward_to='$mbox@$domain'"
|
|
# build query
|
|
if [[ -n $forward ]]; then
|
|
# search for specific forward to address
|
|
dbquery="$dbquery AND vm_forwards.forward_to='$mbox@$domain'"
|
|
elif [[ -n $domain ]]; then
|
|
# add specific domain
|
|
dbquery="$dbquery vm_domains.domain='$domain'"
|
|
if [[ -n "$mbox" ]]; then
|
|
# search for forward for specific email address
|
|
dbquery="$dbquery AND vm_mboxes.mbox='$mbox'"
|
|
fi
|
|
fi
|
|
|
|
# set order by
|
|
dbquery="$dbquery ORDER BY vm_domains.domain, vm_mboxes.mbox, vm_forwards.forward_to;";
|
|
|
|
# execute mysql query
|
|
eval $dbcmd $dbcmdopts "\"$dbquery\"" $cvs
|