Issue with Multi-Collector
Some time user send mail to two collector....
Those mail collector genreate ticket in two diffrent entity.
Saddly, with the plugin enable, the first collector who take de mail create the ticket, and when the second collector take teh mail it' simply add to new generated ticket...
The good beahaviour should be:
If the mail is send to two different mail collector, it's generate two ticket, (one in every entity defined)
And if a emailreply come, its add on both ticket the comment.
Hello @mat44444
Sorry for this bad behavior: the plugin has never been imagined working with several collectors.
But, if you want to split new emails by collector (or by entity), then the followups will be split also... There is no reason to split new emails, and to not split followups.
Regards, Tomolimo
In message-id, if we could add the mail_collector_id at the end for unicity reference, that should to the trick
Hello @mat44444 Could you propose a PR (pull request)? Thank you Regards, Tomolimo
Here my modification and tested on my environnement and seem working fine.
Sorry for the PR been long time i'm not done that
There an exceptioin the patch: The section plugin_item_add_mailanalyzer, i'm not understanding the usage... So that part havent' been touch
Including 2 GLPI email collector in same generate two different ticket now
And every email reply replicate followup in both ticket:

impact in database:

Hello @mat44444,
Thank you, I'm going to look at this.
- To give you an overview: pre_item_add is called by GLPI framework before creating the Ticket in DB and such there is no ticket number yet. And then in the item_add (called by the framework after ticket creation in DB) we have the ticket number, then we need to update the message_id with the ticket number.
- I really don't agree for the followups behavior: for me a followup received by a mailgate should not impact a ticket created via another mailgate.... It must be added to only one ticket: the ticket added via the same mailgate
Thank you Regards, Tomolimo
For the 2., the behaviour happen only when an user send an email to more then one collector at once. Exemple, here we have a T.I department and a security departement. So when a new employe come, they send an email to the both collector over one mail: (ex: TO : [email protected]; [email protected]). So those collector are in different entity(in our case)e, but they add both because they want different follow up and it's not the same team: ex: the I.T department genre, UserId , and allow acces to application and the securitity team, will make parking pass, employe card, allow acces to physical door systeme
This is an excellent contribution @mat44444, I was just going to open a ticket @tomolimo for the same issue, since in the same way we use several receivers for different entities and child-entities, and I had the same problem because we are different support areas, so when they copied to 2 emails receivers, the ticket was only created in 1 entitie and not in the other, and the plugin did not work well when, responding later to another email, only one mail receiver was copied, but the ticket had already been created in another entity and the message_id was associated with that ticket to that identity.
I only had to manually make the following change in the database:
ALTER TABLE glpi.glpi_plugin_mailanalyzer_message_id ADD mailgate_id int (10) DEFAULT 0 NOT NULL;
I have tried with this flow, with some errors:
-
Mail is sent to 2 mail receivers, one mailcollector with ID=1 and the another one with ID=2. Also in the rule "Rules for assigning a ticket created through an email receiver" I have a the first rule that mailcollector with ID=2 is assigned to GLPITest1>GLPITest2 child-entity, and the second rule that the mailcollector with ID=1 is assigned to GLPITest1parent-entity
-
Tickets are created in both entities:

But in the table, is created just one row:

Expected behavior In the table should be created the same message id for both mailcollectors ID, and differents tickets ID.
- The same email is answered to 1 mail receiver with ID=1, and it is verified that the followup has been added only to the corresponding ticket of that entity by its respective mail receiver. And in the table is created the new message_id with its corresponding ticket_id:


- The same step is carried out in point (3), the same email is answered to the other mail receiver with ID=2, but it is verified that the followup hasn't been added to the corresponding ticket of the other entity, but it's create a new one, and in the table it's created a new row associated with the new ticket_id:


Expected behavior The ticket should have be added as followup to the previous created ticket (ID 148 in the image) for the GlpiTest1>GlpiTest2 child-entity and not as a new one (ID 149).
- In the same way, the same email is answered by copying again to both mail receivers, and it is verified that the followup is created in ticket (ID 147) of the GLPITest1 parent-entity of the mailcollector with ID=1, but again as a new ticket (ID 150) for the GlpiTest1>GlpiTest2 child-entity instead as a followup:


And in the table the message id for the last email to mailcollector ID=2 is not added again:

Expected behavior That the mail is correctly added as a follow-up to the ticket created for the child-entity with mailcollector ID=2, that its corresponding message_id correctly associated to the ticket_id and mailcollector ID=2 is added in the table, and that it is not created as a new ticket .
What can be happend here @tomolimo @mat44444?
Hi @tomolimo and @mat44444,
After a reviewed, I found this error on sql-errors.log
SQL: INSERT INTO `glpi_plugin_mailanalyzer_message_id` (`message_id`, `mailgate_id`) VALUES ('<CABq4Eb5Vu22ytr9zFWbzXdq2wkmDK3ouN9tqeZQV8fPHPsgw4A@mail.email.net>', '2')
Error: Duplicate entry '<[email protected]...' for key 'message_id'
Checking the table I found that the Unicity hadn't been alterate:

So checking again the hook.php provided by @mat44444, I execute manually this sentences:
ALTER TABLE glpi_plugin_mailanalyzer_message_id ADD COLUMN `mailgate_id` int(10) NOT NULL DEFAULT 0 AFTER `message_id`;
ALTER TABLE glpi_plugin_mailanalyzer_message_id DROP INDEX `message_id`;
ALTER TABLE glpi_plugin_mailanalyzer_message_id ADD UNIQUE KEY `message_id` (`message_id`,`mailgate_id`);

Although they are specified in the hook.php file, I don't know why they didn't run, so I had to do it manually.
Also I had to updated the hook.php provided by @mat44444 to the last modifications by Release 2.0.2: (at the left is mat44444 file, at right is release 2.0.2)
After all this modifications, I did my last 5 steps flow, with success:
-
Mail is sent to 2 mail receivers, one mailcollector with ID=1 and the another one with ID=2. Also in the rule "Rules for assigning a ticket created through an email receiver" I have a the first rule that mailcollector with ID=2 is assigned to GLPITest1>GLPITest2 child-entity, and the second rule that the mailcollector with ID=1 is assigned to GLPITest1parent-entity
-
Tickets are created in both entities and in the table with they repective message_id, ticket_id, and mailgate_id:


- The same email is answered to 1 mail receiver with ID=1, and it is verified that the followup has been added only to the corresponding ticket of that entity by its respective mail receiver. And in the table is created the new message_id with its corresponding ticket_id:

- The same step is carried out in point (3), the same email is answered to the other mail receiver with ID=2, and it is verified that the followup has been added to the corresponding ticket of the other entity:

- In the same way, the same email is answered by copying again to both mail receivers, and it is verified that the followup is created in ticket of the GLPITest1 parent-entity of the mailcollector with ID=1, and as a followup in the ticket for the GlpiTest1>GlpiTest2 child-entity for the mailcollector with ID=2:



This is the hook.php file of @mat44444 revised and corrected similar as release 2.0.2:
@tomolimo this solution is essential to improve the plugin, and satisfy the needs of some of us especially when we use multiple entities and collectors, it would be good if it is implemented in the next versions of the plugin.
Again, thanks @tomolimo for this plugin and @mat44444 for this contribution and review, you have helped me a lot with this solution.
Hi everyone!
We are having this same issue in our GLPI setup,
This fix will be published in a future update of Mailanalyzer?
Thanks!
Hi @Leofravega,
I have updated the plugin hook.php version 3.0.0 for the compatibility version GLPI 10, with the code that @mat44444 has shared. I'm testing for a while, you should do the same. hook.txt Rename it txt to php, and replace it.
For now, the only problem I got is that in notimportedemail.php I'm getting: "REASON OF REJECTION: Failed operation" but actually the ticket is already imported and added correctly as a followup depending mailcollector/mailgate/receiver as what you want call it.
Good morning, I think it's correct to only generate one ticket to avoid duplicates. It could be possible to add a configuration tab to choose the behavior in future versions. Thank you.
Hi @Leofravega,
I have updated the plugin hook.php version 3.0.0 for the compatibility version GLPI 10, with the code that @mat44444 has shared. I'm testing for a while, you should do the same. hook.txt Rename it txt to php, and replace it.
For now, the only problem I got is that in notimportedemail.php I'm getting: "REASON OF REJECTION: Failed operation" but actually the ticket is already imported and added correctly as a followup depending mailcollector/mailgate/receiver as what you want call it.
Hello @Leofravega This false error message is due to the fact that to prevent a new ticket creation from GLPI core, the only possibility is to return an empty array (or NULL), and then GLPI will automatically consider the current email as not imported and will raise an error with this reason.
Thank you to all your contribution, Regards, Tomolimo
Hi, a friend of mine did this pull request:
https://github.com/tomolimo/mailanalyzer/pull/82/commits/3046142b33fd43b6b62023fe91a4f045379b0eed
Actually, we have been used this change a long of time, for years, so it's so tested.
See release 3.1.1 https://github.com/tomolimo/mailanalyzer/releases/tag/3.1.1
Has this been implemented? I have several receivers, and it works well for me that duplicates are not generated. I suppose I'll be able to add some rule so that it doesn't create double tickets if the option is active. Thank you
Yes, it has been implemented, could you test?



