mirror of
https://github.com/lingble/chatwoot.git
synced 2025-10-30 02:32:29 +00:00
feat: Route emails based on x-original-to in email channel (#6901)
Fixes: #6608 ref: https://linear.app/chatwoot/issue/CW-30/emails-not-routed-based-on-x-original-to
This commit is contained in:
@@ -7,12 +7,18 @@ class EmailChannelFinder
|
||||
|
||||
def perform
|
||||
channel = nil
|
||||
recipient_mails = @email_object.to.to_a + @email_object.cc.to_a
|
||||
|
||||
recipient_mails.each do |email|
|
||||
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
|
||||
end
|
||||
|
||||
def recipient_mails
|
||||
recipient_addresses = @email_object.to.to_a + @email_object.cc.to_a + @email_object.bcc.to_a + [@email_object['X-Original-To'].try(:value)]
|
||||
recipient_addresses.flatten.compact
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,6 +31,30 @@ describe ::EmailChannelFinder do
|
||||
channel = described_class.new(reply_mail.mail).perform
|
||||
expect(channel).to eq(channel_email)
|
||||
end
|
||||
|
||||
it 'return channel with cc email' do
|
||||
channel_email.update(email: 'test@example.com')
|
||||
reply_mail.mail['to'] = nil
|
||||
reply_mail.mail['cc'] = 'test@example.com'
|
||||
channel = described_class.new(reply_mail.mail).perform
|
||||
expect(channel).to eq(channel_email)
|
||||
end
|
||||
|
||||
it 'return channel with bcc email' do
|
||||
channel_email.update(email: 'test@example.com')
|
||||
reply_mail.mail['to'] = nil
|
||||
reply_mail.mail['bcc'] = 'test@example.com'
|
||||
channel = described_class.new(reply_mail.mail).perform
|
||||
expect(channel).to eq(channel_email)
|
||||
end
|
||||
|
||||
it 'return channel with X-Original-To email' do
|
||||
channel_email.update(email: 'test@example.com')
|
||||
reply_mail.mail['to'] = nil
|
||||
reply_mail.mail['X-Original-To'] = 'test@example.com'
|
||||
channel = described_class.new(reply_mail.mail).perform
|
||||
expect(channel).to eq(channel_email)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user