From a26bbff63f5e97e1c162572996e2a0a4e0ffd9d9 Mon Sep 17 00:00:00 2001 From: Dmitriy Alekseev <1865999+dragoangel@users.noreply.github.com> Date: Sat, 23 Oct 2021 18:58:06 +0300 Subject: [PATCH] [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 --- data/conf/rspamd/dynmaps/settings.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/data/conf/rspamd/dynmaps/settings.php b/data/conf/rspamd/dynmaps/settings.php index ddff7ff5..274e9da2 100644 --- a/data/conf/rspamd/dynmaps/settings.php +++ b/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;