NobGit
public nobgit read

NobMail

Based on mailcow: dockerized

Languages

Repository composition by tracked source files.

PHP
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

Add error message when mailbox creation fails

5a727584
FreddleSpl0it <[email protected]> 1 year, 4 months ago
data/conf/phpfpm/crons/keycloak-sync.php | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

Diff

diff --git a/data/conf/phpfpm/crons/keycloak-sync.php b/data/conf/phpfpm/crons/keycloak-sync.php
index 98010648..cdc5a6e9 100644
--- a/data/conf/phpfpm/crons/keycloak-sync.php
+++ b/data/conf/phpfpm/crons/keycloak-sync.php
@@ -79,7 +79,7 @@ if ($iam_settings['authsource'] != "keycloak" || (intval($iam_settings['periodic
 
 // Set pagination variables
 $start = 0;
-$max = 25;
+$max = 100;
 
 // lock sync if already running
 $lock_file = '/tmp/iam-sync.lock';
@@ -167,11 +167,13 @@ while (true) {
     $mailcow_template = $user['attributes']['mailcow_template'];
 
     // try get mailbox user
-    $stmt = $pdo->prepare("SELECT `mailbox`.* FROM `mailbox`
-    INNER JOIN domain on mailbox.domain = domain.domain
-    WHERE `kind` NOT REGEXP 'location|thing|group'
-      AND `domain`.`active`='1'
-      AND `username` = :user");
+    $stmt = $pdo->prepare("SELECT
+      mailbox.*,
+      domain.active AS d_active
+      FROM `mailbox`
+      INNER JOIN domain on mailbox.domain = domain.domain
+      WHERE `kind` NOT REGEXP 'location|thing|group'
+        AND `username` = :user");
     $stmt->execute(array(':user' => $user['email']));
     $row = $stmt->fetch(PDO::FETCH_ASSOC);
 
@@ -192,13 +194,17 @@ while (true) {
     if (!$row && intval($iam_settings['import_users']) == 1){
       // mailbox user does not exist, create...
       logMsg("info", "Creating user " . $user['email']);
-      mailbox('add', 'mailbox_from_template', array(
+      $create_res = mailbox('add', 'mailbox_from_template', array(
         'domain' => explode('@', $user['email'])[1],
         'local_part' => explode('@', $user['email'])[0],
         'name' => $user['firstName'] . " " . $user['lastName'],
         'authsource' => 'keycloak',
         'template' => $mbox_template
       ));
+      if (!$create_res){
+        logMsg("err", "Could not create user " . $user['email']);
+        continue;
+      }
     } else if ($row && intval($iam_settings['periodic_sync']) == 1) {
       // mailbox user does exist, sync attribtues...
       logMsg("info", "Syncing attributes for user " . $user['email']);