Attached you find a patch for the whitelist_soft plugin to allow regular
expressions in the whitelistrcpt configuration file. Regular expressions
have to be enclosed between slashes to differentiate between the old
string matching and the new regular expression matching behaviour.
It is useful if you like me use special addresses to e.g. register at
web sites and don't want to wait for an hour to get the opt in mail due
to the greylisting plugin.
-- Werner
--- whitelist_soft.orig 2007-09-23 23:17:20.000000000 +0200
+++ whitelist_soft 2007-09-23 22:58:58.000000000 +0200
@@ -57,6 +57,10 @@
plugins can test for this exemption using a 'whitelistrcpt'
transaction note, which holds the count of whitelisted recipients.
+Entries in whitelistrcpt may be regular expressions surrounded by
+slashes ('/'). In this case only the recipient but not the hostname
+component is matched.
+
=back
whitelist_soft also supports per-recipient whitelisting when using
@@ -205,11 +209,34 @@
my $host = lc $rcpt->host or return DECLINED;
my $config_arg = $self->{_per_recipient} ? { rcpt => $rcpt, %MERGE } : {};
- for my $h ($self->qp->config('whitelistrcpt', $config_arg)) {
- next unless $h;
- $h = lc $h;
+ for my $re ($self->qp->config('whitelistrcpt', $config_arg)) {
+ next unless $re;
- if ($addr eq $h or $host eq $h) {
+ my $str = undef;
+ my $err;
+ my $ok;
+ if ($re =~ m#^/(.*)/$#) {
+ $re = $1;
+ $ok = eval { $re = qr/$re/i; };
+ if ($@) {
+ ($err = $@) =~ s/\s*at \S+ line \d+\.\s*$//;
+ $self->log(LOGWARN, "REGEXP '$re' not valid: $err");
+ next;
+ }
+ $re = $ok;
+ }
+ else {
+ $str = lc $re;
+ }
+
+ if (defined $str) {
+ $ok = ($addr eq $str) || ($host eq $str);
+ }
+ else {
+ $ok = $addr =~ $re;
+ }
+
+ if ($ok) {
my $note = $transaction->notes('whitelistrcpt');
$transaction->notes('whitelistrcpt', ++$note);
$self->log(2,"recipient $addr in whitelistrcpt");