Apply suggestions from code review
Co-authored-by: Georg Lauterbach <44545919+georglauterbach@users.noreply.github.com>
This commit is contained in:
parent
a5feec5b09
commit
7aaa515ed9
|
@ -47,18 +47,20 @@ function _vhost_collect_postfix_domains() {
|
||||||
if [[ -f ${DATABASE_ACCOUNTS} ]]; then
|
if [[ -f ${DATABASE_ACCOUNTS} ]]; then
|
||||||
while IFS=$'|' read -r FIRST_FIELD _; do
|
while IFS=$'|' read -r FIRST_FIELD _; do
|
||||||
# It is expected valid lines have the format local-part@domain-part:
|
# It is expected valid lines have the format local-part@domain-part:
|
||||||
DOMAIN=$(echo "${FIRST_FIELD}" | cut -d @ -f2)
|
DOMAIN=$(cut -d '@' -f 2 <<< "${FIRST_FIELD}")
|
||||||
|
|
||||||
echo "${DOMAIN}" >>"${TMP_VHOST}"
|
echo "${DOMAIN}" >>"${TMP_VHOST}"
|
||||||
done < <(_get_valid_lines_from_file "${DATABASE_ACCOUNTS}")
|
done < <(_get_valid_lines_from_file "${DATABASE_ACCOUNTS}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# TODO: Consider if virtual aliases should be configured to the same vhost file:
|
||||||
|
# https://github.com/docker-mailserver/docker-mailserver/issues/2813#issuecomment-1272394563
|
||||||
# Extract domains from virtual alias config:
|
# Extract domains from virtual alias config:
|
||||||
# Aliases may have the forms: 'local-part@domain-part', only 'local-part', or '@domain-part' (wildcard catch-all)
|
# Aliases may have the forms: 'local-part@domain-part', only 'local-part', or '@domain-part' (wildcard catch-all)
|
||||||
if [[ -f ${DATABASE_VIRTUAL} ]]; then
|
if [[ -f ${DATABASE_VIRTUAL} ]]; then
|
||||||
while read -r FIRST_FIELD _; do
|
while read -r FIRST_FIELD _; do
|
||||||
UNAME=$(echo "${FIRST_FIELD}" | cut -d @ -f1)
|
UNAME=$(cut -d '@' -f 1 <<< "${FIRST_FIELD}")
|
||||||
DOMAIN=$(echo "${FIRST_FIELD}" | cut -d @ -f2)
|
DOMAIN=$(cut -d '@' -f 2 <<< "${FIRST_FIELD}")
|
||||||
|
|
||||||
# Only add valid domain-parts found:
|
# Only add valid domain-parts found:
|
||||||
# The '@' is optional for an alias key (eg: "user1 other@domain.tld"),
|
# The '@' is optional for an alias key (eg: "user1 other@domain.tld"),
|
||||||
|
|
|
@ -154,9 +154,7 @@ function _legacy_support() {
|
||||||
local DATABASE_VHOST='/etc/postfix/vhost'
|
local DATABASE_VHOST='/etc/postfix/vhost'
|
||||||
|
|
||||||
# Only relevant when `RELAY_HOST` is configured:
|
# Only relevant when `RELAY_HOST` is configured:
|
||||||
if [[ -z ${RELAY_HOST} ]]; then
|
[[ -z ${RELAY_HOST} ]] && return 1
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Configures each `SENDER_DOMAIN` to send outbound mail through the default `RELAY_HOST` + `RELAY_PORT`
|
# Configures each `SENDER_DOMAIN` to send outbound mail through the default `RELAY_HOST` + `RELAY_PORT`
|
||||||
# (by adding an entry in `/etc/postfix/relayhost_map`) provided it:
|
# (by adding an entry in `/etc/postfix/relayhost_map`) provided it:
|
||||||
|
@ -165,11 +163,11 @@ function _legacy_support() {
|
||||||
#
|
#
|
||||||
# NOTE: /etc/postfix/vhost represents managed mail domains sourced from `postfix-accounts.cf` and `postfix-virtual.cf`.
|
# NOTE: /etc/postfix/vhost represents managed mail domains sourced from `postfix-accounts.cf` and `postfix-virtual.cf`.
|
||||||
while read -r SENDER_DOMAIN; do
|
while read -r SENDER_DOMAIN; do
|
||||||
local MATCH_EXISTING_ENTRY="^@${SENDER_DOMAIN}\b"
|
local MATCH_EXISTING_ENTRY="^@${SENDER_DOMAIN}\s+"
|
||||||
local MATCH_OPT_OUT_LINE="^\s*@${SENDER_DOMAIN}\s*$"
|
local MATCH_OPT_OUT_LINE="^\s*@${SENDER_DOMAIN}\s*$"
|
||||||
|
|
||||||
if ! grep -q -e "${MATCH_EXISTING_ENTRY}" /etc/postfix/relayhost_map && ! grep -qs -e "${MATCH_OPT_OUT_LINE}" "${DATABASE_RELAYHOSTS}"; then
|
if ! grep -q -e "${MATCH_EXISTING_ENTRY}" /etc/postfix/relayhost_map && ! grep -qs -e "${MATCH_OPT_OUT_LINE}" "${DATABASE_RELAYHOSTS}"; then
|
||||||
_log 'trace' "Configuring ${SENDER_DOMAIN} for the default relayhost '${RELAY_HOST}'"
|
_log 'trace' "Configuring '${SENDER_DOMAIN}' for the default relayhost '${RELAY_HOST}'"
|
||||||
echo "@${SENDER_DOMAIN} $(_env_relay_host)" >> /etc/postfix/relayhost_map
|
echo "@${SENDER_DOMAIN} $(_env_relay_host)" >> /etc/postfix/relayhost_map
|
||||||
fi
|
fi
|
||||||
done < <(_get_valid_lines_from_file "${DATABASE_VHOST}")
|
done < <(_get_valid_lines_from_file "${DATABASE_VHOST}")
|
||||||
|
|
Loading…
Reference in New Issue