Browse Source

[Rspamd] Enhance SOGo contacts dynmap (#4245)

* [Rspamd] Fix SOGo Contacts Dynmap

1. Lowercase all emails to align with Rspamd
2. Remove dots from gmail.com and change googlemail.com to gmail.com to align with Rspamd per https://github.com/rspamd/rspamd/blob/master/lualib/lua_util.lua#L271-L274

* Update settings.php

Fix case when gmail.com or google.com is stored in contact book not in lowercase

* Update settings.php

Add removing of Tags in emails as Rspamd not count them as part of From
Dmitriy Alekseev 3 years ago
parent
commit
a26bbff63f
1 changed files with 25 additions and 1 deletions
  1. 25 1
      data/conf/rspamd/dynmaps/settings.php

+ 25 - 1
data/conf/rspamd/dynmaps/settings.php

@@ -49,6 +49,30 @@ function parse_email($email) {
   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();
@@ -63,7 +87,7 @@ function wl_by_sogo() {
       }
       // 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;