File Coverage

blib/lib/Mail/Transport.pm
Criterion Covered Total %
statement 15 47 31.9
branch 0 18 0.0
condition 0 16 0.0
subroutine 5 10 50.0
pod 4 5 80.0
total 24 96 25.0


line stmt bran cond sub pod time code
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;{
13             our $VERSION = '4.01';
14             }
15              
16 1     1   595216 use parent 'Mail::Reporter';
  1         1  
  1         5  
17              
18 1     1   59 use strict;
  1         1  
  1         16  
19 1     1   4 use warnings;
  1         1  
  1         41  
20              
21 1     1   4 use Log::Report 'mail-transport', import => [ qw/__x error panic/ ];
  1         1  
  1         6  
22              
23 1     1   144 use File::Spec ();
  1         1  
  1         657  
24              
25             #--------------------
26              
27             my %mailers = (
28             exim => '::Exim',
29             imap => '::IMAP4',
30             imap4 => '::IMAP4',
31             mail => '::Mailx',
32             mailx => '::Mailx',
33             pop => '::POP3',
34             pop3 => '::POP3',
35             postfix => '::Sendmail',
36             qmail => '::Qmail',
37             sendmail => '::Sendmail',
38             smtp => '::SMTP'
39             );
40              
41              
42             sub new(@)
43 0     0 1   { my $class = shift;
44              
45 0 0 0       $class eq __PACKAGE__ || $class eq "Mail::Transport::Send"
46             or return $class->SUPER::new(@_);
47              
48             # auto restart by creating the right transporter.
49              
50 0           my %args = @_;
51 0 0 0       my $via = lc($args{via} // '') or panic "no transport protocol provided";
52              
53 0 0         $via = 'Mail::Transport'.$mailers{$via} if exists $mailers{$via};
54 0           eval "require $via";
55 0 0         $@ ? undef : $via->new(@_);
56             }
57              
58             sub init($)
59 0     0 0   { my ($self, $args) = @_;
60 0           $self->SUPER::init($args);
61              
62 0   0       $self->{MT_hostname} = $args->{hostname} // 'localhost';
63 0           $self->{MT_port} = $args->{port};
64 0           $self->{MT_username} = $args->{username};
65 0           $self->{MT_password} = $args->{password};
66 0   0       $self->{MT_interval} = $args->{interval} || 30;
67 0   0       $self->{MT_retry} = $args->{retry} || -1;
68 0   0       $self->{MT_timeout} = $args->{timeout} || 120;
69 0           $self->{MT_proxy} = $args->{proxy};
70              
71 0 0 0       if(my $exec = $args->{executable} || $args->{proxy})
72 0           { $self->{MT_exec} = $exec;
73              
74 0 0         File::Spec->file_name_is_absolute($exec)
75             or error __x"avoid program abuse: specify an absolute path for {program}.", program => $exec;
76              
77 0 0         -x $exec
78             or error __x"executable {program} does not exist.", program => $exec;
79             }
80              
81 0           $self;
82             }
83              
84             #--------------------
85              
86 0     0 1   sub remoteHost() { @{$_[0]}{ qw/MT_hostname MT_port MT_username MT_password/ } }
  0            
87              
88              
89 0     0 1   sub retry() { @{$_[0]}{ qw/MT_interval MT_retry MT_timeout/ } }
  0            
90              
91              
92             my @safe_directories = qw(/usr/local/bin /usr/bin /bin /sbin /usr/sbin /usr/lib);
93              
94             sub findBinary($@)
95 0     0 1   { my ($self, $name) = (shift, shift);
96              
97             return $self->{MT_exec}
98 0 0         if exists $self->{MT_exec};
99              
100 0           foreach (@_, @safe_directories)
101 0           { my $fullname = File::Spec->catfile($_, $name);
102 0 0         return $fullname if -x $fullname;
103             }
104              
105 0           undef;
106             }
107              
108             #--------------------
109              
110             1;