| 1 | # Copyrights 1995-2024 by [Mark Overmeer <markov@cpan.org>]. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # For other contributors see ChangeLog. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # See the manual pages for details on the licensing terms. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Pod stripped from pm file by OODoc 2.03. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # This code is part of the bundle MailTools. Meta-POD processed with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # OODoc into POD and HTML manual-pages. See README.md for Copyright. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # Licensed under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | package Mail::Util;{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | our $VERSION = '2.22'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | our @EXPORT_OK = qw(read_mbox maildomain mailaddress); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub Version { our $VERSION } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Version: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | my ($domain, $mailaddress); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | my @sendmailcf = qw(/etc /etc/sendmail /etc/ucblib | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | /etc/mail /usr/lib /var/adm/sendmail); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | sub read_mbox($) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | { my $file = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_mbox: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | local *FH; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | open FH,'<', $file | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | or croak "cannot open '$file': $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | local $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my @mbox; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my $mail = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $blank = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | while(<FH>) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | { if($blank && /^From .*\d{4}/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$blank and /^From .*\d{4}/
MC/DC0%0/2
$blank and /^From .*\d{4}/
$blank
/^From .*\d{4}/
Truth table0%0/3
A and B
A= $blankB= /^From .*\d{4}/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | { push @mbox, $mail if @$mail; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $mail = [ $_ ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | $blank = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | { $blank = m/^$/ ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | push @$mail, $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | push @mbox, $mail if @$mail; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | close FH; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | wantarray ? @mbox : \@mbox; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | sub maildomain() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | { return $domain | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
maildomain: not called CC=24 SCAR=64.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | if defined $domain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | $domain = $ENV{MAILDOMAIN} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | and return $domain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # Try sendmail configuration file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my $config = (grep -r, map {"$_/sendmail.cf"} @sendmailcf)[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | local *CF; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | local $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if(defined $config && open CF, '<', $config) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $config and open CF, "<", $config
MC/DC0%0/2
defined $config and open CF, "<", $config
defined $config
open CF, "<", $config
Truth table0%0/3
A and B
A= defined $configB= open CF, "<", $config
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | { my %var; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | while(<CF>) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | { if(my ($v, $arg) = /^D([a-zA-Z])([\w.\$\-]+)/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | { $arg =~ s/\$([a-zA-Z])/exists $var{$1} ? $var{$1} : '$'.$1/eg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | $var{$v} = $arg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | close CF; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | $domain = $var{j} if defined $var{j}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | $domain = $var{M} if defined $var{M}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | $domain = $1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$domain and $domain =~ /([A-Za-z0-9](?:[\.\-A-Za-z0-9]+))/
MC/DC0%0/2
$domain and $domain =~ /([A-Za-z0-9](?:[\.\-A-Za-z0-9]+))/
$domain
$domain =~ /([A-Za-z0-9](?:[\.\-A-Za-z0-9]+))/
Truth table0%0/3
A and B
A= $domainB= $domain =~ /([A-Za-z0-9](?:[\.\-A-Za-z0-9]+))/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | if $domain && $domain =~ m/([A-Za-z0-9](?:[\.\-A-Za-z0-9]+))/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | return $domain | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $domain and not $domain =~ /\$/
MC/DC0%0/2
defined $domain and not $domain =~ /\$/
defined $domain
not $domain =~ /\$/
Truth table0%0/3
A and not(B)
A= defined $domainB= not $domain =~ /\$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | if defined $domain && $domain !~ /\$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # Try smail config file if exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if(open CF, '<', "/usr/lib/smail/config") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | { while(<CF>) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | { if( /\A\s*hostnames?\s*=\s*(\S+)/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | { $domain = (split /\:/,$1)[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | close CF; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | return $domain | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | if defined $domain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # Try a SMTP connection to 'mailhost' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if(eval {require Net::SMTP}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | { foreach my $host (qw(mailhost localhost)) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | { # hosts are local, so short timeout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my $smtp = eval { Net::SMTP->new($host, Timeout => 5) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if(defined $smtp) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | { $domain = $smtp->domain; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $smtp->quit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # Use internet(DNS) domain name, if it can be found | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | $domain = Net::Domain::domainname() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if !defined $domain && eval {require Net::Domain}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $domain and eval {
do {
require Net::Domain
}
}
MC/DC0%0/2
not defined $domain and eval {
do {
require Net::Domain
}
}
not defined $domain
eval {
do {
require Net::Domain
}
}
Truth table0%0/3
not(A) and B
A= not defined $domainB= eval {
do {
require Net::Domain
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | $domain ||= "localhost"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$domain ||= "localhost"
MC/DC0%0/1
$domain ||= "localhost"
$domain
Truth table0%0/2
A
A= $domain
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | sub mailaddress(;$) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | { $mailaddress = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mailaddress: not called CC=10 SCAR=44.7
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | return $mailaddress | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | if defined $mailaddress; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # Get user name from environment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | $mailaddress = $ENV{MAILADDRESS}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | unless($mailaddress || $^O ne 'MacOS') | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mailaddress or $^O ne "MacOS"
MC/DC0%0/2
$mailaddress or $^O ne "MacOS"
$mailaddress
$^O ne "MacOS"
Truth table0%0/3
A or B
A= $mailaddressB= $^O ne "MacOS"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | { require Mac::InternetConfig; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 3 | ▶ | no strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | Mac::InternetConfig->import; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $mailaddress = $InternetConfig{kICEmail()}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | $mailaddress ||= $ENV{USER} || $ENV{LOGNAME} || eval {getpwuid $>} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/11
$mailaddress ||= $ENV{"USER"} || $ENV{"LOGNAME"} || eval {
do {
getpwuid $>
}
} || "postmaster"
$ENV{'USER'} || $ENV{'LOGNAME'} || eval {
do {
getpwuid $>
}
} || 'postmaster'
$ENV{"USER"} or $ENV{"LOGNAME"} or eval {
do {
getpwuid $>
}
}
$ENV{"USER"} or $ENV{"LOGNAME"}
MC/DC0%0/4
$mailaddress ||= $ENV{"USER"} || $ENV{"LOGNAME"} || eval {
do {
getpwuid $>
}
} || "postmaster"
$mailaddress
$ENV{"USER"}
$ENV{"LOGNAME"}
eval {
do {
getpwuid $>
}
}
Truth table0%0/5
A ||= B or C or D
A= $mailaddressB= $ENV{"USER"}C= $ENV{"LOGNAME"}D= eval {
do {
getpwuid $>
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | || "postmaster"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # Add domain if it does not exist | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | $mailaddress .= '@' . maildomain | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | if $mailaddress !~ /\@/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $mailaddress =~ s/(^.*<|>.*$)//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | $mailaddress; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||