Transport/Mailx.pm

filter: Statementstmt 31.9% 15 / 47 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 57.1% 4 / 7 Podpod 50.0% 1 / 2 totaltotal 21.7% 20 / 92 CC 15 SCAR 36.5
CC
15
Cov
19%
init
72.0
_try_send_bsdish
30.0
trySend
20.0
CRAP 38.6
« Transport.pm ↑ Summary Transport/Exim.pm »
1 # This code is part of Perl distribution Mail-Transport version 4.01.
2 # The POD got stripped from this file by OODoc version 3.05.
3 # For contributors see file ChangeLog.
4  
5 # This software is copyright (c) 2001-2025 by Mark Overmeer.
6  
7 # This is free software; you can redistribute it and/or modify it under
8 # the same terms as the Perl 5 programming language system itself.
9 # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10  
11  
12 package Mail::Transport::Mailx;{
13 1 our $VERSION = '4.01';
14 }
15  
16 1 ▶use parent 'Mail::Transport::Send';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use Log::Report 'mail-transport', import => [ qw/__x fault error/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 #--------------------
24  
25 sub init($)
26 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=8 SCAR=42.8
Pod undocumented
27 0 $args->{via} = 'mailx';
28  
29 0 ▶ $self->SUPER::init($args) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init($args) or return 0 0 0
30  
31 0 ▶ $self->{MTM_program} = $args->{proxy} || $self->findBinary('mailx') || $self->findBinary('Mail') || $self->findBinary('mail')
Branch: 1 branch
BranchTrueFalseTotal
$self->{"MTM_program"} = $args->{"proxy"} || $self->findBinary("mailx") || $self->findBinary("Mail") || $self->findBinary("mail") or &error(&__x("cannot find binary of mailx.")) 0 0 0
Condition0%0/9
$args->{'proxy'} || $self->findBinary('mailx') || $self->findBinary('Mail') || $self->findBinary('mail')
l!l&&r!l&&!r
000
$args->{"proxy"} or $self->findBinary("mailx") or $self->findBinary("Mail")
l!l&&r!l&&!r
000
$args->{"proxy"} or $self->findBinary("mailx")
l!l&&r!l&&!r
000
MC/DC0%0/4
$args->{'proxy'} || $self->findBinary('mailx') || $self->findBinary('Mail') || $self->findBinary('mail')
$args->{"proxy"} $self->findBinary("mailx") $self->findBinary("Mail") $self->findBinary('mail')
Truth table0%0/5
A or B or C || D
A= $args->{"proxy"}B= $self->findBinary("mailx")C= $self->findBinary("Mail")D= $self->findBinary('mail')
ABCDresult
1XXX1
01XX1
001X1
00011
00000
32 or error __x"cannot find binary of mailx.";
33  
34 0 ▶ $self->{MTM_style} = $args->{style} // ( $^O =~ m/linux|freebsd|bsdos|netbsd|openbsd/ ? 'BSD' : 'RFC822' );
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /linux|freebsd|bsdos|netbsd|openbsd/ ? : 0 0 0
Condition0%0/2
$args->{"style"} // ($^O =~ /linux|freebsd|bsdos|netbsd|openbsd/ ? "BSD" : "RFC822")
l!l
00
MC/DC0%0/1
$args->{"style"} // ($^O =~ /linux|freebsd|bsdos|netbsd|openbsd/ ? "BSD" : "RFC822")
$args->{"style"}
Truth table0%0/2
A
A= $args->{"style"}
Aresult
11
00
35 0 $self;
36 }
37  
38  
39 sub _try_send_bsdish($$)
40 0 ▶{ my ($self, $message, $args) = @_;
Subroutine _try_send_bsdish: not called CC=5 SCAR=34.0
41  
42 0 my @options = ('-s' => $message->subject);
43  
44 0 { local $" = ',';
45 0 my @cc = map $_->format, $message->cc;
46 0 ▶ push @options, ('-c' => "@cc") if @cc;
Branch: 1 branch
BranchTrueFalseTotal
if @cc 0 0 0
47  
48 0 my @bcc = map $_->format, $message->bcc;
49 0 ▶ push @options, ('-b' => "@bcc") if @bcc;
Branch: 1 branch
BranchTrueFalseTotal
if @bcc 0 0 0
50 }
51  
52 0 my @to = map $_->format, $message->to;
53 0 my $program = $self->{MTM_program};
54  
55 0 my $mailer;
56 0 ▶ if((open $mailer, '|-')==0)
Branch: 1 branch
BranchTrueFalseTotal
if (open($mailer, "|-") == 0) 0 0 0
57 0 { close STDOUT;
58 0 { exec $program, @options, @to }
59 0 fault __x"cannot open pipe to {program}", program => $program;
60 }
61  
62 0 $self->putContent($message, $mailer, body_only => 1);
63  
64 0 ▶ $mailer->close
Branch: 1 branch
BranchTrueFalseTotal
$mailer->close or &fault(&__x("errors when closing Mailx mailer {program}", "program", $program)) 0 0 0
65 or fault __x"errors when closing Mailx mailer {program}", program => $program;
66  
67 0 1;
68 }
69  
70 sub trySend($@)
71 0 ▶{ my ($self, $message, %args) = @_;
Subroutine trySend: not called CC=4 SCAR=30.0
Pod documented
72  
73 return $self->_try_send_bsdish($message, \%args)
74 0 ▶ if $self->{MTM_style} eq 'BSD';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MTM_style"} eq "BSD" 0 0 0
75  
76 0 my $program = $self->{MTM_program};
77 0 ▶ open my $mailer, '|-', $program, '-t'
Branch: 1 branch
BranchTrueFalseTotal
open my $mailer, "|-", $program, "-t" or &fault(&__x("cannot open pipe to {program}", "program", $program)) 0 0 0
78 or fault __x"cannot open pipe to {program}", program => $program;
79  
80 0 $self->putContent($message, $mailer);
81  
82 0 ▶ $mailer->close
Branch: 1 branch
BranchTrueFalseTotal
$mailer->close or &fault(&__x("errors when closing Mailx mailer {program}", "program", $program)) 0 0 0
83 or fault __x"errors when closing Mailx mailer {program}", program => $program;
84  
85 0 1;
86 }
87  
88 1 1;
« Transport.pm ↑ Summary Transport/Exim.pm »