Hi everyone,
We are implementing an automation around email-based replies to tickets, and during testing we made an interesting discovery regarding subject‑line ticket matching.
Summary of the issue
If the ticket uses the default osTicket numeric ticket format, e.g. [#7842], then replying by email successfully threads the message into the existing ticket.
However, if the ticket uses a custom ticket number format, e.g. CCBD‑7842, then replying to the ticket notification creates a new ticket instead of appending to the existing one.
This happens even when all other headers (Message-ID, In-Reply-To, References) are not available (because our notification is generated by a ticket filter rather than the core osTicket mailer), leaving subject‑based matching as the fallback.
Relevant code
We found the fallback subject‑matching code in the osTicket source:
// Search for ticket by the [#123456] in the subject line
// This is the last resort - emails must match to avoid message
// injection by third-party.
$subject = $mailinfo['subject'];
$match = array();
if ($subject
&& $mailinfo['email']
// Required#followed by one or more of
// punctuation (-) then letters, numbers, and symbols
// (Try not to match closing punctuation (]) in [#12345])
&& preg_match("/#((\p{P}*[^\p{C}\p{Z}\p{P}]+)+)/u", $subject, $match)
//Lookup by ticket number
&& ($ticket = Ticket::lookupByNumber($match[1]))
//Lookup the user using the email address
&& ($user = User::lookup(array('emails__address' => $mailinfo['email'])))) {
...
}
ecause the regex requires a literal #, custom ticket numbers like CCBD-7842 or LOG-1274 are never detected via subject fallback, so threading fails and a new ticket is created.
Observed behavior
- Default numeric tickets → reply threading works
- Custom format tickets (e.g., CCBD‑####) → replies open new tickets
This is consistent with the documented fallback logic of matching [#number] only.
My questions
- Is this the expected behavior, meaning osTicket officially only supports subject‑based threading for numeric [#1234] patterns?
- Would the osTicket team consider broadening the regex to allow custom ticket number formats (e.g., CCBD-1234) or to allow configuration of the pattern?
- If not, is there a recommended upgrade‑safe way to support custom ticket numbers while still enabling email-thread replies?
Possible solutions we identified
- Switch back to default numeric ticket IDs externally (e.g., include both [#1234] and CCBD-1234 in the subject).
- Patch the regex locally (not upgrade‑safe).
- Wait for an enhancement in a future version.
We would appreciate guidance on whether expanding the regex or providing a configurable subject‑matching option is something the osTicket team considers feasible or aligned with future plans.
Thanks a lot for your help and for maintaining this great software!