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

plugin hmail-alias integration #1863

Open
wants to merge 1 commit 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

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
113 changes: 113 additions & 0 deletions plugins/hmail-aliases/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

class HmailAliasesPlugin extends \RainLoop\Plugins\AbstractPlugin
{
public function Init()
{
$this->addHook('event.login-post-login-provide', 'loginPostLoginProvide');
}

public function Supported()
{
if (!class_exists('mysqli')) {
return 'The PHP exention mysqli must be installed to use this plugin';
}

return '';
}

/**
* @param \RainLoop\Model\Account $oAccount
* @throws \RainLoop\Exceptions\ClientException
*/
public function loginPostLoginProvide(\RainLoop\Model\Account &$oAccount)
{
$dbservername = \trim($this->Config()->Get('plugin', 'hamilserver', ''));
$dbusername = \trim($this->Config()->Get('plugin', 'hmaildbusername', ''));
$dbpassword = \trim($this->Config()->Get('plugin', 'hmaildbpassword', ''));
$dbname = \trim($this->Config()->Get('plugin', 'hmaildbtable', ''));
$dbport = \trim($this->Config()->Get('plugin', 'hmaildbport', ''));
$datadir = \trim($this->Config()->Get('plugin', 'rainloopDatalocation', ''));

if ($datadir != ""){
$userpath = $datadir.'data/_data_/_default_/storage/cfg/'.substr($oAccount->Email(), 0, 2).'/'.$oAccount->Email().'/identities';
} else {
$userpath = APP_INDEX_ROOT_PATH.'_data_/_default_/storage/cfg/'.substr($oAccount->Email(), 0, 2).'/'.$oAccount->Email().'/identities';
}

$hmailconn = mysqli_connect($dbservername, $dbusername, $dbpassword, $dbname, $dbport);

// Check connection
if (!$hmailconn) {
echo "Hmail-aliases: connection to db failed";
return;
}
//Get aliases
$result = $hmailconn->query("SELECT * FROM " . $dbname . ".hm_aliases WHERE aliasvalue='".$oAccount->Email()."'");

if ($result->num_rows > 0) {
$newidentitiesobj = array();

//Get user account
$result2 = $hmailconn->query("SELECT * FROM " . $dbname . ".hm_accounts WHERE accountaddress='".$oAccount->Email()."'");
$result2 = $result2->fetch_assoc();
$firstname = $result2['accountpersonfirstname'];
$lastname = $result2['accountpersonlastname'];

if ($firstname == "" && $lastname == "") {
$name = "";
} else {
$name = $firstname." ".$lastname;
}

//Get existing settings. If not a alias created by hmail. Transfer settings to the new array.
$identities = file_get_contents($userpath, true);
if ($identities != "") {
$identities = json_decode($identities, true);
error_log(print_r($identities, true));
foreach ($identities as $row) {
if (strpos($row['Id'], 'HMAIL') === false) {
array_push($newidentitiesobj, $row);
}
}
}

// output data of each row
while ($row = $result->fetch_assoc()) {
$obj = array();
$obj['Id'] = "HMAIL".base64_encode($row["aliasname"]);
$obj['Email'] = $row["aliasname"];
$obj['Name'] = $name;
$obj['ReplyTo'] = "";
$obj['Bcc'] = "";
$obj['Signature'] = "";
$obj['SignatureInsertBefore'] = false;
array_push($newidentitiesobj, $obj);
}
file_put_contents($userpath, json_encode($newidentitiesobj));
}
}

/**
* @return array
*/
public function configMapping()
{
return array(
\RainLoop\Plugins\Property::NewInstance('hamilserver')->SetLabel('db-host')
->SetDefaultValue('localhost'),
\RainLoop\Plugins\Property::NewInstance('hmaildbusername')->SetLabel('db-username')
->SetDefaultValue(''),
\RainLoop\Plugins\Property::NewInstance('hmaildbpassword')->SetLabel('db-password')
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD),
\RainLoop\Plugins\Property::NewInstance('hmaildbtable')->SetLabel('db-table')
->SetDefaultValue('mailserver'),
\RainLoop\Plugins\Property::NewInstance('hmaildbport')->SetLabel('db-port')
->SetDefaultValue('3306')
->SetDescription('Connect to mysql hmailserver. The user must have rights to read "hm_aliases" table.'),
\RainLoop\Plugins\Property::NewInstance('rainloopDatalocation')->SetLabel('Data folder location')
->SetDefaultValue('')
->SetDescription('Incase of custom data directory location. Eg. nextcloud/owncloud version (Leave blank for default)')
);
}
}