Skip to content

Conversation

@drsound
Copy link

@drsound drsound commented Apr 21, 2025

Adds a Python script to expunge old emails from specified mailboxes (e.g., Trash, Junk) and remove empty subfolders. Supports single-user, all-user, and dry-run modes.

Contribution Guidelines

What does this PR include?

Short Description

Adds a Python script (mailbox_cleaner.py) located in helper-scripts/ designed to automatically clean up old emails from specified mailboxes (defaults to Trash, Junk) for single or all users in a Mailcow installation. It includes features like configurable retention days, dry-run mode, and automatic deletion of empty subfolders within the target mailboxes. Intended for cron job execution.

Affected Containers

  • None (This PR only adds the script to the repository structure; it does not modify any existing container images or configurations.)

Did you run tests?

What did you tested?

  • Tested script execution with Python 3.x.
  • Tested against a live Mailcow instance.
  • Validated --user <email> argument for single-user processing.
  • Validated --all argument for multi-user processing.
  • Validated --dry-run functionality (logs actions without performing them).
  • Tested default --days-back 30 and custom values.
  • Tested default mailboxes (Trash, Junk) and custom --mailboxes argument.
  • Verified correct identification and processing of target mailboxes and their subfolders.
  • Verified expunge logic based on savedbefore <days>d.
  • Verified deletion logic for empty subfolders within target mailboxes.
  • Verified that non-empty subfolders and top-level standard folders are not deleted.
  • Checked standard and --debug logging output.

What were the final results? (Awaited, got)

  • Awaited: Script correctly identifies target mailboxes/users, simulates actions in dry-run, expunges emails older than the specified period, and deletes empty subfolders under target mailboxes in normal mode.
  • Got: The script performed exactly as awaited in all tested scenarios. Dry-run accurately predicted changes. Normal execution successfully cleaned up old emails and empty specified subfolders without affecting other data. Logs provided clear information.

Adds a Python script to expunge old emails from specified mailboxes (e.g., Trash, Junk) and remove empty subfolders. Supports single-user, all-user, and dry-run modes.
Copy link
Member

@DerLinkman DerLinkman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

@drsound drsound requested a review from DerLinkman May 11, 2025 09:12
@drsound
Copy link
Author

drsound commented May 11, 2025

Search & replace done! :-)

@FreddleSpl0it FreddleSpl0it added the neverstale Bot doesn't mark the issue or PR as stale label May 12, 2025
@DerLinkman DerLinkman requested review from FreddleSpl0it and removed request for DerLinkman May 28, 2025 14:31
@drsound
Copy link
Author

drsound commented Jun 19, 2025

Hi, this PR seems stale. Is any additional action required from my side?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

neverstale Bot doesn't mark the issue or PR as stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants