Update relayhost_map with virtual accounts too

Previously, only postfix-relaymap.cf and postfix-accounts.cf would be
used to populate the relayhost_map file.

Now, also use postfix-virtual.cf when present. To me, there is nothing
absurd about sending mail "From:" a virtual account (or more
specifically its domain) so it makes sense that when a $RELAY_HOST is
defined it should be used for virtual accounts as well.
This commit is contained in:
mwnx 2020-08-24 22:53:54 +02:00
parent 1286a1266b
commit 42352a3259
4 changed files with 25 additions and 3 deletions

View File

@ -81,6 +81,7 @@ if ! cmp --silent -- "$CHKSUM_FILE" "$CHKSUM_FILE.new"; then
#regen postfix accounts.
echo -n > /etc/postfix/vmailbox
echo -n > /etc/dovecot/userdb
if [ -f /tmp/docker-mailserver/postfix-accounts.cf -a "$ENABLE_LDAP" != 1 ]; then
sed -i 's/\r//g' /tmp/docker-mailserver/postfix-accounts.cf
echo "# WARNING: this file is auto-generated. Modify config/postfix-accounts.cf to edit user list." > /etc/postfix/vmailbox

View File

@ -149,9 +149,12 @@ function populate_relayhost_map() {
sed -n '/^\s*[^#[:space:]]\S*\s\+\S/p' /tmp/docker-mailserver/postfix-relaymap.cf \
>> /etc/postfix/relayhost_map
fi
# Note: Won't detect domains when lhs has spaces (but who does that?!).
sed -n '/^\s*[^#[:space:]]/ s/^[^@|]*@\([^|]\+\)|.*$/\1/p' /tmp/docker-mailserver/postfix-accounts.cf |
while read domain; do
{
# Note: Won't detect domains when lhs has spaces (but who does that?!).
sed -n '/^\s*[^#[:space:]]/ s/^[^@|]*@\([^|]\+\)|.*$/\1/p' /tmp/docker-mailserver/postfix-accounts.cf
[ -f /tmp/docker-mailserver/postfix-virtual.cf ] &&
sed -n '/^\s*[^#[:space:]]/ s/^\s*[^@[:space:]]*@\(\S\+\)\s.*/\1/p' /tmp/docker-mailserver/postfix-virtual.cf
} | while read domain; do
if ! grep -q -e "^@${domain}\b" /etc/postfix/relayhost_map &&
! grep -qs -e "^\s*@${domain}\s*$" /tmp/docker-mailserver/postfix-relaymap.cf; then
# Domain not already present *and* not ignored.

View File

@ -0,0 +1 @@
@domain1.tld user1@domainone.tld

View File

@ -42,6 +42,11 @@ function teardown_file() {
assert_output -e '^@domainone.tld\s+\[default.relay.com\]:2525$'
}
@test "checking relay hosts: default mapping is added from env vars for virtual user entry" {
run docker exec mail_with_relays grep -e domain1.tld /etc/postfix/relayhost_map
assert_output -e '^@domain1.tld\s+\[default.relay.com\]:2525$'
}
@test "checking relay hosts: default mapping is added from env vars for new user entry" {
run docker exec mail_with_relays grep -e domainzero.tld /etc/postfix/relayhost_map
assert_output ''
@ -54,6 +59,18 @@ function teardown_file() {
assert_output -e '^@domainzero.tld\s+\[default.relay.com\]:2525$'
}
@test "checking relay hosts: default mapping is added from env vars for new virtual user entry" {
run docker exec mail_with_relays grep -e domain2.tld /etc/postfix/relayhost_map
assert_output ''
run ./setup.sh -c mail_with_relays alias add user2@domain2.tld user2@domaintwo.tld
for i in {1..10}; do
sleep 1
run docker exec mail_with_relays grep -e domain2.tld /etc/postfix/relayhost_map
[[ $status == 0 ]] && break
done
assert_output -e '^@domain2.tld\s+\[default.relay.com\]:2525$'
}
@test "checking relay hosts: custom mapping is added from file" {
run docker exec mail_with_relays grep -e domaintwo.tld /etc/postfix/relayhost_map
assert_output -e '^@domaintwo.tld\s+\[other.relay.com\]:587$'