CGI::Wiki::Plugin::SpamMonkey - CGI::Wiki plugin for SpamMonkey


CGI-Wiki-Plugin-SpamMonkey documentation Contained in the CGI-Wiki-Plugin-SpamMonkey distribution.

Index


Code Index:

NAME

Top

CGI::Wiki::Plugin::SpamMonkey - CGI::Wiki plugin for SpamMonkey

SYNOPSIS

Top

  use CGI::Wiki::Plugin::SpamMonkey;
  my $plugin = CGI::Wiki::Plugin::SpamMonkey->new;
  $wiki->register_plugin( plugin => $plugin );
  ...
  if ($plugin->is_spam( content => $content, metadata => \%metadata)) {
      $wiki->redirect( '/spamerror.html' );
  }
  else {
      $wiki->commit(...);
  }

DESCRIPTION

Top

This module is a plugin for CGI::Wiki sites to interface with the SpamMonkey module.

USAGE

Top

  $plugin->is_spam( content => $content, metadata => \%metadata)

Returns a true value if the content or metadata is spam.

BUGS

Top

Please report any bugs to rt.cpan.org or post to bugs-cgi-wiki-plugin-spammonkey at rt.cpan.org

SUPPORT

Top

This module, and other related modules are discussed on the mailing list: http://www.earth.li/cgi-bin/mailman/listinfo/cgi-wiki-dev

AUTHOR

Top

	Ivor Williams
	CPAN ID: IVORW

	ivorw-openguides at xemaps.com
	http://openguides.org/

COPYRIGHT

Top

SEE ALSO

Top

perl(1).


CGI-Wiki-Plugin-SpamMonkey documentation Contained in the CGI-Wiki-Plugin-SpamMonkey distribution.

package CGI::Wiki::Plugin::SpamMonkey;
use strict;

our $VERSION = '0.03';

use base 'CGI::Wiki::Plugin';
use SpamMonkey;
use Data::Dumper;

sub new {
    my ($class) = @_;
    my $newhome;
    if (!exists $ENV{HOME}) {
        $newhome = $ENV{HOMEDRIVE} . $ENV{HOMEPATH}
            if exists $ENV{HOMEDRIVE}; # Win XP/2000
    }
    local $ENV{HOME} = $newhome if $newhome;
    my $monkey = SpamMonkey->new( rule_dir => "/etc/mail/spamassassin/");
    $monkey->ready;
    my $self = bless ({ monkey => $monkey}, $class);

    return $self;
}

sub is_spam {
    my ($self,%args) = @_;

    my $content = $args{content} || '';
    $content .= Dumper($args{metadata}) if exists $args{metadata};

    my $result = $self->{monkey}->test($content);
    return $result->is_spam;
}

1;