auto-domain-grab plugin: code refactoring

This commit is contained in:
RainLoop Team 2015-11-18 23:22:39 +03:00
parent 53cf543795
commit e8fbdff09c
3 changed files with 48 additions and 57 deletions

View file

@ -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) The MIT License (MIT)

View file

@ -1 +1 @@
1.0 1.1

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* This plug-in automatically detects the IMAP and SMTP settings by extracting them from the email address itself. * This plug-in automatically detects the IMAP and SMTP settings by extracting them from the email address itself.
* For example, user inputs: "info@example.com" * For example, user inputs: "info@example.com"
@ -6,6 +7,7 @@
* *
* Based on: * Based on:
* https://github.com/RainLoop/rainloop-webmail/blob/master/plugins/override-smtp-credentials/index.php * https://github.com/RainLoop/rainloop-webmail/blob/master/plugins/override-smtp-credentials/index.php
*
*/ */
class AutoDomainGrabPlugin extends \RainLoop\Plugins\AbstractPlugin class AutoDomainGrabPlugin extends \RainLoop\Plugins\AbstractPlugin
@ -18,6 +20,7 @@ class AutoDomainGrabPlugin extends \RainLoop\Plugins\AbstractPlugin
/** /**
* This function detects the IMAP Host, and if it is set to "auto", replaces it with the email domain. * 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 \RainLoop\Model\Account $oAccount
* @param array $aImapCredentials * @param array $aImapCredentials
*/ */
@ -25,18 +28,17 @@ class AutoDomainGrabPlugin extends \RainLoop\Plugins\AbstractPlugin
{ {
if ($oAccount instanceof \RainLoop\Model\Account && \is_array($aImapCredentials)) if ($oAccount instanceof \RainLoop\Model\Account && \is_array($aImapCredentials))
{ {
$sEmail = $oAccount->Email();
// Check for mail.$DOMAIN as entered value in RL settings // Check for mail.$DOMAIN as entered value in RL settings
if ( $aImapCredentials['Host'] == "auto" ) if (!empty($aImapCredentials['Host']) && 'auto' === $aImapCredentials['Host'])
{ {
$aImapCredentials['Host'] = $this->getDomainFromEmail($sEmail); $aImapCredentials['Host'] = \MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email());
} }
} }
} }
/** /**
* This function detects the SMTP Host, and if it is set to "auto", replaces it with the email domain. * 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 \RainLoop\Model\Account $oAccount
* @param array $aSmtpCredentials * @param array $aSmtpCredentials
*/ */
@ -44,27 +46,11 @@ class AutoDomainGrabPlugin extends \RainLoop\Plugins\AbstractPlugin
{ {
if ($oAccount instanceof \RainLoop\Model\Account && \is_array($aSmtpCredentials)) if ($oAccount instanceof \RainLoop\Model\Account && \is_array($aSmtpCredentials))
{ {
$sEmail = $oAccount->Email();
// Check for mail.$DOMAIN as entered value in RL settings // Check for mail.$DOMAIN as entered value in RL settings
if ( $aSmtpCredentials['Host'] == "auto" ) if (!empty($aSmtpCredentials['Host']) && 'auto' === $aSmtpCredentials['Host'])
{ {
$aSmtpCredentials['Host'] = $this->getDomainFromEmail($sEmail); $aSmtpCredentials['Host'] = \MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email());
} }
} }
} }
/**
* 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];
} }
}
?>