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:
polarathene 2024-01-28 15:40:45 +13:00
parent 569dd605df
commit 33a911d6cf
1 changed files with 13 additions and 8 deletions

View File

@ -43,21 +43,26 @@ function _vhost_collect_postfix_domains() {
local DATABASE_VIRTUAL='/tmp/docker-mailserver/postfix-virtual.cf' local DATABASE_VIRTUAL='/tmp/docker-mailserver/postfix-virtual.cf'
local DOMAIN UNAME local DOMAIN UNAME
# getting domains FROM mail accounts # Extract domains from mail accounts:
if [[ -f ${DATABASE_ACCOUNTS} ]]; then if [[ -f ${DATABASE_ACCOUNTS} ]]; then
while IFS=$'|' read -r LOGIN _; do while IFS=$'|' read -r FIRST_FIELD _; do
DOMAIN=$(echo "${LOGIN}" | cut -d @ -f2) # It is expected valid lines have the format local-part@domain-part:
DOMAIN=$(echo "${FIRST_FIELD}" | cut -d @ -f2)
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
# 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 if [[ -f ${DATABASE_VIRTUAL} ]]; then
while read -r FROM _; do while read -r FIRST_FIELD _; do
UNAME=$(echo "${FROM}" | cut -d @ -f1) UNAME=$(echo "${FIRST_FIELD}" | cut -d @ -f1)
DOMAIN=$(echo "${FROM}" | cut -d @ -f2) 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}" [[ ${UNAME} != "${DOMAIN}" ]] && echo "${DOMAIN}" >>"${TMP_VHOST}"
done < <(_get_valid_lines_from_file "${DATABASE_VIRTUAL}") done < <(_get_valid_lines_from_file "${DATABASE_VIRTUAL}")
fi fi