-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Make deletion of mailbox data opt-in #4365
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
Merged
casperklein
merged 5 commits into
docker-mailserver:master
from
casperklein:delmailuser
Feb 16, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e0bb79d
Make deletion of mailbox data opt-in
casperklein 7e10ded
streamline wording
casperklein 5b13cff
update changelog
casperklein ce1b34f
add PR # to changelog
casperklein 74d285d
Merge branch 'master' into delmailuser
georglauterbach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,11 @@ function _main() { | |
| for MAIL_ACCOUNT in "${@}"; do | ||
| _account_should_already_exist | ||
|
|
||
| [[ ${MAILDEL} -eq 1 ]] && _remove_maildir "${MAIL_ACCOUNT}" | ||
| if [[ ${MAILDEL} -eq 1 ]]; then | ||
| _remove_maildir "${MAIL_ACCOUNT}" | ||
| else | ||
| _log 'info' "The mailbox data will not be deleted." | ||
| fi | ||
|
|
||
| _manage_virtual_aliases_delete '_' "${MAIL_ACCOUNT}" \ | ||
| || _exit_with_error "Aliases for '${MAIL_ACCOUNT}' could not be deleted" | ||
|
|
@@ -31,7 +35,7 @@ function _main() { | |
| _manage_accounts_delete "${MAIL_ACCOUNT}" \ | ||
| || _exit_with_error "'${MAIL_ACCOUNT}' could not be deleted" | ||
|
|
||
| _log 'info' "'${MAIL_ACCOUNT}' and associated data deleted" | ||
| _log 'info' "'${MAIL_ACCOUNT}' and associated data (aliases, quotas) deleted" | ||
| done | ||
| } | ||
|
|
||
|
|
@@ -43,14 +47,14 @@ ${ORANGE}USAGE${RESET} | |
|
|
||
| ${ORANGE}OPTIONS${RESET} | ||
| -y | ||
| Skip prompt by approving to ${LWHITE}delete all mail storage${RESET} for the account(s). | ||
| Skip prompt by approving to ${LWHITE}delete all mail data${RESET} for the account(s). | ||
|
|
||
| ${BLUE}Generic Program Information${RESET} | ||
| help Print the usage information. | ||
|
|
||
| ${ORANGE}DESCRIPTION${RESET} | ||
| Delete a mail account, including associated data (aliases, quotas) and | ||
| optionally the mailbox storage for that account. | ||
| optionally the mailbox data for that account. | ||
|
|
||
| ${ORANGE}EXAMPLES${RESET} | ||
| ${LWHITE}./setup.sh email del [email protected]${RESET} | ||
|
|
@@ -87,12 +91,10 @@ function _parse_options() { | |
| function _maildel_request_if_missing() { | ||
| if [[ ${MAILDEL} -eq 0 ]]; then | ||
| local MAILDEL_CHOSEN | ||
| read -r -p "Do you want to delete the mailbox as well (removing all mails)? [Y/n] " MAILDEL_CHOSEN | ||
| read -r -p "Do you want to delete the mailbox data as well (removing all mails)? [y/N] " MAILDEL_CHOSEN | ||
|
|
||
| # TODO: Why would MAILDEL be set to true if MAILDEL_CHOSEN is empty? | ||
| if [[ ${MAILDEL_CHOSEN} =~ (y|Y|yes|Yes) ]] || [[ -z ${MAILDEL_CHOSEN} ]]; then | ||
| MAILDEL=1 | ||
| fi | ||
| # Delete mailbox data only if the user provides explicit confirmation. | ||
| [[ ${MAILDEL_CHOSEN,,} == "y" ]] && MAILDEL=1 | ||
| fi | ||
| } | ||
|
|
||
|
|
@@ -103,10 +105,10 @@ function _remove_maildir() { | |
| local DOMAIN_PART="${MAIL_ACCOUNT#*@}" | ||
| local MAIL_ACCOUNT_STORAGE_DIR="/var/mail/${DOMAIN_PART}/${LOCAL_PART}" | ||
|
|
||
| [[ ! -d ${MAIL_ACCOUNT_STORAGE_DIR} ]] && _exit_with_error "Mailbox directory '${MAIL_ACCOUNT_STORAGE_DIR}' does not exist" | ||
| [[ ! -d ${MAIL_ACCOUNT_STORAGE_DIR} ]] && _exit_with_error "Mailbox data directory '${MAIL_ACCOUNT_STORAGE_DIR}' does not exist" | ||
|
|
||
| _log 'info' "Deleting Mailbox: '${MAIL_ACCOUNT_STORAGE_DIR}'" | ||
| rm -R "${MAIL_ACCOUNT_STORAGE_DIR}" || _exit_with_error 'Mailbox could not be deleted' | ||
| _log 'info' "Deleting mailbox data: '${MAIL_ACCOUNT_STORAGE_DIR}'" | ||
| rm -R "${MAIL_ACCOUNT_STORAGE_DIR}" || _exit_with_error 'Mailbox data could not be deleted' | ||
| # Remove parent directory too if it's empty: | ||
| rmdir "/var/mail/${DOMAIN_PART}" &>/dev/null | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the
,,portion meant to do?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes the var value lowercase.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fun π
While a bit more verbose, this is the equivalent with Nu:
Container example:
More fleshed out example
Similar to a previous example I shared in the past to compare to Bash, here's what some more NuShell looks like (I'm still not really sold on it, has some good/bad aspects π )
Some relevant NuShell doc links if you're interested