diff --git a/app/assets/javascripts/app/lib/app_post/utils.js.coffee b/app/assets/javascripts/app/lib/app_post/utils.js.coffee index acb53d3c6..9ec58a2be 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.js.coffee @@ -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 = $('
' + html + '
') # 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(/
/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,30 +236,34 @@ class App.Utils 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 + # find Sent + if fromFound + if line && line.match( /^(Sent|Gesendet):\s.+?/) + return fromFound else - if line && line.match( /^(From|Von):\s.+?/) - fromFound = line + fromFound = undefined + + # find From + else + if line && line.match( /^(From|Von):\s.+?/ ) + 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 = '' - regex = new RegExp( "\>(\s{0,10}#{quote(marker)})\s{0,10}\<" ) - message.replace( regex, ">#{markerTemplate}\$1<" ) + 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) -> diff --git a/public/assets/tests/html-utils.js b/public/assets/tests/html-utils.js index a30c6ef7a..73c8e7fa3 100644 --- a/public/assets/tests/html-utils.js +++ b/public/assets/tests/html-utils.js @@ -99,6 +99,16 @@ test( "html2text", function() { result = App.Utils.html2text( source ) equal( result, should, source ) + source = "test 123










--
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 = "
1









Von: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
\n
Gesendet: Donnerstag, 2. April 2015 11:32
" + 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 = "

test 123

test 123

test 123

test 123

test 123

test 123

test 123

test 123

--

Bob Smith

" result = App.Utils.signatureIdentify( message ) + // apple message = "
test 123









--no not match--

Bob Smith
On 01/04/15 10:55, Bob Smith wrote:
lalala
" should = '
test 123









--no not match--

Bob Smith
On 01/04/15 10:55, Bob Smith wrote:
lalala
' result = App.Utils.signatureIdentify( message ) @@ -539,6 +550,7 @@ test( "identify signature", function() { result = App.Utils.signatureIdentify( message ) equal( result, should ) + // ms message = "
test 123









--no not match--

Bob Smith
Von: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
Gesendet: Donnerstag, 2. April 2015 10:00
lalala
" should = '
test 123









--no not match--

Bob Smith
Von: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
Gesendet: Donnerstag, 2. April 2015 10:00
lalala
' result = App.Utils.signatureIdentify( message ) @@ -549,6 +561,12 @@ test( "identify signature", function() { result = App.Utils.signatureIdentify( message ) equal( result, should ) + message = "
1









Von: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
\n
Gesendet: Donnerstag, 2. April 2015 11:32
" + should = "
1









Von: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
\n
Gesendet: Donnerstag, 2. April 2015 11:32
" + result = App.Utils.signatureIdentify( message ) + equal( result, should ) + + // otrs message = "
test 123









--no not match--

Bob Smith
01/04/15 10:55 - Bob Smith wrote:
lalala
" should = '
test 123









--no not match--

Bob Smith
01/04/15 10:55 - Bob Smith wrote:
lalala
' result = App.Utils.signatureIdentify( message ) @@ -559,6 +577,13 @@ test( "identify signature", function() { result = App.Utils.signatureIdentify( message ) equal( result, should ) + message = "
test 123








24.02.2015 14:20 - Roy Kaldung via Znuny Sales schrieb:  
" + should = "
test 123








24.02.2015 14:20 - Roy Kaldung via Znuny Sales schrieb:  
" + result = App.Utils.signatureIdentify( message ) + equal( result, should ) + +// + }); // replace tags