| 1 | package URI::mailto; # RFC 2368 | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 2 | our $VERSION = '5.40'; | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 2 | ▶ | use parent qw(URI URI::_query); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 14 | ▶ | sub to { | ||||||||||||||||||
|
Subroutine
to: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||
| 11 | 14 | my $self = shift; | |||||||||||||||||||
| 12 | 14 | my @old = $self->headers; | |||||||||||||||||||
| 13 | 14 | ▶ | if (@_) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 14 | 3 | my @new = @old; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | # get rid of any other to: fields | ||||||||||||||||||||
| 17 | 3 | ▶ | for (my $i = 0; $i < @new; $i += 2) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 18 | 6 | ▶ | if (lc($new[$i] || '') eq "to") { | ||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$new[$i] || ''
MC/DC100%1/1
$new[$i] || ''
$new[$i]
Truth table100%2/2
A
A= $new[$i]
| |||||||||||||||||||||
| 19 | 3 | splice(@new, $i, 2); | |||||||||||||||||||
| 20 | 3 | redo; | |||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | } | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 3 | my $to = shift; | |||||||||||||||||||
| 25 | 3 | ▶ | $to = "" unless defined $to; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | 3 | unshift(@new, "to" => $to); | |||||||||||||||||||
| 27 | 3 | $self->headers(@new); | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | 14 | ▶ | return unless defined wantarray; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 12 | my @to; | |||||||||||||||||||
| 32 | 12 | ▶ | while (@old) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | 15 | my $h = shift @old; | |||||||||||||||||||
| 34 | 15 | my $v = shift @old; | |||||||||||||||||||
| 35 | 15 | ▶ | push(@to, $v) if lc($h) eq "to"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | 12 | join(",", @to); | |||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 20 | ▶ | sub headers { | ||||||||||||||||||
|
Subroutine
headers: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||
| 42 | 20 | my $self = shift; | |||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | # The trick is to just treat everything as the query string... | ||||||||||||||||||||
| 45 | 20 | my $opaque = "to=" . $self->opaque; | |||||||||||||||||||
| 46 | 20 | $opaque =~ s/\?/&/; | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 20 | ▶ | if (@_) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | 4 | my @new = @_; | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | # strip out any "to" fields | ||||||||||||||||||||
| 52 | 4 | my @to; | |||||||||||||||||||
| 53 | 4 | ▶ | for (my $i = 0; $i < @new; $i += 2) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | 10 | ▶ | if (lc($new[$i] || '') eq "to") { | ||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$new[$i] || ''
MC/DC100%1/1
$new[$i] || ''
$new[$i]
Truth table100%2/2
A
A= $new[$i]
| |||||||||||||||||||||
| 55 | 4 | push(@to, (splice(@new, $i, 2))[1]); # remove header | |||||||||||||||||||
| 56 | 4 | redo; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 4 | my $new = join(",", @to); | |||||||||||||||||||
| 61 | 4 | $new =~ s/%/%25/g; | |||||||||||||||||||
| 62 | 4 | $new =~ s/\?/%3F/g; | |||||||||||||||||||
| 63 | 4 | $self->opaque($new); | |||||||||||||||||||
| 64 | 4 | ▶ | $self->query_form(@new) if @new; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | 20 | ▶ | return unless defined wantarray; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | # I am lazy today... | ||||||||||||||||||||
| 69 | 16 | URI->new("mailto:?$opaque")->query_form; | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | # https://datatracker.ietf.org/doc/html/rfc6068#section-5 requires | ||||||||||||||||||||
| 73 | # plus signs (+) not to be turned into spaces | ||||||||||||||||||||
| 74 | 17 | ▶ | sub query_form { | ||||||||||||||||||
|
Subroutine
query_form: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 75 | 17 | my $self = shift; | |||||||||||||||||||
| 76 | 17 | my @fields = $self->SUPER::query_form(@_); | |||||||||||||||||||
| 77 | 17 | ▶ | for (my $i = 0; $i < @fields; $i += 2) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 78 | 16 | ▶ | if ($fields[0] eq 'to') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | 16 | $fields[1] =~ s/ /+/g; | |||||||||||||||||||
| 80 | 16 | last; | |||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | 17 | return @fields; | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 2 | 1; | |||||||||||||||||||