Skip to content
Snippets Groups Projects
Commit 8ed93067 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

rel #29345 : zend mail validator can throw exceptions on domain validation...

rel #29345 : zend mail validator can throw exceptions on domain validation failure, consider this as an invalid mail
parent e6d69ba2
Branches
Tags
No related merge requests found
- ticket #29345 : Correction d'un blocage possible de l'envoi des lettres d'information lorsqu'une erreur survient à la validation d'un mail
\ No newline at end of file
......@@ -16,7 +16,7 @@
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class ZendAfi_Mail extends Zend_Mail {
......@@ -24,15 +24,22 @@ class ZendAfi_Mail extends Zend_Mail {
parent::__construct($charset);
}
public function addTo($email, $name='') {
$validator = new Zend_Validate_EmailAddress();
$mails = array_filter(preg_split('/\s*[,;]\s*/', $email),
$validator = $this->_getValidator();
$mails = array_filter(
preg_split('/\s*[,;]\s*/', $email),
function($value) use ($validator) {
return $validator->isValid($value);
try {
return $validator->isValid($value);
} catch(Zend_Validate_Exception $e) {
return false;
}
});
foreach ($mails as $recipient)
parent::addTo($recipient, $name);
return $this;
}
......@@ -43,7 +50,7 @@ class ZendAfi_Mail extends Zend_Mail {
public function addBcc($email) {
$validator = new Zend_Validate_EmailAddress();
$validator = $this->_getValidator();
try {
if ($validator->isValid($email))
......@@ -54,34 +61,37 @@ class ZendAfi_Mail extends Zend_Mail {
return $this;
}
/**
* Sets the subject of the message
*
* @param string $subject
* @return Zend_Mail Provides fluent interface
* @throws Zend_Mail_Exception
*/
public function setSubject($subject)
{
if ($this->_subject === null) {
$subject = strtr($subject,"\r\n\t",'???');
$this->_subject = $subject;
$this->_storeHeader('Subject', $this->_subject);
} else {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('Subject set twice');
}
return $this;
}
public function setBodyText($txt, $charset = null, $encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE) {
parent::setBodyText($txt,'utf-8',Zend_Mime::ENCODING_8BIT);
protected function _getValidator() {
return new Zend_Validate_EmailAddress();
}
/**
* @param string $subject
* @return Zend_Mail Provides fluent interface
* @throws Zend_Mail_Exception
*/
public function setSubject($subject) {
if ($this->_subject === null) {
$subject = strtr($subject, "\r\n\t", '???');
$this->_subject = $subject;
$this->_storeHeader('Subject', $this->_subject);
return $this;
}
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('Subject set twice');
}
public function setBodyText($txt, $charset = null, $encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE) {
parent::setBodyText($txt, 'utf-8', Zend_Mime::ENCODING_8BIT);
return $this;
}
}
?>
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class ZendAfi_MailTest extends ModelTestCase {
/**
* @test
* @see http://forge.afi-sa.fr/issues/29345
*/
public function mailTerminatedByPlusShouldNotBeValid() {
$mail = (new ZendAfi_Mail())
->addTo('username@creutzwaldenergies-services.fr+');
$this->assertEmpty($mail->getRecipients());
}
/**
* @test
* @see http://forge.afi-sa.fr/issues/29345
*/
public function mailNotTerminatedByPlusShouldBeValid() {
$mail = (new ZendAfi_Mail())
->addTo('username@creutzwaldenergies-services.fr');
$this->assertNotEmpty($mail->getRecipients());
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment