2016-12-30 19:06:44 +00:00
|
|
|
#! /bin/bash
|
2016-08-29 11:44:36 +00:00
|
|
|
|
2022-02-21 10:56:57 +00:00
|
|
|
# shellcheck source=../scripts/helpers/index.sh
|
|
|
|
source /usr/local/bin/helpers/index.sh
|
2016-08-29 11:44:36 +00:00
|
|
|
|
2021-11-01 11:09:47 +00:00
|
|
|
# suppress error output, e.g. when listmailuser runs in a fresh container (DMS not running)
|
2022-01-27 13:57:40 +00:00
|
|
|
# shellcheck source=/dev/null
|
2022-02-21 10:56:57 +00:00
|
|
|
source /etc/dms-settings 2>/dev/null
|
2021-11-01 11:09:47 +00:00
|
|
|
|
2022-03-26 08:30:09 +00:00
|
|
|
function dovecot_quota_to_hr
|
2021-04-12 13:18:15 +00:00
|
|
|
{
|
2022-01-27 13:57:40 +00:00
|
|
|
if [[ ${1:-} == "-" ]]
|
2021-04-12 13:18:15 +00:00
|
|
|
then
|
|
|
|
echo "~"
|
2022-01-27 13:57:40 +00:00
|
|
|
elif [[ ${1:-} =~ ^[0-9]+$ ]]
|
|
|
|
then
|
2021-04-12 13:18:15 +00:00
|
|
|
echo $(( 1024 * ${1} )) | numfmt --to=iec
|
2022-01-27 13:57:40 +00:00
|
|
|
else
|
2022-03-26 08:30:09 +00:00
|
|
|
_exit_with_error "Supplied non-number argument '${1:-}' to 'dovecot_quota_to_hr()' in script 'listmailuser'"
|
2021-04-12 13:18:15 +00:00
|
|
|
fi
|
|
|
|
}
|
2016-08-29 11:44:36 +00:00
|
|
|
|
2022-03-26 08:30:09 +00:00
|
|
|
DATABASE='/tmp/docker-mailserver/postfix-accounts.cf'
|
|
|
|
ALIASES='/tmp/docker-mailserver/postfix-virtual.cf'
|
2021-04-12 13:18:15 +00:00
|
|
|
|
2022-03-26 08:30:09 +00:00
|
|
|
[[ -f ${DATABASE} ]] || _exit_with_error "No 'postfix-accounts.cf' file"
|
|
|
|
[[ -s ${DATABASE} ]] || _exit_with_error "Empty 'postfix-accounts.cf' - no accounts have been added"
|
2021-04-12 13:18:15 +00:00
|
|
|
|
|
|
|
while read -r LINE
|
|
|
|
do
|
|
|
|
USER=$(echo "${LINE}" | cut -d'|' -f1)
|
|
|
|
|
2021-12-21 16:01:40 +00:00
|
|
|
if [[ ${ENABLE_QUOTAS} -eq 1 ]]
|
2021-11-01 11:09:47 +00:00
|
|
|
then
|
|
|
|
# ${QUOTA[0]} => current size
|
|
|
|
# ${QUOTA[1]} => configured size limit
|
|
|
|
# ${QUOTA[2]} => usage in percent
|
|
|
|
IFS=' ' read -r -a QUOTA <<< "$(doveadm quota get -u "${USER}" | tail +2 | awk '{ if ($3 == "STORAGE") { print $4" "$5" "$6 } }')"
|
|
|
|
echo "* ${USER} ( $(dovecot_quota_to_hr "${QUOTA[0]}") / $(dovecot_quota_to_hr "${QUOTA[1]}") ) [${QUOTA[2]}%]"
|
|
|
|
else
|
|
|
|
echo "* ${USER}"
|
|
|
|
fi
|
2021-04-12 13:18:15 +00:00
|
|
|
|
|
|
|
if [[ -f ${ALIASES} ]] && grep -q "${USER}" "${ALIASES}"
|
|
|
|
then
|
|
|
|
echo -e " [ aliases -> $(grep "${USER}" "${ALIASES}" | awk '{print $1;}' | sed ':a;N;$!ba;s/\n/, /g')]\n"
|
|
|
|
else
|
|
|
|
echo
|
|
|
|
fi
|
2022-06-05 23:02:52 +00:00
|
|
|
done < <(_filter_to_valid_lines "${DATABASE}")
|
|
|
|
|
2016-08-29 11:44:36 +00:00
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
exit 0
|