0012766: trim invalid mails address format
authorMichael Spahn <m.spahn@metaways.de>
Mon, 6 Mar 2017 15:48:59 +0000 (16:48 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 14 Mar 2017 10:06:07 +0000 (11:06 +0100)
https://forge.tine20.org/view.php?id=12766

Change-Id: If63d46f2bee0ebd5a82da76313f29d34a805c6c3
Reviewed-on: http://gerrit.tine20.com/customers/4317
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Felamimail/Frontend/JsonTest.php
tine20/Felamimail/Model/Message.php

index 90b1448..c3f95f8 100644 (file)
@@ -514,16 +514,18 @@ class Felamimail_Frontend_JsonTest extends TestCase
         $contact = Addressbook_Controller_Contact::getInstance()->get($contactIds[0]);
         $originalEmail =  $contact->email;
         $contact->email = $this->_account->email;
+
+        /* @var $contact Addressbook_Model_Contact */
         $contact = Addressbook_Controller_Contact::getInstance()->update($contact, FALSE);
 
         // send email
         $messageToSend = $this->_getMessageData('unittestalias@' . $this->_mailDomain);
         $messageToSend['note'] = 1;
         $messageToSend['bcc']  = array(Tinebase_Core::getUser()->accountEmailAddress);
-        //print_r($messageToSend);
-        $returned = $this->_json->saveMessage($messageToSend);
+
+        $this->_json->saveMessage($messageToSend);
         $this->_foldersToClear = array('INBOX', $this->_account->sent_folder);
-        
+
         // check if message is in sent folder
         $message = $this->_searchForMessageBySubject($messageToSend['subject'], $this->_account->sent_folder);
         $this->assertEquals($message['from_email'], $messageToSend['from_email']);
@@ -531,14 +533,35 @@ class Felamimail_Frontend_JsonTest extends TestCase
         $this->assertEquals($message['to'][0],      $messageToSend['to'][0], 'recipient not found');
         $this->assertEquals($message['bcc'][0],     $messageToSend['bcc'][0], 'bcc recipient not found');
         $this->assertEquals($message['subject'],    $messageToSend['subject']);
-        
+
         $this->_checkEmailNote($contact, $messageToSend['subject']);
-        
+
         // reset sclevers original email address
         $contact->email = $originalEmail;
         Addressbook_Controller_Contact::getInstance()->update($contact, FALSE);
     }
-    
+
+    /**
+     * test send message
+     */
+    public function testSendMessageInvalidMail()
+    {
+        // send email
+        $messageToSend = $this->_getMessageData('unittestalias@' . $this->_mailDomain);
+        $messageToSend['note'] = 1;
+        $messageToSend['to'] = [
+            sprintf(
+                '%s <    %s     >',
+                Tinebase_Core::getUser()->accountFullName,
+                Tinebase_Core::getUser()->accountEmailAddress
+            )
+        ];
+        $messageToSend['bcc']  = array(Tinebase_Core::getUser()->accountEmailAddress);
+
+        $this->_json->saveMessage($messageToSend);
+        $this->_foldersToClear = array('INBOX', $this->_account->sent_folder);
+    }
+
     /**
      * check email note
      *
@@ -1702,7 +1725,7 @@ IbVx8ZTO7dJRKrg72aFmWTf0uNla7vicAhpiLWobyNYcZbIjrAGDfg==
         return array(
             'account_id'    => $this->_account->getId(),
             'subject'       => $_subject,
-            'to'            => array(Tinebase_Core::getUser()->accountEmailAddress),
+            'to'            => [Tinebase_Core::getUser()->accountEmailAddress],
             'body'          => 'aaaaaä <br>',
             'headers'       => array('X-Tine20TestMessage' => 'jsontest'),
             'from_email'    => $_emailFrom,
index 270f05b..7886df0 100644 (file)
@@ -681,14 +681,14 @@ class Felamimail_Model_Message extends Tinebase_Record_Abstract
                         $recipients = array_merge($recipients, explode($delimiter, $addresses));
                     } else {
                         // single recipient
-                        $recipients[] = $addresses;
+                        $recipients[] = \trim($addresses);
                     }
                 }
                 
                 foreach ($recipients as $key => &$recipient) {
                     // extract email address if name and address given
                     if (preg_match('/(.*)<(.*)>/', $recipient, $matches) > 0) {
-                        $recipient = $matches[2];
+                        $recipient = \trim($matches[2]);
                     }
                     if (empty($recipient)) {
                         unset($recipients[$key]);