WWW-Scraper-Gmail
view release on metacpan or search on metacpan
lib/WWW/Scraper/Gmail.pm view on Meta::CPAN
}
else {
warn $res->content();
warn $res->status_line, "\n";
return("");
}
}
sub fetchMail {
login();
my @msgs;
$req = HTTP::Request->new(GET => $url3, $head);
$res = $ua->request($req);
if ($res->is_success()) {
$inbox = $res->content();
$inbox =~ m!(D\(\[\"t\".*])!mgis;
$inbox = $1;
return(0) if (!$inbox);
$inbox =~ s!\\!!ig;
$inbox =~ s!</?b>!!ig;
while ($inbox =~ m!\[".+?",([01]),[01],"(.+?)","<span id='_user_(.+?)'>.+?",".+?","(.+?)","(.+?)".+?\]!mgis) {
$num++;
#my ($from, $subject, $new) = ($2, (($3 =~ /raquo/) ? $4 : $3), (($1 == 1) ? " NEW!!! " : ""));
my ($time, $from, $subject, $new, $blurb) = ($2, $3, $4, ($1 == 1) ? "new!" : "", $5);
my $rec = {};
$rec = {
from => $from,
subject => $subject,
date => $time,
blurb => $blurb,
new => $1
};
push @msgs, $rec;
#print "Thread Started by $from, Subject $subject @ $time $new\n\t$blurb\n";
}
#print "$num total messages in inbox\n";
return @msgs;
}
else {
warn $res->content();
warn $res->status_line, "\n";
return(0);
}
}
sub setPrefs {
my ($arg) = @_;
login();
doGmailAt();
$arg->{"MaxPer"} = 100 unless defined $arg->{MaxPer};
$arg->{"Signature"} = "" unless defined $arg->{Signature};
$arg->{"Signature"} = HTML::Entities::encode_entities_numeric($arg->{"Signature"});
#print Dumper $arg;
my $url_pref=" http://gmail.google.com/gmail?search=inbox&view=tl&start=0&act=prefs&at=$gmail_at&p_bx_hs=1&p_ix_nt=$arg->{MaxPer}&p_bx_sc=1&p_sx_sg=$arg->{Signature}&zx=$zx";
#print "Going for $url_pref\n";
#$head = HTTP::Headers->new(Cookie => $cookie); #, Referer => $ref);
$req = HTTP::Request->new(GET=>$url_pref, $head);
$res = $ua->request($req);
return ($res->as_string() =~ /saved/);
}
1;
__END__
# Below is stub documentation for your module. You'd better edit it!
=head1 NAME
WWW::Scraper::Gmail - Perl extension for loging in and reading Gmail Mailbox information.
=head1 SYNOPSIS
use WWW::Scraper::Gmail;
A simple scraper for gmail.
=head1 DESCRIPTION
Logs into email through https, does some stuff and gets back a list of inbox items.
Uses ~/.gmailrc for now for username and password. The format is as follows
[gmail]
username=<username>
password=<password>
you'd do well to chmod it 700.
Doesn't do error checking for log in problems.
=head2 EXPORT
None by default.
=head1 SEE ALSO
=head1 AUTHOR
Erik F. Kastner, <lt>kastner@gmail.com<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2004 by Erik F. Kastner
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.3 or,
at your option, any later version of Perl 5 you may have available.
=cut
( run in 1.748 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )