From 298abcb4cb54ddc6c93c451fa8a935c9672ba1ab Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 8 May 2024 13:22:02 +0100 Subject: [PATCH] Bug 31627: (QA follow-up) Catch more locations This patch moves the header set into Koha::Email->create and passes the template_id in a few additional locations to ensure we catch more cases. Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- C4/Letters.pm | 27 ++++++++++++++++----------- Koha/Email.pm | 6 +++++- t/Koha/Email.t | 6 +++++- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index 6bc6e870bd..dfb7b78694 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -330,11 +330,12 @@ sub SendAlerts { # FIXME: This 'default' behaviour should be moved to Koha::Email my $mail = Koha::Email->create( { - to => $email, - from => $library->branchemail, - reply_to => $library->branchreplyto, - sender => $library->branchreturnpath, - subject => "" . $letter->{title}, + to => $email, + from => $library->branchemail, + reply_to => $library->branchreplyto, + sender => $library->branchreturnpath, + subject => "" . $letter->{title}, + template_id => $letter->{id}, } ); @@ -486,8 +487,7 @@ sub SendAlerts { cc => join( ',', @cc ), ( ( - C4::Context->preference("ClaimsBccCopy") - && ( $type eq 'claimacquisition' + C4::Context->preference("ClaimsBccCopy") && ( $type eq 'claimacquisition' || $type eq 'claimissues' ) ) ? ( bcc => $userenv->{emailaddress} ) @@ -510,7 +510,8 @@ sub SendAlerts { : () ) ), - subject => "" . $letter->{title}, + subject => "" . $letter->{title}, + template_id => $letter->{id}, } ); @@ -1453,7 +1454,13 @@ sub _send_message_by_email { from => $from_address, reply_to => $message->{'reply_address'} || $branch_replyto, sender => $branch_returnpath, - subject => "" . $message->{subject} + subject => "" . $message->{subject}, + ( + $message->{letter_id} + ? ( template_id => $message->{letter_id} ) + : () + ), + message_id => $message->{id} }; if ( $message->{'content_type'} && $message->{'content_type'} eq SERIALIZED_EMAIL_CONTENT_TYPE ) { @@ -1464,8 +1471,6 @@ sub _send_message_by_email { $email->create($params); } else { $email = Koha::Email->create($params); - $email->header('X-Koha-Letter-Id', $message->{letter_id} ); - $email->header('X-Koha-Message-Id', $message->{id} ); if ($is_html) { $email->html_body( _wrap_html( $content, $subject ) ); } else { diff --git a/Koha/Email.pm b/Koha/Email.pm index c7c23e3c1c..7701b9e400 100644 --- a/Koha/Email.pm +++ b/Koha/Email.pm @@ -173,11 +173,15 @@ sub create { $email->header( 'Reply-To', $addresses->{reply_to} ) if $addresses->{reply_to}; - $email->header( 'Sender' => $addresses->{sender} ) if $addresses->{sender}; + $email->header( 'Sender' => $addresses->{sender} ) if $addresses->{sender}; $email->header( 'Content-Type' => $params->{contenttype} ) if $params->{contenttype}; $email->header( 'X-Mailer' => "Koha" ); $email->header( 'Message-ID' => Email::MessageID->new->in_brackets ); + # Add Koha message headers to aid later message identification + $email->header( 'X-Koha-Template-Id' => $params->{template_id} ) if $params->{template_id}; + $email->header( 'X-Koha-Message-Id' => $params->{message_id} ) if $params->{message_id}; + if ( $params->{text_body} ) { $email->text_body( $params->{text_body}, %{ $params->{body_params} } ); } diff --git a/t/Koha/Email.t b/t/Koha/Email.t index dbd17834ba..a9ff4c3be3 100755 --- a/t/Koha/Email.t +++ b/t/Koha/Email.t @@ -28,7 +28,7 @@ use_ok('Koha::Email'); subtest 'create() tests' => sub { - plan tests => 25; + plan tests => 27; t::lib::Mocks::mock_preference( 'SendAllEmailsTo', undef ); @@ -46,6 +46,8 @@ subtest 'create() tests' => sub { subject => 'Some subject', html_body => $html_body, body_params => { charset => 'iso-8859-1' }, + template_id => 1, + message_id => 1, } ); @@ -57,6 +59,8 @@ subtest 'create() tests' => sub { is( $email->email->header('Sender'), 'sender@example.com', 'Value set correctly' ); is( $email->email->header('Subject'), 'Some subject', 'Value set correctly' ); is( $email->email->header('X-Mailer'), 'Koha', 'Value set correctly' ); + is( $email->email->header('X-Koha-Template-Id'), 1, 'Value set correctly' ); + is( $email->email->header('X-Koha-Message-Id'), 1, 'Value set correctly' ); is( $email->email->body, $html_body, "Body set correctly" ); like( $email->email->content_type, qr|text/html|, "Content type set correctly"); like( $email->email->content_type, qr|charset="?iso-8859-1"?|, "Charset set correctly"); -- 2.39.5