]> diplodocus.org Git - minc/commitdiff
Add a magic header filters can use to match against any To or
authorepg <>
Mon, 30 Dec 2002 01:51:55 +0000 (01:51 +0000)
committerepg <>
Mon, 30 Dec 2002 01:51:55 +0000 (01:51 +0000)
To-related header, based on procmail's '^TO' special regex.

minc

diff --git a/minc b/minc
index a143457..a11387c 100755 (executable)
--- 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<in order>.  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<minc> 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 = (