Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for #1808 #1864

Merged
merged 5 commits into from Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.sh
Expand Up @@ -312,7 +312,7 @@ function _main
;;

* )
echo "Invalid option: -${OPTARG}" >&2
echo "Invalid option: -${OPT}" >&2
;;

esac
Expand Down
7 changes: 5 additions & 2 deletions target/bin/addmailuser
Expand Up @@ -47,8 +47,11 @@ touch "${DATABASE}"
(
flock -e 200

grep -qi "^$(escape "${USER}")|" "${DATABASE}" 2>/dev/null &&
errex "User \"${USER}\" already exists"
if grep -qi "^$(escape "${USER}")|" "${DATABASE}" 2>/dev/null
then
echo "User '${USER}' already exists."
exit 0
georglauterbach marked this conversation as resolved.
Show resolved Hide resolved
fi

if [[ -z ${PASSWD} ]]
then
Expand Down
99 changes: 49 additions & 50 deletions target/bin/delmailuser
Expand Up @@ -75,7 +75,7 @@ do
done
shift $((OPTIND-1))

[[ -z ${*} ]] && { usage ; errex "No user specifed" ; }
[[ -z ${*} ]] && { __usage ; errex "No user specifed" ; }
[[ -s ${DATABASE} ]] || exit 0

if ! ${MAILDEL}
Expand All @@ -90,73 +90,72 @@ fi
(
flock -e 200
ERROR=false
USER="${*}"

for USER in "${@}"
do
# very simple plausibility check
[[ ${USER} != *'@'*'.'* ]] && errex "No valid address: ${USER}"
# very simple plausibility check
[[ ${USER} != *@*.* ]] && errex "No valid address: ${USER}"

declare -a MAILARR
MAILARR[0]="${USER%@*}"
MAILARR[1]="${USER#*@}"
unset MAILARR
casperklein marked this conversation as resolved.
Show resolved Hide resolved
declare -a MAILARR
MAILARR[0]="${USER%@*}"
MAILARR[1]="${USER#*@}"

# ${USER} must not contain /s and other syntactic characters
UNESCAPED_USER="${USER}"
USER=$(escape "${USER}")
# ${USER} must not contain /s and other syntactic characters
UNESCAPED_USER="${USER}"
USER=$(escape "${USER}")

if [[ -f ${DATABASE} ]]
if [[ -f ${DATABASE} ]]
then
if ! sed -i "/^${USER}|/d" "${DATABASE}"
then
if ! sed -i "/^${USER}|/d" "${DATABASE}"
then
echo "${UNESCAPED_USER} couldn't be deleted in ${DATABASE}." >&2
ERROR=true
fi
echo "${UNESCAPED_USER} couldn't be deleted in ${DATABASE}." >&2
ERROR=true
fi
fi

if [[ -f ${ALIAS_DATABASE} ]]
if [[ -f ${ALIAS_DATABASE} ]]
then
# delete all aliases where the user is the only recipient( " ${USER$}" )
# delete user only for all aliases that deliver to multiple recipients ( ",${USER}" "${USER,}" )
if sed -i \
-e "/ ${USER}$/d" -e "s/,${USER}//g" -e "s/${USER},//g" \
"${ALIAS_DATABASE}"
then
# delete all aliases where the user is the only recipient( " ${USER$}" )
# delete user only for all aliases that deliver to multiple recipients ( ",${USER}" "${USER,}" )
if sed -i \
-e "/ ${USER}$/d" -e "s/,${USER}//g" -e "s/${USER},//g" \
"${ALIAS_DATABASE}"
then
echo "${UNESCAPED_USER} and potential aliases deleted."
else
echo "Aliases for ${UNESCAPED_USER} couldn't be deleted in ${ALIAS_DATABASE}." >&2
ERROR=true
fi
echo "${UNESCAPED_USER} and potential aliases deleted."
else
echo "Aliases for ${UNESCAPED_USER} couldn't be deleted in ${ALIAS_DATABASE}." >&2
ERROR=true
fi
fi

# remove quota directives
if [[ -f ${QUOTA_DATABASE} ]]
# remove quota directives
if [[ -f ${QUOTA_DATABASE} ]]
then
if ! sed -i -e "/^${USER}:.*$/d" "${QUOTA_DATABASE}"
then
if ! sed -i -e "/^${USER}:.*$/d" "${QUOTA_DATABASE}"
then
echo "Quota for ${UNESCAPED_USER} couldn't be deleted in ${QUOTA_DATABASE}." >&2
fi
echo "Quota for ${UNESCAPED_USER} couldn't be deleted in ${QUOTA_DATABASE}." >&2
fi
fi

if ! ${MAILDEL}
then
echo "Leaving the mailbox untouched. If you want to delete it at a later point use 'sudo docker exec mail rm -R /var/mail/${MAILARR[1]}/${MAILARR[0]}'"
exit 0
fi
if ! ${MAILDEL}
then
echo "Leaving the mailbox untouched. If you want to delete it at a later point use 'sudo docker exec mail rm -R /var/mail/${MAILARR[1]}/${MAILARR[0]}'"
exit 0
fi

if [[ -e "/var/mail/${MAILARR[1]}/${MAILARR[0]}" ]]
if [[ -e "/var/mail/${MAILARR[1]}/${MAILARR[0]}" ]]
then
if rm -R "/var/mail/${MAILARR[1]}/${MAILARR[0]}"
then
if rm -R "/var/mail/${MAILARR[1]}/${MAILARR[0]}"
then
echo "Mailbox deleted."
else
echo "Mailbox couldn't be deleted." >&2
ERROR=true
fi
echo "Mailbox deleted."
else
echo "Mailbox directory '/var/mail/${MAILARR[1]}/${MAILARR[0]}' did not exist." >&2
echo "Mailbox couldn't be deleted." >&2
ERROR=true
fi
done
else
echo "Mailbox directory '/var/mail/${MAILARR[1]}/${MAILARR[0]}' did not exist." >&2
ERROR=true
fi

${ERROR} && errex 'Errors encountered.'

Expand Down