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   882 use strict;
  2         3  
  2         58  
4 2     2   20 use warnings;
  2         3  
  2         97  
5              
6             our $VERSION = '5.35';
7              
8 2     2   7 use parent 'URI::_server';
  2         2  
  2         12  
9              
10 2     2   92 use URI::Escape qw(uri_unescape);
  2         4  
  2         743  
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 1062 my $self = shift;
18 14         29 my $old = $self->userinfo;
19              
20 14 100       26 if (@_) {
21 8         10 my $new_info = $old;
22 8 100       11 $new_info = "" unless defined $new_info;
23 8         36 $new_info =~ s/^[^;]*//;
24              
25 8         10 my $new = shift;
26 8 100 66     25 if (!defined($new) && !length($new_info)) {
27 2         4 $self->userinfo(undef);
28             } else {
29 6 50       18 $new = "" unless defined $new;
30 6         8 $new =~ s/%/%25/g;
31 6         37 $new =~ s/;/%3B/g;
32 6         37 $self->userinfo("$new$new_info");
33             }
34             }
35              
36 14 100       25 return undef unless defined $old;
37 10         15 $old =~ s/;.*//;
38 10         19 return uri_unescape($old);
39             }
40              
41             sub auth
42             {
43 10     10 0 612 my $self = shift;
44 10         16 my $old = $self->userinfo;
45              
46 10 100       24 if (@_) {
47 6         7 my $new = $old;
48 6 50       10 $new = "" unless defined $new;
49 6         15 $new =~ s/(^[^;]*)//;
50 6         9 my $user = $1;
51 6         9 $new =~ s/;auth=[^;]*//i;
52              
53              
54 6         9 my $auth = shift;
55 6 100       9 if (defined $auth) {
56 4         4 $auth =~ s/%/%25/g;
57 4         6 $auth =~ s/;/%3B/g;
58 4         6 $new = ";AUTH=$auth$new";
59             }
60 6         14 $self->userinfo("$user$new");
61              
62             }
63              
64 10 50       15 return undef unless defined $old;
65 10         21 $old =~ s/^[^;]*//;
66 10 100       27 return uri_unescape($1) if $old =~ /;auth=(.*)/i;
67 6         12 return;
68             }
69              
70             1;