You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@spamassassin.apache.org by Adi <ad...@gmail.com> on 2014/07/18 22:59:32 UTC

Adding header depending on _SCORE_ and settings UserPref

Hello

I have Spamassassin 3.4 + Exim with router using spamc and exim pipe
(before that remove possible X_SPAM* headers in incoming mails).

SpamAssassin UserPref is in MySQL database.


How can I do that - is it possible? :
1. User set in table userpref variable: kill_spam_score = 17
   (this is not required_hits = mark and move to .SPAM folder)
   Any user can set different value.

2. In Spamassassin I need compare if _SCORE_ > kill_spam_score
   then add header X_Spam_Remove  or X_Spam_Kill

3. In exim make router that check if X_Spam_Kill exists and
   move mail to /dev/null.



If it is not possible I can try make Exim's router,
parse X-Spam-Status compare score directly from SQL result.
But probably better is make it in SA

What do you think about it?


Normaly I used to directly spamd in ACL Exim sections and drop
mail with too high SPAM score, But I want try much flexible solution
with userPrefs.


Thank you for your time.

Best Regards.

Re: Adding header depending on _SCORE_ and settings UserPref

Posted by Adi <ad...@gmail.com>.
Hello

Thanks for answer.

>> Not yet. if I'm not mistaken amavis is working in delivery time not
>> SMTP time?
> 
> AFAIK, it can run in pre-queue mode too. Surely when running as milter.
> and IIRC it runs at SMTP time by default.

For now I'll leave "my" solution with exec spamc in Exim's transport
(by pipe - second process of Exim). It's working good.

I will back to the topic if have more time.

another option to solve this in Exim may be PRDR
(Per-Recipient-Data-Response). Become stable in new 4.83 (in Freebsd
ports).

http://www.eric-a-hall.com/specs/draft-hall-prdr-00.txt

I must read this and test it.

>> Yes this is concept but how can I detect is it single or multi
>> recipient? AND if it is multi recipient I can not reject mail in SMTP
>> time.
> 
> oh yes, you can - with sane defaults, e.g. when final score is over 10 (or
> whatever you configure)

OK. But what if some user want get SPAM, could become unhappy if I
blocked him this opportunity :)


Best Regards.

Re: Adding header depending on _SCORE_ and settings UserPref

Posted by Matus UHLAR - fantomas <uh...@fantomas.sk>.
>> Have you tried the amavis/sa-exim way?

On 20.07.14 15:22, Adi wrote:
>Not yet. if I'm not mistaken amavis is working in delivery time not
>SMTP time?

AFAIK, it can run in pre-queue mode too. Surely when running as milter.
and IIRC it runs at SMTP time by default.

>>> Some my configuration is based on:
>>>
>>> http://www.janoszen.com/2013/07/24/filtering-spam-with-exim-and-spamassassin-properly/
>>
>> I looked onto that and did not like it. Mostly because it does not run at
>> the SMTP time...
>
>yes , but I SMTP time I can't analize spam according user prefs - for
>multi recipient :/

yes, that's feature of SMTP.
That's why I advised you multiple times using sane defaults in such case.

>> you can do two checks, one at SMTP time (with sane defaults), and second
>> (user-personalized) at delivery time.
>> single recipient e-mails can be scanned with user preferences at SMTP time
>> and you can skip the latter step for them.
>> Of course, spam rejected at SMTP time won't be scanned with per-user
>> settings...
>
>Yes this is concept but how can I detect is it single or multi
>recipient? AND if it is multi recipient I can not reject mail in SMTP
>time.

oh yes, you can - with sane defaults, e.g. when final score is over 10 (or
whatever you configure)

-- 
Matus UHLAR - fantomas, uhlar@fantomas.sk ; http://www.fantomas.sk/
Warning: I wish NOT to receive e-mail advertising to this address.
Varovanie: na tuto adresu chcem NEDOSTAVAT akukolvek reklamnu postu.
"The box said 'Requires Windows 95 or better', so I bought a Macintosh".

Re: Adding header depending on _SCORE_ and settings UserPref

Posted by Adi <ad...@gmail.com>.
Hello

Thanks for answer.

> Have you tried the amavis/sa-exim way?

Not yet. if I'm not mistaken amavis is working in delivery time not
SMTP time?

>
>> Some my configuration is based on:
>>
>> http://www.janoszen.com/2013/07/24/filtering-spam-with-exim-and-spamassassin-properly/
> 
> I looked onto that and did not like it. Mostly because it does not run at
> the SMTP time...

yes , but I SMTP time I can't analize spam according user prefs - for
multi recipient :/


> you can do two checks, one at SMTP time (with sane defaults), and second
> (user-personalized) at delivery time.
> single recipient e-mails can be scanned with user preferences at SMTP time
> and you can skip the latter step for them.
> Of course, spam rejected at SMTP time won't be scanned with per-user
> settings...

Yes this is concept but how can I detect is it single or multi
recipient? AND if it is multi recipient I can not reject mail in SMTP
time.



Best Regards





Re: Adding header depending on _SCORE_ and settings UserPref

Posted by Matus UHLAR - fantomas <uh...@fantomas.sk>.
>>> 3. In exim make router that check if X_Spam_Kill exists and
>>>    move mail to /dev/null.
>>
>> As Matus already mentioned, don't plain drop it. SMTP reject is proper
>> handling.

On 20.07.14 10:52, Adi wrote:
>Yes SMTP reject is proper. And normally is can be done in ACL by
>"deny" options.

>But I must do it probably much later in router/transport.
>Because my configuration is different: for each recipient pipe
>spamc and pipe additional process exim to Mailbox.

Have you tried the amavis/sa-exim way?

>Some my configuration is based on:
>
>http://www.janoszen.com/2013/07/24/filtering-spam-with-exim-and-spamassassin-properly/

I looked onto that and did not like it. Mostly because it does not run at
the SMTP time...

>In normal Exim's configuration mail will be analized by SA only once
>(only for TO: address - I must check if all user prefs is readed and
>used in this case).
>
>So, I can:
>1. not worry about the messages with multiple recipients
>   and use simple building ACL options in Exim. Fast and easy to
>   configure.
>
>
>2. try do it properly for multiple recipients mails. But there are
>   many problems. Is slower, hard to configure (example reject email:)

you can do two checks, one at SMTP time (with sane defaults), and second
(user-personalized) at delivery time.
single recipient e-mails can be scanned with user preferences at SMTP time
and you can skip the latter step for them.
Of course, spam rejected at SMTP time won't be scanned with per-user
settings...

-- 
Matus UHLAR - fantomas, uhlar@fantomas.sk ; http://www.fantomas.sk/
Warning: I wish NOT to receive e-mail advertising to this address.
Varovanie: na tuto adresu chcem NEDOSTAVAT akukolvek reklamnu postu.
Fucking windows! Bring Bill Gates! (Southpark the movie)

Re: Adding header depending on _SCORE_ and settings UserPref

Posted by Adi <ad...@gmail.com>.
Hello

Thank you for answer.

>> 2. In Spamassassin I need compare if _SCORE_ > kill_spam_score
>>    then add header X_Spam_Remove  or X_Spam_Kill
> 
> Adding a custom header (or any action for that matter) depending on the
> overall score requires writing a custom plugin.
> 

It looks like :(

I'll have to work on that.


In the meantime, I will use a fixed value, eg 20 and I will compare in
Exim based on X-Spam-Status: Yes, score=32.1

> 
>> 3. In exim make router that check if X_Spam_Kill exists and
>>    move mail to /dev/null.
> 
> As Matus already mentioned, don't plain drop it. SMTP reject is proper
> handling.

Yes SMTP reject is proper. And normally is can be done in ACL by
"deny" options.


But I must do it probably much later in router/transport.
Because my configuration is different: for each recipient pipe
spamc and pipe additional process exim to Mailbox.


Some my configuration is based on:

http://www.janoszen.com/2013/07/24/filtering-spam-with-exim-and-spamassassin-properly/



I can't find info how reject mail in router/transport only info that
should be done in ACL.


Above configuration have advance that if incoming mail have CC, BCC
then each recipient will be process by spamc -u user@mail with own:
userpref (include white/black list), bayes and awl.

In normal Exim's configuration mail will be analized by SA only once
(only for TO: address - I must check if all user prefs is readed and
used in this case).

So, I can:
1. not worry about the messages with multiple recipients
   and use simple building ACL options in Exim. Fast and easy to
   configure.


2. try do it properly for multiple recipients mails. But there are
   many problems. Is slower, hard to configure (example reject email:)

What do you think about?


Best Regards



Re: Adding header depending on _SCORE_ and settings UserPref

Posted by Karsten Bräckelmann <gu...@rudersport.de>.
On Fri, 2014-07-18 at 22:59 +0200, Adi wrote:
> 1. User set in table userpref variable: kill_spam_score = 17
>    (this is not required_hits = mark and move to .SPAM folder)
>    Any user can set different value.
> 
> 2. In Spamassassin I need compare if _SCORE_ > kill_spam_score
>    then add header X_Spam_Remove  or X_Spam_Kill

Adding a custom header (or any action for that matter) depending on the
overall score requires writing a custom plugin.


> 3. In exim make router that check if X_Spam_Kill exists and
>    move mail to /dev/null.

As Matus already mentioned, don't plain drop it. SMTP reject is proper
handling.


-- 
char *t="\10pse\0r\0dtu\0.@ghno\x4e\xc8\x79\xf4\xab\x51\x8a\x10\xf4\xf4\xc4";
main(){ char h,m=h=*t++,*x=t+2*h,c,i,l=*x,s=0; for (i=0;i<l;i++){ i%8? c<<=1:
(c=*++x); c&128 && (s+=h); if (!(h>>=1)||!t[s+h]){ putchar(t[s]);h=m;s=0; }}}


Re: Adding header depending on _SCORE_ and settings UserPref

Posted by Adi <ad...@gmail.com>.
Hello


Thank you for answer.

>> If I'm not mistaken, this solution does NOT support UserPref settings ???
> 
> no idea, but some may do.
> 

I must check it. is it reading usepref (maybe for first recipient).

>> Especially if the incoming message is addressed to a few people.
> 
> Technically not possible. in case of one message to multiple recipients it's
> only possible to accept it or reject it (use sane default values).

Standard exim procedure check only once spam and then I can deny or
accept.

If SA is run by router, for each recipient start another exim process
and check spamc. SA is working on user (recipient) userprefs. It is
much slower (special if recipient is > 1) that standard SA procedure
(in ACL) in Exim.

But I think is more flex for user :)

Yes I can reject/deny mail if is very high score but:
1. I don't know how do that in router (not in ACL by "deny")
2. Still I don't know how flag message as "Spam_kill" in Spamassassin

> the "spam" directory is a good idea, e.g. with courier's imap and its
> emptytrash feature (set to 91 at my former employer)


yes.

1. Normally if mail _SCORE_ > required_score set by user mail
   is moved to user .SPAM folder.

2. But additional I want make deffault setting kill_score = 20
   - user can change it for ex. kill_score = 9999 if user don't want
   delete/reject anything. Or to kill_score=7 if want reject
   many SPAM mails.

   This is my idea.

   And if  _SCORE_ > kill_score (set by user) - exim do action
   delete (move to dev/null) or deny/reject (If is possible is better
   :)

Best Regards.

Re: Adding header depending on _SCORE_ and settings UserPref

Posted by Matus UHLAR - fantomas <uh...@fantomas.sk>.
>>> 3. In exim make router that check if X_Spam_Kill exists and
>>>   move mail to /dev/null.
>>
>> you should reject the mail instead. see the programs above.

On 19.07.14 17:29, Adi wrote:
>If I'm not mistaken, this solution does NOT support UserPref settings ???

no idea, but some may do.

>Especially if the incoming message is addressed to a few people.

Technically not possible. in case of one message to multiple recipients it's
only possible to accept it or reject it (use sane default values).

Rejecting it (in safe case, e.g.  score over 10) is still better than
acepting mail and trowing it away (imho, if you accept the mail, you should
keep track, just for sure, so it doesn't get lost in /dev/null).

the "spam" directory is a good idea, e.g. with courier's imap and its
emptytrash feature (set to 91 at my former employer)
-- 
Matus UHLAR - fantomas, uhlar@fantomas.sk ; http://www.fantomas.sk/
Warning: I wish NOT to receive e-mail advertising to this address.
Varovanie: na tuto adresu chcem NEDOSTAVAT akukolvek reklamnu postu.
"Two words: Windows survives." - Craig Mundie, Microsoft senior strategist
"So does syphillis. Good thing we have penicillin." - Matthew Alton

Re: Adding header depending on _SCORE_ and settings UserPref

Posted by Adi <ad...@gmail.com>.
Hello

>>
>> 2. In Spamassassin I need compare if _SCORE_ > kill_spam_score
>>   then add header X_Spam_Remove  or X_Spam_Kill
> 
> while this is possible, there's no useful use for this.
> There are already middleware programs between SA and various MTAs
> - amavisd-new, sa-exim...
> seems exim has content scanning extension...
> 
> 
>> 3. In exim make router that check if X_Spam_Kill exists and
>>   move mail to /dev/null.
> 
> you should reject the mail instead. see the programs above.


I used earlier appeal directly by Exim SA support, during acl_check_data.
For example:
deny
        condition = ${if >{$spam_score_int}{160}{1}{0}}
        spam = spamd:true


If I'm not mistaken, this solution does NOT support UserPref settings ???
Especially if the incoming message is addressed to a few people.


By using a router, with
spamcheck:
    no_verify
    driver         = accept
    condition      = ${if and {\
                    {eq {$authenticated_id}{}}\
                    {!eq {$received_protocol}{spam-scanned}}\
                     {<{$message_size}{250k}}\
                       } }
    headers_remove =
X-Spam-Flag:X-Spam-Report:X-Spam-Status:X-Spam-Level:X-Spam-Checker-Version
    transport = spam_check



and transport with pipe
spam_check:
    driver            = pipe
    command           = /usr/local/sbin/exim -oMr spam-scanned -bS
    use_bsmtp
    transport_filter  = /usr/local/bin/spamc -U
/var/run/spamd/spamd.socket -u $local_part@$domain
    home_directory    = /tmp
    current_directory = /tmp


each recipient can have its own rules and its own SA score.
So next my other router detect is
{def:h_X-Spam-Flag:}\
{eq {$h_X-Spam-Flag:}{YES}}\

and by SPAM transport move messages to user SPAM folder.


Best Regards.


Re: Adding header depending on _SCORE_ and settings UserPref

Posted by Matus UHLAR - fantomas <uh...@fantomas.sk>.
On 18.07.14 22:59, Adi wrote:
>How can I do that - is it possible? :
>1. User set in table userpref variable: kill_spam_score = 17
>   (this is not required_hits = mark and move to .SPAM folder)
>   Any user can set different value.
>
>2. In Spamassassin I need compare if _SCORE_ > kill_spam_score
>   then add header X_Spam_Remove  or X_Spam_Kill

while this is possible, there's no useful use for this.
There are already middleware programs between SA and various MTAs
- amavisd-new, sa-exim...
seems exim has content scanning extension...


>3. In exim make router that check if X_Spam_Kill exists and
>   move mail to /dev/null.

you should reject the mail instead. see the programs above.

-- 
Matus UHLAR - fantomas, uhlar@fantomas.sk ; http://www.fantomas.sk/
Warning: I wish NOT to receive e-mail advertising to this address.
Varovanie: na tuto adresu chcem NEDOSTAVAT akukolvek reklamnu postu.
Emacs is a complicated operating system without good text editor.