Skip to content

Roundcube duplicates removal.

Core assumptions

  • Maildir format (cur/, new/, tmp/)

  • 1 file = 1 email

  • Never touch tmp/

Scan phase

  • Accept mailbox path as argument

  • Scan cur/ (optionally new/)

  • Ignore non-regular files

  • Read filename metadata (S=, W=, flags) for stats only

Index phase

  • For each file, record:

    • full path

    • file size (stat)

    • content hash (MD5 or SHA-256)

  • Write everything to an index file (CSV / TSV / JSON)

Analysis phase

  • Group by hash

  • Hash groups with count > 1 = real duplicates

  • Decide one keeper per hash group

Action phase (safe by default)

  • Dry-run default

  • Optional modes:

    • move duplicates to quarantine

    • copy duplicates to quarantine

  • Quarantine folder outside Maildir

Safety rules

  • Never delete directly

  • Never act on size alone

  • Verify destination exists and is writable

  • Log every action

Performance

  • Group by size first, hash only same-size files

  • Progress output (files/sec)

  • Resume support (skip already indexed files)

UX / CLI

  • Clear summary:

    • total mails

    • duplicates found

    • space reclaimable

  • Flags:

    • --dry-run

    • --move

    • --hash md5|sha256

    • --include-new

Portability

  • No root required

  • Core Perl modules only

  • UTF-8 safe filenames

Exit criteria

  • Mailbox content unchanged unless explicitly told

  • Re-runnable without side effects

That design will work on any Maildir mailbox, cPanel or not, safely.