37.13. Creating Filter Aliases

Sendmail aliases normally forward email messages to their destinations regardless of their content. It is possible, however, to use this Webmin module to create an alias that forwards to different addresses or files depending on the headers or body of a message sent to it. When you create an alias like this, the module internally creates a script that passes the contents of email to the alias as input, just like a command specified using the Feed to program alias type.

A filter consists of a series of rules, each of which has a condition and action. The condition specifies both a header and text to check if it is contained in that header, while the action specifies an address to which to forward or a file to which to append the message. When a message is received by the filter, it is checked against the rules, in order, until one that matches is found and its action is performed. At the end of the list is a default action, which determines where to forward email that does not match any of the conditions.

Compared to other mail filtering or classification programs like Procmail and SpamAssassin, Webmin's filters are limited in their functionality and flexibility. They are easy to create, however, and require no additional software. To create one, the steps to follow are:

1.
On the module's main page, click on the Mail Aliases icon.

2.
In the Create Alias form, enter a name for the alias and select Apply filter file from the type menu. The alias name can be that of an existing UNIX user if you want to filter his email before delivery.

3.
In the field next to the type menu, enter the path to a file that will contain the filter rules, such as /home/someuser/filter.rules. Because the file format is fairly complex, you should not enter the name of any existing file unless it was created by following these same steps.

4.
Click the Create button to add the alias, and then click on its name in the list to edit again.

5.
Follow the Edit link next to the filter rules file field. This will take you to the form shown in Figure 37.5, which contains a table of empty rows for entering new rules and a text field for the default action address.

Figure 37.5. The filter creation form.


6.
In the first row, select the header on which you want to filter from the menu next to If the. To check the entire undecoded email body, select body from the list instead.

To have the action performed if some text is found in the header or body, select matches from the second menu. To perform the action only when some text is not found, choose doesn't match, instead.

In the field next to this menu, enter the text for which the filter should check the header or body. The comparison will always be case insensitive, and Perl regular expression characters like [, ., +, and * can be used.

In the then forward to field, enter the email address or mailbox name to which messages matching the condition that you specified will be sent. It is also possible to enter an absolute file path like /home/someuser/mail/somefolder to which email will be appended instead. This could be another user's mail file, or a mail folder—however, it must be writable by the UNIX user daemon as whom Sendmail runs.

7.
To enter another rule, fill in the second blank row by repeating the instructions in Step 6 again. Only five empty rows are displayed, but you can create more than five rules by saving and re-editing the filter file.

8.
In the Otherwise forward to field at the bottom of the table, enter an address or filename to which messages that do not match any of the rules will be sent or appended. If this is left blank, unmatched email will be thrown away!

9.
Finally, click the Save button to activate the new filter rules. To make sure they are really working, you should send a few text messages to the alias and check to see that they are delivered correctly.

To have email forwarded to multiple addresses by a single rule or the default action, just enter them separated by commas into one of the forward to fields. You can also enter the name of another alias as the destination, which can then send messages to multiple files, addresses, and/or programs.

When creating a filter alias with the same name as a UNIX user, it is often useful to specify that messages matching some rule be delivered to the user's normal mailbox. Just entering the user's name as the destination, however, would be a big mistake as this would trigger an endless loop through the filter! Instead, you should prepend a backslash to the username—like jcameron. As with aliases, this tells Sendmail to ignore any aliases for this mailbox.

Because it can often be difficult to work out what a filter alias is doing and why it is doing it, the filter script creates a log file in the same directory as the rules file. The log has the same name as the filter file, but with .log appended. Every message received by the alias and delivered to some destination by the filter causes a line to be added to the log, containing the date, time, sender, destination, and rule matched. The log file will only be created if the directory or log itself is writable by the daemon user, though.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.54.7