git subrepo commit (merge) mailcow/src/mailcow-dockerized

subrepo: subdir:   "mailcow/src/mailcow-dockerized"
  merged:   "32243e56"
upstream: origin:   "https://github.com/mailcow/mailcow-dockerized.git"
  branch:   "master"
  commit:   "e2b4b6f6"
git-subrepo: version:  "0.4.3"
  origin:   "???"
  commit:   "???"
Change-Id: I51e2016ef5ab88a8b0bdc08551b18f48ceef0aa5
diff --git a/mailcow/src/mailcow-dockerized/data/conf/rspamd/dynmaps/settings.php b/mailcow/src/mailcow-dockerized/data/conf/rspamd/dynmaps/settings.php
index 0569db9..274e9da 100644
--- a/mailcow/src/mailcow-dockerized/data/conf/rspamd/dynmaps/settings.php
+++ b/mailcow/src/mailcow-dockerized/data/conf/rspamd/dynmaps/settings.php
@@ -26,9 +26,8 @@
 }

 

 // Check if db changed and return header

-/*

-$stmt = $pdo->prepare("SELECT MAX(UNIX_TIMESTAMP(UPDATE_TIME)) AS `db_update_time` FROM information_schema.tables

-  WHERE (`TABLE_NAME` = 'filterconf' OR `TABLE_NAME` = 'settingsmap')

+$stmt = $pdo->prepare("SELECT GREATEST(COALESCE(MAX(UNIX_TIMESTAMP(UPDATE_TIME)), 1), COALESCE(MAX(UNIX_TIMESTAMP(CREATE_TIME)), 1)) AS `db_update_time` FROM `information_schema`.`tables`

+  WHERE (`TABLE_NAME` = 'filterconf' OR `TABLE_NAME` = 'settingsmap' OR `TABLE_NAME` = 'sogo_quick_contact' OR `TABLE_NAME` = 'alias')

     AND TABLE_SCHEMA = :dbname;");

 $stmt->execute(array(

   ':dbname' => $database_name

@@ -43,7 +42,6 @@
 } else {

   header('Last-Modified: '.gmdate('D, d M Y H:i:s', $db_update_time).' GMT', true, 200);

 }

-*/

 

 function parse_email($email) {

   if (!filter_var($email, FILTER_VALIDATE_EMAIL)) return false;

@@ -51,6 +49,30 @@
   return array('local' => substr($email, 0, $a), 'domain' => substr($email, $a));

 }

 

+function normalize_email($email) {

+  $email = strtolower(str_replace('/', '\/', $email));

+  $gm = "@gmail.com";

+  if (substr_compare($email, $gm, -strlen($gm)) == 0) {

+    $email = explode('@', $email);

+    $email[0] = str_replace('.', '', $email[0]);

+    $email = implode('@', $email);

+  } 

+  $gm_alt = "@googlemail.com";

+  if (substr_compare($email, $gm_alt, -strlen($gm_alt)) == 0) {

+    $email = explode('@', $email);

+    $email[0] = str_replace('.', '', $email[0]);

+    $email[1] = str_replace('@', '', $gm);

+    $email = implode('@', $email);

+  }

+  if (str_contains($email, "+")) {

+    $email = explode('@', $email);

+    $user = explode('+', $email[0]);

+    $email[0] = $user[0];

+    $email = implode('@', $email);

+  }

+  return $email;

+}

+

 function wl_by_sogo() {

   global $pdo;

   $rcpt = array();

@@ -65,7 +87,7 @@
       }

       // Explicit from, no mime_from, no regex - envelope must match

       // mailcow white and blacklists also cover mime_from

-      $rcpt[$row['user']][] = str_replace('/', '\/', $contact);

+      $rcpt[$row['user']][] = normalize_email($contact);

     }

   }

   return $rcpt;