John Delacour <JD(_at_)BD8(_dot_)COM> 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 $_;
}