From 7e4e8a4a692b476b1c70d4db51f5e3625a36fb7f Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Fri, 9 Oct 2015 15:03:58 -0500
Subject: [PATCH] bounce: Avoid a loop on new message alert to staff

If a new message alert bounced to a staff member and the postmaster sent
back a bounce notice, which was threaded, then the agent might receive
another new message alert, which would continue a bounce loop.
---
 include/class.ticket.php | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/include/class.ticket.php b/include/class.ticket.php
index 1c9b8dda3..e64c38f40 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -1807,20 +1807,22 @@ class Ticket {
             }
         }
 
-        if(!$alerts) return $message; //Our work is done...
-
         // Do not auto-respond to bounces and other auto-replies
-        $autorespond = isset($vars['flags'])
-            ? !$vars['flags']['bounce'] && !$vars['flags']['auto-reply']
-            : true;
-        if ($autorespond && $message->isAutoReply())
-            $autorespond = false;
+        if ($alerts)
+            $alerts = isset($vars['flags'])
+                ? !$vars['flags']['bounce'] && !$vars['flags']['auto-reply']
+                : true;
+        if ($alerts && $message->isBounceOrAutoReply())
+            $alerts = false;
 
-        $this->onMessage($message, $autorespond); //must be called b4 sending alerts to staff.
+        $this->onMessage($message, $alerts); //must be called b4 sending alerts to staff.
 
-        if ($autorespond && $cfg && $cfg->notifyCollabsONNewMessage())
+        if ($alerts && $cfg && $cfg->notifyCollabsONNewMessage())
             $this->notifyCollaborators($message, array('signature' => ''));
 
+        if (!$alerts)
+            return $message; //Our work is done...
+
         $dept = $this->getDept();
 
 
-- 
GitLab