diff --git a/lib/mail/utilities.rb b/lib/mail/utilities.rb index e07d3526a..a2359558a 100644 --- a/lib/mail/utilities.rb +++ b/lib/mail/utilities.rb @@ -24,9 +24,9 @@ def quote_atom( str ) # If the string supplied has PHRASE unsafe characters in it, will return the string quoted # in double quotes, otherwise returns the string unmodified def quote_phrase( str ) - if RUBY_VERSION >= '1.9' + if str.respond_to?(:force_encoding) original_encoding = str.encoding - ascii_str = str.dup.force_encoding('ASCII-8BIT') + ascii_str = str.to_s.dup.force_encoding('ASCII-8BIT') if (PHRASE_UNSAFE === ascii_str) dquote(ascii_str).force_encoding(original_encoding) else @@ -47,7 +47,7 @@ def token_safe?( str ) def quote_token( str ) if str.respond_to?(:force_encoding) original_encoding = str.encoding - ascii_str = str.dup.force_encoding('ASCII-8BIT') + ascii_str = str.to_s.dup.force_encoding('ASCII-8BIT') if token_safe?( ascii_str ) str else