line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::POP3::XOAuth2; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
745
|
use 5.008001; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
68
|
|
8
|
1
|
|
|
1
|
|
586
|
use Net::POP3; |
|
1
|
|
|
|
|
98525
|
|
|
1
|
|
|
|
|
74
|
|
9
|
1
|
|
|
1
|
|
534
|
use MIME::Base64; |
|
1
|
|
|
|
|
692
|
|
|
1
|
|
|
|
|
307
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.0.2'; |
12
|
|
|
|
|
|
|
|
13
|
0
|
|
|
0
|
|
|
*Net::POP3::_AUTH = sub { shift->command('AUTH', $_[0])->response() == Net::POP3::CMD_OK }; |
14
|
|
|
|
|
|
|
# Send a token directly |
15
|
0
|
|
|
0
|
|
|
*Net::POP3::_XOAUTH2_TOKEN = sub { shift->command($_[0])->response() == Net::POP3::CMD_OK }; |
16
|
|
|
|
|
|
|
*Net::POP3::xoauth2 = sub { |
17
|
0
|
0
|
0
|
0
|
|
|
@_ >= 1 && @_ <= 4 or croak 'usage: $pop3->xoauth2( USER, TOKEN, separate_flag )'; |
18
|
0
|
|
|
|
|
|
my ($me, $user, $token, $separate_flag) = @_; |
19
|
0
|
|
|
|
|
|
my $xoauth2_token = encode_base64("user=$user\001auth=Bearer $token\001\001"); |
20
|
0
|
|
|
|
|
|
$xoauth2_token =~ s/[\r\n]//g; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# If you use office365, need to call 'XOAUTH2' and token separately |
23
|
|
|
|
|
|
|
# https://docs.microsoft.com/ja-jp/Exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth |
24
|
0
|
0
|
|
|
|
|
if ($separate_flag) { |
25
|
0
|
|
|
|
|
|
$me->_AUTH("XOAUTH2"); |
26
|
0
|
|
|
|
|
|
my $r = $me->_XOAUTH2_TOKEN($xoauth2_token); |
27
|
0
|
0
|
|
|
|
|
return unless $r; |
28
|
|
|
|
|
|
|
} else { |
29
|
0
|
0
|
|
|
|
|
return unless ($me->_AUTH("XOAUTH2 $xoauth2_token")); |
30
|
|
|
|
|
|
|
} |
31
|
0
|
|
|
|
|
|
$me->_get_mailbox_count(); |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
35
|
|
|
|
|
|
|
__END__ |