Gmail の Atom フィードは https + basic 認証

と教えてもらった。!!!

さっき書いたの超意味ない。

#!/usr/bin/perl

use strict;
use warnings;
use Carp;
use LWP::UserAgent;
use MIME::Base64;

our $VERSION = '0.02';

# ---- 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 $ua = LWP::UserAgent->new;

my $feed_request =
    HTTP::Request->new( GET => "https://mail.google.com/mail/feed/atom/$label" );
$feed_request->headers->authorization_basic( $username, $password );

$|=1;
while (1) {
    my $res = $ua->request( $feed_request );

    my ($unread) = $res->content =~ m!<fullcount>(\d+)</fullcount>!m;
    print "Plagger($unread) \n" if defined $unread;

    sleep $interval;
}

これでOKだ。

by typester / at 2006-03-06T15:04:00 / plagger · screen / Comments(0)