[BUGFIX] MailUtility breakLinesForEmail cuts text wrong and discard rest 78/22678/2
authorTim Lochmueller <tim@fruit-lab.de>
Mon, 29 Jul 2013 22:58:42 +0000 (00:58 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Mon, 29 Jul 2013 23:00:37 +0000 (01:00 +0200)
Now the substrStart pointer increases in case that the line is longer
than the lineWidth parameter.

Resolves: #49396
Releases: 6.2, 6.1, 6.0
Change-Id: I87b3622c2ada7efdcb4c1992c1cfa43635d68f09
Reviewed-on: https://review.typo3.org/22678
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/core/Classes/Utility/MailUtility.php
typo3/sysext/core/Tests/Unit/Utility/MailUtilityTest.php

index 8eeac85..336f670 100644 (file)
@@ -174,6 +174,7 @@ class MailUtility {
 
        /**
         * Breaks up a single line of text for emails
+        * Words - longer than $lineWidth - will not be split into parts
         *
         * @param string $str The string to break up
         * @param string $newlineChar The string to implode the broken lines with (default/typically \n)
@@ -193,6 +194,7 @@ class MailUtility {
                                if ($spacePos !== FALSE) {
                                        // take everything up to last space-char
                                        $theLine = substr($substr, 0, $spacePos);
+                                       $substrStart++;
                                } else {
                                        // search for space-char in remaining text
                                        // makes this line longer than $lineWidth!
index 32c92c1..a9b3927 100644 (file)
@@ -148,6 +148,15 @@ class MailUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $this->assertEquals($returnString, 'abcdefghijklmnopqrst' . LF . 'uvwxyz' . LF . '123456');
        }
 
+       /**
+        * @test
+        */
+       public function breakLinesForEmailBreaksTextIfLineIsLongerThanTheLineWidth() {
+               $str = 'Mein Link auf eine News (Link: http://zzzzzzzzzzzzz.xxxxxxxxx.de/index.php?id=10&tx_ttnews%5Btt_news%5D=1&cHash=66f5af320da29b7ae1cda49047ca7358)';
+               $returnString = \TYPO3\CMS\Core\Utility\MailUtility::breakLinesForEmail($str);
+               $this->assertEquals($returnString, 'Mein Link auf eine News (Link:' . LF . 'http://zzzzzzzzzzzzz.xxxxxxxxx.de/index.php?id=10&tx_ttnews%5Btt_news%5D=1&cHash=66f5af320da29b7ae1cda49047ca7358)');
+       }
+
 }
 
 ?>
\ No newline at end of file