From daa9d194b54f6ae9fc95c3670eb20a80d04fa140 Mon Sep 17 00:00:00 2001 From: epg <> Date: Mon, 30 Dec 2002 01:51:55 +0000 Subject: [PATCH] Add a magic header filters can use to match against any To or To-related header, based on procmail's '^TO' special regex. --- minc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/minc b/minc index a143457..a11387c 100755 --- a/minc +++ b/minc @@ -37,6 +37,11 @@ use Log::Dispatch; use Log::Dispatch::File; use POSIX qw(strftime WEXITSTATUS WIFEXITED); +# If a filter set's header is $MAGIC_TO_TOKEN, that set is compared +# against headers matching this regex (taken from procmail). +my $MAGIC_TO_REGEX = '^((Original-)?(Resent-)?(To|Cc|Bcc)|(X-Envelope |Apparently(-Resent)?)-To)'; +my $MAGIC_TO_TOKEN = ' TO'; + =head1 OPTIONS =over 4 @@ -566,6 +571,25 @@ sub find_mh_folder { @filter = @$filterref; $header = shift(@filter); + # Handle filters using the magic TO header specially. + if ($header eq $MAGIC_TO_TOKEN) { + foreach $header (keys(%headers)) { + if ($header =~ /$MAGIC_TO_REGEX/i) { + foreach $contents (@{$headers{lc($header)}}) { + foreach $pair (@filter) { + ($match, $expression) = @$pair; + if ($contents =~ /$match/) { + return $expression; + } + } + } + } + } + + # Now that it's been processed specially, skip normal handling. + continue; + } + # Walk the list of message headers matching the filter's # specified header. foreach $contents (@{$headers{lc($header)}}) { @@ -646,6 +670,11 @@ are traversed I. This means the filters can be arranged so that some have priority over others. XXX: get Doug to write an example of having the same header matched more than once. +Lastly, B supports a magic ' TO' header. Filters using this +header are matched against a collection of headers related to (and +including) the To. Which headers to use is determined by a regular +expression borrowed from procmail. + =head1 EXAMPLES @FILTERS = ( -- 2.56.0