The mdsort(1) utility moves messages from one maildir to another according to a set of rules expressed in the mdsort.conf(5) format.
Example configuration:
$ cat ~/.mdsort.conf
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-\e1"
# Label messages with the plus portion of the address.
match header "To" /user\e+(.+)@example.com/l label "\e1"
# Conditionally move to a maildir named after the plus portion of the
# address.
match header "To" /user\e+(.+)@example.com/l and
isdirectory "~/Maildir/\e1"
move "~/Maildir/\e1"
# 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
}
Invoking
mdsort(1)
with the -d
option shows which messages would be moved and why, leaving the
maildir(s) unchanged:
$ mdsort -d
/home/anton/Maildir/INBOX/new/1521917775.89020_21.host -> /home/anton/Maildir/mdsort/new
~/.mdsort.conf:3: From: Charlie Root <[email protected]>
^ $
~/.mdsort.conf:4: Subject: mptre commented on pull request mptre/mdsort#1337
^ $
In addition, mdsort(1) can also act as a MDA reading messages from stdin:
$ cat ~/.mdsort.conf
stdin {
match all move "~/Maildir/INBOX"
}
$ mdsort - <message
# pkg_add mdsort
The installation prefix defaults to /usr/local
and can be altered using the
PREFIX
environment variable when invoking configure
:
$ ./configure
$ make
$ make install
Copyright (c) 2018-2024 Anton Lindqvist. Distributed under the MIT license.