Last active
December 18, 2015 04:39
-
-
Save tigris/5727307 to your computer and use it in GitHub Desktop.
Bug in Mail::Address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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