Skip to content

Commit

Permalink
Handle message without subject in mail collector; fixes #7790
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne authored and trasher committed Aug 4, 2020
1 parent 408c463 commit 4e03028
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
6 changes: 5 additions & 1 deletion inc/mailcollector.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,11 @@ function buildTicket($uid, \Laminas\Mail\Storage\Message $message, $options = []
$tkt['_do_not_check_users_id'] = 1;
$body = $this->getBody($message);

$subject = $message->subject;
try {
$subject = $message->getHeader('subject')->getFieldValue();
} catch (Laminas\Mail\Storage\Exception\InvalidArgumentException $e) {
$subject = null;
}
$tkt['_message'] = $message;

if (!Toolbox::seems_utf8($body)) {
Expand Down
27 changes: 27 additions & 0 deletions tests/emails-tests/16-no-subject.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Return-Path: normal@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; Thu, 11 Jul 2019 14:36:19 +0200
(CEST)
Received: from mail.glpi-project.org (localhost [127.0.0.1])
by mail.glpi-project.org (Postfix) with ESMTP id E93F77E80CDC
for <unittests@glpi-project.org>; Thu, 11 Jul 2019 14:36:19 +0200 (CEST)
Received: from localhost (localhost [127.0.0.1])
by mail.glpi-project.org (Postfix) with ESMTP id DDBE07E80832
for <unittests@glpi-project.org>; Thu, 11 Jul 2019 14:36:19 +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 5TmiDey5TKGa for <unittest@glpi-project.org>;
Thu, 11 Jul 2019 14:36:19 +0200 (CEST)
Received: from mail.glpi-project.org (localhost [127.0.0.1])
by mail.glpi-project.org (Postfix) with ESMTP id CAB177E806B4
for <unittests@glpi-project.org>; Thu, 11 Jul 2019 14:36:19 +0200 (CEST)
Date: Thu, 11 Jul 2019 14:36:19 +0200 (CEST)
From: Normal User <normal@glpi-project.org>
To: GLPI debug <unittests@glpi-project.org>
Message-ID: <799153164.8345898.1562848579774.JavaMail.zimbra@glpi-project.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Mailer: Zimbra 8.0.9_GA_6191 (ZimbraWebClient - FF67 (Linux)/8.0.9_GA_6191)

This is a mail without subject.
3 changes: 2 additions & 1 deletion tests/imap/MailCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public function testCollect() {
]
]);

$this->integer(count($iterator))->isIdenticalTo(8);
$this->integer(count($iterator))->isIdenticalTo(9);
$names = [];
while ($data = $iterator->next()) {
$names[] = $data['name'];
Expand All @@ -336,6 +336,7 @@ public function testCollect() {
'проверка',
'тест2',
'Inlined image with no Content-Disposition',
'This is a mail without subject.', // No subject = name is set using ticket contents
];
$this->array($names)->isIdenticalTo($expected_names);

Expand Down

0 comments on commit 4e03028

Please sign in to comment.