Improved App.Utils.signatureIdentify(), if an agent message is checked, just different detection priority.
This commit is contained in:
parent
af746d8f21
commit
0201d44c69
3 changed files with 39 additions and 24 deletions
|
@ -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
|
||||
|
|
|
@ -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 = '<span class="js-signatureMarker"></span>'
|
||||
|
||||
# search for zammad
|
||||
# <div data-signature="true" data-signature-id=".{1,3}">
|
||||
if !markers || !markers[0]
|
||||
regex = new RegExp( "(<div data-signature=\"true\" data-signature-id=\".{1,5}\">)" )
|
||||
if message.match( regex )
|
||||
return message.replace( regex, "#{markerTemplate}\$1" )
|
||||
regex = new RegExp( "(<div data-signature-id=\".{1,5}\" data-signature=\"true\">)" )
|
||||
if message.match( regex )
|
||||
return message.replace( regex, "#{markerTemplate}\$1" )
|
||||
# <div data-signature="true" data-signature-id=".{1,5}">
|
||||
if !markers || !markers[0] || internal
|
||||
regex = new RegExp("(<div data-signature=\"true\" data-signature-id=\".{1,5}\">)")
|
||||
if message.match(regex)
|
||||
return message.replace(regex, "#{markerTemplate}\$1")
|
||||
regex = new RegExp("(<div data-signature-id=\".{1,5}\" data-signature=\"true\">)")
|
||||
if message.match(regex)
|
||||
return message.replace(regex, "#{markerTemplate}\$1")
|
||||
|
||||
# search for <blockquote type="cite">
|
||||
# <blockquote type="cite">
|
||||
if !markers || !markers[0]
|
||||
regex = new RegExp( "(<blockquote type=\"cite\">)" )
|
||||
if message.match( regex )
|
||||
return message.replace( regex, "#{markerTemplate}\$1" )
|
||||
regex = new RegExp("(<blockquote type=\"cite\">)")
|
||||
if message.match(regex)
|
||||
return message.replace(regex, "#{markerTemplate}\$1")
|
||||
|
||||
# gmail
|
||||
# <div class="ecxgmail_quote">
|
||||
if !markers || !markers[0]
|
||||
regex = new RegExp( "(<blockquote class=\"(ecxgmail_quote|gmail_quote)\">)" )
|
||||
if message.match( regex )
|
||||
return message.replace( regex, "#{markerTemplate}\$1" )
|
||||
regex = new RegExp("(<blockquote class=\"(ecxgmail_quote|gmail_quote)\">)")
|
||||
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) ->
|
||||
|
|
|
@ -726,13 +726,27 @@ test("identify signature", function() {
|
|||
result = App.Utils.signatureIdentify(message, true)
|
||||
equal(result, should)
|
||||
|
||||
message = "Dear Mr. Smith,<div><br></div><div>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 <span style=\"line-height: 1.45; background-color: initial;\"><ABC_CONFIG_Home>/war/log/ITSMChangeCounter.log befindenden Zahl die SystemID (SysConfig) geschrieben. Dies ist ein Standardverhalten, dass auch bei der Ticketnummer verwendet wird.<br><br>Please ask me if you have questions.</span></div><div><span style=\"line-height: 1.45; background-color: initial;\"><br></span></div><div><span style=\"line-height: 1.45; background-color: initial;\">Viele Grüße,</span></div><div><div data-signature=\"true\" data-signature-id=\"1\"> Thorsten Smith\n<br>\n<br>--\n<br>Enterprise Services for ABC\n<br>\n<br>Znuny GmbH // Marienstraße 11 // 10117 Berlin // Germany\n<br>\n<br>P: +49 (0) 30 111 111 111-0\n<br>F: +49 (0) 30 111 111 111-8\n<br>W: http://znuny.com \n<br>\n<br>Location: Berlin - HRB 12345678 B Amtsgericht Berlin-Charlottenburg\n<br>Managing Director: Martin Edenhofer\n<br></div></div>"
|
||||
should = "Dear Mr. Smith,<div><br></div><div>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 <span style=\"line-height: 1.45; background-color: initial;\"><ABC_CONFIG_Home>/war/log/ITSMChangeCounter.log befindenden Zahl die SystemID (SysConfig) geschrieben. Dies ist ein Standardverhalten, dass auch bei der Ticketnummer verwendet wird.<br><br>Please ask me if you have questions.</span></div><div><span style=\"line-height: 1.45; background-color: initial;\"><br></span></div><div><span style=\"line-height: 1.45; background-color: initial;\">Viele Grüße,</span></div><div><span class=\"js-signatureMarker\"></span><div data-signature=\"true\" data-signature-id=\"1\"> Thorsten Smith\n<br>\n<br>--\n<br>Enterprise Services for ABC\n<br>\n<br>Znuny GmbH // Marienstraße 11 // 10117 Berlin // Germany\n<br>\n<br>P: +49 (0) 30 111 111 111-0\n<br>F: +49 (0) 30 111 111 111-8\n<br>W: http://znuny.com \n<br>\n<br>Location: Berlin - HRB 12345678 B Amtsgericht Berlin-Charlottenburg\n<br>Managing Director: Martin Edenhofer\n<br></div></div>"
|
||||
result = App.Utils.signatureIdentify(message, true, true)
|
||||
equal(result, should)
|
||||
|
||||
message = "Dear Mr. Smith, nice to read you,<div><div data-signature=\"true\" data-signature-id=\"1\"> Thorsten Smith\n<br>\n<br>--\n</div></div>"
|
||||
should = "Dear Mr. Smith, nice to read you,<div><span class=\"js-signatureMarker\"></span><div data-signature=\"true\" data-signature-id=\"1\"> Thorsten Smith\n<br>\n<br>--\n</div></div>"
|
||||
result = App.Utils.signatureIdentify(message, true, true)
|
||||
equal(result, should)
|
||||
|
||||
message = "Dear Mr. Smith, nice to read you,<div><div data-signature=\"true\" data-signature-id=\"9999\"> Thorsten Smith\n<br>\n<br>--\n</div></div>"
|
||||
should = "Dear Mr. Smith, nice to read you,<div><div data-signature=\"true\" data-signature-id=\"9999\"> Thorsten Smith\n<br>\n<br>--\n</div></div>"
|
||||
result = App.Utils.signatureIdentify(message, false, true)
|
||||
equal(result, should)
|
||||
|
||||
// fr
|
||||
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>De : Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]<br/>Envoyé : mercredi 29 avril 2015 17:31<br/>Objet : lalala</div>"
|
||||
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class="js-signatureMarker"></span>De : Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]<br/>Envoyé : mercredi 29 avril 2015 17:31<br/>Objet : lalala</div>'
|
||||
result = App.Utils.signatureIdentify(message, true)
|
||||
equal(result, should)
|
||||
|
||||
|
||||
// thunderbird
|
||||
// de
|
||||
message = "<div><br></div><div>Viele Grüße,</div><div>Christian</div><div><br></div><div>Am 04.03.2015 um 12:47 schrieb Martin Edenhofer via Znuny Sales:</div><div>> Hallo Christian,</div>"
|
||||
|
|
Loading…
Reference in a new issue