From f9cd95fdce180037fbb50101066d959ba3e083ca Mon Sep 17 00:00:00 2001 From: Jordan Schelew Date: Fri, 28 Feb 2025 10:40:40 -0400 Subject: [PATCH] Add Sieve support to auto domain grab plugin --- plugins/auto-domain-grab/index.php | 35 +++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/plugins/auto-domain-grab/index.php b/plugins/auto-domain-grab/index.php index ee2458948..4ac8dad07 100644 --- a/plugins/auto-domain-grab/index.php +++ b/plugins/auto-domain-grab/index.php @@ -1,10 +1,10 @@ addHook('smtp.before-connect', 'FilterSmtpCredentials'); $this->addHook('imap.before-connect', 'FilterImapCredentials'); + $this->addHook('smtp.before-connect', 'FilterSmtpCredentials'); + $this->addHook('sieve.before-connect', 'FilterSieveCredentials'); } /** @@ -71,4 +73,25 @@ class AutoDomainGrabPlugin extends \RainLoop\Plugins\AbstractPlugin } } } + + /** + * This function detects the Sieve Host, and if it is set to 'auto', replaces it with the MX or email domain. + */ + public function FilterSieveCredentials(\RainLoop\Model\Account $oAccount, \MailSo\Sieve\SieveClient $oSieveClient, \MailSo\Sieve\Settings $oSettings) + { + // Check for mail.$DOMAIN as entered value in RL settings + if ('auto' === $oSettings->host) + { + $domain = \substr(\strrchr($oAccount->Email(), '@'), 1); + $mxhosts = array(); + if (\getmxrr($domain, $mxhosts) && $mxhosts) + { + $oSettings->host = $mxhosts[0]; + } + else + { + $oSettings->host = $this->sieve_prefix.$domain; + } + } + } }