|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class OverrideSmtpCredentialsPlugin extends \RainLoop\Plugins\AbstractPlugin |
|
4
|
|
|
{ |
|
5
|
|
|
public function Init() |
|
6
|
|
|
{ |
|
7
|
|
|
$this->addHook('filter.smtp-credentials', 'FilterSmtpCredentials'); |
|
8
|
|
|
} |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @param \RainLoop\Model\Account $oAccount |
|
12
|
|
|
* @param array $aSmtpCredentials |
|
13
|
|
|
*/ |
|
14
|
|
|
public function FilterSmtpCredentials($oAccount, &$aSmtpCredentials) |
|
15
|
|
|
{ |
|
16
|
|
|
if ($oAccount instanceof \RainLoop\Model\Account && \is_array($aSmtpCredentials)) |
|
|
|
|
|
|
17
|
|
|
{ |
|
18
|
|
|
$sEmail = $oAccount->Email(); |
|
19
|
|
|
|
|
20
|
|
|
$sHost = \trim($this->Config()->Get('plugin', 'smtp_host', '')); |
|
21
|
|
|
$sWhiteList = \trim($this->Config()->Get('plugin', 'override_users', '')); |
|
22
|
|
|
|
|
23
|
|
|
if (0 < strlen($sWhiteList) && 0 < \strlen($sHost) && \RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sWhiteList)) |
|
24
|
|
|
{ |
|
25
|
|
|
$aSmtpCredentials['Host'] = $sHost; |
|
26
|
|
|
$aSmtpCredentials['Port'] = (int) $this->Config()->Get('plugin', 'smtp_port', 25); |
|
27
|
|
|
|
|
28
|
|
|
$sSecure = \trim($this->Config()->Get('plugin', 'smtp_secure', 'None')); |
|
29
|
|
|
switch ($sSecure) |
|
30
|
|
|
{ |
|
31
|
|
|
case 'SSL': |
|
32
|
|
|
$aSmtpCredentials['Secure'] = MailSo\Net\Enumerations\ConnectionSecurityType::SSL; |
|
33
|
|
|
break; |
|
34
|
|
|
case 'TLS': |
|
35
|
|
|
$aSmtpCredentials['Secure'] = MailSo\Net\Enumerations\ConnectionSecurityType::STARTTLS; |
|
36
|
|
|
break; |
|
37
|
|
|
default: |
|
38
|
|
|
$aSmtpCredentials['Secure'] = MailSo\Net\Enumerations\ConnectionSecurityType::NONE; |
|
39
|
|
|
break; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$aSmtpCredentials['UseAuth'] = (bool) $this->Config()->Get('plugin', 'smtp_auth', true); |
|
43
|
|
|
$aSmtpCredentials['Login'] = \trim($this->Config()->Get('plugin', 'smtp_user', '')); |
|
44
|
|
|
$aSmtpCredentials['Password'] = (string) $this->Config()->Get('plugin', 'smtp_password', ''); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @return array |
|
51
|
|
|
*/ |
|
52
|
|
|
public function configMapping() |
|
53
|
|
|
{ |
|
54
|
|
|
return array( |
|
55
|
|
|
\RainLoop\Plugins\Property::NewInstance('smtp_host')->SetLabel('SMTP Host') |
|
56
|
|
|
->SetDefaultValue(''), |
|
57
|
|
|
\RainLoop\Plugins\Property::NewInstance('smtp_port')->SetLabel('SMTP Port') |
|
58
|
|
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::INT) |
|
59
|
|
|
->SetDefaultValue(25), |
|
60
|
|
|
\RainLoop\Plugins\Property::NewInstance('smtp_secure')->SetLabel('SMTP Secure') |
|
61
|
|
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::SELECTION) |
|
62
|
|
|
->SetDefaultValue(array('None', 'SSL', 'TLS')), |
|
63
|
|
|
\RainLoop\Plugins\Property::NewInstance('smtp_auth')->SetLabel('Use auth') |
|
64
|
|
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL) |
|
65
|
|
|
->SetDefaultValue(true), |
|
66
|
|
|
\RainLoop\Plugins\Property::NewInstance('smtp_user')->SetLabel('SMTP User') |
|
67
|
|
|
->SetDefaultValue(''), |
|
68
|
|
|
\RainLoop\Plugins\Property::NewInstance('smtp_password')->SetLabel('SMTP Password') |
|
69
|
|
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD) |
|
70
|
|
|
->SetDefaultValue(''), |
|
71
|
|
|
\RainLoop\Plugins\Property::NewInstance('override_users')->SetLabel('Override users') |
|
72
|
|
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT) |
|
73
|
|
|
->SetDescription('space as delimiter, wildcard supported.') |
|
74
|
|
|
->SetDefaultValue('[email protected] *@example2.com') |
|
75
|
|
|
); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.