diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee index 10e0b2fb2..e62f7ef52 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee @@ -1390,8 +1390,7 @@ class ArticleView extends App.Controller # convert to html signature = @ui.signature.body - #signature = signature.replace(//g, " ") - signature = '
' + signature.replace(/\n/g, '
') + '
' + signature = App.Utils.text2html( signature ) regexp = new RegExp( escapeRegExp( signature ) , 'im') #console.log('aaa', body, regexp) if !body || !body.match(regexp) @@ -1490,11 +1489,11 @@ class ArticleView extends App.Controller body = @ui.el.find('[data-name="body"]').html() || '' # quote text - selectedText = selectedText.replace /^(.*)$/mg, (match) => - '> ' + match + selectedText = App.Utils.textCleanup( selectedText ) + selectedText = App.Utils.quote( selectedText ) # convert to html - selectedText = '' + selectedText.replace(/\n/g, "
") + '
' + selectedText = App.Utils.text2html( selectedText ) articleNew.body = selectedText + body 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 084b7cf76..8878a2d33 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.js.coffee @@ -1,24 +1,26 @@ class App.Utils # textCleand = App.Utils.textCleanup( rawText ) - @textCleanup: ( ascii ) -> $.trim( ascii ) .replace(/(\r\n|\n\r)/g, "\n") # cleanup .replace(/\r/g, "\n") # cleanup - .replace(/\s+$/gm, "\n") # remove tailing spaces - .replace(/\n{2,9}/gm, "\n\n") # remove multible empty lines + .replace(/[ ]\n/g, "\n") # remove tailing spaces + .replace(/\n{3,9}/g, "\n\n") # remove multible empty lines # htmlEscapedAndLinkified = App.Utils.text2html( rawText ) - @text2html: ( ascii ) -> + console.log('AA0', ascii) ascii = @textCleanup(ascii) #ascii = @htmlEscape(ascii) + console.log('AA1', ascii) ascii = @linkify(ascii) - ascii.replace( /\n/g, ']*)>/i, '> '). - gsub(/<(br)(| [^>]*)>/i, "\n"). + gsub(/<(br)(|\/| [^>]*)>/i, "\n"). + gsub(/<\/div(| [^>]*)>/i, "\n"). gsub(/<(\/h[\d]+|p)(| [^>]*)>/i, "\n\n"). gsub(/<[^>]*>/, '') ).lstrip.gsub(/\n[ ]+/, "\n") + "\n" @@ -74,6 +75,6 @@ class String text = text + "\n [#{i+1}] <#{CGI.unescapeHTML(links[i])}>" unless links[i].nil? end links = nil - text + text.chomp end end \ No newline at end of file diff --git a/public/assets/tests/html-utils.js b/public/assets/tests/html-utils.js index f23c39b5b..cb8607f6b 100644 --- a/public/assets/tests/html-utils.js +++ b/public/assets/tests/html-utils.js @@ -33,6 +33,12 @@ test( "textCleanup", function() { result = App.Utils.textCleanup( source ) equal( result, should, source ) + source = "> Welcome!\n> \n> Thank you for installing Zammad.\n> \n> You will find ..." + should = "> Welcome!\n>\n> Thank you for installing Zammad.\n>\n> You will find ..." + result = App.Utils.textCleanup( source ) + equal( result, should, source ) + + }); // htmlEscape @@ -95,17 +101,22 @@ test( "htmlEscape", function() { test( "text2html", function() { var source = "Some\nValue\n\n\nTest" - var should = "Some
Value
Test" + var should = "SomeValueTest" var result = App.Utils.text2html( source ) equal( result, should, source ) source = "Some\nValue\n" - should = "Some
Value" + should = "SomeValue" result = App.Utils.text2html( source ) equal( result, should, source ) source = "Some\nValue\n" - should = "Some
<b>Value</b>" + should = "Some<b>Value</b>" + result = App.Utils.text2html( source ) + equal( result, should, source ) + + source = "> Welcome!\n> \n> Thank you for installing Zammad.\n> \n> You will find ..." + should = "> Welcome!>> Thank you for installing Zammad.>> You will find ..." result = App.Utils.text2html( source ) equal( result, should, source ) @@ -149,4 +160,29 @@ test( "linkify", function() { }); +// quote +test( "quote", function() { + + var source = "some text" + var should = '> some text' + var result = App.Utils.quote( source ) + equal( result, should, source ) + + source = "some text\nsome other text\n" + should = "> some text\n> some other text" + result = App.Utils.quote( source ) + equal( result, should, source ) + + source = "\n\nsome text\nsome other text\n \n" + should = "> some text\n> some other text" + result = App.Utils.quote( source ) + equal( result, should, source ) + + source = "Welcome!\n\nThank you for installing Zammad.\n\nYou will find ..." + should = "> Welcome!\n>\n> Thank you for installing Zammad.\n>\n> You will find ..." + result = App.Utils.quote( source ) + equal( result, should, source ) + +}); + } \ No newline at end of file diff --git a/test/unit/email_build_test.rb b/test/unit/email_build_test.rb index f21e9eff6..a3cd255de 100644 --- a/test/unit/email_build_test.rb +++ b/test/unit/email_build_test.rb @@ -24,4 +24,67 @@ class EmailBuildTest < ActiveSupport::TestCase assert( result =~ /test<\/b>/, 'test 2') end + + test 'html email check' do + html = ' + + + + + +> Welcome!>> Thank you for installing Zammad.>+ +' + mail = Channel::EmailBuild.build( + :from => 'sender@example.com', + :to => 'recipient@example.com', + :body => html, + :content_type => 'text/html', + ) + + should = '> Welcome! +> +> Thank you for installing Zammad. +> +' + assert_equal( should, mail.text_part.body.to_s ) + assert_equal( html, mail.html_part.body.to_s ) + + end + + + test 'html2text' do + html = ' + + + + + +> Welcome!>> Thank you for installing Zammad.>+ +' + should = '> Welcome! +> +> Thank you for installing Zammad. +> +' + assert_equal( should, html.html2text ) + + + html = ' line 1
+you
+-----&' + should = 'line 1 +you +-----&' + assert_equal( should, html.html2text ) + + + html = '' + should = '* #1 +* #2' + assert_equal( should, html.html2text ) + + + end end \ No newline at end of file
- #1
- #2