window.onload = function() { // textCleanup test("textCleanup", function() { var source = "Some\nValue\n\n\nTest" var should = "Some\nValue\n\nTest" var result = App.Utils.textCleanup(source) equal(result, should, source) source = "Some\nValue\n\n \n\n\nTest" should = "Some\nValue\n\nTest" result = App.Utils.textCleanup(source) equal(result, should, source) source = "Some\n\rValue\n\r\n\r\n\rTest" should = "Some\nValue\n\nTest" result = App.Utils.textCleanup(source) equal(result, should, source) source = "Some\n\rValue\n\r\n\r\n\rTest\r" should = "Some\nValue\n\nTest" result = App.Utils.textCleanup(source) equal(result, should, source) source = "Some\r\nValue\r\n\r\n\r\nTest\r\n" should = "Some\nValue\n\nTest" result = App.Utils.textCleanup(source) equal(result, should, source) source = "Some\r\nValue\r\n\r\n\r\n\r\n\r\n\r\nTest\r\n" should = "Some\nValue\n\nTest" 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) }); // text2html test("text2html", function() { var source = "Some\nValue\n\n\nTest" var should = "
Some
Value

Test
" var result = App.Utils.text2html(source) equal(result, should, source) source = "Some\nValue\n" should = "
Some
Value
" result = App.Utils.text2html(source) equal(result, should, source) source = "Some\nValue\n" 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) source = "Some\nValue\n" should = "
Some
Value
" result = App.Utils.text2html(source) equal(result, should, source) source = "Some\rValue\r" should = "
Some
Value
" result = App.Utils.text2html(source) equal(result, should, source) source = "Some\n\rValue\n\r" should = "
Some
Value
" result = App.Utils.text2html(source) equal(result, should, source) source = "Some\r\nValue\r\n" should = "
Some
Value
" result = App.Utils.text2html(source) equal(result, should, source) source = "Some Value 123" should = "
Some   Value 123
" result = App.Utils.text2html(source) equal(result, should, source) source = "Some\n Value\n 123" should = "
Some
  Value
   123
" result = App.Utils.text2html(source) equal(result, should, source) }); // htmlStrip test("htmlStrip", function() { var source = $('

lala
') var should = '
lala
' App.Utils.htmlStrip(source) equal(source.get(0).outerHTML, should) source = $('



lala
') should = '
lala
' App.Utils.htmlStrip(source) equal(source.get(0).outerHTML, should) source = $('



lala

') should = '
lala
' App.Utils.htmlStrip(source) equal(source.get(0).outerHTML, should) source = $('



lala

') should = '

lala
' App.Utils.htmlStrip(source) equal(source.get(0).outerHTML, should) }); // lastLineEmpty test("htmlLastLineEmpty", function() { var source = $('

lala
') equal(App.Utils.htmlLastLineEmpty(source), false) source = $('

lala
') equal(App.Utils.htmlLastLineEmpty(source), true) }); // html2text test("html2text", function() { var source = "
Some
Value

Test
" var should = "Some\nValue\n\nTest" var result = App.Utils.html2text(source) equal(result, should, source) source = "
Some
Value
" should = "Some\nValue" result = App.Utils.html2text(source) equal(result, should, source) source = "
Some
Value
" should = "Some\nValue" result = App.Utils.html2text(source) equal(result, should, source) source = "
Some & <Value>
" should = "Some & " result = App.Utils.html2text(source) equal(result, should, source) source = "
Some
<b>Value</b>
" should = "Some\nValue" result = App.Utils.html2text(source) equal(result, should, source) source = "
> Welcome!
>
> Thank you for installing Zammad.
>
> You will find ...
" should = "> Welcome!\n>\n> Thank you for installing Zammad.\n>\n> You will find ..." result = App.Utils.html2text(source) equal(result, should, source) source = "
test 123










--
Bob Smith
" should = "test 123 \n\n--\nBob Smith" result = App.Utils.html2text(source) equal(result, should, source) source = "test 123










--
Bob Smith" should = "test 123 \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\nVon: 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) source = "
test 123
lalala

--

some test
" should = "test 123\nlalala\n--\nsome test" result = App.Utils.html2text(source) equal(result, should, source) source = "

Was\nsoll verbessert werden:

" should = "Was soll verbessert werden:" result = App.Utils.html2text(source) equal(result, should, source) // in raw format, without cleanup source = "
Some
1234
" should = "Some\n1234\n" result = App.Utils.html2text(source, true) equal(result, should, source) source = "
Some
1234
" should = "Some\n 1234\n" result = App.Utils.html2text(source, true) equal(result, should, source) source = "\n\n
Some
\n
1234
" should = "Some\n 1234\n" result = App.Utils.html2text(source, true) equal(result, should, source) source = "
Some
1234
" should = "Some\n 1234\n" result = App.Utils.html2text(source, true) equal(result, should, source) source = "
Some
\n\n
1234
\n" should = "Some\n 1234\n" result = App.Utils.html2text(source, true) equal(result, should, source) source = "
test
new line
" should = "test\nnew line\n\n" result = App.Utils.html2text(source, true) equal(result, should, source) source = "

Was\nsoll verbessert werden:

" should = "Was soll verbessert werden:\n" result = App.Utils.html2text(source, true) equal(result, should, source) }); // phoneify test("phoneify", function() { var source = "+1 123 123 123-123" var should = 'tel:+1123123123123' var result = App.Utils.phoneify(source) equal(result, should, source) source = "+1 123 123 A 123-123<>" should = 'tel:+1123123123123' result = App.Utils.phoneify(source) equal(result, should, source) source = "+1 (123) 123 123-123" should = 'tel:+1123123123123' result = App.Utils.phoneify(source) equal(result, should, source) source = "+1 (123) 123 1#23-123" should = 'tel:+11231231#23123' result = App.Utils.phoneify(source) equal(result, should, source) source = "+1 (123) 12*3 1#23-123" should = 'tel:+112312*31#23123' result = App.Utils.phoneify(source) equal(result, should, source) source = "+1 (123) 12+3" should = 'tel:+1123123' result = App.Utils.phoneify(source) equal(result, should, source) source = "+1 (123) 123 " should = 'tel:+1123123' result = App.Utils.phoneify(source) equal(result, should, source) source = " +1 (123) 123 " should = 'tel:+1123123' result = App.Utils.phoneify(source) equal(result, should, source) }) // linkify test("linkify", function() { var source = "http://example.com" var should = 'http://example.com' var result = App.Utils.linkify(source) equal(result, should, source) source = "http://example.com?some_param=lalala" should = 'http://example.com?some_param=lalala' result = App.Utils.linkify(source) equal(result, should, source) source = "example.com" should = 'example.com' result = App.Utils.linkify(source) equal(result, should, source) source = "some text example.com" should = 'some text example.com' result = App.Utils.linkify(source) equal(result, should, source) source = "example.com some text" should = 'example.com some text' result = App.Utils.linkify(source) equal(result, should, source) source = "test@example.com some text" should = 'test@example.com some text' result = App.Utils.linkify(source) equal(result, should, source) source = "abc test@example.com some text" should = 'abc test@example.com some text' result = App.Utils.linkify(source) equal(result, should, source) /* source = "example.com" should = 'http://example.com' result = App.Utils.linkify(source) equal(result, should, source) */ }); // htmlEscape test("htmlEscape", function() { var source = "<" var should = "<" var result = App.Utils.htmlEscape(source) equal(result, should, source) source = ">" should = ">" result = App.Utils.htmlEscape(source) equal(result, should, source) source = "&" should = "&" result = App.Utils.htmlEscape(source) equal(result, should, source) source = "&" should = "&amp;" result = App.Utils.htmlEscape(source) equal(result, should, source) source = "& ;" should = "&amp ;" result = App.Utils.htmlEscape(source) equal(result, should, source) source = "& amp;" should = "& amp;" result = App.Utils.htmlEscape(source) equal(result, should, source) source = "'test'" should = "'test'" result = App.Utils.htmlEscape(source) equal(result, should, source) source = '"test"' should = ""test"" result = App.Utils.htmlEscape(source) equal(result, should, source) source = "<>" should = "<>" result = App.Utils.htmlEscape(source) equal(result, should, source) source = "<<>" should = "<&lt;>" result = App.Utils.htmlEscape(source) equal(result, should, source) }); // htmlRemoveTags test("htmlRemoveTags", function() { var source = "
test
" //var should = "
test
" var should = "test" var result = App.Utils.htmlRemoveTags($(source)) equal(result.html(), should, source) source = "
test
" //should = "
test
" should = "test" result = App.Utils.htmlRemoveTags($(source)) equal(result.html(), should, source) source = "some link to somewhere" should = "some link to somewhere" result = App.Utils.htmlRemoveTags($(source)) equal(result.html(), should, source) source = "
some link to somewhere
" //should = "
some link to somewhere
" should = "some link to somewhere" result = App.Utils.htmlRemoveTags($(source)) equal(result.html(), should, source) source = "
some link to somewhere
" //should = "
some link to somewhere
" should = "some link to somewhere" result = App.Utils.htmlRemoveTags($(source)) equal(result.html(), should, source) source = "
some link to somewhere

123
" //should = "
some link to somewhere 123
" should = "some link to somewhere 123 " result = App.Utils.htmlRemoveTags($(source)) equal(result.html(), should, source) }); // htmlRemoveRichtext test("htmlRemoveRichtext", function() { source = "
test 123
" //should = "
test 123
" should = "test 123" result = App.Utils.htmlRemoveRichtext($(source)) equal(result.html(), should, source) source = "
" //should = "
test 123
" should = "test 123" result = App.Utils.htmlRemoveRichtext($(source)) equal(result.html(), should, source) source = "

test 123

" should = "

test 123

" result = App.Utils.htmlRemoveRichtext($(source)) equal(result.html(), should, source) source = "
This is some text!
" should = "This is some text!" result = App.Utils.htmlRemoveRichtext($(source)) equal(result.html(), should, source) should = "This is some text!" result = App.Utils.htmlRemoveRichtext(source) equal(result.html(), should, source) var source = "
test
" //var should = "
test
" var should = "test" var result = App.Utils.htmlRemoveRichtext($(source)) equal(result.html(), should, source) source = "
1.1.1     Description
" //should = "
1.1.1     Description
" should = "1.1.1     Description" //should = '1.1.1 Description' result = App.Utils.htmlRemoveRichtext($(source)) equal(result.html(), should, source) source = "some link to somewhere" should = "some link to somewhere" result = App.Utils.htmlRemoveRichtext($(source)) equal(result.html(), should, source) source = "
test
" //should = "
test
" should = " test " result = App.Utils.htmlRemoveRichtext($(source)) equal(result.html(), should, source) source = "
test
" //should = "
test
" should = " test " result = App.Utils.htmlRemoveRichtext($(source)) equal(result.html(), should, source) source = "
test
" //should = "
test
" should = "
test
" result = App.Utils.htmlRemoveRichtext($(source)) equal(result.html(), should, source) source = "
test
" //should = "
test
" should = "
test
" result = App.Utils.htmlRemoveRichtext($(source)) equal(result.html(), should, source) source = "
test
123
" //should = "
test
123
" should = "
test
123" //should = '
test
123' result = App.Utils.htmlRemoveRichtext($(source)) equal(result.html(), should, source) source = "
test
" //should = "
test
" should = "
test
" result = App.Utils.htmlRemoveRichtext($(source)) equal(result.html(), should, source) source = "
" //should = "
test
" should = " test " result = App.Utils.htmlRemoveRichtext($(source)) equal(result.html(), should, source) source = "

" //should = "

" should = "
" result = App.Utils.htmlRemoveRichtext($(source)) equal(result.html(), should, source) source = "

" //should = "

" should = "

" result = App.Utils.htmlRemoveRichtext($(source)) equal(result.html(), should, source) source = "
test 123
" //should = "
test 123
" should = "test 123" result = App.Utils.htmlRemoveRichtext($(source)) equal(result.html(), should, source) source = "
\n" //should = "
test 123
" should = '
Gruppe *
Besitzer
Status *
' result = App.Utils.htmlRemoveRichtext(source) equal(result.html(), should, source) source = "
This is some text!
" should = "This is some text!" result = App.Utils.htmlRemoveRichtext($(source)) equal(result.html(), should, source) should = "This is some text!" result = App.Utils.htmlRemoveRichtext(source) equal(result.html(), should, source) var source = "
test
" var should = "
test
" var result = App.Utils.htmlRemoveRichtext($(source)) equal(result.get(0).outerHTML, should, source) source = "
some link to somewhere" should = "
some link to somewhere
" result = App.Utils.htmlRemoveRichtext($(source)) equal(result.get(0).outerHTML, should, source) source = "

" should = "

" result = App.Utils.htmlRemoveRichtext($(source)) equal(result.get(0).outerHTML, should, source) source = "
111aaa
keyvalue
" should = "
111aaakeyvalue
" result = App.Utils.htmlRemoveRichtext(source, true) equal(result.get(0).outerHTML, should, source) }); // htmlCleanup test("htmlCleanup", function() { var source = "
test
" //var should = "
test
" var should = "test" var result = App.Utils.htmlCleanup($(source)) equal(result.html(), should, source) source = "
test
" should = "test" result = App.Utils.htmlCleanup(source) equal(result.html(), should, source) source = "some link to somewhere" should = "some link to somewhere" result = App.Utils.htmlCleanup(source) equal(result.html(), should, source) source = "
  • a
  • b
  • " should = "
  • a
  • b
  • " result = App.Utils.htmlCleanup(source) equal(result.html(), should, source) source = "some link to somewhere" should = "some link to somewhere" result = App.Utils.htmlCleanup($(source)) equal(result.html(), should, source) source = "

    some link to somewhere

    " should = "some link to somewhere" result = App.Utils.htmlCleanup($(source)) equal(result.html(), should, source) source = "

    some link to somewhere

    " should = "

    some link to somewhere

    " result = App.Utils.htmlCleanup($(source)) equal(result.html(), should, source) source = "

    some link to somewhere

    " should = "

    some link to somewhere

    " result = App.Utils.htmlCleanup($(source)) equal(result.html(), should, source) source = "
    some link to somewhere" //should = "
    some link to somewhere
    " should = "some link to somewhere" result = App.Utils.htmlCleanup($(source)) equal(result.html(), should, source) source = "
    " //should = "
    some link to somewhere
    " should = "some link to somewhere" result = App.Utils.htmlCleanup($(source)) equal(result.html(), should, source) source = "

    some h1 for somewhere


    " should = "

    some h1 for somewhere


    " result = App.Utils.htmlCleanup($(source)) equal(result.html(), should, source) source = "

    " //should = "

    " should = "
    " result = App.Utils.htmlCleanup($(source)) equal(result.html(), should, source) source = "

    " //should = "

    " should = "

    " result = App.Utils.htmlCleanup($(source)) equal(result.html(), should, source) source = "
    test 123
    " //should = "
    test 123
    " should = "test 123" result = App.Utils.htmlCleanup($(source)) equal(result.html(), should, source) source = "
    test 123
    some other value
    " //should = "
    test 123 some other value
    " should = "test 123 some other value" result = App.Utils.htmlCleanup($(source)) equal(result.html(), should, source) source = "
    test 123
    some other value
    " //should = "
    test 123 some other value
    " should = "test 123 some other value" result = App.Utils.htmlCleanup($(source)) equal(result.html(), should, source) source = "
    This is some text!
    " //should = "
    This is some text!
    " should = "This is some text!" result = App.Utils.htmlCleanup($(source)) equal(result.html(), should, source) source = "

    some link to somewhere from wordabc

    " //should = "

    some link to somewhere from wordabc

    " should = '

    some link to somewhere from wordabc

    ' result = App.Utils.htmlCleanup($(source)) equal(result.html(), should, source) source = "
    \n" //should = "
    test 123
    " should = '
    Gruppe *
    Besitzer
    Status *
    ' result = App.Utils.htmlCleanup(source) equal(result.html(), should, source) source = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n

    ·            \nTest 1

    \n\n

    ·            \nTest 2

    \n\n

    ·            \nTest 3

    \n\n

    ·            \nTest 4

    \n\n

    ·            \nTest5

    \n\n\n\n\n" should = "
    • Test 1
    • Test 2
    • Test 3
    • Test 4
    • Test5
    " result = App.Utils.htmlCleanup(source) equal(result.html().trim(), should, source) source = "\n\n\n \n \n \n \n\n\n

    1.\nGehe auf https://www.pferdiathek.ge

    \n


    \n\n

    \n

    2.\nMelde Dich mit folgende Zugangsdaten an:

    \n

    Benutzer:\nme@xxx.net

    \n

    Passwort:\nxxx.

    \n\n" should = "\n\n\n \n \n \n \n\n\n

    1.\nGehe auf https://www.pferdiathek.ge

    \n


    \n\n

    \n

    2.\nMelde Dich mit folgende Zugangsdaten an:

    \n

    Benutzer:\nme@xxx.net

    \n

    Passwort:\nxxx.

    \n\n" result = App.Utils.htmlCleanup(source) equal(result.html(), should, source) source = "
    aaa
    value
    " should = "
    aaa
    value
    " result = App.Utils.htmlCleanup(source) equal(result.get(0).outerHTML, should, source) // strip out browser-inserted (broken) link (see https://github.com/zammad/zammad/issues/2019) source = "" should = "test" result = App.Utils.htmlCleanup(source) equal(result.html(), should, source) source = "
    aaa
    value
    " should = "
    aaa
    value
    " result = App.Utils.htmlCleanup(source) result.get(0).outerHTML //equal(result.get(0).outerHTML, should, source) / string order is different on browsers equal(result.first().attr('bgcolor'), 'green') equal(result.first().attr('style'), 'color:red;') equal(result.first().attr('aaa'), undefined) equal(result.find('tr').first().attr('style'), 'margin-top:10px;') equal(result.find('th').first().attr('colspan'), '2') equal(result.find('th').first().attr('abc'), undefined) equal(result.find('th').first().attr('style'), 'margin-top:12px;') source = "
    aaa
    value
    " should = "
    aaa
    value
    " result = App.Utils.htmlCleanup(source) //equal(result.get(0).outerHTML, should, source) / string order is different on browsers equal(result.first().attr('bgcolor'), 'green') equal(result.first().attr('style'), 'color:red;') equal(result.first().attr('aaa'), undefined) equal(result.find('tr').first().attr('style'), undefined) equal(result.find('th').first().attr('colspan'), '2') equal(result.find('th').first().attr('abc'), undefined) equal(result.find('th').first().attr('style'), undefined) }); // wrap test("wrap", function() { var source = "some text" var should = 'some text' var result = App.Utils.wrap(source) equal(result, should, source) source = "some text\nsome other text\n" should = "some text\nsome other text\n" result = App.Utils.wrap(source) equal(result, should, source) source = "some text with some line to wrap" should = "some text with\nsome line to\nwrap" result = App.Utils.wrap(source, 14) equal(result, should, source) source = "some text\nsome other text\n" should = "some text\nsome other text\n" result = App.Utils.wrap(source) equal(result, should, source) source = "1234567890 1234567890 1234567890 1234567890" should = "1234567890 1234567890 1234567890 1234567890" result = App.Utils.wrap(source) equal(result, should, source) source = "123456789012 123456789012 123456789012" should = "123456789012\n123456789012\n123456789012" result = App.Utils.wrap(source, 14) equal(result, should, source) }); // remove empty lines test("remove empty lines", function() { var source = "\ntest 123\n" var should = "test 123\n" var result = App.Utils.removeEmptyLines(source) equal(result, should, source) source = "\ntest\n\n123\n" should = "test\n123\n" result = App.Utils.removeEmptyLines(source) equal(result, should, source) }); // 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) source = "Welcome! Thank you for installing Zammad. You will find ..." should = "> Welcome! Thank you\n> for installing\n> Zammad. You will\n> find ..." result = App.Utils.quote(source, 20) equal(result, should, source) }); // check signature test("check signature", function() { var message = "
    test 123
    " var signature = '
    --
    Some Signature
    some department
    ' var result = App.Utils.signatureCheck(message, signature) equal(result, true) message = "
    test 123
    --
    Some Signature
    some department\n
    " signature = '
    --
    Some Signature
    some department
    ' result = App.Utils.signatureCheck(message, signature) equal(result, false) message = "
    test 123
    --
    Some Signature\n
    some department\n
    " signature = '
    --
    Some Signature
    some department
    ' result = App.Utils.signatureCheck(message, signature) equal(result, false) message = "
    test 123
    --

    Some Signature

    \n

    some department
    \n

    \n
    " signature = '
    --
    Some Signature
    some department
    ' result = App.Utils.signatureCheck(message, signature) equal(result, false) message = "" signature = '
    --
    Some Signature
    some department
    ' result = App.Utils.signatureCheck(message, signature) equal(result, true) message = "" signature = "--\nSome Signature\nsome department" result = App.Utils.signatureCheck(message, signature) equal(result, true) }); // identify signature test("identify signature by plaintext", function() { var message = "
    test 123
    " var should = '
    test 123
    ' var result = App.Utils.signatureIdentifyByPlaintext(message) equal(result, should) message = "
    test 123
    --
    Bob Smith
    " should = '
    test 123
    --
    Bob Smith
    ' result = App.Utils.signatureIdentifyByPlaintext(message) equal(result, should) message = "
    test 123
    1
    2
    3
    4
    5
    6
    7
    8
    9

    --
    Bob Smith
    " should = '
    test 123
    1
    2
    3
    4
    5
    6
    7
    8
    9

    --
    Bob Smith
    ' result = App.Utils.signatureIdentifyByPlaintext(message) equal(result, should) message = "
    test 123

    --no not match--
    --
    Bob Smith
    " should = '
    test 123

    --no not match--
    --
    Bob Smith
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) message = "
    test 123

    --no not match--
    --
    Bob Smith
    " should = '
    test 123

    --no not match--
    --
    Bob Smith
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) message = "
    test 123

    --
    Bob Smith




    --
    Bob Smith
    " should = '
    test 123

    --
    Bob Smith




    --
    Bob Smith
    ' //should = '
    test 123










    --
    Bob Smith




    --
    Bob Smith
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) message = "
    test 123
    test 123
    --
    Bob Smith
    " should = "
    test 123
    test 123
    --
    Bob Smith
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) message = "

    test 123

    test 123

    --

    Bob Smith

    " should = "

    test 123

    test 123

    --

    Bob Smith

    " result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) message = "Test reply to zammad

    Am 24.10.2016 18:55 schrieb "Android Support" <android-support@example.com>:

    >
    > Sehr geehrte Damen" should = "Test reply to zammad

    Am 24.10.2016 18:55 schrieb "Android Support" <android-support@example.com>:

    >
    > Sehr geehrte Damen" result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) message = "
    < On 20 Oct 2016, at 12:23, Martin Edenhofer via Zammad Helpdesk wrote:
    " should = "
    < On 20 Oct 2016, at 12:23, Martin Edenhofer via Zammad Helpdesk wrote:
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) // apple // en message = "
    test 123

    --no not match--

    Bob Smith
    On 01/04/15 10:55, Bob Smith wrote:
    lalala

    --

    some test
    " should = '
    test 123

    --no not match--

    Bob Smith
    On 01/04/15 10:55, Bob Smith wrote:
    lalala

    --

    some test
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) // de message = "
    test 123

    --no not match--

    Bob Smith
    Am 03.04.2015 um 20:58 schrieb Bob Smith <bob@example.com>:
    lalala
    " should = '
    test 123

    --no not match--

    Bob Smith
    Am 03.04.2015 um 20:58 schrieb Bob Smith <bob@example.com>:
    lalala
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) // ms // en message = "
    test 123

    --no not match--

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

    --no not match--

    Bob Smith
    From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
    Sent: Donnerstag, 2. April 2015 10:00
    lalala
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) message = "
    test 123

    --no not match--

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

    --no not match--

    Bob Smith
    From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
    Sent: Donnerstag, 2. April 2015 10:00
    Subject: lalala
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) message = "
    test 123

    --no not match--

    Bob Smith
    From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
    Sent: Donnerstag, 2. April 2015 10:00
    1
    2
    3
    4
    4
    Subject: lalala
    " should = '
    test 123

    --no not match--

    Bob Smith
    From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
    Sent: Donnerstag, 2. April 2015 10:00
    1
    2
    3
    4
    4
    Subject: lalala
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) // de 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
    Betreff: 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
    Betreff: lalala
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) 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.signatureIdentifyByPlaintext(message, true) equal(result, should) message = "
    1

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

    Von: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
    \n
    Gesendet: Donnerstag, 2. April 2015 11:32
    Betreff: lalala
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) message = "
    1

    Von: Martin Edenhofer via Znuny Support <mailto:support@znuny.inc>
    \n
    An: somebody
    Datum: Donnerstag, 2. April 2015 11:32
    Betreff: lalala
    " should = "
    1

    Von: Martin Edenhofer via Znuny Support <mailto:support@znuny.inc>
    \n
    An: somebody
    Datum: Donnerstag, 2. April 2015 11:32
    Betreff: lalala
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) message = "
    Von: "Johannes Nickel via Znuny Projects" <projects@znuny.inc>
    An: \"Lisa Smith\" <lisa.smith@example.com>
    Gesendet: Donnerstag, 2. April 2015 10:11:12
    Betreff: Angebot Redundanz / Paket mit Silver Subscription [Ticket#424242]

    Hallo Frau Smith,
    " should = "
    Von: "Johannes Nickel via Znuny Projects" <projects@znuny.inc>
    An: \"Lisa Smith\" <lisa.smith@example.com>
    Gesendet: Donnerstag, 2. April 2015 10:11:12
    Betreff: Angebot Redundanz / Paket mit Silver Subscription [Ticket#424242]

    Hallo Frau Smith,
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) message = "
    Hi Johannes,

    das Angebot für den halben Tag bitte an uns.
    Der Termin hat sich jetzt auf 10-12 Uhr verschoben, hab ich dir weitergeleitet.

    Viele Grüße
    Max

    > On 07 Oct 2015, at 11:55, Johannes Smith <smith@example.com <mailto:smith@example.com>> wrote:
    >
    > Hi,
    >
    > OK. Wer kriegt das Angebot? Ist das wirklich nur ein halber Tag?
    " should = "
    Hi Johannes,

    das Angebot für den halben Tag bitte an uns.
    Der Termin hat sich jetzt auf 10-12 Uhr verschoben, hab ich dir weitergeleitet.

    Viele Grüße
    Max

    > On 07 Oct 2015, at 11:55, Johannes Smith <smith@example.com <mailto:smith@example.com>> wrote:
    >
    > Hi,
    >
    > OK. Wer kriegt das Angebot? Ist das wirklich nur ein halber Tag?
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) message = "Dear Mr. Smith,

    it seems to be, dass Sie den AutoIncrement Nummerngenerator für Ihre ITSMChangeManagement Installation verwenden. Seit ABC 3.2 wird führend vor der sich in der Datei <ABC_CONFIG_Home>/war/log/ITSMChangeCounter.log  befindenden Zahl die SystemID (SysConfig) geschrieben. Dies ist ein Standardverhalten, dass auch bei der Ticketnummer verwendet wird.

    Please ask me if you have questions.

    Viele Grüße,
      Thorsten Smith\n
    \n
    --\n
    Enterprise Services for ABC\n
    \n
    Znuny GmbH // Marienstraße 11 // 10117 Berlin // Germany\n
    \n
    P: +49 (0) 30 111 111 111-0\n
    F: +49 (0) 30 111 111 111-8\n
    W: http://znuny.com \n
    \n
    Location: Berlin - HRB 12345678 B Amtsgericht Berlin-Charlottenburg\n
    Managing Director: Martin Edenhofer\n
    " should = "Dear Mr. Smith,

    it seems to be, dass Sie den AutoIncrement Nummerngenerator für Ihre ITSMChangeManagement Installation verwenden. Seit ABC 3.2 wird führend vor der sich in der Datei <ABC_CONFIG_Home>/war/log/ITSMChangeCounter.log  befindenden Zahl die SystemID (SysConfig) geschrieben. Dies ist ein Standardverhalten, dass auch bei der Ticketnummer verwendet wird.

    Please ask me if you have questions.

    Viele Grüße,
      Thorsten Smith\n
    \n
    --\n
    Enterprise Services for ABC\n
    \n
    Znuny GmbH // Marienstraße 11 // 10117 Berlin // Germany\n
    \n
    P: +49 (0) 30 111 111 111-0\n
    F: +49 (0) 30 111 111 111-8\n
    W: http://znuny.com \n
    \n
    Location: Berlin - HRB 12345678 B Amtsgericht Berlin-Charlottenburg\n
    Managing Director: Martin Edenhofer\n
    " result = App.Utils.signatureIdentifyByPlaintext(message, true, true) equal(result, should) message = "Dear Mr. Smith, nice to read you,
      Thorsten Smith\n
    \n
    --\n
    " should = "Dear Mr. Smith, nice to read you,
      Thorsten Smith\n
    \n
    --\n
    " result = App.Utils.signatureIdentifyByPlaintext(message, true, true) equal(result, should) message = "Dear Mr. Smith, nice to read you,
      Thorsten Smith\n
    \n
    --\n
    " should = "Dear Mr. Smith, nice to read you,
      Thorsten Smith\n
    \n
    --\n
    " result = App.Utils.signatureIdentifyByPlaintext(message, false, true) equal(result, should) // fr message = "
    test 123

    --no not match--

    Bob Smith
    De : Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
    Envoyé : mercredi 29 avril 2015 17:31
    Objet : lalala
    " should = '
    test 123

    --no not match--

    Bob Smith
    De : Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
    Envoyé : mercredi 29 avril 2015 17:31
    Objet : lalala
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) // thunderbird // de message = "

    Viele Grüße,
    Christian

    Am 04.03.2015 um 12:47 schrieb Martin Edenhofer via Znuny Sales:
    > Hallo Christian,
    " should = "

    Viele Grüße,
    Christian

    Am 04.03.2015 um 12:47 schrieb Martin Edenhofer via Znuny Sales:
    > Hallo Christian,
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) // en - Thunderbird default - http://kb.mozillazine.org/Reply_header_settings message = "

    Viele Grüße,
    Christian

    On 01-01-2007 11:00 AM, Alf Aardvark wrote:
    > Hallo Christian,
    " should = "

    Viele Grüße,
    Christian

    On 01-01-2007 11:00 AM, Alf Aardvark wrote:
    > Hallo Christian,
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) // en - http://kb.mozillazine.org/Reply_header_settings message = "

    Viele Grüße,
    Christian

    Alf Aardvark wrote, on 01-01-2007 11:00 AM:
    > Hallo Christian,
    " should = "

    Viele Grüße,
    Christian

    Alf Aardvark wrote, on 01-01-2007 11:00 AM:
    > Hallo Christian,
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) // otrs // en 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.signatureIdentifyByPlaintext(message, true) equal(result, should) // de message = "
    test 123

    --no not match--

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

    --no not match--

    Bob Smith
    01/04/15 10:55 - Bob Smith schrieb:
    lalala
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) 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.signatureIdentifyByPlaintext(message, true) equal(result, should) // zammad message = "
    test 123

    --no not match--

    Bob Smith
    lalala
    " should = "
    test 123

    --no not match--

    Bob Smith
    lalala
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) message = "
    test 123

    --no not match--

    Bob Smith
    lalala
    " should = "
    test 123

    --no not match--

    Bob Smith
    lalala
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) // gmail message = "
    test 123

    --no not match--

    Bob Smith
    lalala
    " should = "
    test 123

    --no not match--

    Bob Smith
    lalala
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) message = "
    test 123

    --no not match--

    Bob Smith
    lalala
    " should = "
    test 123

    --no not match--

    Bob Smith
    lalala
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) message = "
    test 123

    --no not match--

    Bob Smith
    Am 24. Dezember 2015 um 07:45 schrieb kathrine <kathrine@example.com>:
    lalala
    " should = "
    test 123

    --no not match--

    Bob Smith
    Am 24. Dezember 2015 um 07:45 schrieb kathrine <kathrine@example.com>:
    lalala
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) // word 14 // en message = "
    test 123

    --no not match--

    Bob Smith
    Bob Smith wrote:
    lalala
    " should = '
    test 123

    --no not match--

    Bob Smith
    Bob Smith wrote:
    lalala
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) // de message = "
    test 123

    --no not match--

    Bob Smith
    Bob Smith schrieb:
    lalala
    " should = '
    test 123

    --no not match--

    Bob Smith
    Bob Smith schrieb:
    lalala
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) equal(result, should) }); test("identify signature by HTML", function() { var message = "
    test 123
    " var should = message var result = App.Utils.signatureIdentifyByHtml(message) equal(result, should) // test if, according to jQuery, invalid HTML does not cause a a crash // https://github.com/zammad/zammad/issues/3393 message = "
    test 123
    " should = message result = App.Utils.signatureIdentifyByHtml(message) equal(result, should) // simple case 1 message = '
    actual content
    quoted content
    ' should = '
    actual content
    quoted content
    ' result = App.Utils.signatureIdentifyByHtml(message) equal(result, should) // simple case 2 message = '
    actual content
    quoted content



    ' should = '
    actual content
    quoted content



    ' result = App.Utils.signatureIdentifyByHtml(message) equal(result, should) // simple case 3 message = '
    actual content
    quoted content

    actual content 2
    ' should = message result = App.Utils.signatureIdentifyByHtml(message) equal(result, should) // simple case 4 message = ' content 0
    content 1
    content 2
    quoted content



    ' should = ' content 0
    content 1
    content 2
    quoted content



    ' result = App.Utils.signatureIdentifyByHtml(message) equal(result, should) // ignore mail structures of case Ticket#1085048 message = '
    CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

    actual content

    actual content 2

     

    actual quote

    actual quote

     

     

    ' should = '
    CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

    actual content

    actual content 2

     

    actual quote

    actual quote

     

     

    ' result = App.Utils.signatureIdentifyByHtml(message) equal(result, should) // Gmail via Safari on MacOS 10.12 message = '
    Reply with gmail via Safari on MacOS 10.12

    \
    \
    Am Mi., 5. Sep. 2018 um 09:22 Uhr schrieb Billy Zhou <bz@zammad.com>:
    \
    \
    test email content
    \
    \
    \
    ' should = '
    Reply with gmail via Safari on MacOS 10.12

    \
    \
    Am Mi., 5. Sep. 2018 um 09:22 Uhr schrieb Billy Zhou <bz@zammad.com>:
    \
    \
    test email content
    \
    \
    \
    ' result = App.Utils.signatureIdentifyByHtml(message) equal(result, should) // Yahoo Mail via Safari on MacOS 10.12 message = '
    Reply with Yahoo Mail via Safari on MacOS 10.12


    Billy Zhou <bz@zammad.com> schrieb am 9:08 Mittwoch, 5.September 2018:


    test email content



    ' should = '
    Reply with Yahoo Mail via Safari on MacOS 10.12


    Billy Zhou <bz@zammad.com> schrieb am 9:08 Mittwoch, 5.September 2018:


    test email content



    ' result = App.Utils.signatureIdentifyByHtml(message) equal(result, should) // Thunderbird 52 on MacOS 10.12 message = 'Reply with Thunderbird 52 on MacOS 10.12
    \
    \
    Am 04.09.18 um 15:32 schrieb Billy\ Zhou:
    \
    \
    test\ email content\
    \
    \
    \
    ' should = 'Reply with Thunderbird 52 on MacOS 10.12
    \
    \
    Am 04.09.18 um 15:32 schrieb Billy\ Zhou:
    \
    \
    test\ email content\
    \
    \
    \
    ' result = App.Utils.signatureIdentifyByHtml(message) equal(result, should) // Apple Mail on MacOS 10 message = '
    Reply by Apple Mail on MacOS 10.


    On 4. Sep 2018, at 15:32, Billy Zhou <bz@zammad.com> wrote:

    test email content


    ' should = '
    Reply by Apple Mail on MacOS 10.


    On 4. Sep 2018, at 15:32, Billy Zhou <bz@zammad.com> wrote:

    test email content


    ' result = App.Utils.signatureIdentifyByHtml(message) equal(result, should) // Office 365 (10325.20118) on Windows 10 Build 1803 // With German marker: -----Ursprüngliche Nachricht----- // Using fallback to signatureIdentifyByPlaintext message = '
    \

    Reply with Office 365 (10325.20118) on Windows 10 Build 1803

    \

    \

    fett

    \

    \

    --

    \

    Zammad GmbH // Marienstraße 11 // 10117 Berlin // Germany

    \

    \

    P: +49 (0) 30 55 57 160-0

    \

    F: +49 (0) 30 55 57 160-99

    \

    W: https://zammad.com

    \

    \

    Location: Berlin - HRB 163946 B Amtsgericht Berlin-Charlottenburg

    \

    Managing Director: Martin Edenhofer

    \

    \

    -----Ursprüngliche Nachricht-----
    Von: Billy Zhou <bz@zammad.com>
    Gesendet: Dienstag, 4. September 2018 15:33
    An: me@zammad.com
    Betreff: test email title

    \

    \

    test email content

    \

    \
    ' should = '
    \

    Reply with Office 365 (10325.20118) on Windows 10 Build 1803

    \

    \

    fett

    \

    \

    --

    \

    Zammad GmbH // Marienstraße 11 // 10117 Berlin // Germany

    \

    \

    P: +49 (0) 30 55 57 160-0

    \

    F: +49 (0) 30 55 57 160-99

    \

    W: https://zammad.com

    \

    \

    Location: Berlin - HRB 163946 B Amtsgericht Berlin-Charlottenburg

    \

    Managing Director: Martin Edenhofer

    \

    \

    -----Ursprüngliche Nachricht-----
    Von: Billy Zhou <bz@zammad.com>
    Gesendet: Dienstag, 4. September 2018 15:33
    An: me@zammad.com
    Betreff: test email title

    \

    \

    test email content

    \

    \
    ' result = App.Utils.signatureIdentifyByHtml(message) equal(result, should) // Office 365 (10325.20118) on Windows 10 Build 1803 // With English marker: -----Original Message----- // Using fallback to signatureIdentifyByPlaintext message = '
    \

    Reply with Office 365 (10325.20118) on Windows 10 Build 1803

    \

    \

    fett

    \

    \

    --

    \

    Zammad GmbH // Marienstraße 11 // 10117 Berlin // Germany

    \

    \

    P: +49 (0) 30 55 57 160-0

    \

    F: +49 (0) 30 55 57 160-99

    \

    W: https://zammad.com

    \

    \

    Location: Berlin - HRB 163946 B Amtsgericht Berlin-Charlottenburg

    \

    Managing Director: Martin Edenhofer

    \

    \

    -----Original Message-----
    Von: Billy Zhou <bz@zammad.com>
    Gesendet: Dienstag, 4. September 2018 15:33
    An: me@zammad.com
    Betreff: test email title

    \

    \

    test email content

    \

    \
    ' should = '
    \

    Reply with Office 365 (10325.20118) on Windows 10 Build 1803

    \

    \

    fett

    \

    \

    --

    \

    Zammad GmbH // Marienstraße 11 // 10117 Berlin // Germany

    \

    \

    P: +49 (0) 30 55 57 160-0

    \

    F: +49 (0) 30 55 57 160-99

    \

    W: https://zammad.com

    \

    \

    Location: Berlin - HRB 163946 B Amtsgericht Berlin-Charlottenburg

    \

    Managing Director: Martin Edenhofer

    \

    \

    -----Original Message-----
    Von: Billy Zhou <bz@zammad.com>
    Gesendet: Dienstag, 4. September 2018 15:33
    An: me@zammad.com
    Betreff: test email title

    \

    \

    test email content

    \

    \
    ' result = App.Utils.signatureIdentifyByHtml(message) equal(result, should) // Office 365 (10325.20118) on Windows 10 Build 1803 // With German marker: -----Ursprüngliche Nachricht----- // Without any existing // Using fallback to signatureIdentifyByPlaintext message = '
    \

    Reply with Office 365 (10325.20118) on Windows 10 Build 1803

    \

    \

    fett

    \

    \

    --

    \

    Zammad GmbH // Marienstraße 11 // 10117 Berlin // Germany

    \

    \

    P: +49 (0) 30 55 57 160-0

    \

    F: +49 (0) 30 55 57 160-99

    \

    W: https://zammad.com

    \

    \

    Location: Berlin - HRB 163946 B Amtsgericht Berlin-Charlottenburg

    \

    Managing Director: Martin Edenhofer

    \

    \

    -----Ursprüngliche Nachricht-----
    Von: Billy Zhou <bz@zammad.com>
    Gesendet: Dienstag, 4. September 2018 15:33
    An: me@zammad.com
    Betreff: test email title

    \

    \

    test email content

    \

    \
    ' should = '
    \

    Reply with Office 365 (10325.20118) on Windows 10 Build 1803

    \

    \

    fett

    \

    \

    --

    \

    Zammad GmbH // Marienstraße 11 // 10117 Berlin // Germany

    \

    \

    P: +49 (0) 30 55 57 160-0

    \

    F: +49 (0) 30 55 57 160-99

    \

    W: https://zammad.com

    \

    \

    Location: Berlin - HRB 163946 B Amtsgericht Berlin-Charlottenburg

    \

    Managing Director: Martin Edenhofer

    \

    \

    -----Ursprüngliche Nachricht-----
    Von: Billy Zhou <bz@zammad.com>
    Gesendet: Dienstag, 4. September 2018 15:33
    An: me@zammad.com
    Betreff: test email title

    \

    \

    test email content

    \

    \
    ' result = App.Utils.signatureIdentifyByHtml(message) equal(result, should) }); // check attachment references test("check check attachment reference", function() { var message = 'some not existing' var result = false var verify = App.Utils.checkAttachmentReference(message) equal(verify, result) message = 'some attachment for you' result = 'Attachment' verify = App.Utils.checkAttachmentReference(message) equal(verify, result) message = 'your attachment.' result = 'Attachment' verify = App.Utils.checkAttachmentReference(message) equal(verify, result) message = 'some otherattachment for you' result = false verify = App.Utils.checkAttachmentReference(message) equal(verify, result) message = 'some attachmentother for you' result = false verify = App.Utils.checkAttachmentReference(message) equal(verify, result) message = 'someattachment' result = false verify = App.Utils.checkAttachmentReference(message) equal(verify, result) message = 'As enclosed you will find.' result = 'Enclosed' verify = App.Utils.checkAttachmentReference(message) equal(verify, result) message = '
    Hi Test,
    On Monday, 22 July 2019, 14:07:54, Test User wrote:

    Test attachment
    ' result = false verify = App.Utils.checkAttachmentReference(message) equal(verify, result) message = '
    Hi Test,
    cite attachment
    ' result = false verify = App.Utils.checkAttachmentReference(message) equal(verify, result) message = '
    Hi Test,
    ecxgmail_quote attachment
    ' result = false verify = App.Utils.checkAttachmentReference(message) equal(verify, result) }); // replace tags test("check replace tags", function() { var formatNumber = function(num, digits) { while (num.toString().length < digits) { num = '0' + num } return num } var formatTimestamp = function(timestamp) { localTime = new Date(Date.parse(timestamp)) d = formatNumber(localTime.getDate(), 2) m = formatNumber(localTime.getMonth() + 1, 2) yfull = localTime.getFullYear() M = formatNumber(localTime.getMinutes(), 2) H = formatNumber(localTime.getHours(), 2) return m + '/' + d + '/' + yfull + ' ' + H + ':' + M } var message = "
    #{user.firstname} #{user.lastname}
    " var result = '
    Bob Smith
    ' var data = { user: { firstname: 'Bob', lastname: 'Smith', }, } var verify = App.Utils.replaceTags(message, data) equal(verify, result) message = "
    #{user.firstname} #{user.lastname}
    " result = '
    Bob Smith
    ' data = { user: { firstname: function() { return 'Bob' }, lastname: function() { return 'Smith' }, }, } verify = App.Utils.replaceTags(message, data) equal(verify, result) message = "
    #{user.firstname} #{user.lastname}
    " result = '
    Bob -
    ' data = { user: { firstname: 'Bob', }, } verify = App.Utils.replaceTags(message, data) equal(verify, result) message = "
    #{user.firstname} #{user.lastname}
    " result = '
    Bob 0
    ' data = { user: { firstname: 'Bob', lastname: 0, }, } verify = App.Utils.replaceTags(message, data) equal(verify, result) message = "
    #{user.firstname} #{user.lastname}
    " result = '
    Bob -
    ' data = { user: { firstname: 'Bob', lastname: '', }, } verify = App.Utils.replaceTags(message, data) equal(verify, result) message = "
    #{user.firstname} #{user.not.existing.test}
    " result = '
    Bob -
    ' data = { user: { firstname: 'Bob', }, } verify = App.Utils.replaceTags(message, data) equal(verify, result) message = "
    #{user.firstname} #{not.existing.test}
    " result = '
    Bob -
    ' data = { user: { firstname: 'Bob', }, } verify = App.Utils.replaceTags(message, data) equal(verify, result) message = "
    #{user.firstname} #{not.existing.test}
    " result = '
    Bob -
    ' data = { user: { firstname: 'Bob', not: null, }, } verify = App.Utils.replaceTags(message, data) equal(verify, result) message = "
    #{user.firstname} #{not.existing.test}
    " result = '
    Bob -
    ' data = { user: { firstname: 'Bob', not: {}, }, } verify = App.Utils.replaceTags(message, data) equal(verify, result) message = "
    #{user.firstname} #{user.lastname}
    " result = '
    Bob Smith
    ' data = { user: { firstname: 'Bob', lastname: 'Smith', }, } verify = App.Utils.replaceTags(message, data) equal(verify, result) user = new App.User({ firstname: 'Bob', lastname: 'Smith Good', created_at: '2018-10-31T10:00:00Z', }) message = "
    #{user.firstname} #{user.created_at}
    " result = '
    Bob ' + formatTimestamp('2018-10-31T10:00:00Z') + '
    ' data = { user: user } verify = App.Utils.replaceTags(message, data) equal(verify, result) message = "
    #{user.firstname} #{user.created_at.date}
    " result = '
    Bob -
    ' data = { user: user } verify = App.Utils.replaceTags(message, data) equal(verify, result) message = "
    #{user.firstname} #{user.created.date}
    " result = '
    Bob -
    ' data = { user: user } verify = App.Utils.replaceTags(message, data) equal(verify, result) message = "some text" result = 'some text' data = { user: user } verify = App.Utils.replaceTags(message, data, true) equal(verify, result) }); // check attibute validation test("check attibute validation", function() { var string = '123' var result = '123' var verify = App.Utils.htmlAttributeCleanup(string) equal(verify, result, string) string = '123!' result = '123' verify = App.Utils.htmlAttributeCleanup(string) equal(verify, result, string) string = '12 3!' result = '123' verify = App.Utils.htmlAttributeCleanup(string) equal(verify, result, string) string = '12-3!' result = '12-3' verify = App.Utils.htmlAttributeCleanup(string) equal(verify, result, string) string = '12_3!' result = '12_3' verify = App.Utils.htmlAttributeCleanup(string) equal(verify, result, string) string = '^12_3!' result = '12_3' verify = App.Utils.htmlAttributeCleanup(string) equal(verify, result, string) string = '^1\n 2_3!' result = '12_3' verify = App.Utils.htmlAttributeCleanup(string) equal(verify, result, string) string = 'abc?' result = 'abc' verify = App.Utils.htmlAttributeCleanup(string) equal(verify, result, string) string = 'abc."' result = 'abc' verify = App.Utils.htmlAttributeCleanup(string) equal(verify, result, string) string = '#abc!^' result = 'abc' verify = App.Utils.htmlAttributeCleanup(string) equal(verify, result, string) string = 'abc()=$' result = 'abc' verify = App.Utils.htmlAttributeCleanup(string) equal(verify, result, string) string = "abc()=$\n123\rß" result = 'abc123' verify = App.Utils.htmlAttributeCleanup(string) equal(verify, result, string) }); // check form diff test("check form diff", function() { var dataNow = { owner_id: 1, pending_date: '2015-01-28T09:39:00Z', } var dataLast = { owner_id: '', pending_date: '2015-01-28T09:39:00Z', } var diff = {} var result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') dataNow = { owner_id: '1', pending_date: '2015-01-28T09:39:00Z', } dataLast = { owner_id: '', pending_date: '2015-01-28T09:39:00Z', } diff = {} result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') dataNow = { pending_date: '2015-01-28T09:39:00Z', } dataLast = { owner_id: 1, pending_date: '2015-01-28T09:39:00Z', } diff = {} result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') dataNow = { owner_id: '', pending_date: '2015-01-28T09:39:00Z', } dataLast = { pending_date: '2015-01-28T09:39:00Z', } diff = { } result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') dataNow = { owner_id: '', state_ids: [1,5,6,7], } dataLast = {} diff = { state_ids: ['1','5','6','7'], } result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') dataNow = { owner_id: 1, state_ids: [1,5,7,6], } dataLast = { owner_id: '', state_ids: [1,5,6,7], } diff = {} result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') dataNow = { owner_id: 1, state_ids: [1,5,6,7], } dataLast = { state_ids: ['1','5','7'], } diff = { state_ids: ['6'], } result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') dataNow = { owner_id: '', state_ids: [1,5,6,7], } dataLast = { owner_id: 1, state_ids: [1,5,6,7], } diff = {} result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') dataNow = { owner_id: '', state_ids: [1,5,6,7], } dataLast = { owner_id: 5, state_ids: [1,5,6,7], } diff = { owner_id: '' } result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') dataNow = { state_id: 4, pending_time: '2015-01-28T11:34:00Z' } dataLast = { state_id: 5, pending_time: undefined } diff = { state_id: '4', pending_time: '2015-01-28T11:34:00Z' } result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') dataNow = { pending_time: undefined } dataLast = { pending_time: null } diff = {} result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') dataNow = { ticket: { pending_time: undefined, }, } dataLast = { ticket: { pending_time: null, }, } diff = {} result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') dataNow = { test: '123', ticket: { pending_time: undefined, }, } dataLast = { test: '123', ticket: { pending_time: null, }, } diff = {} result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') dataNow = { test: '123', } dataLast = {} diff = { test: '123', } result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') dataNow = { test: '123', } dataLast = { test: [1,2,3,4] } diff = { test: '123', } result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') dataNow = { test: '123', } dataLast = { test: { 1: 1, 2: 2, } } diff = { test: '123', } result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') dataNow = { test: [1,2,3,'4'] } dataLast = { test: '123', } diff = { test: ['1','2','3','4'] } result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') dataNow = { test: { 1: 1, 2: 2, } } dataLast = { test: '123', } diff = { test: { 1: '1', 2: '2', } } result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') // regression test for issue #2042 - incorrect notification when closing a tab after setting up an object // A newly created attribute will have the empty string as its value, this should be ignored for formDiff comparison dataNow = { test: '', } dataLast = {} diff = {} result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff for a newly created attribute that is blank') dataNow = { test: '', } dataLast = { test: '123', } diff = { test: '', } result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff for setting a previously valid value to blank') dataNow = { test: '123', ticket: { pending_time: undefined, }, } dataLast = { ticket: { pending_time: null, }, } diff = { test: '123', } result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') dataNow = undefined dataLast = undefined diff = {} result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') dataNow = {} dataLast = {"number":"10012","title":"some subject 123äöü","group_id":1,"owner_id":1,"customer_id":2,"state_id":3,"priority_id":2,"article":{"from":"Test Master Agent","to":"","cc":"","body":"dasdad","content_type":"text/html","ticket_id":12,"type_id":9,"sender_id":1,"internal":false,"form_id":"523405147"},"updated_at":"2015-01-29T09:22:23.000Z","pending_time":"2015-01-28T22:22:00.000Z","id":12} diff = {} result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') // do not compare content of data instances/objects no = function test_object() { this.a = function() { return 123; } this.b = function() { return '1234'; } this.c = function() { return [123]; } this.d = [1,2,3]; this.e = 'abc'; } no1 = new no() no2 = new no() no3 = new no() dataNow = { number:'10013', Article: [no1], } dataLast = { number: "10012", title: "some subject 123äöü", Article: [ no2, no3 ], } diff = { number:'10013', } result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') dataNow = { number:'10013', Article: [no1,2], } dataLast = { number: "10012", title: "some subject 123äöü", Article: [ no2, no3 ], } diff = { number:'10013', Article: ['2'], } result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') }); // check decimal format test("check decimal format", function() { var string = '123' var result = '123.00' var verify = App.Utils.decimal(string) equal(verify, result, string) string = '0.6' result = '0.60' verify = App.Utils.decimal(string) equal(verify, result, string) string = '6' result = '6.00' verify = App.Utils.decimal(string) equal(verify, result, string) string = 6.5 result = '6.50' verify = App.Utils.decimal(string) equal(verify, result, string) string = '111111.6' result = '111111.60' verify = App.Utils.decimal(string) equal(verify, result, string) string = '111111.622' result = '111111.62' verify = App.Utils.decimal(string) equal(verify, result, string) string = 'abc.6' result = 'abc.6' verify = App.Utils.decimal(string) equal(verify, result, string) string = '' result = '' verify = App.Utils.decimal(string) equal(verify, result, string) string = undefined result = '' verify = App.Utils.decimal(string) equal(verify, result, string) string = null result = '' verify = App.Utils.decimal(string) equal(verify, result, string) }); // check formatTime format test("check formatTime format", function() { var string = '123' var result = '123' var verify = App.Utils.formatTime(string, 0) equal(verify, result, string) string = '6' result = '06' verify = App.Utils.formatTime(string, 2) equal(verify, result, string) string = '' result = '00' verify = App.Utils.formatTime(string, 2) equal(verify, result, string) string = undefined result = '' verify = App.Utils.formatTime(string, 2) equal(verify, result, string) string = null result = '' verify = App.Utils.formatTime(string, 2) equal(verify, result, string) }); // check diffPosition test("check diffPosition format", function() { var a = [1,2,3,4] var b = [1,2,3,4,5] var result = [ { position: 4, id: 5, }, ] var verify = App.Utils.diffPositionAdd(a, b) deepEqual(verify, result) a = [2,3,4] b = [1,2,3,4] result = [ { position: 0, id: 1, }, ] verify = App.Utils.diffPositionAdd(a, b) deepEqual(verify, result) a = [2,3,4] b = [1,2,3,4,5] result = [ { position: 0, id: 1, }, { position: 4, id: 5, }, ] verify = App.Utils.diffPositionAdd(a, b) deepEqual(verify, result) a = [2,3,4] b = [1,99,12,2,3,4,5] result = [ { position: 0, id: 1, }, { position: 1, id: 99, }, { position: 2, id: 12, }, { position: 6, id: 5, }, ] verify = App.Utils.diffPositionAdd(a, b) deepEqual(verify, result) a = [4,3,1] b = [1,2,3,4,5] result = false verify = App.Utils.diffPositionAdd(a, b) deepEqual(verify, result) a = ['Ticket-347', 'TicketCreateScreen-2217'] b = ['Ticket-347', 'TicketCreateScreen-2217', 'TicketCreateScreen-71517'] result = [ { position: 2, id: 'TicketCreateScreen-71517', }, ] verify = App.Utils.diffPositionAdd(a, b) deepEqual(verify, result) }); // check textLengthWithUrl format test("check textLengthWithUrl format", function() { var string = '123' var result = 3 var verify = App.Utils.textLengthWithUrl(string) equal(verify, result) string = '123 http is not here' result = 20 verify = App.Utils.textLengthWithUrl(string) equal(verify, result) string = '123 http://host is not here' result = 39 verify = App.Utils.textLengthWithUrl(string) equal(verify, result) string = '123 http://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX is not here' result = 39 verify = App.Utils.textLengthWithUrl(string) equal(verify, result) string = 'http://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' result = 23 verify = App.Utils.textLengthWithUrl(string) equal(verify, result) string = 'http://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX, some other text' result = 23 + 17 verify = App.Utils.textLengthWithUrl(string) equal(verify, result) string = 'some other text,http://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' result = 23 + 16 verify = App.Utils.textLengthWithUrl(string) equal(verify, result) string = 'some other text, http://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX?abc=123;aaa=ab+c usw' result = 23 + 21 verify = App.Utils.textLengthWithUrl(string) equal(verify, result) }); // check getRecipientArticle format test('check getRecipientArticle format', function() { var customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } var ticket = { customer: customer, } var article = { type: { name: 'phone', }, sender: { name: 'Customer', }, from: customer.email, to: 'some group', message_id: 'message_id1', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', }, } var result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id1', } var verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } ticket = { customer: customer, } article = { type: { name: 'phone', }, sender: { name: 'Customer', }, from: customer.email, message_id: 'message_id2', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', }, } result = { to: customer.email, cc: '', body: '', in_reply_to: 'message_id2', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id3', type: { name: 'phone', }, sender: { name: 'Agent', }, from: 'article_created_by@example.com', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', }, } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id3', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id4', created_by: customer, type: { name: 'web', }, sender: { name: 'Customer', }, from: customer.email, to: 'some group', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', }, } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id4', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id5', type: { name: 'web', }, sender: { name: 'Customer', }, from: customer.email, created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', } } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id5', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id6', type: { name: 'email', }, sender: { name: 'Customer', }, from: customer.email, to: 'some group', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', } } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id6', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id7', type: { name: 'email', }, sender: { name: 'Customer', }, from: 'some other invalid part, ' + customer.email, to: 'some group', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', } } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id7', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) console.log(verify) deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id7.1', type: { name: 'email', }, sender: { name: 'Customer', }, from: 'some other invalid part, Some Realname ' + customer.email, to: 'some group', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', } } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id7.1', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) console.log(verify) deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id7.2', type: { name: 'email', }, sender: { name: 'Customer', }, from: 'some other invalid part, Some Realname ' + customer.email + ' , abc', to: 'some group', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', } } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id7.2', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) console.log(verify) deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'agent@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id8', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'customer2@example.com', to: 'customer@example.com', } result = { to: 'customer2@example.com', cc: '', body: '', in_reply_to: 'message_id8', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'agent@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id9', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'agent@example.com', to: 'customer@example.com', } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id9', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'agent@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id10', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'Agent@Example.com', to: 'customer@example.com', cc: 'zammad@example.com', } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id10', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'agent@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id11', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'Agent@Example.com', to: 'customer@example.com, agent@example.com', cc: 'zammad@example.com', } result = { to: 'customer@example.com, agent@example.com', cc: 'zammad@example.com', body: '', in_reply_to: 'message_id11', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type, [], true) deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'agent@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id12', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'Agent@Example.com', to: 'customeR@EXAMPLE.com, agent@example.com', cc: 'zammad@example.com, customer@example.com', } result = { to: 'customer@example.com, agent@example.com', cc: 'zammad@example.com', body: '', in_reply_to: 'message_id12', } verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, [], true) deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'agent@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id13', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'Agent@Example.com', to: 'customeR@EXAMPLE.com, agent@example.com, zammad2@EXAMPLE.com', cc: 'zammad@example.com, customer2@example.com', } result = { to: 'customer@example.com, agent@example.com', cc: 'customer2@example.com', body: '', in_reply_to: 'message_id13', } email_addresses = [ { email: 'zammad@example.com', }, { email: 'zammad2@example.com', } ] verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, true) deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'AGENT@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id14', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'Agent@Example.com', to: 'customeR@EXAMPLE.com, agent@example.com, zammad2@EXAMPLE.com', cc: 'zammad@example.com, customer2@example.com', } result = { to: 'customer@example.com, agent@example.com', cc: 'customer2@example.com', body: '', in_reply_to: 'message_id14', } email_addresses = [ { email: 'zammad@example.com', }, { email: 'zammad2@example.com', } ] verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, true) deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'zammad@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id15', created_by: customer, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'zammad@EXAMPLE.com', to: 'customeR@EXAMPLE.com, agent@example.com, zammad2@EXAMPLE.com', cc: 'zammad@example.com, customer2@example.com', } result = { to: 'customer@example.com, agent@example.com', cc: 'customer2@example.com', body: '', in_reply_to: 'message_id15', } email_addresses = [ { email: 'zammad@example.com', }, { email: 'zammad2@example.com', } ] verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, true) deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id16', created_by: customer, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'customer@example.com', to: 'customer1@example.com, customer2@example.com, zammad@example.com', cc: '', } result = { to: 'customer1@example.com, customer2@example.com, customer@example.com', cc: '', body: '', in_reply_to: 'message_id16', } email_addresses = [ { email: 'zammad@example.com', }, { email: 'zammad2@example.com', } ] verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, true) deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id17', created_by: customer, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'customer@example.com', to: 'customer1@example.com, customer2@example.com, zammad@example.com, customer2+2@example.com', cc: '', } result = { to: 'customer1@example.com, customer2@example.com, customer2+2@example.com, customer@example.com', cc: '', body: '', in_reply_to: 'message_id17', } email_addresses = [ { email: 'zammad@example.com', }, { email: 'zammad2@example.com', } ] verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, true) deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'zammad@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id18', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'zammad@example.com', to: 'customer@example.com', cc: '', } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id18', } email_addresses = [ { email: 'zammad@example.com', }, { email: 'zammad2@example.com', } ] verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, true) deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'zammad@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id19', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'Sender ', to: 'Customer ', cc: '', } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id19', } email_addresses = [ { email: 'zammad@example.com', }, { email: 'zammad2@example.com', } ] verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, false) deepEqual(verify, result) agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'agent@example.com', } ticket = { customer: agent, } article = { message_id: 'message_id20', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'Agent ', to: 'Sender ', cc: '', } result = { to: 'agent@example.com', cc: '', body: '', in_reply_to: 'message_id20', } email_addresses = [ { email: 'zammad@example.com', }, { email: 'zammad2@example.com', } ] verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, false) deepEqual(verify, result) agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'agent@example.com', } ticket = { customer: agent, } article = { message_id: 'message_id20', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'Agent ', to: 'somebodyelse@example.com, Zammad ', cc: '', } result = { to: 'agent@example.com', cc: '', body: '', in_reply_to: 'message_id20', } email_addresses = [ { email: 'zammad@example.com', }, { email: 'zammad2@example.com', } ] verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, false) deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: "'customer@example.com'", } agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'agent@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id21', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: customer.email, to: 'agent@example.com', } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id21', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) deepEqual(verify, result) // Regression test for issue #2184 // Case 1 // 1. Create a "Received Call" Ticket for article_customer // 2. Change the Customer of the ticket to ticket_customer (but article.from still points to article_customer) // 3. Reply to the first Article // Recipient SHOULD BE Article.from var article_customer = { login: 'login', firstname: 'article', lastname: 'lastname', email: 'article_customer@example.com', } var ticket_customer = { login: 'login2', firstname: 'ticket', lastname: 'lastname', email: 'ticket_customer@example.com', } ticket = { customer: ticket_customer, } article = { type: { name: 'phone', }, sender: { name: 'Customer', }, from: 'article lastname ', to: 'some group', message_id: 'message_id22', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', }, } result = { to: 'article_customer@example.com', cc: '', body: '', in_reply_to: 'message_id22', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) deepEqual(verify, result) // Regression test for issue #2184 // Case 2 // 1. Create a "Outbound Call" Ticket for article_customer // 2. Change the Customer of the Ticket to ticket_customer (but article.to still points to article_customer) // 3. Reply to the first Article // Recipient SHOULD BE Article.to article_customer = { login: 'login', firstname: 'article', lastname: 'lastname', email: 'article_customer@example.com', } ticket_customer = { login: 'login2', firstname: 'ticket', lastname: 'lastname', email: 'ticket_customer@example.com', } ticket = { customer: ticket_customer, } article = { type: { name: 'phone', }, sender: { name: 'Agent', }, from: 'agent1@example.com', to: article_customer.email, message_id: 'message_id23', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', }, } result = { to: 'article_customer@example.com', cc: '', body: '', in_reply_to: 'message_id23', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) deepEqual(verify, result) // https://github.com/zammad/zammad/issues/2551 // If "From:" is local address and "Reply-To:" is available, use it var article_customer = { login: 'login', firstname: 'article', lastname: 'lastname', email: 'article_customer@example.com', } var ticket_customer = { login: 'login2', firstname: 'ticket', lastname: 'lastname', email: 'ticket_customer@example.com', } ticket = { customer: ticket_customer, } article = { type: { name: 'email', }, sender: { name: 'Customer', }, from: 'article lastname ', to: 'some group', reply_to: 'asd@example.com', message_id: 'message_id22', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', }, } email_addresses = [{ email: 'article_customer@example.com'}] result = { to: 'asd@example.com', cc: '', body: '', in_reply_to: 'message_id22', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type, email_addresses) deepEqual(verify, result) }); test("contentTypeCleanup", function() { var source = "image/png" var should = "image/png" var result = App.Utils.contentTypeCleanup(source) equal(result, should, source) source = "image/png; some.file" should = "image/png" result = App.Utils.contentTypeCleanup(source) equal(result, should, source) source = "image/png;some.file" should = "image/png" result = App.Utils.contentTypeCleanup(source) equal(result, should, source) source = "image/jpeg;some.file" should = "image/jpeg" result = App.Utils.contentTypeCleanup(source) equal(result, should, source) source = "image/jpg;some.file" should = "image/jpg" result = App.Utils.contentTypeCleanup(source) equal(result, should, source) source = "image/gif;some.file" should = "image/gif" result = App.Utils.contentTypeCleanup(source) equal(result, should, source) source = "image/gif\n;some.file" should = "image/gif" result = App.Utils.contentTypeCleanup(source) equal(result, should, source) }); // htmlImage2DataUrl test("htmlImage2DataUrl", function() { var source = '
    test 13
    ' var should = '
    test 13
    ' var result = App.Utils.htmlImage2DataUrl(source) equal(result, should, source) source = 'some test' should = 'some test' result = App.Utils.htmlImage2DataUrl(source) equal(result, should, source) source = 'some test' should = 'some test' result = App.Utils.htmlImage2DataUrl(source) equal(result, should, source) source = 'some test' should = 'some test' result = App.Utils.htmlImage2DataUrl(source) equal(result, should, source) source = 'some test' should = 'some test' result = App.Utils.htmlImage2DataUrl(source) equal(result, should, source) // GitHub issue #2305 source = 'some test' should = 'some test' result = App.Utils.htmlImage2DataUrl(source) equal(result, should, source) // GitHub issue #2701 source = 'foosome test' should = 'foosome test' result = App.Utils.htmlImage2DataUrl(source) equal(result, should, source) }); test('App.Utils.icon()', function() { // When given no arguments, // expect @icon() to return null equal(App.Utils.icon(), null, 'with no arguments') // On a modern browser and when given a single argument, // expect @icon(name) to return an tag window.svgPolyfill = false svgTag = '' equal(App.Utils.icon('foo'), svgTag, 'with one arg / no SVG polyfill') // On a modern browser and when given two arguments, // expect @icon(name) to return an tag // with second arg as add'l class name window.svgPolyfill = false svgTag = '' equal(App.Utils.icon('foo', 'bar'), svgTag, 'with two args / no SVG polyfill') // On a browser requiring SVG polyfill and when given a single argument, // expect @icon(name, class) to return an tag // with pathless xlink:href attr window.svgPolyfill = true svgTag = '' equal(App.Utils.icon('foo'), svgTag, 'with one arg / SVG polyfill') // On a browser requiring SVG polyfill and when given two arguments, // expect @icon(name, class) to return an tag // with pathless xlink:href attr and second arg as add'l class name window.svgPolyfill = true svgTag = '' equal(App.Utils.icon('foo', 'bar'), svgTag, 'with two args / SVG polyfill') // For a left-to-right browser language and when given an argument containing '{start}' or '{end}', // expect @icon(name) to return an tag // replacing '{start}' with 'left' and '{end}' with 'right' window.svgPolyfill = false App.i18n.dir = function() { return 'ltr' } svgTag = '' equal(App.Utils.icon('arrow-{start}'), svgTag, 'for ltr locale / name includes "{start}"') svgTag = '' equal(App.Utils.icon('arrow-{end}'), svgTag, 'for ltr locale / name includes "{end}"') // For a right-to-left browser language and when given an argument containing '{start}' or '{end}', // expect @icon(name) to return an tag // replacing '{start}' with 'left' and '{end}' with 'right' window.svgPolyFill = false App.i18n.dir = function() { return 'rtl' } svgTag = '' equal(App.Utils.icon('arrow-{start}'), svgTag, 'for rtl locale / name includes "{start}"') svgTag = '' equal(App.Utils.icon('arrow-{end}'), svgTag, 'for rtl locale / name includes "{end}"') }); var source1 = 'some test' $('#image2data1').html(source1) var htmlImage2DataUrlTest1 = function() { test("htmlImage2DataUrl1 async", function() { var result1 = App.Utils.htmlImage2DataUrl(source1) ok(result1.match(/some test/), source1) ok(!result1.match(/avatar-bg.png/), source1) ok(result1.match(/^\'), false) equal(App.Utils.clipboardHtmlIsWithText('
    '), false) equal(App.Utils.clipboardHtmlIsWithText('
    '), false) equal(App.Utils.clipboardHtmlIsWithText('
    '), false) equal(App.Utils.clipboardHtmlIsWithText('
    '), false) equal(App.Utils.clipboardHtmlIsWithText("
    \n
    "), false) // content with text equal(App.Utils.clipboardHtmlIsWithText('test'), true) equal(App.Utils.clipboardHtmlIsWithText('
    test
    '), true) equal(App.Utils.clipboardHtmlIsWithText('sometext'), true) }); test('App.Utils.clipboardHtmlInsertPreperation()', function() { equal(App.Utils.clipboardHtmlInsertPreperation('
    ', {}), '') equal(App.Utils.clipboardHtmlInsertPreperation('
    ', {}), ' ') equal(App.Utils.clipboardHtmlInsertPreperation('
    ', {}), '') equal(App.Utils.clipboardHtmlInsertPreperation('
    ', {}), '') equal(App.Utils.clipboardHtmlInsertPreperation('
    ', {}), ' ') equal(App.Utils.clipboardHtmlInsertPreperation("
    \n
    ", {}), " \n ") equal(App.Utils.clipboardHtmlInsertPreperation('test', {}), 'test') equal(App.Utils.clipboardHtmlInsertPreperation('
    test
    ', {}), 'test') equal(App.Utils.clipboardHtmlInsertPreperation('sometext', {}), '
    sometext
    ') equal(App.Utils.clipboardHtmlInsertPreperation('
    test 123
    ', { mode: 'textonly' }), 'test 123') equal(App.Utils.clipboardHtmlInsertPreperation('
    test
    123
    ', { mode: 'textonly' }), 'test 123') equal(App.Utils.clipboardHtmlInsertPreperation('
    test
    123
    ', { mode: 'textonly', multiline: true }), 'test
    123') }); test('App.Utils.signatureIdentifyByHtmlHelper()', function() { result = App.Utils.signatureIdentifyByHtmlHelper("<script>alert('fish2');</script>
    ") equal(result, "<script>alert('fish2');</script>
    ", 'signatureIdentifyByHtmlHelper does not reactivate alert') }); test("#safeParseHtml", function() { var unwrap = input => $('
    ').html(input)[0].innerHTML var html = "
    test 123
    " var result = App.Utils.safeParseHtml(html) var should = html equal(unwrap(result), html) // test if, according to jQuery, invalid HTML does not cause a a crash // https://github.com/zammad/zammad/issues/3393 html = "
    test 123
    " should = "
    test 123
    " result = App.Utils.safeParseHtml(html) equal(unwrap(result), should) })