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

Handle missing 'to' email header #7694

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions inc/mailcollector.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1369,14 +1369,16 @@ function getHeaders(\Laminas\Mail\Storage\Message $message) {
$mail_details = [];

// Construct to and cc arrays
$h_tos = $message->getHeader('to');
$tos = [];
foreach ($h_tos->getAddressList() as $address) {
$mailto = Toolbox::strtolower($address->getEmail());
if ($mailto === $this->fields['name']) {
$to = $mailto;
if (isset($message->to)) {
$h_tos = $message->getHeader('to');
foreach ($h_tos->getAddressList() as $address) {
$mailto = Toolbox::strtolower($address->getEmail());
if ($mailto === $this->fields['name']) {
$to = $mailto;
}
$tos[] = $mailto;
}
$tos[] = $mailto;
}

$ccs = [];
Expand Down
28 changes: 28 additions & 0 deletions tests/emails-tests/12-missing-to.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Return-Path: [email protected]
Received: from 192.168.1.3 (LHLO mail.glpi-project.org) (192.168.1.3)
by mail.glpi-project.org with LMTP; Tue, 2 Apr 2019 14:43:12 +0200
(CEST)
Received: from mail.glpi-project.org (localhost [127.0.0.1])
by mail.glpi-project.org (Postfix) with ESMTP id 6F3457E80D1E
for <[email protected]>; Tue, 2 Apr 2019 14:43:12 +0200 (CEST)
Received: from localhost (localhost [127.0.0.1])
by mail.glpi-project.org (Postfix) with ESMTP id 645C77E80D1C
for <[email protected]>; Tue, 2 Apr 2019 14:43:12 +0200 (CEST)
Received: from mail.glpi-project.org ([127.0.0.1])
by localhost (mail.glpi-project.org [127.0.0.1]) (amavisd-new, port 10026)
with ESMTP id POJTfrC8TVrL for <[email protected]>;
Tue, 2 Apr 2019 14:43:12 +0200 (CEST)
Received: from mail.glpi-project.org (localhost [127.0.0.1])
by mail.glpi-project.org (Postfix) with ESMTP id 55AF37E80C20
for <[email protected]>; Tue, 2 Apr 2019 14:43:12 +0200 (CEST)
Date: Tue, 2 Apr 2019 14:43:12 +0200 (CEST)
From: Tech Ni Cian <[email protected]>
Cci: GLPI debug <[email protected]>
Message-ID: <2078889367.1658939.1554208992329.JavaMail.zimbra@glpi-project.org>
Subject: A message without to header
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit

This message was sent to multiple mailboxes using cci header.

5 changes: 3 additions & 2 deletions tests/imap/MailCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public function testCollect() {
$this->doConnect();
$this->collector->maxfetch_emails = 1000; // Be sure to fetch all mails from test suite
$msg = $this->collector->collect($this->mailgate_id);
$this->variable($msg)->isIdenticalTo('Number of messages: available=12, retrieved=12, refused=2, errors=1, blacklisted=0');
$this->variable($msg)->isIdenticalTo('Number of messages: available=13, retrieved=13, refused=2, errors=1, blacklisted=0');
$rejecteds = iterator_to_array($DB->request(['FROM' => \NotImportedEmail::getTable()]));

$this->array($rejecteds)->hasSize(2);
Expand Down Expand Up @@ -286,7 +286,7 @@ public function testCollect() {
]
]);

$this->integer(count($iterator))->isIdenticalTo(4);
$this->integer(count($iterator))->isIdenticalTo(5);
$names = [];
while ($data = $iterator->next()) {
$names[] = $data['name'];
Expand All @@ -297,6 +297,7 @@ public function testCollect() {
'Re: [GLPI #0001155] New ticket database issue',
'Ticket with observer',
'Re: [GLPI #0038927] Update - Issues with new Windows 10 machine',
'A message without to header',
];
$this->array($names)->isIdenticalTo($expected_names);

Expand Down