Improved signatureIdentify().
This commit is contained in:
parent
dd56429adc
commit
c15f204b87
2 changed files with 52 additions and 18 deletions
|
@ -18,10 +18,15 @@ class App.Utils
|
|||
|
||||
# rawText = App.Utils.html2text( html )
|
||||
@html2text: ( html ) ->
|
||||
|
||||
# remove not needed new lines
|
||||
html = html.replace(/>\n/g, '>')
|
||||
|
||||
# convert to jquery
|
||||
html = $('<div>' + html + '</div>')
|
||||
|
||||
# insert new lines
|
||||
html.find('div, p, pre, code, center, blockquote, form, textarea, address, table, tr').replaceWith( ->
|
||||
html.find('div, p, pre, code, center, blockquote, form, textarea, address, tr').replaceWith( ->
|
||||
content = $(@).html() + "\n"
|
||||
content
|
||||
.replace(/<br>/g, "\n")
|
||||
|
@ -223,7 +228,7 @@ class App.Utils
|
|||
return line
|
||||
false
|
||||
if !marker
|
||||
marker = searchForOtrs(textToSearchInLines)
|
||||
markerOtrs = searchForOtrs(textToSearchInLines)
|
||||
|
||||
# search for Ms
|
||||
# From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
|
||||
|
@ -231,7 +236,6 @@ class App.Utils
|
|||
searchForMs = (textToSearchInLines) ->
|
||||
fromFound = undefined
|
||||
for line in textToSearchInLines
|
||||
if !marker
|
||||
|
||||
# find Sent
|
||||
if fromFound
|
||||
|
@ -243,18 +247,23 @@ class App.Utils
|
|||
# find From
|
||||
else
|
||||
if line && line.match( /^(From|Von):\s.+?/ )
|
||||
fromFound = line
|
||||
fromFound = line.replace(/\s{0,5}\[.+?\]/g, '')
|
||||
false
|
||||
if !marker
|
||||
marker = searchForMs(textToSearchInLines)
|
||||
if !marker && !markerOtrs
|
||||
markerMs = searchForMs(textToSearchInLines)
|
||||
|
||||
# if no marker is found, return
|
||||
return message if !marker
|
||||
return message if !marker && !markerMs && !markerOtrs
|
||||
|
||||
# insert marker
|
||||
markerTemplate = '<span class="js-signatureMarker"></span>'
|
||||
if marker
|
||||
regex = new RegExp( "\>(\s{0,10}#{quote(marker)})\s{0,10}\<" )
|
||||
message.replace( regex, ">#{markerTemplate}\$1<" )
|
||||
else
|
||||
marker = markerMs || markerOtrs
|
||||
regex = new RegExp( "\>(\s{0,10}#{quote(marker)})" )
|
||||
message.replace( regex, ">#{markerTemplate}\$1" )
|
||||
|
||||
# textReplaced = App.Utils.replaceTags( template, { user: { firstname: 'Bob', lastname: 'Smith' } } )
|
||||
@replaceTags: (template, objects) ->
|
||||
|
|
|
@ -99,6 +99,16 @@ test( "html2text", function() {
|
|||
result = App.Utils.html2text( source )
|
||||
equal( result, should, source )
|
||||
|
||||
source = "test 123 <br><br><br><br><br><br><br><br><br><br><br>--<br>Bob Smith"
|
||||
should = "test 123 \n\n\n\n\n\n\n\n\n\n\n--\nBob Smith"
|
||||
result = App.Utils.html2text( source )
|
||||
equal( result, should, source )
|
||||
|
||||
source = "<div>1<br><br><br><br><br><br><br><br><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 = "1\n\n\n\n\n\n\n\n\n\n\n\Von: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]\nGesendet: Donnerstag, 2. April 2015 11:32"
|
||||
result = App.Utils.html2text( source )
|
||||
equal( result, should, source )
|
||||
|
||||
});
|
||||
|
||||
// linkify
|
||||
|
@ -529,6 +539,7 @@ test( "identify signature", function() {
|
|||
should = "<p><span>test 123</span></p><p><span>test 123</span></p><p><span>test 123</span></p><p><span>test 123</span></p><p><span>test 123</span></p><p><span>test 123</span></p><p><span>test 123</span></p><p><span>test 123</span></p><p><span><span class=\"js-signatureMarker\"></span>--</span></p><p><span>Bob Smith</span></p><div></div>"
|
||||
result = App.Utils.signatureIdentify( message )
|
||||
|
||||
// apple
|
||||
message = "<div>test 123 <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>--no not match--<br/><br/>Bob Smith<br/>On 01/04/15 10:55, Bob Smith wrote:<br/>lalala</div>"
|
||||
should = '<div>test 123 <br/><br/><br/><br/><br/><br/><br/><br/><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</div>'
|
||||
result = App.Utils.signatureIdentify( message )
|
||||
|
@ -539,6 +550,7 @@ test( "identify signature", function() {
|
|||
result = App.Utils.signatureIdentify( message )
|
||||
equal( result, should )
|
||||
|
||||
// ms
|
||||
message = "<div>test 123 <br/><br/><br/><br/><br/><br/><br/><br/><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/>lalala</div>"
|
||||
should = '<div>test 123 <br/><br/><br/><br/><br/><br/><br/><br/><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/>lalala</div>'
|
||||
result = App.Utils.signatureIdentify( message )
|
||||
|
@ -549,6 +561,12 @@ test( "identify signature", function() {
|
|||
result = App.Utils.signatureIdentify( message )
|
||||
equal( result, should )
|
||||
|
||||
message = "<div>1<br><br><br><br><br><br><br><br><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><br><br><br><br><br><br><br><br></div><div><span class=\"js-signatureMarker\"></span>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 )
|
||||
equal( result, should )
|
||||
|
||||
// otrs
|
||||
message = "<div>test 123 <br/><br/><br/><br/><br/><br/><br/><br/><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/><br/><br/><br/><br/><br/><br/><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 )
|
||||
|
@ -559,6 +577,13 @@ test( "identify signature", function() {
|
|||
result = App.Utils.signatureIdentify( message )
|
||||
equal( result, should )
|
||||
|
||||
message = "<div>test 123 <br/><br/><br/><br/><br/><br/><br/><br/><br/></div><div>24.02.2015 14:20 - Roy Kaldung via Znuny Sales schrieb: </div>"
|
||||
should = "<div>test 123 <br/><br/><br/><br/><br/><br/><br/><br/><br/></div><div><span class=\"js-signatureMarker\"></span>24.02.2015 14:20 - Roy Kaldung via Znuny Sales schrieb: </div>"
|
||||
result = App.Utils.signatureIdentify( message )
|
||||
equal( result, should )
|
||||
|
||||
//</div>
|
||||
|
||||
});
|
||||
|
||||
// replace tags
|
||||
|
|
Loading…
Reference in a new issue