[TASK] Rework t3lib_utility_Mail::breakLinesForEmail to drop
authorStefan Neufeind <typo3.neufeind@speedpartner.de>
Tue, 7 Feb 2012 08:12:10 +0000 (09:12 +0100)
committerSteffen Ritter <info@rs-websystems.de>
Mon, 13 Feb 2012 08:31:46 +0000 (09:31 +0100)
 strrev-magic

Use strrpos/substr instead of strrev-magic.
Add testcase for one more cornercase when breaking lines.

Change-Id: Icfa5bb44dc750100ed97aa4e22f43263d2072d26
Resolves: #28039
Releases: 4.7
Reviewed-on: http://review.typo3.org/5133
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
t3lib/utility/class.t3lib_utility_mail.php
tests/t3lib/utility/class.t3lib_utility_mailTest.php

index 1567134..7c216ee 100644 (file)
@@ -215,12 +215,11 @@ final class t3lib_utility_Mail {
                                // has line exceeded (reached) the maximum width?
                        if (strlen($substr) == $lineWidth) {
                                        // find last space-char
-                               $count = count(explode(' ', trim(strrev($substr))));
+                               $spacePos = strrpos(rtrim($substr), ' ');
                                        // space-char found?
-                               if ($count > 1) {
+                               if ($spacePos !== FALSE) {
                                                // take everything up to last space-char
-                                       $parts = explode(' ', strrev($substr), 2);
-                                       $theLine = strrev($parts[1]);
+                                       $theLine = substr($substr, 0, $spacePos);
                                } else {
                                                // search for space-char in remaining text
                                                // makes this line longer than $lineWidth!
index cb0b1eb..c199341 100644 (file)
@@ -158,5 +158,20 @@ class t3lib_utility_MailTest extends tx_phpunit_testcase {
             count(explode($newlineChar, $returnString))
         );
     }
+
+    /**
+     * @test
+     */
+    public function breakLinesForEmailBreaksTextWithNoSpaceFoundBeforeLimit() {
+        $newlineChar = LF;
+        $lineWidth = 10;
+               // first space after 20 chars (more than $lineWidth)
+        $str = 'abcdefghijklmnopqrst uvwxyz 123456';
+        $returnString = t3lib_utility_Mail::breakLinesForEmail($str, $newlineChar, $lineWidth);
+        $this->assertEquals(
+            $returnString,
+            'abcdefghijklmnopqrst' . LF . 'uvwxyz' . LF . '123456'
+        );
+    }
 }
-?>
\ No newline at end of file
+?>