line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::IMAP::Simple::Gmail; |
2
|
1
|
|
|
1
|
|
48612
|
use Text::ParseWords; |
|
1
|
|
|
|
|
1740
|
|
|
1
|
|
|
|
|
2663
|
|
3
|
1
|
|
|
1
|
|
19
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
59
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use vars qw[$VERSION]; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
108
|
|
6
|
|
|
|
|
|
|
$VERSION = (qw$Revision: 0.21 $)[1]; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use base qw[Net::IMAP::Simple::SSL]; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3503
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub run_search { |
12
|
0
|
|
|
0
|
1
|
|
my ( $self, $search_terms ) = @_; |
13
|
0
|
|
|
|
|
|
my @hits; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
return $self->_process_cmd( |
16
|
|
|
|
|
|
|
cmd => [ SEARCH => qq[X-GM-RAW "$search_terms"] ], |
17
|
|
|
|
|
|
|
final => sub { |
18
|
0
|
|
|
0
|
|
|
return \@hits; |
19
|
|
|
|
|
|
|
}, |
20
|
|
|
|
|
|
|
process => sub { |
21
|
0
|
0
|
|
0
|
|
|
if ( $_[0] =~ /^\* SEARCH (.*)\s*$/ ) { |
22
|
0
|
|
|
|
|
|
@hits = split / /, $1; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
}, |
25
|
0
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub get_msgids { |
31
|
0
|
|
|
0
|
0
|
|
my ( $self, $number ) = @_; |
32
|
0
|
|
|
|
|
|
return $self->_get_gminfo( $number, 'X-GM-MSGID' ); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub get_threadids { |
36
|
0
|
|
|
0
|
1
|
|
my ( $self, $number ) = @_; |
37
|
0
|
|
|
|
|
|
return $self->_get_gminfo( $number, 'X-GM-THRID' ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _get_gminfo { |
42
|
0
|
|
|
0
|
|
|
my ( $self, $number, $gm_identifier ) = @_; |
43
|
0
|
|
|
|
|
|
my %threadid; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
return $self->_process_cmd( |
46
|
|
|
|
|
|
|
cmd => [ FETCH => qq[$number ($gm_identifier)] ], |
47
|
|
|
|
|
|
|
final => sub { |
48
|
|
|
|
|
|
|
# if range, return hashref, else scalar |
49
|
0
|
0
|
|
0
|
|
|
return ($number =~ /:/) ? \%threadid : $threadid{$number}; |
50
|
|
|
|
|
|
|
}, |
51
|
|
|
|
|
|
|
process => sub { |
52
|
0
|
|
|
0
|
|
|
foreach (@_) { |
53
|
0
|
0
|
|
|
|
|
if ( $_ =~ /^\* (\d+) FETCH \($gm_identifier (\d+)\)\s*$/ ) { |
54
|
0
|
|
|
|
|
|
my ($num, $label) = ($1, $2); |
55
|
0
|
|
|
|
|
|
$threadid{$1} = $2; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
}, |
59
|
0
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub get_labels { |
63
|
0
|
|
|
0
|
1
|
|
my ( $self, $number ) = @_; |
64
|
0
|
|
|
|
|
|
my %labels; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
return $self->_process_cmd( |
67
|
|
|
|
|
|
|
cmd => [ FETCH => qq[$number (X-GM-LABELS)] ], |
68
|
|
|
|
|
|
|
final => sub { |
69
|
|
|
|
|
|
|
# if range, return hashref else arrayrg |
70
|
0
|
0
|
|
0
|
|
|
return ($number =~ /:/) ? \%labels : $labels{$number}; |
71
|
|
|
|
|
|
|
}, |
72
|
|
|
|
|
|
|
process => sub { |
73
|
0
|
|
|
0
|
|
|
foreach (@_) { |
74
|
0
|
0
|
|
|
|
|
if ( $_ =~ /^\* (\d+) FETCH \(X-GM-LABELS \((.+)\)\)\s*$/ ) { |
75
|
0
|
|
|
|
|
|
my ($num, $label) = ($1, $2); |
76
|
0
|
|
|
|
|
|
my @labels = Text::ParseWords::parse_line(' ', 0, $label); |
77
|
0
|
|
|
|
|
|
$labels{$num} = \@labels; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
}, |
81
|
0
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub add_labels { |
86
|
0
|
|
|
0
|
1
|
|
my ( $self, $number, @labels ) = @_; |
87
|
0
|
|
|
|
|
|
return $self->_label_manip( $number, '+X-GM-LABELS', @labels ); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub remove_labels { |
91
|
0
|
|
|
0
|
1
|
|
my ( $self, $number, @labels ) = @_; |
92
|
0
|
|
|
|
|
|
return $self->_label_manip( $number, '-X-GM-LABELS', @labels ); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _label_manip { |
97
|
0
|
|
|
0
|
|
|
my ( $self, $number, $op, @labels ) = @_; |
98
|
0
|
0
|
|
|
|
|
return unless @labels; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# quote labels with spaces |
101
|
0
|
0
|
|
|
|
|
@labels = map { / / ? '"' . $_ . '"' : $_ } @labels; |
|
0
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my $label_line = join ' ', @labels; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
return $self->_process_cmd( |
105
|
|
|
|
|
|
|
cmd => [ STORE => qq[$number $op ($label_line)] ], |
106
|
0
|
|
|
0
|
|
|
final => sub { }, |
107
|
0
|
|
|
0
|
|
|
process => sub { }, |
108
|
0
|
|
|
|
|
|
); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
__END__ |