| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::Automaton::Plugin::Source::IMAP; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: IMAP email input module |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
444
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
26
|
|
|
6
|
1
|
|
|
1
|
|
2
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
21
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
374
|
use Moo; |
|
|
1
|
|
|
|
|
8806
|
|
|
|
1
|
|
|
|
|
5
|
|
|
9
|
1
|
|
|
1
|
|
1403
|
use Net::IMAP::Simple; |
|
|
1
|
|
|
|
|
33271
|
|
|
|
1
|
|
|
|
|
42
|
|
|
10
|
1
|
|
|
1
|
|
527
|
use Email::Simple; |
|
|
1
|
|
|
|
|
3015
|
|
|
|
1
|
|
|
|
|
27
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
7
|
use Data::Dumper; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
231
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub go { |
|
15
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
16
|
0
|
|
|
|
|
|
my $in = shift; |
|
17
|
0
|
|
|
|
|
|
my $d = $in->{debug}; |
|
18
|
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $server = $in->{server} . ':' . $in->{port}; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Create the object |
|
22
|
0
|
|
0
|
|
|
|
my $imap = Net::IMAP::Simple->new( $server, use_ssl => $in->{ssl} ) |
|
23
|
|
|
|
|
|
|
|| die "Unable to connect to IMAP: $Net::IMAP::Simple::errstr\n"; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Log on |
|
26
|
0
|
0
|
|
|
|
|
$imap->login( $in->{account}, $in->{password} ) |
|
27
|
|
|
|
|
|
|
|| die "imap login failed"; |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my @output; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Get messages |
|
32
|
0
|
|
|
|
|
|
my $nm = $imap->select('INBOX'); |
|
33
|
0
|
|
|
|
|
|
_logger($d, "Found $nm messages"); |
|
34
|
0
|
|
|
|
|
|
for ( my $i = 1; $i <= $nm; $i++ ) { |
|
35
|
0
|
|
|
|
|
|
_logger($d, "getting message $i"); |
|
36
|
|
|
|
|
|
|
#my $message = $imap->get( $i, 2 ) || $imap->get($i); |
|
37
|
0
|
|
|
|
|
|
my $message = $imap->get($i); |
|
38
|
0
|
0
|
|
|
|
|
die("imap message undef") unless defined $message; |
|
39
|
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
push( @output, $message ); |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
if ($in->{delete}) { |
|
43
|
|
|
|
|
|
|
# delete message |
|
44
|
0
|
|
|
|
|
|
_logger($d, "Deleting message $i"); |
|
45
|
0
|
|
|
|
|
|
$imap->delete($i); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
} |
|
49
|
0
|
|
|
|
|
|
chomp(@output); #probably not needed, maybe even a bad idea |
|
50
|
0
|
|
|
|
|
|
return (@output); |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _logger { |
|
55
|
0
|
|
|
0
|
|
|
my $level = shift; |
|
56
|
0
|
|
|
|
|
|
my $message = shift; |
|
57
|
0
|
0
|
|
|
|
|
print "$message\n" if $level; |
|
58
|
0
|
|
|
|
|
|
return 1; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |