[BUGFIX] MailUtility::parseAddresses() returns @localhost on empty string 05/20905/2
authorPhilipp Gampe <philipp.gampe@typo3.org>
Thu, 16 May 2013 17:01:17 +0000 (19:01 +0200)
committerPhilipp Gampe <philipp.gampe@typo3.org>
Sun, 19 May 2013 09:37:29 +0000 (11:37 +0200)
parseAddresses should return an array of email addresses ready to be
feed into swiftmailer.
If an empty string is passed to the function, then it returns
"@localhost", which is not a valid email.
Swiftmailer will throw an exception "Address in mailbox given
[@localhost] does not comply with RFC 2822, 3.6.2."
This happens in ContentObjectRenderer->sendNotifyEmail() which is in
turn used by the frontend login forgotten passwort form.

Skip any addresses without a mailbox given.

Resolves: #48247
Releases: 6.2, 6.1
Change-Id: If8724416b3451417db7729dc81abdbd068dc8b10
Reviewed-on: https://review.typo3.org/20905
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
typo3/sysext/core/Classes/Utility/MailUtility.php
typo3/sysext/core/Tests/Unit/Utility/MailUtilityTest.php

index 44008ec..7799907 100644 (file)
@@ -242,6 +242,9 @@ class MailUtility {
                $addresses = $addressParser->parseAddressList();
                $addressList = array();
                foreach ($addresses as $address) {
+                       if ($address->mailbox === '') {
+                               continue;
+                       }
                        if ($address->personal) {
                                // item with name found ( name <email@example.org> )
                                $addressList[$address->mailbox . '@' . $address->host] = $address->personal;
index 529732a..7892701 100644 (file)
@@ -148,6 +148,41 @@ class MailUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $this->assertEquals($returnString, 'abcdefghijklmnopqrst' . LF . 'uvwxyz' . LF . '123456');
        }
 
+       /**
+        * Data provider for parseAddressesTest
+        *
+        * @return array Data sets
+        */
+       public function parseAddressesProvider() {
+               return array(
+                       'name &ltemail&gt;' => array('name <email@example.org>', array('email@example.org' => 'name')),
+                       '&lt;email&gt;' => array('<email@example.org>', array('email@example.org')),
+                       '@localhost' => array('@localhost', array()),
+                       '000@example.com' => array('000@example.com', array('000@example.com')),
+                       'email' => array('email@example.org', array('email@example.org')),
+                       'email1,email2' => array('email1@example.org,email2@example.com', array('email1@example.org', 'email2@example.com')),
+                       'name &ltemail&gt;,email2' => array('name <email1@example.org>,email2@example.com', array('email1@example.org' => 'name', 'email2@example.com')),
+                       '"last, first" &lt;name@example.org&gt;' => array('"last, first" <email@example.org>', array('email@example.org' => '"last, first"')),
+                       'email,name &ltemail&gt;,"last, first" &lt;name@example.org&gt;' => array(
+                               'email1@example.org, name <email2@example.org>, "last, first" <email3@example.org>',
+                               array(
+                                       'email1@example.org',
+                                       'email2@example.org' => 'name',
+                                       'email3@example.org' => '"last, first"'
+                               )
+                       )
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider parseAddressesProvider
+        */
+       public function parseAddressesTest($source, $addressList) {
+               $returnArray = \TYPO3\CMS\Core\Utility\MailUtility::parseAddresses($source);
+               $this->assertEquals($addressList, $returnArray);
+       }
+
 }
 
 ?>
\ No newline at end of file