MDSORT.CONF(5) File Formats Manual MDSORT.CONF(5)

mdsort.confmdsort configuration file

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 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.

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.

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.

path” { rule ... }
 
{ path ... } { rule ... }
A maildir rooted in path; mdsort(1) iterates over each message present in the cur and new directory.
{ 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:

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:

[!]
Evaluates to true for any message.
[!] /pattern/[flags]
Evaluates to true if the message body matches pattern.
[!] command
 
[!] command {command... }
Evaluates to true if command exits zero. The command is interpolated.
[!] [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.
 
[!] 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.
[!] path
Evaluates to true if path refers to an existing directory. The path is interpolated.
[!]
Evaluates to true if the message is not read.
[!]
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
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:

name” “value
Add header with name and value, unconditionally replacing any existing header with the same name. The value is interpolated.
{ rule ... }
Evaluate the nested block of rules on each attachment in message. The only available action in rule is exec.
Abort evaluation of the current block of rules. Especially useful when using nested match blocks, see below.
[options] “command
 
[options] {command... }
Execute command, which is interpolated. The options may be any combination of the following:
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.
Remove the message from the maildir.

Mutually exclusive with all other actions.

[!] new
Flag the message as read or not.
flags
Flag the message with each character in flags.
label
 
{label... }
Add label to the X-Label header in message. The label is interpolated.
path
Move the message to the maildir located at path. The path is interpolated.
Continue evaluation of the current block of rules up to the next matching rule.

In addition, stdin also supports the following actions:

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

Mutually exclusive with all other actions.

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

~/.mdsort.conf
The default configuration file.

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}"
}

mdsort(1), re_format(7)

Anton Lindqvist <anton@basename.se>

March 17, 2018 OpenBSD 7.5