mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-29 20:19:22 +03:00
Resolve #233
This commit is contained in:
parent
76ae57b481
commit
cc383f6b0e
5 changed files with 142 additions and 76 deletions
20
plugins/login-override/LICENSE
Normal file
20
plugins/login-override/LICENSE
Normal file
|
|
@ -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.
|
||||
63
plugins/login-override/index.php
Normal file
63
plugins/login-override/index.php
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
class LoginOverridePlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||
{
|
||||
const
|
||||
NAME = 'Login Override',
|
||||
VERSION = '2.0',
|
||||
RELEASE = '2023-02-01',
|
||||
REQUIRED = '2.25.2',
|
||||
CATEGORY = 'Filters',
|
||||
DESCRIPTION = 'Override IMAP/SMTP login credentials for specific users.';
|
||||
|
||||
public function Init() : void
|
||||
{
|
||||
$this->addHook('imap.before-login', 'MapImapCredentials');
|
||||
$this->addHook('smtp.before-login', 'MapSmtpCredentials');
|
||||
}
|
||||
|
||||
public function MapImapCredentials(\RainLoop\Model\Account $oAccount, \MailSo\Imap\ImapClient $oSmtpClient, \MailSo\Imap\Settings $oSettings)
|
||||
{
|
||||
static::MapCredentials($oAccount, $oSettings, $this->Config()->getDecrypted('plugin', 'imap_mapping', ''));
|
||||
}
|
||||
|
||||
public function MapSmtpCredentials(\RainLoop\Model\Account $oAccount, \MailSo\Smtp\SmtpClient $oSmtpClient, \MailSo\Smtp\Settings $oSettings)
|
||||
{
|
||||
static::MapCredentials($oAccount, $oSettings, $this->Config()->getDecrypted('plugin', 'smtp_mapping', ''));
|
||||
}
|
||||
|
||||
private static function MapCredentials(\RainLoop\Model\Account $oAccount, \MailSo\Net\ConnectSettings $oSettings, string $mapping)
|
||||
{
|
||||
$sEmail = $oAccount->Email();
|
||||
$aList = \preg_split('/\\R/', $mapping);
|
||||
foreach ($aList as $line) {
|
||||
$line = \explode(':', $line, 3);
|
||||
if (!empty($line[0]) && $line[0] === $sEmail) {
|
||||
if (!empty($line[1])) {
|
||||
$oSettings->Login = $line[1];
|
||||
}
|
||||
if (!empty($line[2])) {
|
||||
$oSettings->Password = $line[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function configMapping() : array
|
||||
{
|
||||
return array(
|
||||
\RainLoop\Plugins\Property::NewInstance('imap_mapping')
|
||||
->SetLabel('IMAP mapping')
|
||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
|
||||
->SetDescription('Each line as email:loginname:password, loginname or password may be empty to use default')
|
||||
->SetDefaultValue('user@example.com:user1:password1')
|
||||
->SetEncrypted(),
|
||||
\RainLoop\Plugins\Property::NewInstance('smtp_mapping')
|
||||
->SetLabel('SMTP mapping')
|
||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
|
||||
->SetDescription('Each line as email:loginname:password, loginname or password may be empty to use default')
|
||||
->SetDefaultValue('user@example.com:user1:password1')
|
||||
->SetEncrypted()
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue