duplicate header don't match header test?

2009-02-24 Thread Nicolas Haller
Hi all,

I have a problem. I have a rule like this
header GM_BLAH X-BLAH ~= /^blah$/

If I receive a mail with one header X-BLAH, all is right, the rule
match.
But, If a receive a mail with two header lines X-BLAH, the rule don't
match.

So, is it normal? What can I do for my rule matching mail with duplicate
header lines?

Regards,

-- 
Nicolas Haller


Re: duplicate header don't match header test?

2009-02-24 Thread Karsten Bräckelmann
On Tue, 2009-02-24 at 14:54 +0100, Nicolas Haller wrote:
 I have a problem. I have a rule like this
 header GM_BLAH X-BLAH ~= /^blah$/
 
 If I receive a mail with one header X-BLAH, all is right, the rule
 match.
 But, If a receive a mail with two header lines X-BLAH, the rule don't
 match.

No real rule, no sample that should be hit. Well, guess I see your
problem anyway... ;)

Please do provide useful, stripped-down and carefully crafted examples,
please. The operator is =~ rather than ~=. See my point?


 So, is it normal? What can I do for my rule matching mail with duplicate
 header lines?

IIRC the values of headers occuring multiple times are stored in a
single string. Including the newline char.

With your RE modifiers (or the lack thereof), ^ and $ only match the
beginning and end respectively of the string. Notably, they don't match
an embedded newline, as they do with the /m modifier. Also, the '.' does
not match a newline either, unless you specify the /s modifier. See the
perlre documentation for details:
  http://perldoc.perl.org/perlre.html#Modifiers

Point in case: /^.*$/ can not match here, while /^.*$/ms does.

If you need the anchoring to match a single header only (either one),
add /m. If you want '.' to span multiple headers, add /s. You can use
both, if desired.

  guenther


Example, using a quickly forged mail ;)  an ad-hoc rule and the relevant
debug output.

$ echo -e Foo: A\nFoo: B\n\n |
  spamassassin --cf=header FOO Foo =~ /^.*$/ms -D

[5674] dbg: rules: ran header rule FOO == got hit: A
[5674] dbg: rules: B
[5674] dbg: rules: 


-- 
char *t=\10pse\0r\0dtu...@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;il;i++){ i%8? c=1:
(c=*++x); c128  (s+=h); if (!(h=1)||!t[s+h]){ putchar(t[s]);h=m;s=0; }}}



Re: duplicate header don't match header test?

2009-02-24 Thread Nicolas Haller
On Tue, Feb 24, 2009 at 03:52:02PM +0100, Karsten Bräckelmann wrote:
 On Tue, 2009-02-24 at 14:54 +0100, Nicolas Haller wrote:
  I have a problem. I have a rule like this
  header GM_BLAH X-BLAH ~= /^blah$/
  
  If I receive a mail with one header X-BLAH, all is right, the rule
  match.
  But, If a receive a mail with two header lines X-BLAH, the rule don't
  match.

 No real rule, no sample that should be hit. Well, guess I see your
 problem anyway... ;)

 Please do provide useful, stripped-down and carefully crafted examples,
 please. The operator is =~ rather than ~=. See my point?

Oops :-)

  So, is it normal? What can I do for my rule matching mail with duplicate
  header lines?

 IIRC the values of headers occuring multiple times are stored in a
 single string. Including the newline char.

Ok, I didn't know this.

 With your RE modifiers (or the lack thereof), ^ and $ only match the
 beginning and end respectively of the string. Notably, they don't match
 an embedded newline, as they do with the /m modifier. Also, the '.' does
 not match a newline either, unless you specify the /s modifier. See the
 perlre documentation for details:
   http://perldoc.perl.org/perlre.html#Modifiers

Thank you, you solve my problem :-)

Regards,

-- 
Nicolas Haller