imap-rules 0.2.1

A utility for running rules against an IMAP server
imap-rules-0.2.1 is not a library.

IMAP rules

This is a command-line utility that can run simple rules against an IMAP server. Run it as a once-off, or schedule it to run more frequently.

Usage

cargo run -- --help                           # Show usage instructions
cargo run -- rules.toml --dry-run             # Describe what would happen
cargo run -- rules.toml --describe            # List all folders and flags
cargo run -- rules.toml --rule-name inbox     # Run only a specific rule
cargo run -- rules.toml                       # Actually run

How does it work?

The program reads your config file which contains any number of rules. These rules contain filters (folder, min age, read status) and action (delete, move, purge)

What do rules look like?

Rules describe what messages they should search for, and what should happen with them. Rules can move messages to trash or any other folder.

Rules have the following properties:

Property description default
path IMAP folder name required
min_age Only affect messages older than given number of days required
include_unread Also affect unread messages false
include_flagged Also affect flagged messages false
action What to do with the message required
move_target Where to move the message if action is move required if action is move

actions

  • move - Move the messages to the folder in move_target
  • trash - Move messages to the trash folder
  • purge - Permanently delete messages

Examples

[rules]
[rules.inbox]
path = "Inbox"          # Search inbox for messages
min_age = "28d"         # Only messages older than 28 days
include_unread = false  # Only read messages
action = "move"         # Move to a different folder
move_target = "Archive.auto_expire"  # Move to this folder

[rules.auto_archive]
path = "Archive.auto_expire"
min_age = "180d"        # Only include messages older than 180 days
include_unread = true   # Also include unread messages
action = "trash"        # Move messages to trash

[rules.cleanup_spam]
path = "Junk"
min_age = "30d"
include_unread = true
action = "purge"        # Permanently delete messages

Here you can see that you can combine rules by moving messages between folders. In the example, we move all read messages from the inbox to Archive/auto_expire after 28 days. Then messages in that folder are deleted after 180 days.