Added signature detection.
This commit is contained in:
parent
a644b300bc
commit
af89daae67
4 changed files with 210 additions and 6 deletions
|
@ -484,13 +484,17 @@ class App.TicketZoom extends App.Controller
|
||||||
)
|
)
|
||||||
|
|
||||||
# set see more options
|
# set see more options
|
||||||
previewHeight = 270
|
maxHeight = 450
|
||||||
@$('.textBubble-content').each( (index) ->
|
@$('.textBubble-content').each( (index) ->
|
||||||
bubble = $( @ )
|
bubble = $( @ )
|
||||||
heigth = bubble.height()
|
offsetTop = bubble.find('.js-signatureMarker').position()
|
||||||
if heigth > (previewHeight + 30)
|
heigth = bubble.height()
|
||||||
|
if offsetTop
|
||||||
bubble.attr('data-height', heigth)
|
bubble.attr('data-height', heigth)
|
||||||
bubble.css('height', "#{previewHeight}px")
|
bubble.css('height', "#{offsetTop.top + 42}px")
|
||||||
|
else if heigth > maxHeight
|
||||||
|
bubble.attr('data-height', heigth)
|
||||||
|
bubble.css('height', "#{maxHeight}px")
|
||||||
else
|
else
|
||||||
bubble.parent().find('.textBubble-overflowContainer').addClass('hide')
|
bubble.parent().find('.textBubble-overflowContainer').addClass('hide')
|
||||||
)
|
)
|
||||||
|
|
|
@ -16,6 +16,26 @@ class App.Utils
|
||||||
ascii = '<div>' + ascii.replace(/\n/g, '</div><div>') + '</div>'
|
ascii = '<div>' + ascii.replace(/\n/g, '</div><div>') + '</div>'
|
||||||
ascii.replace(/<div><\/div>/g, '<div><br></div>')
|
ascii.replace(/<div><\/div>/g, '<div><br></div>')
|
||||||
|
|
||||||
|
# rawText = App.Utils.html2text( html )
|
||||||
|
@html2text: ( html ) ->
|
||||||
|
html = $('<div>' + html + '</div>')
|
||||||
|
|
||||||
|
# insert new lines
|
||||||
|
html.find('div, p, pre, code, center, blockquote, form, textarea, address, table, tr').replaceWith( ->
|
||||||
|
content = $(@).html() + "\n"
|
||||||
|
content
|
||||||
|
.replace(/<br>/g, "\n")
|
||||||
|
.replace(/<br\/>/g, "\n")
|
||||||
|
)
|
||||||
|
|
||||||
|
# replace <br> as string, is/was not possible throuh replaceWith
|
||||||
|
htmlTmp = html.html().replace(/<br>/g, "\n")
|
||||||
|
|
||||||
|
# trim and cleanup
|
||||||
|
$('<div>' + htmlTmp + '</div>').text().trim()
|
||||||
|
.replace(/(\r\n|\n\r)/g, "\n") # cleanup
|
||||||
|
.replace(/\r/g, "\n") # cleanup
|
||||||
|
|
||||||
# htmlEscapedAndLinkified = App.Utils.linkify( rawText )
|
# htmlEscapedAndLinkified = App.Utils.linkify( rawText )
|
||||||
@linkify: (ascii) ->
|
@linkify: (ascii) ->
|
||||||
window.linkify( ascii )
|
window.linkify( ascii )
|
||||||
|
@ -166,6 +186,76 @@ class App.Utils
|
||||||
else
|
else
|
||||||
true
|
true
|
||||||
|
|
||||||
|
# messageWithMarker = App.Utils.signatureIdentify( message, sender )
|
||||||
|
@signatureIdentify: (message, sender = false) ->
|
||||||
|
textToSearch = @html2text( message )
|
||||||
|
|
||||||
|
# count lines, if we do have lower the 10, ignore this
|
||||||
|
textToSearchInLines = textToSearch.split("\n")
|
||||||
|
return message if textToSearchInLines.length < 10
|
||||||
|
|
||||||
|
quote = (str) ->
|
||||||
|
(str + '').replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&")
|
||||||
|
|
||||||
|
# search for signature seperator "--\n"
|
||||||
|
searchForSeperator = (textToSearchInLines) ->
|
||||||
|
for line in textToSearchInLines
|
||||||
|
if line && line.match( /^\s{0,10}--\s{0,10}$/ )
|
||||||
|
return line
|
||||||
|
false
|
||||||
|
marker = searchForSeperator(textToSearchInLines)
|
||||||
|
|
||||||
|
# search for Apple Mail
|
||||||
|
# On 01/04/15 10:55, Bob Smith wrote:
|
||||||
|
searchForAppleMail = (textToSearchInLines) ->
|
||||||
|
for line in textToSearchInLines
|
||||||
|
if line && line.match( /^(On|Am)\s.+?\s(wrote|schrieb):/ )
|
||||||
|
return line
|
||||||
|
false
|
||||||
|
if !marker
|
||||||
|
marker = searchForAppleMail(textToSearchInLines)
|
||||||
|
|
||||||
|
# search for otrs
|
||||||
|
# 25.02.2015 10:26 - edv hotline schrieb:
|
||||||
|
searchForOtrs = (textToSearchInLines) ->
|
||||||
|
for line in textToSearchInLines
|
||||||
|
if line && line.match( /^.+?\s.+?\s-\s.+?\s(wrote|schrieb):/ )
|
||||||
|
return line
|
||||||
|
false
|
||||||
|
if !marker
|
||||||
|
marker = searchForOtrs(textToSearchInLines)
|
||||||
|
|
||||||
|
# search for Ms
|
||||||
|
# From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
|
||||||
|
# Send: Donnerstag, 2. April 2015 10:00
|
||||||
|
searchForMs = (textToSearchInLines) ->
|
||||||
|
fromFound = undefined
|
||||||
|
for line in textToSearchInLines
|
||||||
|
if !marker
|
||||||
|
|
||||||
|
# find Sent
|
||||||
|
if fromFound
|
||||||
|
if line && line.match( /^(Sent|Gesendet):\s.+?/)
|
||||||
|
return fromFound
|
||||||
|
else
|
||||||
|
fromFound = undefined
|
||||||
|
|
||||||
|
# find From
|
||||||
|
else
|
||||||
|
if line && line.match( /^(From|Von):\s.+?/)
|
||||||
|
fromFound = line
|
||||||
|
false
|
||||||
|
if !marker
|
||||||
|
marker = searchForMs(textToSearchInLines)
|
||||||
|
|
||||||
|
# if no marker is found, return
|
||||||
|
return message if !marker
|
||||||
|
|
||||||
|
# insert marker
|
||||||
|
markerTemplate = '<span class="js-signatureMarker"></span>'
|
||||||
|
regex = new RegExp( "\>(\s{0,10}#{quote(marker)})\s{0,10}\<" )
|
||||||
|
message.replace( regex, ">#{markerTemplate}\$1<" )
|
||||||
|
|
||||||
# textReplaced = App.Utils.replaceTags( template, { user: { firstname: 'Bob', lastname: 'Smith' } } )
|
# textReplaced = App.Utils.replaceTags( template, { user: { firstname: 'Bob', lastname: 'Smith' } } )
|
||||||
@replaceTags: (template, objects) ->
|
@replaceTags: (template, objects) ->
|
||||||
template = template.replace( /#\{\s{0,2}(.+?)\s{0,2}\}/g, ( index, key ) ->
|
template = template.replace( /#\{\s{0,2}(.+?)\s{0,2}\}/g, ( index, key ) ->
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
<div class="textBubble">
|
<div class="textBubble">
|
||||||
<div class="bubble-arrow"></div>
|
<div class="bubble-arrow"></div>
|
||||||
<div class="textBubble-content">
|
<div class="textBubble-content">
|
||||||
<%- @article.html %>
|
<%- App.Utils.signatureIdentify( @article.html ) %>
|
||||||
<div class="textBubble-overflowContainer">
|
<div class="textBubble-overflowContainer">
|
||||||
<div class="btn btn--text js-unfold"><%- @T('See more') %></div>
|
<div class="btn btn--text js-unfold"><%- @T('See more') %></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -66,6 +66,41 @@ test( "text2html", function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// html2text
|
||||||
|
test( "html2text", function() {
|
||||||
|
|
||||||
|
var source = "<div>Some</div><div>Value</div><div><br></div><div>Test</div>"
|
||||||
|
var should = "Some\nValue\n\n\nTest"
|
||||||
|
var result = App.Utils.html2text( source )
|
||||||
|
equal( result, should, source )
|
||||||
|
|
||||||
|
source = "<div>Some</div><div>Value</div>"
|
||||||
|
should = "Some\nValue"
|
||||||
|
result = App.Utils.html2text( source )
|
||||||
|
equal( result, should, source )
|
||||||
|
|
||||||
|
source = "<div>Some<br/>Value</div>"
|
||||||
|
should = "Some\nValue"
|
||||||
|
result = App.Utils.html2text( source )
|
||||||
|
equal( result, should, source )
|
||||||
|
|
||||||
|
source = "<div>Some</div><div><b>Value</b></div>"
|
||||||
|
should = "Some\n<b>Value</b>"
|
||||||
|
result = App.Utils.html2text( source )
|
||||||
|
equal( result, should, source )
|
||||||
|
|
||||||
|
source = "<div>> Welcome!</div><div>></div><div>> Thank you for installing Zammad.</div><div>></div><div>> You will find ...</div>"
|
||||||
|
should = "> Welcome!\n>\n> Thank you for installing Zammad.\n>\n> You will find ..."
|
||||||
|
result = App.Utils.html2text( source )
|
||||||
|
equal( result, should, source )
|
||||||
|
|
||||||
|
source = "<div>test 123 <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>--<br/>Bob Smith</div>"
|
||||||
|
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 )
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
// linkify
|
// linkify
|
||||||
test( "linkify", function() {
|
test( "linkify", function() {
|
||||||
|
|
||||||
|
@ -451,6 +486,81 @@ test( "check signature", function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// identify signature
|
||||||
|
test( "identify signature", function() {
|
||||||
|
|
||||||
|
var message = "<div>test 123 </div>"
|
||||||
|
var should = '<div>test 123 </div>'
|
||||||
|
var result = App.Utils.signatureIdentify( message )
|
||||||
|
equal( result, should )
|
||||||
|
|
||||||
|
message = "<div>test 123 <br/>--<br/>Bob Smith</div>"
|
||||||
|
should = '<div>test 123 <br/>--<br/>Bob Smith</div>'
|
||||||
|
result = App.Utils.signatureIdentify( message )
|
||||||
|
equal( result, should )
|
||||||
|
|
||||||
|
message = "<div>test 123 <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>--<br/>Bob Smith</div>"
|
||||||
|
should = '<div>test 123 <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><span class="js-signatureMarker"></span>--<br/>Bob Smith</div>'
|
||||||
|
result = App.Utils.signatureIdentify( message )
|
||||||
|
equal( result, should )
|
||||||
|
|
||||||
|
message = "<div>test 123 <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>--no not match--<br/>--<br/>Bob Smith</div>"
|
||||||
|
should = '<div>test 123 <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>--no not match--<br/><span class="js-signatureMarker"></span>--<br/>Bob Smith</div>'
|
||||||
|
result = App.Utils.signatureIdentify( message )
|
||||||
|
equal( result, should )
|
||||||
|
|
||||||
|
message = "<div>test 123 <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>--no not match--<br/> -- <br/>Bob Smith</div>"
|
||||||
|
should = '<div>test 123 <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>--no not match--<br/><span class="js-signatureMarker"></span> -- <br/>Bob Smith</div>'
|
||||||
|
result = App.Utils.signatureIdentify( message )
|
||||||
|
equal( result, should )
|
||||||
|
|
||||||
|
message = "<div>test 123 <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>--<br/>Bob Smith<br/><br/><br/><br/><br/>--<br/>Bob Smith</div>"
|
||||||
|
should = '<div>test 123 <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><span class="js-signatureMarker"></span>--<br/>Bob Smith<br/><br/><br/><br/><br/>--<br/>Bob Smith</div>'
|
||||||
|
//should = '<div>test 123 <br><br><br><br><br><br><br><br><br><br><br><span class="js-signatureMarker"></span>--<br>Bob Smith<br/><br/><br/><br/><br/>--<br/>Bob Smith</div>'
|
||||||
|
result = App.Utils.signatureIdentify( message )
|
||||||
|
equal( result, should )
|
||||||
|
|
||||||
|
message = "<div>test 123</div><div>test 123</div><div>test 123</div><div>test 123</div><div>test 123</div><div>test 123</div><div>test 123</div><div>test 123</div><div>--</div><div>Bob Smith</div>"
|
||||||
|
should = "<div>test 123</div><div>test 123</div><div>test 123</div><div>test 123</div><div>test 123</div><div>test 123</div><div>test 123</div><div>test 123</div><div><span class=\"js-signatureMarker\"></span>--</div><div>Bob Smith</div>"
|
||||||
|
result = App.Utils.signatureIdentify( message )
|
||||||
|
equal( result, should )
|
||||||
|
|
||||||
|
message = "<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></p><p><span>Bob Smith</span></p><div></div>"
|
||||||
|
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 )
|
||||||
|
|
||||||
|
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 )
|
||||||
|
equal( result, should )
|
||||||
|
|
||||||
|
message = "<div>test 123 <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>--no not match--<br/><br/>Bob Smith<br/>Am 01/04/15 10:55, Bob Smith schrieb:<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>Am 01/04/15 10:55, Bob Smith schrieb:<br/>lalala</div>'
|
||||||
|
result = App.Utils.signatureIdentify( message )
|
||||||
|
equal( result, should )
|
||||||
|
|
||||||
|
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 )
|
||||||
|
equal( result, should )
|
||||||
|
|
||||||
|
message = "<div>test 123 <br/><br/><br/><br/><br/><br/><br/><br/><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/><br/><br/><br/><br/><br/><br/><br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class="js-signatureMarker"></span>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 )
|
||||||
|
equal( result, should )
|
||||||
|
|
||||||
|
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 )
|
||||||
|
equal( result, should )
|
||||||
|
|
||||||
|
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 schrieb:<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 schrieb:<br/>lalala</div>'
|
||||||
|
result = App.Utils.signatureIdentify( message )
|
||||||
|
equal( result, should )
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
// replace tags
|
// replace tags
|
||||||
test( "check replace tags", function() {
|
test( "check replace tags", function() {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue