Skip to content

Commit

Permalink
Handle missing 'to' email header
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne committed Jul 16, 2020
1 parent b38ee57 commit 222fc34
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
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: tech@glpi-project.org
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 <unittests@glpi-project.org>; 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 <unittests@glpi-project.org>; 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 <unittests@glpi-project.org>;
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 <unittests@glpi-project.org>; Tue, 2 Apr 2019 14:43:12 +0200 (CEST)
Date: Tue, 2 Apr 2019 14:43:12 +0200 (CEST)
From: Tech Ni Cian <tech@glpi-project.org>
Cci: GLPI debug <unittests@glpi-project.org>
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

0 comments on commit 222fc34

Please sign in to comment.