I'm using several filter modules within Julian Mehnle's excellent
Courier::Filter package.  Everything works fine, but there's a feature
that I'd like to request.

Although the various filtering tasks that I perform within my modules
are mostly independent of one another, sometimes the result of one
filtering action can affect what I want to do within a subsequent
filter.

One example (out of many) involves Courier::Filter::Module::SPF.  A
subsequent home-grown filtering step of mine wants to know the exact
result of the SPF filtering: its processing differs depending on whether
the SPF is 'softfail', 'unknown', 'neutral', or 'none'.

This illustrates the need for state information that can be shared
among the various filtering steps.

I came up with a way to do this (see below), but it's a hack, and I'm
wondering how feasible it would be to enhance Courier::Filter so that
there is a more formal mechanism for sharing state among the various
calls to the filter modules.

My hacked up method can be illustrated in this code fragment from my
pureperlfilter.conf file:

  # ... etc. ...

  # State information.
  my %state = ();

  $options = {

    # ... etc. ...

    modules     => [ Courier::Filter::Module::MyFirst->new(
                       state => \%state,
                     ),
                     # My modified version of C::F::M::SPF
                     Courier::Filter::Module::MySPF->new(
                       reject_on => [ 'fail', 'error' ],
                       state     => \%state,
                     ),
                     Courier::Filter::Module::MyFilter->new(
                       state => \%state,
                     ),
                   ],
  };

Each filter module can then access the 'state' hashmap via
$module->{state}.

All that the 'MyFirst' filter does is to remove all keys from
$module->{state} and then return 'undef'.

Then, in the 'MySPF' filter, which is a minor rewrite of
Courier::Filter::Module::SPF, the SPF query gets performed and its
result ('pass', 'unknown', 'softfail', etc.) gets stored in
$module->{state}->{spfresult}.

Finally, in 'MyFilter', $module->{state}->{spfresult} gets
queried, and this value gets used to do more filtering of
my choice.

I want to reiterate that this SPF case is but one example of many in
which the passing of state among the various filters would be useful.
Therefore, I am _not_ requesting simply an SPF-specific feature, but
rather, a more general feature that allows state to be shared among
all the steps within a filter chain.

I can think of a couple ways that this could be implemented:

1.  A getstate() and setstate() method within Courier::Filter
    which manages a global state hash that is initialized to
    be empty before the filter chain gets invoked.  Then, 
    the following could be done:

         $module->setstate('foo', $bar);
         $module->setstate('bar', $burfle);

         # And then later ...

         my $foo = $module->getstate('foo');

2.  Direct access to a module-specific state hash that is automatically
    initialized to be empty at the start of the filter chain.  This
    would work pretty much the same as my hack from within a filter
    module, but without the necessity for the user to manage it
    from within pureperlfilter.conf and without the user needing
    to define a first-in-the-chain filter that does nothing more
    than clear the keys of the hash.  The example in (1) would
    then look like this within the filter module:

         $module->{state}->{foo} = $bar;
         $module->{state}->{bar} = $burfle;

         # And then later ...

         my $foo = $module->{state}->{foo};

And, of course, there are other ways in which this could be done.

What do you think?

Thanks in advance.


-- 
 Lloyd Zusman
 [EMAIL PROTECTED]
 God bless you.



-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
courier-users mailing list
[EMAIL PROTECTED]
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users

Reply via email to