diff options
| author | fukachan <fukachan> | 2002-09-29 12:43:23 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2002-09-29 12:43:23 +0000 |
| commit | b62d3d1ba49e3361b91fdb34e13a75d035f5d2ce (patch) | |
| tree | 21f87c38881f672379bf7814d2c87b3940696c7d | |
| parent | 20ac052fa6f69eb6df330fee8c30a04d98c87bb9 (diff) | |
| download | fml8-b62d3d1ba49e3361b91fdb34e13a75d035f5d2ce.tar.gz fml8-b62d3d1ba49e3361b91fdb34e13a75d035f5d2ce.tar.bz2 fml8-b62d3d1ba49e3361b91fdb34e13a75d035f5d2ce.zip | |
reconstruction phase 1: following new variable $article_filter_functions,
call the following function sequentially.
o article_header_filter
o article_non_mime_filter
o article_mime_component_filter
o article_text_plain_filter
| -rw-r--r-- | fml/lib/FML/Filter.pm | 197 |
1 files changed, 133 insertions, 64 deletions
diff --git a/fml/lib/FML/Filter.pm b/fml/lib/FML/Filter.pm index d5d693da..17850ec4 100644 --- a/fml/lib/FML/Filter.pm +++ b/fml/lib/FML/Filter.pm @@ -4,13 +4,14 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: Filter.pm,v 1.10 2002/09/11 23:18:02 fukachan Exp $ +# $FML: Filter.pm,v 1.11 2002/09/22 14:56:40 fukachan Exp $ # package FML::Filter; use strict; use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD); use Carp; +use FML::Log qw(Log LogWarn LogError); use ErrorStatus qw(error_set error error_clear); =head1 NAME @@ -19,14 +20,7 @@ FML::Filter - entry point for FML::Filter::* modules =head1 SYNOPSIS - use FML::Filter; - my $filter = new FML::Filter; - - $filter->check( $message ); - - if ($filter->error()) { - ... error handling ... - } + ... under reconstruction now. synopsis disabled once ... where C<$message> is C<Mail::Message> object. @@ -63,78 +57,153 @@ sub new # Arguments: OBJ($self) OBJ($curproc) HASH_REF($args) # Side Effects: none # Return Value: STR or UNDEF, error reason (string). return undef if ok. -sub check +sub article_filter { my ($self, $curproc, $args) = @_; - my $message = $curproc->{ 'incoming_message' }->{ message }; - my $config = $curproc->{ 'config' }; + my $message = $curproc->incoming_message(); + my $config = $curproc->config(); if (defined $message) { - if ($config->yes( 'use_article_header_filter' )) { - use FML::Filter::HeaderCheck; - my $obj = new FML::Filter::HeaderCheck; - - # overwrite filter rules based on FML::Config - if (defined $config->{ article_header_filter_rules }) { - my (@rules) = split(/\s+/, $config->{ article_header_filter_rules }); - $obj->rules( \@rules ); + my $functions = $config->get_as_array_ref('article_filter_functions'); + my $status = 0; + + FUNCTION: + for my $function (@$functions) { + if ($config->yes( "use_${function}" )) { + Log("filter(debug): check by $function"); + my $fp = "_load_$function"; + $status = $self->$fp($curproc, $args, $message); } - - # go check - $obj->header_check($message); - if ($obj->error()) { - my $x = $obj->error(); - $x =~ s/\s*at .*$//; - $x =~ s/[\n\s]*$//m; - $self->error_set($x); - return $x; + else { + Log("filter(debug): not check by $function"); } + + last FUNCTION if $status; } - if ($config->yes( 'use_article_body_filter' )) { - use FML::Filter::BodyCheck; - my $obj = new FML::Filter::BodyCheck; + return $status if $status; + } +} + - # overwrite filter rules based on FML::Config - if (defined $config->{ article_body_filter_rules }) { - my (@rules) = split(/\s+/, $config->{ article_body_filter_rules }); - $obj->rules( \@rules ); - } +# Descriptions: +# Arguments: OBJ($self) OBJ($curproc) HASH_REF($args) OBJ($mesg) +# Side Effects: +# Return Value: STR(reason) or 0 (not trapped, ok) +sub _load_article_header_filter +{ + my ($self, $curproc, $args, $mesg) = @_; + my $config = $curproc->config(); - # go check - $obj->body_check($message); - if ($obj->error()) { - my $x = $obj->error(); - $x =~ s/\s*at .*$//; - $x =~ s/[\n\s]*$//m; - $self->error_set($x); - return $x; - } + use FML::Filter::HeaderCheck; + my $obj = new FML::Filter::HeaderCheck; + + if (defined $obj) { + # overwrite filter rules based on FML::Config + my $rules = $config->get_as_array_ref('article_header_filter_rules'); + + if (defined $rules) { + $obj->rules( $rules ); } - if ($config->yes( 'use_content_filter' )) { - use FML::Filter::ContentCheck; - my $obj = new FML::Filter::ContentCheck; + # go check + $obj->header_check($mesg); + if ($obj->error()) { + my $x = $obj->error(); + $x =~ s/\s*at .*$//; + $x =~ s/[\n\s]*$//m; + $self->error_set($x); + return $x; + } + } - # overwrite filter rules based on FML::Config - if (defined $config->{ content_filter_rules }) { - my (@rules) = split(/\s+/, $config->{ content_filter_rules }); - $obj->rules( \@rules ); - } + return 0; +} - # go check - $obj->content_check($message); - if ($obj->error()) { - my $x = $obj->error(); - $x =~ s/\s*at .*$//; - $x =~ s/[\n\s]*$//m; - $self->error_set($x); - return $x; - } + +# Descriptions: +# Arguments: OBJ($self) HASH_REF($args) +# Side Effects: +# Return Value: 0 (always ok, anyway) +sub _load_article_non_mime_filter +{ + my ($self, $curproc, $args, $mesg) = @_; + my $config = $curproc->config(); + + return 0; +} + + +# Descriptions: +# Arguments: OBJ($self) HASH_REF($args) +# Side Effects: +# Return Value: none +sub _load_article_text_plain_filter +{ + my ($self, $curproc, $args, $mesg) = @_; + my $config = $curproc->config(); + + if ($config->yes( 'use_article_text_plain_filter' )) { + use FML::Filter::BodyCheck; + my $obj = new FML::Filter::BodyCheck; + + # overwrite filter rules based on FML::Config + my $rules = + $config->get_as_array_ref('article_text_plain_filter_rules'); + if (defined $rules) { + $obj->rules( $rules ); + } + + # go check + $obj->body_check($mesg); + if ($obj->error()) { + my $x = $obj->error(); + $x =~ s/\s*at .*$//; + $x =~ s/[\n\s]*$//m; + $self->error_set($x); + return $x; + } + } + + return 0; +} + + +# Descriptions: +# Arguments: OBJ($self) HASH_REF($args) +# Side Effects: +# Return Value: none +sub _load_article_mime_component_filter +{ + my ($self, $curproc, $args, $mesg) = @_; + my $config = $curproc->config(); + + if ($config->yes( 'use_article_mime_component_filter' )) { + use FML::Filter::ContentCheck; + my $obj = new FML::Filter::ContentCheck; + + # XXX DISABLED NOW ANYWAY + return 0; + + # overwrite filter rules based on FML::Config + my $rules = + $config->get_as_array_ref('article_mime_component_filter_rules'); + if (defined $rules) { + $obj->rules( $rules ); + } + + # go check + $obj->content_check($mesg); + if ($obj->error()) { + my $x = $obj->error(); + $x =~ s/\s*at .*$//; + $x =~ s/[\n\s]*$//m; + $self->error_set($x); + return $x; } } - return undef; # O.K. + return 0; } |
