Improved signature identifier.
This commit is contained in:
parent
06341d543b
commit
5b139076ad
3 changed files with 126 additions and 16 deletions
|
@ -507,7 +507,7 @@ class App.TicketZoom extends App.Controller
|
||||||
|
|
||||||
# set see more options
|
# set see more options
|
||||||
setSeeMore: =>
|
setSeeMore: =>
|
||||||
maxHeight = 480
|
maxHeight = 560
|
||||||
@$('.textBubble-content').each( (index) ->
|
@$('.textBubble-content').each( (index) ->
|
||||||
bubble = $( @ )
|
bubble = $( @ )
|
||||||
|
|
||||||
|
|
|
@ -198,6 +198,11 @@ class App.Utils
|
||||||
quote = (str) ->
|
quote = (str) ->
|
||||||
(str + '').replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&")
|
(str + '').replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&")
|
||||||
|
|
||||||
|
cleanup = (str) ->
|
||||||
|
if str.match(/(<|>|&)/)
|
||||||
|
str = str.replace(/(<|>|&).+?$/, '').trim()
|
||||||
|
str
|
||||||
|
|
||||||
# search for signature seperator "--\n"
|
# search for signature seperator "--\n"
|
||||||
markers = []
|
markers = []
|
||||||
searchForSeperator = (textToSearchInLines, markers) ->
|
searchForSeperator = (textToSearchInLines, markers) ->
|
||||||
|
@ -210,34 +215,84 @@ class App.Utils
|
||||||
lineCount: lineCount
|
lineCount: lineCount
|
||||||
type: 'seperator'
|
type: 'seperator'
|
||||||
markers.push marker
|
markers.push marker
|
||||||
|
return
|
||||||
searchForSeperator(textToSearchInLines, markers)
|
searchForSeperator(textToSearchInLines, markers)
|
||||||
|
|
||||||
|
# search for Thunderbird
|
||||||
|
searchForThunderbird = (textToSearchInLines, markers) ->
|
||||||
|
lineCount = 0
|
||||||
|
for line in textToSearchInLines
|
||||||
|
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.+?:/ )
|
||||||
|
marker =
|
||||||
|
line: cleanup(line)
|
||||||
|
lineCount: lineCount
|
||||||
|
type: 'thunderbird'
|
||||||
|
markers.push marker
|
||||||
|
return
|
||||||
|
|
||||||
|
# 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):/ )
|
||||||
|
marker =
|
||||||
|
line: cleanup(line)
|
||||||
|
lineCount: lineCount
|
||||||
|
type: 'thunderbird'
|
||||||
|
markers.push marker
|
||||||
|
return
|
||||||
|
|
||||||
|
# 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}:/ )
|
||||||
|
marker =
|
||||||
|
line: cleanup(line)
|
||||||
|
lineCount: lineCount
|
||||||
|
type: 'thunderbird'
|
||||||
|
markers.push marker
|
||||||
|
return
|
||||||
|
searchForThunderbird(textToSearchInLines, markers)
|
||||||
|
|
||||||
# search for Apple Mail
|
# search for Apple Mail
|
||||||
# On 01/04/15 10:55, Bob Smith wrote:
|
|
||||||
searchForAppleMail = (textToSearchInLines, markers) ->
|
searchForAppleMail = (textToSearchInLines, markers) ->
|
||||||
lineCount = 0
|
lineCount = 0
|
||||||
for line in textToSearchInLines
|
for line in textToSearchInLines
|
||||||
lineCount += 1
|
lineCount += 1
|
||||||
if line && line.match( /^(On|Am)\s.+?\s(wrote|schrieb):/ )
|
|
||||||
|
# On 01/04/15 10:55, Bob Smith wrote:
|
||||||
|
if line && line.match( /^(On)\s.{6,10}\s.{3,10}\s.+?\s(wrote):/ )
|
||||||
marker =
|
marker =
|
||||||
line: line
|
line: cleanup(line)
|
||||||
lineCount: lineCount
|
lineCount: lineCount
|
||||||
type: 'apple'
|
type: 'apple'
|
||||||
markers.push marker
|
markers.push marker
|
||||||
|
return
|
||||||
|
|
||||||
|
# Am 03.04.2015 um 20:58 schrieb Martin Edenhofer <me@znuny.ink>:
|
||||||
|
if line && line.match( /^(Am)\s.{6,10}\s(um)\s.{3,10}\s(schrieb)\s.+?:/ )
|
||||||
|
marker =
|
||||||
|
line: cleanup(line)
|
||||||
|
lineCount: lineCount
|
||||||
|
type: 'apple'
|
||||||
|
markers.push marker
|
||||||
|
return
|
||||||
searchForAppleMail(textToSearchInLines, markers)
|
searchForAppleMail(textToSearchInLines, markers)
|
||||||
|
|
||||||
# search for otrs
|
# search for otrs
|
||||||
|
# 25.02.2015 10:26 - edv hotline wrote:
|
||||||
# 25.02.2015 10:26 - edv hotline schrieb:
|
# 25.02.2015 10:26 - edv hotline schrieb:
|
||||||
searchForOtrs = (textToSearchInLines, markers) ->
|
searchForOtrs = (textToSearchInLines, markers) ->
|
||||||
lineCount = 0
|
lineCount = 0
|
||||||
for line in textToSearchInLines
|
for line in textToSearchInLines
|
||||||
lineCount += 1
|
lineCount += 1
|
||||||
if line && line.match( /^.+?\s.+?\s-\s.+?\s(wrote|schrieb):/ )
|
if line && line.match( /^..{6,10}\s.{3,10}\s-\s.+?\s(wrote|schrieb):/ )
|
||||||
marker =
|
marker =
|
||||||
line: line
|
line: cleanup(line)
|
||||||
lineCount: lineCount
|
lineCount: lineCount
|
||||||
type: 'Otrs'
|
type: 'Otrs'
|
||||||
markers.push marker
|
markers.push marker
|
||||||
|
return
|
||||||
searchForOtrs(textToSearchInLines, markers)
|
searchForOtrs(textToSearchInLines, markers)
|
||||||
|
|
||||||
# search for Ms
|
# search for Ms
|
||||||
|
@ -277,12 +332,26 @@ class App.Utils
|
||||||
foundInLines = lineCount
|
foundInLines = lineCount
|
||||||
searchForMs(textToSearchInLines, markers)
|
searchForMs(textToSearchInLines, markers)
|
||||||
|
|
||||||
|
# marker template
|
||||||
|
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,3}\">)" )
|
||||||
|
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" )
|
||||||
|
|
||||||
# if no marker is found, return
|
# if no marker is found, return
|
||||||
return message if !markers || !markers[0]
|
return message if !markers || !markers[0]
|
||||||
|
|
||||||
# insert marker
|
|
||||||
markerTemplate = '<span class="js-signatureMarker"></span>'
|
|
||||||
|
|
||||||
# get first marker
|
# get first marker
|
||||||
markers = _.sortBy(markers, 'lineCount')
|
markers = _.sortBy(markers, 'lineCount')
|
||||||
if markers[0].type is 'seperator'
|
if markers[0].type is 'seperator'
|
||||||
|
|
|
@ -544,22 +544,20 @@ test( "identify signature", function() {
|
||||||
result = App.Utils.signatureIdentify( message, true )
|
result = App.Utils.signatureIdentify( message, true )
|
||||||
|
|
||||||
// apple
|
// apple
|
||||||
|
// en
|
||||||
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>On 01/04/15 10:55, Bob Smith wrote:<br/>lalala<p>--</p>some test</div>"
|
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>On 01/04/15 10:55, Bob Smith wrote:<br/>lalala<p>--</p>some test</div>"
|
||||||
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class="js-signatureMarker"></span>On 01/04/15 10:55, Bob Smith wrote:<br/>lalala<p>--</p>some test</div>'
|
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class="js-signatureMarker"></span>On 01/04/15 10:55, Bob Smith wrote:<br/>lalala<p>--</p>some test</div>'
|
||||||
result = App.Utils.signatureIdentify( message, true )
|
result = App.Utils.signatureIdentify( message, true )
|
||||||
equal( result, should )
|
equal( result, should )
|
||||||
|
|
||||||
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>Am 01/04/15 10:55, Bob Smith schrieb:<br/>lalala</div>"
|
// de
|
||||||
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class="js-signatureMarker"></span>Am 01/04/15 10:55, Bob Smith schrieb:<br/>lalala</div>'
|
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>Am 03.04.2015 um 20:58 schrieb Bob Smith <bob@example.com>:<br/>lalala</div>"
|
||||||
|
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class="js-signatureMarker"></span>Am 03.04.2015 um 20:58 schrieb Bob Smith <bob@example.com>:<br/>lalala</div>'
|
||||||
result = App.Utils.signatureIdentify( message, true )
|
result = App.Utils.signatureIdentify( message, true )
|
||||||
equal( result, should )
|
equal( result, should )
|
||||||
|
|
||||||
// ms
|
// ms
|
||||||
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>Von: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]<br/>Gesendet: Donnerstag, 2. April 2015 10:00<br/>Betreff: lalala</div>"
|
// en
|
||||||
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class="js-signatureMarker"></span>Von: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]<br/>Gesendet: Donnerstag, 2. April 2015 10:00<br/>Betreff: lalala</div>'
|
|
||||||
result = App.Utils.signatureIdentify( message, true )
|
|
||||||
equal( result, should )
|
|
||||||
|
|
||||||
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]<br/>Sent: Donnerstag, 2. April 2015 10:00<br/>lalala</div>"
|
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]<br/>Sent: Donnerstag, 2. April 2015 10:00<br/>lalala</div>"
|
||||||
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]<br/>Sent: Donnerstag, 2. April 2015 10:00<br/>lalala</div>'
|
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]<br/>Sent: Donnerstag, 2. April 2015 10:00<br/>lalala</div>'
|
||||||
result = App.Utils.signatureIdentify( message, true )
|
result = App.Utils.signatureIdentify( message, true )
|
||||||
|
@ -575,6 +573,12 @@ test( "identify signature", function() {
|
||||||
result = App.Utils.signatureIdentify( message, true )
|
result = App.Utils.signatureIdentify( message, true )
|
||||||
equal( result, should )
|
equal( result, should )
|
||||||
|
|
||||||
|
// de
|
||||||
|
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>Von: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]<br/>Gesendet: Donnerstag, 2. April 2015 10:00<br/>Betreff: lalala</div>"
|
||||||
|
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class="js-signatureMarker"></span>Von: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]<br/>Gesendet: Donnerstag, 2. April 2015 10:00<br/>Betreff: lalala</div>'
|
||||||
|
result = App.Utils.signatureIdentify( message, true )
|
||||||
|
equal( result, should )
|
||||||
|
|
||||||
message = "<div>1<br><br></div><div>Von: Martin Edenhofer via Znuny Support [<a href=\"mailto:support@znuny.inc\" title=\"mailto:support@znuny.inc\" target=\"_blank\">mailto:support@znuny.inc</a>]</div>\n<div>Gesendet: Donnerstag, 2. April 2015 11:32</div>"
|
message = "<div>1<br><br></div><div>Von: Martin Edenhofer via Znuny Support [<a href=\"mailto:support@znuny.inc\" title=\"mailto:support@znuny.inc\" target=\"_blank\">mailto:support@znuny.inc</a>]</div>\n<div>Gesendet: Donnerstag, 2. April 2015 11:32</div>"
|
||||||
should = "<div>1<br><br></div><div>Von: Martin Edenhofer via Znuny Support [<a href=\"mailto:support@znuny.inc\" title=\"mailto:support@znuny.inc\" target=\"_blank\">mailto:support@znuny.inc</a>]</div>\n<div>Gesendet: Donnerstag, 2. April 2015 11:32</div>"
|
should = "<div>1<br><br></div><div>Von: Martin Edenhofer via Znuny Support [<a href=\"mailto:support@znuny.inc\" title=\"mailto:support@znuny.inc\" target=\"_blank\">mailto:support@znuny.inc</a>]</div>\n<div>Gesendet: Donnerstag, 2. April 2015 11:32</div>"
|
||||||
result = App.Utils.signatureIdentify( message, true )
|
result = App.Utils.signatureIdentify( message, true )
|
||||||
|
@ -590,12 +594,38 @@ test( "identify signature", function() {
|
||||||
result = App.Utils.signatureIdentify( message, true )
|
result = App.Utils.signatureIdentify( message, true )
|
||||||
equal( result, should )
|
equal( result, should )
|
||||||
|
|
||||||
|
message = "<div>Von: \"Johannes Nickel via Znuny Projects\" <<a href=\"mailto:projects@znuny.inc\" title=\"mailto:projects@znuny.inc\">projects@znuny.inc</a>></div><div>An: \"Lisa Smith\" <<a href=\"mailto:lisa.smith@example.com\" title=\"mailto:lisa.smith@example.com\">lisa.smith@example.com</a>></div><div>Gesendet: Donnerstag, 2. April 2015 10:11:12</div><div>Betreff: Angebot Redundanz / Paket mit Silver Subscription [Ticket#424242]</div><div><br></div><div>Hallo Frau Smith,</div>"
|
||||||
|
should = "<div><span class=\"js-signatureMarker\"></span>Von: \"Johannes Nickel via Znuny Projects\" <<a href=\"mailto:projects@znuny.inc\" title=\"mailto:projects@znuny.inc\">projects@znuny.inc</a>></div><div>An: \"Lisa Smith\" <<a href=\"mailto:lisa.smith@example.com\" title=\"mailto:lisa.smith@example.com\">lisa.smith@example.com</a>></div><div>Gesendet: Donnerstag, 2. April 2015 10:11:12</div><div>Betreff: Angebot Redundanz / Paket mit Silver Subscription [Ticket#424242]</div><div><br></div><div>Hallo Frau Smith,</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>"
|
||||||
|
should = "<div><br></div><div>Viele Grüße,</div><div>Christian</div><div><br></div><div><span class=\"js-signatureMarker\"></span>Am 04.03.2015 um 12:47 schrieb Martin Edenhofer via Znuny Sales:</div><div>> Hallo Christian,</div>"
|
||||||
|
result = App.Utils.signatureIdentify( message, true )
|
||||||
|
equal( result, should )
|
||||||
|
|
||||||
|
// en - Thunderbird default - http://kb.mozillazine.org/Reply_header_settings
|
||||||
|
message = "<div><br></div><div>Viele Grüße,</div><div>Christian</div><div><br></div><div>On 01-01-2007 11:00 AM, Alf Aardvark wrote:</div><div>> Hallo Christian,</div>"
|
||||||
|
should = "<div><br></div><div>Viele Grüße,</div><div>Christian</div><div><br></div><div><span class=\"js-signatureMarker\"></span>On 01-01-2007 11:00 AM, Alf Aardvark wrote:</div><div>> Hallo Christian,</div>"
|
||||||
|
result = App.Utils.signatureIdentify( message, true )
|
||||||
|
equal( result, should )
|
||||||
|
|
||||||
|
// en - http://kb.mozillazine.org/Reply_header_settings
|
||||||
|
message = "<div><br></div><div>Viele Grüße,</div><div>Christian</div><div><br></div><div>Alf Aardvark wrote, on 01-01-2007 11:00 AM:</div><div>> Hallo Christian,</div>"
|
||||||
|
should = "<div><br></div><div>Viele Grüße,</div><div>Christian</div><div><br></div><div><span class=\"js-signatureMarker\"></span>Alf Aardvark wrote, on 01-01-2007 11:00 AM:</div><div>> Hallo Christian,</div>"
|
||||||
|
result = App.Utils.signatureIdentify( message, true )
|
||||||
|
equal( result, should )
|
||||||
|
|
||||||
// otrs
|
// otrs
|
||||||
|
// en
|
||||||
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>01/04/15 10:55 - Bob Smith wrote:<br/>lalala</div>"
|
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>01/04/15 10:55 - Bob Smith wrote:<br/>lalala</div>"
|
||||||
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class="js-signatureMarker"></span>01/04/15 10:55 - Bob Smith wrote:<br/>lalala</div>'
|
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class="js-signatureMarker"></span>01/04/15 10:55 - Bob Smith wrote:<br/>lalala</div>'
|
||||||
result = App.Utils.signatureIdentify( message, true )
|
result = App.Utils.signatureIdentify( message, true )
|
||||||
equal( result, should )
|
equal( result, should )
|
||||||
|
|
||||||
|
// de
|
||||||
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>01/04/15 10:55 - Bob Smith schrieb:<br/>lalala</div>"
|
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>01/04/15 10:55 - Bob Smith schrieb:<br/>lalala</div>"
|
||||||
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class="js-signatureMarker"></span>01/04/15 10:55 - Bob Smith schrieb:<br/>lalala</div>'
|
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class="js-signatureMarker"></span>01/04/15 10:55 - Bob Smith schrieb:<br/>lalala</div>'
|
||||||
result = App.Utils.signatureIdentify( message, true )
|
result = App.Utils.signatureIdentify( message, true )
|
||||||
|
@ -606,6 +636,17 @@ test( "identify signature", function() {
|
||||||
result = App.Utils.signatureIdentify( message, true )
|
result = App.Utils.signatureIdentify( message, true )
|
||||||
equal( result, should )
|
equal( result, should )
|
||||||
|
|
||||||
|
// zammad
|
||||||
|
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><div data-signature=\"true\" data-signature-id=\"5\">lalala</div></div>"
|
||||||
|
should = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class=\"js-signatureMarker\"></span><div data-signature=\"true\" data-signature-id=\"5\">lalala</div></div>"
|
||||||
|
result = App.Utils.signatureIdentify( message, true )
|
||||||
|
equal( result, should )
|
||||||
|
|
||||||
|
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><blockquote type=\"cite\">lalala</blockquote></div>"
|
||||||
|
should = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class=\"js-signatureMarker\"></span><blockquote type=\"cite\">lalala</blockquote></div>"
|
||||||
|
result = App.Utils.signatureIdentify( message, true )
|
||||||
|
equal( result, should )
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// replace tags
|
// replace tags
|
||||||
|
|
Loading…
Reference in a new issue