mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-02-24 23:08:08 +08:00
Also allow changing email address (untested) for #859
This commit is contained in:
parent
73e6848ff4
commit
4521a9917a
1 changed files with 25 additions and 2 deletions
|
@ -12,10 +12,26 @@ class LoginOverridePlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
|
||||
public function Init() : void
|
||||
{
|
||||
$this->addHook('login.credentials', 'MapEmailAddress');
|
||||
$this->addHook('imap.before-login', 'MapImapCredentials');
|
||||
$this->addHook('smtp.before-login', 'MapSmtpCredentials');
|
||||
}
|
||||
|
||||
public function MapEmailAddress(string &$sEmail, string &$sLogin, string &$sPassword)
|
||||
{
|
||||
$sMapping = \trim($this->Config()->Get('plugin', 'email_mapping', ''));
|
||||
if (!empty($sMapping)) {
|
||||
$aList = \preg_split('/\\R/', $sMapping);
|
||||
foreach ($aList as $line) {
|
||||
$aData = \explode(':', $sLine, 2);
|
||||
if (!empty($aData[1]) && $sEmail === \trim($aData[0])) {
|
||||
$sEmail = \trim($aData[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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', ''));
|
||||
|
@ -26,10 +42,10 @@ class LoginOverridePlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
static::MapCredentials($oAccount, $oSettings, $this->Config()->getDecrypted('plugin', 'smtp_mapping', ''));
|
||||
}
|
||||
|
||||
private static function MapCredentials(\RainLoop\Model\Account $oAccount, \MailSo\Net\ConnectSettings $oSettings, string $mapping)
|
||||
private static function MapCredentials(\RainLoop\Model\Account $oAccount, \MailSo\Net\ConnectSettings $oSettings, string $sMapping)
|
||||
{
|
||||
$sEmail = $oAccount->Email();
|
||||
$aList = \preg_split('/\\R/', $mapping);
|
||||
$aList = \preg_split('/\\R/', \trim($sMapping));
|
||||
foreach ($aList as $line) {
|
||||
$line = \explode(':', $line, 3);
|
||||
if (!empty($line[0]) && $line[0] === $sEmail) {
|
||||
|
@ -39,6 +55,7 @@ class LoginOverridePlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
if (!empty($line[2])) {
|
||||
$oSettings->Password = $line[2];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +63,12 @@ class LoginOverridePlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
protected function configMapping() : array
|
||||
{
|
||||
return array(
|
||||
\RainLoop\Plugins\Property::NewInstance('email_mapping')
|
||||
->SetLabel('Email mapping')
|
||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
|
||||
->SetDescription('Changes email address as login@example.com:email@example.com')
|
||||
->SetDefaultValue('john-user1@example.com:john.doe@example.com')
|
||||
->SetEncrypted(),
|
||||
\RainLoop\Plugins\Property::NewInstance('imap_mapping')
|
||||
->SetLabel('IMAP mapping')
|
||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
|
||||
|
|
Loading…
Reference in a new issue