You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@spamassassin.apache.org by Daniel Lemke <le...@jam-software.com> on 2010/06/14 16:41:48 UTC

regex for short messages

Hi,

I want to check some mails for their char count (will be part of a meta
rule) but spamassassin does hit the rule, even if the mail has less chars
than defined in regex.

The regex was tested in Perl and was working fine, so what did I miss?

body			MY_BODY_SHORT_MAIL		/\A.{0,150}\z/s
describe		MY_BODY_SHORT_MAIL		Short Mail
score			MY_BODY_SHORT_MAIL		0.1

Best regards
Daniel
-- 
View this message in context: http://old.nabble.com/regex-for-short-messages-tp28880387p28880387.html
Sent from the SpamAssassin - Users mailing list archive at Nabble.com.


Re: regex for short messages

Posted by John Hardin <jh...@impsec.org>.
On Mon, 14 Jun 2010, Daniel Lemke wrote:

> I want to check some mails for their char count (will be part of a meta 
> rule) but spamassassin does hit the rule, even if the mail has less 
> chars than defined in regex.
>
> body			MY_BODY_SHORT_MAIL		/\A.{0,150}\z/s
> describe		MY_BODY_SHORT_MAIL		Short Mail
> score			MY_BODY_SHORT_MAIL		0.1

This might be simpler and faster (untested):

   rawbody   __MSG_MIN_LEN   /.{151}/s

   meta      WHATEVER    !__MSG_MIN_LEN && etc.

-- 
  John Hardin KA7OHZ                    http://www.impsec.org/~jhardin/
  jhardin@impsec.org    FALaholic #11174     pgpk -a jhardin@impsec.org
  key: 0xB8732E79 -- 2D8C 34F4 6411 F507 136C  AF76 D822 E6E6 B873 2E79
-----------------------------------------------------------------------
   The third basic rule of firearms safety:
   Keep your booger hook off the bang switch!
-----------------------------------------------------------------------
  4 days until SWMBO's Birthday

Re: regex for short messages

Posted by Karsten Bräckelmann <gu...@rudersport.de>.
On Mon, 2010-06-14 at 07:41 -0700, Daniel Lemke wrote:
> I want to check some mails for their char count (will be part of a meta
> rule) but spamassassin does hit the rule, even if the mail has less chars
> than defined in regex.

You mean *more* chars, no? Less than zero isn't possible, and the RE
allows any number of chars up to 150. Less is explicitly allowed.

> The regex was tested in Perl and was working fine, so what did I miss?

I'd run a test message through spamassassin -D and watch out for the
rule hit. The debug output includes the match against the RE.

> body			MY_BODY_SHORT_MAIL		/\A.{0,150}\z/s
> describe		MY_BODY_SHORT_MAIL		Short Mail
> score			MY_BODY_SHORT_MAIL		0.1

-- 
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: regex for short messages

Posted by Daniel Lemke <le...@jam-software.com>.

Bowie Bailey wrote:
> 
> The best idea was suggested by someone else.  Instead of trying to match
> a short segment, do a negative match on a longer one.
> 
> rawbody T__LONG_MAIL /.{151}/s
> meta T_SHORT_MAIL !T__LONG_MAIL
> 

Hmm, I saw the suggestion but missed to negate the meta...
Thank you :-)

Daniel
-- 
View this message in context: http://old.nabble.com/regex-for-short-messages-tp28880387p29020879.html
Sent from the SpamAssassin - Users mailing list archive at Nabble.com.


Re: regex for short messages

Posted by Bowie Bailey <Bo...@BUC.com>.
Daniel Lemke wrote:
> Hmm, I've just noticed that my rule is working fine for simple text
> messages, but is also been triggered when checking mails containing html
> (http://pastebin.com/xB7SKnFV).
>
> rawbody	T__SHORT_MAIL	/\A.{0,150}\z/s
>
> -D reports:
> Jun 28 13:32:40.961 [4200] dbg: rules: ran rawbody rule T__SHORT_MAIL
> ======> got hit: "
>
> Any hints on this?

The best idea was suggested by someone else.  Instead of trying to match
a short segment, do a negative match on a longer one.

rawbody T__LONG_MAIL /.{151}/s
meta T_SHORT_MAIL !T__LONG_MAIL

Once you've tested the rule, you can remove the "T" from the T_LONG_MAIL
rule so that it becomes a subrule and will not be scored or show in the
reports.

-- 
Bowie

Re: regex for short messages

Posted by Daniel Lemke <le...@jam-software.com>.

Bowie Bailey wrote:
> 
> Bowie Bailey wrote:
>> Daniel Lemke wrote:
>>   
>>> Hi,
>>>
>>> I want to check some mails for their char count (will be part of a meta
>>> rule) but spamassassin does hit the rule, even if the mail has less
>>> chars
>>> than defined in regex.
>>>
>>> The regex was tested in Perl and was working fine, so what did I miss?
>>>
>>> body			MY_BODY_SHORT_MAIL		/\A.{0,150}\z/s
>>> describe		MY_BODY_SHORT_MAIL		Short Mail
>>> score			MY_BODY_SHORT_MAIL		0.1
>>>   
>>>     
>>
>> I assume you meant to say that it does NOT hit?
>>
>> Don't know what the problem is.  It works fine for me.
>>   
> 
> I see now.  It's hitting on long messages too.  I saw it match the
> subject line rather than the body.  I'm not quite sure why.  It works if
> you change it to a rawbody match.
> 
> -- 
> Bowie
> 
> 


Hmm, I've just noticed that my rule is working fine for simple text
messages, but is also been triggered when checking mails containing html
(http://pastebin.com/xB7SKnFV).

rawbody	T__SHORT_MAIL	/\A.{0,150}\z/s

-D reports:
Jun 28 13:32:40.961 [4200] dbg: rules: ran rawbody rule T__SHORT_MAIL
======> got hit: "

Any hints on this?

Daniel

-- 
View this message in context: http://old.nabble.com/regex-for-short-messages-tp28880387p29008540.html
Sent from the SpamAssassin - Users mailing list archive at Nabble.com.


Re: regex for short messages

Posted by Bowie Bailey <Bo...@BUC.com>.
Bowie Bailey wrote:
> Daniel Lemke wrote:
>   
>> Hi,
>>
>> I want to check some mails for their char count (will be part of a meta
>> rule) but spamassassin does hit the rule, even if the mail has less chars
>> than defined in regex.
>>
>> The regex was tested in Perl and was working fine, so what did I miss?
>>
>> body			MY_BODY_SHORT_MAIL		/\A.{0,150}\z/s
>> describe		MY_BODY_SHORT_MAIL		Short Mail
>> score			MY_BODY_SHORT_MAIL		0.1
>>   
>>     
>
> I assume you meant to say that it does NOT hit?
>
> Don't know what the problem is.  It works fine for me.
>   

I see now.  It's hitting on long messages too.  I saw it match the
subject line rather than the body.  I'm not quite sure why.  It works if
you change it to a rawbody match.

-- 
Bowie

Re: regex for short messages

Posted by Bowie Bailey <Bo...@BUC.com>.
Daniel Lemke wrote:
> Hi,
>
> I want to check some mails for their char count (will be part of a meta
> rule) but spamassassin does hit the rule, even if the mail has less chars
> than defined in regex.
>
> The regex was tested in Perl and was working fine, so what did I miss?
>
> body			MY_BODY_SHORT_MAIL		/\A.{0,150}\z/s
> describe		MY_BODY_SHORT_MAIL		Short Mail
> score			MY_BODY_SHORT_MAIL		0.1
>   

I assume you meant to say that it does NOT hit?

Don't know what the problem is.  It works fine for me.

-- 
Bowie