mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
e3cc627e18
* chore: Split vhost helper method and use filepath vars - Helpers `accounts.sh` and `aliases.sh` can move their vhost code into this helper. - They share duplicate code with `bin/open-dkim` which will also leverage this vhost helper going forward. * chore: Sync vhost generation logic into helper - Chunky commit, but mostly copy/paste of logic into a common method. - `bin/open-dkim` additionally wrapped relevant logic in a function call and revised inline docs. * chore: Include LDAP vhost support - Revises notes for LDAP vhost support. - This now ensures LDAP users get vhost rebuilt to match the startup script for when change detection support is enabled. - `bin/open-dkim` will additionally be able to support the default `DOMAINNAME` var (set via `helpers/dns.sh`) for LDAP users instead of requiring them to provide one explicitly. * chore(`bin/open-dkim`): Ensure `DOMAINNAME` is properly set - This will ensure LDAP users insert the same `DOMAINNAME` value as used during container startup. - The container itself should panic at startup (during `helpers/dns.sh`) if this isn't configured correctly already, thus it should not introduce any breaking change to users of this utility? * chore: Set the 2nd value as blank `_` Line is split by a delimiter such as white-space (or via IFS: `|`), the blank `_` var is to indicate we're not interested in that value, but still leverage how `read -r` works, instead of splitting the var ourselves first thing. * chore: Remove shellcheck disable lines No longer applicable with the switch to `_`
66 lines
1.9 KiB
Bash
66 lines
1.9 KiB
Bash
#! /bin/bash
|
|
# Support for Postfix aliases
|
|
|
|
# NOTE: LDAP doesn't appear to use this, but the docs page: "Use Cases | Forward-Only Mail-Server with LDAP"
|
|
# does have an example where /etc/postfix/virtual is referenced in addition to ldap config for Postfix `main.cf:virtual_alias_maps`.
|
|
# `setup-stack.sh:_setup_ldap` does not seem to configure for `/etc/postfix/virtual however.`
|
|
|
|
# NOTE: `accounts.sh` and `relay.sh:_populate_relayhost_map` also process on `postfix-virtual.cf`.
|
|
function _handle_postfix_virtual_config
|
|
{
|
|
: >/etc/postfix/virtual
|
|
: >/etc/postfix/regexp
|
|
|
|
local DATABASE_VIRTUAL=/tmp/docker-mailserver/postfix-virtual.cf
|
|
|
|
if [[ -f ${DATABASE_VIRTUAL} ]]
|
|
then
|
|
# fixing old virtual user file
|
|
if grep -q ",$" "${DATABASE_VIRTUAL}"
|
|
then
|
|
sed -i -e "s|, |,|g" -e "s|,$||g" "${DATABASE_VIRTUAL}"
|
|
fi
|
|
|
|
cp -f "${DATABASE_VIRTUAL}" /etc/postfix/virtual
|
|
else
|
|
_log 'debug' "'${DATABASE_VIRTUAL}' not provided - no mail alias/forward created"
|
|
fi
|
|
}
|
|
|
|
function _handle_postfix_regexp_config
|
|
{
|
|
if [[ -f /tmp/docker-mailserver/postfix-regexp.cf ]]
|
|
then
|
|
_log 'trace' "Adding regexp alias file postfix-regexp.cf"
|
|
|
|
cp -f /tmp/docker-mailserver/postfix-regexp.cf /etc/postfix/regexp
|
|
|
|
if ! grep 'virtual_alias_maps.*pcre:/etc/postfix/regexp' /etc/postfix/main.cf
|
|
then
|
|
sed -i -E \
|
|
's|virtual_alias_maps(.*)|virtual_alias_maps\1 pcre:/etc/postfix/regexp|g' \
|
|
/etc/postfix/main.cf
|
|
fi
|
|
fi
|
|
}
|
|
|
|
function _handle_postfix_aliases_config
|
|
{
|
|
_log 'trace' 'Configuring root alias'
|
|
|
|
echo "root: ${POSTMASTER_ADDRESS}" >/etc/aliases
|
|
|
|
local DATABASE_ALIASES='/tmp/docker-mailserver/postfix-aliases.cf'
|
|
[[ -f ${DATABASE_ALIASES} ]] && cat "${DATABASE_ALIASES}" >>/etc/aliases
|
|
|
|
postalias /etc/aliases
|
|
}
|
|
|
|
# Other scripts should call this method, rather than the ones above:
|
|
function _create_aliases
|
|
{
|
|
_handle_postfix_virtual_config
|
|
_handle_postfix_regexp_config
|
|
_handle_postfix_aliases_config
|
|
}
|