chore: Support plus forwarding in email channel (#6482)
- Support for plus forwarding in the email addresses for email channels Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
class EmailChannelFinder
|
||||
include EmailHelper
|
||||
|
||||
def initialize(email_object)
|
||||
@email_object = email_object
|
||||
end
|
||||
@@ -7,7 +9,8 @@ class EmailChannelFinder
|
||||
channel = nil
|
||||
recipient_mails = @email_object.to.to_a + @email_object.cc.to_a
|
||||
recipient_mails.each do |email|
|
||||
channel = Channel::Email.find_by('lower(email) = ? OR lower(forward_to_email) = ?', email.downcase, email.downcase)
|
||||
normalized_email = normalize_email_with_plus_addressing(email)
|
||||
channel = Channel::Email.find_by('lower(email) = ? OR lower(forward_to_email) = ?', normalized_email, normalized_email)
|
||||
break if channel.present?
|
||||
end
|
||||
channel
|
||||
|
||||
@@ -3,4 +3,11 @@ module EmailHelper
|
||||
domain = email.split('@').last
|
||||
domain.split('.').first
|
||||
end
|
||||
|
||||
# ref: https://www.rfc-editor.org/rfc/rfc5233.html
|
||||
# This is not a mandatory requirement for email addresses, but it is a common practice.
|
||||
# john+test@xyc.com is the same as john@xyc.com
|
||||
def normalize_email_with_plus_addressing(email)
|
||||
"#{email.split('@').first.split('+').first}@#{email.split('@').last}".downcase
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user