Skip to content

sburina/imap-retention

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IMAP Retention

Delete old messages from one or more IMAP accounts based on per-folder criteria:

  • days:N — delete messages older than N days
  • last:N — keep only the last N messages

Starred (flagged) messages are never deleted.

Requirements

  • PHP >= 7.4
  • PHP imap extension

Note: The ext-imap extension is deprecated as of PHP 8.4 and will be removed in a future PHP version. A migration path will be evaluated when that happens.

Installation

Copy the included imap_maint_config_example.php to imap_maint_config.php and add your IMAP account details. You can configure as many accounts and folders as you like.

Keep your credentials secure:

chmod 0600 imap_maint_config.php

For details on the mailbox parameter format, see the PHP imap_open documentation.

Usage

# Normal run (e.g. from cron)
./imap_maint.php

# Preview what would be deleted, without deleting anything
./imap_maint.php --dry-run

# Show per-message details during deletion
./imap_maint.php --verbose

# Show help
./imap_maint.php --help

Cron

Run daily as a cron job. The script connects to IMAP servers remotely, so any host with PHP and shell access will work:

30 7 * * *  /path/to/imap_maint.php

Output is timestamped for log readability. The exit code is 0 on success, 1 if any account or folder had errors.

License

Released under the MIT License. See the bundled LICENSE file for details.

About

Remote IMAP Account Folders Maintenance - Retention

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages