mirror of
https://github.com/discourse/discourse.git
synced 2024-12-30 08:33:45 +08:00
30 lines
719 B
Ruby
30 lines
719 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
module Email
|
||
|
class Validator
|
||
|
def self.ensure_valid!(mail)
|
||
|
Email::Validator.ensure_valid_address_lists!(mail)
|
||
|
Email::Validator.ensure_valid_date!(mail)
|
||
|
|
||
|
mail
|
||
|
end
|
||
|
|
||
|
def self.ensure_valid_address_lists!(mail)
|
||
|
%i[to cc bcc].each do |field|
|
||
|
addresses = mail[field]
|
||
|
|
||
|
if addresses&.errors.present?
|
||
|
mail[field] = addresses.to_s.scan(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def self.ensure_valid_date!(mail)
|
||
|
if mail.date.nil?
|
||
|
raise Email::Receiver::InvalidPost,
|
||
|
I18n.t("system_messages.email_reject_invalid_post_specified.date_invalid")
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|