mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
auto-domain-grab plugin: code refactoring
This commit is contained in:
parent
53cf543795
commit
e8fbdff09c
3 changed files with 48 additions and 57 deletions
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
1.0
|
1.1
|
||||||
|
|
@ -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,65 +7,50 @@
|
||||||
*
|
*
|
||||||
* 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
|
||||||
{
|
{
|
||||||
public function Init()
|
public function Init()
|
||||||
{
|
{
|
||||||
$this->addHook('filter.smtp-credentials', 'FilterSmtpCredentials');
|
$this->addHook('filter.smtp-credentials', 'FilterSmtpCredentials');
|
||||||
$this->addHook('filter.imap-credentials', 'FilterImapCredentials');
|
$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.
|
* 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
|
* @param \RainLoop\Model\Account $oAccount
|
||||||
*/
|
* @param array $aImapCredentials
|
||||||
public function FilterImapCredentials($oAccount, &$aImapCredentials)
|
*/
|
||||||
{
|
public function FilterImapCredentials($oAccount, &$aImapCredentials)
|
||||||
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
|
||||||
|
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" )
|
* This function detects the SMTP Host, and if it is set to "auto", replaces it with the email domain.
|
||||||
{
|
*
|
||||||
$aImapCredentials['Host'] = $this->getDomainFromEmail($sEmail);
|
* @param \RainLoop\Model\Account $oAccount
|
||||||
}
|
* @param array $aSmtpCredentials
|
||||||
}
|
*/
|
||||||
}
|
public function FilterSmtpCredentials($oAccount, &$aSmtpCredentials)
|
||||||
|
{
|
||||||
/**
|
if ($oAccount instanceof \RainLoop\Model\Account && \is_array($aSmtpCredentials))
|
||||||
* This function detects the SMTP Host, and if it is set to "auto", replaces it with the email domain.
|
{
|
||||||
* @param \RainLoop\Model\Account $oAccount
|
// Check for mail.$DOMAIN as entered value in RL settings
|
||||||
* @param array $aSmtpCredentials
|
if (!empty($aSmtpCredentials['Host']) && 'auto' === $aSmtpCredentials['Host'])
|
||||||
*/
|
{
|
||||||
public function FilterSmtpCredentials($oAccount, &$aSmtpCredentials)
|
$aSmtpCredentials['Host'] = \MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email());
|
||||||
{
|
}
|
||||||
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];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue