diff --git a/target/bin/delalias b/target/bin/delalias index c89c69c8..c97a1c39 100755 --- a/target/bin/delalias +++ b/target/bin/delalias @@ -21,10 +21,7 @@ escape() { [ -z "$EMAIL" ] || [ -z "$RECIPIENT" ] && { usage; errex "No email specifed"; } [ -s "$DATABASE" ] || exit 0 -CNT=$(grep "^$EMAIL" $DATABASE | wc -w | awk '{print $1}') - -if [[ $CNT -eq 2 ]]; then - sed -i "/^$EMAIL/d" $DATABASE - else - sed -i "/^$EMAIL/s/,$RECIPIENT//g" $DATABASE -fi +#CNT=$(grep "^$EMAIL" $DATABASE | wc -w | awk '{print $1}') +sed -i -e "/^$EMAIL *$RECIPIENT$/d" \ + -e "/^$EMAIL/s/,$RECIPIENT//g" \ + -e "/^$EMAIL/s/$RECIPIENT,//g" $DATABASE diff --git a/test/tests.bats b/test/tests.bats index a9e540b3..c6ee913a 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -1243,12 +1243,27 @@ load 'test_helper/bats-assert/load' run /bin/sh -c 'cat ./config/postfix-virtual.cf | grep "test1@example.org test1@forward.com,test2@forward.com" | wc -l | grep 1' assert_success } + @test "checking setup.sh: setup.sh alias del" { - echo 'test1@example.org test1@forward.com, test2@forward.com,' > ./config/postfix-virtual.cf + echo -e 'test1@example.org test1@forward.com,test2@forward.com\ntest2@example.org test1@forward.com' > ./config/postfix-virtual.cf + ./setup.sh -c mail alias del test1@example.org test1@forward.com + run grep "test1@forward.com" ./config/postfix-virtual.cf + assert_output --regexp "^test2@example.org +test1@forward.com$" + + run grep "test2@forward.com" ./config/postfix-virtual.cf + assert_output --regexp "^test1@example.org +test2@forward.com$" + ./setup.sh -c mail alias del test1@example.org test2@forward.com - run cat ./config/postfix-virtual.cf | wc -l | grep 0 + run grep "test1@example.org" ./config/postfix-virtual.cf + assert_failure + + run grep "test2@example.org" ./config/postfix-virtual.cf assert_success + + ./setup.sh -c mail alias del test2@example.org test1@forward.com + run grep "test2@example.org" ./config/postfix-virtual.cf + assert_failure } # config