From 5d9ecee99c1bf2aff66a1b7b2a457b2eb2c32513 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 9 Jul 2020 17:06:20 +0200 Subject: [PATCH] Follow up - 6309eacc55f28ae4cb67f128d36085447537f3c1 - Fixes #3110 - ServiceNow mails from other service providers are not detected: Enhanced handling of key insensitive ServiceNow sender address. --- app/models/channel/filter/service_now_check.rb | 15 ++++----------- spec/models/channel/email_parser_spec.rb | 9 +++++++++ 2 files changed, 13 insertions(+), 11 deletions(-) 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