[FrontPage] [TitleIndex] [WordIndex]

FilterSpecification

TMDA Filter Specification

TMDA filter files are used to control mail both coming in to and going out of TMDA. For incoming, the filter controls how the message is disposed of. For outgoing, it controls how the message is tagged. The incoming filter file default is ~/.tmda/filters/incoming, which can be changed by setting FILTER_INCOMING in your ~/.tmda/config. The outgoing filter file default is ~/.tmda/filters/outgoing, which can be changed by setting FILTER_OUTGOING.

Format of Filter Files:

A filter file is composed of filters, blank lines and comments. For ease of organization, macros, variable interpolation and the ability to include other filter files are supported. These features are documented below in the Additional Features section.

Each filter in a filter file is expected to be a string containing three fields separated by whitespace. Each filter may be placed on a single line or may be spread over several lines, to increase readability. You must follow a few rules when formatting your filters.

The filter file is read sequentially from top to bottom. The first filter that matches is used. The three fields in a filter are:

* source: specifices the source of the match.

Some sources take optional arguments. An argument begins with a dash (-). Some arguments take options. If an argument takes an option, the argument is followed immediately by an equals sign (=) and the option. No whitespace is allowed on either side of the equals sign.

Single arguments look like this:

Sources are documented here along with any optional arguments and the expected match field.

* match: should be an expression, or the full path to a textfile, CDB database, or DBM database containing more expressions if source was suffixed with -file', -cdb', or `-dbm'.

The match expression and the contents of the textfile vary based on the source. For an explanation of the match field expected for a given source, see FilterSources.

The second field within a textfile, CDB or DBM is optional, but overrides action if present. e.g,

DBM support comes with your Python interpreter, but CDB support currently requires that you first install the python-cdb extension module.

The printcdb/printdbm scripts in the contrib directory can be used to print the contents of CDB/DBM files in TMDA-list format.

* action: action specifies what action to take on the message. An optional '''=''' separates the action from the action's option. Possible values differ based on whether the message is incoming or outgoing.

(for incoming, action can be one of):

The template option to bounce,reject and confirm can be used to bounce or confirm the message using a specific template file rather than the default (bounce.txt or confirm_request.txt). The option can be an absolute pathname to the template file (e.g, /path/to/template.txt). Pathnames starting with a tilde will be expanded. It can also be a relative pathname, in which case the template will be searched f or under TEMPLATE_DIR as described in TemplateHowto.

The instruction option to ok,accept,deliver can be used to short-circuit the default delivery method by delivering the message to a specific location. Delivery to qmail-style Maildirs, mboxrd-format mboxes,programs (pipe), and different e-mail addresses are supported.

instruction:

format:

examples:

program (pipe)

A program instruction begins with a vertical bar. The rest of the line will be passed to /bin/sh. Whitespace and shell variables (i.e, $HOME and ~) are allowed.

deliver=|/usr/ucb/vacation jason
deliver=| /usr/bin/maildrop $HOME/.mailfilter

forward

A forward instruction begins with an ampersand. If the address begins with a letter or number, you may leave out the ampersand.

deliver=&johndoe@new.job.com
deliver=janedoe@new.isp.net

mmdf

An mmdf instruction begins with a colon. Please note the following restrictions below.

deliver=:/home/jason/Mailbox
deliver=:~/Mailbox 

mbox

An mbox instruction begins with a slash or tilde, and does not end with a slash. Please note the following restrictions below.

deliver=/home/jason/Mailbox
deliver=~/Mailbox 

maildir

A maildir instruction begins with a slash or tilde and ends with a slash. Please note the following restrictions below.

deliver=/home/jason/Maildir/
deliver=~/Maildir/

Please note the following restrictions to mmdf, mbox and Maildir delivery:

(for outgoing, action can be one of):

For all of the outgoing actions except tag, the tag applies to both the From: (or Resent-From:) header and the envelope sender. Both will be set to the same address.

The tag action is a little more flexible, in that it can be used to tag more than one header and each header can be tagged with a different address. The tag syntax is as follows:

Any of the to* or from* sources may be used. The <match> is explained in FilterSources. The <match> is followed by the keyword tag which is followed by a list of header/action pairs.

The header is the name of the RFC822 header field you want to tag, usually From: or Reply-To:. When you specify the header name, do not include the colon (''':'''). Use envelope to tag the envelope sender.

The action is any one of the outgoing actions from the list above (except tag, of course). That action will be used to tag the specified header only. If the specified action is not one from the list above, the action is inserted verbatim as a string. This can be used to add arbitrary headers to your outgoing messages based on destination. Quotes are required for text that includes whitespace and are unnecessary for single word strings.

The tag action is especially useful for mailing lists. Here, the envelope sender is set to your subscription address but the From: header is set to a dated address, making it easy for list members to respond to you but greatly reducing the likelihood that spammers will be able to harvest and use the dated address before it expires.

In simple cases where you wish to tag the From: header and the envelope sender with the same address but tag Reply-To: differently, you may specify the From: header but not the envelope sender. TMDA will use address in the From: header as the envelope sender.

This will set both the From: header and the envelope sender to the same address (a sender address) based on the envelope sender of the list. Reply-To: will be dated to allow list members to reply to you.

Additional Features:

* Macros

A macro is, in its simplest form, a piece of text that is to be substituted for another piece of text, rather like a #define in C. Here's how to define a simple macro in a filter file.

Here's how to use that macro in a filter rule.

Before the filter parser attempts to parse a rule it performs a macro substitution pass on the text. The result of that substitution on the a bove example filter is this.

After the substitution is performed, the rule is parsed normally and any syntax errors are identified and logged as usual.

Macros may also take parameters. For example, assume that you always deliver list mail to a unique maildir per list. Here's a macro to help with that.

Here's how you might use it for the two TMDA mailing lists.

Expanding the above macros results in these rules.

Macros may refer to other macros but may not refer to themselves, even indirectly. In other words, if macro A refers to macro B, B may not refer to A. This will result in a parser syntax error.

Macros are not case-sensitive. Use case as you prefer to help clarify your filter files.

* Included Filters

Filter files may include the contents of other filter files. The included filter rules are placed inline right where they were included. This positioning is important to remember, since the first matching rule encountered is the one that will be applied to an incoming email.

A filter include statement looks like this.

If the -optional flag is specified, the parser will not raise an error if the file is missing. If you expect that the file will always be present and its absence would be an error, do not specify this flag! That way, the parser will log an error and defer the mail, so that you can fix the problem.

Filter includes may be nested; that is, the included filter file may include other filter files itself, and those files may also include other files. If a filter file tries to include one of the files that included it, however, an error will be logged and the mail will be deferred.

* Variable Interpolation

Filter files support variable interpolation or substitution, like the shell. A variable is recognized if it begins with a dollar sign and a left curly brace ('''${''') and ends with a right curly brace ('''}'''), like this: ${TMDADIR}.

A variable name is looked up first in the Defaults namespace (all of the configuration variables set in Defaults.py or your ~/.tmda/config) and then in the environment if it was not found in the Defaults namespace. If it is still not found, the parser generates an error and the mail is deferred. Variable names are case-sensitive.

Using variables may allow you to create a system-wide filter that users can modify by providing their own additions. A Python variable, such as 'username', would need to be set in the user's configuration file, like this.

Here's an extremely simple system-wide filter that uses the 'username' variable to include a user's filter.

If the 'foo' user chooses to create a whitelist and names it "whitelist.foo", it will automatically be included. Because of the use of the -o ptional flag, the file is not required.

Example Incoming Filter:

Example Outgoing Filter:

A set of starter filter files are included in the TMDA distribution (tarball) within the contrib/dot-tmda subdirectory.


2007-02-24 17:18