MDSORT.CONF(5)

NAME
mdsort.conf - mdsort configuration file

DESCRIPTION
mdsort.conf is the configuration file for mdsort(1).

Comments can be put anywhere in the file using a hash mark (‘#’) and extend to the end of the current line.

Macros can be define anywhere at the top level of the configuration. A macro name may only contain lowercase letters and must not conflict with reserved words. They can later be interpolated inside strings which are denoted as “string” in this manual.

    prefix = "~/Maildir"
    inbox = "${prefix}/INBOX"
    maildir "${inbox}" {
    	match date > 1 week move "${prefix}/Trash"
    }

The configuration may contain one or many maildir definitions. Each maildir is associated with a block of rules. For each message present in a maildir, each rule is evaluated in sequential order where the first matching rule is favored.

maildir
    “path” [options] {rule ...} A maildir rooted in path; mdsort(1) iterates over each message present in the cur and new directory. The options may be any combination of the following:

    sync
        Call fsync(2) after writing a new message.

stdin
    [options] {rule ...} Accepts a message from stdin. This type of maildir will only be evaluated if mdsort(1) is invoked with the stdin option. Accepts the same options as listed above with sync being implicitly enabled.

A rule is defined as follows:

match condition action ...
    A rule starts with the match keyword followed by a condition then actions to perform if the condition evaluates to true. Each rule spans to the end of the current line but can extended over multiple lines using a backslash (‘\’).

    A pattern used within a condition is interpreted as an extended regular expression. Subexpressions in pattern can be used to interpolate arguments to action. Referencing a subexpression is done using back-references on the form ‘\#’ where ‘#’ is a digit. The digit refers to the nth subexpression of pattern and will be replaced with the matched string. By default, subexpressions of the first matching pattern is used. Each pattern optionally accepts one or many of the following flags:

    f   Force usage of subexpressions from the corresponding pattern, as opposed of using the ones from the first matching pattern.

    i   Make pattern case insensitive.

    l   Lowercase the matched string from a subexpression before interpolation. Mutually exclusive with ‘u’.

    u   Uppercase the matched string from a subexpression before interpolation. Mutually exclusive with ‘l’.

    A pattern is by default expected to be enclosed in a pair of ‘/’ delimiters. A literal ‘/’ can be expressed as ‘\/’ inside a pattern. However, any character can be used as the delimiter and same escaping principle also applies.

    The conditions are as follows and may be negated:

    []! [attachment] body /pattern/[flags] Evaluates to true if the message body matches pattern.

        If attachment is present, evalutes to true if the body of an attachment matches pattern.

    []! [attachment] header “name” /pattern/[flags]

    []! [attachment] header { “name” ... } /pattern/[flags] Evaluates to true if the value of any of the headers with name in message matches pattern. Finding the header with name in message is done case insensitive.

        If attachment is present, evalutes to true if any of the headers with name in an attachment matches pattern.

    []! attachment Evaluates to true if the message has attachments.

    []! date [field] > age scale

    []! date [field] < age scale Evaluates to true if the message date field is either greater or less than age. The field must be either header, access, modified or created and defaults to header in which the date header in message is used. The age must be a positive number. The scale must be either seconds, minutes, hours, days, weeks, months or years. It may be abbreviated in a non-ambiguous way, such as second or s.

    []! all Evaluates to true for any message.

    []! new Evaluates to true if the message is not read.

    []! old Evaluates to true if the message is old. Meaning, a message that has been read but later flagged as not read.

    Multiple and nested conditions may also be specified:

    condition and condition
        Evaluates to true if both condition are true.

    condition or condition
        Evaluates to true if any of the condition are true.

    []! (condition) Evaluates to true if the nested condition is true.

    Next comes one or many actions:

    break
        Abort evaluation of the current block of rules. Especially useful when using nested match blocks, see below.

        Mutually exclusive with all other actions.

    exec
        [options] “command”

    exec
        [options] { “command” ... } Execute command, which may contain back-references. The options may be any combination of the following:

        stdin
            Pass the matched message on stdin to command.

    discard
        Remove the message from the maildir.

        Mutually exclusive with all other actions.

    flag [!] new
        Flag the message as read or not.

    label “label”

    label { “label” ... }
        Add label to the X-Label header in message. The label may contain back-references.

    move “path”
        Move the message to the maildir located at path. The path may contain back-references.

        Only one move action can be defined per rule.

    pass
        Continue evaluation of the current block of rules up to the next matching rule.

    In addition, stdin also supports the following actions:

    reject
        Reject the message by causing mdsort(1) to exit non-zero.

        Mutually exclusive with all other actions.

match condition { rule ... }
    The nested block of rules is only evaluated if condition is true.

FILES

~/.mdsort.conf
    The default configuration file.

EXAMPLES

    inbox = "~/Maildir/INBOX"
    maildir "${inbox}" {
    	# Move messages from OpenBSD mailing lists into dedicated directories.
    	match header { "Cc" "To" } /(bugs|misc|ports|tech)@openbsd.org/i \
    		move "~/Maildir/openbsd-\1"
    	# Label messages with the plus portion of the address.
    	match header "To" /user\+(.+)@example.com/l label "\1"
    	# Archive read messages.
    	match ! new move "~/Maildir/Archive"
    }
    maildir "~/Maildir/Trash" {
    	# Delete messages older than 2 weeks.
    	match date > 2 weeks discard
    }
    # Accept messages from stdin and move to the invoking user's inbox.
    stdin {
    	match all move "${inbox}"
    }

SEE ALSO
mdsort(1), re_format(7)

AUTHORS
Anton Lindqvist <anton@basename.se>