From a13217e18b2b92d31bdc6d119b4562067324a5be Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 5 Apr 2015 00:43:01 +0200 Subject: [PATCH] Improved signature identifier. --- .../app/lib/app_post/utils.js.coffee | 19 +++++++++++++------ public/assets/tests/html-utils.js | 11 +++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/app/lib/app_post/utils.js.coffee b/app/assets/javascripts/app/lib/app_post/utils.js.coffee index 8a7645150..d9bbef762 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.js.coffee @@ -225,7 +225,7 @@ class App.Utils lineCount += 1 # Am 04.03.2015 um 12:47 schrieb Alf Aardvark: - if line && line.match( /^(Am)\s.{6,10}\s(um)\s.{3,10}\s(schrieb)\s.+?:/ ) + if line && line.match( /^(Am)\s.{6,20}\s(um)\s.{3,10}\s(schrieb)\s.{1,250}:/ ) marker = line: cleanup(line) lineCount: lineCount @@ -235,7 +235,7 @@ class App.Utils # Thunderbird default - http://kb.mozillazine.org/Reply_header_settings # On 01-01-2007 11:00 AM, Alf Aardvark wrote: - if line && line.match( /^(On)\s.{6,10}\s.{3,10},\s.{1,100}(wrote):/ ) + if line && line.match( /^(On)\s.{6,20}\s.{3,10},\s.{1,250}(wrote):/ ) marker = line: cleanup(line) lineCount: lineCount @@ -245,7 +245,7 @@ class App.Utils # http://kb.mozillazine.org/Reply_header_settings # Alf Aardvark wrote, on 01-01-2007 11:00 AM: - if line && line.match( /^.{1,100}\s(wrote),\son\s.{3,20}:/ ) + if line && line.match( /^.{1,250}\s(wrote),\son\s.{3,20}:/ ) marker = line: cleanup(line) lineCount: lineCount @@ -261,7 +261,7 @@ class App.Utils lineCount += 1 # On 01/04/15 10:55, Bob Smith wrote: - if line && line.match( /^(On)\s.{6,10}\s.{3,10}\s.+?\s(wrote):/ ) + if line && line.match( /^(On)\s.{6,20}\s.{3,10}\s.{1,250}\s(wrote):/ ) marker = line: cleanup(line) lineCount: lineCount @@ -270,7 +270,7 @@ class App.Utils return # Am 03.04.2015 um 20:58 schrieb Martin Edenhofer : - if line && line.match( /^(Am)\s.{6,10}\s(um)\s.{3,10}\s(schrieb)\s.+?:/ ) + if line && line.match( /^(Am)\s.{6,20}\s(um)\s.{3,10}\s(schrieb)\s.{1,250}:/ ) marker = line: cleanup(line) lineCount: lineCount @@ -286,7 +286,7 @@ class App.Utils lineCount = 0 for line in textToSearchInLines lineCount += 1 - if line && line.match( /^..{6,10}\s.{3,10}\s-\s.+?\s(wrote|schrieb):/ ) + if line && line.match( /^.{6,10}\s.{3,10}\s-\s.{1,250}\s(wrote|schrieb):/ ) marker = line: cleanup(line) lineCount: lineCount @@ -349,6 +349,13 @@ class App.Utils if message.match( regex ) return message.replace( regex, "#{markerTemplate}\$1" ) + # gmail + #
+ if !markers || !markers[0] + regex = new RegExp( "(
)" ) + if message.match( regex ) + return message.replace( regex, "#{markerTemplate}\$1" ) + # if no marker is found, return return message if !markers || !markers[0] diff --git a/public/assets/tests/html-utils.js b/public/assets/tests/html-utils.js index 7e1209f48..1ebc4391c 100644 --- a/public/assets/tests/html-utils.js +++ b/public/assets/tests/html-utils.js @@ -647,6 +647,17 @@ test( "identify signature", function() { result = App.Utils.signatureIdentify( message, true ) equal( result, should ) + // gmail + message = "
test 123

--no not match--

Bob Smith
lalala
" + should = "
test 123

--no not match--

Bob Smith
lalala
" + result = App.Utils.signatureIdentify( message, true ) + equal( result, should ) + + message = "
test 123

--no not match--

Bob Smith
Am 24. Dezember 2015 um 07:45 schrieb kathrine <kathrine@example.com>:
lalala
" + should = "
test 123

--no not match--

Bob Smith
Am 24. Dezember 2015 um 07:45 schrieb kathrine <kathrine@example.com>:
lalala
" + result = App.Utils.signatureIdentify( message, true ) + equal( result, should ) + }); // replace tags