View | Details | Raw Unified | Return to bug 37918
Collapse All | Expand All

(-)a/Koha/Template/Plugin/EmailHeader.pm (+59 lines)
Line 0 Link Here
1
package Koha::Template::Plugin::EmailHeader;
2
3
# Copyright PTFS Europe 2024
4
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
=head1 NAME
21
22
Koha::Template::Plugin::EmailHeader - Template Toolkit filter to encode email headers as per RFC2047
23
24
=head1 SYNOPSIS
25
26
    [% USE EmailHeader %]
27
    [% header | email_header %]
28
29
=head1 DESCRIPTION
30
31
This plugin provides a Template Toolkit filter `email_header` that encodes
32
email headers according to RFC2047 using Encode::MIME::Header.
33
34
=cut
35
36
use Modern::Perl;
37
use Encode;
38
use Encode::MIME::Header;
39
40
use base qw( Template::Plugin::Filter );
41
42
our $DYNAMIC = 1;
43
44
=head1 FUNCTIONS
45
46
=head2 filter
47
48
  [% subject | email_header %]
49
50
Filters the given text as per RFC2047.
51
52
=cut
53
54
sub filter {
55
    my ( $self, $text, $args, $config ) = @_;
56
    return encode('MIME-Header', $text);
57
}
58
59
1;
(-)a/cpanfile (+2 lines)
Lines 42-47 requires 'Email::Date', '1.103'; Link Here
42
requires 'Email::MessageID', '1.406';
42
requires 'Email::MessageID', '1.406';
43
requires 'Email::Sender', '1.300030';
43
requires 'Email::Sender', '1.300030';
44
requires 'Email::Stuffer', '0.014';
44
requires 'Email::Stuffer', '0.014';
45
requires 'Encode::MIME::Header', '2.17';
45
requires 'Exception::Class', '1.38';
46
requires 'Exception::Class', '1.38';
46
requires 'File::Slurp', '9999.13';
47
requires 'File::Slurp', '9999.13';
47
requires 'Font::TTF', '0.45';
48
requires 'Font::TTF', '0.45';
Lines 113-118 requires 'Test', '1.25'; Link Here
113
requires 'Test::Harness', '2.56';
114
requires 'Test::Harness', '2.56';
114
requires 'Test::MockModule', '0.05';
115
requires 'Test::MockModule', '0.05';
115
requires 'Test::More', '1.302073';
116
requires 'Test::More', '1.302073';
117
requires 'Test::More::UTF8', '0.05';
116
requires 'Text::Bidi', '0.03';
118
requires 'Text::Bidi', '0.03';
117
requires 'Text::CSV', '0.01';
119
requires 'Text::CSV', '0.01';
118
requires 'Text::CSV::Encoded', '0.09';
120
requires 'Text::CSV::Encoded', '0.09';
(-)a/t/Koha_Template_Email_Header.t (-1 / +54 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use utf8;
19
use Modern::Perl;
20
21
use Test::More tests => 4;
22
use Test::More::UTF8;
23
24
use Encode qw(encode);
25
use Encode::MIME::Header;
26
27
use open qw( :std :encoding(UTF-8) );
28
29
use_ok( 'Koha::Template::Plugin::EmailHeader' );
30
31
my $filter = Koha::Template::Plugin::EmailHeader->new();
32
33
# Test cases with plain text and non-ASCII characters
34
my @tests = (
35
    {
36
        input    => 'Hello World',
37
        expected => encode('MIME-Header', 'Hello World'), # ASCII text doesn't need encoding
38
    },
39
    {
40
        input    => 'こんにちは', # Japanese text (Hello)
41
        expected => encode('MIME-Header', 'こんにちは'),
42
    },
43
    {
44
        input    => 'Café au lait', # Contains non-ASCII character (é)
45
        expected => encode('MIME-Header', 'Café au lait'),
46
    },
47
);
48
49
# Test each case
50
for my $test (@tests) {
51
     is($filter->filter($test->{input}), $test->{expected}, "Correctly encoded: '$test->{input} -> $test->{expected}'");
52
}
53
54
done_testing();

Return to bug 37918