From 108ddf3abe4d1a06e6cf95e1477aab8a521f59d4 Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Thu, 16 Jan 2014 21:20:14 +0000 Subject: [PATCH] Add ability to tag email reference ids With the introduction of collaborators, this is necessary so we can determine who is replying without relying on the FROM address - which can be easily spoofed. --- include/class.thread.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/include/class.thread.php b/include/class.thread.php index 282e8b122..6569f72b1 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -351,6 +351,37 @@ Class ThreadEntry { return $this->_references; } + function getTaggedEmailReferences($prefix, $refId) { + + $ref = "+$prefix".Base32::encode(pack('VV', $this->getId(), $refId)); + + $mid = substr_replace($this->getEmailMessageId(), + $ref, strpos($this->getEmailMessageId(), '@'), 0); + + //TODO: Confirm how references are ordered on reply - we want the tagged + // reference to be processed first. + + return sprintf('%s %s', $this->getEmailReferences(), $mid); + } + + function getEmailReferencesForUser($user) { + return $this->getTaggedEmailReferences('u', $user->getId()); + } + + function getEmailReferencesForStaff($staff) { + return $this->getTaggedEmailReferences('s', $staff->getId()); + } + + function getUIDFromEmailReference($ref) { + + $info = unpack('Vtid/Vuid', + Base32::decode(strtolower(substr($ref, -13)))); + + if ($info && $info['tid'] == $this->getId()) + return $info['uid']; + + } + function getTicket() { if(!$this->ticket && $this->getTicketId()) -- GitLab