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
|
|
390
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
386
|
use Moo; |
|
1
|
|
|
|
|
9420
|
|
|
1
|
|
|
|
|
6
|
|
9
|
1
|
|
|
1
|
|
1465
|
use Net::IMAP::Simple; |
|
1
|
|
|
|
|
29255
|
|
|
1
|
|
|
|
|
32
|
|
10
|
1
|
|
|
1
|
|
430
|
use Email::Simple; |
|
1
|
|
|
|
|
3012
|
|
|
1
|
|
|
|
|
21
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use Data::Dumper; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
225
|
|
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__ |