You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@spamassassin.apache.org by Philip Prindeville <ph...@redfish-solutions.com> on 2019/11/03 20:51:19 UTC
HeaderEval::check_header_count_range() not working correctly?
Hi.
I’m looking at:
# Return true if the count of $hdr headers are within the given range
sub check_header_count_range {
my ($self, $pms, $hdr, $min, $max) = @_;
my %uniq = ();
my @hdrs = grep(!$uniq{$_}++, $pms->{msg}->get_header ($hdr));
return (scalar @hdrs >= $min && scalar @hdrs <= $max);
}
in HeaderEval.pm and I’m not getting it. It inserts (once and only once) each occurrence of a unique RHS for the header X. So if I had:
X-yzzy: A
X-yzzy: A
X-yzzy: B
X-yzzy: C
Then $uniq{A} would be 2, $uniq${B} would be 1, and $uniq{C} would be 1, so the number of elements in @hdrs would be 3, once each for ‘A’, ‘B’, and ‘C’.
But if I have:
X-yzzy: A
X-yzzy: A
X-yzzy: A
X-yzzy: A
then $uniq{A} is 4, but the number of elements in @hdrs would be 1 (because of the ‘!’ which only passes the first).
This seems counter-intuitive. What if I want to count the absolute number of headers of type ‘X-yzzy:’ regardless of their RHS?
I’ve been seeing a lot of Spam recently with duplicative Received-SPF: lines, but since they are all identical, it’s not nudging the number of @hdrs past one.
Thanks,
-Philip
Re: HeaderEval::check_header_count_range() not working correctly?
Posted by Philip Prindeville <ph...@redfish-solutions.com>.
Sigh… “downside”.
> On Nov 3, 2019, at 2:32 PM, Philip Prindeville <ph...@redfish-solutions.com> wrote:
>
> What would be the downsize of having:
>
> my @hdrs = grep($uniq{$_}++, $pms->{msg}->get_header ($hdr));
>
> instead and counting ALL instances of $hdr, not just the unique RHS’s?
>
>
>
>> On Nov 3, 2019, at 1:51 PM, Philip Prindeville <ph...@redfish-solutions.com> wrote:
>>
>> Hi.
>>
>> I’m looking at:
>>
>> # Return true if the count of $hdr headers are within the given range
>> sub check_header_count_range {
>> my ($self, $pms, $hdr, $min, $max) = @_;
>> my %uniq = ();
>> my @hdrs = grep(!$uniq{$_}++, $pms->{msg}->get_header ($hdr));
>> return (scalar @hdrs >= $min && scalar @hdrs <= $max);
>> }
>>
>> in HeaderEval.pm and I’m not getting it. It inserts (once and only once) each occurrence of a unique RHS for the header X. So if I had:
>>
>> X-yzzy: A
>> X-yzzy: A
>> X-yzzy: B
>> X-yzzy: C
>>
>> Then $uniq{A} would be 2, $uniq${B} would be 1, and $uniq{C} would be 1, so the number of elements in @hdrs would be 3, once each for ‘A’, ‘B’, and ‘C’.
>>
>> But if I have:
>>
>> X-yzzy: A
>> X-yzzy: A
>> X-yzzy: A
>> X-yzzy: A
>>
>> then $uniq{A} is 4, but the number of elements in @hdrs would be 1 (because of the ‘!’ which only passes the first).
>>
>> This seems counter-intuitive. What if I want to count the absolute number of headers of type ‘X-yzzy:’ regardless of their RHS?
>>
>> I’ve been seeing a lot of Spam recently with duplicative Received-SPF: lines, but since they are all identical, it’s not nudging the number of @hdrs past one.
>>
>> Thanks,
>>
>> -Philip
>>
>
Re: HeaderEval::check_header_count_range() not working correctly?
Posted by Philip Prindeville <ph...@redfish-solutions.com>.
What would be the downsize of having:
my @hdrs = grep($uniq{$_}++, $pms->{msg}->get_header ($hdr));
instead and counting ALL instances of $hdr, not just the unique RHS’s?
> On Nov 3, 2019, at 1:51 PM, Philip Prindeville <ph...@redfish-solutions.com> wrote:
>
> Hi.
>
> I’m looking at:
>
> # Return true if the count of $hdr headers are within the given range
> sub check_header_count_range {
> my ($self, $pms, $hdr, $min, $max) = @_;
> my %uniq = ();
> my @hdrs = grep(!$uniq{$_}++, $pms->{msg}->get_header ($hdr));
> return (scalar @hdrs >= $min && scalar @hdrs <= $max);
> }
>
> in HeaderEval.pm and I’m not getting it. It inserts (once and only once) each occurrence of a unique RHS for the header X. So if I had:
>
> X-yzzy: A
> X-yzzy: A
> X-yzzy: B
> X-yzzy: C
>
> Then $uniq{A} would be 2, $uniq${B} would be 1, and $uniq{C} would be 1, so the number of elements in @hdrs would be 3, once each for ‘A’, ‘B’, and ‘C’.
>
> But if I have:
>
> X-yzzy: A
> X-yzzy: A
> X-yzzy: A
> X-yzzy: A
>
> then $uniq{A} is 4, but the number of elements in @hdrs would be 1 (because of the ‘!’ which only passes the first).
>
> This seems counter-intuitive. What if I want to count the absolute number of headers of type ‘X-yzzy:’ regardless of their RHS?
>
> I’ve been seeing a lot of Spam recently with duplicative Received-SPF: lines, but since they are all identical, it’s not nudging the number of @hdrs past one.
>
> Thanks,
>
> -Philip
>
Re: HeaderEval::check_header_count_range() not working correctly?
Posted by RW <rw...@googlemail.com>.
On Sun, 3 Nov 2019 13:51:19 -0700
Philip Prindeville wrote:
> then $uniq{A} is 4, but the number of elements in @hdrs would be 1
> (because of the ‘!’ which only passes the first).
>
> This seems counter-intuitive. What if I want to count the absolute
> number of headers of type ‘X-yzzy:’ regardless of their RHS?
>
> I’ve been seeing a lot of Spam recently with duplicative
> Received-SPF: lines, but since they are all identical, it’s not
> nudging the number of @hdrs past one.
You shouldn't need perl for this. Header tests run on a string that
contains all the RHS's for the named header, so something like the
following should do it:
header __RECSPF_COUNT Received-SPF =~ /^.*$/m
tflags __RECSP__COUNT multiple