Revert "0012292: check and show invalid email addresses before sending mail"
authorPhilipp Schüle <p.schuele@metaways.de>
Thu, 10 Nov 2016 13:54:17 +0000 (14:54 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 10 Nov 2016 13:54:17 +0000 (14:54 +0100)
This reverts commit f1d894ba5433a1b4811331b0b53c369db23a3196.

tests/tine20/Felamimail/Frontend/JsonTest.php
tine20/Felamimail/Controller/Message/Send.php
tine20/Felamimail/Message.php
tine20/Felamimail/Model/Message.php
tine20/Tinebase/Mail.php

index 9a9995c..b491d58 100644 (file)
@@ -137,9 +137,6 @@ class Felamimail_Frontend_JsonTest extends TestCase
         
         // get (or create) test accout
         $this->_account = Felamimail_Controller_Account::getInstance()->search()->getFirstRecord();
-        if ($this->_account === null) {
-            $this->markTestSkipped('no account found');
-        }
         $this->_oldSieveVacationActiveState = $this->_account->sieve_vacation_active;
         try {
             $this->_oldSieveData = new Felamimail_Sieve_Backend_Sql($this->_account);
@@ -568,41 +565,21 @@ class Felamimail_Frontend_JsonTest extends TestCase
     /**
      * test send message to invalid recipient
      */
-    public function testSendMessageToInvalidRecipient($invalidEmail = null, $toField = 'to', $expectedExceptionMessage = 'Recipient address rejected')
+    public function testSendMessageToInvalidRecipient()
     {
         $messageToSend = $this->_getMessageData($this->_account->email);
-        if ($invalidEmail === null) {
-            $invalidEmail = 'invaliduser@' . $this->_mailDomain;
-        }
-        if ($toField !== 'to') {
-            $messageToSend['to'] = array(Tinebase_Core::getUser()->accountEmailAddress);
-        }
-        $messageToSend[$toField] = array($invalidEmail);
-
-        $translation = Tinebase_Translation::getTranslation('Felamimail');
-
+        $invalidEmail = 'invaliduser@' . $this->_mailDomain;
+        $messageToSend['to'] = array($invalidEmail);
+        
         try {
-            $this->_json->saveMessage($messageToSend);
+            $returned = $this->_json->saveMessage($messageToSend);
             $this->fail('Tinebase_Exception_SystemGeneric expected');
         } catch (Tinebase_Exception_SystemGeneric $tesg) {
-            $this->assertContains('<' . $invalidEmail . '>: ' . $translation->_($expectedExceptionMessage), $tesg->getMessage(),
+            $this->assertContains('550 5.1.1 <' . $invalidEmail . '>: Recipient address rejected', $tesg->getMessage(),
                 'exception message did not match: ' . $tesg->getMessage());
         }
     }
-
-    /**
-     * test send message to invalid recipients (invalid email addresses)
-     *
-     * @see 0012292: check and show invalid email addresses before sending mail
-     */
-    public function testSendMessageWithInvalidEmails()
-    {
-        $this->testSendMessageToInvalidRecipient('memyselfandi.de', 'to', 'Invalid address format');
-        $this->testSendMessageToInvalidRecipient('mymail@ ' . $this->_mailDomain, 'cc', 'Invalid address format');
-        $this->testSendMessageToInvalidRecipient('mymail\@' . $this->_mailDomain, 'bcc', 'Invalid address format');
-        $this->testSendMessageToInvalidRecipient('my@mail@' . $this->_mailDomain, 'bcc', 'Invalid address format');
-    }
-
+    
     /**
      * try to get a message from imap server (with complete body, attachments, etc)
      *
index ff844ff..d7a3861 100644 (file)
@@ -80,14 +80,9 @@ class Felamimail_Controller_Message_Send extends Felamimail_Controller_Message
         } catch (Exception $e) {
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not send message: ' . $e);
             $translation = Tinebase_Translation::getTranslation('Felamimail');
-            if (preg_match('/^501 5\.1\.3/', $e->getMessage())) {
-                $messageText = $translation->_('Bad recipient address syntax');
-            } else if (preg_match('/^550 5\.1\.1 <(.*?)>/', $e->getMessage(), $match)) {
-                $messageText = '<' . $match[1] . '>: ' . $translation->_('Recipient address rejected');
-            } else {
-                $messageText = $e->getMessage();
-            }
-            $tesg = $this->_getErrorException($messageText);
+            $message = sprintf($translation->_('Error: %s'), $e->getMessage());
+            $tesg = new Tinebase_Exception_SystemGeneric($message);
+            $tesg->setTitle($translation->_('Could not send message'));
             throw $tesg;
         }
         
@@ -442,58 +437,34 @@ class Felamimail_Controller_Message_Send extends Felamimail_Controller_Message
     {
         $nonPrivateRecipients = array();
         $punycodeConverter = $this->getPunycodeConverter();
-        $invalidEmailAddresses = array();
         
         foreach (array('to', 'cc', 'bcc') as $type) {
             if (isset($_message->{$type})) {
                 foreach((array) $_message->{$type} as $address) {
-
-                    $punyCodedAddress = $punycodeConverter->encode($address);
-
-                    if (! preg_match(Tinebase_Mail::EMAIL_ADDRESS_REGEXP, $punyCodedAddress)) {
-                        $invalidEmailAddresses[] = $address;
-                        continue;
-                    }
-
-                    if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::'
-                        . __LINE__ . ' Add ' . $type . ' address: ' . $punyCodedAddress);
+                    
+                    $address = $punycodeConverter->encode($address);
+                    
+                    if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Add ' . $type . ' address: ' . $address);
                     
                     switch($type) {
                         case 'to':
-                            $_mail->addTo($punyCodedAddress);
-                            $nonPrivateRecipients[] = $punyCodedAddress;
+                            $_mail->addTo($address);
+                            $nonPrivateRecipients[] = $address;
                             break;
                         case 'cc':
-                            $_mail->addCc($punyCodedAddress);
-                            $nonPrivateRecipients[] = $punyCodedAddress;
+                            $_mail->addCc($address);
+                            $nonPrivateRecipients[] = $address;
                             break;
                         case 'bcc':
-                            $_mail->addBcc($punyCodedAddress);
+                            $_mail->addBcc($address);
                             break;
                     }
                 }
             }
         }
-
-        if (count($invalidEmailAddresses) > 0) {
-            $translation = Tinebase_Translation::getTranslation('Felamimail');
-            $messageText = '<' . implode(',', $invalidEmailAddresses) . '>: ' . $translation->_('Invalid address format');
-            $tesg = $this->_getErrorException($messageText);
-            throw $tesg;
-        }
         
         return $nonPrivateRecipients;
     }
-
-    protected function _getErrorException($messageText)
-    {
-        $translation = Tinebase_Translation::getTranslation('Felamimail');
-        $message = sprintf($translation->_('Error: %s'), $messageText);
-        $tesg = new Tinebase_Exception_SystemGeneric($message);
-        $tesg->setTitle($translation->_('Could not send message'));
-
-        return $tesg;
-    }
     
     /**
      * set headers in mail to be sent
index 8806be7..8d1ef33 100644 (file)
@@ -241,7 +241,7 @@ class Felamimail_Message extends Zend_Mail_Message
         // add anchor to email addresses (remove mailto hrefs first)
         $mailtoPattern = '/<a[="a-z\-0-9 ]*href="mailto:([a-z0-9_\+-\.]+@[a-z0-9-\.]+\.[a-z]{2,4})"[^>]*>.*<\/a>/iU';
         $result = preg_replace($mailtoPattern, "\\1", $_content);
-        $emailRegex = Tinebase_Mail::EMAIL_ADDRESS_CONTAINED_REGEXP;
+        $emailRegex = Tinebase_Mail::EMAIL_ADDRESS_REGEXP;
         // don't match emails with '=' as used in subscription uris (?email=blabla@aha.com)
         $emailRegex = str_replace('/(', '/^=(', $emailRegex);
         $result = preg_replace($emailRegex, "<a href=\"#\" id=\"123:\\1\" class=\"tinebase-email-link\">\\1</a>", $result);
index 198cde4..7b285d4 100644 (file)
@@ -676,6 +676,21 @@ class Felamimail_Model_Message extends Tinebase_Record_Abstract
                         $recipients[] = $addresses;
                     }
                 }
+                
+                foreach ($recipients as $key => &$recipient) {
+                    // get address 
+                    // @todo get name here
+                    //<*([a-zA-Z@_\-0-9\.]+)>*/
+                    if (preg_match(Tinebase_Mail::EMAIL_ADDRESS_REGEXP, $recipient, $matches) > 0) {
+                        $recipient = $matches[1];
+                    }
+                    if (empty($recipient)) {
+                        unset($recipients[$key]);
+                    }
+                }
+
+                //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($recipients, true));
+                
                 $recordData[$field] = array_unique($recipients);
             }
         }
index 7dbb4d3..f5dd02d 100644 (file)
@@ -20,13 +20,8 @@ class Tinebase_Mail extends Zend_Mail
     /**
     * email address regexp
     */
-    const EMAIL_ADDRESS_REGEXP = '/^([a-z0-9_\+-\.]+@[a-z0-9-\.]+\.[a-z]{2,63})$/i';
-
-    /**
-     * email address regexp (which might be contained in a longer text)
-     */
-    const EMAIL_ADDRESS_CONTAINED_REGEXP = '/([a-z0-9_\+-\.]+@[a-z0-9-\.]+\.[a-z]{2,63})/i';
-
+    const EMAIL_ADDRESS_REGEXP = '/([a-z0-9_\+-\.]+@[a-z0-9-\.]+\.[a-z]{2,63})/i';
+    
     /**
      * Sender: address
      * @var string