From 08f1f7bc791cadbd620af4308a1f345796f3700b Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 6 Aug 2020 15:06:48 -0300 Subject: [PATCH] Bug 22343: Adapt Koha::Illrequest This patch makes Koha::Illrequest use the new syntax for Koha::Email and sending the email. Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize --- Koha/Illrequest.pm | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/Koha/Illrequest.pm b/Koha/Illrequest.pm index 5ab0adc210..269e45a949 100644 --- a/Koha/Illrequest.pm +++ b/Koha/Illrequest.pm @@ -22,7 +22,6 @@ use Modern::Perl; use Clone 'clone'; use File::Basename qw( basename ); use Encode qw( encode ); -use Mail::Sendmail; use Try::Tiny; use DateTime; @@ -40,6 +39,7 @@ use Koha::Biblios; use Koha::Items; use Koha::ItemTypes; use Koha::Libraries; + use C4::Circulation qw( CanBookBeIssued AddIssue ); use base qw(Koha::Object); @@ -1284,7 +1284,7 @@ attempts to submit the email. sub generic_confirm { my ( $self, $params ) = @_; - my $branch = Koha::Libraries->find($params->{current_branchcode}) + my $library = Koha::Libraries->find($params->{current_branchcode}) || die "Invalid current branchcode. Are you logged in as the database user?"; if ( !$params->{stage}|| $params->{stage} eq 'init' ) { my $draft->{subject} = "ILL Request"; @@ -1309,7 +1309,7 @@ Kind Regards EOF - my @address = map { $branch->$_ } + my @address = map { $library->$_ } qw/ branchname branchaddress1 branchaddress2 branchaddress3 branchzip branchcity branchstate branchcountry branchphone branchemail /; @@ -1346,27 +1346,28 @@ EOF "No target email addresses found. Either select at least one partner or check your ILL partner library records.") if ( !$to ); # Create the from, replyto and sender headers - my $from = $branch->branchemail; - my $replyto = $branch->branchreplyto || $from; + my $from = $library->branchemail; + my $reply_to = $library->branchreplyto || $from; Koha::Exceptions::Ill::NoLibraryEmail->throw( "Your library has no usable email address. Please set it.") if ( !$from ); # Create the email - my $message = Koha::Email->new; - my %mail = $message->create_message_headers( + my $email = Koha::Email->create( { - to => $to, - from => $from, - replyto => $replyto, - subject => Encode::encode( "utf8", $params->{subject} ), - message => Encode::encode( "utf8", $params->{body} ), - contenttype => 'text/plain', + to => $to, + from => $from, + reply_to => $reply_to, + subject => $params->{subject}, + text_body => $params->{body}, } ); + # Send it - my $result = sendmail(%mail); - if ( $result ) { + try { + + $email->send_or_die({ transport => $library->smtp_server->transport }); + $self->status("GENREQ")->store; $self->_backend_capability( 'set_requested_partners', @@ -1383,15 +1384,16 @@ EOF stage => 'commit', next => 'illview', }; - } else { + } + catch { return { error => 1, status => 'email_failed', - message => $Mail::Sendmail::error, + message => "$_", method => 'generic_confirm', stage => 'draft', }; - } + }; } else { die "Unknown stage, should not have happened." } -- 2.20.1