|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the ZBateson\MailMimeParser project. |
|
4
|
|
|
* |
|
5
|
|
|
* @license http://opensource.org/licenses/bsd-license.php BSD |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace ZBateson\MailMimeParser\Header\Consumer\Received; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Parses a so-called "extended-domain" (from and by) part of a Received header. |
|
12
|
|
|
* |
|
13
|
|
|
* Looks for and extracts the following fields from an extended-domain part: |
|
14
|
|
|
* Name, Hostname and Address. |
|
15
|
|
|
* |
|
16
|
|
|
* The Name part is always the portion of the extended-domain part existing on |
|
17
|
|
|
* its own, outside of the parenthesized hostname and address part. This is |
|
18
|
|
|
* true regardless of whether an address is used as the name, as its assumed to |
|
19
|
|
|
* be the string used to identify the server, whatever it may be. |
|
20
|
|
|
* |
|
21
|
|
|
* The parenthesized part normally (but not necessarily) following a name must |
|
22
|
|
|
* "look like" a tcp-info section of an extended domain as defined by RFC5321. |
|
23
|
|
|
* The validation is very purposefully very loose to be accommodating to many |
|
24
|
|
|
* erroneous implementations. The only restriction is the host part must |
|
25
|
|
|
* contain two characters, the first being alphanumeric, followed by any number |
|
26
|
|
|
* of more alphanumeric, '.', and '-' characters. The address part must be |
|
27
|
|
|
* within square brackets, '[]'... although an address outside of square |
|
28
|
|
|
* brackets could be matched by the domain matcher if it exists alone within the |
|
29
|
|
|
* parentheses. The address is any number of '.', numbers, ':' and letters a-f. |
|
30
|
|
|
* This allows it to match ipv6 addresses as well. In addition, the address may |
|
31
|
|
|
* start with the string "ipv6", and may be followed by a port number as some |
|
32
|
|
|
* implementations seem to do. |
|
33
|
|
|
* |
|
34
|
|
|
* Strings in parentheses not matching the aforementioned 'domain/address' |
|
35
|
|
|
* pattern will be considered comments, and will be returned as a separate |
|
36
|
|
|
* CommentPart. |
|
37
|
|
|
* |
|
38
|
|
|
* @see https://tools.ietf.org/html/rfc5321#section-4.4 |
|
39
|
|
|
* @see https://github.com/Te-k/pyreceived/blob/master/test.py |
|
40
|
|
|
* @author Zaahid Bateson |
|
41
|
|
|
* @author Mariusz Krzaczkowski |
|
42
|
|
|
*/ |
|
43
|
|
|
class DomainConsumerService extends GenericReceivedConsumerService |
|
44
|
|
|
{ |
|
45
|
|
|
/** |
|
46
|
|
|
* Overridden to return true if the passed token is a closing parenthesis. |
|
47
|
|
|
*/ |
|
48
|
|
|
protected function isEndToken(string $token) : bool |
|
49
|
|
|
{ |
|
50
|
7 |
|
if ($token === ')') { |
|
51
|
|
|
return true; |
|
52
|
7 |
|
} |
|
53
|
4 |
|
return parent::isEndToken($token); |
|
54
|
|
|
} |
|
55
|
7 |
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Creates a single ReceivedDomainPart out of matched parts. If an |
|
58
|
|
|
* unmatched parenthesized expression was found, it's returned as a |
|
59
|
|
|
* CommentPart. |
|
60
|
|
|
* |
|
61
|
|
|
* @param \ZBateson\MailMimeParser\Header\Part\HeaderPart[] $parts |
|
62
|
|
|
* @return \ZBateson\MailMimeParser\Header\Part\ReceivedDomainPart[]|\ZBateson\MailMimeParser\Header\Part\CommentPart[]|\ZBateson\MailMimeParser\Header\Part\HeaderPart[] |
|
63
|
4 |
|
*/ |
|
64
|
|
|
protected function processParts(array $parts) : array |
|
65
|
4 |
|
{ |
|
66
|
4 |
|
return [$this->partFactory->newReceivedDomainPart($this->partName, $parts)]; |
|
67
|
4 |
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|