Mail::Abuse::Incident - Parses a Mail::Abuse::Report to extract incidents


Mail-Abuse documentation Contained in the Mail-Abuse distribution.

Index


Code Index:

NAME

Top

Mail::Abuse::Incident - Parses a Mail::Abuse::Report to extract incidents

SYNOPSIS

Top

  package Mail::Abuse::Incident::MyIncident;
  use Mail::Abuse::Incident;

  use base 'Mail::Abuse::Incident';
  sub ip { ... };
  sub time { ... };
  sub type { ... };
  sub data { ... };
  sub parse { ... }
  package main;

  use Mail::Abuse::Report;
  my $i = new Mail::Abuse::Incident::MyIncident;
  my $report = new Mail::Abuse::Report (incidents => [$i] );

DESCRIPTION

Top

This class implements the reception of an abuse report and its conversion to a Mail::Abuse::Report object.

An object must respond to all the methods in the synopsis, returning the required information about the incident (after it has been parsed).

The following items of information have been defined:

ip

A NetAddr::IP object encoding the origin of the particular incident.

time

A timestamp of the incident, extracted from the report. It must be a a timestamp in the UTC timezone, for consistency.

type

A string identifying the type of incident. Normally of the form spam/SpamCom or virus/Nimda, if such filters exist.

data

Any additional data that the class might want to keep regarding the incident.

Although specific incident parsers are free to define further class methodsor information items.

The following functions are provided for the customization of the behavior of the class.

items()

Enumerates the defined information items that have been defined for this object. Essentially, returns a list of the accessor methods. The object is overloaded so that this method is invoked automatically when serialization is required. This means that

    print $incident, "\n";

Will produce human-readable information.

serialize()

Produces a print()able representation of the Incident object, suitable for showing it to a human being.

parse($report)

Pushes incidents into the given report, based on parsing of the text in the report itself.

It must return a list of objects of the same class, with the incident data (IP address, timestamp and other information) filled.

EXPORT

None by default.

HISTORY

Top

0.01

Original version; created by h2xs 1.2 with options

  -ACOXcfkn
	Mail::Abuse
	-v
	0.01

LICENSE AND WARRANTY

Top

This code and all accompanying software comes with NO WARRANTY. You use it at your own risk.

This code and all accompanying software can be used freely under the same terms as Perl itself.

AUTHOR

Top

Luis E. Muņoz <luismunoz@cpan.org>

SEE ALSO

Top

perl(1).


Mail-Abuse documentation Contained in the Mail-Abuse distribution.
package Mail::Abuse::Incident;

require 5.005_62;

use Carp;
use strict;
use warnings;

use overload '""' => "serialize";
use overload 'eq' =>  sub { "$_[0]" eq "$_[1]" };
				# The code below should be in a single line

our $VERSION = do { my @r = (q$Revision: 1.11 $ =~ /\d+/g); sprintf " %d."."%03d" x $#r, @r };

sub new
{
    my $type	= shift;
    my $class	= ref($type) || $type;

    croak "Invalid call to Mail::Abuse::Incident::new"
	unless $class;

    bless {}, $class;
}

sub items
{
    my $self = shift;
    return wantarray ? sort keys %$self : scalar keys %$self;
}

sub _helper
{
    my $thing = shift;

    if (ref $thing eq 'SCALAR')
    {
	return $$thing;
    }
    elsif (ref $thing eq 'HASH')
    {
	my $ret = '{ ';
	for my $k (sort keys %$thing)
	{
	    $ret .= "$k => ";
	    $ret .= _helper($thing->{$k});
	    $ret .= " ";
	}
	$ret .= '}';
	return $ret;
    }
    elsif (ref $thing eq 'ARRAY')
    {
	my $ret = '[ ';
	for my $k (0 .. $#$thing)
	{
	    $ret .= "$k => ";
	    $ret .= _helper($thing->[$k]);
	    $ret .= " ";
	}
	$ret .= ']';
	return $ret;
    }
    elsif (ref $thing eq 'NetAddr::IP')
    {
	return "$thing";
    }
    else
    {
	if (defined $thing)
	{
	    $thing =~ s/\n/\\n/g;
	    return $thing;
	}
	else
	{
	    return 'undef';
	}
    }
}

sub serialize
{
    my $self = shift;
    my $ret = ref($self) . ":";
    for my $k ($self->items)
    {
	no strict 'refs';
	$ret .= " $k=" . _helper($self->$k);
    }
    $ret .= "no further data" unless $ret;
    return $ret;
}

sub parse
{
    croak "Mail::Abuse::Incident is a virtual class";
}

				# This helps subclasses to provide accessors
				# automagically
sub AUTOLOAD 
{
    no strict "refs";
    use vars qw($AUTOLOAD);
    my $method = $AUTOLOAD;
    $method =~ s/^.*:://;
    *$method = sub 
    { 
	my $self = shift;
	my $ret = $self->{$method};
	if (@_)
	{
	    $ret = $self->{$method};
	    $self->{$method} = shift;
	}
	return $ret;
    };
    goto \&$method;
}

__END__