Fixes #3296 - Channel::EmailParser.process_unprocessable_mails doesn't find matching Group because of key insensitive mismatch in email address.

This commit is contained in:
Thorsten Eckel 2020-11-23 16:16:11 +01:00
parent 34ed189881
commit f851b58062
2 changed files with 58 additions and 1 deletions

View file

@ -337,7 +337,7 @@ returns
end
return if to.blank?
email = EmailAddress.find_by(email: to)
email = EmailAddress.find_by(email: to.downcase)
return if email&.channel.blank?
email.channel&.group

View file

@ -1357,4 +1357,61 @@ RSpec.describe Channel::EmailParser, type: :model do
end
end
end
describe '#mail_to_group' do
context 'when EmailAddress exists' do
context 'when gives address matches exactly' do
let(:group) { create(:group) }
let(:channel) { create(:email_channel, group: group) }
let!(:email_address) { create(:email_address, channel: channel) }
it 'returns the Channel Group' do
expect(described_class.mail_to_group(email_address.email)).to eq(group)
end
end
context 'when gives address matches key insensitive' do
let(:group) { create(:group) }
let(:channel) { create(:email_channel, group: group) }
let(:address) { 'KeyInsensitive@example.COM' }
let!(:email_address) { create(:email_address, email: address, channel: channel) }
it 'returns the Channel Group' do
expect(described_class.mail_to_group(address)).to eq(group)
end
end
context 'when no Channel is assigned' do
let!(:email_address) { create(:email_address, channel: nil) }
it 'returns nil' do
expect(described_class.mail_to_group(email_address.email)).to be_nil
end
end
context 'when Channel has no Group assigned' do
let(:channel) { create(:email_channel, group: nil) }
let!(:email_address) { create(:email_address, channel: channel) }
it 'returns nil' do
expect(described_class.mail_to_group(email_address.email)).to be_nil
end
end
end
context 'when given address is not parse-able' do
let(:address) { 'this_is_not_a_valid_email_address' }
it 'returns nil' do
expect(described_class.mail_to_group(address)).to be_nil
end
end
end
end