| 1 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Email::LocalDelivery::Mbox 1.201; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: deliver mail to an mbox | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | #pod =head1 INSTEAD... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | #pod Instead, consider using L<Email::Sender::Transport::Maildir>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use File::Path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Email::Simple 1.998; # needed for ->header_obj | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Fcntl ':flock'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Symbol qw(gensym); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | sub deliver { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deliver: called CC=7 SCAR=20.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # The slightly convoluted method of unrolling the stack is intended to limit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # the scope of which a large string at $_[1] might be in memory before being | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # constructed into an Email::Simple. -- rjbs, 2007-05-25 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | my $email; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | if (eval { $_[0]->isa('Email::Simple') }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | $email = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | my $text = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | $email = Email::Simple->new(\$text); # requires Email::Simple 1.998 or so | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | my @files = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | my @rv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | for my $file (@files) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | my $fh = $class->_open_fh($file) or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | print $fh "\n" if tell($fh) > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | print $fh $class->_from_line($email); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | print $fh $class->_escape_from_body($email); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # This will make streaming a bit more annoying. -- rjbs, 2007-05-25 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | print $fh "\n" unless $email->as_string =~ /\n$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | $class->_close_fh($fh) || next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | push @rv, $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | return @rv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | sub _open_fh { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_open_fh: called CC=5 SCAR=17.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | my ($class, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | my $dir = dirname($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | return if !-d $dir and not mkpath($dir); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-d $dir or mkpath($dir)
MC/DC0%0/2
-d $dir or mkpath($dir)
-d $dir
mkpath($dir)
Truth table33%1/3
A or B
A= -d $dirB= mkpath($dir)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | my $fh = gensym; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | open $fh, ">> $file" or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | ▶ | $class->getlock($fh) || return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | seek $fh, 0, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | return $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | sub _close_fh { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_close_fh: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | my ($class, $fh) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | $class->unlock($fh) || return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | ▶ | close $fh or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | sub _escape_from_body { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_escape_from_body: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | my ($class, $email) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | my $body = $email->body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | $body =~ s/^(From )/>$1/gm; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | return $email->header_obj->as_string . $email->crlf . $body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | ▶ | sub _from_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_from_line: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | my ($class, $email) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # The qmail way. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | ▶ | return $ENV{UFLINE} . $ENV{RPLINE} . $ENV{DTLINE} if exists $ENV{UFLINE}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # The boring way. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | return _from_line_boring($email); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | ▶ | sub _from_line_boring { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_from_line_boring: called CC=6 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | my $mail = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | ▶ | my $from = $mail->header("Return-path") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition36%4/11
$mail->header('Return-path') || $mail->header('Sender') || $mail->header('Reply-To') || $mail->header('From') || 'root@localhost'
$mail->header("Return-path") or $mail->header("Sender") or $mail->header("Reply-To") or $mail->header("From")
$mail->header("Return-path") or $mail->header("Sender") or $mail->header("Reply-To")
$mail->header("Return-path") or $mail->header("Sender")
MC/DC0%0/4
$mail->header('Return-path') || $mail->header('Sender') || $mail->header('Reply-To') || $mail->header('From') || 'root@localhost'
$mail->header("Return-path")
$mail->header("Sender")
$mail->header("Reply-To")
$mail->header("From")
Truth table20%1/5
A or B or C or D
A= $mail->header("Return-path")B= $mail->header("Sender")C= $mail->header("Reply-To")D= $mail->header("From")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | || $mail->header("Sender") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | || $mail->header("Reply-To") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | || $mail->header("From") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | || 'root@localhost'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | ▶ | $from = $1 if $from =~ /<(.*?)>/; # comment <email@address> -> email@address | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | $from =~ s/\s*\(.*\)\s*//; # email@address (comment) -> email@address | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | $from =~ s/\s+//g; # if any whitespace remains, get rid of it. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | my $fromtime = localtime; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | $fromtime =~ s/(:\d\d) \S+ (\d{4})$/$1 $2/; # strip timezone. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | return "From $from $fromtime\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | ▶ | sub getlock { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getlock: called CC=3 SCAR=13.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | my ($class, $fh) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | for (1 .. 10) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | ▶ | return 1 if flock($fh, LOCK_EX | LOCK_NB); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | sleep $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | ▶ | sub unlock { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unlock: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | my ($class, $fh) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | flock($fh, LOCK_UN); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||