fix: Raise error if email to_header is invalid (#8688)

This commit is contained in:
Vishnu Narayanan
2024-02-21 06:33:39 +05:30
committed by GitHub
parent 9911c5dc12
commit d53097f77d
4 changed files with 90 additions and 0 deletions

View File

@@ -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