Follow up 85856cbd40 - Fixes #3571 - Invalid html signature detection for exchange warning boxes.

This commit is contained in:
Rolf Schmidt 2021-07-14 13:47:26 +00:00 committed by Thorsten Eckel
parent 07a0864989
commit 869a9a5632
4 changed files with 27 additions and 3 deletions

View file

@ -795,8 +795,8 @@ class App.Utils
try content = $('<div/>').html(message) try content = $('<div/>').html(message)
catch e then content = $('<div/>').html('<div>' + message + '</div>') catch e then content = $('<div/>').html('<div>' + message + '</div>')
# ignore mail structures of case Ticket#1085048 # Invalid html signature detection for exchange warning boxes #3571
return message if content.find("div:first span:contains('CAUTION:')").css('color') == 'rgb(156, 101, 0)' return message if content.find("div:first:contains('CAUTION:')").length > 0
content.contents().each (index, node) -> content.contents().each (index, node) ->
text = $(node).text() text = $(node).text()

View file

@ -47,6 +47,9 @@ returns
.map { |l| l.sub(%r{^.}, '') } .map { |l| l.sub(%r{^.}, '') }
.first(10).join("\n") .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 # Add this substring to the signature_candidates hash and increment its match score
signature_candidates[match_content] += 1 signature_candidates[match_content] += 1
end end

View file

@ -1083,12 +1083,18 @@ test("identify signature by HTML", function() {
result = App.Utils.signatureIdentifyByHtml(message) result = App.Utils.signatureIdentifyByHtml(message)
equal(result, should) equal(result, should)
// ignore mail structures of case Ticket#1085048 // Invalid html signature detection for exchange warning boxes #3571
message = '<div><span style="color:#9c6500;">CAUTION:</span> 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.</div><br><div><p>actual content</p><div><p>actual content 2</p></div><p>&nbsp;</p><div><p>actual quote</p></div><div><blockquote><p>actual quote</p></blockquote></div><div><p>&nbsp;</p></div><p>&nbsp;</p></div></div>' message = '<div><span style="color:#9c6500;">CAUTION:</span> 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.</div><br><div><p>actual content</p><div><p>actual content 2</p></div><p>&nbsp;</p><div><p>actual quote</p></div><div><blockquote><p>actual quote</p></blockquote></div><div><p>&nbsp;</p></div><p>&nbsp;</p></div></div>'
should = '<div><span style="color:#9c6500;">CAUTION:</span> 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.</div><br><div><p>actual content</p><div><p>actual content 2</p></div><p>&nbsp;</p><div><p>actual quote</p></div><div><blockquote><p>actual quote</p></blockquote></div><div><p>&nbsp;</p></div><p>&nbsp;</p></div></div>' should = '<div><span style="color:#9c6500;">CAUTION:</span> 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.</div><br><div><p>actual content</p><div><p>actual content 2</p></div><p>&nbsp;</p><div><p>actual quote</p></div><div><blockquote><p>actual quote</p></blockquote></div><div><p>&nbsp;</p></div><p>&nbsp;</p></div></div>'
result = App.Utils.signatureIdentifyByHtml(message) result = App.Utils.signatureIdentifyByHtml(message)
equal(result, should) equal(result, should)
// Invalid html signature detection for exchange warning boxes #3571
message = '<div>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.</div><br><div><p>actual content</p><div><p>actual content 2</p></div><p>&nbsp;</p><div><p>actual quote</p></div><div><blockquote><p>actual quote</p></blockquote></div><div><p>&nbsp;</p></div><p>&nbsp;</p></div></div>'
should = '<div>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.</div><br><div><p>actual content</p><div><p>actual content 2</p></div><p>&nbsp;</p><div><p>actual quote</p></div><div><blockquote><p>actual quote</p></blockquote></div><div><p>&nbsp;</p></div><p>&nbsp;</p></div></div>'
result = App.Utils.signatureIdentifyByHtml(message)
equal(result, should)
// Gmail via Safari on MacOS 10.12 // Gmail via Safari on MacOS 10.12
message = '<div dir="ltr">Reply with <b>gmail</b> via Safari on MacOS 10.12</div><br>\ message = '<div dir="ltr">Reply with <b>gmail</b> via Safari on MacOS 10.12</div><br>\
<div>\ <div>\

View file

@ -107,6 +107,21 @@ RSpec.describe SignatureDetection do
expect { described_class.find_signature(messages) }.not_to raise_error expect { described_class.find_signature(messages) }.not_to raise_error
end end
end end
context 'when message contains exchange warning (#3571)' do
let(:content_type) { 'text/html' }
let(:messages) do
[
{ content: '<div><span style="color:#9c6500;">CAUTION:</span> 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.</div><br><div><p>actual content</p><div><p>actual content 2</p></div><p>&nbsp;</p><div><p>actual quote</p></div><div><blockquote><p>actual quote</p></blockquote></div><div><p>&nbsp;</p></div><p>&nbsp;</p></div></div>', content_type: 'text/html' },
{ content: '<div><span style="color:#9c6500;">CAUTION:</span> 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.</div><br><div><p>333 content</p><div><p>4452134123 content 2</p></div><p>&nbsp;</p><div><p>123124123 quote</p></div><div><blockquote><p>123141 144234</p></blockquote></div><div><p>&nbsp;</p></div><p>&nbsp;</p></div></div>', content_type: 'text/html' },
{ content: '<div><span style="color:#9c6500;">CAUTION:</span> 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.</div><br><div><p>333 content</p><div><p>4452134123 content 2</p></div><p>&nbsp;</p><div><p>9999 quote</p></div><div><blockquote><p>999 144234</p></blockquote></div><div><p>&nbsp;</p></div><p>&nbsp;</p></div></div>', 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 end
describe '.find_signature_line' do describe '.find_signature_line' do