diff --git a/app/models/channel/filter/service_now_check.rb b/app/models/channel/filter/service_now_check.rb index 3f24d40ff..281ace9d2 100644 --- a/app/models/channel/filter/service_now_check.rb +++ b/app/models/channel/filter/service_now_check.rb @@ -66,17 +66,10 @@ returns: =end def self.source_name(from:) - result = nil - begin - Mail::AddressList.new(from).addresses.each do |line| - result = "ServiceNow-#{line.address}" - break - end - rescue - Rails.logger.info "Unable to parse email address in '#{from}'" - end - - result + address = Mail::AddressList.new(from).addresses.first.address.downcase + "ServiceNow-#{address}" + rescue => e + Rails.logger.info "Unable to parse email address in '#{from}': #{e.message}" end def self.from_sync_entry(mail:, source_name:, source_id:) diff --git a/spec/models/channel/email_parser_spec.rb b/spec/models/channel/email_parser_spec.rb index 9475ac498..dd2b35598 100644 --- a/spec/models/channel/email_parser_spec.rb +++ b/spec/models/channel/email_parser_spec.rb @@ -1024,6 +1024,15 @@ RSpec.describe Channel::EmailParser, type: :model do it 'adds Article to existing Ticket' do expect { described_class.new.process({}, raw_mail) }.to change { ticket.reload.articles.count } end + + context 'key insensitive sender address' do + + let(:raw_mail) { super().gsub('example@service-now.com', 'Example@Service-Now.com') } + + it 'adds Article to existing Ticket' do + expect { described_class.new.process({}, raw_mail) }.to change { ticket.reload.articles.count } + end + end end end