mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Resolve #207
This commit is contained in:
parent
45a714ee08
commit
ef61603431
1 changed files with 31 additions and 43 deletions
|
|
@ -3,8 +3,8 @@
|
|||
/**
|
||||
* This extension automatically detects the IMAP and SMTP settings by
|
||||
* extracting them from the email address itself. For example, if the user
|
||||
* attemps to login as "info@example.com", then the IMAP and SMTP host would
|
||||
* be set to to "example.com".
|
||||
* attemps to login as 'info@example.com', then the IMAP and SMTP host would
|
||||
* be set to to 'example.com'.
|
||||
*
|
||||
* Based on:
|
||||
* https://github.com/the-djmaze/snappymail/blob/master/plugins/override-smtp-credentials/index.php
|
||||
|
|
@ -20,31 +20,26 @@ class AutoDomainGrabPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
CATEGORY = 'General',
|
||||
DESCRIPTION = 'Sets the IMAP/SMTP host based on the user\'s login';
|
||||
|
||||
private $imap_prefix = "mail.";
|
||||
private $smtp_prefix = "mail.";
|
||||
private $imap_prefix = 'mail.';
|
||||
private $smtp_prefix = 'mail.';
|
||||
|
||||
public function Init() : void
|
||||
{
|
||||
$this->addHook('smtp.credentials', 'FilterSmtpCredentials');
|
||||
$this->addHook('imap.credentials', 'FilterImapCredentials');
|
||||
$this->addHook('smtp.before-connect', 'FilterSmtpCredentials');
|
||||
$this->addHook('imap.before-connect', 'FilterImapCredentials');
|
||||
}
|
||||
|
||||
/**
|
||||
* This function detects the IMAP Host, and if it is set to "auto", replaces it with the MX or email domain.
|
||||
*
|
||||
* @param \RainLoop\Model\Account $oAccount
|
||||
* @param array $aImapCredentials
|
||||
* This function detects the IMAP Host, and if it is set to 'auto', replaces it with the MX or email domain.
|
||||
*/
|
||||
public function FilterImapCredentials($oAccount, &$aImapCredentials)
|
||||
{
|
||||
if ($oAccount instanceof \RainLoop\Model\Account && \is_array($aImapCredentials))
|
||||
public function FilterImapCredentials(\RainLoop\Model\Account $oAccount, \MailSo\Imap\ImapClient $oImapClient, array &$aImapCredentials)
|
||||
{
|
||||
// Check for mail.$DOMAIN as entered value in RL settings
|
||||
if (!empty($aImapCredentials['Host']) && 'auto' === $aImapCredentials['Host'])
|
||||
{
|
||||
$domain = substr(strrchr($oAccount->Email(), "@"), 1);
|
||||
$domain = \substr(\strrchr($oAccount->Email(), '@'), 1);
|
||||
$mxhosts = array();
|
||||
if(getmxrr($domain, $mxhosts) && sizeof($mxhosts) > 0)
|
||||
if (\getmxrr($domain, $mxhosts) && $mxhosts)
|
||||
{
|
||||
$aImapCredentials['Host'] = $mxhosts[0];
|
||||
}
|
||||
|
|
@ -54,24 +49,18 @@ class AutoDomainGrabPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function detects the SMTP Host, and if it is set to "auto", replaces it with the MX or email domain.
|
||||
*
|
||||
* @param \RainLoop\Model\Account $oAccount
|
||||
* @param array $aSmtpCredentials
|
||||
* This function detects the SMTP Host, and if it is set to 'auto', replaces it with the MX or email domain.
|
||||
*/
|
||||
public function FilterSmtpCredentials($oAccount, &$aSmtpCredentials)
|
||||
{
|
||||
if ($oAccount instanceof \RainLoop\Model\Account && \is_array($aSmtpCredentials))
|
||||
public function FilterSmtpCredentials(\RainLoop\Model\Account $oAccount, \MailSo\Smtp\SmtpClient $oSmtpClient, array &$aSmtpCredentials)
|
||||
{
|
||||
// Check for mail.$DOMAIN as entered value in RL settings
|
||||
if (!empty($aSmtpCredentials['Host']) && 'auto' === $aSmtpCredentials['Host'])
|
||||
{
|
||||
$domain = substr(strrchr($oAccount->Email(), "@"), 1);
|
||||
$domain = \substr(\strrchr($oAccount->Email(), '@'), 1);
|
||||
$mxhosts = array();
|
||||
if(getmxrr($domain, $mxhosts) && sizeof($mxhosts) > 0)
|
||||
if (\getmxrr($domain, $mxhosts) && $mxhosts)
|
||||
{
|
||||
$aSmtpCredentials['Host'] = $mxhosts[0];
|
||||
}
|
||||
|
|
@ -82,4 +71,3 @@ class AutoDomainGrabPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue