2014-02-01 04:32:42 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class OverrideSmtpCredentialsPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|
|
|
{
|
2021-02-10 16:50:20 +08:00
|
|
|
const
|
2021-08-28 05:49:03 +08:00
|
|
|
NAME = 'Override SMTP Credentials',
|
2022-04-13 15:46:58 +08:00
|
|
|
VERSION = '2.2',
|
|
|
|
RELEASE = '2022-04-13',
|
2021-04-21 16:34:54 +08:00
|
|
|
REQUIRED = '2.5.0',
|
2021-02-10 16:50:20 +08:00
|
|
|
CATEGORY = 'Filters',
|
2021-08-28 05:49:03 +08:00
|
|
|
DESCRIPTION = 'Override SMTP credentials for specific users.';
|
2021-02-10 16:50:20 +08:00
|
|
|
|
2020-08-31 00:04:54 +08:00
|
|
|
public function Init() : void
|
2014-02-01 04:32:42 +08:00
|
|
|
{
|
2022-04-13 15:46:58 +08:00
|
|
|
$this->addHook('smtp.before-connect', 'FilterSmtpCredentials');
|
|
|
|
$this->addHook('smtp.before-login', 'FilterSmtpCredentials');
|
2014-02-01 04:32:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-11-15 04:23:46 +08:00
|
|
|
* @param \RainLoop\Model\Account $oAccount
|
2022-04-13 15:46:58 +08:00
|
|
|
* @param \MailSo\Smtp\SmtpClient $oSmtpClient
|
2014-02-01 04:32:42 +08:00
|
|
|
* @param array $aSmtpCredentials
|
|
|
|
*/
|
2022-04-13 15:46:58 +08:00
|
|
|
public function FilterSmtpCredentials($oAccount, $oSmtpClient, &$aSmtpCredentials)
|
2014-02-01 04:32:42 +08:00
|
|
|
{
|
2014-11-15 04:23:46 +08:00
|
|
|
if ($oAccount instanceof \RainLoop\Model\Account && \is_array($aSmtpCredentials))
|
2014-02-01 04:32:42 +08:00
|
|
|
{
|
|
|
|
$sEmail = $oAccount->Email();
|
|
|
|
|
|
|
|
$sHost = \trim($this->Config()->Get('plugin', 'smtp_host', ''));
|
|
|
|
$sWhiteList = \trim($this->Config()->Get('plugin', 'override_users', ''));
|
|
|
|
|
2022-06-08 19:12:33 +08:00
|
|
|
$sFoundValue = '';
|
|
|
|
if (0 < strlen($sWhiteList) && 0 < \strlen($sHost) && \RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sWhiteList, $sFoundValue))
|
2014-02-01 04:32:42 +08:00
|
|
|
{
|
2022-06-08 19:12:33 +08:00
|
|
|
\SnappyMail\LOG::debug('SMTP Override', "{$sEmail} matched {$sFoundValue}");
|
2014-02-01 04:32:42 +08:00
|
|
|
$aSmtpCredentials['Host'] = $sHost;
|
|
|
|
$aSmtpCredentials['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;
|
|
|
|
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', '');
|
|
|
|
}
|
2022-06-08 19:12:33 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
\SnappyMail\LOG::debug('SMTP Override', "{$sEmail} no match");
|
|
|
|
}
|
2014-02-01 04:32:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2020-08-31 00:04:54 +08:00
|
|
|
protected function configMapping() : array
|
2014-02-01 04:32:42 +08:00
|
|
|
{
|
|
|
|
return array(
|
|
|
|
\RainLoop\Plugins\Property::NewInstance('smtp_host')->SetLabel('SMTP Host')
|
|
|
|
->SetDefaultValue(''),
|
|
|
|
\RainLoop\Plugins\Property::NewInstance('smtp_port')->SetLabel('SMTP Port')
|
|
|
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::INT)
|
|
|
|
->SetDefaultValue(25),
|
|
|
|
\RainLoop\Plugins\Property::NewInstance('smtp_secure')->SetLabel('SMTP Secure')
|
|
|
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::SELECTION)
|
|
|
|
->SetDefaultValue(array('None', 'SSL', 'TLS')),
|
|
|
|
\RainLoop\Plugins\Property::NewInstance('smtp_auth')->SetLabel('Use auth')
|
|
|
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
|
|
|
->SetDefaultValue(true),
|
|
|
|
\RainLoop\Plugins\Property::NewInstance('smtp_user')->SetLabel('SMTP User')
|
|
|
|
->SetDefaultValue(''),
|
|
|
|
\RainLoop\Plugins\Property::NewInstance('smtp_password')->SetLabel('SMTP Password')
|
|
|
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)
|
|
|
|
->SetDefaultValue(''),
|
|
|
|
\RainLoop\Plugins\Property::NewInstance('override_users')->SetLabel('Override users')
|
|
|
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
|
|
|
|
->SetDescription('space as delimiter, wildcard supported.')
|
|
|
|
->SetDefaultValue('user@example.com *@example2.com')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|