summaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2024-09-20 01:58:08 +0000
committerGo MAEDA <maeda@farend.jp>2024-09-20 01:58:08 +0000
commit52deba3abf4753777d189b379df3acec723c7bce (patch)
tree254b060bc8bfe97cf59fb5d61528e4b505773ec0 /app/models
parent1905b26683d86adf1f5c75b4ba8b517763ef7e6c (diff)
downloadredmine-52deba3abf4753777d189b379df3acec723c7bce.tar.gz
redmine-52deba3abf4753777d189b379df3acec723c7bce.zip
Replace custom email normalization logic with Rails' `normalizes` method (#29208).
git-svn-id: https://svn.redmine.org/redmine/trunk@23064 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r--app/models/email_address.rb16
1 files changed, 7 insertions, 9 deletions
diff --git a/app/models/email_address.rb b/app/models/email_address.rb
index 8b9ecd415..69ae8a066 100644
--- a/app/models/email_address.rb
+++ b/app/models/email_address.rb
@@ -36,21 +36,19 @@ class EmailAddress < ApplicationRecord
:if => Proc.new {|email| email.address_changed? && email.address.present?}
validate :validate_email_domain, :if => proc {|email| email.address.present?}
- safe_attributes 'address'
-
- def address=(arg)
- normalized_address = arg.to_s.strip
-
- # Convert internationalized domain name (IDN) to Punycode
- # e.g. 'marie@société.example' => 'marie@xn--socit-esab.example'
+ normalizes :address, with: lambda { |address|
+ normalized_address = address.to_s.strip
local_part, _at, domain = normalized_address.partition('@')
if domain.present?
+ # Convert internationalized domain name (IDN) to Punycode
+ # e.g. 'marie@société.example' => 'marie@xn--socit-esab.example'
ascii_domain = Addressable::IDNA.to_ascii(domain)
normalized_address = "#{local_part}@#{ascii_domain}"
end
+ normalized_address
+ }
- write_attribute(:address, normalized_address)
- end
+ safe_attributes 'address'
def destroy
if is_default?