diff --git a/lib/Listeners/UserChangedListener.php b/lib/Listeners/UserChangedListener.php index 40c782c251c74ca7f787e562f41a624b4fe9b5ff..d6942f61c778fbaa9ec488ff4e5c5230d4943115 100644 --- a/lib/Listeners/UserChangedListener.php +++ b/lib/Listeners/UserChangedListener.php @@ -17,6 +17,8 @@ class UserChangedListener implements IEventListener { private const QUOTA_FEATURE = 'quota'; + private const RECOVERY_EMAIL_FEATURE = 'recovery-email'; + private $util; private $logger; @@ -40,39 +42,51 @@ class UserChangedListener implements IEventListener } $feature = $event->getFeature(); - - if ($feature !== self::QUOTA_FEATURE) { - return; - } $user = $event->getUser(); $username = $user->getUID(); - $updatedQuota = $event->getValue(); - $quotaInBytes = (int) $this->util->computerFileSize($updatedQuota); - $backend = $user->getBackend()->getBackendName(); + + if ($feature === self::QUOTA_FEATURE) { + $updatedQuota = $event->getValue(); + $quotaInBytes = (int) $this->util->computerFileSize($updatedQuota); + $backend = $user->getBackend()->getBackendName(); + + $this->updateQuota($username, $backend, $quotaInBytes); + } + + if ($feature === self::RECOVERY_EMAIL_FEATURE) { + $recoveryEmail = $event->getValue(); + $recoveryEmailAttribute = [ + 'recoveryMailAddress' => $recoveryEmail + ]; + $this->updateAttributesInLDAP($username, $recoveryEmailAttribute); + } + } + + private function updateQuota(string $username, string $backend, int $quotaInBytes) + { try { if ($backend === 'SQL raw') { $this->mailboxMapper->updateMailboxQuota($username, $quotaInBytes); } if ($backend === 'LDAP') { - $this->updateQuotaInLDAP($username, $quotaInBytes); + $quotaAttribute = [ + 'quota' => $quotaInBytes + ]; + $this->updateAttributesInLDAP($username, $quotaAttribute); } } catch (Exception $e) { $this->logger->error("Error setting quota for user $username " . $e->getMessage()); } } - - private function updateQuotaInLDAP(string $username, int $quota) + + private function updateAttributesInLDAP(string $username, array $attributes) { if ($this->ldapConnectionService->isLDAPEnabled()) { $conn = $this->ldapConnectionService->getLDAPConnection(); $userDn = $this->ldapConnectionService->username2dn($username); - - $entry = [ - 'quota' => $quota - ]; - - if (!ldap_modify($conn, $userDn, $entry)) { + + if (!ldap_modify($conn, $userDn, $attributes)) { throw new Exception('Could not modify user entry at LDAP server!'); } $this->ldapConnectionService->closeLDAPConnection($conn);