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

Zend Mail Pop3 - Invalid header value detected #58

Open
michalbundyra opened this issue Jan 15, 2020 · 3 comments
Open

Zend Mail Pop3 - Invalid header value detected #58

michalbundyra opened this issue Jan 15, 2020 · 3 comments

Comments

@michalbundyra
Copy link
Member

This issue has been moved from the zendframework repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html


Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7655
User: @stmaxvl
Created On: 2015-12-28T12:01:52Z
Updated At: 2016-02-13T15:34:07Z
Body
I use Zend\Mail\Storage\Pop3 to get message.
ZF Version 2.5.1

Code:

$mail = new \Zend\Mail\Storage\Pop3(
array(
'host' => '...',
'user' => '...',
'password' => '...',
'ssl' => 'SSL'
));
$count = $mail->countMessages();
for($messageNum=1; $messageNum<=$count; $messageNum++){
$message = $mail->getMessage($messageNum);
}

Trace error:

Invalid header value detected#0 C:\xampp\htdocs\master4u\vendor\zendframework\zend-mail\src\Header\GenericHeader.php(35): Zend\Mail\Header\GenericHeader::splitHeaderLine('Subject: \xD0\x9E\xD1\x84\xD0\xBB...')
#1 C:\xampp\htdocs\master4u\vendor\zendframework\zend-mail\src\Headers.php(231): Zend\Mail\Header\GenericHeader::fromString('Subject: \xD0\x9E\xD1\x84\xD0\xBB...')
#2 C:\xampp\htdocs\master4u\vendor\zendframework\zend-mail\src\Headers.php(95): Zend\Mail\Headers->addHeaderLine('Subject: \xD0\x9E\xD1\x84\xD0\xBB...')
#3 C:\xampp\htdocs\master4u\vendor\zendframework\zend-mail\src\Storage\Part.php(108): Zend\Mail\Headers::fromString('X-Yandex-Folder...')
#4 C:\xampp\htdocs\master4u\vendor\zendframework\zend-mail\src\Storage\Message.php(54): Zend\Mail\Storage\Part->__construct(Array)
#5 C:\xampp\htdocs\master4u\vendor\zendframework\zend-mail\src\Storage\Pop3.php(65): Zend\Mail\Storage\Message->__construct(Array)
#6 C:\xampp\htdocs\master4u\module\PpModuleMailer\src\PpModuleMailer\Controller\ConsoleController.php(82): Zend\Mail\Storage\Pop3->getMessage(1)



Originally posted by @GeeH at zendframework/zend-mail#97

@michalbundyra
Copy link
Member Author

I have the same problem, I'm also using \Zend\Mail\Storage\Message.
Some of my incoming emails containing non ASCII characters in header values, especially in subject :(

I tried to disable the validation but I failed because the validation is hard wired and deep nested in the parse logic.

At the moment i've no idea how to solve this problem. Does anyone have an idea?


Originally posted by @nickel715 at zendframework/zend-mail#97 (comment)

@triproject
Copy link

triproject commented Jun 23, 2020

got the solution. but i think this must be done with new update of laminas/mail

`
$data = [];

	for ($index = 0; $index <= $mail->countMessages(); $index++)  {
		try {
			$message = $mail->getMessage($index);

			$data[] = [
				'id' => $index,
				'has_seen' => $message->hasFlag(Storage::FLAG_SEEN),
				'from' => trim(strip_tags($message->from)),
				'from_email' => $this->_getEmail($message->from),
				'subject' => $message->subject,
				'content' => Str::words($message->getContent(), 20),
				'date' => Carbon::parse($message->date)->format('Y-m-d H:i:s'),
				'date_differece' => Carbon::parse($message->date)->diffForHumans(),
				'mimeversion' => $message->mimeversion,
				'isMultipart' => $message->isMultipart(),
				'cc' => $message->cc ?? '',
				'contenttype' => $message->contenttype ?? '',
			];
		} catch (Exception $e) {
			
		}
	}

	return $data;

`

@parijke
Copy link

parijke commented Sep 16, 2020

I have the same issue using imap instead of pop3. The above is not a solution as it skips the mails who are "in error" according to laminas-mail

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

3 participants