From e8fbdff09c736e27d8fd1cb6a1eb2b12b55cfd1e Mon Sep 17 00:00:00 2001 From: RainLoop Team Date: Wed, 18 Nov 2015 23:22:39 +0300 Subject: [PATCH] auto-domain-grab plugin: code refactoring --- plugins/auto-domain-grab/LICENSE | 7 ++- plugins/auto-domain-grab/VERSION | 2 +- plugins/auto-domain-grab/index.php | 96 +++++++++++++----------------- 3 files changed, 48 insertions(+), 57 deletions(-) diff --git a/plugins/auto-domain-grab/LICENSE b/plugins/auto-domain-grab/LICENSE index d6b23af63..325ab989b 100644 --- a/plugins/auto-domain-grab/LICENSE +++ b/plugins/auto-domain-grab/LICENSE @@ -1,4 +1,9 @@ -This plugin, written by https://github.com/jas8522 and optimised by https://github.com/rhyswilliamsza / https://github.com/rhysit/ is released under: +This plugin, written by https://github.com/jas8522 +and optimised by + https://github.com/rhyswilliamsza + https://github.com/rhysit + https://github.com/RainLoop +is released under: The MIT License (MIT) diff --git a/plugins/auto-domain-grab/VERSION b/plugins/auto-domain-grab/VERSION index d3827e75a..b123147e2 100644 --- a/plugins/auto-domain-grab/VERSION +++ b/plugins/auto-domain-grab/VERSION @@ -1 +1 @@ -1.0 +1.1 \ No newline at end of file diff --git a/plugins/auto-domain-grab/index.php b/plugins/auto-domain-grab/index.php index 303a7594b..fed64d297 100644 --- a/plugins/auto-domain-grab/index.php +++ b/plugins/auto-domain-grab/index.php @@ -1,4 +1,5 @@ addHook('filter.smtp-credentials', 'FilterSmtpCredentials'); - $this->addHook('filter.imap-credentials', 'FilterImapCredentials'); - } + public function Init() + { + $this->addHook('filter.smtp-credentials', 'FilterSmtpCredentials'); + $this->addHook('filter.imap-credentials', 'FilterImapCredentials'); + } - /** - * This function detects the IMAP Host, and if it is set to "auto", replaces it with the email domain. - * @param \RainLoop\Model\Account $oAccount - * @param array $aImapCredentials - */ - public function FilterImapCredentials($oAccount, &$aImapCredentials) - { - if ($oAccount instanceof \RainLoop\Model\Account && \is_array($aImapCredentials)) - { - $sEmail = $oAccount->Email(); + /** + * This function detects the IMAP Host, and if it is set to "auto", replaces it with the email domain. + * + * @param \RainLoop\Model\Account $oAccount + * @param array $aImapCredentials + */ + public function FilterImapCredentials($oAccount, &$aImapCredentials) + { + if ($oAccount instanceof \RainLoop\Model\Account && \is_array($aImapCredentials)) + { + // Check for mail.$DOMAIN as entered value in RL settings + if (!empty($aImapCredentials['Host']) && 'auto' === $aImapCredentials['Host']) + { + $aImapCredentials['Host'] = \MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email()); + } + } + } - // Check for mail.$DOMAIN as entered value in RL settings - if ( $aImapCredentials['Host'] == "auto" ) - { - $aImapCredentials['Host'] = $this->getDomainFromEmail($sEmail); - } - } - } - - /** - * This function detects the SMTP Host, and if it is set to "auto", replaces it with the email domain. - * @param \RainLoop\Model\Account $oAccount - * @param array $aSmtpCredentials - */ - public function FilterSmtpCredentials($oAccount, &$aSmtpCredentials) - { - if ($oAccount instanceof \RainLoop\Model\Account && \is_array($aSmtpCredentials)) - { - $sEmail = $oAccount->Email(); - - // Check for mail.$DOMAIN as entered value in RL settings - if ( $aSmtpCredentials['Host'] == "auto" ) - { - $aSmtpCredentials['Host'] = $this->getDomainFromEmail($sEmail); - } - } - } - - - /** - * This function extracts the domain from the email address. - * @param string $emailAdress - * @return string - */ - private function getDomainFromEmail($emailAddress){ - - $parts = explode("@", trim($emailAddress)); - return $parts[1]; - } + /** + * This function detects the SMTP Host, and if it is set to "auto", replaces it with the email domain. + * + * @param \RainLoop\Model\Account $oAccount + * @param array $aSmtpCredentials + */ + public function FilterSmtpCredentials($oAccount, &$aSmtpCredentials) + { + if ($oAccount instanceof \RainLoop\Model\Account && \is_array($aSmtpCredentials)) + { + // Check for mail.$DOMAIN as entered value in RL settings + if (!empty($aSmtpCredentials['Host']) && 'auto' === $aSmtpCredentials['Host']) + { + $aSmtpCredentials['Host'] = \MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email()); + } + } + } } - -?>