Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

The first thing which springs into my eye is the line: Encode::_utf8_on($params{umlaut}); It is almost always just plain wrong to use this function (and the documentation contains sufficient warnings). I guess that it is an attempt to fix your issue, but it is the wrong way. So I'll start by just deleting this line.

The next thing you need to care about is the encoding in which your Perl source is stored. It contains literal äöu, and your source code editor will decide (or take hints from you) whether it stores it as UTF-8 or something like ISO-LATIN-1. If your editor saves as UTF-8, you need to inform the interpreter about this by including the following line in your source code: use utf8;

For the moment I'll assume that your source file is encoded in ISO-LATIN-1, because there's more.

The documentation of MIME::Lite::TT::HTML tells us that it has two options which are missing from your source code:

  • Encoding is the "transfer encoding", the default value is 7bit. Here you are: Umlauts are outside the 7-bit range. Probably the module should warn you that your content contains non-ASCII characters, but apparently it doesn't, it just deletes all offending characters (actually, this happens in MIME::Lite). Any of the other values will will do the trick: Today's mail programs usually support 8bit, and $msg->as_string; will be more readable for humans. If you want to play it safe, use quoted-printable.
  • Charset is the actual encoding of your text. You are using binmode STDOUT, ':utf8';, and you need to include that information in the mail so that the reader on the other end knows how to interpret the strings by setting Charset => 'utf8',.

So this is my version of the source code, which I saved in ISO-LATIN-1-encoding:

#!/usr/bin/env perl use strict; use warnings; use MIME::Lite::TT::HTML; 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', }, Charset => 'utf8', Encoding => '8bit', TmplOptions => \%options, TmplParams => \%params, ); binmode STDOUT, ':utf8'; print "Should be: ", $params{umlaut},$/; print '-' x 79,$/; print $msg->as_string;

And on a contemporary Linux console (which means: it expects UTF-8 encoding), the output looks like this:

Should be: fööbär ---------------------------------------------------------------------- +--------- Content-Transfer-Encoding: binary Content-Type: multipart/alternative; boundary="_----------=_1580811788 +55330" MIME-Version: 1.0 X-Mailer: MIME::Lite 3.031 (F2.85; T2.17; A2.21; B3.15; Q3.13) Subject: =?UTF8?B?WW91ciByZWNlbnQgcHVyY2hhc2U=?= Date: Tue, 4 Feb 2020 10:23:08 +0000 From: admin@example.com To: frank@example.com This is a multi-part message in MIME format. --_----------=_158081178855330 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=utf8 text: fööbär --_----------=_158081178855330 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/html; charset=utf8 <h1>fööbär</h1> --_----------=_158081178855330--

Note that both headers Content-Transfer-Encoding and Content-Type are now correct.


In reply to Re: MIME::Lite::TT::Html - issues with umlauts by haj
in thread MIME::Lite::TT::Html - issues with umlauts by Skeeve

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-03-28 17:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found