mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-24 10:21:32 +01:00
swiftmailer
This commit is contained in:
@@ -8,6 +8,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
use Egulias\EmailValidator\Validation\RFCValidation;
|
||||
|
||||
/**
|
||||
* A Path Header in Swift Mailer, such a Return-Path.
|
||||
*
|
||||
@@ -20,18 +23,25 @@ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_address;
|
||||
private $address;
|
||||
|
||||
/**
|
||||
* The strict EmailValidator.
|
||||
*
|
||||
* @var EmailValidator
|
||||
*/
|
||||
private $emailValidator;
|
||||
|
||||
/**
|
||||
* Creates a new PathHeader with the given $name.
|
||||
*
|
||||
* @param string $name
|
||||
* @param Swift_Mime_Grammar $grammar
|
||||
* @param string $name
|
||||
* @param EmailValidator $emailValidator
|
||||
*/
|
||||
public function __construct($name, Swift_Mime_Grammar $grammar)
|
||||
public function __construct($name, EmailValidator $emailValidator)
|
||||
{
|
||||
$this->setFieldName($name);
|
||||
parent::__construct($grammar);
|
||||
$this->emailValidator = $emailValidator;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,13 +90,13 @@ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*/
|
||||
public function setAddress($address)
|
||||
{
|
||||
if (is_null($address)) {
|
||||
$this->_address = null;
|
||||
if (null === $address) {
|
||||
$this->address = null;
|
||||
} elseif ('' == $address) {
|
||||
$this->_address = '';
|
||||
$this->address = '';
|
||||
} else {
|
||||
$this->_assertValidAddress($address);
|
||||
$this->_address = $address;
|
||||
$this->assertValidAddress($address);
|
||||
$this->address = $address;
|
||||
}
|
||||
$this->setCachedValue(null);
|
||||
}
|
||||
@@ -100,7 +110,7 @@ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*/
|
||||
public function getAddress()
|
||||
{
|
||||
return $this->_address;
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,8 +126,8 @@ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
public function getFieldBody()
|
||||
{
|
||||
if (!$this->getCachedValue()) {
|
||||
if (isset($this->_address)) {
|
||||
$this->setCachedValue('<'.$this->_address.'>');
|
||||
if (isset($this->address)) {
|
||||
$this->setCachedValue('<'.$this->address.'>');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,13 +141,12 @@ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*
|
||||
* @throws Swift_RfcComplianceException If address is invalid
|
||||
*/
|
||||
private function _assertValidAddress($address)
|
||||
private function assertValidAddress($address)
|
||||
{
|
||||
if (!preg_match('/^'.$this->getGrammar()->getDefinition('addr-spec').'$/D',
|
||||
$address)) {
|
||||
if (!$this->emailValidator->isValid($address, new RFCValidation())) {
|
||||
throw new Swift_RfcComplianceException(
|
||||
'Address set in PathHeader does not comply with addr-spec of RFC 2822.'
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user