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

Fix mail parsing in collector #7652

Conversation

cedric-anne
Copy link
Member

@cedric-anne cedric-anne commented Jul 10, 2020

Q A
Bug fix? yes/no
New feature? yes/no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #7643 , #7649

@cedric-anne cedric-anne self-assigned this Jul 10, 2020
@cedric-anne cedric-anne force-pushed the fix/9.5/fix-emails-without-reply-to branch 8 times, most recently from cea7c1e to 9b6c501 Compare July 13, 2020 10:27
@cedric-anne cedric-anne changed the title Handle emails having no 'reply-to' header; fixes #7643 Fix mail parsing in collector Jul 13, 2020
- Prevent exception on addresses parsing; fixes glpi-project#7643
- Correctly fetch additionnal headers that may be used in rules
- Fix exclusion of mailer-daemon/postmaster
- Prevent exception when "Content-Transfer-Encoding" is not set; fixes glpi-project#7649
@cedric-anne cedric-anne force-pushed the fix/9.5/fix-emails-without-reply-to branch from 9b6c501 to b280b4e Compare July 13, 2020 10:39
Comment on lines +1322 to +1325
foreach ($headers as $header) {
// is line with additional header?
$key = $header->getFieldName();
$value = $header->getFieldValue();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$key was a numeric key here, so following preg_match() calls were always returning false.

$req_field = $this->getRequesterField();
$h_requester = $message->getHeader($req_field)->getAddressList();
$requester = $h_requester->current()->getEmail();
$requester = $this->getRequesterEmail($message);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reply-to was always defined when using the imap extension (see #4554 (comment)), but now this header is not available if not set in the message.

$h_reply_to = $message->getHeader('reply_to')->getAddressList();
$reply_to = $h_reply_to->current();
$reply_to_addr = Toolbox::strtolower($reply_to->getEmail());
if (preg_match('/^(mailer-daemon|postmaster)@/i', $sender_email) === 1) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With imap extension, we were comparing $sender->mailbox, which was not containing the host (i.e. postmaster@domain.org was returning postmater).
Now, we have to deal with the full email address.

@@ -1996,10 +2014,9 @@ public function getDecodedContent(\Laminas\Mail\Storage\Part $part) {
case '7bit':
case '8bit':
case 'binary':
default:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In GLPI 9.4, we were returning verbatim content if no transfer encoding was defined. I put back this behaviour as it seems that emails sent by Outlook are not containing this header for text parts (see attached email from #7649).

@cedric-anne cedric-anne marked this pull request as ready for review July 13, 2020 11:15
@dtobal
Copy link

dtobal commented Jul 16, 2020

Hi @cedric-anne sorry, but I tried this fix (inc/mailcollector.class.php) and I still have Uncaught Exception Laminas\Mail\Storage\Exception\InvalidArgumentException: Header with Name to or to not found in /var/www/html/glpi/vendor/laminas/laminas-mail/src/Storage/Part.php at line 307. Am I missing some step? I am using Office365, IMAP, SSL, NOTLS (I dont understand why NOTLS because MS says it is IMAPS TLS), and NO VALIDATE CERT. After I did upload this mailcollector... I did my connector sync ONLY ONE TIME. After that... just this error.

@trasher
Copy link
Contributor

trasher commented Jul 16, 2020

@dtobal see #7682.

@cedric-anne
Copy link
Member Author

Hi @cedric-anne sorry, but I tried this fix (inc/mailcollector.class.php) and I still have Uncaught Exception Laminas\Mail\Storage\Exception\InvalidArgumentException: Header with Name to or to not found in /var/www/html/glpi/vendor/laminas/laminas-mail/src/Storage/Part.php at line 307. Am I missing some step? I am using Office365, IMAP, SSL, NOTLS (I dont understand why NOTLS because MS says it is IMAPS TLS), and NO VALIDATE CERT. After I did upload this mailcollector... I did my connector sync ONLY ONE TIME. After that... just this error.

This one should be fixed by #7694

@dtobal
Copy link

dtobal commented Jul 16, 2020

Hi @cedric-anne sorry, but I tried this fix (inc/mailcollector.class.php) and I still have Uncaught Exception Laminas\Mail\Storage\Exception\InvalidArgumentException: Header with Name to or to not found in /var/www/html/glpi/vendor/laminas/laminas-mail/src/Storage/Part.php at line 307. Am I missing some step? I am using Office365, IMAP, SSL, NOTLS (I dont understand why NOTLS because MS says it is IMAPS TLS), and NO VALIDATE CERT. After I did upload this mailcollector... I did my connector sync ONLY ONE TIME. After that... just this error.

This one should be fixed by #7694

100% worked! Thanks!

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