2022-10-17 08:40:09 +00:00
|
|
|
#!/bin/bash
|
2021-11-20 20:33:49 +00:00
|
|
|
# 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
|
|
|
|
|
2022-06-06 13:07:30 +00:00
|
|
|
local DATABASE_VIRTUAL=/tmp/docker-mailserver/postfix-virtual.cf
|
|
|
|
|
2023-05-24 07:06:59 +00:00
|
|
|
if [[ -f ${DATABASE_VIRTUAL} ]]; then
|
2021-11-20 20:33:49 +00:00
|
|
|
# fixing old virtual user file
|
2023-05-24 07:06:59 +00:00
|
|
|
if grep -q ",$" "${DATABASE_VIRTUAL}"; then
|
2022-06-06 13:07:30 +00:00
|
|
|
sed -i -e "s|, |,|g" -e "s|,$||g" "${DATABASE_VIRTUAL}"
|
2021-11-20 20:33:49 +00:00
|
|
|
fi
|
|
|
|
|
2022-06-06 13:07:30 +00:00
|
|
|
cp -f "${DATABASE_VIRTUAL}" /etc/postfix/virtual
|
2021-11-20 20:33:49 +00:00
|
|
|
else
|
2022-06-06 13:07:30 +00:00
|
|
|
_log 'debug' "'${DATABASE_VIRTUAL}' not provided - no mail alias/forward created"
|
2021-11-20 20:33:49 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function _handle_postfix_regexp_config
|
|
|
|
{
|
2022-06-11 23:36:37 +00:00
|
|
|
: >/etc/postfix/regexp
|
|
|
|
|
2023-05-24 07:06:59 +00:00
|
|
|
if [[ -f /tmp/docker-mailserver/postfix-regexp.cf ]]; then
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'trace' "Adding regexp alias file postfix-regexp.cf"
|
2021-11-20 20:33:49 +00:00
|
|
|
|
|
|
|
cp -f /tmp/docker-mailserver/postfix-regexp.cf /etc/postfix/regexp
|
2022-02-11 20:20:45 +00:00
|
|
|
|
2023-05-24 07:06:59 +00:00
|
|
|
if ! grep 'virtual_alias_maps.*pcre:/etc/postfix/regexp' /etc/postfix/main.cf; then
|
2022-02-11 20:20:45 +00:00
|
|
|
sed -i -E \
|
|
|
|
's|virtual_alias_maps(.*)|virtual_alias_maps\1 pcre:/etc/postfix/regexp|g' \
|
|
|
|
/etc/postfix/main.cf
|
|
|
|
fi
|
2021-11-20 20:33:49 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function _handle_postfix_aliases_config
|
|
|
|
{
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'trace' 'Configuring root alias'
|
2021-11-20 20:33:49 +00:00
|
|
|
|
2022-02-11 20:20:45 +00:00
|
|
|
echo "root: ${POSTMASTER_ADDRESS}" >/etc/aliases
|
2021-11-20 20:33:49 +00:00
|
|
|
|
2022-06-09 07:48:07 +00:00
|
|
|
local DATABASE_ALIASES='/tmp/docker-mailserver/postfix-aliases.cf'
|
|
|
|
[[ -f ${DATABASE_ALIASES} ]] && cat "${DATABASE_ALIASES}" >>/etc/aliases
|
2021-11-20 20:33:49 +00:00
|
|
|
|
2023-01-12 21:10:58 +00:00
|
|
|
_adjust_mtime_for_postfix_maincf
|
2021-11-20 20:33:49 +00:00
|
|
|
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
|
|
|
|
}
|