diff --git a/target/scripts/helpers/postfix.sh b/target/scripts/helpers/postfix.sh index 483696a2..19b80cbd 100644 --- a/target/scripts/helpers/postfix.sh +++ b/target/scripts/helpers/postfix.sh @@ -47,18 +47,20 @@ function _vhost_collect_postfix_domains() { if [[ -f ${DATABASE_ACCOUNTS} ]]; then while IFS=$'|' read -r FIRST_FIELD _; do # 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}" done < <(_get_valid_lines_from_file "${DATABASE_ACCOUNTS}") 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: # Aliases may have the forms: 'local-part@domain-part', only 'local-part', or '@domain-part' (wildcard catch-all) if [[ -f ${DATABASE_VIRTUAL} ]]; then while read -r FIRST_FIELD _; do - UNAME=$(echo "${FIRST_FIELD}" | cut -d @ -f1) - DOMAIN=$(echo "${FIRST_FIELD}" | cut -d @ -f2) + UNAME=$(cut -d '@' -f 1 <<< "${FIRST_FIELD}") + DOMAIN=$(cut -d '@' -f 2 <<< "${FIRST_FIELD}") # Only add valid domain-parts found: # The '@' is optional for an alias key (eg: "user1 other@domain.tld"), diff --git a/target/scripts/helpers/relay.sh b/target/scripts/helpers/relay.sh index 3744c41c..845f2b6f 100644 --- a/target/scripts/helpers/relay.sh +++ b/target/scripts/helpers/relay.sh @@ -88,7 +88,7 @@ function _relayhost_sasl() { # Support authentication to a primary relayhost (when configured with credentials via ENV): if [[ -n ${DEFAULT_RELAY_HOST} || -n ${RELAY_HOST} ]] \ && [[ -n ${RELAY_USER} && -n ${RELAY_PASSWORD} ]]; then - echo "${DEFAULT_RELAY_HOST:-$(_env_relay_host)} ${RELAY_USER}:${RELAY_PASSWORD}" >> /etc/postfix/sasl_passwd + echo "${DEFAULT_RELAY_HOST:-$(_env_relay_host)} ${RELAY_USER}:${RELAY_PASSWORD}" >>/etc/postfix/sasl_passwd fi # Enable credential lookup + SASL authentication to relayhost: @@ -154,9 +154,7 @@ function _legacy_support() { local DATABASE_VHOST='/etc/postfix/vhost' # Only relevant when `RELAY_HOST` is configured: - if [[ -z ${RELAY_HOST} ]]; then - return 1 - fi + [[ -z ${RELAY_HOST} ]] && return 1 # 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: @@ -165,11 +163,11 @@ function _legacy_support() { # # NOTE: /etc/postfix/vhost represents managed mail domains sourced from `postfix-accounts.cf` and `postfix-virtual.cf`. 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*$" 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 fi done < <(_get_valid_lines_from_file "${DATABASE_VHOST}")