<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://commons.oreilly.com/wiki/skins/common/feed.css?97"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>SpamAssassin/Integrating SpamAssassin with qmail - Revision history</title>
		<link>http://commons.oreilly.com/wiki/index.php?title=SpamAssassin/Integrating_SpamAssassin_with_qmail&amp;action=history</link>
		<description>Revision history for this page on the wiki</description>
		<language>en</language>
		<generator>MediaWiki 1.11.0</generator>
		<lastBuildDate>Sun, 19 May 2013 09:49:32 GMT</lastBuildDate>
		<item>
			<title>Docbook2Wiki: Initial conversion from Docbook</title>
			<link>http://commons.oreilly.com/wiki/index.php?title=SpamAssassin/Integrating_SpamAssassin_with_qmail&amp;diff=5286&amp;oldid=prev</link>
			<description>&lt;p&gt;Initial conversion from Docbook&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 10:56, 7 March 2008&lt;/td&gt;
			&lt;/tr&gt;
		&lt;/table&gt;</description>
			<pubDate>Fri, 07 Mar 2008 10:56:42 GMT</pubDate>			<dc:creator>Docbook2Wiki</dc:creator>			<comments>http://commons.oreilly.com/wiki/index.php/Talk:SpamAssassin/Integrating_SpamAssassin_with_qmail</comments>		</item>
		<item>
			<title>Docbook2Wiki: Initial conversion from Docbook</title>
			<link>http://commons.oreilly.com/wiki/index.php?title=SpamAssassin/Integrating_SpamAssassin_with_qmail&amp;diff=5232&amp;oldid=prev</link>
			<description>&lt;p&gt;Initial conversion from Docbook&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{SpamAssassin/TOC}}&lt;br /&gt;
qmail is a mail transport agent written by cryptography researcher Dan Bernstein and designed to provide a highly secure mail system. It consists of several components, each of which runs with least privilege and none of which trusts data from the other without validating it itself. qmail works best in concert with several other systems designed by Bernstein that take over other functions traditionally performed by standard system utilities.&lt;br /&gt;
&lt;br /&gt;
This chapter explains how to integrate SpamAssassin into a qmail-based mail server to perform spam-checking for local recipients or to create a spam-checking mail gateway.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;warning&amp;quot;&amp;gt;&lt;br /&gt;
'''Warning'''&lt;br /&gt;
&lt;br /&gt;
qmail is a complex piece of software and, like most MTAs, offers scores of configuration choices. This chapter assumes that you are running the netqmail 1.05 version of qmail 1.03 and does not cover how to securely install, configure, or operate qmail itself. For that information, see the qmail documentation, David Sill's ''Life with qmail'' web site (''http://www.lifewithqmail.org'') and ''The qmail Handbook''by David Sill (Apress) or ''qmail'' by John Levine (O'Reilly).&lt;br /&gt;
&lt;br /&gt;
This chapter assumes that you have set up your qmail system as described in ''Life with qmail'' and that you are using the recommended ''daemontools'' and ''ucspi-tcp'' packages.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== qmail Architecture ==&lt;br /&gt;
&lt;br /&gt;
Several different qmail components play roles in receiving messages from the Internet. Messages from the Internet typically enter the mail server via the &amp;lt;tt&amp;gt;qmail-smtpd&amp;lt;/tt&amp;gt; daemon, which listens on port 25 and conducts the SMTP transaction with the remote sender. &amp;lt;tt&amp;gt;qmail-smtpd&amp;lt;/tt&amp;gt; passes the messages to the &amp;lt;tt&amp;gt;qmail-queue&amp;lt;/tt&amp;gt; program, which stores them in an outgoing queue for further processing. The &amp;lt;tt&amp;gt;qmail-send&amp;lt;/tt&amp;gt; daemon reads the messages in the outgoing queue and attempts to deliver them using either the &amp;lt;tt&amp;gt;qmail-lspawn&amp;lt;/tt&amp;gt; daemon (which passes it to the &amp;lt;tt&amp;gt;qmail-local&amp;lt;/tt&amp;gt; program for local delivery) or the &amp;lt;tt&amp;gt;qmail-rspawn&amp;lt;/tt&amp;gt; daemon (which passes them to the &amp;lt;tt&amp;gt;qmail-remote&amp;lt;/tt&amp;gt; program for relaying to remote hosts). [[SpamAssassin/Integrating SpamAssassin with qmail#spamassassin-CHP-7-FIG-1|Figure 7-1]] illustrates the flow of email through qmail components.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;spamassassin-CHP-7-FIG-1&amp;quot;&amp;gt;&lt;br /&gt;
'''Figure 7-1. qmail architecture during message receipt'''&lt;br /&gt;
&lt;br /&gt;
[[Image:SpamAssassin_I_7_tt122.png|qmail architecture during message receipt]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Most systems keep all of qmail's files in ''/var/qmail''. Configuration files reside in ''/var/qmail/control''.&lt;br /&gt;
&lt;br /&gt;
== Spam-Checking During Local Delivery ==&lt;br /&gt;
&lt;br /&gt;
The easiest way to add SpamAssassin to a qmail system is to configure qmail to pipe messages through SpamAssassin during local delivery.&lt;br /&gt;
&lt;br /&gt;
The advantages of this approach are:&lt;br /&gt;
&lt;br /&gt;
* It's easy to set up.&lt;br /&gt;
* You can run &amp;lt;tt&amp;gt;spamd&amp;lt;/tt&amp;gt; and can use &amp;lt;tt&amp;gt;spamc&amp;lt;/tt&amp;gt; for faster spam-checking.&lt;br /&gt;
* User preference files, autowhitelists, and Bayesian databases can be used, because qmail will invoke SpamAssassin as the user to whom it is delivering a message.&lt;br /&gt;
&lt;br /&gt;
However, qmail runs a local delivery agent only for email destined for a local recipient. You cannot create a spam-checking gateway with this approach.&lt;br /&gt;
&lt;br /&gt;
If you're using the installation described in the ''Life with qmail'' web site, the ''/var/qmail/control/defaultdelivery''file contains a line that specifies either a directory (e.g., ''./Maildir/'') or a filename (e.g., ''./Mailbox''). The ''/var/qmail/rc'' script passes the contents of ''defaultdelivery'' to &amp;lt;tt&amp;gt;qmail-start&amp;lt;/tt&amp;gt;, and thence to &amp;lt;tt&amp;gt;qmail-lspawn&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;qmail-local&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you deliver to a ''maildir'' directory, change the line in your ''defaultdelivery'' file to read:&lt;br /&gt;
&lt;br /&gt;
 | /usr/bin/spamc | maildir ''./Maildir/''&lt;br /&gt;
          &lt;br /&gt;
&lt;br /&gt;
In this case, be sure you've installed the ''safecat'' package, which includes the &amp;lt;tt&amp;gt;maildir&amp;lt;/tt&amp;gt; script. You can get ''safecat'' at ''http://www.pobox.com/~lbudney/linux/software/safecat.html''.&lt;br /&gt;
&lt;br /&gt;
If you deliver to a ''mailbox'' file in each user's home directory, install procmail and change the line in ''defaultdelivery'' to read:&lt;br /&gt;
&lt;br /&gt;
         | preline procmail&lt;br /&gt;
&lt;br /&gt;
In this case, the system's ''/etc/procmailrc'' file should have a default recipe that looks like this:&lt;br /&gt;
&lt;br /&gt;
 :0fw&lt;br /&gt;
 * &amp;lt;300000&lt;br /&gt;
 |/usr/bin/spamc&lt;br /&gt;
 &lt;br /&gt;
 :0:&lt;br /&gt;
 $HOME/Mailbox&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;tip&amp;quot;&amp;gt;&lt;br /&gt;
'''Tip'''&lt;br /&gt;
&lt;br /&gt;
The default delivery method is used only when users don't have their own ''.qmail'' files. This permits users to override spam-checking. Conversely, if you don't do spam-checking by default during local delivery, any user can add the preceding lines to her ''.qmail'' file and have her messages checked.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Spam-Checking All Incoming Mail ==&lt;br /&gt;
&lt;br /&gt;
If you want to set up a spam-checking gateway for all recipients, local or not, you need a way to perform spam-checking as mail is received, before final delivery. qmail provides this capability through the QMAILQUEUE patch, which is included in the netqmail distribution of qmail (and most packaged qmail distributions).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;tip&amp;quot;&amp;gt;&lt;br /&gt;
'''Tip'''&lt;br /&gt;
&lt;br /&gt;
You can find out if your qmail installation has the QMAILQUEUE patch applied by executing the following commands:&lt;br /&gt;
&lt;br /&gt;
 # '''cd /var/qmail/bin'''&lt;br /&gt;
 &lt;br /&gt;
 # '''strings qmail-smtpd | grep QMAILQUEUE'''&lt;br /&gt;
 &lt;br /&gt;
 QMAILQUEUE&lt;br /&gt;
&lt;br /&gt;
If you don't see &amp;lt;tt&amp;gt;QMAILQUEUE&amp;lt;/tt&amp;gt; in response to the strings command, the patch has not been applied. You will have to recompile qmail from the netqmail source code.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With the QMAILQUEUE patch applied, the &amp;lt;tt&amp;gt;qmail-smtpd&amp;lt;/tt&amp;gt; daemon checks to see if the environment variable &amp;lt;tt&amp;gt;QMAILQUEUE&amp;lt;/tt&amp;gt; has been set. If so, &amp;lt;tt&amp;gt;qmail-smtpd&amp;lt;/tt&amp;gt; hands the message off to the program specified in that variable instead of to the default &amp;lt;tt&amp;gt;qmail-queue&amp;lt;/tt&amp;gt; program. The new program can call SpamAssassin and then pass the (possibly tagged) message to &amp;lt;tt&amp;gt;qmail-queue&amp;lt;/tt&amp;gt;. [[SpamAssassin/Integrating SpamAssassin with qmail#spamassassin-CHP-7-FIG-2|Figure 7-2]] illustrates this arrangement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;spamassassin-CHP-7-FIG-2&amp;quot;&amp;gt;&lt;br /&gt;
'''Figure 7-2. qmail configuration to check all incoming email for spam'''&lt;br /&gt;
&lt;br /&gt;
[[Image:SpamAssassin_I_7_tt127.png|qmail configuration to check all incoming email for spam]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SpamAssassin includes a small C program called &amp;lt;tt&amp;gt;qmail-spamc&amp;lt;/tt&amp;gt; by John Peacock, with its source code (in the ''qmail'' subdirectory in SpamAssassin 2.63, and in the ''spamc'' subdirectory in SpamAssassin 3.0). When compiled, &amp;lt;tt&amp;gt;qmail-spamc&amp;lt;/tt&amp;gt; is suitable for use as a &amp;lt;tt&amp;gt;QMAILQUEUE&amp;lt;/tt&amp;gt; program; it invokes &amp;lt;tt&amp;gt;spamc&amp;lt;/tt&amp;gt; on an incoming message and pipes the result to &amp;lt;tt&amp;gt;qmail-queue&amp;lt;/tt&amp;gt;. Because it's written in C and is a very simple program, it runs quickly. To set up &amp;lt;tt&amp;gt;qmail-spamc&amp;lt;/tt&amp;gt;, perform the following steps:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Compile ''qmail-spamc.c''. On most systems, issue a command like the following in the directory containing ''qmail-spamc.c'':&lt;br /&gt;
&lt;br /&gt;
                   '''cc -O -o qmail-spamc qmail-spamc.c'''&lt;br /&gt;
                &lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;As ''root'', install &amp;lt;tt&amp;gt;qmail-spamc&amp;lt;/tt&amp;gt; in an appropriate location on your system (e.g., ''/var/qmail/bin'' or ''/usr/local/bin''). Make it executable. For example:&lt;br /&gt;
&lt;br /&gt;
                   '''install -m 755 qmail-spamc '''&lt;br /&gt;
                   &lt;br /&gt;
 '''                     /var/qmail/bin'''&lt;br /&gt;
 '''                  '''&lt;br /&gt;
                &lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Ensure that &amp;lt;tt&amp;gt;qmail-queue&amp;lt;/tt&amp;gt; is on the system's default path. The easiest way to do so is usually to create a symbolic link from ''/var/qmail/bin/qmail-queue'' to ''/usr/bin/qmail-queue''. Do the same for &amp;lt;tt&amp;gt;spamc&amp;lt;/tt&amp;gt; if it is not already installed in ''/usr/bin''. For example:&lt;br /&gt;
&lt;br /&gt;
 ln -s /var/qmail/bin/qmail-queue /usr/bin/qmail-queue&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Ensure that &amp;lt;tt&amp;gt;spamd&amp;lt;/tt&amp;gt; is running.&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Ensure that &amp;lt;tt&amp;gt;qmail-smtpd&amp;lt;/tt&amp;gt; has enough memory available to allow it to run &amp;lt;tt&amp;gt;qmail-spamc&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;spamc&amp;lt;/tt&amp;gt;. Edit ''/var/qmail/supervise/qmail-smtpd/run'' and modify the &amp;lt;tt&amp;gt;-m&amp;lt;/tt&amp;gt; and/or &amp;lt;tt&amp;gt;-a&amp;lt;/tt&amp;gt; arguments of &amp;lt;tt&amp;gt;softlimit&amp;lt;/tt&amp;gt; to increase the number of bytes available to &amp;lt;tt&amp;gt;qmail-smtpd&amp;lt;/tt&amp;gt; and its child processes to an amount sufficient to allow all of the processes to execute completely on a large message. A setting of 10MB (roughly 10,000,000) is usually sufficient, but you may have to vary the setting and keep an eye on your logs to find the right amount. If the setting is too low, you will see errors such as the following at the end of the DATA step during SMTP transactions:&lt;br /&gt;
&lt;br /&gt;
 fatal: qq temporary problem (#4.3.0)&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Edit ''/etc/tcp.smtp''. This file controls access to the SMTP service when you're using ''ucspi-tcp''. Add or modify the line shown in bold:&lt;br /&gt;
&lt;br /&gt;
 127.:allow,RELAYCLIENT=&amp;quot;&amp;quot;&lt;br /&gt;
 ''':allow,QMAILQUEUE=&amp;quot;/var/qmail/bin/qmail-spamc'''&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This change causes the &amp;lt;tt&amp;gt;QMAILQUEUE&amp;lt;/tt&amp;gt; environment variable to be set when &amp;lt;tt&amp;gt;qmail-smtpd&amp;lt;/tt&amp;gt; is invoked by a connection from hosts outside the ''127''. network (i.e., spam-checking will be performed on email from remote hosts, but not from the local host).&lt;br /&gt;
&lt;br /&gt;
With the version of &amp;lt;tt&amp;gt;qmail-spamc&amp;lt;/tt&amp;gt; distributed with SpamAssassin 3.0, you can customize the way &amp;lt;tt&amp;gt;spamc&amp;lt;/tt&amp;gt; is invoked by adding additional environment variables to the list in ''/etc/tcp.smtp'', including:&lt;br /&gt;
&lt;br /&gt;
;&amp;lt;tt&amp;gt;SPAMDSOCK=&amp;lt;/tt&amp;gt;&amp;quot;&amp;lt;tt&amp;gt;''/path/to/socket''&amp;lt;/tt&amp;gt;&amp;quot;&lt;br /&gt;
: Direct &amp;lt;tt&amp;gt;spamc&amp;lt;/tt&amp;gt; to use the given path to a Unix socket for connecting to &amp;lt;tt&amp;gt;spamd&amp;lt;/tt&amp;gt;.&lt;br /&gt;
;&amp;lt;tt&amp;gt;SPAMDHOST=&amp;lt;/tt&amp;gt;&amp;quot;&amp;lt;tt&amp;gt;''hostname''&amp;lt;/tt&amp;gt;&amp;quot;&lt;br /&gt;
: Direct &amp;lt;tt&amp;gt;spamc&amp;lt;/tt&amp;gt; to connect to &amp;lt;tt&amp;gt;spamd&amp;lt;/tt&amp;gt; at the given host.&lt;br /&gt;
;&amp;lt;tt&amp;gt;SPAMDPORT=&amp;lt;/tt&amp;gt;&amp;quot;&amp;lt;tt&amp;gt;''port-number''&amp;lt;/tt&amp;gt;&amp;quot;&lt;br /&gt;
: Direct &amp;lt;tt&amp;gt;spamc&amp;lt;/tt&amp;gt; to connect to &amp;lt;tt&amp;gt;spamd&amp;lt;/tt&amp;gt; at the given TCP port number.&lt;br /&gt;
;&amp;lt;tt&amp;gt;SPAMDSSL=&amp;quot;1&amp;lt;/tt&amp;gt;&amp;quot;&lt;br /&gt;
: Direct &amp;lt;tt&amp;gt;spamc&amp;lt;/tt&amp;gt; to connect to &amp;lt;tt&amp;gt;spamd&amp;lt;/tt&amp;gt; using SSL.&lt;br /&gt;
;&amp;lt;tt&amp;gt;SPAMDSIZE=&amp;lt;/tt&amp;gt;&amp;quot;&amp;lt;tt&amp;gt;''number-of-bytes''&amp;lt;/tt&amp;gt;&amp;quot;&lt;br /&gt;
: Direct &amp;lt;tt&amp;gt;spamc&amp;lt;/tt&amp;gt; not to perform spam-checking on messages that exceed &amp;lt;tt&amp;gt;''number-of-bytes''&amp;lt;/tt&amp;gt; in size.&lt;br /&gt;
;&amp;lt;tt&amp;gt;SPAMDUSER=&amp;lt;/tt&amp;gt;&amp;quot;&amp;lt;tt&amp;gt;''username''&amp;lt;/tt&amp;gt;&amp;quot;&lt;br /&gt;
: Direct &amp;lt;tt&amp;gt;spamc&amp;lt;/tt&amp;gt; to supply the given username to &amp;lt;tt&amp;gt;spamd&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Update the TCP rules database by running the command &amp;lt;tt&amp;gt;qmailctl cdb&amp;lt;/tt&amp;gt;, which is found in your ''/var/qmail/bin/'' directory. At this point, all incoming remote SMTP connections should have their messages passed through &amp;lt;tt&amp;gt;qmail-spamc&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;tip&amp;quot;&amp;gt;&lt;br /&gt;
'''Tip'''&lt;br /&gt;
&lt;br /&gt;
You can emulate the QMAILQUEUE approach without the QMAILQUEUE patch by renaming &amp;lt;tt&amp;gt;qmail-queue&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;qmail-queue.orig&amp;lt;/tt&amp;gt; and writing a new &amp;lt;tt&amp;gt;qmail-queue&amp;lt;/tt&amp;gt; script that pipes the message through SpamAssassin and then to &amp;lt;tt&amp;gt;qmail-queue.orig&amp;lt;/tt&amp;gt;, like this:&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 &lt;br /&gt;
 PATH=/var/qmail/bin:$PATH&lt;br /&gt;
 &lt;br /&gt;
 | spamc | qmail-queue.orig&lt;br /&gt;
&lt;br /&gt;
However, this approach is less flexible than using QMAILQUEUE and more prone to causing trouble later when you want to queue messages without spam-checking them.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Building a Spam-Checking Gateway ==&lt;br /&gt;
&lt;br /&gt;
Several content-filtering daemons that call SpamAssassin are available for qmail. This section provides a complete sample installation of qmail-scanner, a particularly flexible filter that supports both spam-checking and virus-checking. qmail-scanner is written in Perl and available at ''http://qmail-scanner.sourceforge.net/''. The version used in this section's example is 1.21. Some of qmail-scanner's features include:&lt;br /&gt;
&lt;br /&gt;
* The filter was specifically developed and tested for qmail.&lt;br /&gt;
* Messages can be rejected based on MIME type or extensions of attached filenames.&lt;br /&gt;
* Messages can be rejected based on invalid formatting.&lt;br /&gt;
* Messages can be checked with multiple virus scanners, and messages carrying viruses can be refused, discarded, or quarantined.&lt;br /&gt;
* SpamAssassin can be invoked on a message, and spam can be refused, discarded, quarantined, or tagged.&lt;br /&gt;
&lt;br /&gt;
The rest of this chapter details the installation, configuration, and operation of qmail-scanner as an example of a full-scale approach to using SpamAssassin with qmail. qmail-scanner's other functions, such as virus-checking, are mentioned but not covered in detail; read the documentation to learn more about these features.&lt;br /&gt;
&lt;br /&gt;
=== Installation ===&lt;br /&gt;
&lt;br /&gt;
qmail-scanner is written in Perl and invokes SpamAssassin by running &amp;lt;tt&amp;gt;spamc&amp;lt;/tt&amp;gt;, so you must run &amp;lt;tt&amp;gt;spamd&amp;lt;/tt&amp;gt; to use qmail-scanner. You should set up &amp;lt;tt&amp;gt;spamd&amp;lt;/tt&amp;gt; before you install qmail-scanner. Install SpamAssassin (and your antivirus software) first, then install qmail-scanner. qmail-scanner also requires some other Perl modules, including: ''Time::HiRes'', ''DB_File'', and ''Sys::Syslog''. You can install these Perl modules using CPAN as described in [[SpamAssassin/SpamAssassin Basics|Chapter 2]]. You must also install the Maildrop software package (''http://www.courier-mta.org/download.php''), and if you plan to perform virus-checking, TNEF (''http://sourceforge.net/projects/tnef/''). ''''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;tip&amp;quot;&amp;gt;&lt;br /&gt;
'''Tip'''&lt;br /&gt;
&lt;br /&gt;
qmail-scanner requires the 5.005_03 version of Perl or later. Perl must be compiled to allow ''setuid'' Perl scripts; often this means that a separate &amp;lt;tt&amp;gt;suidperl&amp;lt;/tt&amp;gt; program is available on the system. If your system's Perl does not support ''setuid'' Perl scripts, you may be able to find a package for your system that does, you may build Perl from source code and enable support, or you may compile a ''setuid'' wrapper program in C (described later in this chapter).&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Begin the install process by creating a new user account and group for running qmail-scanner; the usual name for both the user and group is ''qscand''. The new user will own qmail-scanner's files, and the user (or group) must have access to SpamAssassin's configuration and database files as well. The user's home directory is traditionally ''/home/qscand'', but you can create it anywhere that fits your system's needs.&lt;br /&gt;
&lt;br /&gt;
qmail-scanner uses several important directories and files in ''/var/spool/qmailscan''. For example, quarantined messages are stored in ''/var/spool/qmailscan/quarantine'', and qmail-scanner logs its operations in ''/var/spool/qmailscan/qmail-queue.log''. The directories ''/var/spool/qmailscan/tmp'' and ''/var/spool/qmailscan/working'' are temporary directories used for unpacking and processing messages. For optimal performance, these directories should be on a fast disk—even a RAM disk if your operating system supports it and you have enough memory to spare. In contrast, the ''quarantine'' directory should never be located on a RAM disk because you will often want to be sure that you can access quarantined files.&lt;br /&gt;
&lt;br /&gt;
Next, download the qmail-scanner source code, unpack it, and build it. You must be ''root'' to configure and build qmail-scanner. The qmail-scanner build process uses the familiar &amp;lt;tt&amp;gt;configure&amp;lt;/tt&amp;gt; command to configure and build qmail-scanner's components, which you then install.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;sidebar&amp;quot;&amp;gt;&lt;br /&gt;
'''qmail-scanner Configuration Options'''&lt;br /&gt;
&lt;br /&gt;
qmail-scanner has only a few &amp;lt;tt&amp;gt;configure&amp;lt;/tt&amp;gt; options related to SpamAssassin. If you don't specify any options, qmail-scanner will use &amp;lt;tt&amp;gt;spamc -c&amp;lt;/tt&amp;gt; for spam-checking and will add ''X-Spam-Status'' and ''X-Spam-Level'' headers to messages, but will not modify the ''Subject'' header of spam messages.&lt;br /&gt;
&lt;br /&gt;
If you specify the &amp;lt;tt&amp;gt;--scanners 'fast_spamassassin=&amp;lt;/tt&amp;gt; &amp;lt;tt&amp;gt;''string''&amp;lt;/tt&amp;gt;' command-line option to &amp;lt;tt&amp;gt;configure&amp;lt;/tt&amp;gt;, qmail-scanner will also modify the ''Subject'' header of spam messages by prepending a &amp;lt;tt&amp;gt;''string''&amp;lt;/tt&amp;gt;. A typical choice for &amp;lt;tt&amp;gt;''string''&amp;lt;/tt&amp;gt; might be &amp;lt;tt&amp;gt;SPAM&amp;lt;/tt&amp;gt;. If you plan to use other virus-scanners, you must specify thom in this command-line option as well or qmail-scanner will not use them. (If you've already installed qmail-scanner and want to start adding a ''Subject'' header tag, you can also edit the ''/var/qmail/bin/qmail-scanner-queue.pl'' file itself; search for the line that defines the &amp;lt;tt&amp;gt;$spamc_subject&amp;lt;/tt&amp;gt; variable, and modify it to set your subject prefix.)&lt;br /&gt;
&lt;br /&gt;
If you specify the &amp;lt;tt&amp;gt;--scanners verbose_spamassassin&amp;lt;/tt&amp;gt; command-line option to &amp;lt;tt&amp;gt;configure&amp;lt;/tt&amp;gt;, qmail-scanner will use &amp;lt;tt&amp;gt;spamc&amp;lt;/tt&amp;gt; without the &amp;lt;tt&amp;gt;-c&amp;lt;/tt&amp;gt; option. This alternative runs more slowly, because the entire spam-checked message is read back from &amp;lt;tt&amp;gt;spamc&amp;lt;/tt&amp;gt; instead of just the spam scores. The advantage of this configuration, however, is that messages will be tagged exactly as defined in the SpamAssassin rules and report templates. For example, you'll get the SpamAssassin headers that report which spam tests matched, any custom headers you've defined, and full MIME-rewriting of messages. If you plan to use other virus scanners, you must specify them in this command-line option as well or qmail-scanner will not use them.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To configure qmail-scanner, use the commands shown in [[SpamAssassin/Integrating SpamAssassin with qmail#spamassassin-CHP-7-EX-1|Example 7-1]]. The example also reproduces the output you should expect.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;spamassassin-CHP-7-EX-1&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 7-1. Building qmail-scanner'''&lt;br /&gt;
&lt;br /&gt;
 $ '''tar xfz qmail-scanner-1.21.tar.gz'''&lt;br /&gt;
 $ '''cd qmail-scanner-1.21'''&lt;br /&gt;
 $ '''su'''&lt;br /&gt;
 Password: &lt;br /&gt;
 '''                     XXXXXXXX'''&lt;br /&gt;
 '''                  '''&lt;br /&gt;
 # '''./configure --install'''&lt;br /&gt;
 Building Qmail-Scanner 1.21...&lt;br /&gt;
 &lt;br /&gt;
 This script will search your system for the virus scanners it knows&lt;br /&gt;
 about, and will ensure that all external programs&lt;br /&gt;
 qmail-scanner-queue.pl uses are explicitly pathed for performance&lt;br /&gt;
 reasons.&lt;br /&gt;
 &lt;br /&gt;
 It will then generate qmail-scanner-queue.pl - it is up to you to install it&lt;br /&gt;
 correctly.&lt;br /&gt;
 &lt;br /&gt;
 Continue? ([Y]/N) '''Y'''&lt;br /&gt;
 &lt;br /&gt;
 /usr/bin/uudecode works as expected on system...&lt;br /&gt;
 &lt;br /&gt;
 The following binaries and scanners were found on your system:&lt;br /&gt;
 &lt;br /&gt;
 mimeunpacker=/usr/local/bin/reformime&lt;br /&gt;
 uudecode=/usr/bin/uudecode&lt;br /&gt;
 unzip=/usr/bin/unzip&lt;br /&gt;
 &lt;br /&gt;
 Content/Virus Scanners installed on your System&lt;br /&gt;
 &lt;br /&gt;
 fprot=/usr/local/bin/f-prot&lt;br /&gt;
 fast_spamassassin=/usr/local/bin/spamc&lt;br /&gt;
 &lt;br /&gt;
 Qmail-Scanner details.&lt;br /&gt;
 &lt;br /&gt;
 log-details=0&lt;br /&gt;
 fix-mime=2&lt;br /&gt;
 ignore-eol-check=0&lt;br /&gt;
 debug=1&lt;br /&gt;
 notify=psender,nmlvadm&lt;br /&gt;
 redundant-scanning=no&lt;br /&gt;
 virus-admin=postmaster@example.com&lt;br /&gt;
 local-domains='example.com'&lt;br /&gt;
 silent-&lt;br /&gt;
 viruses='klez','bugbear','hybris','yaha','braid','nimda','tanatos','sobig','winevar','pal&lt;br /&gt;
 yh','fizzer','gibe','cailont','lovelorn','swen','dumaru','sober','hawawi','holar-&lt;br /&gt;
 i','mimail','poffer','bagle','worm.galil','mydoom','worm.sco','tanx','novarg','@mm'&lt;br /&gt;
 scanners=&amp;quot;fprot_scanner&amp;quot;,&amp;quot;fast_spamassassin&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 If that looks correct, I will now generate qmail-scanner-queue.pl&lt;br /&gt;
 for your system...&lt;br /&gt;
 Continue? ([Y]/N) '''Y'''&lt;br /&gt;
 &lt;br /&gt;
 Finished. Please read README(.html) and then go over the script to&lt;br /&gt;
 check paths/etc, and then install as you see fit.&lt;br /&gt;
 &lt;br /&gt;
 Remember to copy quarantine-attachments.txt to /var/spool/qmailscan and then&lt;br /&gt;
 run &amp;quot;qmail-scanner-queue.pl -g&amp;quot; to generate DB version.&lt;br /&gt;
 &lt;br /&gt;
               ****** FINAL TEST ******&lt;br /&gt;
 &lt;br /&gt;
 Please log into an unpriviledged account and run&lt;br /&gt;
 /var/qmail/bin/qmail-scanner-queue.pl -g&lt;br /&gt;
 &lt;br /&gt;
 If you see the error &amp;quot;Can't do setuid&amp;quot;, or &amp;quot;Permission denied&amp;quot;, then&lt;br /&gt;
 refer to the FAQ.&lt;br /&gt;
 &lt;br /&gt;
 (e.g.  &amp;quot;setuidgid qmaild /var/qmail/bin/qmail-scanner-queue.pl -g&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 That's it! To report success:&lt;br /&gt;
 &lt;br /&gt;
    % (echo 'First M. Last'; cat SYSDEF)|mail jhaar-s4vstats@crom.trimble.co.nz&lt;br /&gt;
 Replace First M. Last with your name.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;sidebar&amp;quot;&amp;gt;&lt;br /&gt;
'''No setuid Perl'''&lt;br /&gt;
&lt;br /&gt;
When qmail-scanner's &amp;lt;tt&amp;gt;configure&amp;lt;/tt&amp;gt; script can't find a suitable version of Perl for running ''setuid'' scripts, it prints out an error like this:&lt;br /&gt;
&lt;br /&gt;
 Testing suid nature of /usr/bin/suidperl...&lt;br /&gt;
 Whoa - broken perl install found.&lt;br /&gt;
 Cannot even run a simple script setuid&lt;br /&gt;
 Installation of Qmail-Scanner FAILED&lt;br /&gt;
&lt;br /&gt;
If you can't (or don't want to) install a Perl that runs ''setuid'' scripts, you can use a ''setuid'' wrapper in C instead. Follow these steps as ''root'':&lt;br /&gt;
&lt;br /&gt;
# Install qmail-scanner with &amp;lt;tt&amp;gt;./configure --skip-setuid-test --install&amp;lt;/tt&amp;gt;. This will produce an error at the end of the installation.&lt;br /&gt;
# Compile and install the C wrapper with &amp;lt;tt&amp;gt;(cd contrib; make install)&amp;lt;/tt&amp;gt;. If you're not using the default &amp;lt;tt&amp;gt;qscand&amp;lt;/tt&amp;gt; user and group and ''/var/qmail/bin'' directory for installation, you'll have to edit ''contrib/Makefile'' first.&lt;br /&gt;
# Remove the setuid bit from ''/var/qmail/bin/qmail-scanner-queue.pl'' with &amp;lt;tt&amp;gt;chmod 0755 /var/qmail/bin/qmail-scanner-queue.pl&amp;lt;/tt&amp;gt;.&lt;br /&gt;
# Edit ''/var/qmail/bin/qmail-scanner-queue.pl'' and change the first line from &amp;lt;tt&amp;gt;#!/usr/bin/suidperl -T&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;#!/usr/bin/perl -T&amp;lt;/tt&amp;gt;.&lt;br /&gt;
# Use ''qmail-scanner-queue'' (the compiled C wrapper) in place of ''qmail-scanner-queue.pl'' in the rest of the qmail-scanner setup process.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As with &amp;lt;tt&amp;gt;qmail-spamc&amp;lt;/tt&amp;gt;, ensure that &amp;lt;tt&amp;gt;qmail-smtpd&amp;lt;/tt&amp;gt; has enough memory available to allow it to run &amp;lt;tt&amp;gt;qmail-scanner-queue.pl&amp;lt;/tt&amp;gt;, any virus checkers you have configured, and &amp;lt;tt&amp;gt;spamc&amp;lt;/tt&amp;gt;. Edit ''/var/qmail/supervise/qmail-smtpd/run'' and modify the &amp;lt;tt&amp;gt;-m&amp;lt;/tt&amp;gt; and/or &amp;lt;tt&amp;gt;-a&amp;lt;/tt&amp;gt; arguments of &amp;lt;tt&amp;gt;softlimit&amp;lt;/tt&amp;gt; to increate the number of bytes available to &amp;lt;tt&amp;gt;qmail-smtpd&amp;lt;/tt&amp;gt; and its child processes to an amount sufficient to allow all of the processes to execute completely on a large message.&lt;br /&gt;
&lt;br /&gt;
To enable qmail-scanner, edit ''/etc/tcp.smtp''. Add or modify lines such as those shown in bold:&lt;br /&gt;
&lt;br /&gt;
 127.:allow,RELAYCLIENT=&amp;quot;&amp;quot;&lt;br /&gt;
 '''192.168.:allow,RELAYCLIENT=&amp;quot;&amp;quot;,QMAILQUEUE=&amp;quot;/var/qmail/bin/qmail-scanner-queue.pl'''&amp;quot;&lt;br /&gt;
 '''10.:allow,RELAYCLIENT=&amp;quot;&amp;quot;,QS_SPAMASSASSIN=&amp;quot;on&amp;quot;,QMAILQUEUE=&amp;quot;/var/qmail/bin/qmail-'''&lt;br /&gt;
 '''scanner-queue.pl'''&amp;quot;&lt;br /&gt;
 ''':allow,QMAILQUEUE=&amp;quot;/var/qmail/bin/qmail-scanner-queue.pl'''&amp;quot;&lt;br /&gt;
&lt;br /&gt;
When you invoke qmail-scanner with qmail's &amp;lt;tt&amp;gt;RELAYCLIENT&amp;lt;/tt&amp;gt; variable set, as in the line for connections from the 192.168/16 network, only virus-checking is performed, unless you also include &amp;lt;tt&amp;gt;QS_SPAMASSASSIN=&amp;quot;on&amp;lt;/tt&amp;gt;&amp;quot;, as in the line for connections from the 10/8 network. When you invoke it without setting &amp;lt;tt&amp;gt;RELAYCLIENT&amp;lt;/tt&amp;gt;, as in the line for default connections, both virus-checking and spam-checking are performed.&lt;br /&gt;
&lt;br /&gt;
Be sure to run &amp;lt;tt&amp;gt;/var/qmail/bin/qmailctl cdb&amp;lt;/tt&amp;gt; after updating ''/etc/tcp.smtp''.&lt;br /&gt;
&lt;br /&gt;
=== Initialization ===&lt;br /&gt;
&lt;br /&gt;
The first time you install qmail-scanner, you must direct it to initialize its databases. As the ''qscand'' user, run these commands:&lt;br /&gt;
&lt;br /&gt;
 $ '''/var/qmail/bin/qmail-scanner-queue.pl -z'''&lt;br /&gt;
 $ '''/var/qmail/bin/qmail-scanner-queue.pl -g'''&lt;br /&gt;
 perlscanner: generate new DB file from /var/spool/qmailscan/quarantine-attachments.txt&lt;br /&gt;
 perlscanner: total of 9 entries.&lt;br /&gt;
&lt;br /&gt;
=== Basic Operations ===&lt;br /&gt;
&lt;br /&gt;
qmail-scanner comes with a shell script called &amp;lt;tt&amp;gt;test_installation.sh&amp;lt;/tt&amp;gt; that can be used to exercise an installation. [[SpamAssassin/Integrating SpamAssassin with qmail#spamassassin-CHP-7-EX-2|Example 7-2]] shows how to run the script, along with its output.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;spamassassin-CHP-7-EX-2&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 7-2. Testing qmail-scanner'''&lt;br /&gt;
&lt;br /&gt;
 # '''cd contrib'''&lt;br /&gt;
 # '''QMAILQUEUE=&amp;quot;/var/qmai/bin/qmail-scanner-queue.pl&amp;quot; ./test_installation.sh -doit'''&lt;br /&gt;
 &lt;br /&gt;
 Sending standard test message - no viruses...&lt;br /&gt;
 done!&lt;br /&gt;
 &lt;br /&gt;
 Sending eicar test virus - should be caught by perlscanner module...&lt;br /&gt;
 done!&lt;br /&gt;
 &lt;br /&gt;
 Sending eicar test virus with altered filename - should only be caught by commercial &lt;br /&gt;
 anti-virus modules (if you have any)...&lt;br /&gt;
 &lt;br /&gt;
 Sending bad spam message for anti-spam testing - In case you are using SpamAssassin...&lt;br /&gt;
 Done!&lt;br /&gt;
 &lt;br /&gt;
 Finished test. Now go and check Email for root&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If qmail-scanner's spam-checking is operating properly, ''root'' (or the user that receives ''root'''s email) should receive a non-spam message like this:&lt;br /&gt;
&lt;br /&gt;
 From MAILER-DAEMON Tue Mar 23 05:03:28 2004&lt;br /&gt;
 From: Qmail-Scanner Test &amp;lt;example.com@example.com&amp;gt;&lt;br /&gt;
 '''Received: from  by example.com by uid 0 with qmail-scanner-1.21'''&lt;br /&gt;
                '''(f-prot: 3.11/. spamassassin: 2.63.  Clear:RC:1(127.0.0.1):SA:0(0.0/5.0):'''.&lt;br /&gt;
  '''Processed in 5.577981 secs); 23 Mar 2004 05:03:28 -0000'''&lt;br /&gt;
 To: Root Account &amp;lt;root@example.com&amp;gt;&lt;br /&gt;
 Subject: Qmail-Scanner test (1/4): inoffensive message&lt;br /&gt;
 Date: 23 Mar 2004 05:03:22 -0000&lt;br /&gt;
 Delivered-To: root@example.com&lt;br /&gt;
 '''X-Spam-Status: No, hits=0.0 required=5.0'''&lt;br /&gt;
 &lt;br /&gt;
 Message 1/4&lt;br /&gt;
 &lt;br /&gt;
 This is a test message. It should arrive unaffected.&lt;br /&gt;
&lt;br /&gt;
The same user should also receive a spam message like this:&lt;br /&gt;
&lt;br /&gt;
 From MAILER-DAEMON Tue Mar 23 05:03:41 2004&lt;br /&gt;
 '''Received: from  by example.com by uid 0 with qmail-scanner-1.21'''&lt;br /&gt;
                '''(f-prot: 3.11/. spamassassin: 2.63.  Clear:RC:1(127.0.0.1):SA:1(16.7/5.0):'''.&lt;br /&gt;
  '''Processed in 5.129358 secs); 23 Mar 2004 05:03:40 -0000'''&lt;br /&gt;
                '''X-Spam-Status: Yes, hits=16.7 required=5.0'''&lt;br /&gt;
                '''X-Spam-Level: ++++++++++++++++'''&amp;lt;nowiki&amp;gt;&lt;br /&gt;
Delivery-Date: Mon, 19 Feb 2001 13:57:29 +0000&lt;br /&gt;
Delivered-To: jm@netnoteinc.com&lt;br /&gt;
Received: from webnote.net (mail.webnote.net [193.120.211.219])&lt;br /&gt;
        by mail.netnoteinc.com (Postfix) with ESMTP id 09C18114095&lt;br /&gt;
        for &amp;lt;jm7@netnoteinc.com&amp;gt;; Mon, 19 Feb 2001 13:57:29 +0000 (GMT)&lt;br /&gt;
Received: from netsvr.Internet (USR-157-050.dr.cgocable.ca [24.226.157.50] (may&lt;br /&gt;
+be forged))&lt;br /&gt;
        by webnote.net (8.9.3/8.9.3) with ESMTP id IAA29903&lt;br /&gt;
        for &amp;lt;jm7@netnoteinc.com&amp;gt;; Sun, 18 Feb 2001 08:28:16 GMT&lt;br /&gt;
From: sb55sb55@yahoo.com&lt;br /&gt;
Received: from R00UqS18S (max1-45.losangeles.corecomm.net [216.214.106.173]) by&lt;br /&gt;
+netsvr.Internet with SMTP (Microsoft Exchange Internet Mail Service Version&lt;br /&gt;
+5.5.2653.13)&lt;br /&gt;
        id 1429NTL5; Sun, 18 Feb 2001 03:26:12 -0500&lt;br /&gt;
DATE: 18 Feb 01 12:29:13 AM&lt;br /&gt;
Message-ID: &amp;lt;9PS291LhupY&amp;gt;&lt;br /&gt;
Subject: Qmail-Scanner anti-spam test (4/4): checking SpamAssassin [if present]&lt;br /&gt;
+(There yours for FREE!)&lt;br /&gt;
To: undisclosed-recipients: ;&lt;br /&gt;
&lt;br /&gt;
Congratulations! You have been selected to receive 2 FREE 2 Day VIP Passes to &lt;br /&gt;
Universal Studios!&lt;br /&gt;
&lt;br /&gt;
Click here http://209.61.190.180&lt;br /&gt;
&lt;br /&gt;
As an added bonus you will also be registered to receive vacations discounted 25%-&lt;br /&gt;
75%!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;br /&gt;
This mailing is done by an independent marketing co.&lt;br /&gt;
We apologize if this message has reached you in error.&lt;br /&gt;
Save the Planet, Save the Trees! Advertise via E mail.&lt;br /&gt;
No wasted paper! Delete with one simple keystroke!&lt;br /&gt;
Less refuse in our Dumps! This is the new way of the new millennium&lt;br /&gt;
To be removed please reply back with the word &amp;quot;remove&amp;quot; in the subject line.&lt;br /&gt;
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the bold lines in the messages. These are headers demonstrating that the messages were processed by qmail-scanner, and in the case of the spam message, that qmail-scanner can recognize spam.&lt;br /&gt;
&lt;br /&gt;
qmail-scanner uses ''/var/spool/qmailscan'' as a working directory and quarantine area for viruses. By default, qmail-scanner's operations are logged to the ''/var/spool/qmailscan/qmail-queue.log'' file, which should be added to your log rotation schedule. Errors are also reported to qmail's log files.&lt;br /&gt;
&lt;br /&gt;
When an SMTP session is dropped partway, temporary files may remain in ''/var/spool/qmailscan''. These messages can be cleared out by running &amp;lt;tt&amp;gt;/var/qmail/bin/qmail-scanner-queue.pl -z&amp;lt;/tt&amp;gt;. Set up a &amp;lt;tt&amp;gt;cron&amp;lt;/tt&amp;gt; job to execute this command once a day to delete older files in this directory.&lt;br /&gt;
&lt;br /&gt;
=== Per-User Spam Preferences ===&lt;br /&gt;
&lt;br /&gt;
qmail-scanner invokes &amp;lt;tt&amp;gt;spamc&amp;lt;/tt&amp;gt; with the &amp;lt;tt&amp;gt;-u&amp;lt;/tt&amp;gt; &amp;lt;tt&amp;gt;''recipient''&amp;lt;/tt&amp;gt; argument when a message has a single recipient. Accordingly, in this case, per-user spam-checking preferences (either from users' ''.spamassassin/user_prefs'' files or from an SQL or LDAP database if &amp;lt;tt&amp;gt;spamd&amp;lt;/tt&amp;gt; is so configured) will be applied when qmail-scanner checks messages. When a message has multiple recipients, qmail-scanner uses the default preferences.&lt;br /&gt;
&lt;br /&gt;
Although there is no way to configure qmail to force senders to send messages with one recipient at a time, qmail itself always breaks up a multirecipient message when it is ''sending'' and sends copies of the message to single recipients. Ron Culler pointed out in a December 2003 message to the ''qmail-scanner-general'' mailing list that one way to ensure that every message has only a single recipient is to run a pair of qmail gateways. The first gateway receives messages from the Internet and can perform some general scanning (e.g., refusing viruses) before forwarding messages on to the second gateway for spam-checking. Because the first qmail server will always split up multirecipient messages before sending them, the second qmail server will always receive messages with a single recipient and can apply per-user spam preferences.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;tip&amp;quot;&amp;gt;&lt;br /&gt;
'''Tip'''&lt;br /&gt;
&lt;br /&gt;
If you built qmail-scanner using the default &amp;lt;tt&amp;gt;fast_spamassassin&amp;lt;/tt&amp;gt; configuration (described in the [[SpamAssassin/Integrating SpamAssassin with qmail|qmail-scanner Configuration Options]] sidebar), &amp;lt;tt&amp;gt;spamc&amp;lt;/tt&amp;gt; is invoked with the &amp;lt;tt&amp;gt;-c&amp;lt;/tt&amp;gt; option. This limits which per-user spam preferences are applied: spam thresholds and score modifications will work, but preferences that affect the way messages or headers are rewritten will not (because &amp;lt;tt&amp;gt;spamc -c&amp;lt;/tt&amp;gt; returns only a spam score, not a rewritten message). Use the &amp;lt;tt&amp;gt;verbose_spamassassin&amp;lt;/tt&amp;gt; configuration if you need to enable these preferences.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sitewide Bayesian Filtering ===&lt;br /&gt;
&lt;br /&gt;
You can easily add sitewide Bayesian filtering to qmail-scanner. Use the usual SpamAssassin &amp;lt;tt&amp;gt;use_bayes&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;bayes_path&amp;lt;/tt&amp;gt; directives in ''local.cf'', and ensure that the ''spamd''user has permission to create the databases in the directory named in &amp;lt;tt&amp;gt;bayes_path&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Sitewide Autowhitelisting ===&lt;br /&gt;
&lt;br /&gt;
Adding autowhitelisting is just as easy. Add the usual SpamAssassin &amp;lt;tt&amp;gt;auto_whitelist_path&amp;lt;/tt&amp;gt; directive to ''local.cf'', and if you're using SpamAssassin 2.63, invoke &amp;lt;tt&amp;gt;spamd&amp;lt;/tt&amp;gt; with the &amp;lt;tt&amp;gt;--auto-whitelist&amp;lt;/tt&amp;gt; option (which is unnecessary in SpamAssassin 3.0). As with the Bayesian databases, the ''spamd'' user must have permission to create the autowhitelist database and read and write to it.&lt;br /&gt;
&lt;br /&gt;
=== Routing Email Through the Gateway ===&lt;br /&gt;
&lt;br /&gt;
Once you have qmail and qmail-scanner receiving messages for the local host and performing SpamAssassin checks on them, you can start accepting email for your domain and routing it to an internal mail server after spam-checking. [[SpamAssassin/Integrating SpamAssassin with qmail#spamassassin-CHP-7-FIG-3|Figure 7-3]] illustrates this topology.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;spamassassin-CHP-7-FIG-3&amp;quot;&amp;gt;&lt;br /&gt;
'''Figure 7-3. Spam-checking gateway topology'''&lt;br /&gt;
&lt;br /&gt;
[[Image:SpamAssassin_I_7_tt139.png|Spam-checking gateway topology]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following sections describe the changes you need to make to implement the topology shown in [[SpamAssassin/Integrating SpamAssassin with qmail#spamassassin-CHP-7-FIG-3|Figure 7-3]].&lt;br /&gt;
&lt;br /&gt;
==== qmail changes ====&lt;br /&gt;
&lt;br /&gt;
To configure qmail to relay incoming mail for ''example.com'' to ''internal.example.com'', add the following line to ''/var/qmail/control/rcpthosts'':&lt;br /&gt;
&lt;br /&gt;
 example.com&lt;br /&gt;
&lt;br /&gt;
Then, create the ''/var/qmail/control/smtproutes'' file, and add either:&lt;br /&gt;
&lt;br /&gt;
 example.com:internal.example.com&lt;br /&gt;
&lt;br /&gt;
or, if ''mail.example.com'' can look up an (internal) MX record for ''example.com'' that points to ''internal.example.com'' (and possibly other internal mail servers), you could use&lt;br /&gt;
&lt;br /&gt;
 example.com:&lt;br /&gt;
&lt;br /&gt;
==== Routing changes ====&lt;br /&gt;
&lt;br /&gt;
Mail from the Internet for ''example.com'' should be sent to the spam-checking gateway ''mail.example.com''. Add a DNS MX record for the ''example.com'' domain that points to ''mail.example.com''.&lt;br /&gt;
&lt;br /&gt;
Once received by ''mail.example.com'', messages will be spam-checked and should then be relayed to ''internal.example.com'' by qmail. No DNS records for ''internal.example.com'' need be published to the Internet, but it's necessary that ''mail.example.com'' can resolve ''internal.example.com''.&lt;br /&gt;
&lt;br /&gt;
==== Internal server configuration ====&lt;br /&gt;
&lt;br /&gt;
Once the external mail gateway is in place, you can configure the internal mail server to accept SMTP connections only from the gateway (for incoming Internet mail). If you don't have a separate server for outgoing mail, the internal mail server should also accept SMTP connections from hosts on the internal network. These restrictions are usually enforced by limiting access to TCP port 25 using a host-based firewall or a packet-filtering router.&lt;/div&gt;</description>
			<pubDate>Fri, 07 Mar 2008 10:53:32 GMT</pubDate>			<dc:creator>Docbook2Wiki</dc:creator>			<comments>http://commons.oreilly.com/wiki/index.php/Talk:SpamAssassin/Integrating_SpamAssassin_with_qmail</comments>		</item>
	</channel>
</rss>