2017-04-17 16:27:28 +00:00
|
|
|
#! /bin/bash
|
|
|
|
|
2021-01-16 09:16:05 +00:00
|
|
|
# shellcheck source=../scripts/helper-functions.sh
|
|
|
|
. /usr/local/bin/helper-functions.sh
|
2017-04-17 16:27:28 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
DATABASE=${DATABASE:-/tmp/docker-mailserver/postfix-virtual.cf}
|
2017-04-17 16:27:28 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
EMAIL="${1}"
|
|
|
|
RECIPIENT="${2}"
|
2017-04-17 16:27:28 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
function usage { echo "Usage: delalias <alias@domain> <recipient@other>" ; }
|
2020-07-19 19:23:59 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
[[ -z ${EMAIL} ]] && { usage ; errex "Error: No alias specified" ; }
|
|
|
|
[[ -z ${RECIPIENT} ]] && { usage ; errex "Error: No recipient specified" ; }
|
|
|
|
[[ -s ${DATABASE} ]] || exit 0
|
2017-04-17 16:27:28 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
sed -i -e "/^${EMAIL} *${RECIPIENT}$/d" \
|
|
|
|
-e "/^${EMAIL}/s/,${RECIPIENT}//g" \
|
|
|
|
-e "/^${EMAIL}/s/${RECIPIENT},//g" "${DATABASE}"
|