How to encode mail subject in perl?

How to encode mail subject in perl?

Now I finally found something, but it still does not work:

use MIME::Words qw/encode_mimewords/;
$recipientsubject = encode_mimewords('Votre fichier a bien été envoyé');

But the result (listening):

Subject: Votre fichier a bien =? ISO-8859-1? Q? = E9t = E9? = =? ISO-8859-1? Q? envoy = E9? =

What is displayed:

Inspire Bien étéenvoyé

(He eats some spaces)

+5
source share
2 answers

Use Encode , this is the main module.

perl -Mutf8 -MEncode -E 'say encode("MIME-Header", "Votre fichier a bien été envoyé")'

... displays either one of:

=?UTF-8?Q?Votre=20fichier=20a=20bien=20?= =?UTF-8?Q?=C3=A9t=C3=A9=20envoy=C3=A9?=
=?UTF-8?B?Vm90cmUgZmljaGllciBhIGJpZW4gw6l0w6kgZW52b3nDqQ==?=

And decode with:

perl -C -MEncode -E 'say decode("MIME-Header", "=?UTF-8?Q?Votre=20fichier=20a=20bien=20?= =?UTF-8?Q?=C3=A9t=C3=A9=20envoy=C3=A9?=")'
perl -C -MEncode -E 'say decode("MIME-Header", "=?UTF-8?B?Vm90cmUgZmljaGllciBhIGJpZW4gw6l0w6kgZW52b3nDqQ==?=")'

What will print:

Votre fichier a bien été envoyé

If you still have the same results, you should provide more information about your Perl environment. Version is a good starter.

+16
source

, MIME- , ASCII, Email::MIME::RFC2047.

use strict;
use warnings;
use utf8;

use Email::MIME::RFC2047::Encoder;
use Email::MIME::RFC2047::Decoder;

binmode(STDOUT, ':utf8');

my $encoder = Email::MIME::RFC2047::Encoder->new;
my $encoded = $encoder->encode_text('Votre fichier a bien été envoyé');
print "$encoded\n";

my $decoder = Email::MIME::RFC2047::Decoder->new;
my $decoded = $decoder->decode_text($encoded);
print "$decoded\n";

Votre fichier a bien =?utf-8?Q?=c3=a9t=c3=a9_envoy=c3=a9?=
Votre fichier a bien été envoyé

Email:: MIME:: RFC2047 Encode:

  • MIME- , .
  • MIME-, To, From Cc ( Encode).
  • , UTF-8.
  • MIME-Q.
  • , Encode ( ).

: .

+2

All Articles