Repository: Mailu/Mailu

Issue:
[Enhancement] List of previously used addresses/aliases to block accidental reuse and privacy implications
I did search for existing issues first. Not quite sure how this feature would be worded so I may have missed a discussion.

I propose a simple feature, definitely easily overrideable if need be and with a toggle to turn it off, that permanently keeps track of used addresses so you cannot accidentally reuse a previously used one and leak data.

Address reuse is a problem for obvious reasons:
- intermingling different identities
- therefore leaking private information 

Storing the addresses can be done privacy friendly: simply store exclusively the address itself, no metadata.

On a side note: Deleting accounts does not delete the actual folders. I am doing this manually so far, but it'd be nice if *delete* actually meant *delete*.

As usual I have to praise how well Mailu works in general. I realized I've been using it for years now, and apart from some inconveniences like this or #1700 #1328 there hasn't been an issue, and it's more lightweight than the competitors. I wish you all the best!


Discussion:
If I understand you correctly, deleting an user in the web administration GUI does not delete the mail folders of the user.
When you create a new user with the same user name (same email address), then this user sees the mail box of the deleted user.  For me this sounds as a bug./

The enhancement request is clear for me. This should be configurable via the GUI or via mailu.env.
Yes, it does not delete the folders/data.

I did not check if you would see the content of the previous user, that'd be quite a grave bug indeed. I simply meant reusing addresses means that addresses could in the future receive data meant for the previous user. That's why pretty much every mailprovider blocks it.

I suggest:
- having an option to keep a list of all addresses that ever existed
- when creating a new inbox that matches, showing a warning, but having an option to override this as domain administrator if need be (deleting and recreating postmaster@ should be easy for instance)
Mailu still does not remove deleted user data, or block/warn of address reusage for the record. You have to keep your own list and delete the folder in `/mail`.

Edit: Here it leaves traces as well:

`mailu/webmail/_data_/_default_/storage/cfg`

Resolving patch:
diff --git a/core/admin/mailu/manage.py b/core/admin/mailu/manage.py
--- a/core/admin/mailu/manage.py
+++ b/core/admin/mailu/manage.py
@@ -304,6 +304,7 @@ def config_update(verbose=False, delete_objects=False):
                 if verbose:
                     print(f'Deleting domain: {domain.name}')
                 db.session.delete(domain)
+
     db.session.commit()
 
 
@@ -351,7 +352,7 @@ def config_import(verbose=0, secrets=False, debug=False, quiet=False, color=Fals
             raise click.ClickException(msg) from exc
         raise
 
-    # don't commit when running dry
+    # do not commit when running dry
     if dry_run:
         log.changes('Dry run. Not committing changes.')
         db.session.rollback()
@@ -403,13 +404,16 @@ def config_export(full=False, secrets=False, color=False, dns=False, output=None
 
 @mailu.command()
 @click.argument('email')
+@click.option('-r', '--really', is_flag=True)
 @with_appcontext
-def user_delete(email):
-    """delete user"""
-    user = models.User.query.get(email)
-    if user:
-        db.session.delete(user)
-    db.session.commit()
+def user_delete(email, really=False):
+    """disable or delete user"""
+    if user := models.User.query.get(email):
+        if really:
+            db.session.delete(user)
+        else:
+            user.enabled = False
+        db.session.commit()
 
 
 @mailu.command()
@@ -417,10 +421,9 @@ def user_delete(email):
 @with_appcontext
 def alias_delete(email):
     """delete alias"""
-    alias = models.Alias.query.get(email)
-    if alias:
+    if alias := models.Alias.query.get(email):
         db.session.delete(alias)
-    db.session.commit()
+        db.session.commit()
 
 
 @mailu.command()
diff --git a/core/admin/mailu/ui/views/users.py b/core/admin/mailu/ui/views/users.py
--- a/core/admin/mailu/ui/views/users.py
+++ b/core/admin/mailu/ui/views/users.py
@@ -80,19 +80,6 @@ def user_edit(user_email):
         domain=user.domain, max_quota_bytes=max_quota_bytes)
 
 
-@ui.route('/user/delete/<path:user_email>', methods=['GET', 'POST'])
-@access.domain_admin(models.User, 'user_email')
-@access.confirmation_required("delete {user_email}")
-def user_delete(user_email):
-    user = models.User.query.get(user_email) or flask.abort(404)
-    domain = user.domain
-    models.db.session.delete(user)
-    models.db.session.commit()
-    flask.flash('User %s deleted' % user)
-    return flask.redirect(
-        flask.url_for('.user_list', domain_name=domain.name))
-
-
 @ui.route('/user/settings', methods=['GET', 'POST'], defaults={'user_email': None})
 @ui.route('/user/usersettings/<path:user_email>', methods=['GET', 'POST'])
 @access.owner(models.User, 'user_email')


Test patch: