Recipe 6.7 Filtering Local Mail with procmail

Problem

You want to filter mail with procmail before making deliveries to local users.

Solution

Add the local_procmail feature to the sendmail configuration, placing the FEATURE macro after the OSTYPE macro and before the MAILER(`local') line in the master configuration file. Values for the local mailer are usually set in the OSTYPE file. Carefully review the file for your operating system. Add the local_procmail feature to your master configuration file only if local_procmail is not already included in the OSTYPE file.

Create an /etc/procmailrc file containing the filters you want to apply to local mail.

Build and install the new configuration, as described in Recipe 1.8.

Discussion

The linux.m4 OSTYPE file contains the local_procmail feature because procmail is the local mailer used by default on most Linux systems. On a Linux system, just running a configuration that uses the linux.m4 OSTYPE file is sufficient for this recipe. Other systems are not so easy. For example, assume you have a Solaris 8 system. The solaris8.m4 OSTYPE file uses the local_lmtp feature to set mail.local as the local mailer. To change the local mailer to procmail , override the local_lmtp feature by placing the local_procmail feature in the master configuration file. Here is an example based on the generic-solaris.mc file:

 VERSIONID(`Solaris with local_procmail added') OSTYPE(solaris2) DOMAIN(generic) dnl Add the local_procmail feature FEATURE(`local_procmail') MAILER(local) MAILER(smtp) 

Because the local_procmail feature occurs after the OSTYPE macro, it overrides the local_lmtp feature defined in the OSTYPE file. The local_procmail feature is enabled once the sendmail.cf file is built, copied to sendmail.cf , and sendmail is restarted.

When the local_procmail feature is used, sendmail passes local mail to procmail for delivery. procmail processes the mail, first using the commands defined in the /etc/procmailrc file and then using the commands defined in the .procmailrc file in the recipient's home directory. If no rc file is defined, procmail writes the mail to the user's mailbox unaltered. Note that the user 's .procmailrc file is applied to mail delivered by the local_procmail feature. When local_procmail is used, it is not necessary for the user to call the procmail program from the .forward file as shown in this chapter's Introduction. All the user needs to do is create a .procmailrc file and it will be applied to the mail. Using procmail as a local mailer allows both the system administrator and the user to filter inbound mail with procmail .

When procmail is used as the local mailer, sendmail runs it with three arguments: -Y , -a , and -d . The -Y argument tells procmail to use the standard Berkeley Unix mailbox format. The -d argument provides procmail with the username of the local recipient who is to receive the mail (in the mail delivery triple this is the user value). The -a argument passes an optional value to procmail that is accessible inside the procmail recipe as the $1 variable; in the mail delivery triple, this is the host value. sendmail only passes a value through -a when either the + detail syntax is used or mail is routed to the local mailer via the mailertable . In the case of the + detail syntax, the detail value is passed. In the case of the mailertable , the input address that was the key to the mailertable entry is the value passed. In all other cases, no value is passed by the -a argument and the $1 variable is unassigned .

The local_procmail feature has security implications for smrsh and for attempts to limit user mail forwarding. See Recipe 10.6 and Recipe 10.8 for more details.


See Also

Recipe 6.8 provides additional information about procmail . The sendmail book covers .forward in Chapter 13 and the local_procmail feature in Section 4.8.21. See the procmail , procmailrc , procmailex , and procmailsc manpages for more information about filtering mail with procmail .



Sendmail Cookbook
sendmail Cookbook
ISBN: 0596004710
EAN: 2147483647
Year: 2005
Pages: 178
Authors: Craig Hunt

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net