1
0
mirror of https://github.com/tomav/docker-mailserver.git synced 2024-06-28 20:21:14 +02:00
docker-mailserver/target/bin/delalias
2022-03-21 15:01:07 +01:00

24 lines
672 B
Bash
Executable File

#! /bin/bash
# shellcheck source=../scripts/helpers/index.sh
source /usr/local/bin/helpers/index.sh
DATABASE=${DATABASE:-/tmp/docker-mailserver/postfix-virtual.cf}
EMAIL="${1}"
RECIPIENT="${2}"
function __usage { echo "Usage: delalias <alias@domain> <recipient@other>" ; }
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
[[ -z ${EMAIL} ]] && { __usage ; _exit_with_error "Error: No alias specified" ; }
[[ -z ${RECIPIENT} ]] && { __usage ; _exit_with_error "Error: No recipient specified" ; }
[[ -s ${DATABASE} ]] || exit 0
sed -i \
-e "/^${EMAIL} *${RECIPIENT}$/d" \
-e "/^${EMAIL}/s/,${RECIPIENT}//g" \
-e "/^${EMAIL}/s/${RECIPIENT},//g" \
"${DATABASE}"