From 0201d44c69ce825103da1cb492bcb14a84696d30 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 11 Feb 2016 20:17:39 +0100 Subject: [PATCH] Improved App.Utils.signatureIdentify(), if an agent message is checked, just different detection priority. --- .../ticket_zoom/article_view.coffee | 6 ++- .../javascripts/app/lib/app_post/utils.coffee | 41 +++++++++---------- public/assets/tests/html_utils.js | 16 +++++++- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/article_view.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/article_view.coffee index c90822624..e2c85f12f 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/article_view.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/article_view.coffee @@ -118,8 +118,10 @@ class ArticleViewItem extends App.Controller # prepare html body if @article.content_type is 'text/html' - @article['html'] = @article.body - @article['html'] = App.Utils.signatureIdentify( @article['html'] ) + if @article.sender.type is 'Agent' + @article['html'] = App.Utils.signatureIdentify(@article.body, false, true) + else + @article['html'] = App.Utils.signatureIdentify(@article.body) else # client signature detection diff --git a/app/assets/javascripts/app/lib/app_post/utils.coffee b/app/assets/javascripts/app/lib/app_post/utils.coffee index 59487baac..6bfc363e2 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.coffee @@ -247,13 +247,12 @@ class App.Utils true # messageWithMarker = App.Utils.signatureIdentify(message, false) - @signatureIdentify: (message, test = false) -> + @signatureIdentify: (message, test = false, internal = false) -> textToSearch = @html2text(message) # if we do have less then 8 lines and less then 300 chars ignore this textToSearchInLines = textToSearch.split("\n") - if !test - return message if textToSearchInLines.length < 8 && textToSearch.length < 300 + return message if !test && (textToSearchInLines.length < 8 && textToSearch.length < 300) quote = (str) -> (str + '').replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&") @@ -417,28 +416,28 @@ class App.Utils markerTemplate = '' # search for zammad - #
- if !markers || !markers[0] - regex = new RegExp( "(
)" ) - if message.match( regex ) - return message.replace( regex, "#{markerTemplate}\$1" ) - regex = new RegExp( "(
)" ) - if message.match( regex ) - return message.replace( regex, "#{markerTemplate}\$1" ) + #
+ if !markers || !markers[0] || internal + regex = new RegExp("(
)") + if message.match(regex) + return message.replace(regex, "#{markerTemplate}\$1") + regex = new RegExp("(
)") + if message.match(regex) + return message.replace(regex, "#{markerTemplate}\$1") # search for
#
if !markers || !markers[0] - regex = new RegExp( "(
)" ) - if message.match( regex ) - return message.replace( regex, "#{markerTemplate}\$1" ) + regex = new RegExp("(
)") + 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" ) + 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] @@ -446,11 +445,11 @@ class App.Utils # get first marker markers = _.sortBy(markers, 'lineCount') if markers[0].type is 'seperator' - regex = new RegExp( "\>(\s{0,10}#{quote(App.Utils.htmlEscape(markers[0].line))})\s{0,10}\<" ) - message.replace( regex, ">#{markerTemplate}\$1<" ) + regex = new RegExp("\>(\s{0,10}#{quote(App.Utils.htmlEscape(markers[0].line))})\s{0,10}\<") + message.replace(regex, ">#{markerTemplate}\$1<") else - regex = new RegExp( "\>(\s{0,10}#{quote(App.Utils.htmlEscape(markers[0].line))})" ) - message.replace( regex, ">#{markerTemplate}\$1" ) + regex = new RegExp("\>(\s{0,10}#{quote(App.Utils.htmlEscape(markers[0].line))})") + message.replace(regex, ">#{markerTemplate}\$1") # textReplaced = App.Utils.replaceTags( template, { user: { firstname: 'Bob', lastname: 'Smith' } } ) @replaceTags: (template, objects) -> diff --git a/public/assets/tests/html_utils.js b/public/assets/tests/html_utils.js index c9bd78c3e..7aef1d5fb 100644 --- a/public/assets/tests/html_utils.js +++ b/public/assets/tests/html_utils.js @@ -726,13 +726,27 @@ test("identify signature", function() { result = App.Utils.signatureIdentify(message, true) equal(result, should) + message = "Dear Mr. Smith,

it seems to be, dass Sie den AutoIncrement Nummerngenerator für Ihre ITSMChangeManagement Installation verwenden. Seit ABC 3.2 wird führend vor der sich in der Datei <ABC_CONFIG_Home>/war/log/ITSMChangeCounter.log  befindenden Zahl die SystemID (SysConfig) geschrieben. Dies ist ein Standardverhalten, dass auch bei der Ticketnummer verwendet wird.

Please ask me if you have questions.

Viele Grüße,
  Thorsten Smith\n
\n
--\n
Enterprise Services for ABC\n
\n
Znuny GmbH // Marienstraße 11 // 10117 Berlin // Germany\n
\n
P: +49 (0) 30 111 111 111-0\n
F: +49 (0) 30 111 111 111-8\n
W: http://znuny.com \n
\n
Location: Berlin - HRB 12345678 B Amtsgericht Berlin-Charlottenburg\n
Managing Director: Martin Edenhofer\n
" + should = "Dear Mr. Smith,

it seems to be, dass Sie den AutoIncrement Nummerngenerator für Ihre ITSMChangeManagement Installation verwenden. Seit ABC 3.2 wird führend vor der sich in der Datei <ABC_CONFIG_Home>/war/log/ITSMChangeCounter.log  befindenden Zahl die SystemID (SysConfig) geschrieben. Dies ist ein Standardverhalten, dass auch bei der Ticketnummer verwendet wird.

Please ask me if you have questions.

Viele Grüße,
  Thorsten Smith\n
\n
--\n
Enterprise Services for ABC\n
\n
Znuny GmbH // Marienstraße 11 // 10117 Berlin // Germany\n
\n
P: +49 (0) 30 111 111 111-0\n
F: +49 (0) 30 111 111 111-8\n
W: http://znuny.com \n
\n
Location: Berlin - HRB 12345678 B Amtsgericht Berlin-Charlottenburg\n
Managing Director: Martin Edenhofer\n
" + result = App.Utils.signatureIdentify(message, true, true) + equal(result, should) + + message = "Dear Mr. Smith, nice to read you,
  Thorsten Smith\n
\n
--\n
" + should = "Dear Mr. Smith, nice to read you,
  Thorsten Smith\n
\n
--\n
" + result = App.Utils.signatureIdentify(message, true, true) + equal(result, should) + + message = "Dear Mr. Smith, nice to read you,
  Thorsten Smith\n
\n
--\n
" + should = "Dear Mr. Smith, nice to read you,
  Thorsten Smith\n
\n
--\n
" + result = App.Utils.signatureIdentify(message, false, true) + equal(result, should) + // fr message = "
test 123

--no not match--

Bob Smith
De : Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
Envoyé : mercredi 29 avril 2015 17:31
Objet : lalala
" should = '
test 123

--no not match--

Bob Smith
De : Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
Envoyé : mercredi 29 avril 2015 17:31
Objet : lalala
' result = App.Utils.signatureIdentify(message, true) equal(result, should) - // thunderbird // de message = "

Viele Grüße,
Christian

Am 04.03.2015 um 12:47 schrieb Martin Edenhofer via Znuny Sales:
> Hallo Christian,
"