perlquestion
Skeeve
<p>
Dear fellow monks,
</p>
<p>
I have an issue with MIME::Lite::TT::Html in that it does not properly handle umlauts (UTF-8 in general).
</p>
<p>
This is my sample code:
</p>
<code>
#!/usr/bin/env perl
use strict;
use warnings;
use MIME::Lite::TT::HTML;
use Encode;
my %params;
$params{umlaut} = 'fööbär';
Encode::_utf8_on($params{umlaut});
my %options= (
INCLUDE_PATH => '.',
ENCODING => 'UTF-8',
);
my $msg = MIME::Lite::TT::HTML->new(
From => 'admin@example.com',
To => 'frank@example.com',
Subject => 'Your recent purchase',
Template => {
text => 'revsys.txt.tt',
html => 'revsys.html.tt',
},
TmplOptions => \%options,
TmplParams => \%params,
);
binmode STDOUT, ':utf8';
print "Should be: ", $params{umlaut},$/;
print '-' x 79,$/;
print $msg->as_string;
</code>
<p>
And these are the templates:
</p>
<code>
revsys.txt.tt:
text: [% umlaut %]
revsys.html.tt:
<h1>[% umlaut %]</h1>
</code>
<p>
The output is:
</p>
<code>
Should be: fööbär
-------------------------------------------------------------------------------
Content-Transfer-Encoding: binary
Content-Type: multipart/alternative; boundary="_----------=_158080661890"
MIME-Version: 1.0
X-Mailer: MIME::Lite 3.031 (F2.85; T2.17; A2.21; B3.15; Q3.13)
Subject: =?US-ASCII?B?WW91ciByZWNlbnQgcHVyY2hhc2U=?=
Date: Tue, 4 Feb 2020 08:56:58 +0000
To: frank@example.com
From: admin@example.com
This is a multi-part message in MIME format.
--_----------=_158080661890
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=us-ascii
text: fbr
--_----------=_158080661890
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
Content-Type: text/html; charset=us-ascii
<h1>fbr</h1>
--_----------=_158080661890--
</code>
<p>
As you can see: The Template output is just "fbr" and should be "fööbär".
</p>
<p>
Any advice? Did I do something wrong? Are there alternatives I should consider which can handle UTF-8?
</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-253915">
<hr><code>s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%</code>
<br><font color="red"><code>+</code></font><code>.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e</code>
</div></div>