Feature #29208 » 0002-Support-IDN-email-addresses.patch
Gemfile | ||
---|---|---|
14 | 14 |
gem "mimemagic" |
15 | 15 |
gem "mail", "~> 2.6.4" |
16 | 16 |
gem "csv", "~> 1.0.2" if RUBY_VERSION >= "2.3" |
17 |
gem "simpleidn" |
|
17 | 18 | |
18 | 19 |
gem "nokogiri", "~> 1.8.0" |
19 | 20 |
gem "i18n", "~> 0.7.0" |
app/models/email_address.rb | ||
---|---|---|
33 | 33 |
safe_attributes 'address' |
34 | 34 | |
35 | 35 |
def address=(arg) |
36 |
write_attribute(:address, arg.to_s.strip) |
|
36 |
local_part, at, domain = arg.to_s.strip.partition('@') |
|
37 |
ascii_address = local_part + at + SimpleIDN.to_ascii(domain) |
|
38 |
write_attribute(:address, ascii_address) |
|
37 | 39 |
end |
38 | 40 | |
39 | 41 |
def destroy |
test/unit/user_test.rb | ||
---|---|---|
84 | 84 |
assert_equal "foo@bar.com", u.mail |
85 | 85 |
end |
86 | 86 | |
87 |
def test_mail_should_accept_idn |
|
88 |
u = User.new |
|
89 |
u.mail = "maeda@испытание.test.テスト" |
|
90 |
assert_equal "maeda@xn--80akhbyknj4f.test.xn--zckzah", u.mail |
|
91 |
# The local-part should be encoded with Punycode |
|
92 |
u.mail = "前田@example.jp" |
|
93 |
assert_equal "前田@example.jp", u.mail |
|
94 |
u.mail = "前田" |
|
95 |
assert_equal "前田", u.mail |
|
96 |
end |
|
97 | ||
87 | 98 |
def test_should_create_email_address |
88 | 99 |
u = User.new(:firstname => "new", :lastname => "user") |
89 | 100 |
u.login = "create_email_address" |