chore: Better document postfix helper `_vhost_collect_postfix_domains()`
The functionality is effectively the same for the two configs for the most part when it comes to parsing out a domain from the target value. Virtual aliases is more flexible in value, which may not have a domain-part present (manual user edit).
This commit is contained in:
parent
569dd605df
commit
33a911d6cf
|
@ -43,21 +43,26 @@ function _vhost_collect_postfix_domains() {
|
|||
local DATABASE_VIRTUAL='/tmp/docker-mailserver/postfix-virtual.cf'
|
||||
local DOMAIN UNAME
|
||||
|
||||
# getting domains FROM mail accounts
|
||||
# Extract domains from mail accounts:
|
||||
if [[ -f ${DATABASE_ACCOUNTS} ]]; then
|
||||
while IFS=$'|' read -r LOGIN _; do
|
||||
DOMAIN=$(echo "${LOGIN}" | cut -d @ -f2)
|
||||
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)
|
||||
|
||||
echo "${DOMAIN}" >>"${TMP_VHOST}"
|
||||
done < <(_get_valid_lines_from_file "${DATABASE_ACCOUNTS}")
|
||||
fi
|
||||
|
||||
# getting domains FROM mail aliases
|
||||
# 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 FROM _; do
|
||||
UNAME=$(echo "${FROM}" | cut -d @ -f1)
|
||||
DOMAIN=$(echo "${FROM}" | cut -d @ -f2)
|
||||
while read -r FIRST_FIELD _; do
|
||||
UNAME=$(echo "${FIRST_FIELD}" | cut -d @ -f1)
|
||||
DOMAIN=$(echo "${FIRST_FIELD}" | cut -d @ -f2)
|
||||
|
||||
# if they are equal it means the line looks like: "user1 other@domain.tld"
|
||||
# Only add valid domain-parts found:
|
||||
# The '@' is optional for an alias key (eg: "user1 other@domain.tld"),
|
||||
# but cut with -f2 would output the same value as it would -f1 when '@' is missing.
|
||||
[[ ${UNAME} != "${DOMAIN}" ]] && echo "${DOMAIN}" >>"${TMP_VHOST}"
|
||||
done < <(_get_valid_lines_from_file "${DATABASE_VIRTUAL}")
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue