8000
Skip to content

Fix: mail collector attaches reply to the wrong ticket when subject holds a foreign reference - #25213

Open
Megachip wants to merge 9 commits into
glpi-project:11.0/bugfixesfrom
Megachip:glpi-ticket-id-source
Open

Fix: mail collector attaches reply to the wrong ticket when subject holds a foreign reference#25213
Megachip wants to merge 9 commits into
glpi-project:11.0/bugfixesfrom
Megachip:glpi-ticket-id-source

Conversation

@Megachip
@Megachip Megachip commented Aug 20, 2026
Copy link
Copy Markdown
Contributor

Checklist before requesting a review

  • I have read the CONTRIBUTING document.
  • I have performed a self-review of my code.
  • I have added tests that prove my fix is effective or that my feature works.

Description

When matching an incoming reply to an existing ticket via the subject, the
fallback pattern \[.+#(\d+)\] in MailCollector::getItemFromHeaders() was
greedy and could span several bracketed tokens. If the subject contained a
second, unrelated reference — e.g. a hoster's [Ticket#2026072803024161] — GLPI
extracted that number instead of its own [<tag> #<id>] id. getFromDB()
then failed on the non-existent id and a new ticket was created instead of
adding a followup to the existing one.

Example subject that triggered it:
Re: [B45 #0000054] [Ticket#2026072803024161] DNS Request
→ matched 2026072803024161 instead of 0000054.

Fix: restrict the pattern to a single bracketed token ([^\]]) and require
the whitespace that GLPI always inserts before # when building the subject
(see NotificationTargetCommonITILObject). Foreign [Ticket#...] references
without that space are ignored, and the correct id is matched regardless of its
position in the subject. A regression test is added.

Megachip added 7 commits July 24, 2026 15:44
#BUG
On location view, I can assign documents to a location, on document view there is no option to choose a location
Fix: mail collector attaches reply to the wrong ticket when subject holds a foreign reference
Added a test case for GLPI subject fallback handling.
@stonebuzz stonebuzz left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JGTM

@AdrienClairembault AdrienClairembault left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It fixes foreign tags that come after GLPI's own id tag but it now fails for any tags set before.

Take this example: [Case #4711] Re: [GLPI #0000054]

With the original regex, 0000054 is matched as expected.

Image

With the new regex, we now match 4711:

Image

@trasher trasher left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix and add test case following @AdrienClairembault comments

@AdrienClairembault
Copy link
Copy Markdown
Member

I don't think we can ever fix the fact that it takes the last correct tag found in the title. It would be a breaking change.

What we can do is improve what we call a "correct" tag by making sure the regex follow the format described here:
image

That would mean:

  • A space between [GLPI] and the number
  • A number with 7 chars minimum
  • A known tag? That would be all possible values for notification_subject_tag found in the database. Might not be a good idea to put it directly in the regex as it may be very long but rather use it to filter the values returned by the regex.

Comment thread src/MailCollector.php Outdated
Comment thread tests/imap/MailCollectorTest.php
Megachip and others added 2 commits August 21, 2026 16:15
Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com>
Match ticket id against configured notification subject tags.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

0