public
nobgit
read
NobMail
Based on mailcow: dockerized
Languages
Repository composition by tracked source files.
PHP
49%
JavaScript
35%
HTML
9%
CSS
4%
Shell
2%
Python
1%
Lua
0%
Perl
0%
Ruby
0%
SCSS
0%
Create file
Wiki Documentation
Clone
https://nobgit.com/orgs/nobgit/nobmail.git
ssh://[email protected]:2222/orgs/nobgit/nobmail.git
Commit
[Rspamd] Add SOGo contacts to whitelist
4f7f4934
data/conf/rspamd/dynmaps/settings.php | 89 +++++++++++++++++++++++++++++++----
1 file changed, 81 insertions(+), 8 deletions(-)
Diff
diff --git a/data/conf/rspamd/dynmaps/settings.php b/data/conf/rspamd/dynmaps/settings.php
index 9799c712..3af3245a 100644
--- a/data/conf/rspamd/dynmaps/settings.php
+++ b/data/conf/rspamd/dynmaps/settings.php
@@ -26,13 +26,32 @@ catch (PDOException $e) {
}
function parse_email($email) {
- if(!filter_var($email, FILTER_VALIDATE_EMAIL)) return false;
+ if (!filter_var($email, FILTER_VALIDATE_EMAIL)) return false;
$a = strrpos($email, '@');
return array('local' => substr($email, 0, $a), 'domain' => substr($email, $a));
}
+function wl_by_sogo() {
+ global $pdo;
+ $rcpt = array();
+ $stmt = $pdo->query("SELECT DISTINCT(`sogo_folder_info`.`c_path2`) AS `user`, GROUP_CONCAT(`sogo_quick_contact`.`c_mail`) AS `contacts` FROM `sogo_folder_info`
+ INNER JOIN `sogo_quick_contact` ON `sogo_quick_contact`.`c_folder_id` = `sogo_folder_info`.`c_folder_id`
+ GROUP BY `c_path2`");
+ $sogo_contacts = $stmt->fetchAll(PDO::FETCH_ASSOC);
+ while ($row = array_shift($sogo_contacts)) {
+ foreach (explode(',', $row['contacts']) as $contact) {
+ if (!filter_var($contact, FILTER_VALIDATE_EMAIL)) {
+ continue;
+ }
+ $rcpt[$row['user']][] = '/^' . str_replace('/', '\/', $contact) . '$/i';
+ }
+ }
+ return $rcpt;
+}
+
function ucl_rcpts($object, $type) {
global $pdo;
+ $rcpt = array();
if ($type == 'mailbox') {
// Standard aliases
$stmt = $pdo->prepare("SELECT `address` FROM `alias`
@@ -82,10 +101,7 @@ function ucl_rcpts($object, $type) {
$rcpt[] = '/.*@' . $row['alias_domain'] . '/i';
}
}
- if (!empty($rcpt)) {
- return $rcpt;
- }
- return false;
+ return $rcpt;
}
?>
settings {
@@ -138,6 +154,65 @@ while ($row = array_shift($rows)) {
<?php
}
+/*
+// Start SOGo contacts whitelist
+// Priority 4, lower than a domain whitelist (5) and lower than a mailbox whitelist (6)
+*/
+
+foreach (wl_by_sogo() as $user => $contacts) {
+ $username_sane = preg_replace("/[^a-zA-Z0-9]+/", "", $user);
+?>
+ whitelist_sogo_<?=$username_sane;?> {
+<?php
+ foreach ($contacts as $contact) {
+?>
+ from = <?=json_encode($contact, JSON_UNESCAPED_SLASHES);?>;
+<?php
+ }
+?>
+ priority = 4;
+<?php
+ foreach (ucl_rcpts($user, 'mailbox') as $rcpt) {
+?>
+ rcpt = <?=json_encode($rcpt, JSON_UNESCAPED_SLASHES);?>;
+<?php
+ }
+?>
+ apply "default" {
+ SOGO_CONTACT = -999.0;
+ }
+ symbols [
+ "SOGO_CONTACT"
+ ]
+ }
+ whitelist_sogo_<?=$username_sane;?>_header {
+ header = {
+<?php
+ foreach ($contacts as $contact) {
+?>
+ "From" = <?=json_encode(str_replace('/^', '/(', str_replace('$/i', ')/i', $contact)), JSON_UNESCAPED_SLASHES);?>;
+<?php
+ }
+?>
+ }
+ priority = 4;
+<?php
+ foreach (ucl_rcpts($user, 'mailbox') as $rcpt) {
+?>
+ rcpt = <?=json_encode($rcpt, JSON_UNESCAPED_SLASHES);?>;
+<?php
+ }
+?>
+ apply "default" {
+ SOGO_CONTACT = -999.0;
+ }
+ symbols [
+ "SOGO_CONTACT"
+ ]
+ }
+<?php
+}
+
/*
// Start whitelist
*/
@@ -343,7 +418,6 @@ while ($row = array_shift($rows)) {
priority = 9;
want_spam = yes;
}
-
<?php
// Start additional content
@@ -363,5 +437,4 @@ while ($row = array_shift($rows)) {
<?php
}
?>
-}
-
+}
\ No newline at end of file