15 |
15 |
# along with this program; if not, write to the Free Software
|
16 |
16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
17 |
17 |
|
|
18 |
require 'simpleidn'
|
|
19 |
|
18 |
20 |
class EmailAddress < ActiveRecord::Base
|
19 |
21 |
include Redmine::SafeAttributes
|
20 |
22 |
|
... | ... | |
25 |
27 |
after_destroy :destroy_tokens, :deliver_security_notification_destroy
|
26 |
28 |
|
27 |
29 |
validates_presence_of :address
|
28 |
|
validates_format_of :address, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, :allow_blank => true
|
|
30 |
validates_format_of :address, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+(xn--)?[a-z0-9]{2,})\z/i, :allow_blank => true
|
29 |
31 |
validates_length_of :address, :maximum => User::MAIL_LENGTH_LIMIT, :allow_nil => true
|
30 |
32 |
validates_uniqueness_of :address, :case_sensitive => false,
|
31 |
33 |
:if => Proc.new {|email| email.address_changed? && email.address.present?}
|
... | ... | |
33 |
35 |
safe_attributes 'address'
|
34 |
36 |
|
35 |
37 |
def address=(arg)
|
36 |
|
write_attribute(:address, arg.to_s.strip)
|
|
38 |
local_part, at, domain = arg.to_s.strip.rpartition('@')
|
|
39 |
ascii_address = local_part + at + SimpleIDN.to_ascii(domain)
|
|
40 |
write_attribute(:address, ascii_address)
|
37 |
41 |
end
|
38 |
42 |
|
39 |
43 |
def destroy
|