#!/bin/bash # # vmail-stack # https://git.stack-source.com/msb/vmail-stack # Copyright (c) 2022 Matthew Saunders Brown # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # 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 address to get autresonder for." echo " -d 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 autoresponder info for that email address." echo " Enter domain name to get all autoresponders 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" if [[ -n $tab ]]; then dbcmdopts="-s -N $dbcmdopts" fi # build query dbquery="SELECT mbox, domain, QUOTE(subject) AS subject, QUOTE(REPLACE(REPLACE(body,'\r\n','\n'),'\n','\\n')) AS body, mode, status FROM vm_autoresponders" # set search options if [[ -n $email ]]; then # search for specific autoresponder dbquery="$dbquery WHERE mbox='$mbox' AND domain='$domain'" elif [[ -n $domain ]]; then # get all autoresponders for given domain dbquery="$dbquery WHERE domain='$domain'" fi # sort results dbquery="$dbquery ORDER BY domain, mbox" # execute mysql query eval $dbcmd $dbcmdopts "\"$dbquery\"" $cvs