Re: Encode the subject line in MIME header using Perl 5.6

[email protected] (Nick Ing-Simmons)
Newsgroups perl.unicode
Message-ID <[email protected]>
John Delacour <[email protected]> writes:
>use MIME::QuotedPrint;
>$qp = encode_qp ($_, '');
>print "=?UTF-8?Q?$qp?=" . $/;

That isn't quite right.
MIME::QuotedPrint does NOT encode space or tab.

RFC2047 says:

"   The "Q" encoding is similar to the "Quoted-Printable" content-
   transfer-encoding defined in RFC 2045.  
...
   (3) 8-bit values which correspond to printable ASCII characters other
       than "=", "?", and "_" (underscore), MAY be represented as those
       characters.  (But see section 5 for restrictions.)  In
       particular, SPACE and TAB MUST NOT be represented as themselves
       within encoded words."

So I use simpler rule scheme which just hex-ifys any non-word chars.


sub encode_q{
    local $_ = shift;
    s{([^0-9A-Za-z-])}{
      join("" => map {sprintf "=%02X", $_} unpack("C*", $1))
     }egox;
    return $_;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.