From 8eda7e38729ce00b86fc338d88bff83a8968d894 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Tue, 11 Mar 2014 09:12:38 -0500
Subject: [PATCH] Log errors on email loop detection

If an email loop is detected, in addition to dropping the message, also log
an error to the system log, but do not send an email to the administrator in
the event that it is the administrator's email that is looped.
---
 include/class.thread.php | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/class.thread.php b/include/class.thread.php
index 355e0890e..8f6f9f156 100644
--- a/include/class.thread.php
+++ b/include/class.thread.php
@@ -600,6 +600,8 @@ Class ThreadEntry {
      *      - body - (string) email message body (decoded)
      */
     function postEmail($mailinfo) {
+        global $ost;
+
         // +==================+===================+=============+
         // | Orig Thread-Type | Reply Thread-Type | Requires    |
         // +==================+===================+=============+
@@ -628,6 +630,15 @@ Class ThreadEntry {
             // This mail was sent by this system. It was received due to
             // some kind of mail delivery loop. It should not be considered
             // a response to an existing thread entry
+            if ($ost) $ost->log(LOG_ERR, 'Email loop detected', sprintf(
+               'It appears as though &lt;%s&gt; is being used as a forwarded or
+                fetched email account and is also being used as a user /
+                system account. Please correct the loop or seek technical
+                assistance.', $mailinfo['email']),
+                // This is quite intentional -- don't continue the loop
+                false,
+                // Force the message, even if logging is disabled
+                true);
             return true;
         }
 
-- 
GitLab