From 0ce8062f644f00864bd048784a246a95ce56e371 Mon Sep 17 00:00:00 2001 From: Lars Kaltefleiter Date: Wed, 11 Aug 2021 12:21:10 +0200 Subject: [PATCH] Check whether a message is an auto reply based on configuration --- classes/emailmessage.class.inc.php | 30 ++++++++++++++++++++++++++++++ module.combodo-email-synchro.php | 3 +++ 2 files changed, 33 insertions(+) diff --git a/classes/emailmessage.class.inc.php b/classes/emailmessage.class.inc.php index 1ef6654..177991d 100644 --- a/classes/emailmessage.class.inc.php +++ b/classes/emailmessage.class.inc.php @@ -462,4 +462,34 @@ protected function IsNewPartLine($sLine, $aDelimiterPatterns) } return null; } + + /** + * Check whether the message is an auto reply + * @return bool + * @since 3.5.1 + */ + public function IsAutoReplyEmail() + { + $aAutoReplyHeaderPatterns = array( + 'auto-submitted' => '/^auto-replied.*$/i', + ); + if (class_exists('MetaModel')) + { + $aAutoReplyHeaderPatterns = MetaModel::GetModuleSetting('combodo-email-synchro', 'auto_reply_header_patterns', $aAutoReplyHeaderPatterns); + } + foreach ($aAutoReplyHeaderPatterns as $sHeader => $sPattern) { + if(array_key_exists(strtolower($sHeader), $this->aHeaders)) + { + IssueLog::Debug("Header \"$sHeader\" exists with the value: \"" . $this->aHeaders[strtolower($sHeader)] . "\""); + if (preg_match($sPattern, $this->aHeaders[strtolower($sHeader)])) + { + // Current mail is an auto reply + IssueLog::Debug("Given mail is an autoreply!"); + return true; + } + } + } + + return false; + } } diff --git a/module.combodo-email-synchro.php b/module.combodo-email-synchro.php index 505a6d1..5f8f04f 100644 --- a/module.combodo-email-synchro.php +++ b/module.combodo-email-synchro.php @@ -61,6 +61,9 @@ 'images_minimum_size' => '100x20', // Images smaller that these dimensions will be ignored (signatures...) 'images_maximum_size' => '', // Images bigger that these dimensions will be resized before uploading into iTop 'recommended_max_allowed_packet' => 10*1024*1024, // MySQL parameter for attachments + 'auto_reply_header_patterns' => array ( + 'auto-submitted' => '/^auto-replied.*$/i', + ), ), ) );