Skip to content

Commit

Permalink
fix: Emails not delivered when case does not match
Browse files Browse the repository at this point in the history
Fixes #2504
  • Loading branch information
tejaswinichile committed Sep 17, 2021
1 parent 0c3e8b6 commit 6ad5a74
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/mailboxes/application_mailbox.rb
Expand Up @@ -22,7 +22,7 @@ def self.support_mail?
proc do |inbound_mail_obj|
is_a_support_email = false
inbound_mail_obj.mail.to&.each do |email|
channel = Channel::Email.find_by('email = ? OR forward_to_email = ?', email, email)
channel = Channel::Email.find_by('lower(email) = ? OR lower(forward_to_email) = ?', email.downcase, email.downcase)
if channel.present?
is_a_support_email = true
break
Expand Down
2 changes: 1 addition & 1 deletion app/mailboxes/support_mailbox.rb
Expand Up @@ -21,7 +21,7 @@ def process

def find_channel
mail.to.each do |email|
@channel = Channel::Email.find_by('email = ? OR forward_to_email = ?', email, email)
@channel = Channel::Email.find_by('lower(email) = ? OR lower(forward_to_email) = ?', email.downcase, email.downcase)
break if @channel.present?
end
raise 'Email channel/inbox not found' if @channel.nil?
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/files/support_without_sender_name.eml
Expand Up @@ -4,7 +4,7 @@ Content-Type: multipart/alternative; boundary="Apple-Mail=_33A037C7-4BB3-4772-AE
Subject: Discussion: Let's debate these attachments
Date: Tue, 20 Apr 2020 04:20:20 -0400
In-Reply-To: <4e6e35f5a38b4_479f13bb90078178@small-app-01.mail>
To: "Replies" <care@example.com>
To: "Replies" <Care@example.com>
References: <4e6e35f5a38b4_479f13bb90078178@small-app-01.mail>
Message-Id: <0CB459E0-0336-41DA-BC88-E6E28C697DDB@chatwoot.com>
X-Mailer: Apple Mail (2.1244.3)
Expand Down
10 changes: 10 additions & 0 deletions spec/mailboxes/support_mailbox_spec.rb
Expand Up @@ -66,6 +66,16 @@
end
end

describe 'Sender with upcase mail address' do
let(:support_mail_without_sender_name) { create_inbound_email_from_fixture('support_without_sender_name.eml') }
let(:described_subject) { described_class.receive support_mail_without_sender_name }

it 'create a new inbox with the email case insensitive' do
described_subject
expect(conversation.inbox.id).to eq(channel_email.inbox.id)
end
end

describe 'handle inbox contacts' do
let(:contact) { create(:contact, account: account, email: support_mail.mail.from.first) }
let(:contact_inbox) { create(:contact_inbox, inbox: channel_email.inbox, contact: contact) }
Expand Down

0 comments on commit 6ad5a74

Please sign in to comment.