View | Details | Raw Unified | Return to bug 22343
Collapse All | Expand All

(-)a/Koha/SMTP/Server.pm (+38 lines)
Lines 21-26 use Koha::Database; Link Here
21
use Koha::Exceptions::Object;
21
use Koha::Exceptions::Object;
22
use Koha::SMTP::Servers;
22
use Koha::SMTP::Servers;
23
23
24
use Email::Sender::Transport::SMTP;
25
24
use base qw(Koha::Object);
26
use base qw(Koha::Object);
25
27
26
=head1 NAME
28
=head1 NAME
Lines 100-105 sub library { Link Here
100
    return Koha::Library->_new_from_dbic($self->_result->library);
102
    return Koha::Library->_new_from_dbic($self->_result->library);
101
}
103
}
102
104
105
=head3 transport
106
107
    my $transport = $smtp_server->transport;
108
    sendmail( $message, { transport => $transport } );
109
110
Returns an I<Email::Sender::Transport::SMTP> object that can be used directly
111
with Email::Sender.
112
113
=cut
114
115
sub transport {
116
    my ($self) = @_;
117
118
    my $params = {
119
        host => $self->host,
120
        port => $self->port,
121
    };
122
123
    $params->{ssl} = $self->ssl_mode
124
        unless $self->ssl_mode eq 'disabled';
125
126
    $params->{timeout} = $self->timeout
127
        if $self->timeout;
128
129
    $params->{sasl_username} = $self->user_name
130
        if $self->user_name;
131
132
    $params->{sasl_password} = $self->password
133
        if $self->password;
134
135
136
    my $transport = Email::Sender::Transport::SMTP->new( $params );
137
138
    return $transport;
139
}
140
103
=head3 to_api_mapping
141
=head3 to_api_mapping
104
142
105
This method returns the mapping for representing a Koha::SMTP::Server object
143
This method returns the mapping for representing a Koha::SMTP::Server object
(-)a/cpanfile (+1 lines)
Lines 36-41 requires 'Digest::MD5', '2.36'; Link Here
36
requires 'Digest::SHA', '5.43';
36
requires 'Digest::SHA', '5.43';
37
requires 'Email::Date', '1.103';
37
requires 'Email::Date', '1.103';
38
requires 'Email::MessageID', '1.406';
38
requires 'Email::MessageID', '1.406';
39
requires 'Email::Sender', '1.300030';
39
requires 'Email::Valid', '0.190';
40
requires 'Email::Valid', '0.190';
40
requires 'Exception::Class', '1.38';
41
requires 'Exception::Class', '1.38';
41
requires 'File::Slurp', '9999.13';
42
requires 'File::Slurp', '9999.13';
(-)a/t/db_dependent/Koha/SMTP/Server.t (-2 / +28 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 2;
20
use Test::More tests => 3;
21
use Test::Exception;
21
use Test::Exception;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 118-120 subtest 'store() tests' => sub { Link Here
118
118
119
    $schema->storage->txn_rollback;
119
    $schema->storage->txn_rollback;
120
};
120
};
121
- 
121
122
subtest 'transport() tests' => sub {
123
124
    plan tests => 4;
125
126
    $schema->storage->txn_begin;
127
128
    my $server = $builder->build_object(
129
        {
130
            class => 'Koha::SMTP::Servers',
131
            value => { ssl_mode => 'disabled' }
132
        }
133
    );
134
135
    my $transport = $server->transport;
136
137
    is( ref($transport), 'Email::Sender::Transport::SMTP', 'Type is correct' );
138
    is( $transport->ssl, 0, 'SSL is not set' );
139
140
    $server->set({ ssl_mode => 'ssl' })->store;
141
    $transport = $server->transport;
142
143
    is( ref($transport), 'Email::Sender::Transport::SMTP', 'Type is correct' );
144
    is( $transport->ssl, 'ssl', 'SSL is set' );
145
146
    $schema->storage->txn_rollback;
147
};

Return to bug 22343