plagger_backtick.pl
つくた。
こんな感じ。
#!/usr/bin/perl
use strict;
use warnings;
use Carp;
use WWW::Mechanize;
use HTTP::Cookies;
use MIME::Base64;
our $VERSION = '0.01';
# ---- Configurations ----------------
my $username = 'username';
my $password = 'base64::cGFzc3dvcmQ=';
my $label = '!!Plagger';
my $interval = 60;
# ------------------------------------
if ( my ($crypt, $pass) = $password =~ /^(\w+)::(.+)$/ ) {
$password = $crypt eq 'base64' ? decode_base64($pass) : undef;
croak qq/Invalid password crypt type, "$crypt"/ unless $password;
}
my $mech = WWW::Mechanize->new( cookie_jar => HTTP::Cookies->new, );
$mech->agent_alias('Windows IE 6');
$|=1;
while (1) {
$mech->get('http://mail.google.com/');
if ( $mech->content =~ /ServiceLoginAuth/ ) {
$mech->submit_form(
fields => {
Email => $username,
Passwd => $password,
}
);
my ($redirect_url) = $mech->content =~ /url=(.*?)"/;
$mech->get($redirect_url);
}
$mech->get("http://mail.google.com/mail/feed/atom/$label");
my ($unread) = $mech->content =~ m!<fullcount>(\d+)</fullcount>!m;
print "Plagger($unread) \n" if defined $unread;
sleep $interval;
}
これ作ってて見つけたんだけど、Gmail の Atom フィードって URL に Label 名つけるとそれで絞り込めるのね。便利!!