[Catalyst] UTF-8 and mails

Bernhard Graf catalyst4 at augensalat.de
Mon Jan 25 14:54:44 GMT 2010


Jens Schwarz schrieb:

> first of all: I have read http://dev.catalystframework.org/wiki/tutorialsandhowtos/Using_Unicode (especially the "Tips for Troubleshooting Unicode in Perl Web Applications")
> Nevertheless I have a strange UTF-8 problem that I need help with:
> 
> Concerning UTF-8 everything in my App seems to work correct - except my mail action (I use Mail::Sender::Easy) in my Root controller:
> 
> <code>
> (...)
> use Mail::Sender::Easy qw(email);
> use utf8;
> (...)
> sub mail :Private {
> (...)
> $mail_return = email({
>   (...)
>   'subject'    => (... something from the database ...),
>   '_text_info' => {
>     charset  => 'utf-8',
>     encoding => 'quoted-printable',
>   },
>   '_text'      => (... some text with literal UTF-8 characters NOT from the database ...),
>   (...)
> });
> (...)
> }
> </code>
> 
> This produces mails that have messed up UTF-8 characters although the charset is set in the mail header, and the clients (right now tested with Thunderbird 3 and Outlook 2003) are configured to treat incoming mails as utf-8 encoded text. Strange: If I switch to ISO8859-1 in Thunderbird, the mails look alright. Outlook however simply drops the UTF-8 characters, so that p.ex. the German sentence "Nachricht für Herrn Müller" results in "Nachricht fr Herrn Mller".
> If I remove the "use utf8", the UTF-8 characters that do NOT come from the database look fine (in the example above: everything in '_text'), the ones from the database are messed up (in the example above: everything in 'subject'). Removing the "charset => 'utf-8'" flag of the mail subroutine results in fine mails if I set the charset to ISO8859-1 in the clients.


Does Mail::Sender::Easy automatically encode "_text" into the encoding
given in charset? If not, then /you/ have to do it:
Encode::encode("utf-8", $string);

Concerning "use utf8": As soon as you have any non-ASCII literals in
your code ("Herr Müller"), then you want to use that, BUT only if your
perl code file is also utf-8 encoded. Read the perl man pages about
unicode, if you are not sure. Read them twice, and then once more. ;-)
It's not a shame, if you don't get the whole picture at first.

And LBNL the charset in the header has no meaning for any header line.
For your subject line your have to encode this acording to RFC 2047 (but
you don't actually have to code that yourself - CPAN is your friend ;-).

Maybe you should change to another email module anyway. I don't know
Mail::Sender::Easy, but it seems old and unmaintained.

HTH

Bernhard



More information about the Catalyst mailing list