I dont fully know how it does it, but the TLDR; reference id, subject, message id and in-reply-to are all taken into account in different ways.More in depth:osTicket checks the emails message-id header field first and tries to compare it to existing message-ids. Then it checks the reference-id and in-reply-to. Lastly if all else fails it checks the message subject for the ticket number (like ) to see if it matches an existing ticket.