Skip to content

Instantly share code, notes, and snippets.

@tigris
Last active December 18, 2015 04:39
Show Gist options
  • Save tigris/5727307 to your computer and use it in GitHub Desktop.
Save tigris/5727307 to your computer and use it in GitHub Desktop.
Bug in Mail::Address
#!/usr/bin/env ruby
# encoding: utf-8
require 'bundler/setup'
require 'mail'
def formatted_email(name, email)
address = Mail::Address.new(email)
address.display_name = name
address.format
end
def test name, email
puts 'BEFORE'
puts '======'
puts "name: #{name} (#{name.encoding})"
puts "email: #{email} (#{email.encoding})"
puts "\n"
formatted = formatted_email(name, email)
puts 'AFTER'
puts '====='
puts "formatted: #{formatted} (#{formatted.encoding})"
puts "name: #{name} (#{name.encoding})"
puts "email: #{email} (#{email.encoding})"
puts "\n"
end
test 'Joe', 'joe@example.com'
test 'Zoé', 'zoe@example.com'
BEFORE
======
name: Joe (UTF-8)
email: joe@example.com (UTF-8)
AFTER
=====
formatted: Joe <joe@example.com> (UTF-8)
name: Joe (UTF-8)
email: joe@example.com (UTF-8)
BEFORE
======
name: Zoé (UTF-8)
email: zoe@example.com (UTF-8)
AFTER
=====
formatted: =?UTF-8?B?Wm/DqQ==?= <zoe@example.com> (UTF-8)
name: Zoé (UTF-8)
email: zoe@example.com (UTF-8)
BEFORE
======
name: Joe (UTF-8)
email: joe@example.com (UTF-8)
AFTER
=====
formatted: Joe <joe@example.com> (UTF-8)
name: Joe (UTF-8)
email: joe@example.com (UTF-8)
BEFORE
======
name: Zoé (UTF-8)
email: zoe@example.com (UTF-8)
AFTER
=====
formatted: "Zoé" <zoe@example.com> (UTF-8)
name: Zoé (ASCII-8BIT)
email: zoe@example.com (UTF-8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment