| 1 | package Net::DNS::Mailbox; | ||||||||||||
| 2 | |||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 10 | our $VERSION = (qw$Id: Mailbox.pm 2002 2025-01-07 09:57:46Z willem $)[2]; | |||||||||||
| 7 | |||||||||||||
| 8 | |||||||||||||
| 9 | =head1 NAME | ||||||||||||
| 10 | |||||||||||||
| 11 | Net::DNS::Mailbox - DNS mailbox representation | ||||||||||||
| 12 | |||||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||||
| 14 | |||||||||||||
| 15 | use Net::DNS::Mailbox; | ||||||||||||
| 16 | |||||||||||||
| 17 | $mailbox = Net::DNS::Mailbox->new('user@example.com'); | ||||||||||||
| 18 | $address = $mailbox->address; | ||||||||||||
| 19 | |||||||||||||
| 20 | =head1 DESCRIPTION | ||||||||||||
| 21 | |||||||||||||
| 22 | The Net::DNS::Mailbox module implements a subclass of DNS domain name | ||||||||||||
| 23 | objects representing the DNS coded form of RFC822 mailbox address. | ||||||||||||
| 24 | |||||||||||||
| 25 | The Net::DNS::Mailbox1035 and Net::DNS::Mailbox2535 packages | ||||||||||||
| 26 | implement mailbox representation subtypes which provide the name | ||||||||||||
| 27 | compression and canonicalisation specified by RFC1035 and RFC2535. | ||||||||||||
| 28 | These are necessary to meet the backward compatibility requirements | ||||||||||||
| 29 | introduced by RFC3597. | ||||||||||||
| 30 | |||||||||||||
| 31 | =cut | ||||||||||||
| 32 | |||||||||||||
| 33 | |||||||||||||
| 34 | 10 | ▶ | use integer; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 35 | 10 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 36 | |||||||||||||
| 37 | 10 | ▶ | use base qw(Net::DNS::DomainName); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 38 | |||||||||||||
| 39 | |||||||||||||
| 40 | =head1 METHODS | ||||||||||||
| 41 | |||||||||||||
| 42 | =head2 new | ||||||||||||
| 43 | |||||||||||||
| 44 | $mailbox = Net::DNS::Mailbox->new('John Doe <john.doe@example.com>'); | ||||||||||||
| 45 | $mailbox = Net::DNS::Mailbox->new('john.doe@example.com'); | ||||||||||||
| 46 | $mailbox = Net::DNS::Mailbox->new('john\.doe.example.com'); | ||||||||||||
| 47 | |||||||||||||
| 48 | Creates a mailbox object representing the RFC822 mail address specified by | ||||||||||||
| 49 | the character string argument. An encoded domain name is also accepted for | ||||||||||||
| 50 | backward compatibility with Net::DNS 0.68 and earlier. | ||||||||||||
| 51 | |||||||||||||
| 52 | The argument string consists of printable characters from the 7-bit | ||||||||||||
| 53 | ASCII repertoire. | ||||||||||||
| 54 | |||||||||||||
| 55 | =cut | ||||||||||||
| 56 | |||||||||||||
| 57 | 57 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 58 | 57 | my $class = shift; | |||||||||||
| 59 | 57 | local $_ = shift; | |||||||||||
| 60 | 57 | ▶ | croak 'undefined mail address' unless defined $_; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 61 | |||||||||||||
| 62 | 55 | s/^.*<//g; # strip excess on left | |||||||||||
| 63 | 55 | s/>.*$//g; # strip excess on right | |||||||||||
| 64 | 55 | s/^\@.+://; # strip deprecated source route | |||||||||||
| 65 | 55 | s/\\\./\\046/g; # disguise escaped dots | |||||||||||
| 66 | |||||||||||||
| 67 | 55 | my ( $localpart, @domain ) = split /[@.]([^@;:"]*$)/; # split on rightmost @ | |||||||||||
| 68 | 55 | ▶ | s/\./\\046/g for $localpart ||= ''; # escape dots in local part | ||||||||||
|
Condition100%2/2
$localpart ||= ""
MC/DC100%1/1
$localpart ||= ""
$localpart
Truth table100%2/2
A
A= $localpart
| |||||||||||||
| 69 | |||||||||||||
| 70 | 55 | return bless __PACKAGE__->SUPER::new( join '.', $localpart, @domain ), $class; | |||||||||||
| 71 | } | ||||||||||||
| 72 | |||||||||||||
| 73 | |||||||||||||
| 74 | =head2 address | ||||||||||||
| 75 | |||||||||||||
| 76 | $address = $mailbox->address; | ||||||||||||
| 77 | |||||||||||||
| 78 | Returns a character string containing the RFC822 mailbox address | ||||||||||||
| 79 | corresponding to the encoded domain name representation described | ||||||||||||
| 80 | in RFC1035 section 8. | ||||||||||||
| 81 | |||||||||||||
| 82 | =cut | ||||||||||||
| 83 | |||||||||||||
| 84 | 54 | ▶ | sub address { | ||||||||||
|
Subroutine
address: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 85 | 54 | ▶ | return unless defined wantarray; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 86 | 22 | my @label = shift->label; | |||||||||||
| 87 | 22 | ▶ | local $_ = shift(@label) || return '<>'; | ||||||||||
|
Condition100%2/2
shift @label || (return '<>')
MC/DC100%1/1
shift @label || (return '<>')
shift @label
Truth table100%2/2
A
A= shift @label
| |||||||||||||
| 88 | 19 | s/\\\\//g; # delete escaped \ | |||||||||||
| 89 | 19 | s/^\\034(.*)\\034$/"$1"/; # unescape enclosing quotes | |||||||||||
| 90 | 19 | s/\\\d\d\d//g; # delete non-printable | |||||||||||
| 91 | 19 | s/\\\./\./g; # unescape dots | |||||||||||
| 92 | 19 | s/\\//g; # delete escapes | |||||||||||
| 93 | 19 | ▶ | return $_ unless scalar(@label); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 94 | 15 | return join '@', $_, join '.', @label; | |||||||||||
| 95 | } | ||||||||||||
| 96 | |||||||||||||
| 97 | |||||||||||||
| 98 | ######################################## | ||||||||||||
| 99 | |||||||||||||
| 100 | package Net::DNS::Mailbox1035; ## no critic ProhibitMultiplePackages | ||||||||||||
| 101 | 10 | our @ISA = qw(Net::DNS::Mailbox); | |||||||||||
| 102 | |||||||||||||
| 103 | 26 | ▶ | sub encode { return &Net::DNS::DomainName1035::encode; } | ||||||||||
|
Subroutine
encode: called CC=1 SCAR=0.0
| |||||||||||||
| 104 | |||||||||||||
| 105 | |||||||||||||
| 106 | package Net::DNS::Mailbox2535; ## no critic ProhibitMultiplePackages | ||||||||||||
| 107 | 10 | our @ISA = qw(Net::DNS::Mailbox); | |||||||||||
| 108 | |||||||||||||
| 109 | 9 | ▶ | sub encode { return &Net::DNS::DomainName2535::encode; } | ||||||||||
|
Subroutine
encode: called CC=1 SCAR=0.0
| |||||||||||||
| 110 | |||||||||||||
| 111 | |||||||||||||
| 112 | 10 | 1; | |||||||||||
| 113 | __END__ | ||||||||||||