Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Encoding changes when PHRASE_UNSAFE in Mail::Utilities#quote_phrase #621

bmorton opened this Issue · 2 comments

3 participants


When I do this:
address =
address.display_name = name

If name is UTF-8, it gets force encoded to ASCII-8BIT and then doesn't get force encoded back to its original encoding because of:

Do we need to pass the ASCII-8BIT string to dquote and then return the new string in its original encoding or can we pass the originally encoded string to dquote so that the string that's passed in gets set back to its proper encoding?

I'll throw together a quick pull request for this, but comments on the question above would be appreciated.


I just checked this, I think you want to call encoded on address first before calling format.

$> address ='')
 => #<Mail::Address:70191549114900 Address: || > 
$> address.display_name = ""
 => "" 
$> address.encoded
 => "=?UTF-8?B?4piD?= <>" 

It's actually worse than all that. Under some conditions, Mail::Address may mutate the display name string and destroy its encoding.

>> name = "\u{101}\u{10d}\u{113}"
=> "āčē"
>> name.encoding
=> #<Encoding:UTF-8>
>> e ='')
=> #<Mail::Address:70108045388440 Address: || >
>> e.display_name = name
=> "āčē"
>> e.format
=> ""āčē" <>"
>> name.encoding
=> #<Encoding:ASCII-8BIT>
>> name
=> "\xC4\x81\xC4\x8D\xC4\x93"

The UTF-8 encoding has been destroyed. If this was the name of a new user on an as-yet unsaved database record, preparing an email to send may wreck the database record.

Such is the bane of a language with mutable strings and the possibility for side-effects.

At the very least we should consider force_encoding to be a !-method and clone the string before using it. str = str.clone within the Ruby 1.9 block of quote_phrase would solve at least my case.

@ryanwood ryanwood referenced this issue in Shopify/liquid

UTF-8 Support Again #290

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.