mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
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:
parent
1286a1266b
commit
42352a3259
|
@ -81,6 +81,7 @@ if ! cmp --silent -- "$CHKSUM_FILE" "$CHKSUM_FILE.new"; then
|
||||||
#regen postfix accounts.
|
#regen postfix accounts.
|
||||||
echo -n > /etc/postfix/vmailbox
|
echo -n > /etc/postfix/vmailbox
|
||||||
echo -n > /etc/dovecot/userdb
|
echo -n > /etc/dovecot/userdb
|
||||||
|
|
||||||
if [ -f /tmp/docker-mailserver/postfix-accounts.cf -a "$ENABLE_LDAP" != 1 ]; then
|
if [ -f /tmp/docker-mailserver/postfix-accounts.cf -a "$ENABLE_LDAP" != 1 ]; then
|
||||||
sed -i 's/\r//g' /tmp/docker-mailserver/postfix-accounts.cf
|
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
|
echo "# WARNING: this file is auto-generated. Modify config/postfix-accounts.cf to edit user list." > /etc/postfix/vmailbox
|
||||||
|
|
|
@ -149,9 +149,12 @@ function populate_relayhost_map() {
|
||||||
sed -n '/^\s*[^#[:space:]]\S*\s\+\S/p' /tmp/docker-mailserver/postfix-relaymap.cf \
|
sed -n '/^\s*[^#[:space:]]\S*\s\+\S/p' /tmp/docker-mailserver/postfix-relaymap.cf \
|
||||||
>> /etc/postfix/relayhost_map
|
>> /etc/postfix/relayhost_map
|
||||||
fi
|
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 |
|
# Note: Won't detect domains when lhs has spaces (but who does that?!).
|
||||||
while read domain; do
|
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 &&
|
if ! grep -q -e "^@${domain}\b" /etc/postfix/relayhost_map &&
|
||||||
! grep -qs -e "^\s*@${domain}\s*$" /tmp/docker-mailserver/postfix-relaymap.cf; then
|
! grep -qs -e "^\s*@${domain}\s*$" /tmp/docker-mailserver/postfix-relaymap.cf; then
|
||||||
# Domain not already present *and* not ignored.
|
# Domain not already present *and* not ignored.
|
||||||
|
|
1
test/config/relay-hosts/postfix-virtual.cf
Normal file
1
test/config/relay-hosts/postfix-virtual.cf
Normal file
|
@ -0,0 +1 @@
|
||||||
|
@domain1.tld user1@domainone.tld
|
|
@ -42,6 +42,11 @@ function teardown_file() {
|
||||||
assert_output -e '^@domainone.tld\s+\[default.relay.com\]:2525$'
|
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" {
|
@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
|
run docker exec mail_with_relays grep -e domainzero.tld /etc/postfix/relayhost_map
|
||||||
assert_output ''
|
assert_output ''
|
||||||
|
@ -54,6 +59,18 @@ function teardown_file() {
|
||||||
assert_output -e '^@domainzero.tld\s+\[default.relay.com\]:2525$'
|
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" {
|
@test "checking relay hosts: custom mapping is added from file" {
|
||||||
run docker exec mail_with_relays grep -e domaintwo.tld /etc/postfix/relayhost_map
|
run docker exec mail_with_relays grep -e domaintwo.tld /etc/postfix/relayhost_map
|
||||||
assert_output -e '^@domaintwo.tld\s+\[other.relay.com\]:587$'
|
assert_output -e '^@domaintwo.tld\s+\[other.relay.com\]:587$'
|
||||||
|
|
Loading…
Reference in a new issue