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; + } + } + } }