Postfix, dovecot, spamassassin SPAM to a spam folder
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Postfix, dovecot, spamassassin SPAM to a spam folder
My mail gets a [SPAM] prefix, but I need it to automatically go to a SPAM folder on the servers. I am fedora core 6 with postfix, dovecot, spamassassin,
my master.cf file has
smtp inet n - n - - smtpd
-o content_filter=spamfilter:dummy
#
maildrop unix - n n - - pipe
flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}
#
# The Cyrus deliver program has changed incompatibly, multiple times.
#
spamfilter unix - n n - - pipe
flags=Rq user=spamfilter argv=/usr/local/bin/spamfilter -f ${sender} -- ${recipient}
in my /etc/mail/spamassassin dir I have
local.cf =
required_hits 5
rewrite_header Subject [SPAM]
report_safe 0
So what do I need to do to get spamassassin to move the messages with [SPAM] to the SPAM folder for each user? I need to do this on the server. I tried to use the sa-learn command but that did nothing as far as transferring future messages. Is my local.cf file correct to have spamassassin learn? Is there something I need in my postfix configuration?
Scott
smtp unix - - n - - smtp
# When relaying mail as backup MX, disable fallback_relay to avoid MX loops
relay unix - - n - - smtp
-o fallback_relay=
I use a address extension for spam, which integrates nicely if you use amavis-new between postfix and spamassissan, but not sure if you don't. The other alternaitive is to use a delivery agent like maildrop or procmail.
I also use maildrop, have a look at http://www.postfix.org/MAILDROP_README.html. Looks like you are most of the way there and will simply need a .mailfilter in the user's home directory to do the pattern matching
cd mail
[scott@streit mail]$ tree
.
|-- Drafts
|-- SPAM
|-- Sent
|-- Sent Items
`-- Trash
0 directories, 5 files
[scott@streit mail]$
[scott@streit mail]$ ls -al
total 80
drwx------ 3 scott scott 4096 Feb 10 18:56 .
drwx------ 47 scott scott 4096 Feb 12 20:26 ..
-rw------- 1 scott scott 0 Feb 10 14:56 Drafts
drwx------ 8 scott scott 4096 Feb 10 18:57 .imap
-rw------- 1 scott scott 0 Feb 10 14:56 Sent
-rw------- 1 scott scott 0 Feb 10 18:56 Sent Items
-rw------- 1 scott scott 31810 Feb 10 19:46 SPAM
-rw------- 1 scott scott 40 Feb 10 18:56 .subscriptions
-rw------- 1 scott scott 562 Feb 10 16:24 Trash
[scott@streit mail]$
I have tried many permutations in the .mailfilter file without a difference.
Still it goes to the inbox. In squirelmail I created the SPAM folder, how is it referenced in .mailfilter. Is it SPAM mail/SPAM mail/SPAM??? How do I find this out? When I loaded dovecot, I ended up with a .imap folder, how do these play together? How can I tell if my .mailfilter is being called and what is mbox or maildir?
I reconfigured postfix and dovecot to use Maildir. That is working. My mail filter is still not being called, or is incorrect. Here is my directory.
[scott@streit ~]$ ls -al Maildir/
total 76
drwxrwxr-x 9 scott scott 4096 Feb 14 12:08 .
drwx------ 47 scott scott 4096 Feb 14 12:08 ..
drwx------ 2 scott scott 4096 Feb 14 12:08 cur
-rw------- 1 scott scott 252 Feb 14 12:08 dovecot.index
-rw------- 1 scott scott 19456 Feb 14 12:08 dovecot.index.cache
-rw------- 1 scott scott 2088 Feb 14 12:08 dovecot.index.log
-rw------- 1 scott scott 519 Feb 14 12:08 dovecot-uidlist
drwx------ 5 scott scott 4096 Feb 14 11:47 .Drafts
drwx------ 2 scott scott 4096 Feb 14 12:08 new
drwx------ 5 scott scott 4096 Feb 14 11:47 .Sent
drwx------ 5 scott scott 4096 Feb 14 12:03 .Spam
-rw------- 1 scott scott 23 Feb 14 11:59 subscriptions
drwx------ 2 scott scott 4096 Feb 14 12:08 tmp
drwx------ 5 scott scott 4096 Feb 14 11:47 .Trash
[
My filter is
[scott@streit ~]$ more .mailfilter
if ( /^"Subject:.*[SPAM]/ )
to Maildir/.SPAM
1. Check the maillogs to ensure that maildrop is being called. i assume siomething shows up there
2. in case [ & ] are special characters or need escaping, try taking them out of the pattern
3. I think you need the full path for a maildir, so /home/user/Maildir/.SPAM
I checked and both [ and ] are special characters in maildrop patters, so you either need to escape them or drop them (http://www.courier-mta.org/?maildropfilter.html). Since you are unlikely to have SPAM in a genuine subject line, I'd just drop them
> I got an error in the maillog and no delivery. Here is the error:
>
>
> Feb 14 21:27:44 streit maildrop[11750]: Temporary authentication failure.
> Feb 14 21:27:44 streit postfix/local[11669]: 1959F5A6C10:
> to= , orig_to= ,
> relay=local, delay=5.4, delays=5.4/0/0/0.01, dsn=4.3.0, status=deferred
> (temporary failure. Command output: ERR: authdaemon: s_connect() failed:
> Permission denied /usr/bin/maildrop: Temporary authentication failure. )
> Feb 14 21:27:45 streit dovecot: imap-login: Login: user= ,
> method=PLAIN, rip=::ffff:127.0.0.1, lip=::ffff:127.0.0.1, secured
> Feb 14 21:27:45 streit dovecot: IMAP(scott): Disconnected: Logged out
>
I started with the following permissions on /var/spool/postfix
[root@streit postfix]# ls -al
total 128
drwxr-xr-x 16 root root 4096 Nov 3 08:20 .
drwxr-xr-x 14 root root 4096 Feb 14 21:23 ..
drwx------ 2 postfix root 4096 Feb 15 12:25 active
drwx------ 2 postfix root 4096 Feb 15 05:23 bounce
drwx------ 2 postfix root 4096 Sep 1 12:47 corrupt
drwx------ 18 postfix root 4096 Nov 8 17:42 defer
drwx------ 18 postfix root 4096 Nov 8 17:42 deferred
drwx------ 2 postfix root 4096 Feb 14 21:26 flush
drwx------ 2 postfix root 4096 Sep 1 12:47 hold
drwx------ 2 postfix root 4096 Feb 15 12:25 incoming
drwx-wx--- 2 postfix postdrop 4096 Feb 15 12:20 maildrop
drwxr-xr-x 2 root root 4096 Feb 14 21:26 pid
drwx------ 2 postfix root 4096 Feb 15 10:28 private
drwx--x--- 2 postfix postdrop 4096 Feb 15 10:28 public
drwx------ 2 postfix root 4096 Sep 1 12:47 saved
drwx------ 2 postfix root 4096 Sep 1 12:47 trace
[root@streit postfix]#
I changed it to
[root@streit postfix]# ls -al
total 128
drwxr-xr-x 16 root root 4096 Nov 3 08:20 .
drwxr-xr-x 14 root root 4096 Feb 14 21:23 ..
drwx------ 2 postfix root 4096 Feb 15 12:45 active
drwx------ 2 postfix root 4096 Feb 15 05:23 bounce
drwx------ 2 postfix root 4096 Sep 1 12:47 corrupt
drwx------ 18 postfix root 4096 Nov 8 17:42 defer
drwx------ 18 postfix root 4096 Nov 8 17:42 deferred
drwx------ 2 postfix root 4096 Feb 14 21:26 flush
drwx------ 2 postfix root 4096 Sep 1 12:47 hold
drwx------ 2 postfix root 4096 Feb 15 12:45 incoming
drwxrwsrwx 2 postfix postdrop 4096 Feb 15 12:45 maildrop
drwxr-xr-x 2 root root 4096 Feb 14 21:26 pid
drwx------ 2 postfix root 4096 Feb 15 12:44 private
drwxrwsrwx 2 postfix postdrop 4096 Feb 15 12:44 public
drwx------ 2 postfix root 4096 Sep 1 12:47 saved
drwx------ 2 postfix root 4096 Sep 1 12:47 trace
trying to take a broad approach, and still got the same error. What I did was consistent with the reference you gave me. Do you see any holes in what I did.
I also tried to change the permission to /usr/lib/maildrop to
[root@streit bin]# ls -al maildrop
-rwxr-xr-x 1 postfix mail 184600 Dec 30 20:16 maildrop
[root@streit bin]# chmod +S maildrop
chmod: invalid mode: `+S'
Try `chmod --help' for more information.
[root@streit bin]# chmod +s maildrop
[root@streit bin]# ls -al maildrop
-rwsr-sr-x 1 postfix mail 184600 Dec 30 20:16 maildrop
[root@streit bin]#
Assuming it's looking for the correct user, are the permissions for .mailfilter consistent with the user (should be owner by the relevant user and I think wxr for that user
Last edited by billymayday; 02-16-2007 at 01:31 AM.
I don't think it's .mailfilter permissions - I tried stuffing mine up and I get a different error
Here are my maildrop permissions
-rwxr-xr-x 1 root mail 824389 May 3 2006 /usr/local/bin/maildrop
If there's something weird going on with usernames getting dropped, try disabling maildrop for a moment and see if mail is getting delivered - at least you'll know for sure where the problem is. just comment out mailbox_command line in main.cf
Last edited by billymayday; 02-16-2007 at 01:33 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.