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
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
function __usage { echo "Usage: delalias <alias@domain> <recipient@other>" ; }
|
2020-07-19 19:23:59 +00:00
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
|
|
|
|
|
|
|
|
[[ -z ${EMAIL} ]] && { __usage ; errex "Error: No alias specified" ; }
|
|
|
|
[[ -z ${RECIPIENT} ]] && { __usage ; errex "Error: No recipient specified" ; }
|
2020-10-21 16:16:32 +00:00
|
|
|
[[ -s ${DATABASE} ]] || exit 0
|
2017-04-17 16:27:28 +00:00
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
sed -i \
|
|
|
|
-e "/^${EMAIL} *${RECIPIENT}$/d" \
|
2020-10-21 16:16:32 +00:00
|
|
|
-e "/^${EMAIL}/s/,${RECIPIENT}//g" \
|
2021-02-23 19:03:01 +00:00
|
|
|
-e "/^${EMAIL}/s/${RECIPIENT},//g" \
|
|
|
|
"${DATABASE}"
|