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."
|
2023-11-27 09:13:59 -08:00
|
|
|
echo " -c Output in csv format."
|
2022-05-23 15:49:49 -07:00
|
|
|
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."
|
2022-11-29 16:33:15 -08:00
|
|
|
echo " Enter email address to get autoresponder info for that email address."
|
|
|
|
echo " Enter domain name to get all autoresponders for all email addresses under that domain."
|
2023-11-27 14:48:55 -08:00
|
|
|
echo " Body is returned in base64 encoding, for handling special characters and html entities."
|
2022-05-23 15:49:49 -07:00
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
vmail:getoptions "$@"
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
# build query
|
2023-11-27 14:48:55 -08:00
|
|
|
dbquery="SELECT mbox, domain, QUOTE(subject) AS subject, TO_BASE64(body) AS body, mode, status FROM vm_autoresponders"
|
2022-11-29 16:33:15 -08:00
|
|
|
|
|
|
|
# set search options
|
2022-05-23 15:49:49 -07:00
|
|
|
if [[ -n $email ]]; then
|
|
|
|
# search for specific autoresponder
|
2022-11-29 16:33:15 -08:00
|
|
|
dbquery="$dbquery WHERE mbox='$mbox' AND domain='$domain'"
|
|
|
|
elif [[ -n $domain ]]; then
|
|
|
|
# get all autoresponders for given domain
|
|
|
|
dbquery="$dbquery WHERE domain='$domain'"
|
2022-05-23 15:49:49 -07:00
|
|
|
fi
|
|
|
|
|
2022-11-29 16:33:15 -08:00
|
|
|
# sort results
|
|
|
|
dbquery="$dbquery ORDER BY domain, mbox"
|
2022-05-23 15:49:49 -07:00
|
|
|
# execute mysql query
|
2023-11-27 09:13:59 -08:00
|
|
|
eval $dbcmd $dbcmdopts "\"$dbquery\"" $csv
|