WWW::Anonymouse - interface to Anonymouse.org Email and News posting


WWW-Anonymouse documentation Contained in the WWW-Anonymouse distribution.

Index


Code Index:

NAME

Top

WWW::Anonymouse - interface to Anonymouse.org Email and News posting

SYNOPSIS

Top

    use WWW::Anonymouse;

    my $an = WWW::Anonymouse::Email->new;
    $an->send( to=>'bubba@example.com', subject=>'test', text=>'test' );

    my $an = WWW::Anonymouse::News->new;
    $an->send( to=>'alt.test', subject=>'test', text=>'test' );

DESCRIPTION

Top

The WWW::Anonymouse module provides an interface to the Anonymouse.org anonymous email and news posting.

METHODS

Top

$an = WWW::Anonymouse::Email->new
$an = WWW::Anonymouse::Email->new( ua => $ua )
$an = WWW::Anonymouse::News->new
$an = WWW::Anonymouse::News->new( ua => $ua )

Creates a new Email or News object. The constructor accepts an optional LWP::UserAgent derived object.

$ret = $an->send( to => $to, subject => $subject, text => $text )

Sends a message to the given email address(es) or newsgroup(s). Returns true on success.

$error = $an->error

Returns the error string, if present.

NOTES

Top

Anonymouse has a flood protection limit of about 1 message per minute. If you need to post more frequently, you can use http proxies or cgi proxies- but don't abuse the service.

SEE ALSO

Top

http://anonymouse.org/anonemail.html

http://anonymouse.org/anonnews.html

REQUESTS AND BUGS

Top

Please report any bugs or feature requests to http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Anonymouse. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc WWW::Anonymouse

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/WWW-Anonymouse

* CPAN Ratings

http://cpanratings.perl.org/d/WWW-Anonymouse

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Anonymouse

* Search CPAN

http://search.cpan.org/dist/WWW-Anonymouse

COPYRIGHT AND LICENSE

Top

AUTHOR

Top

gray, <gray at cpan.org>


WWW-Anonymouse documentation Contained in the WWW-Anonymouse distribution.

package WWW::Anonymouse;

use strict;
use warnings;

use LWP::UserAgent;
use URI;
use Carp ();

our $VERSION = '0.04';

use constant DEBUG => $ENV{ WWW_ANONYMOUSE_DEBUG } || 0;
use constant MAX_BYTES => 3072;

sub new {
    my ($class, %params) = @_;
    if ( $class eq __PACKAGE__ ) {
        Carp::croak __PACKAGE__,
            ' is a virtual class; use the Email or News class';
    }

    unless ( ref $params{ua} and $params{ua}->isa( q(LWP::UserAgent) ) ) {
        $params{ua} = LWP::UserAgent->new( agent => __PACKAGE__.'/'.$VERSION );
    }

    return bless \%params, $class;
}

sub error {
    return $_[0]->{error};
}

sub _ua_content_cb {
    my ($data, $res, $proto) = @_;
    $res->add_content(\$data);

    # Abort the request if enough content is received to parse for status.
    die if length $res->content > MAX_BYTES;
}

sub send {
    my ($self, %params) = @_;
    my %fields;

    unless ( $fields{qw( to )} = $params{qw( to )} ) {
        $self->{error} = qq(Missing field "to");
        return;
    }

    for my $field ( qw( subject text ) ) {
        $fields{$field} = $params{$field} || '';
    }

    my $res = $self->{ua}->post(
        $self->_url, \%fields, ':read_size_hint' => MAX_BYTES,
        ':content_cb' => \&_ua_content_cb,
    );
    unless ( $res->is_success ) {
        $self->{error} = $res->status_line;
        return;
    }

    # TODO: consider using HTML::TreeBuilder::XPath

    $self->{error} = 'Unknown error';
    my $cref = $res->content_ref;

    if ( $$cref !~ /<FONT size="\+2"/g ) { }
    elsif ( $$cref =~ /\G color="#FF0000">(?:Mixmaster-)?Error - ([^>]+?)\!?</gc ) {
        $self->{error} = $1;
    }
    elsif ( $$cref =~ /\G>(?:Email|Posting) has been sent anonymously/ ) {
        $self->{error} = undef;
        return 1;
    }

    return;
}

BEGIN {
    package WWW::Anonymouse::Email;
    use base qw( WWW::Anonymouse );
    sub _url { 'http://anonymouse.org/cgi-bin/anon-email.cgi' }
    sub _referer { 'http://anonymouse.org/anonemail.html' }
}

BEGIN {
    package WWW::Anonymouse::News;
    use base qw( WWW::Anonymouse );
    sub _url { 'http://anonymouse.org/cgi-bin/anon-news.cgi' }
    sub _referer { 'http://anonymouse.org/anonnews.html' }
}

1;

__END__