Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

plugin hmail-alias integration #2211

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions plugins/hmail-aliases/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions plugins/hmail-aliases/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Plugin which allows you to use hmail aliases
1 change: 1 addition & 0 deletions plugins/hmail-aliases/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
119 changes: 119 additions & 0 deletions plugins/hmail-aliases/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php

class HmailAliasesPlugin extends \RainLoop\Plugins\AbstractPlugin
{
public function Init()
{
$this->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('')
);
}
}