Skip to content

Commit

Permalink
feat(mail collector): add 'TO' as observer
Browse files Browse the repository at this point in the history
  • Loading branch information
Rom1-B authored and trasher committed Nov 18, 2024
1 parent a02669e commit 84e7dbb
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@
*/

$migration->addField('glpi_mailcollectors', 'create_user_from_email', 'bool', ['value' => 0]);
$migration->addField('glpi_mailcollectors', 'add_to_to_observer', 'bool', ['value' => 1]);
1 change: 1 addition & 0 deletions install/mysql/glpi-empty.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4265,6 +4265,7 @@ CREATE TABLE `glpi_mailcollectors` (
`use_mail_date` tinyint NOT NULL DEFAULT '0',
`date_creation` timestamp NULL DEFAULT NULL,
`requester_field` int NOT NULL DEFAULT '0',
`add_to_to_observer` tinyint NOT NULL DEFAULT '1',
`add_cc_to_observer` tinyint NOT NULL DEFAULT '0',
`collect_only_unread` tinyint NOT NULL DEFAULT '0',
`create_user_from_email` tinyint NOT NULL DEFAULT '0',
Expand Down
2 changes: 1 addition & 1 deletion src/MailCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ public function buildTicket($uid, \Laminas\Mail\Storage\Message $message, $optio
}

$tos = $headers['tos'];
if (is_array($tos) && count($tos)) {
if (is_array($tos) && count($tos) && $this->getField("add_to_to_observer")) {
foreach ($tos as $to) {
if (
$to != $requester
Expand Down
1 change: 1 addition & 0 deletions templates/pages/setup/mailcollector/setup_form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
(constant('MailCollector::REQUESTER_FIELD_FROM')): __('No'),
(constant('MailCollector::REQUESTER_FIELD_REPLY_TO')): __('Yes'),
}, __('Use Reply-To as requester (when available)')) }}
{{ fields.dropdownYesNo('add_to_to_observer', item.fields['add_to_to_observer'], __('Add TO users as observer')) }}
{{ fields.dropdownYesNo('add_cc_to_observer', item.fields['add_cc_to_observer'], __('Add CC users as observer')) }}
{{ fields.dropdownYesNo('collect_only_unread', item.fields['collect_only_unread'], __('Collect only unread mail')) }}
{% set create_user_helper %}
Expand Down
32 changes: 32 additions & 0 deletions tests/emails-tests/44-multiple-to.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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]>
To: GLPI debug <[email protected]>, Normal User <[email protected]>
Message-ID: <2078889367.1658939.1554208992329.JavaMail.zimbra@glpi-project.org>
Subject: Ticket with multiple to
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Mailer: Zimbra 8.0.9_GA_6191 (ZimbraWebClient - FF66 (Linux)/8.0.9_GA_6191)
Thread-Topic: Ticket with multiple to
Thread-Index: OOKl6v3Lu6HeDTdJe0OrUl01ERm/dw==

This ticket have multiple to

Best regards,
12 changes: 10 additions & 2 deletions tests/imap/MailCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function testGetEmpty()
'use_mail_date' => '',
'date_creation' => '',
'requester_field' => '',
'add_to_to_observer' => '',
'add_cc_to_observer' => '',
'collect_only_unread' => '',
'create_user_from_email' => '',
Expand Down Expand Up @@ -597,6 +598,7 @@ private function doConnect()
'server_port' => 143,
'server_ssl' => '',
'server_cert' => '/novalidate-cert',
'add_to_to_observer' => 1,
'add_cc_to_observer' => 1,
'collect_only_unread' => 1,
'requester_field' => \MailCollector::REQUESTER_FIELD_REPLY_TO,
Expand Down Expand Up @@ -738,6 +740,7 @@ function () use (&$msg) {
'Ticket with observer',
'Re: [GLPI #0038927] Update - Issues with new Windows 10 machine',
'A message without to header',
'Ticket with multiple to',
]
],
// Mails having "normal" user as requester
Expand Down Expand Up @@ -781,12 +784,13 @@ function () use (&$msg) {
'43 - Korean encoding issue',
]
],
// Mails having "normal" user as observer (add_cc_to_observer = true)
// Mails having "normal" user as observer
[
'users_id' => $nuid,
'actor_type' => \CommonITILActor::OBSERVER,
'tickets_names' => [
'Ticket with observer',
'Ticket with observer', // add_cc_to_observer = true
'Ticket with multiple to', // add_to_to_observer = true
]
],
];
Expand Down Expand Up @@ -937,6 +941,8 @@ function () use (&$msg) {
$names[] = $name;
}

sort($names);
sort($actor_specs['tickets_names']);
$this->array($names)->isIdenticalTo($actor_specs['tickets_names']);
}

Expand Down Expand Up @@ -984,6 +990,8 @@ function () use (&$msg) {
foreach ($iterator as $data) {
$filenames[$data['filename']] = $data['mime'];
}
ksort($filenames);
ksort($expected_docs);
$this->array($filenames)->isIdenticalTo($expected_docs);

$this->integer(count($iterator))->isIdenticalTo(count($expected_docs));
Expand Down

0 comments on commit 84e7dbb

Please sign in to comment.