From 2e01010e9015baf4bc4ab09d17f4400a09d64c57 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Thu, 13 Nov 2014 09:16:33 -0600
Subject: [PATCH] thread: Fix regex for ticket # in email subject

The ticket number regex was changed with the advent of custom ticket
numbers, and it matches the closing punctuation in [#12345], that is, the
closing bracket would be included in the ticket number sought in the
database. Therefore, it would never match the ticket number properly.

The new regex attempts to match punctuation and non-punctuation groups so
that punctuation in the middle of the ticket number is matched; however,
punctuation at the end is not. So #12345+DEPT will match properly and will
ignore any trailing whitespace and punctuation.
---
 include/class.thread.php | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/class.thread.php b/include/class.thread.php
index b57da9713..aa1404d26 100644
--- a/include/class.thread.php
+++ b/include/class.thread.php
@@ -910,7 +910,10 @@ Class ThreadEntry {
         $match = array();
         if ($subject
                 && $mailinfo['email']
-                && preg_match("/\b#(\S+)/u", $subject, $match)
+                // 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
-- 
GitLab