Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReceivedHeader: incorrectly parse #183

Closed
mariuszkrzaczkowski opened this issue Nov 29, 2021 · 7 comments
Closed

ReceivedHeader: incorrectly parse #183

mariuszkrzaczkowski opened this issue Nov 29, 2021 · 7 comments

Comments

@mariuszkrzaczkowski
Copy link
Contributor

mariuszkrzaczkowski commented Nov 29, 2021

I found a strange bug, the problem is probably in the word 'id'

My code:

$message = \ZBateson\MailMimeParser\Message::from($contents, false);
foreach ($message->getAllHeadersByName('Received') as $received) {
	echo 'FromName: ' . $received->getFromName() . PHP_EOL;
	echo 'FromHostname: ' . $received->getFromHostname() . PHP_EOL;
	echo 'FromAddress: ' . $received->getFromAddress() . PHP_EOL;
	echo 'ByName: ' . $received->getByName() . PHP_EOL;
	echo 'ByHostname: ' . $received->getByHostname() . PHP_EOL;
	echo 'ByAddress: ' . $received->getByAddress() . PHP_EOL;
	echo 'with: ' . $received->getValueFor('with') . PHP_EOL;
	echo 'getComments: ' . implode(' | ', $received->getComments()) . '<hr>';
}

Example 1 (working properly)
Code:

$contents = 'Received: from mail.uiii.ac.idd ([111.222.333.444])
by mail.yetiforce.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
(Exim 4.94.2)
(envelope-from <noreply@mail.uiii.ac.idd>)
id 1mrMVK-00079p-W2
for m.krzaczkowski@yetiforce.com; Sun, 28 Nov 2021 16:54:15 +0100';

Response:

FromName: mail.uiii.ac.idd
FromHostname: 
FromAddress: 111.222.333.444
ByName: 
ByHostname: 
ByAddress: 
with: 
getComments: 

Example 1 (bug)
Code:

$contents = 'Received: from mail.uiii.ac.id ([111.222.333.444])
by mail.yetiforce.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
(Exim 4.94.2)
(envelope-from <noreply@mail.uiii.ac.id>)
id 1mrMVK-00079p-W2
for m.krzaczkowski@yetiforce.com; Sun, 28 Nov 2021 16:54:15 +0100';

Response:

FromName: mail.uiii.ac.
FromHostname: 
FromAddress: 
ByName: 
ByHostname: 
ByAddress: 
with: 
getComments: [111.222.333.444]

difference: mail.uiii.ac.idd VS mail.uiii.ac.id

@zbateson
Copy link
Owner

Aah, it's because there's a section called 'id' so it starts a sub-consumer at that point. Should be an easy enough fix to the regex here:

$pattern = '/^\s*(' . preg_quote($this->getPartName(), '/') . ')\s*$/i';

In most cases the spaces before/after aren't optional except for 'from' which I think is required and always comes at the start but would have to refresh my memory on it. So it might make more sense to have a 'FromReceivedConsumer' that uses \s*(from)\s+ and the rest have \s+(token)\s+.

Lastly some better testing needs to be added.

Thanks for reporting, @mariuszkrzaczkowski

@mariuszkrzaczkowski
Copy link
Contributor Author

some solution ?? it blocks my job

@zbateson
Copy link
Owner

zbateson commented Dec 1, 2021

some solution ?? it blocks my job

Feel free to submit a PR with a fix.

@mariuszkrzaczkowski
Copy link
Contributor Author

I have no idea how to fix it and where

@mariuszkrzaczkowski
Copy link
Contributor Author

if I knew it, I would have created PR a long time ago

@mariuszkrzaczkowski
Copy link
Contributor Author

In most cases the spaces before/after aren't optional except for 'from' which I think is required and always comes at the start but would have to refresh my memory on it. So it might make more sense to have a 'FromReceivedConsumer' that uses \s*(from)\s+ and the rest have \s+(token)\s+.

I tried what you wrote but it didn't work

zbateson added a commit that referenced this issue Jan 24, 2022
@zbateson
Copy link
Owner

Fixed in 2.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants