From ca346b72f016efc74ec3ef9a5ce3be6bfc2b118d Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Tue, 12 Aug 2014 09:54:48 +1200 Subject: [PATCH] [SIGNED-OFF] Bug 9530: Making changes to C4::Letters Content-Type: text/plain; charset="utf-8" So notices using it (circulation, holds etc) will now use the new behaviour To test: 1/ Edit the new systempreferences (ReplytoDefault and ReturnpathDefault) 2/ Optionally edit the branch the mail will be sent from, adding email addresses 3/ Test some mails, a circulation alert, an acquisitions claim, or a newly created borrower alert 4/ Check that the mails have the correct From, Replyto and ReturnPath set The rules are If the values are set in the branch use that, else use the syspref Signed-off-by: Owen Leonard --- C4/Letters.pm | 79 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 26 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index 1d916e0..45b8e4e 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -34,6 +34,7 @@ use Koha::DateUtils; use Date::Calc qw( Add_Delta_Days ); use Encode; use Carp; +use Koha::Email; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); @@ -262,11 +263,10 @@ sub SendAlerts { # find the list of borrowers to alert my $alerts = getalert( '', 'issue', $externalid ); foreach (@$alerts) { - my $borinfo = C4::Members::GetMember('borrowernumber' => $_->{'borrowernumber'}); my $email = $borinfo->{email} or next; - # warn "sending issues..."; +# warn "sending issues..."; my $userenv = C4::Context->userenv; my $branchdetails = GetBranchDetail($_->{'branchcode'}); my $letter = GetPreparedLetter ( @@ -283,13 +283,20 @@ sub SendAlerts { ) or return; # ... then send mail - my %mail = ( - To => $email, - From => $branchdetails->{'branchemail'} || C4::Context->preference("KohaAdminEmailAddress"), - Subject => Encode::encode( "utf8", "" . $letter->{title} ), - Message => Encode::encode( "utf8", "" . $letter->{content} ), - 'Content-Type' => 'text/plain; charset="utf8"', - ); + my $message = Koha::Email->new(); + my %mail = $message->create_message_headers( + { + to => $email, + from => $branchdetails->{'branchemail'}, + replyto => $branchdetails->{'branchreplyto'}, + sender => $branchdetails->{'branchreturnpath'}, + subject => Encode::encode( "utf8", "" . $letter->{title} ), + message => + Encode::encode( "utf8", "" . $letter->{content} ), + contenttype => 'text/plain; charset="utf8"', + + } + ); sendmail(%mail) or carp $Mail::Sendmail::error; } } @@ -356,6 +363,11 @@ sub SendAlerts { Message => Encode::encode( "utf8", "" . $letter->{content} ), 'Content-Type' => 'text/plain; charset="utf8"', ); + $mail{'Reply-to'} = C4::Context->preference('ReplytoDefault') + if C4::Context->preference('ReplytoDefault'); + $mail{'Sender'} = C4::Context->preference('ReturnpathDefault') + if C4::Context->preference('ReturnpathDefault'); + sendmail(%mail) or carp $Mail::Sendmail::error; logaction( @@ -384,14 +396,18 @@ sub SendAlerts { substitute => { 'borrowers.password' => $externalid->{'password'} }, want_librarian => 1, ) or return; - return { error => "no_email" } unless $externalid->{'emailaddr'}; - my %mail = ( - To => $externalid->{'emailaddr'}, - From => $branchdetails->{'branchemail'} || C4::Context->preference("KohaAdminEmailAddress"), - Subject => Encode::encode( "utf8", $letter->{'title'} ), - Message => Encode::encode( "utf8", $letter->{'content'} ), - 'Content-Type' => 'text/plain; charset="utf8"', + my $email = Koha::Email->new(); + my %mail = $email->create_message_headers( + { + to => $externalid->{'emailaddr'}, + from => $branchdetails->{'branchemail'}, + replyto => $branchdetails->{'branchreplyto'}, + sender => $branchdetails->{'branchreturnpath'}, + subject => Encode::encode( "utf8", "" . $letter->{'title'} ), + message => Encode::encode( "utf8", "" . $letter->{'content'} ), + contenttype => 'text/plain; charset="utf8"' + } ); sendmail(%mail) or carp $Mail::Sendmail::error; } @@ -949,17 +965,28 @@ sub _send_message_by_email { my $content = encode('utf8', $message->{'content'}); my $content_type = $message->{'content_type'} || 'text/plain; charset="UTF-8"'; my $is_html = $content_type =~ m/html/io; - - my $branch_email = ( $member ) ? GetBranchDetail( $member->{'branchcode'} )->{'branchemail'} : undef; - - my %sendmail_params = ( - To => $to_address, - From => $message->{'from_address'} || $branch_email || C4::Context->preference('KohaAdminEmailAddress'), - Subject => $subject, - charset => 'utf8', - Message => $is_html ? _wrap_html($content, $subject) : $content, - 'content-type' => $content_type, + my $branch_email = undef; + my $branch_replyto = undef; + my $branch_returnpath = undef; + if ($member){ + my $branchdetail = GetBranchDetail( $member->{'branchcode'} ); + $branch_email = $branchdetail->{'branchemail'}; + $branch_replyto = $branchdetail->{'branchreplyto'}; + $branch_returnpath = $branchdetail->{'branchreturnpath'}; + } + my $email = Koha::Email->new(); + my %sendmail_params = $email->create_message_headers( + { + to => $to_address, + from => $message->{'from_address'} || $branch_email, + replyto => $branch_replyto, + sender => $branch_returnpath, + subject => $subject, + message => $is_html ? _wrap_html( $content, $subject ) : $content, + contenttype => $content_type + } ); + $sendmail_params{'Auth'} = {user => $username, pass => $password, method => $method} if $username; if ( my $bcc = C4::Context->preference('OverdueNoticeBcc') ) { $sendmail_params{ Bcc } = $bcc; -- 1.7.9.5