2017-04-17 16:27:28 +00:00
|
|
|
#! /bin/bash
|
|
|
|
|
2022-02-21 10:56:57 +00:00
|
|
|
# shellcheck source=../scripts/helpers/index.sh
|
|
|
|
source /usr/local/bin/helpers/index.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 ; }
|
|
|
|
|
2022-03-26 08:30:09 +00:00
|
|
|
[[ -z ${EMAIL} ]] && { __usage ; _exit_with_error 'No alias specified' ; }
|
|
|
|
[[ -z ${RECIPIENT} ]] && { __usage ; _exit_with_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}"
|