Defect #36969 » 36969-v2.patch
| app/models/email_address.rb | ||
|---|---|---|
|
class EmailAddress < ActiveRecord::Base
|
||
|
include Redmine::SafeAttributes
|
||
|
EMAIL_REGEXP = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+(?:(?:xn--[-a-z0-9]+)|(?:[a-z]{2,})))\z/i
|
||
|
belongs_to :user
|
||
|
after_update :destroy_tokens
|
||
| ... | ... | |
|
after_destroy_commit :deliver_security_notification_destroy
|
||
|
validates_presence_of :address
|
||
|
validates_format_of :address, :with => EMAIL_REGEXP, :allow_blank => true
|
||
|
validates_format_of :address, :with => URI::MailTo::EMAIL_REGEXP, :allow_blank => true
|
||
|
validates_length_of :address, :maximum => User::MAIL_LENGTH_LIMIT, :allow_nil => true
|
||
|
validates_uniqueness_of :address, :case_sensitive => false,
|
||
|
:if => Proc.new {|email| email.address_changed? && email.address.present?}
|
||
| app/models/setting.rb | ||
|---|---|---|
|
if settings.key?(:mail_from)
|
||
|
begin
|
||
|
mail_from = Mail::Address.new(settings[:mail_from])
|
||
|
raise unless EmailAddress::EMAIL_REGEXP.match?(mail_from.address)
|
||
|
raise unless URI::MailTo::EMAIL_REGEXP.match?(mail_from.address)
|
||
|
rescue
|
||
|
messages << [:mail_from, l('activerecord.errors.messages.invalid')]
|
||
|
end
|
||
| test/unit/email_address_test.rb | ||
|---|---|---|
|
assert email.valid?
|
||
|
end
|
||
|
end
|
||
|
def test_should_reject_invalid_email
|
||
|
assert_not EmailAddress.new(address: 'invalid,email@example.com').valid?
|
||
|
end
|
||
|
end
|
||
- « Previous
- 1
- 2
- Next »