[Mimedefang] mimedefang-filter $Subject variable encoding
Dianne Skoll
dfs at roaringpenguin.com
Fri Jun 10 09:50:31 EDT 2016
On Fri, 10 Jun 2016 07:36:28 +0200
Christoph Lehmann <post at christophlehmann.eu> wrote:
> This is a good one for the man / documentation. Can you provide an
> example there, Dianne?
Well, for example, let's say you want the subject to be:
$internal_perl_string = "J'adore lété";
Assuming the Perl string is in internal Perl format, you first convert
to UTF-8:
use Encode;
my $octets = encode('UTF-8', $internal_perl_string);
NOTE: If $internal_perl_string is *already* UTF-8 and not perl's
native format, skip the encode() step!!!
Then you convert to MIME encoding:
use MIME::Words;
my $mime_subject = MIME::Words::encode_mimewords($octets, Charset => 'UTF-8');
Here's a little test program:
===============================================================================
use MIME::Words;
use Encode;
my $internal_perl_string = "j'adore l\xE9t\xE9";
my $octets = encode('UTF-8', $internal_perl_string);
my $mime_subject = MIME::Words::encode_mimewords($octets, Charset => 'UTF-8');
print "Subject = " . $mime_subject . "\n";
===============================================================================
and here is the output:
Subject = j'adore =?UTF-8?Q?l=C3=A9t=C3=A9?=
Regards,
Dianne.
More information about the MIMEDefang
mailing list