fix: Raise error if email to_header is invalid (#8688)
This commit is contained in:
@@ -37,10 +37,24 @@ class ApplicationMailbox < ActionMailbox::Base
|
||||
# checks if follow this pattern send it to reply_mailbox
|
||||
# reply+<conversation-uuid>@<mailer-domain.com>
|
||||
def reply_uuid_mail?(inbound_mail)
|
||||
validate_to_address(inbound_mail)
|
||||
|
||||
inbound_mail.mail.to&.any? do |email|
|
||||
conversation_uuid = email.split('@')[0]
|
||||
conversation_uuid.match?(REPLY_EMAIL_UUID_PATTERN)
|
||||
end
|
||||
end
|
||||
|
||||
# if mail.to returns a string, then it is a malformed `to` header
|
||||
# valid `to` header will be of type Mail::AddressContainer
|
||||
# validate if the to address is of type string
|
||||
def validate_to_address(inbound_mail)
|
||||
to_address_class = inbound_mail.mail.to&.class
|
||||
|
||||
return if to_address_class == Mail::AddressContainer
|
||||
|
||||
Rails.logger.error "Email to address header is malformed `#{inbound_mail.mail.to}`"
|
||||
raise StandardError, "Invalid email to address header #{inbound_mail.mail.to}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user