File Coverage

blib/lib/URI/_emailauth.pm
Criterion Covered Total %
statement 46 46 100.0
branch 17 20 85.0
condition 2 3 66.6
subroutine 6 6 100.0
pod 0 2 0.0
total 71 77 92.2


line stmt bran cond sub pod time code
1             package URI::_emailauth;
2              
3 2     2   1336 use strict;
  2         6  
  2         89  
4 2     2   12 use warnings;
  2         4  
  2         149  
5              
6             our $VERSION = '5.34';
7              
8 2     2   12 use parent 'URI::_server';
  2         3  
  2         16  
9              
10 2     2   144 use URI::Escape qw(uri_unescape);
  2         5  
  2         1396  
11              
12             # Common user/auth code used in email URL schemes, such as POP, SMTP, IMAP.
13             # ://;auth=@:
14              
15             sub user
16             {
17 14     14 0 1390 my $self = shift;
18 14         44 my $old = $self->userinfo;
19              
20 14 100       34 if (@_) {
21 8         14 my $new_info = $old;
22 8 100       18 $new_info = "" unless defined $new_info;
23 8         29 $new_info =~ s/^[^;]*//;
24              
25 8         15 my $new = shift;
26 8 100 66     28 if (!defined($new) && !length($new_info)) {
27 2         7 $self->userinfo(undef);
28             } else {
29 6 50       12 $new = "" unless defined $new;
30 6         12 $new =~ s/%/%25/g;
31 6         45 $new =~ s/;/%3B/g;
32 6         68 $self->userinfo("$new$new_info");
33             }
34             }
35              
36 14 100       32 return undef unless defined $old;
37 10         22 $old =~ s/;.*//;
38 10         29 return uri_unescape($old);
39             }
40              
41             sub auth
42             {
43 10     10 0 735 my $self = shift;
44 10         32 my $old = $self->userinfo;
45              
46 10 100       26 if (@_) {
47 6         13 my $new = $old;
48 6 50       16 $new = "" unless defined $new;
49 6         19 $new =~ s/(^[^;]*)//;
50 6         13 my $user = $1;
51 6         13 $new =~ s/;auth=[^;]*//i;
52              
53              
54 6         7 my $auth = shift;
55 6 100       14 if (defined $auth) {
56 4         9 $auth =~ s/%/%25/g;
57 4         7 $auth =~ s/;/%3B/g;
58 4         8 $new = ";AUTH=$auth$new";
59             }
60 6         35 $self->userinfo("$user$new");
61              
62             }
63              
64 10 50       24 return undef unless defined $old;
65 10         30 $old =~ s/^[^;]*//;
66 10 100       40 return uri_unescape($1) if $old =~ /;auth=(.*)/i;
67 6         16 return;
68             }
69              
70             1;