diff --git a/plugins/hmail-aliases/LICENSE b/plugins/hmail-aliases/LICENSE new file mode 100644 index 0000000000..69d4b4db02 --- /dev/null +++ b/plugins/hmail-aliases/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2019 Karobolas, 2023 Oxymoron290 + +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/hmail-aliases/README b/plugins/hmail-aliases/README new file mode 100644 index 0000000000..57efea0de8 --- /dev/null +++ b/plugins/hmail-aliases/README @@ -0,0 +1 @@ +Plugin which allows you to use hmail aliases diff --git a/plugins/hmail-aliases/VERSION b/plugins/hmail-aliases/VERSION new file mode 100644 index 0000000000..9f8e9b69a3 --- /dev/null +++ b/plugins/hmail-aliases/VERSION @@ -0,0 +1 @@ +1.0 \ No newline at end of file diff --git a/plugins/hmail-aliases/index.php b/plugins/hmail-aliases/index.php new file mode 100755 index 0000000000..aa26843b59 --- /dev/null +++ b/plugins/hmail-aliases/index.php @@ -0,0 +1,119 @@ +addHook('event.login-post-login-provide', 'loginPostLoginProvide'); + } + + public function Supported() + { + if (!class_exists('COM')) + { + return 'The PHP extension COM must be installed to use this plugin'; + } + + return ''; + } + + /** + * @param \RainLoop\Model\Account $oAccount + * @throws \RainLoop\Exceptions\ClientException + */ + public function loginPostLoginProvide(\RainLoop\Model\Account &$oAccount) + { + // Get Logger + $oLogger = $this->Manager()->Actions()->Logger(); + // Load values from configuration + $sLogin = (string) $this->Config()->Get('plugin', 'login', ''); + $sPassword = (string) $this->Config()->Get('plugin', 'password', ''); + // prime result value + $bResult = false; + + try + { + // Create a connection with the hMailServer + $oHmailApp = new COM("hMailServer.Application"); + $oHmailApp->Connect(); + + //$oLogger->Write("Connected"); + if ($oHmailApp->Authenticate($sLogin, $sPassword)) + { + //$oLogger->Write("Authenticated"); + $sEmail = $oAccount->Email(); + //$oLogger->Write("Using ". $sEmail); + $sDomain = \MailSo\Base\Utils::GetDomainFromEmail($sEmail); + //$oLogger->Write("Searching for domain ".$sDomain); + + $oHmailDomain = $oHmailApp->Domains->ItemByName($sDomain); + if ($oHmailDomain) + { + $oHmailAccount = $oHmailDomain->Accounts->ItemByAddress($sEmail); + if ($oHmailAccount) + { + // Get account details for alias + $firstName = $oHmailAccount->PersonFirstName; + $lastName = $oHmailAccount->PersonLastName; + if ($firstName == "" && $lastName == "") { + $name = ""; + } else { + $name = $firstName." ".$lastName; + } + + // ========vvv========= Update Rainloop Identity ========vvv========= + $identities = $this->Manager()->Actions()->GetIdentities($oAccount); + if(empty($identities)){ + // I am assuming [0] is the "default" identity... + $identity = \RainLoop\Model\Identity::NewInstanceFromAccount($oAccount); + array_push($identities, $identity); + } + + $identity = $identities[0]; + $identity->FromJSON(array('Email' => $sEmail, 'Name' => $name)); + // TODO Account::DoIdentityUpdate is possible if I knew how to use actoinParams + $result = $this->Manager()->Actions()->SetIdentities($oAccount, $identities); + $oLogger->Write('HMAILSERVER Identity Update Successful'); + // ========^^^========= Update Rainloop Idnetity ========^^^========= + $bResult = true; + } + else + { + $oLogger->Write('HMAILSERVER: Unknown account ('.$sEmail.')', \MailSo\Log\Enumerations\Type::ERROR); + } + } + else + { + $oLogger->Write('HMAILSERVER: Unknown domain ('.$sDomain.')', \MailSo\Log\Enumerations\Type::ERROR); + } + } + else + { + $oLogger->Write('HMAILSERVER: Auth error', \MailSo\Log\Enumerations\Type::ERROR); + } + } + catch (\Exception $oException) + { + if ($oLogger) + { + $oLogger->WriteException($oException); + } + } + + return $bResult; + } + + /** + * @return array + */ + public function configMapping() + { + return array( + \RainLoop\Plugins\Property::NewInstance('login')->SetLabel('HmailServer Admin Login') + ->SetDefaultValue('Administrator'), + \RainLoop\Plugins\Property::NewInstance('password')->SetLabel('HmailServer Admin Password') + ->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD) + ->SetDefaultValue('') + ); + } +}