| 1 | package Mail::Verp; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.000; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use vars qw($VERSION @ENCODE_MAP @DECODE_MAP $DEFAULT_SEPARATOR $SEPARATOR); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | $VERSION = '0.06'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | my @chars = qw(@ : % ! - [ ]); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | @ENCODE_MAP = map { quotemeta($_), sprintf '%.2X', ord($_) } ('+', @chars); | |||||||||||||||||||||||||||
| 14 | 1 | @DECODE_MAP = map { sprintf('%.2X', ord($_)), $_ } (@chars, '+'); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | $DEFAULT_SEPARATOR = '-'; #used as a constant | |||||||||||||||||||||||||||
| 18 | 1 | $SEPARATOR = $DEFAULT_SEPARATOR; #used by class methods. Can be changed. | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 129 | ▶ | sub separator { | ||||||||||||||||||||||||||
|
Subroutine
separator: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 129 | my $self = shift; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | #called as class or instance object? | ||||||||||||||||||||||||||||
| 24 | 129 | ▶ | my $var = ref($self) ? \$self->{separator} : \$SEPARATOR; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 129 | my $value = $$var; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 129 | ▶ | if (@_){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 49 | $$var = shift; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 129 | return $value; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | sub new | ||||||||||||||||||||||||||||
| 36 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 38 | 1 | ▶ | $self = bless { separator => $DEFAULT_SEPARATOR, @_ }, ref($self) || $self; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||
| 39 | 1 | $self->separator($self->{separator}); | |||||||||||||||||||||||||||
| 40 | 1 | return $self; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | sub encode | ||||||||||||||||||||||||||||
| 44 | 24 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
encode: called CC=9 SCAR=27.4
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 24 | my $self = shift; | |||||||||||||||||||||||||||
| 46 | 24 | my $sender = shift; | |||||||||||||||||||||||||||
| 47 | 24 | my $recipient = shift; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 24 | ▶ | unless ($sender){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | carp "Missing sender address"; | |||||||||||||||||||||||||||
| 51 | 0 | return; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 24 | ▶ | unless ($recipient){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | carp "Missing recipient address"; | |||||||||||||||||||||||||||
| 56 | 0 | return; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 24 | my ($slocal, $sdomain) = $sender =~ m/(.+)\@([^\@]+)$/; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 24 | ▶ | unless ($slocal && $sdomain){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$slocal and $sdomain
MC/DC0%0/2
$slocal and $sdomain
$slocal
$sdomain
Truth table33%1/3
A and B
A= $slocalB= $sdomain
| |||||||||||||||||||||||||||||
| 62 | 0 | carp "Cannot parse sender address [$sender]"; | |||||||||||||||||||||||||||
| 63 | 0 | return; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 24 | my ($rlocal, $rdomain) = $recipient =~ m/(.+)\@([^\@]+)$/; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 24 | ▶ | unless ($rlocal && $rdomain){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$rlocal and $rdomain
MC/DC0%0/2
$rlocal and $rdomain
$rlocal
$rdomain
Truth table33%1/3
A and B
A= $rlocalB= $rdomain
| |||||||||||||||||||||||||||||
| 69 | 0 | carp "Cannot parse recipient address [$recipient]"; | |||||||||||||||||||||||||||
| 70 | 0 | return; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 24 | ▶ | for (my $i = 0; $i < @ENCODE_MAP; $i += 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 192 | for my $t ($rlocal, $rdomain){ | |||||||||||||||||||||||||||
| 75 | 384 | $t =~ s/$ENCODE_MAP[$i]/+$ENCODE_MAP[$i + 1]/g; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 24 | return join('', $slocal, $self->separator, $rlocal, '=', $rdomain, '@', $sdomain); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | sub decode | ||||||||||||||||||||||||||||
| 83 | 48 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
decode: called CC=6 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | 48 | my $self = shift; | |||||||||||||||||||||||||||
| 85 | 48 | my $address = shift; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 48 | ▶ | unless ($address){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | carp "Missing encoded address"; | |||||||||||||||||||||||||||
| 89 | 0 | return; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 48 | my $separator = $self->separator; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 48 | ▶ | if (my ($slocal, $rlocal, $rdomain, $sdomain) = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | $address =~ m/^(.+?)\Q${separator}\E(.+)=([^=\@]+)\@(.+)/){ | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | # warn "$address $slocal $rlocal $rdomain $sdomain\n"; | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 48 | ▶ | for (my $i = 0; $i < @DECODE_MAP; $i += 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 384 | for my $t ($rlocal, $rdomain){ | |||||||||||||||||||||||||||
| 101 | 768 | $t =~ s/\+$DECODE_MAP[$i]/$DECODE_MAP[$i + 1]/ig; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 48 | ▶ | return (qq[$slocal\@$sdomain], qq[$rlocal\@$rdomain]) if wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | return qq[$rlocal\@$rdomain]; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | else { | ||||||||||||||||||||||||||||
| 109 | 0 | return $address; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 1 | 1; | |||||||||||||||||||||||||||
| 115 | __END__ | ||||||||||||||||||||||||||||