Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

TIA

share|improve this question

3 Answers 3

up vote 2 down vote accepted

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.

spamcheck:
 debug_print = "R: spamcheck for $local_part@$domain"
 driver = accept
 check_local_user
 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:

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

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

share|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
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.

share|improve this answer

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

mysql_delivery:
   driver = appendfile
   maildir_format
   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.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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