Skip to content
Permalink
Browse files

#403 - Use of EmailValidator for versions of PHP >= 5.3

  • Loading branch information...
egulias authored and fabpot committed Dec 24, 2013
1 parent 613354e commit 6776d293954416a9ee7df4d76f24cea6eb3370a9
Showing with 207 additions and 397 deletions.
  1. +2 −1 composer.json
  2. +6 −4 lib/classes/Swift/Mime/Attachment.php
  3. +4 −3 lib/classes/Swift/Mime/EmbeddedFile.php
  4. +0 −176 lib/classes/Swift/Mime/Grammar.php
  5. +23 −43 lib/classes/Swift/Mime/Headers/AbstractHeader.php
  6. +1 −3 lib/classes/Swift/Mime/Headers/DateHeader.php
  7. +14 −11 lib/classes/Swift/Mime/Headers/IdentificationHeader.php
  8. +15 −8 lib/classes/Swift/Mime/Headers/MailboxHeader.php
  9. +3 −4 lib/classes/Swift/Mime/Headers/ParameterizedHeader.php
  10. +14 −6 lib/classes/Swift/Mime/Headers/PathHeader.php
  11. +1 −3 lib/classes/Swift/Mime/Headers/UnstructuredHeader.php
  12. +5 −3 lib/classes/Swift/Mime/MimePart.php
  13. +14 −10 lib/classes/Swift/Mime/SimpleHeaderFactory.php
  14. +6 −4 lib/classes/Swift/Mime/SimpleMessage.php
  15. +14 −18 lib/classes/Swift/Mime/SimpleMimeEntity.php
  16. +0 −42 lib/classes/Swift/Validate.php
  17. +7 −7 lib/dependency_maps/mime_deps.php
  18. +6 −3 tests/acceptance/Swift/Mime/AttachmentAcceptanceTest.php
  19. +6 −4 tests/acceptance/Swift/Mime/EmbeddedFileAcceptanceTest.php
  20. +7 −5 tests/acceptance/Swift/Mime/MimePartAcceptanceTest.php
  21. +4 −2 tests/bug/Swift/Bug206Test.php
  22. +12 −10 tests/unit/Swift/Mime/AttachmentTest.php
  23. +3 −1 tests/unit/Swift/Mime/EmbeddedFileTest.php
  24. +1 −1 tests/unit/Swift/Mime/Headers/DateHeaderTest.php
  25. +3 −1 tests/unit/Swift/Mime/Headers/IdentificationHeaderTest.php
  26. +4 −2 tests/unit/Swift/Mime/Headers/MailboxHeaderTest.php
  27. +1 −3 tests/unit/Swift/Mime/Headers/ParameterizedHeaderTest.php
  28. +3 −1 tests/unit/Swift/Mime/Headers/PathHeaderTest.php
  29. +1 −1 tests/unit/Swift/Mime/Headers/UnstructuredHeaderTest.php
  30. +12 −10 tests/unit/Swift/Mime/MimePartTest.php
  31. +3 −1 tests/unit/Swift/Mime/SimpleHeaderFactoryTest.php
  32. +3 −1 tests/unit/Swift/Mime/SimpleMessageTest.php
  33. +3 −1 tests/unit/Swift/Mime/SimpleMimeEntityTest.php
  34. +6 −4 tests/unit/Swift/Signers/DKIMSignerTest.php
@@ -15,7 +15,8 @@
}
],
"require": {
"php": ">=5.3.3"
"php": ">=5.3.3",
"egulias/email-validator": "~1.2"
},
"require-dev": {
"mockery/mockery": "~0.9.1"
@@ -8,6 +8,8 @@
* file that was distributed with this source code.
*/
use Egulias\EmailValidator\EmailValidator;
/**
* An attachment, in a multipart message.
*
@@ -24,12 +26,12 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
* @param Swift_Mime_HeaderSet $headers
* @param Swift_Mime_ContentEncoder $encoder
* @param Swift_KeyCache $cache
* @param Swift_Mime_Grammar $grammar
* @param array $mimeTypes optional
* @param EmailValidator $emailValidator
* @param array $mimeTypes
*/
public function __construct(Swift_Mime_HeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_Mime_Grammar $grammar, $mimeTypes = array())
public function __construct(Swift_Mime_HeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, EmailValidator $emailValidator, $mimeTypes = array())
{
parent::__construct($headers, $encoder, $cache, $grammar);
parent::__construct($headers, $encoder, $cache, $emailValidator);
$this->setDisposition('attachment');
$this->setContentType('application/octet-stream');
$this->_mimeTypes = $mimeTypes;
@@ -8,6 +8,8 @@
* file that was distributed with this source code.
*/
use Egulias\EmailValidator\EmailValidator;
/**
* An embedded file, in a multipart message.
*
@@ -21,12 +23,11 @@ class Swift_Mime_EmbeddedFile extends Swift_Mime_Attachment
* @param Swift_Mime_HeaderSet $headers
* @param Swift_Mime_ContentEncoder $encoder
* @param Swift_KeyCache $cache
* @param Swift_Mime_Grammar $grammar
* @param array $mimeTypes optional
*/
public function __construct(Swift_Mime_HeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_Mime_Grammar $grammar, $mimeTypes = array())
public function __construct(Swift_Mime_HeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, EmailValidator $emailValidator, $mimeTypes = array())
{
parent::__construct($headers, $encoder, $cache, $grammar, $mimeTypes);
parent::__construct($headers, $encoder, $cache, $emailValidator, $mimeTypes);
$this->setDisposition('inline');
$this->setId($this->getId());
}

This file was deleted.

@@ -15,20 +15,15 @@
*/
abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
{
const PHRASE_PATTERN = '(?:(?:(?:(?:(?:(?:(?:[ \t]*(?:\r\n))?[ \t])?(\((?:(?:(?:[ \t]*(?:\r\n))?[ \t])|(?:(?:[\x01-\x08\x0B\x0C\x0E-\x19\x7F]|[\x21-\x27\x2A-\x5B\x5D-\x7E])|(?:\\[\x00-\x08\x0B\x0C\x0E-\x7F])|(?1)))*(?:(?:[ \t]*(?:\r\n))?[ \t])?\)))*(?:(?:(?:(?:[ \t]*(?:\r\n))?[ \t])?(\((?:(?:(?:[ \t]*(?:\r\n))?[ \t])|(?:(?:[\x01-\x08\x0B\x0C\x0E-\x19\x7F]|[\x21-\x27\x2A-\x5B\x5D-\x7E])|(?:\\[\x00-\x08\x0B\x0C\x0E-\x7F])|(?1)))*(?:(?:[ \t]*(?:\r\n))?[ \t])?\)))|(?:(?:[ \t]*(?:\r\n))?[ \t])))?[a-zA-Z0-9!#\$%&\'\*\+\-\/=\?\^_`\{\}\|~]+(?:(?:(?:(?:[ \t]*(?:\r\n))?[ \t])?(\((?:(?:(?:[ \t]*(?:\r\n))?[ \t])|(?:(?:[\x01-\x08\x0B\x0C\x0E-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x5B\x5D-\x7E])|(?:\\[\x00-\x08\x0B\x0C\x0E-\x7F])|(?1)))*(?:(?:[ \t]*(?:\r\n))?[ \t])?\)))*(?:(?:(?:(?:[ \t]*(?:\r\n))?[ \t])?(\((?:(?:(?:[ \t]*(?:\r\n))?[ \t])|(?:(?:[\x01-\x08\x0B\x0C\x0E-\x19\x7F]|[\x21-\x27\x2A-\x5B\x5D-\x7E])|(?:\\[\x00-\x08\x0B\x0C\x0E-\x7F])|(?1)))*(?:(?:[ \t]*(?:\r\n))?[ \t])?\)))|(?:(?:[ \t]*(?:\r\n))?[ \t])))?))+?)';
/**
* The name of this Header.
*
* @var string
*/
private $_name;
/**
* The Grammar used for this Header.
*
* @var Swift_Mime_Grammar
*/
private $_grammar;
/**
* The Encoder used to encode this Header.
*
@@ -64,16 +59,6 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
*/
private $_cachedValue = null;
/**
* Creates a new Header.
*
* @param Swift_Mime_Grammar $grammar
*/
public function __construct(Swift_Mime_Grammar $grammar)
{
$this->setGrammar($grammar);
}
/**
* Set the character set used in this Header.
*
@@ -143,27 +128,6 @@ public function getEncoder()
return $this->_encoder;
}
/**
* Set the grammar used for the header.
*
* @param Swift_Mime_Grammar $grammar
*/
public function setGrammar(Swift_Mime_Grammar $grammar)
{
$this->_grammar = $grammar;
$this->setCachedValue(null);
}
/**
* Get the grammar used for this Header.
*
* @return Swift_Mime_Grammar
*/
public function getGrammar()
{
return $this->_grammar;
}
/**
* Get the name of this header (e.g. charset).
*
@@ -247,13 +211,12 @@ protected function createPhrase(Swift_Mime_Header $header, $string, $charset, Sw
// Treat token as exactly what was given
$phraseStr = $string;
// If it's not valid
if (!preg_match('/^'.$this->getGrammar()->getDefinition('phrase').'$/D', $phraseStr)) {
if (!preg_match('/^'.self::PHRASE_PATTERN.'$/D', $phraseStr)) {
// .. but it is just ascii text, try escaping some characters
// and make it a quoted-string
if (preg_match('/^'.$this->getGrammar()->getDefinition('text').'*$/D', $phraseStr)) {
$phraseStr = $this->getGrammar()->escapeSpecials(
$phraseStr, array('"'), $this->getGrammar()->getSpecials()
);
if (preg_match('/^[\x00-\x08\x0B\x0C\x0E-\x7F]*$/D', $phraseStr)) {
$phraseStr = $this->escapeSpecials($phraseStr, array('"'));
$phraseStr = '"'.$phraseStr.'"';
} else {
// ... otherwise it needs encoding
@@ -270,6 +233,23 @@ protected function createPhrase(Swift_Mime_Header $header, $string, $charset, Sw
return $phraseStr;
}
/**
* Escape special characters in a string (convert to quoted-pairs).
*
* @param string $token
* @param string[] $include additional chars to escape
*
* @return string
*/
private function escapeSpecials($token, $include = array())
{
foreach (array_merge(array('\\'), $include) as $char) {
$token = str_replace($char, '\\'.$char, $token);
}
return $token;
}
/**
* Encode needed word tokens within a string of input.
*
@@ -33,12 +33,10 @@ class Swift_Mime_Headers_DateHeader extends Swift_Mime_Headers_AbstractHeader
* </code>
*
* @param string $name of Header
* @param Swift_Mime_Grammar $grammar
*/
public function __construct($name, Swift_Mime_Grammar $grammar)
public function __construct($name)
{
$this->setFieldName($name);
parent::__construct($grammar);
}
/**

0 comments on commit 6776d29

Please sign in to comment.
You can’t perform that action at this time.