Skip to content

Commit

Permalink
Allow 'Received' hostnames without '.' chars #104
Browse files Browse the repository at this point in the history
  • Loading branch information
zbateson committed Feb 14, 2023
1 parent 996266b commit 16bd507
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
21 changes: 10 additions & 11 deletions src/Header/Consumer/Received/DomainConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@
* The parenthesized part normally (but not necessarily) following a name must
* "look like" a tcp-info section of an extended domain as defined by RFC5321.
* The validation is very purposefully very loose to be accommodating to many
* erroneous implementations. Strictly speaking, a domain part, if it exists,
* must start with an alphanumeric character. There must be at least one '.' in
* the domain part, followed by any number of more alphanumeric, '.', and '-'
* characters. The address part must be within square brackets, '[]'...
* although an address outside of square brackets could be matched by the domain
* matcher if it exists alone within the parentheses. The address, strictly
* speaking, is any number of '.', numbers, ':' and letters a-f. This allows it
* to match ipv6 addresses as well. In addition, the address may start with the
* string "ipv6", and may be followed by a port number as some implementations
* seem to do.
* erroneous implementations. The only restriction is the host part must
* contain two characters, the first being alphanumeric, followed by any number
* of more alphanumeric, '.', and '-' characters. The address part must be
* within square brackets, '[]'... although an address outside of square
* brackets could be matched by the domain matcher if it exists alone within the
* parentheses. The address is any number of '.', numbers, ':' and letters a-f.
* This allows it to match ipv6 addresses as well. In addition, the address may
* start with the string "ipv6", and may be followed by a port number as some
* implementations seem to do.
*
* Strings in parentheses not matching the aforementioned 'domain/address'
* pattern will be considered comments, and will be returned as a separate
Expand Down Expand Up @@ -67,7 +66,7 @@ protected function isEndToken(string $token) : bool
private function matchHostPart(string $value, ?string &$hostname, ?string &$address) : bool
{
$matches = [];
$pattern = '~^(\[(IPv[64])?(?P<addr1>[a-f\d\.\:]+)\])?\s*(helo=)?(?P<name>[a-z0-9\-]+\.[a-z0-9\-\.]+)?\s*(\[(IPv[64])?(?P<addr2>[a-f\d\.\:]+)\])?$~i';
$pattern = '~^(\[(IPv[64])?(?P<addr1>[a-f\d\.\:]+)\])?\s*(helo=)?(?P<name>[a-z0-9\-]+[a-z0-9\-\.]+)?\s*(\[(IPv[64])?(?P<addr2>[a-f\d\.\:]+)\])?$~i';
if (\preg_match($pattern, $value, $matches)) {
if (!empty($matches['name'])) {
$hostname = $matches['name'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public function testConsumeParts() : void
['hello ([2001:0db8:85a3:0000:0000:8a2e:0370:7334])', ['ehloName' => 'hello', 'address' => '2001:0db8:85a3:0000:0000:8a2e:0370:7334'], []],
['hello', ['ehloName' => 'hello'], []],
['hello (blah.blooh [1.2.3.4]) (TEST)', ['ehloName' => 'hello', 'hostname' => 'blah.blooh', 'address' => '1.2.3.4'], []],
['hello (TEST)', ['ehloName' => 'hello'], ['TEST']],
['(blah.blooh)', ['hostname' => 'blah.blooh'], []],
['(blah-blooh)', ['hostname' => 'blah-blooh'], []],
['hello ([1.2.3.4] blah.blooh)', ['ehloName' => 'hello', 'hostname' => 'blah.blooh', 'address' => '1.2.3.4'], []],
['hello ([1.2.3.4] helo=blah.blooh)', ['ehloName' => 'hello', 'hostname' => 'blah.blooh', 'address' => '1.2.3.4'], []],
['hello (helo=blah.blooh [1.2.3.4])', ['ehloName' => 'hello', 'hostname' => 'blah.blooh', 'address' => '1.2.3.4'], []],
['(negatron)', [], ['negatron']],
['(negatron)', ['hostname' => 'negatron'], []],
['(.negatron)', [], ['.negatron']],
];

foreach ($aTests as $test) {
Expand Down

0 comments on commit 16bd507

Please sign in to comment.