From 26137edb94687381bd623919a36f1308f3b0c0fa Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Mon, 20 Apr 2015 17:04:01 -0500
Subject: [PATCH] email: Support agents emailing as collaborators

---
 include/class.thread.php | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/include/class.thread.php b/include/class.thread.php
index 3f10ac94c..67f9bfbfa 100644
--- a/include/class.thread.php
+++ b/include/class.thread.php
@@ -745,10 +745,20 @@ class ThreadEntry {
         if ($mailinfo['userId']
                 || strcasecmp($mailinfo['email'], $ticket->getEmail()) == 0) {
             $vars['message'] = $body;
-            $vars['userId'] = $mailinfo['userId'] ? $mailinfo['userId'] : $ticket->getUserId();
+            $vars['userId'] = $mailinfo['userId'] ?: $ticket->getUserId();
+            return $ticket->postMessage($vars, 'Email');
+        }
+        // Consider collaborator role (disambiguate staff members as
+        // collaborators)
+        elseif (($E = UserEmail::lookup($mailinfo['email']))
+            && ($C = Collaborator::lookup(array(
+                'ticketId' => $ticket->getId(), 'userId' => $E->user_id
+            )))
+        ) {
+            $vars['userId'] = $C->getUserId();
+            $vars['message'] = $body;
             return $ticket->postMessage($vars, 'Email');
         }
-        // XXX: Consider collaborator role
         elseif ($mailinfo['staffId']
                 || ($mailinfo['staffId'] = Staff::getIdByEmail($mailinfo['email']))) {
             $vars['staffId'] = $mailinfo['staffId'];
-- 
GitLab