#!/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 alias data from vmail database." echo "" echo "usage: $thisfilename [-a |-e |-d ] [-c] [-t] [-h]" echo "" echo " -h Print this help." echo " -a Return info for specific alias." echo " -e Return all aliases for specified email address." echo " -d Return all aliases for specified domain." 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 aliases for all email acccounts for all domains will be returned." echo " Enter email address to get all aliases that route to that email address." echo " Enter alias (in full email address format) with the -a option to get address that alias delivers to." echo " Enter domain name to get all aliases 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 alias, mbox, domain FROM vm_aliases" if [[ -n $tab ]]; then dbcmdopts="-s -N $dbcmdopts" fi if [[ -n $alias ]]; then if [[ -n $domain ]] ; then dbquery="$dbquery WHERE alias='$alias' AND domain='$domain'" else echo "ERROR: alias should be in full email address format." exit 1 fi elif [[ -n $email ]]; then dbquery="$dbquery WHERE mbox='$mbox' AND domain='$domain'" elif [[ -n $domain ]]; then dbquery="$dbquery WHERE domain='$domain'" else echo "You must specify either or or ." exit 1 fi # set order by dbquery="$dbquery ORDER BY domain, mbox, alias;"; # execute mysql query eval $dbcmd $dbcmdopts "\"$dbquery\"" $cvs