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

View file

@ -15,8 +15,9 @@ class AutoDomainGrabPlugin extends \RainLoop\Plugins\AbstractPlugin
{ {
const const
NAME = 'Auto Domain Selection', NAME = 'Auto Domain Selection',
VERSION = '2.8', VERSION = '2.9',
REQUIRED = '2.8.0', RELEASE = '2022-11-11',
REQUIRED = '2.21.0',
CATEGORY = 'General', CATEGORY = 'General',
DESCRIPTION = 'Sets the IMAP/SMTP host based on the user\'s login'; 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. * 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 // 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); $domain = \substr(\strrchr($oAccount->Email(), '@'), 1);
$mxhosts = array(); $mxhosts = array();
if (\getmxrr($domain, $mxhosts) && $mxhosts) if (\getmxrr($domain, $mxhosts) && $mxhosts)
{ {
$aImapCredentials['Host'] = $mxhosts[0]; $oSettings->host = $mxhosts[0];
} }
else 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. * 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 // 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); $domain = \substr(\strrchr($oAccount->Email(), '@'), 1);
$mxhosts = array(); $mxhosts = array();
if (\getmxrr($domain, $mxhosts) && $mxhosts) if (\getmxrr($domain, $mxhosts) && $mxhosts)
{ {
$aSmtpCredentials['Host'] = $mxhosts[0]; $oSettings->host = $mxhosts[0];
} }
else 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 const
NAME = 'OAuth2', NAME = 'OAuth2',
VERSION = '1.0', VERSION = '1.1',
RELEASE = '2021-11-12', RELEASE = '2022-11-11',
REQUIRED = '2.9.1', REQUIRED = '2.21.0',
CATEGORY = 'Login', CATEGORY = 'Login',
DESCRIPTION = 'IMAP, Sieve & SMTP login using RFC 7628 OAuth2'; DESCRIPTION = 'IMAP, Sieve & SMTP login using RFC 7628 OAuth2';
@ -19,18 +19,18 @@ class LoginOAuth2Plugin extends \RainLoop\Plugins\AbstractPlugin
{ {
$this->UseLangs(true); $this->UseLangs(true);
$this->addJs('LoginOAuth2.js'); $this->addJs('LoginOAuth2.js');
// $this->addHook('imap.before-connect', array($this, $oImapClient, &$aCredentials)); // $this->addHook('imap.before-connect', array($this, $oImapClient, $oSettings));
// $this->addHook('imap.after-connect', array($this, $oImapClient, $aCredentials)); // $this->addHook('imap.after-connect', array($this, $oImapClient, $oSettings));
$this->addHook('imap.before-login', 'clientLogin'); $this->addHook('imap.before-login', 'clientLogin');
// $this->addHook('imap.after-login', array($this, $oImapClient, $aCredentials)); // $this->addHook('imap.after-login', array($this, $oImapClient, $oSettings));
// $this->addHook('smtp.before-connect', array($this, $oSmtpClient, &$aCredentials)); // $this->addHook('smtp.before-connect', array($this, $oSmtpClient, $oSettings));
// $this->addHook('smtp.after-connect', array($this, $oSmtpClient, $aCredentials)); // $this->addHook('smtp.after-connect', array($this, $oSmtpClient, $oSettings));
$this->addHook('smtp.before-login', 'clientLogin'); $this->addHook('smtp.before-login', 'clientLogin');
// $this->addHook('smtp.after-login', array($this, $oSmtpClient, $aCredentials)); // $this->addHook('smtp.after-login', array($this, $oSmtpClient, $oSettings));
// $this->addHook('sieve.before-connect', array($this, $oSieveClient, &$aCredentials)); // $this->addHook('sieve.before-connect', array($this, $oSieveClient, $oSettings));
// $this->addHook('sieve.after-connect', array($this, $oSieveClient, $aCredentials)); // $this->addHook('sieve.after-connect', array($this, $oSieveClient, $oSettings));
$this->addHook('sieve.before-login', 'clientLogin'); $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'); $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); $iGatLen = \strlen(static::GMAIL_TOKENS_PREFIX);
if ($sPassword && static::GMAIL_TOKENS_PREFIX === \substr($sPassword, 0, $iGatLen)) { if ($sPassword && static::GMAIL_TOKENS_PREFIX === \substr($sPassword, 0, $iGatLen)) {
$aTokens = \json_decode(\substr($sPassword, $iGatLen)); $aTokens = \json_decode(\substr($sPassword, $iGatLen));
@ -56,8 +56,8 @@ class LoginOAuth2Plugin extends \RainLoop\Plugins\AbstractPlugin
$sRefreshToken = !empty($aTokens[1]) ? $aTokens[1] : ''; $sRefreshToken = !empty($aTokens[1]) ? $aTokens[1] : '';
} }
if ($sAccessToken && $sRefreshToken) { if ($sAccessToken && $sRefreshToken) {
$aCredentials['Password'] = $this->gmailRefreshToken($sAccessToken, $sRefreshToken); $oSettings->Password = $this->gmailRefreshToken($sAccessToken, $sRefreshToken);
\array_unshift($aCredentials['SASLMechanisms'], 'OAUTHBEARER', 'XOAUTH2'); \array_unshift($oSettings->SASLMechanisms, 'OAUTHBEARER', 'XOAUTH2');
} }
} }

View file

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