From ef951bc441ed8e78e09548d8a7ae8a60efaa40cc Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Tue, 23 Sep 2025 11:03:05 +0000 Subject: [PATCH] Bug 40860: Consider is_html template notice Change logic of get_notice to fetch the template before GetPreparedLetter. This allows to verify is the template is HTML or not, and act accordingly. Test plan, before applying patch: 1) Enable ILLModule 2) Edit the default ktd ILL partner patron and add a primary email address: /cgi-bin/koha/circ/circulation.pl?borrowernumber=16 3) Create a new ILL request, visit: /cgi-bin/koha/ill/ill-requests.pl?method=create&backend=Standard 4) Add some metadata like title and author, after creation click 'Place request with partners'. 'FRL - Walker' should show up as an option. Select that and click 'Send email'. 5) Run the following query to grab the produced email content: $ koha-mysql kohadev $ SELECT content FROM message_queue; 6) Utilize an HTML previewer (to avoid having to send the mail for testing): https://html.onlineviewer.net/ 7) Paste the contents there, notice there's no line breaks when shown as HTML. 8) Apply patch, restart plack, repeat test plan. Notice the HTML preview has appropriate line breaks for each metadata entry. Please note that any other remaining line breaks need to replaced by a

tag but that is besides the ill_full_metadata substitution scope of this patch. Signed-off-by: Katrin Fischer --- Koha/ILL/Request.pm | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/Koha/ILL/Request.pm b/Koha/ILL/Request.pm index 50a8f733bcc..2728cee1bfa 100644 --- a/Koha/ILL/Request.pm +++ b/Koha/ILL/Request.pm @@ -26,6 +26,7 @@ use DateTime; use C4::Letters; use Mojo::Util qw(deprecated); use File::Basename qw(dirname); +use Carp qw( croak ); use Koha::AuthorisedValue; use Koha::AuthorisedValues; @@ -2021,21 +2022,39 @@ sub get_notice { my $author = $self->extended_attributes->find( { type => 'author' } ); my $metahash = $self->metadata; my @metaarray = (); + my $template = Koha::Notice::Templates->find_effective_template( + { + module => 'ill', + code => $params->{notice_code}, + branchcode => $self->branchcode, + message_transport_type => $params->{transport}, + lang => $self->patron ? $self->patron->lang : undef + } + ); + + unless ($template) { + croak "No 'ill' " . $params->{notice_code} . " letter transported by " . $params->{transport}; + return; + } + foreach my $key ( sort { lc $a cmp lc $b } keys %{$metahash} ) { my $value = $metahash->{$key}; push @metaarray, "- $key: $value" if $value; } - my $metastring = join( "\n", @metaarray ); + my $metastring; + my $template_hash = $template->unblessed; + if ( $template_hash->{is_html} ) { + $metastring = join( "
\n", @metaarray ); + $template_hash->{'content-type'} = 'text/html; charset="UTF-8"'; + } else { + $metastring = join( "\n", @metaarray ); + } my $illrequestattributes = { map { $_->type => $_->value } $self->extended_attributes->as_list }; my $letter = C4::Letters::GetPreparedLetter( - module => 'ill', - letter_code => $params->{notice_code}, - branchcode => $self->branchcode, - message_transport_type => $params->{transport}, - lang => $self->patron ? $self->patron->lang : undef, - tables => { + letter => $template_hash, + tables => { illrequests => $self->illrequest_id, borrowers => $self->borrowernumber, biblio => $self->biblio_id, -- 2.39.5