Make deletion of mailbox data opt-in#4365
Merged
casperklein merged 5 commits intodocker-mailserver:masterfrom Feb 16, 2025
Merged
Make deletion of mailbox data opt-in#4365casperklein merged 5 commits intodocker-mailserver:masterfrom
casperklein merged 5 commits intodocker-mailserver:masterfrom
Conversation
polarathene
reviewed
Feb 16, 2025
| MAILDEL=1 | ||
| fi | ||
| # Delete mailbox data only if the user provides explicit confirmation. | ||
| [[ ${MAILDEL_CHOSEN,,} == "y" ]] && MAILDEL=1 |
Member
There was a problem hiding this comment.
What's the ,, portion meant to do?
Member
There was a problem hiding this comment.
Fun 😒
While a bit more verbose, this is the equivalent with Nu:
if ($MAILDEL_CHOSEN | str downcase) == 'y' { $MAILDEL = true }Container example:
$ docker run --rm ghcr.io/nushell/nushell -c 'mut MAILDEL_CHOSEN = "Y" ; print ($MAILDEL_CHOSEN | str downcase)'
yMore 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 😅)
#!/usr/bin/env nu
# Implicit default method run:
def main [] {
print "this is setup CLI"
}
# Subcommand (see usage example below),
# also implicitly has `--help` generated `email del --help` (can be improved)
# Args are between the [], a bool flag with long and short forms,
# and spread syntax to indicate the rest of the CLI args will be collected as a list variable
def "main email del" [--yes (-y), ...accounts] {
# `let` is immutable (read-only) after assignment
let force_skip = $yes
# `mut` allow updating the variable after assignment
mut should_delete = false
if not $force_skip {
print 'Do you want to delete the mailbox data as well (removing all mails)? [y/N]'
# Read the next input from the user, lowercase it and compare to get true/false:
# `--numchar 1` is like `read -n 1` stopping after the first char input from the user.
# `--suppress-output` so regardless of char when input is not `y`, we later print `no`.
$should_delete = (input --numchar 1 --suppress-output | str downcase) == 'y'
# Alternative that provides an interactive prompt and converts selection to boolean:
# https://github.com/nushell/nushell/issues/15124
#$should_delete = try { (['no', 'yes'] | input list --index | into bool) } catch { false }
# Formats the bool result as yes/no for optionally logging to stdout:
print (if $should_delete { 'yes' } else { 'no' })
}
# Iterate through the array of 1 or more accounts:
for account in $accounts {
if $should_delete { delete_mailbox $account }
}
}
# Pretend this has full functionality of `_remove_maildir()` :)
def delete_mailbox [account: string] {
# This variable will split the email address at `@` into subfields `.local` + `.domain`:
let mail_parts = ($account | split column --number 2 '@' local domain | first)
let mailbox_path = $"/var/mail/($mail_parts.domain)/($mail_parts.local)"
print $"Deleting Mailbox: '($mailbox_path)'"
}$ ./setup.nu email del [email protected]
Do you want to delete the mailbox data as well (removing all mails)? [y/N]
yes
Deleting Mailbox: '/var/mail/example.test/john.doe'Some relevant NuShell doc links if you're interested
- https://www.nushell.sh/book/working_with_strings.html
- https://www.nushell.sh/commands/categories/strings.html
- https://www.nushell.sh/commands/docs/str_downcase.html
- https://www.nushell.sh/commands/docs/input.html
- https://www.nushell.sh/commands/docs/split_column.html
- https://www.nushell.sh/book/cheat_sheet.html#variables
- https://www.nushell.sh/commands/
- https://www.nushell.sh/book/thinking_in_nu.html#nushell-isn-t-bash
- An issue of mine with some basic examples / insights for prompting input
polarathene
approved these changes
Feb 16, 2025
georglauterbach
approved these changes
Feb 16, 2025
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Fixes #4338
Type of change
Checklist
docs/)CHANGELOG.md