mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 06:01:26 +08:00
FIX: Replace use of regular expression (#12838)
It used a regular expression to check if message IDs were in RFC format.
This commit is contained in:
13
lib/email.rb
13
lib/email.rb
@ -3,9 +3,6 @@
|
||||
require 'mail'
|
||||
|
||||
module Email
|
||||
# cute little guy ain't he?
|
||||
MESSAGE_ID_REGEX = /<(.*@.*)+>/
|
||||
|
||||
def self.is_valid?(email)
|
||||
return false unless String === email
|
||||
!!(EmailValidator.email_regex =~ email)
|
||||
@ -57,17 +54,19 @@ module Email
|
||||
|
||||
# https://tools.ietf.org/html/rfc850#section-2.1.7
|
||||
def self.message_id_rfc_format(message_id)
|
||||
return message_id if message_id =~ MESSAGE_ID_REGEX
|
||||
"<#{message_id}>"
|
||||
message_id.present? && !is_message_id_rfc?(message_id) ? "<#{message_id}>" : message_id
|
||||
end
|
||||
|
||||
def self.message_id_clean(message_id)
|
||||
return message_id if !(message_id =~ MESSAGE_ID_REGEX)
|
||||
message_id.tr("<>", "")
|
||||
message_id.present? && is_message_id_rfc?(message_id) ? message_id.gsub(/^<|>$/, "") : message_id
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.is_message_id_rfc?(message_id)
|
||||
message_id.start_with?('<') && message_id.include?('@') && message_id.end_with?('>')
|
||||
end
|
||||
|
||||
def self.obfuscate_part(part)
|
||||
if part.size < 3
|
||||
"*" * part.size
|
||||
|
Reference in New Issue
Block a user