I have a mail server running Exim and Dovecot, backed by MySQL for virtual users. Spamassassin is configured and seems to be working reasonably, but sending flagged spams to a "spam" dir for the recipient is not configured. We are using the maildir format for storage.

How would I go about processing where mails are to be delivered to? I would have thought procmail could do this, but I don't see any decent configs for this particular setup.

In short: - Exim - Spamassassin - Virtual Users, root of each user = /home/mail/$domain/$local_part - Want to deliver spams to /home/mail/$domain/$local_part/spam/ for example



Here's something that should work ok. I've based it off the standard "local delivery" router/transports, but added in conditions on the X-Spam-Flag header, which I'm setting earlier in the relevant ACL. If you don't know how to do that, let me know and I'll amend the answer.

I do something similar, but at a domain level, and my setup probably won't work too well for you.

First of all, you need a router. Routers are processed in order, so put this somewhere suitable - generally before you catch normal mail, because that will take precedence.

 debug_print = "R: spamcheck for $local_part@$domain"
 driver = accept
 user = mail
 condition = "${if def:h_X-Spam-Flag: {yes}{no}}"
 transport = local_spam_delivery

Now you need a local_spam_delivery transport, so put this anywhere in your transports section:

 debug_print = "T: local_spam_delivery for $local_part@$domain"
 driver = appendfile
 directory = /home/mail/$domain/$local_part/spam/

If you don't want it as a maildir, remove the maildir_format command. You may have to tweak the rules a bit, especially regarding user and group settings etc.

If there is something missing in my above example, I notice there's a similar example documented here

| improve this answer | |

You could do this easily with a couple of routers. Alternatively, you can use an exim filter file to do it.

I have the following in my ~/.forward, but you could easily use something similar for your global filter file.

if $spam_score_int is not "" then
   if $spam_score_int is above 49 then save $home/Maildir/.SPAM/ finish endif

Using your path should work. Just replace replace it in the example and don't forget the trailing slash or you may end up delivering to mbox format.

| improve this answer | |

I came up with the following to send spam to a maildir called "Junk" for each domain.

   driver = appendfile
   directory = "${if and { {def:h_X-Spam-Flag:} {eq {$h_X-Spam-Flag}{YES}}} {/home/mail/${domain}/${local_part}/.Junk}{/home/mail/${domain}/${local_part}} }"

I guess I was thinking about it too hard when I originally posted the question. The above appears to be working quite well. I will accept Daniel's answer though.

| improve this answer | |
  • Why, because he wrote the most? – dubRun Sep 4 '09 at 1:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.