Re: MIME::QuotedPrint - extra '=' and linebreak?



op wrote:
when it comes to character encodings I decided to let myself off
the hook and use a module, namely MIME::QuotedPrint.

<snip>

However, the module didn't quite produce the result I expected. It
correctly encoded the non-ASCII characters to '=<1byte_hexcode>', but
unexpectedly also added an extra '=\n' sequence to the end of the
string I was encoding.

Not quite. Without further arguments to encode_qp() it splits up long lines with "=\n" in between. I haven't noticed any "=\n" at the end of the encoded string, though.

The relevant code is pasted below. chomp'ing the encoded string and
removing the final '=' does now produce subject headers that display
the (iso-8859-15 encoded) characters properly, but it does seem to me
to be a bit of a hacky solution. So, have I misunderstood the use of
the module, is there a more "proper" way to get this done?

<snip>

my $encoded = $data{'tilaaja'}; #CAN CONTAIN NON-ASCII (ISO-8859-15)
CHARS
$encoded = MIME::QuotedPrint::encode($encoded);

#NECESSARY HACK?
chomp $encoded;
$encoded =~ s/=$//;

print MAIL "Subject: ORDER: =?iso-8859-15?q?$encoded?= \n\n";

I have made a similar experience, and my "hack" is even more complicated:

$encoded = join "\n ",
map { tr/ /_/; "=?ISO-8859-15?Q?$_?=" }
split /\s*=\n\s*/, $encoded;

When sending a long subject header via a sendmail pipe, that code makes at least my email client (Thunderbird) happy...

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.



Relevant Pages

  • Re: MIME::QuotedPrint - extra = and linebreak?
    ... unexpectedly also added an extra '=\n' sequence to the end of the ... string I was encoding. ... the encoded string, though. ... When sending a long subject header via a sendmail pipe, that code makes at least my email client happy... ...
    (perl.beginners)
  • Re: Why asci-only symbols?
    ... >> Perhaps string equivalence in keys will be treated like numeric equivalence? ... I know typewill be and in itself contain no encoding information now, ... >and a Unicode string, the system default encoding ...
    (comp.lang.python)
  • Re: Byte Array to String
    ... retrieved text will mismatch the original characters. ... encoding the characters. ... Dim strFileData as String ...
    (microsoft.public.dotnet.framework.aspnet)
  • F is evil (was: XML::LibXML UTF-8 toString() -vs- nodeValue())
    ... And with C<use encoding 'utf8';> you'll get the same character string, ... A script is the complete program text, ...
    (comp.lang.perl.misc)
  • Re: eval and unicode
    ... encoding your terminal/file/whatnot is written in. ... you have a byte string that starts with u, then ", then something ... The first item in the sequence is \u5fb9 -- a unicode code point. ...
    (comp.lang.python)