NAME
mdsort.conf
—
mdsort configuration file
DESCRIPTION
mdsort.conf
is the configuration file for
mdsort(1). The manual is divided into the sections as follows:
- MACROS
- Macros may be defined and used later, simplifying the configuration file.
- PATTERNS AND INTERPOLATION
- Description of patterns expressed as regular expressions and how they can be used for interpolation.
- CONFIGURATION
- Configuration 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
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, such as maildir
. They
can later be interpolated inside strings.
- macro = “value”
- Define a macro named macro with a corresponding value.
PATTERNS AND INTERPOLATION
A pattern used within a
condition is interpreted as an extended regular
expression. Subexpressions in pattern can be used to
interpolate certain configuration arguments. 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.
The subexpressions of the first matching pattern
within a match
rule is used. Referrencing the
subexpressions of a specific pattern can be done using
the second form ‘\#.#’ where the first digit refers to the nth
pattern and the second digit the nth
subexpression.
Each pattern optionally accepts one or many of the following flags:
- 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.
Macros may also be interpolated inside strings on the form “${macro}” where macro is a defined macro.
In addition, the following macros are available in action:
- path
- Expands to the path of the matched message.
CONFIGURATION
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” { rule ... }maildir
{ path ... } { rule ... }- A maildir rooted in path; mdsort(1) iterates over each message present in the cur and new directory.
stdin
{ rule ... }- Accepts a message from stdin. This type of maildir will only be evaluated if mdsort(1) is invoked with the stdin option.
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.The conditions are as follows and may be negated:
- [
!
]all
- Evaluates to true for any message.
- [
!
]body
/pattern/[flags] - Evaluates to true if the message body matches pattern.
- [
!
]command
“command” - [
!
]command
{ “command” ... } - Evaluates to true if command exits zero. The command is interpolated.
- [
!
]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
orcreated
and defaults toheader
in which the date header in message is used. The age must be a positive number. The scale must be eitherseconds
,minutes
,hours
,days
,weeks
,months
oryears
. It may be abbreviated in a non-ambiguous way, such assecond
ors
. - [
!
]header
“name” /pattern/[flags] - [
!
]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.
- [
!
]isdirectory
“path” - Evaluates to true if path refers to an existing directory. The path is interpolated.
- [
!
]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:
attachment
condition- Evaluates to true if any attachment in the message matches condition.
- 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:
add-header
“name” “value”- Add header with name and value, unconditionally replacing any existing header with the same name. The value is interpolated.
attachment
{ rule ... }- Evaluate the nested block of rules on each attachment in message. The
only available action in rule is
exec
. break
- Abort evaluation of the current block of rules. Especially useful when
using nested
match
blocks, see below. exec
[options] “command”exec
[options] { “command” ... }- Execute command, which is interpolated. The
options may be any combination of the following:
stdin
- Pass the matched message on stdin to command.
body
- While used in combination with
stdin
, only the body of the matched message is passed on stdin.
discard
- Remove the message from the maildir.
Mutually exclusive with all other actions.
flag
[!
]new
- Flag the message as read or not.
flags
“flags”- Flag the message with each character in flags.
label
“label”label
{ “label” ... }- Add label to the X-Label header in message. The label is interpolated.
move
“path”- Move the message to the maildir located at path. The path is interpolated.
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" # Conditionally move to a maildir named after the plus portion of the # address. match header "To" /user\+(.+)@example.com/l and isdirectory "~/Maildir/\1" move "~/Maildir/\1" # Extract calendar attachments. match all attachment { match header "Content-Type" |text/calendar| exec stdin body "icalendar2calendar" } # Archive read messages. match ! new move "~/Maildir/Archive" } maildir { "~/Maildir/Junk" "~/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
AUTHORS
Anton Lindqvist <anton@basename.se>