Re: HeaderEval::check_header_count_range() not working correctly?
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
Re: HeaderEval::check_header_count_range() not working correctly?
Sigh… “downside”. > On Nov 3, 2019, at 2:32 PM, Philip Prindeville > 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 >> 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?
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 > 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 >
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