From 6cb811c3bb1a5445e23035b4c9f74d8fdbed7e0a Mon Sep 17 00:00:00 2001 From: David Bourgault Date: Thu, 12 Apr 2018 11:43:49 -0400 Subject: [PATCH] Bug 8000: Make all branches use Koha::Email in C4::Letters Corrects the unique branch in C4::Letters that didn't use Koha::Email to build the %mail hash. From a search in all pl/pm files, all %mail now built with Koha::Email. Addresses CC and BCC fields (CC and BCC fields are ignored, except for NoticeBCC which is overriden by SendAllEmailsTo) --- C4/Letters.pm | 21 ++++++++++++--------- Koha/Email.pm | 3 +++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index d4664d0..a08a71d 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -580,18 +580,21 @@ sub SendAlerts { # ... then send mail my $library = Koha::Libraries->find( $userenv->{branch} ); - my %mail = ( - To => join( ',', @email), - Cc => join( ',', @cc), - From => $library->branchemail || C4::Context->preference('KohaAdminEmailAddress'), - Subject => Encode::encode( "UTF-8", "" . $letter->{title} ), - Message => $letter->{'is_html'} + my $email = Koha::Email->new(); + my %mail = $email->create_message_headers( + { + to => join( ',', @email), + cc => join( ',', @cc), + from => $library->branchemail || C4::Context->preference('KohaAdminEmailAddress'), + subject => Encode::encode( "UTF-8", "" . $letter->{title} ), + message => $letter->{'is_html'} ? _wrap_html( Encode::encode( "UTF-8", $letter->{'content'} ), Encode::encode( "UTF-8", "" . $letter->{'title'} )) : Encode::encode( "UTF-8", "" . $letter->{'content'} ), - 'Content-Type' => $letter->{'is_html'} + contenttype => $letter->{'is_html'} ? 'text/html; charset="utf-8"' : 'text/plain; charset="utf-8"', + } ); if ($type eq 'claimacquisition' || $type eq 'claimissues' ) { @@ -600,7 +603,7 @@ sub SendAlerts { $mail{'Sender'} = C4::Context->preference('ReturnpathDefault') if C4::Context->preference('ReturnpathDefault'); $mail{'Bcc'} = $userenv->{emailaddress} - if C4::Context->preference("ClaimsBccCopy"); + if C4::Context->preference("ClaimsBccCopy") and not C4::Context->preference("SendAllEmailsTo"); } unless ( Mail::Sendmail::sendmail(%mail) ) { @@ -1396,7 +1399,7 @@ sub _send_message_by_email { $sendmail_params{'Auth'} = {user => $username, pass => $password, method => $method} if $username; if ( my $bcc = C4::Context->preference('NoticeBcc') ) { - $sendmail_params{ Bcc } = $bcc; + $sendmail_params{ Bcc } = C4::Context->preference("SendAllEmailsTo") || $bcc; } _update_message_to_address($message->{'message_id'},$to_address) unless $message->{to_address}; #if initial message address was empty, coming here means that a to address was found and queue should be updated diff --git a/Koha/Email.pm b/Koha/Email.pm index 9f63e39..b9e3241 100644 --- a/Koha/Email.pm +++ b/Koha/Email.pm @@ -54,6 +54,9 @@ sub create_message_headers { if (C4::Context->preference('SendAllEmailsTo') && Email::Valid->address(C4::Context->preference('SendAllEmailsTo'))) { $mail{'To'} = C4::Context->preference('SendAllEmailsTo'); } + else { + $mail{'Cc'} = $params->{cc}; + } if ( C4::Context->preference('ReplytoDefault') ) { $params->{replyto} ||= C4::Context->preference('ReplytoDefault'); -- 2.7.4