Update plugins to use new Net/Imap/Smtp/Sieve Settings object

This commit is contained in:
the-djmaze 2022-11-11 14:32:24 +01:00
parent cc1d0a6e38
commit ff065378ab
4 changed files with 86 additions and 75 deletions

View file

@ -3,12 +3,25 @@ PHP
class Plugin extends \RainLoop\Plugins\AbstractPlugin
{
public function __construct();
/** Returns static::NAME */
public function Name() : string;
/** Returns /README file contents or static::DESCRIPTION */
public function Description() : string;
/** When $bLangs is boolean it sets the value, else returns current value */
public function UseLangs(?bool $bLangs = null) : bool;
/** When true the result is empty string, else the error message */
public function Supported() : string;
/** Initialize settings */
public function Init() : void;
public function FilterAppDataPluginSection(bool $bAdmin, bool $bAuth, array &$aConfig) : void;
/** Returns array of all plugin Property options for use in Admin -> Extensions -> Plugin cog wheel */
protected function configMapping() : array;
}
```
@ -72,26 +85,26 @@ $Plugin->addHook('hook.name', 'functionName');
params:
\RainLoop\Model\Account $oAccount
\MailSo\Imap\ImapClient $oImapClient
array &$aCredentials
\MailSo\Imap\Settings $oSettings
### imap.after-connect
params:
\RainLoop\Model\Account $oAccount
\MailSo\Imap\ImapClient $oImapClient
array $aCredentials
\MailSo\Imap\Settings $oSettings
### imap.before-login
params:
\RainLoop\Model\Account $oAccount
\MailSo\Imap\ImapClient $oImapClient
array &$aCredentials
\MailSo\Imap\Settings $oSettings
### imap.after-login
params:
\RainLoop\Model\Account $oAccount
\MailSo\Imap\ImapClient $oImapClient
bool $bSuccess
array $aCredentials
\MailSo\Imap\Settings $oSettings
## Sieve
@ -99,26 +112,26 @@ $Plugin->addHook('hook.name', 'functionName');
params:
\RainLoop\Model\Account $oAccount
\MailSo\Sieve\ManageSieveClient $oSieveClient
array &$aCredentials
\MailSo\Sieve\Settings $oSettings
### sieve.after-connect
params:
\RainLoop\Model\Account $oAccount
\MailSo\Sieve\ManageSieveClient $oSieveClient
array $aCredentials
\MailSo\Sieve\Settings $oSettings
### sieve.before-login
params:
\RainLoop\Model\Account $oAccount
\MailSo\Sieve\ManageSieveClient $oSieveClient
array &$aCredentials
\MailSo\Sieve\Settings $oSettings
### sieve.after-login
params:
\RainLoop\Model\Account $oAccount
\MailSo\Sieve\ManageSieveClient $oSieveClient
bool $bSuccess
array $aCredentials
\MailSo\Sieve\Settings $oSettings
## SMTP
@ -126,26 +139,26 @@ $Plugin->addHook('hook.name', 'functionName');
params:
\RainLoop\Model\Account $oAccount
\MailSo\Smtp\SmtpClient $oSmtpClient
array &$aCredentials
\MailSo\Smtp\Settings $oSettings
### smtp.after-connect
params:
\RainLoop\Model\Account $oAccount
\MailSo\Smtp\SmtpClient $oSmtpClient
array $aCredentials
\MailSo\Smtp\Settings $oSettings
### smtp.before-login
params:
\RainLoop\Model\Account $oAccount
\MailSo\Smtp\SmtpClient $oSmtpClient
array &$aCredentials
\MailSo\Smtp\Settings $oSettings
### smtp.after-login
params:
\RainLoop\Model\Account $oAccount
\MailSo\Smtp\SmtpClient $oSmtpClient
bool $bSuccess
array $aCredentials
\MailSo\Smtp\Settings $oSettings
## Folders

View file

@ -15,8 +15,9 @@ class AutoDomainGrabPlugin extends \RainLoop\Plugins\AbstractPlugin
{
const
NAME = 'Auto Domain Selection',
VERSION = '2.8',
REQUIRED = '2.8.0',
VERSION = '2.9',
RELEASE = '2022-11-11',
REQUIRED = '2.21.0',
CATEGORY = 'General',
DESCRIPTION = 'Sets the IMAP/SMTP host based on the user\'s login';
@ -32,20 +33,20 @@ class AutoDomainGrabPlugin extends \RainLoop\Plugins\AbstractPlugin
/**
* This function detects the IMAP Host, and if it is set to 'auto', replaces it with the MX or email domain.
*/
public function FilterImapCredentials(\RainLoop\Model\Account $oAccount, \MailSo\Imap\ImapClient $oImapClient, array &$aImapCredentials)
public function FilterImapCredentials(\RainLoop\Model\Account $oAccount, \MailSo\Imap\ImapClient $oImapClient, \MailSo\Imap\Settings $oSettings)
{
// Check for mail.$DOMAIN as entered value in RL settings
if (!empty($aImapCredentials['Host']) && 'auto' === $aImapCredentials['Host'])
if ('auto' === $oSettings->host)
{
$domain = \substr(\strrchr($oAccount->Email(), '@'), 1);
$mxhosts = array();
if (\getmxrr($domain, $mxhosts) && $mxhosts)
{
$aImapCredentials['Host'] = $mxhosts[0];
$oSettings->host = $mxhosts[0];
}
else
{
$aImapCredentials['Host'] = $this->imap_prefix.$domain;
$oSettings->host = $this->imap_prefix.$domain;
}
}
}
@ -53,20 +54,20 @@ 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.
*/
public function FilterSmtpCredentials(\RainLoop\Model\Account $oAccount, \MailSo\Smtp\SmtpClient $oSmtpClient, array &$aSmtpCredentials)
public function FilterSmtpCredentials(\RainLoop\Model\Account $oAccount, \MailSo\Smtp\SmtpClient $oSmtpClient, \MailSo\Smtp\Settings $oSettings)
{
// Check for mail.$DOMAIN as entered value in RL settings
if (!empty($aSmtpCredentials['Host']) && 'auto' === $aSmtpCredentials['Host'])
if ('auto' === $oSettings->host)
{
$domain = \substr(\strrchr($oAccount->Email(), '@'), 1);
$mxhosts = array();
if (\getmxrr($domain, $mxhosts) && $mxhosts)
{
$aSmtpCredentials['Host'] = $mxhosts[0];
$oSettings->host = $mxhosts[0];
}
else
{
$aSmtpCredentials['Host'] = $this->smtp_prefix . $domain;
$oSettings->host = $this->smtp_prefix . $domain;
}
}
}

View file

@ -4,9 +4,9 @@ class LoginOAuth2Plugin extends \RainLoop\Plugins\AbstractPlugin
{
const
NAME = 'OAuth2',
VERSION = '1.0',
RELEASE = '2021-11-12',
REQUIRED = '2.9.1',
VERSION = '1.1',
RELEASE = '2022-11-11',
REQUIRED = '2.21.0',
CATEGORY = 'Login',
DESCRIPTION = 'IMAP, Sieve & SMTP login using RFC 7628 OAuth2';
@ -19,18 +19,18 @@ class LoginOAuth2Plugin extends \RainLoop\Plugins\AbstractPlugin
{
$this->UseLangs(true);
$this->addJs('LoginOAuth2.js');
// $this->addHook('imap.before-connect', array($this, $oImapClient, &$aCredentials));
// $this->addHook('imap.after-connect', array($this, $oImapClient, $aCredentials));
// $this->addHook('imap.before-connect', array($this, $oImapClient, $oSettings));
// $this->addHook('imap.after-connect', array($this, $oImapClient, $oSettings));
$this->addHook('imap.before-login', 'clientLogin');
// $this->addHook('imap.after-login', array($this, $oImapClient, $aCredentials));
// $this->addHook('smtp.before-connect', array($this, $oSmtpClient, &$aCredentials));
// $this->addHook('smtp.after-connect', array($this, $oSmtpClient, $aCredentials));
// $this->addHook('imap.after-login', array($this, $oImapClient, $oSettings));
// $this->addHook('smtp.before-connect', array($this, $oSmtpClient, $oSettings));
// $this->addHook('smtp.after-connect', array($this, $oSmtpClient, $oSettings));
$this->addHook('smtp.before-login', 'clientLogin');
// $this->addHook('smtp.after-login', array($this, $oSmtpClient, $aCredentials));
// $this->addHook('sieve.before-connect', array($this, $oSieveClient, &$aCredentials));
// $this->addHook('sieve.after-connect', array($this, $oSieveClient, $aCredentials));
// $this->addHook('smtp.after-login', array($this, $oSmtpClient, $oSettings));
// $this->addHook('sieve.before-connect', array($this, $oSieveClient, $oSettings));
// $this->addHook('sieve.after-connect', array($this, $oSieveClient, $oSettings));
$this->addHook('sieve.before-login', 'clientLogin');
// $this->addHook('sieve.after-login', array($this, $oSieveClient, $aCredentials));
// $this->addHook('sieve.after-login', array($this, $oSieveClient, $oSettings));
$this->addHook('filter.account', 'filterAccount');
}
@ -46,9 +46,9 @@ class LoginOAuth2Plugin extends \RainLoop\Plugins\AbstractPlugin
];
}
public function clientLogin(\RainLoop\Model\Account $oAccount, \MailSo\Net\NetClient $oClient, array &$aCredentials) : void
public function clientLogin(\RainLoop\Model\Account $oAccount, \MailSo\Net\NetClient $oClient, \MailSo\Net\ConnectSettings $oSettings) : void
{
$sPassword = $aCredentials['Password'];
$sPassword = $oSettings->Password;
$iGatLen = \strlen(static::GMAIL_TOKENS_PREFIX);
if ($sPassword && static::GMAIL_TOKENS_PREFIX === \substr($sPassword, 0, $iGatLen)) {
$aTokens = \json_decode(\substr($sPassword, $iGatLen));
@ -56,8 +56,8 @@ class LoginOAuth2Plugin extends \RainLoop\Plugins\AbstractPlugin
$sRefreshToken = !empty($aTokens[1]) ? $aTokens[1] : '';
}
if ($sAccessToken && $sRefreshToken) {
$aCredentials['Password'] = $this->gmailRefreshToken($sAccessToken, $sRefreshToken);
\array_unshift($aCredentials['SASLMechanisms'], 'OAUTHBEARER', 'XOAUTH2');
$oSettings->Password = $this->gmailRefreshToken($sAccessToken, $sRefreshToken);
\array_unshift($oSettings->SASLMechanisms, 'OAUTHBEARER', 'XOAUTH2');
}
}

View file

@ -4,9 +4,9 @@ class OverrideSmtpCredentialsPlugin extends \RainLoop\Plugins\AbstractPlugin
{
const
NAME = 'Override SMTP Credentials',
VERSION = '2.2',
RELEASE = '2022-04-13',
REQUIRED = '2.5.0',
VERSION = '2.3',
RELEASE = '2022-11-11',
REQUIRED = '2.21.0',
CATEGORY = 'Filters',
DESCRIPTION = 'Override SMTP credentials for specific users.';
@ -19,11 +19,9 @@ class OverrideSmtpCredentialsPlugin extends \RainLoop\Plugins\AbstractPlugin
/**
* @param \RainLoop\Model\Account $oAccount
* @param \MailSo\Smtp\SmtpClient $oSmtpClient
* @param array $aSmtpCredentials
* @param \MailSo\Smtp\Settings $oSettings
*/
public function FilterSmtpCredentials($oAccount, $oSmtpClient, &$aSmtpCredentials)
{
if ($oAccount instanceof \RainLoop\Model\Account && \is_array($aSmtpCredentials))
public function FilterSmtpCredentials(\RainLoop\Model\Account $oAccount, \MailSo\Smtp\SmtpClient $oSmtpClient, \MailSo\Smtp\Settings $oSettings)
{
$sEmail = $oAccount->Email();
@ -34,33 +32,32 @@ class OverrideSmtpCredentialsPlugin extends \RainLoop\Plugins\AbstractPlugin
if (0 < strlen($sWhiteList) && 0 < \strlen($sHost) && \RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sWhiteList, $sFoundValue))
{
\SnappyMail\LOG::debug('SMTP Override', "{$sEmail} matched {$sFoundValue}");
$aSmtpCredentials['Host'] = $sHost;
$aSmtpCredentials['Port'] = (int) $this->Config()->Get('plugin', 'smtp_port', 25);
$oSettings->host = $sHost;
$oSettings->port = (int) $this->Config()->Get('plugin', 'smtp_port', 25);
$sSecure = \trim($this->Config()->Get('plugin', 'smtp_secure', 'None'));
switch ($sSecure)
{
case 'SSL':
$aSmtpCredentials['Secure'] = MailSo\Net\Enumerations\ConnectionSecurityType::SSL;
$oSettings->type = MailSo\Net\Enumerations\ConnectionSecurityType::SSL;
break;
case 'TLS':
$aSmtpCredentials['Secure'] = MailSo\Net\Enumerations\ConnectionSecurityType::STARTTLS;
$oSettings->type = MailSo\Net\Enumerations\ConnectionSecurityType::STARTTLS;
break;
default:
$aSmtpCredentials['Secure'] = MailSo\Net\Enumerations\ConnectionSecurityType::NONE;
$oSettings->type = MailSo\Net\Enumerations\ConnectionSecurityType::NONE;
break;
}
$aSmtpCredentials['UseAuth'] = (bool) $this->Config()->Get('plugin', 'smtp_auth', true);
$aSmtpCredentials['Login'] = \trim($this->Config()->Get('plugin', 'smtp_user', ''));
$aSmtpCredentials['Password'] = (string) $this->Config()->Get('plugin', 'smtp_password', '');
$oSettings->useAuth = (bool) $this->Config()->Get('plugin', 'smtp_auth', true);
$oSettings->Login = \trim($this->Config()->Get('plugin', 'smtp_user', ''));
$oSettings->Password = (string) $this->Config()->Get('plugin', 'smtp_password', '');
}
else
{
\SnappyMail\LOG::debug('SMTP Override', "{$sEmail} no match");
}
}
}
/**
* @return array