diff --git a/build/plugin.xml b/build/plugin.xml index e58039acd..3c385394a 100644 --- a/build/plugin.xml +++ b/build/plugin.xml @@ -87,6 +87,11 @@ + + + + + diff --git a/plugins/override-smtp-credentials/LICENSE b/plugins/override-smtp-credentials/LICENSE new file mode 100644 index 000000000..4a4ca8d81 --- /dev/null +++ b/plugins/override-smtp-credentials/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2014 RainLoop Team + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/plugins/override-smtp-credentials/README b/plugins/override-smtp-credentials/README new file mode 100644 index 000000000..291c3e8d3 --- /dev/null +++ b/plugins/override-smtp-credentials/README @@ -0,0 +1 @@ +Plugin which allows you to override smtp credentials specified users. \ No newline at end of file diff --git a/plugins/override-smtp-credentials/VERSION b/plugins/override-smtp-credentials/VERSION new file mode 100644 index 000000000..9f8e9b69a --- /dev/null +++ b/plugins/override-smtp-credentials/VERSION @@ -0,0 +1 @@ +1.0 \ No newline at end of file diff --git a/plugins/override-smtp-credentials/index.php b/plugins/override-smtp-credentials/index.php new file mode 100644 index 000000000..bb7f6767c --- /dev/null +++ b/plugins/override-smtp-credentials/index.php @@ -0,0 +1,77 @@ +addHook('filter.smtp-credentials', 'FilterSmtpCredentials'); + } + + /** + * @param \RainLoop\Account $oAccount + * @param array $aSmtpCredentials + */ + public function FilterSmtpCredentials($oAccount, &$aSmtpCredentials) + { + if ($oAccount instanceof \RainLoop\Account && \is_array($aSmtpCredentials)) + { + $sEmail = $oAccount->Email(); + + $sHost = \trim($this->Config()->Get('plugin', 'smtp_host', '')); + $sWhiteList = \trim($this->Config()->Get('plugin', 'override_users', '')); + + if (0 < strlen($sWhiteList) && 0 < \strlen($sHost) && \RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sWhiteList)) + { + $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', ''); + } + } + } + + /** + * @return array + */ + public function configMapping() + { + 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') + ); + } +}