From: Michael Witten Date: Sun, 19 Apr 2009 02:37:57 GMT Subject: Re: [PATCH RFC3.5 08/12] send-email: Move Subject sanitization from --compose code to send_message Message-ID: In-Reply-To: <76718490904181854o380fe118y9f3a52c926bd1f6d@mail.gmail.com> On Sat, Apr 18, 2009 at 20:54, Jay Soffian wrote: > On Sat, Apr 18, 2009 at 1:02 PM, Michael Witten wrote: >> +       my $sanitized_subject = ($subject =~ /[^[:ascii:]]/) ? quote_rfc2047($subject) : $subject; > > I wonder if it would be clearer to always call quote_rfc2047, then > have that function just return its input unaltered if quoting is not > needed. It actually ALWAYS changes the input. This code: sub quote_rfc2047 { local $_ = shift; my $encoding = shift || 'utf-8'; s/([^-a-zA-Z0-9!*+\/])/sprintf("=%02X", ord($1))/eg; s/(.*)/=\?$encoding\?q\?$1\?=/; return $_; } print quote_rfc2047("Yiarg #&@$! This output is messy!") . "\n" gives this output: =?utf-8?q?Yiarg=20=23=26!=20This=20output=20is=20messy!?= Therfore the /[^[:ascii:]]/ check actually saves us from corrupting already encoded subjects or from encoding ones that shouldn't be. In fact, I'm not entirely sure the original code is correct to make that check, because some of the characters that are replaced are ascii characters. This is all rather strange. Thanks! I should have tested it more; I'm constantly amazed by my inability to see the problems I introduce ;-)