File Coverage

blib/lib/Mail/Transport/Send.pm
Criterion Covered Total %
statement 18 54 33.3
branch 0 32 0.0
condition 0 3 0.0
subroutine 6 11 54.5
pod 5 5 100.0
total 29 105 27.6


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::Send;{
13             our $VERSION = '4.01';
14             }
15              
16 1     1   483 use parent 'Mail::Transport';
  1         2  
  1         8  
17              
18 1     1   109 use strict;
  1         3  
  1         27  
19 1     1   4 use warnings;
  1         2  
  1         62  
20              
21 1     1   6 use Log::Report 'mail-transport', import => [ qw/__x error warning/ ];
  1         2  
  1         8  
22              
23 1     1   242 use File::Spec ();
  1         2  
  1         22  
24 1     1   3 use Errno 'EAGAIN';
  1         1  
  1         752  
25              
26             #--------------------
27              
28             sub new(@)
29 0     0 1   { my $class = shift;
30 0 0         $class eq __PACKAGE__ or return $class->SUPER::new(@_);
31              
32 0           require Mail::Transport::Sendmail;
33 0           Mail::Transport::Sendmail->new(@_);
34             }
35              
36             #--------------------
37              
38             sub send($@)
39 0     0 1   { my ($self, $message, %args) = @_;
40              
41 0 0         $message = Mail::Message->coerce($message)
42             unless $message->isa('Mail::Message');
43              
44 0 0         $self->trySend($message, %args)
45             and return 1;
46              
47 0 0         $?==EAGAIN
48             or return 0;
49              
50 0           my ($interval, $retry) = $self->retry;
51 0 0         $interval = $args{interval} if exists $args{interval};
52 0 0         $retry = $args{retry} if exists $args{retry};
53              
54 0           while($retry!=0)
55 0           { sleep $interval;
56 0 0         return 1 if $self->trySend($message, %args);
57 0 0         $?==EAGAIN or return 0;
58 0           $retry--;
59             }
60              
61 0           0;
62             }
63              
64              
65             sub trySend($@)
66 0     0 1   { my $self = shift;
67 0           error __x"transporters of type {class} cannot send.", class => ref $self;
68             }
69              
70              
71             sub putContent($$@)
72 0     0 1   { my ($self, $message, $fh, %args) = @_;
73              
74 0 0         if($args{body_only}) { $message->body->print($fh) }
  0 0          
75 0           elsif($args{undisclosed}) { $message->Mail::Message::print($fh) }
76             else
77 0           { $message->head->printUndisclosed($fh);
78 0           $message->body->print($fh);
79             }
80              
81 0           $self;
82             }
83              
84              
85              
86             sub destinations($;$)
87 0     0 1   { my ($self, $message, $overrule) = @_;
88 0           my @to;
89              
90 0 0         if(defined $overrule) # Destinations overruled by user.
    0          
91 0 0 0       { @to = map { ref $_ && $_->isa('Mail::Address') ? ($_) : Mail::Address->parse($_) }
  0 0          
92             ref $overrule eq 'ARRAY' ? @$overrule : ($overrule);
93             }
94             elsif(my @rgs = $message->head->resentGroups)
95             { # Create with bounce
96 0           @to = $rgs[0]->destinations;
97 0 0         @to or warning(__x"resent group does not specify a destination."), return ();
98             }
99             else
100 0           { @to = $message->destinations;
101 0 0         @to or warning(__x"message has no destination."), return ();
102             }
103              
104 0           @to;
105             }
106              
107             #--------------------
108              
109             1;