comments are not allowed in IDLeft for message-id

This commit is contained in:
Eduardo Gulias Davis
2021-02-28 17:02:00 +01:00
parent 8fb7a88965
commit b03e9c935f
6 changed files with 49 additions and 11 deletions
+2 -2
View File
@@ -5,7 +5,7 @@ namespace Egulias\EmailValidator;
use Egulias\EmailValidator\Parser;
use Egulias\EmailValidator\EmailLexer;
use Egulias\EmailValidator\Result\Result;
use Egulias\EmailValidator\Parser\LocalPart;
use Egulias\EmailValidator\Parser\IDLeftPart;
use Egulias\EmailValidator\Parser\IDRightPart;
use Egulias\EmailValidator\Result\ValidEmail;
use Egulias\EmailValidator\Result\InvalidEmail;
@@ -61,7 +61,7 @@ class MessageIDParser extends Parser
private function processIDLeft() : Result
{
$localPartParser = new LocalPart($this->lexer);
$localPartParser = new IDLeftPart($this->lexer);
$localPartResult = $localPartParser->parse();
$this->idLeft = $localPartParser->localPart();
$this->warnings = array_merge($localPartParser->getWarnings(), $this->warnings);
-8
View File
@@ -133,14 +133,6 @@ class DomainPart extends PartParser
return new ValidEmail();
}
/**
* @return string
*/
public function getDomainPart()
{
return $this->domainPart;
}
protected function parseComments(): Result
{
$commentParser = new Comment($this->lexer, new DomainComment());
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace Egulias\EmailValidator\Parser;
use Egulias\EmailValidator\Result\Result;
use Egulias\EmailValidator\Parser\LocalPart;
use Egulias\EmailValidator\Result\InvalidEmail;
use Egulias\EmailValidator\Result\Reason\CommentsInIDRight;
class IDLeftPart extends LocalPart
{
protected function parseComments(): Result
{
return new InvalidEmail(new CommentsInIDRight(), $this->lexer->token['value']);
}
}
+1 -1
View File
@@ -133,7 +133,7 @@ class LocalPart extends PartParser
return $parseAgain;
}
private function parseComments(): Result
protected function parseComments(): Result
{
$commentParser = new Comment($this->lexer, new LocalComment());
$result = $commentParser->parse();
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace Egulias\EmailValidator\Result\Reason;
class CommentsInIDRight implements Reason
{
public function code() : int
{
return 400;
}
public function description() : string
{
return 'Comments are not allowed in IDRight for message-id';
}
}
@@ -45,6 +45,20 @@ class MessageIDValidationTest extends TestCase
['example@with space'],
['example@iana.'],
['example@ia\na.'],
/**
* RFC 2822, section 3.6.4, Page 25
* Since the msg-id has
* a similar syntax to angle-addr (identical except that comments and
* folding white space are not allowed), a good method is to put the
* domain name (or a domain literal IP address) of the host on which the
* message identifier was created on the right hand side of the "@", and
* put a combination of the current absolute date and time along with
* some other currently unique (perhaps sequential) identifier available
* on the system (for example, a process id number) on the left hand
* side.
*/
['example(comment)@example.com'],
["\r\nFWS@example.com"]
];
}