line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AnyEvent::Gmail::Feed; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
32
|
use 5.008_001; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
69
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
12556
|
use AnyEvent; |
|
1
|
|
|
|
|
11848
|
|
|
1
|
|
|
|
|
386
|
|
8
|
1
|
|
|
1
|
|
1324
|
use AnyEvent::HTTP; |
|
1
|
|
|
|
|
49736
|
|
|
1
|
|
|
|
|
130
|
|
9
|
1
|
|
|
1
|
|
1150
|
use MIME::Base64; |
|
1
|
|
|
|
|
1777
|
|
|
1
|
|
|
|
|
158
|
|
10
|
1
|
|
|
1
|
|
502
|
use XML::Atom::Feed; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
|
|
|
|
|
|
my ($class, %args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $username = delete $args{username}; |
16
|
|
|
|
|
|
|
my $password = delete $args{password}; |
17
|
|
|
|
|
|
|
my $label = delete $args{label}; |
18
|
|
|
|
|
|
|
my $interval = delete $args{interval} || 60; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
unless ($username && $password) { |
21
|
|
|
|
|
|
|
die "both username and password are required"; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $self = bless {}, $class; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $auth = MIME::Base64::encode( join(":", $username, $password) ); |
27
|
|
|
|
|
|
|
my $headers = {Authorization => "Basic $auth"}; |
28
|
|
|
|
|
|
|
my $uri = 'https://mail.google.com/mail/feed/atom/'; |
29
|
|
|
|
|
|
|
$uri .= $label . '/' if $label; ## 'unread' or whatever |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my %seen; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $timer; |
34
|
|
|
|
|
|
|
my $checker; $checker = sub { |
35
|
|
|
|
|
|
|
http_get $uri, headers => $headers, sub { |
36
|
|
|
|
|
|
|
my ($body, $hdr) = @_; |
37
|
|
|
|
|
|
|
return unless $body; |
38
|
|
|
|
|
|
|
my $feed = XML::Atom::Feed->new(\$body) or return; |
39
|
|
|
|
|
|
|
for my $e ($feed->entries) { |
40
|
|
|
|
|
|
|
unless ($seen{$e->id}) { |
41
|
|
|
|
|
|
|
($args{on_new_entry} || sub {})->($e); |
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
$seen{$e->id}++; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
$timer = AnyEvent->timer( after => $interval, cb => $checker); |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
}; |
48
|
|
|
|
|
|
|
$checker->(); |
49
|
|
|
|
|
|
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
__END__ |