lib/Exim/Grey.pm
changeset 72 f095f28db247
parent 70 bb6af74ba8b2
child 73 e2559ee78cb3
equal deleted inserted replaced
71:46ba051d29bd 72:f095f28db247
    50 
    50 
    51     my $key = "$item\0";
    51     my $key = "$item\0";
    52 
    52 
    53     # we do not know anything about the client -> unknown
    53     # we do not know anything about the client -> unknown
    54     if (not exists $h{$key}) {
    54     if (not exists $h{$key}) {
    55         $h{$key} = "$now $now 0\0";
    55         $h{$key} = "$now $now 0"
       
    56             . (defined $auto ? " auto=$auto" : '')
       
    57             . "\0";
    56         return 'yes';
    58         return 'yes';
    57     }
    59     }
    58 
    60 
    59     my ($created, undef, $count) = split /[ \0]/, $h{$key};
    61     my ($created, undef, $count, $flags) = split /[ \0]/, $h{$key};
    60 
    62 
    61     # we know the client, but last contact was recently (too fast)
    63     # we know the client, but last contact was recently (too fast)
    62     if ($now - $created < $delay) {
    64     if ($now - $created < $delay) {
    63         return 'yes';
    65         return 'yes';
    64     }
    66     }
    65 
    67 
    66     # we know the client, was patiently enough
    68     # we know the client, was patiently enough
    67     ++$count;
    69     ++$count;
    68     $h{$key} = "$created $now $count\0";
    70     $h{$key} = "$created $now $count\0";
    69     whitelist($auto, \%h) if defined $auto;
    71     whitelist(\%h, $auto, $flags =~ /auto=(\S+)/) if defined $auto;
    70     return 'no';
    72     return 'no';
    71 }
    73 }
    72 
    74 
    73 sub seen {
    75 sub seen {
    74     return(unseen(@_) eq 'yes' ? 'no' : 'yes');
    76     return(unseen(@_) eq 'yes' ? 'no' : 'yes');
    89 # (Where <KEY> is something like <$sender_address>+<$local_part@$domain>
    91 # (Where <KEY> is something like <$sender_address>+<$local_part@$domain>
    90 # If we see the same message a second time (same message means here:
    92 # If we see the same message a second time (same message means here:
    91 # same greylist criteria
    93 # same greylist criteria
    92 
    94 
    93 sub whitelist {
    95 sub whitelist {
    94     my ($item, $h) = @_;
    96     my ($h, @items) = @_;
    95     my $now = time;
    97     my $now = time;
    96     $h->{"$item\0"} = "$now $now 1 auto\0";
    98     $h->{"$_\0"} = "$now $now 1 auto\0"
       
    99         foreach uniq(@items);
       
   100 }
       
   101 
       
   102 sub uniq {
       
   103     my %h = map { $_, undef } @_;
       
   104     return keys %h;
    97 }
   105 }
    98 
   106 
    99 sub is_whitelisted {
   107 sub is_whitelisted {
   100     my ($item, $h) = @_;
   108     my ($item, $h) = @_;
   101     my $key = "$item\0";
   109     my $key = "$item\0";