Changeset 90

Show
Ignore:
Timestamp:
06/21/01 04:58:07
Author:
miyagawa
Message:

make subclassing possible
added FilterTest?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Apache-AntiSpam/trunk/MANIFEST

    r61 r90  
    44README 
    55lib/Apache/AntiSpam.pm 
     6lib/Apache/AntiSpam/HTMLEncode.pm 
     7lib/Apache/AntiSpam/Heuristic.pm 
     8lib/Apache/AntiSpam/NoSpam.pm 
    69t/00_load.t 
     10t/01_filter.t 
     11t/rfc822.txt 
  • Apache-AntiSpam/trunk/Makefile.PL

    r69 r90  
    66    'PREREQ_PM' => { 
    77        Email::Find     => 0.04, 
     8        HTML::Entities  => 0, 
    89        mod_perl        => 1.21, 
    910    }, 
  • Apache-AntiSpam/trunk/lib/Apache/AntiSpam.pm

    r68 r90  
    33use strict; 
    44use vars qw($VERSION); 
    5 $VERSION = '0.03'; 
     5$VERSION = '0.04'; 
    66 
    77use Apache::Constants qw(:common); 
    88use Apache::File; 
     9use Carp (); 
    910use Email::Find 0.04; 
    1011 
    11 sub handler
    12     my $r = shift
     12sub handler ($$)
     13    my($class, $r) = @_
    1314 
    1415    my $filtered = uc($r->dir_config('Filter')) eq 'ON'; 
     
    5556    local $/;           # slurp 
    5657    my $input = <$fh>; 
    57     find_emails($input, \&$replacer); 
     58    find_emails($input, sub { $class->antispamize(@_) }); 
    5859    $r->print($input); 
    5960 
    6061    return OK; 
    6162}     
     63 
     64sub antispamize { 
     65    my($class, $email, $orig) = @_; 
     66    Carp::carp "Apache::AntiSpam should be subclassed. I'll do nothing"; 
     67    return $orig; 
     68} 
     69     
    6270 
    63711; 
     
    7078=head1 SYNOPSIS 
    7179 
     80  # You can't use this class directry 
     81  # see Apache::AntiSpam::*  
     82 
     83  # or ... if you want your own AntiSpam Filter, 
     84  package Your::AntiSpamFilter; 
     85  use base qw(Apache::AntiSpam); 
     86 
     87  sub antispamize { 
     88      my($class, $email, $orig) = @_; 
     89      # do some filtering with $orig, and 
     90      return $orig; 
     91  } 
     92 
    7293  # in httpd.conf 
    7394  <Location /antispam> 
    7495  SetHandler perl-script 
    75   PerlHandler Apache::AntiSpam 
     96  PerlHandler Your::AntiSpamFilter 
    7697  </Location> 
    7798 
    78   # off course, filter aware! 
     99  # filter aware 
    79100  PerlModule Apache::Filter 
    80101  SetHandler perl-script 
    81102  PerlSetVar Filter On 
    82   PerlHandler Apache::RegistryFilter Apache::AntiSpam Apache::Compress 
     103  PerlHandler Apache::RegistryFilter Your::AntiSpamFilter Apache::Compress 
    83104 
    84105=head1 DESCRIPTION 
    85106 
    86107Apache::AntiSpam is a filter module to prevent e-mail addresses 
    87 exposed as is on web pages. This module replaces e-mail addresses in 
    88 web pages with one of the formats listed below. (you can choose one) 
    89  
    90 =over 4 
    91  
    92 =item * 
    93  
    94 miyagawa-nospam@cpan.org 
    95  
    96 =item * 
    97  
    98 miyagawa at cpan dot org 
    99  
    100 =back 
     108exposed as is on web pages. The way to hide addresses from spammers 
     109are implemented in each of Apache::Antispam::* subclasses. 
    101110 
    102111This module is Filter aware, meaning that it can work within 
    103112Apache::Filter framework without modification. 
    104113 
    105 =head1 CONFIGURATION 
     114=head1 SUBCLASSING 
    106115 
    107   # choose either of two 
    108   PerlSetVar AntiSpamFormat NoSpam 
    109   PerlSetVar AntiSpamFormat Spaces 
    110  
    111 C<AntiSpamFormat> indicates the way Apache::AntiSpam replaces the 
    112 e-mail addresses. 
     116Here is how to make your own filter. 
    113117 
    114118=over 4 
    115119 
    116 =item C<NoSpam> 
     120=item Declare your class 
    117121 
    118 replaces B<miyagawa@cpan.org> with B<miyagawa-nospam@cpan.org>. (default) 
     122=item Inherit from Apache::AntiSpam 
    119123 
    120 =item C<Spaces> 
    121  
    122 replaces B<miyagawa@cpan.org> with B<miyagawa at cpan dot org>. 
     124=item define antispamize() method 
    123125 
    124126=back 
     127 
     128That's all. Template of antispamize() method will be like this: 
     129 
     130  sub antispamize { 
     131      my($class, $email, $orig) = @_; 
     132      # do some stuff.. 
     133      return $orig; 
     134  } 
     135 
     136where C<$class> is your class, C<$email> is an instance of 
     137Mail::Address, and C<$orig> is an original e-mail address string. See 
     138L<Email::Find> for details. 
    125139 
    126140=head1 TODO 
     
    130144=item * 
    131145 
    132 B<-nospam> suffix should be configured (easy). 
    133  
    134 =item * 
    135  
    136 More logging with Apache::Log. 
    137  
    138 =item * 
    139  
    140146remove mailto: tags using HTML::Parser. 
    141  
    142 =item * 
    143  
    144 Make it easy to subclass so that the antispamming method can be configured. 
    145147 
    146148=back 
     
    149151 
    150152The idea of this module is stolen from Apache::AddrMunge by Mark J 
    151 Dominus. See http://perl.plover.com/AddrMunge/ for details. 
     153Dominus. See http://perl.plover.com/AddrMunge/ for details. 
    152154 
    153155Many thanks to Michael G. Schwern for kindly improving the matching 
     
    163165=head1 SEE ALSO 
    164166 
    165 L<Email::Find>, L<Apache::Filter> 
     167L<Email::Find>, L<Apache::Filter>, L<Apache::AntiSpam::NoSpam>, 
     168L<Apache::AntiSpam::Heuristic>, L<Apache::AntiSpam::HTMLEncode>. 
    166169 
    167170=cut 
  • Apache-AntiSpam/trunk/t/00_load.t

    r61 r90  
    11use strict; 
    22use Test; 
    3 BEGIN { plan tests => 3
     3BEGIN { plan tests => 2
    44 
    55use Apache::AntiSpam; 
    6 ok(1); 
     6use Apache::AntiSpam::Heuristic; 
     7use Apache::AntiSpam::HTMLEncode; 
     8use Apache::AntiSpam::NoSpam; 
    79 
    810use mod_perl;