Skip to content

Commit

Permalink
Merged pull request #87
Browse files Browse the repository at this point in the history
  • Loading branch information
derickr committed Sep 6, 2023
2 parents b7854b9 + fe0c4aa commit da14a9c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- Fixed tests.
- Fixed #87: Use filter_var(FILTER_VALIDATE_EMAIL) instead of homegrown
validation for email addresses.

1.9.4 - Wednesday 14 September 2022
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
15 changes: 5 additions & 10 deletions src/mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Expand Down Expand Up @@ -93,7 +93,7 @@
* address embedded in the
* ezcMailAddress object may only
* contain letters from the
* RETURN_PATH_CHARS set.
* function filter_var FILTER_VALIDATE_EMAIL.
* @property ezcMailOptions $options
* Options for generating mail. See {@link ezcMailOptions}.
*
Expand Down Expand Up @@ -130,11 +130,6 @@ class ezcMail extends ezcMailPart
*/
const BASE64 = "base64";

/**
* Characters allowed in the returnPath address
*/
const RETURN_PATH_CHARS = 'A-Za-z0-9_.@=/+{}#~\-\'';

/**
* Holds the options for this class.
*
Expand Down Expand Up @@ -187,9 +182,9 @@ public function __set( $name, $value )
{
throw new ezcBaseValueException( $name, $value, 'ezcMailAddress or null' );
}
if ( $value !== null && preg_replace( '([' . self::RETURN_PATH_CHARS . '])', '', $value->email ) != '' )
if ( $value !== null && !filter_var( $value->email, FILTER_VALIDATE_EMAIL ) )
{
throw new ezcBaseValueException( $name, $value->email, 'the characters \'' . self::RETURN_PATH_CHARS . '\'' );
throw new ezcBaseValueException( $name, $value->email, 'a valid email address or null' );
}
$this->properties[$name] = $value;
break;
Expand Down
7 changes: 6 additions & 1 deletion src/transports/mta/mta_transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
*/
class ezcMailMtaTransport implements ezcMailTransport
{
/**
* Characters allowed in the returnPath address
*/
const RETURN_PATH_CHARS = 'A-Za-z0-9_.@=/+{}#~\-\'';

/**
* Constructs a new ezcMailMtaTransport.
*/
Expand Down Expand Up @@ -68,7 +73,7 @@ public function send( ezcMail $mail )
$additionalParameters = "";
if ( isset( $mail->returnPath ) )
{
$sanitized = preg_replace( '([^' . ezcMail::RETURN_PATH_CHARS . '])', '', $mail->returnPath->email );
$sanitized = preg_replace( '([^' . self::RETURN_PATH_CHARS . '])', '', $mail->returnPath->email );
$additionalParameters = "-f{$sanitized}";
}
$success = mail( ezcMailTools::composeEmailAddresses( $mail->to ),
Expand Down
2 changes: 1 addition & 1 deletion tests/mail_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ public function testInvalidReturnPathChars()
}
catch ( ezcBaseValueException $e )
{
$this->assertEquals( "The value 'with [email protected]' that you were trying to assign to setting 'returnPath' is invalid. Allowed values are: the characters '" . ezcMail::RETURN_PATH_CHARS . "'.", $e->getMessage() );
$this->assertEquals( "The value 'with [email protected]' that you were trying to assign to setting 'returnPath' is invalid. Allowed values are: a valid email address or null.", $e->getMessage() );
}
}

Expand Down

0 comments on commit da14a9c

Please sign in to comment.