You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
Sophie Hirn c74fbcb4cc Improved matching. 3 years ago
LICENSE initial commit 7 years ago
README.md Improved matching. 3 years ago
mdod.sh Improved matching. 3 years ago

README.md

maildir-ocd-daemon (mdod)

mdod sorts your local maildir-formatted mail boxes. Everything you need to know about the maildir format.

Usage

Either:

  • Create the file $HOME/.config/mail_rules.sh and put all rules in there. Call mdod.sh without arguments.

  • Create one file for each mailbox and call mdod.sh <file>. Alternatively, put #!/path/to/mdod.sh on the first line of each rules file and execute it directly.

As all files are bash scripts, writing your own plugins should be easy.

Commands

  • box <dirname>: Switch to the mail account located at the specified folder.

  • maildir_mode { cur | new | tmp }: Operate only on these maildir folders. Don’t use tmp unless you know exactly what you’re doing. I’d recommend maildir_mode new if performance is a concern and maildir_mode cur new otherwise.

  • daemon: Switch to daemon mode, re-executing the script at regular intervals.

  • refresh <seconds>: When in daemon mode, re-execute after the given amount of seconds.

  • match <directory> <matcher> <matcher parameter> <action> [<action parameter>]: Run <matcher> <file name> <matcher parameter> for each mail in <directory> (relative to the path selected by box). If the matcher returns zero, run <action> <file name> <action parameter>.

  • match_all <dir> <matcher1> <matcher1 param> [<...>] -- <action> [<action parameter>]: Similar to match, but all matchers need to return zero for <action> to be executed. Aborts after the first matcher returns a nonzero value, therefore it might pay off to order the checks based on complexity.

Matchers

All matchers take PCREs that match on the entire header line.

  • subject <regex>

  • from <regex>

  • to <regex>

  • cc <regex>

  • bcc <regex>

  • involves <regex> (Matches if from to, cc or bcc matches)

  • return_path <regex>

These matchers take a date(1) compatible date string.

  • newer_than <date>

  • older_than <date>

Actions

  • move <target dir>: Move the matched mail into <target dir>, relative to the mail box root specified by box. Will automatically append new/tmp/cur to the path.

Example Config

#!/bin/bash

# Run as a daemon, once every 10 seconds.
daemon
refresh 10

# Operate on both maildir directories
maildir_mode new cur


# Sort mail
box "/home/boonami/.mail/sophie.hirn@wyvernscale.com"
match "INBOX" to "list" move "INBOX/Lists"

box "/home/boonami/.mail/boonami@wyvernscale.com"
match "INBOX" to "list" move "INBOX/Lists"