mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2025-06-28 19:50:16 +02:00
Change 'function' style (#3364)
This commit is contained in:
parent
cf74127f78
commit
37ca0f9ba9
60 changed files with 233 additions and 466 deletions
|
@ -18,8 +18,7 @@ DATABASE_PASSWD="${DMS_CONFIG}/postfix-sasl-password.cf"
|
|||
DATABASE_RELAY="${DMS_CONFIG}/postfix-relaymap.cf"
|
||||
|
||||
# Individual scripts with convenience methods to manage operations easier:
|
||||
function _db_import_scripts
|
||||
{
|
||||
function _db_import_scripts() {
|
||||
# This var is stripped by shellcheck from source paths below,
|
||||
# like the shellcheck source-path above, it shouold match this scripts
|
||||
# parent directory, with the rest of the relative path in the source lines:
|
||||
|
@ -35,8 +34,7 @@ function _db_entry_add_or_append { _db_operation 'append' "${@}" ; } # Only us
|
|||
function _db_entry_add_or_replace { _db_operation 'replace' "${@}" ; }
|
||||
function _db_entry_remove { _db_operation 'remove' "${@}" ; }
|
||||
|
||||
function _db_operation
|
||||
{
|
||||
function _db_operation() {
|
||||
local DB_ACTION=${1}
|
||||
local DATABASE=${2}
|
||||
local KEY=${3}
|
||||
|
@ -126,8 +124,7 @@ function _db_operation
|
|||
}
|
||||
|
||||
# Internal method for: _db_operation
|
||||
function __db_list_already_contains_value
|
||||
{
|
||||
function __db_list_already_contains_value() {
|
||||
# Avoids accidentally matching a substring (case-insensitive acceptable):
|
||||
# 1. Extract the current value of the entry (`\1`),
|
||||
# 2. Value list support: Split values into separate lines (`\n`+`g`) at V_DELIMITER,
|
||||
|
@ -140,8 +137,7 @@ function __db_list_already_contains_value
|
|||
|
||||
# Internal method for: _db_operation + _db_has_entry_with_key
|
||||
# References global vars `DATABASE_*`:
|
||||
function __db_get_delimiter_for
|
||||
{
|
||||
function __db_get_delimiter_for() {
|
||||
local DATABASE=${1}
|
||||
|
||||
case "${DATABASE}" in
|
||||
|
@ -171,8 +167,7 @@ function __db_get_delimiter_for
|
|||
# `\` can escape these (`/` exists in postfix-account.cf base64 encoded pw hash),
|
||||
# But otherwise care should be taken with `\`, which should be forbidden for input here?
|
||||
# NOTE: Presently only `.` is escaped with `\` via `_escape`.
|
||||
function __escape_sed_replacement
|
||||
{
|
||||
function __escape_sed_replacement() {
|
||||
# Matches any `/` or `&`, and escapes them with `\` (`\\\1`):
|
||||
sed 's/\([/&]\)/\\\1/g' <<< "${ENTRY}"
|
||||
}
|
||||
|
@ -181,8 +176,7 @@ function __escape_sed_replacement
|
|||
# Validation Methods
|
||||
#
|
||||
|
||||
function _db_has_entry_with_key
|
||||
{
|
||||
function _db_has_entry_with_key() {
|
||||
local KEY=${1}
|
||||
local DATABASE=${2}
|
||||
|
||||
|
@ -202,8 +196,7 @@ function _db_has_entry_with_key
|
|||
grep --quiet --no-messages --ignore-case "^${KEY_LOOKUP}" "${DATABASE}"
|
||||
}
|
||||
|
||||
function _db_should_exist_with_content
|
||||
{
|
||||
function _db_should_exist_with_content() {
|
||||
local DATABASE=${1}
|
||||
|
||||
[[ -f ${DATABASE} ]] || _exit_with_error "'${DATABASE}' does not exist"
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
# Manage DB writes for: DATABASE_QUOTA
|
||||
|
||||
# Logic to perform for requested operations handled here:
|
||||
function _manage_dovecot_quota
|
||||
{
|
||||
function _manage_dovecot_quota() {
|
||||
local ACTION=${1}
|
||||
local MAIL_ACCOUNT=${2}
|
||||
# Only for ACTION 'update':
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
# - DATABASE_DOVECOT_MASTERS
|
||||
|
||||
# Logic to perform for requested operations handled here:
|
||||
function _manage_accounts
|
||||
{
|
||||
function _manage_accounts() {
|
||||
local ACTION=${1}
|
||||
local DATABASE=${2}
|
||||
local MAIL_ACCOUNT=${3}
|
||||
|
@ -60,8 +59,7 @@ function _manage_accounts_dovecotmaster_delete { _manage_accounts 'delete' "${DA
|
|||
# - Calling external method '__usage' as part of error handling.
|
||||
|
||||
# Also used by setquota, delquota
|
||||
function _arg_expect_mail_account
|
||||
{
|
||||
function _arg_expect_mail_account() {
|
||||
[[ -z ${MAIL_ACCOUNT} ]] && { __usage ; _exit_with_error 'No account specified' ; }
|
||||
|
||||
# Dovecot Master accounts are validated (they are not email addresses):
|
||||
|
@ -71,8 +69,7 @@ function _arg_expect_mail_account
|
|||
[[ ${MAIL_ACCOUNT} =~ .*\@.* ]] || { __usage ; _exit_with_error "'${MAIL_ACCOUNT}' should include the domain (eg: user@example.com)" ; }
|
||||
}
|
||||
|
||||
function _account_should_not_exist_yet
|
||||
{
|
||||
function _account_should_not_exist_yet() {
|
||||
__account_already_exists && _exit_with_error "'${MAIL_ACCOUNT}' already exists"
|
||||
if [[ -f ${DATABASE_VIRTUAL} ]] && grep -q "^${MAIL_ACCOUNT}" "${DATABASE_VIRTUAL}"; then
|
||||
_exit_with_error "'${MAIL_ACCOUNT}' is already defined as an alias"
|
||||
|
@ -80,20 +77,17 @@ function _account_should_not_exist_yet
|
|||
}
|
||||
|
||||
# Also used by delmailuser, setquota, delquota
|
||||
function _account_should_already_exist
|
||||
{
|
||||
function _account_should_already_exist() {
|
||||
! __account_already_exists && _exit_with_error "'${MAIL_ACCOUNT}' does not exist"
|
||||
}
|
||||
|
||||
function __account_already_exists
|
||||
{
|
||||
function __account_already_exists() {
|
||||
local DATABASE=${DATABASE:-"${DATABASE_ACCOUNTS}"}
|
||||
_db_has_entry_with_key "${MAIL_ACCOUNT}" "${DATABASE}"
|
||||
}
|
||||
|
||||
# Also used by addsaslpassword
|
||||
function _password_request_if_missing
|
||||
{
|
||||
function _password_request_if_missing() {
|
||||
if [[ -z ${PASSWD} ]]; then
|
||||
read -r -s -p 'Enter Password: ' PASSWD
|
||||
echo
|
||||
|
|
|
@ -11,8 +11,7 @@
|
|||
# mail to an alias address.
|
||||
|
||||
# Logic to perform for requested operations handled here:
|
||||
function _manage_virtual_aliases
|
||||
{
|
||||
function _manage_virtual_aliases() {
|
||||
local ACTION=${1}
|
||||
local MAIL_ALIAS=${2}
|
||||
local RECIPIENT=${3}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue