adding headers to all mails with spamassassin
hi!
i've followed this instructions: http://docs.sun.com/source/819-0105/anti-spam.html#wp45386
to configure spasassassin and is working fine.
i want to know the score for all my mails not only the ones detected as spam so i want to enable headers for all mails.
is there a way to do it?
regards
[333 byte] By [
abosch] at [2007-11-26 10:53:27]

# 1
not that I know of.You can manually submit any mail you like to SA, and get a score.
# 2
i also wanted to do this, and asked on the arnold list as advised.
here is some of the conversation, though i never tried to get this to work - it seemed too complex.
the idea of seeing the header, no matter the score is helpful in tuning SA (and also to satisfy curiosity).
http://forum.sun.com/jive/thread.jspa?forumID=15&threadID=59739
- --
i'd like all messages to have the X-Spam-Level header (regardless of
their spam score), but still have the spam ones go into the spam folder, with the subject modified.
my implementation (6.2-3.04) only adds the X-Spam-Level header when it
is spam (and also tags the subject and files into the SPAM folder).
i received a response here recently to the same question:
>Try something like
>http://docs.sun.com/app/docs/doc/819-2650/6n4u4dtrb?a=view
>i.e. only set the spam score in spamfilter_string_action, interpret that
>value later in other Sieve filters, and take different actions according
>to the score. (The addheader may remain in _string_action; I don't think
>it matters where it will end up.)
>It might seem simpler to check the added header in the other Sieve
>scripts, but it won't work because of the way Sieve filters are applied.
but could do with an example.
# 3
Hi,
After a lot of stuffing around I finally managed to get a configuration that fulfills your requirements. You can customise the sieve filter to add the appropriate header - I used Spam-test in this case - and to relocate to the appropriate spam folder - I used the 'spam' folder in this case.
These steps assume that you have spamassassin filtering running already.
1. Add "sourcespamfilter1optin spam" to the tcp_local channel.
2. Add the following to option.dat:
spamfilter1_config_file=/opt/SUNWmsgsrv/config/spamassassin.opt
spamfilter1_library=/opt/SUNWmsgsrv/lib/libspamass.so
spamfilter1_optional=1
spamfilter1_string_action=data:, \
require ["spamtest","relational","comparator-i;ascii-numeric","fileinto","addheader"]; \
spamadjust "$U"; addheader "Spam-Test: $U"; \
if spamtest :value "ge" :comparator "i;ascii-numeric" "5" {fileinto "spam";} \
else {keep;}
3. Add the following to /opt/SUNWmsgsrv/config/spamassassin.opt
!enable debug of spamassassin if set to 1
debug=0
!host/interface spamd process is listening on
host=localhost
! This port setting should match what spamd listens on, by default its 783
port=783
!return a result regardless of whether spam or not
mode=2
!need to have an empty field, otherwise spamadjust "$U" doesn't work
field=
!verdict not used with mode=2
verdict=
Regards,
Shane.
# 4
thanks for this example - haven't had time to try it. when you say SA should be up - would your example replace (or work along side of) a configuration which currently only tags messages above the spam threshold and moves them to a folder ...thanks,s7
# 5
Hi,
This example would replace your current configuration - but you could customise the example to process emails how you like. The secret is in the use of "mode=2" to always call the spamfilter sieve rule and the use of the spamtest/spamadjust sieve actions.
The example provided will add a 'Spam-test: [True|False];<spam-score>/<spam threshold>' header to all emails (including ham emails as you requested), moving spam emails (ones with a score of 5 or more) to a "spam" folder.
You could also customise the filter provided to say discard emails that score greater then 10 (which is also pretty common).
Regards,
Shane.
# 6
thanks again - you have piqued my curiosity - how would you discard spam above 10? in addition to tagging each, and filing all else under 10 to the spam folder?do you add the spam header on ham too? how do you deal with spam in general?
# 7
Hi,
Unfortunately due to a limit in the size of the argument to the spamfilter1_string_action parameter the sieve filter that does the heavy lifting has been moved to a channel level sieve.
So to discard the email over 10, tag emails below 10 (ham & spam) and file emails from 5-10 into a spam folder you need to do the following:
Replace the previous spamfilter1_string_action with:
spamfilter1_string_action=data:, require ["addheader","spamtest"]; \
spamadjust "$U"; addheader "Spam-test: $U"
Create a file called spamassassin.filter in your msg_base/config/ directory and add the following:
require ["spamtest","relational","comparator-i;ascii-numeric","fileinto"];
if spamtest :value "ge" :comparator "i;ascii-numeric" "10" {discard;}
elsif spamtest :value "ge" :comparator "i;ascii-numeric" "5" {fileinto "spam";}
else {keep;}
Add the following in your imta.cnf file to the ims-ms channel definition:
destinationfilter file:IMTA_TABLE:spamassassin.filter
>do you add the spam header on ham too?
Yes. ALL scanned emails gets a header added - no harm really.
>how do you deal with spam in general?
At my previous employee we did what was listed above. Discard spam > 10, tag all emails with the score and filter emails into a spam folder for those emails between 5 and 10 (actually this was customisable/user but that means having a different sieve filter/user and you need to write a custom admin interface for that - most users used the default level to filter into a spam folder).
Also make sure you write an expiry rule for the spam folder so that the spam emails don't build up and consume a users quota e.g. expire emails in the spam folder greater then 30 days.
Regards,
Shane.
# 8
thanks - what about seeing exactly which rules are triggered (in the header as well, for both filed spam and delivered ham - and discarded spam)? i remember this was possible in a milter implementation i had going with sendmail and fetchmail on freebsd ...s7
# 9
Hi,
As I noted earlier, the $U substitution occurs prior to the rule being evaluated, and given that the entire length of the spamfilter1_string_action is currently limited to 256 characters, if you were to pass in a whole bunch of rules hit (via $U) it would exceed the limit.
For future reference though you set use_check=0 in the spamassassin.opt file to return the rules hit, this will give you a header like the following:
Spam-test:False ; 0.2 / 5.0 ; ALL_TRUSTED,MISSING_HEADERS,MISSING_SUBJECT,TO_CC_NONE
Regards,
Shane.
# 10
I tried the above example, changed the messaging path to use /opt//SUNWmsgsr/ ... as in my system, (ran imsimta cnbuild, restarted servers), but it didn't completely work. I sent a test spam (anti-ube string) from another system, and it comes through. Nothing gets filedinto, no subject modification. Though I do see the Spam-testTrue ; 997.7 / 5.0 header. How should i debug?
my spam folder is called SPAM not spam - would that matter?
Thanks,
S.7.
Sun Java(tm) System Messaging Server 6.2-7.05 (built Sep 5 2006)
libimta.so 6.2-7.05 (built 12:18:44, Sep 5 2006)
SunOS mail 5.9 Generic_118558-21 sun4u sparc SUNW,Ultra-60
# 11
Fileinto, if done by a sieve rule requires that the folder being filed into have aci permissions set so that "others" can write to the folder.Did you set that?
# 12
hi jay - no i didn't. how can i set the aci permissions to allow this on everyone's SPAM folder. from a previous post, i see i could use the DS console ... any details? you also said it could be done in webmail, does this mean share the spam folder - would that be sufficient (which perms: read, read write, read/write manage, for anyone, or anyone@mydomanin.com)?
p.s. when i try the initial example (for writing headers on all mail but only filing actual spam) it seems to work, but i see the spam-test header twice - is it looping (or being evaluated twice -maybe on another channel)? what's really odd is sometimes the first one is false, and the second one is true - i wonder if it were reversed, would the message not be filed?
when i addtag - here is how the message appears in my spam folder (note score discrepency - which corresponds exactly to the two different Spam-test scores as above) - sometimes the placement of the tag is jumbled too... e.g. the score and tag will come after the subject, etc.
Space Monkey 998.7 [SPAM detected True ; 997.5 / 5.0] test
i should mention, as i look back on my older spam (from my original config, which files spam, and only writes headers on spam) the header was being written twice as well, the subject tags in these are also sometimes jumbled.
thanks,
s7
.
# 13
> hi jay - no i didn't. how can i set the aci
> permissions to allow this on everyone's SPAM folder.
> from a previous post, i see i could use the DS
> console ... any details? you also said it could be
> done in webmail, does this mean share the spam folder
> - would that be sufficient (which perms: read, read
> write, read/write manage, for anyone, or
> anyone@mydomanin.com)?
Write is what you need. For the Messaging Server.
>
> p.s. when i try the initial example (for writing
> headers on all mail but only filing actual spam) it
> seems to work, but i see the spam-test header twice -
> is it looping (or being evaluated twice -maybe on
> another channel)? what's really odd is sometimes the
> first one is false, and the second one is true - i
> wonder if it were reversed, would the message not be
> filed?
>
> when i addtag - here is how the message appears in my
> spam folder (note score discrepency - which
> corresponds exactly to the two different Spam-test
> scores as above) - sometimes the placement of the tag
> is jumbled too... e.g. the score and tag will come
> after the subject, etc.
>
> Space Monkey 998.7 [SPAM detected True ; 997.5 /
> 5.0] test
>
> i should mention, as i look back on my older spam
> (from my original config, which files spam, and only
> writes headers on spam) the header was being written
> twice as well, the subject tags in these are also
> sometimes jumbled.
>
> thanks,
> s7
>
> .
I'll answer what I know, and hopefully, Shane will help out.
# 14
thanks - i have also noticed with this rule -
require ["spamtest","relational","comparator-i;ascii-numeric","addtag", "fileinto","addheader"]; \
spamadjust "$U"; addheader "Spam-Test: $U"; \
if spamtest :value "ge" :comparator "i;ascii-numeric" "5" {addtag "[SPAM detected $U]"; fileinto "SPAM";} \
else {keep;}
some messages that are spam-test False are filed into my SPAM folder. i added the addtag (is the addtag specification in require necessary?).
e.g.
Mooky[SPAM detected False ; 4.9 / 5.0] A news.com item from Space Monkey
.
# 15
Hi,
Please try turning on sieve filter logging (LOG_FILTER=1 in option.dat) and see what is logged in mail.log_current when you send a message.
Given the addition of two headers, I suspect you are either processing the message twice somehow or you are filtering the message twice e.g. one filter in the option.dat and another at the user-level or channel level.
Regards,
Shane.
# 16
will this help even if i'm not using a sieve filter?
since to have a sieve filter fileinto folders, i have to give write permission to the system for each of these folders, i tried your first example which i don't think uses sieve?
i'll turn it on anyway.
in ims-ms i have: destinationspamfilteroptin SPAM
in tcp_local i have: sourcespamfilteroptin SPAM
# 17
Hi,
> will this help even if i'm not using a sieve filter?
I think you will find you are...
> since to have a sieve filter fileinto folders, i
> have to give write permission to the system for each
> of these folders, i tried your first example which i
> don't think uses sieve?
Yep it uses sieve. The rule is specified in the option.dat file.
> in ims-ms i have: destinationspamfilteroptin SPAM
> in tcp_local i have: sourcespamfilteroptin SPAM
There is two things wrong with this:
1. You are calling the filter twice for some reason and this would be causing you all sorts of issues (such as what you have already described).
I would only use the tcp_local version since you only want spam filtering for emails that come from outside your organisation (tcp_local). Scanning emails from within your organisation is a waste of time & effort.
2. The rule should have a number in it e.g. sourcespamfilter1optin
So you should have a rule something like:
tcp_local sourcespamfilter1optin spam
Regards,
Shane.
# 18
thanks -
removing the thing in ims-ms seems to have fixed the duplicate header
but now fileinto isn't working - here's some log:
05-Nov-2006 22:26:13.09 tcp_localtcp_scanE 2 spacemonkey@gmail.com rfc822;s7@domain.com @tcp_scan-daemon:s7@domain.com <d3f0d5800611051927j3eea12bfkfb9b90a553843a33@mail.gmail.com> mailsrv nf-out-0910.google.com ([64.233.182.189]) 'spamfilter1:3wFNAP5h3i8vXGohhqkBxg==, addheader, spamfilter1:3wFNAP5h3i8vXGohhqkBxg==, keep'
05-Nov-2006 22:26:13.24 tcp_noscanims-msE 3 spacemonkey@gmail.com rfc822;s7@domain.com s7@ims-ms-daemon <d3f0d5800611051927j3eea12bfkfb9b90a553843a33@mail.gmail.com> mailsrv mail.domain.com ([192.168.1.10]) ''
05-Nov-2006 22:26:13.25 tcp_scanD 2 spacemonkey@gmail.com rfc822;s7@domain.com @tcp_scan-daemon:s7@domain.com <d3f0d5800611051927j3eea12bfkfb9b90a553843a33@mail.gmail.com> mailsrv [192.168.1.10] '' dns;[192.168.1.10] (TCP|192.168.1.10|34465|192.168.1.10|10024) (smtp.passthru) smtp;250 2.1.5 s7@domain.com and options OK.
05-Nov-2006 22:26:13.84 ims-msD 3 spacemonkey@gmail.com rfc822;s7@domain.com s7@ims-ms-daemon <d3f0d5800611051927j3eea12bfkfb9b90a553843a33@mail.gmail.com> mailsrv ''
# 19
Hi,
Why have you got emails going from tcp_local -> tcp_scan -> ims-ms? I assume this is some kind of virus processing step?
If so that is probably causing the problem. In my example I am going directly from tcp_local -> ims-ms, therefore any store related sieve actions (such as fileinto) can occur since it applies to the ims-ms straight away.
You may have to add in a channel-level filter on ims-ms to use spamtest which does the fileinto etc. There is an example in this thread which goes through the steps required:
Re: adding headers to all mails with spamassassin
24/10/2006 10:32 (reply 7 of 18)
Regards,
Shane.
# 20
yes - i am scanning for viruses with clamsmtpd/clamav - i hope to use the new library asap.
i am using the alternate conversion channel from balius.
e.g.
! tcp_noscan
[] $E$R${NOSCAN_IP,$L}$U%[$L]@tcp_noscan-daemon
!
! tcp_scan
tcp_scan smtp single_sys subdirs 20 noreverse dequeue_removeroute maxjobs 7 pool SMTP_POOL daemon [192.168.1.10] port 10
024
tcp_scan-daemon
!
! tcp_noscan
tcp_noscan smtp single_sys subdirs 20 noreverse maxjobs 7 pool SMTP_POOL allowswitchchannel
tcp_noscan-daemon
NOSCAN_IP
$(192.168.1.10/32) $Y$E
* $N
CONVERSIONS
IN-CHAN=tcp_noscan;OUT-CHAN=*;CONVERT No
IN-CHAN=tcp_local;OUT-CHAN=tcp_intranet;CONVERT No
IN-CHAN=tcp_*;OUT-CHAN=*;CONVERT Yes,Channel=tcp_scan
ORIG_SEND_ACCESS
tcp_noscan|*|ims-ms|* $Y
i have made sure my spam folder is writeable and manageable by others, using the messenger express interface still no filing (or discarding) is getting done. i am using the example in post no. 7 of this thread. more log (the following caused by the anti-ube test string):
05-Nov-2006 23:16:50.17 tcp_localtcp_scanE 2 spacemonkey@gmail.com rfc822;s7@domain.com @tcp_scan-daemon:s7@domain.com <d3f0d5800611052018y6fe3bf61sa2878da3dcbe532f@mail.gmail.com> mailsrv nf-out-0910.google.com ([64.233.182.188]) 'spamfilter1:GM7ALdzwddnxi4ntu/wu4A==, addheader, keep'
05-Nov-2006 23:16:50.32 tcp_noscanims-msE 3 spacemonkey@gmail.com rfc822;s7@domain.com s7@ims-ms-daemon <d3f0d5800611052018y6fe3bf61sa2878da3dcbe532f@mail.gmail.com> mailsrv mail.domain.com ([192.168.1.10]) 'file:IMTA_TABLE:spamassassin.filter, keep'
05-Nov-2006 23:16:50.33 tcp_scanD 2 spacemonkey@gmail.com rfc822;s7@domain.com @tcp_scan-daemon:s7@domain.com <d3f0d5800611052018y6fe3bf61sa2878da3dcbe532f@mail.gmail.com> mailsrv [192.168.1.10] '' dns;[192.168.1.10] (TCP|192.168.1.10|35785|192.168.1.10|10024) (smtp.passthru) smtp;250 2.1.5 s7@domain.com and options OK.
05-Nov-2006 23:16:50.93 ims-msD 3 spacemonkey@gmail.com rfc822;s7@domain.com s7@ims-ms-daemon <d3f0d5800611052018y6fe3bf61sa2878da3dcbe532f@mail.gmail.com> mailsrv ''
i tried adjusting the filter changing the discard threshold, but either way, the message wound up in my inbox (not filed or discarded), albeit with the header and score appended.
from the log it seems to be hitting the spamassassin.filter but evaluating to keep instead of discard or fileinto ... ?
.
