From 869a9a5632e113c0b578839e9a2c30eac3d6d4f5 Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Wed, 14 Jul 2021 13:47:26 +0000 Subject: [PATCH] Follow up 85856cbd40774e223950beeab793fffa4b35e733 - Fixes #3571 - Invalid html signature detection for exchange warning boxes. --- .../javascripts/app/lib/app_post/utils.coffee | 4 ++-- lib/signature_detection.rb | 3 +++ public/assets/tests/html_utils.js | 8 +++++++- spec/lib/signature_detection_spec.rb | 15 +++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/app/lib/app_post/utils.coffee b/app/assets/javascripts/app/lib/app_post/utils.coffee index 3d506bed1..39b8105d8 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.coffee @@ -795,8 +795,8 @@ class App.Utils try content = $('
').html(message) catch e then content = $('
').html('
' + message + '
') - # ignore mail structures of case Ticket#1085048 - return message if content.find("div:first span:contains('CAUTION:')").css('color') == 'rgb(156, 101, 0)' + # Invalid html signature detection for exchange warning boxes #3571 + return message if content.find("div:first:contains('CAUTION:')").length > 0 content.contents().each (index, node) -> text = $(node).text() diff --git a/lib/signature_detection.rb b/lib/signature_detection.rb index 2bb62e40c..82d1d530b 100644 --- a/lib/signature_detection.rb +++ b/lib/signature_detection.rb @@ -47,6 +47,9 @@ returns .map { |l| l.sub(%r{^.}, '') } .first(10).join("\n") + # Invalid html signature detection for exchange warning boxes #3571 + next if match_content.include?('CAUTION:') + # Add this substring to the signature_candidates hash and increment its match score signature_candidates[match_content] += 1 end diff --git a/public/assets/tests/html_utils.js b/public/assets/tests/html_utils.js index c44b0c9d2..c45278a76 100644 --- a/public/assets/tests/html_utils.js +++ b/public/assets/tests/html_utils.js @@ -1083,12 +1083,18 @@ test("identify signature by HTML", function() { result = App.Utils.signatureIdentifyByHtml(message) equal(result, should) - // ignore mail structures of case Ticket#1085048 + // Invalid html signature detection for exchange warning boxes #3571 message = '
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

actual content

actual content 2

 

actual quote

actual quote

 

 

' should = '
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

actual content

actual content 2

 

actual quote

actual quote

 

 

' result = App.Utils.signatureIdentifyByHtml(message) equal(result, should) + // Invalid html signature detection for exchange warning boxes #3571 + message = '
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

actual content

actual content 2

 

actual quote

actual quote

 

 

' + should = '
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

actual content

actual content 2

 

actual quote

actual quote

 

 

' + result = App.Utils.signatureIdentifyByHtml(message) + equal(result, should) + // Gmail via Safari on MacOS 10.12 message = '
Reply with gmail via Safari on MacOS 10.12

\
\ diff --git a/spec/lib/signature_detection_spec.rb b/spec/lib/signature_detection_spec.rb index 53b130746..bc1dacff9 100644 --- a/spec/lib/signature_detection_spec.rb +++ b/spec/lib/signature_detection_spec.rb @@ -107,6 +107,21 @@ RSpec.describe SignatureDetection do expect { described_class.find_signature(messages) }.not_to raise_error end end + + context 'when message contains exchange warning (#3571)' do + let(:content_type) { 'text/html' } + let(:messages) do + [ + { content: '
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

actual content

actual content 2

 

actual quote

actual quote

 

 

', content_type: 'text/html' }, + { content: '
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

333 content

4452134123 content 2

 

123124123 quote

123141 144234

 

 

', content_type: 'text/html' }, + { content: '
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

333 content

4452134123 content 2

 

9999 quote

999 144234

 

 

', content_type: 'text/html' }, + ] + end + + it 'does not detect the warning information as signature' do + expect(described_class.find_signature(messages)).to eq(nil) + end + end end describe '.find_signature_line' do