Commit 143210d0 authored by Sebastian Kummer's avatar Sebastian Kummer

ZP-1065 Extended IBackend, implemented in Backend and BackendKopano.

Released under the Affero GNU General Public License (AGPL) version 3.
parent 98f0ab56
......@@ -1476,6 +1476,37 @@ class BackendKopano implements IBackend, ISearchProvider {
}
}
/**
* Returns a KoeSignatures object.
*
* @access public
* @return KoeSignatures
*/
public function GetKoeSignatures() {
$sigs = new KoeSignatures();
$storeProps = mapi_getprops($this->store, array(PR_EC_WEBACCESS_SETTINGS_JSON));
// Check if property exists, if it doesn't exist then we can continue with empty an empty signature object
if (isset($storeProps[PR_EC_WEBACCESS_SETTINGS_JSON]) || MAPIUtils::GetError(PR_EC_WEBACCESS_SETTINGS_JSON, $storeProps) == MAPI_E_NOT_ENOUGH_MEMORY) {
$settings_string = MAPIUtils::readPropStream($this->store, PR_EC_WEBACCESS_SETTINGS_JSON);
if(!empty($settings_string)) {
$settings = json_decode($settings_string, true);
if (json_last_error()) {
ZLog::Write(LOGLEVEL_WARN, sprintf("KopanoBackend->GetKoeSignatures(): Error decoding JSON WebApp settings: %s", json_last_error()));
}
if (isset($settings['settings']['zarafa']['v1']['contexts']['mail']['signatures'])) {
// convert WebApp signatures into KoeSignatures object
$sigs->LoadSignaturesFromData($settings['settings']['zarafa']['v1']['contexts']['mail']['signatures']);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->GetKoeSignatures(): Found %d signatures - new '%s' - reply/fw: '%s' - hash: %s", count($sigs->GetSignatures()), $sigs->GetNewMessageSignature(), $sigs->GetReplyForwardSignature(), $sigs->GetHash()));
}
else {
ZLog::Write(LOGLEVEL_DEBUG, "KopanoBackend->GetKoeSignatures(): No signature data in WebApp settings");
}
}
}
return $sigs;
}
/**----------------------------------------------------------------------------------------------------------
* Private methods
*/
......
<?php
/***********************************************
* File : koesignatures.php
* Project : Z-Push
* Descr : Holds a list of signatures and signature options for KOE.
*
* Created : 06.02.2017
*
* Copyright 2007 - 2017 Zarafa Deutschland GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Consult LICENSE file for details
*************************************************/
class KoeSignatures {
private $all = array();
private $new_message;
private $replyforward_message;
private $hash;
/**
* Constructor
*
* @access public
*/
public function __construct() {
$this->GetHash();
}
/**
* Loads data from an array.
*
* @param array $data
*
* @access public
* @return void
*/
public function LoadSignaturesFromData($data) {
if (isset($data['all'])) {
foreach ($data['all'] as $id => $signature) {
$koeSig = KoeSignature::GetSignatureFromArray($id, $signature);
$this->AddSignature($koeSig);
}
}
if (isset($data['new_message'])) {
$this->SetNewMessageSignature($data['new_message']);
}
if (isset($data['replyforward_message'])) {
$this->SetReplyForwardSignature($data['replyforward_message']);
}
// update the hash
$this->GetHash();
}
/**
* Adds a KoeSignature object to the list.
*
* @param KoeSignature $koeSig
*
* @access public
* @return void
*/
public function AddSignature($koeSig) {
$this->all[$koeSig->id] = $koeSig;
}
/**
* Returns an array of KoeSignature objects.
*
* @access public
* @return array
*/
public function GetSignatures() {
return $this->all;
}
/**
* Returns a KoeSignature signature object or null if id is not available.
*
* @param KoeSignature $koeSig
*
* @access public
* @return KoeSignature | null
*/
public function GetSignature($id) {
return (isset($this->all[$id]) ? $this->all[$id] : null);
}
/**
* Sets the KoeSignature id to be used for new messages.
* The id is not verified if present.
*
* @param string $id
*
* @access public
* @return void
*/
public function SetNewMessageSignature($id) {
$this->new_message = $id;
}
/**
* Gets the KoeSignature id to be used for new messages.
*
* @access public
* @return string | null
*/
public function GetNewMessageSignature() {
return $this->new_message;
}
/**
* Sets the KoeSignature id to be used when replying or forwarding.
* The id is not verified if present.
*
* @param string $id
*
* @access public
* @return void
*/
public function SetReplyForwardSignature($id) {
$this->replyforward_message = $id;
}
/**
* Gets the KoeSignature id to be used when replying or forwarding.
*
* @access public
* @return string | null
*/
public function GetReplyForwardSignature() {
return $this->replyforward_message;
}
/**
* Returns the hash of the currently loaded data.
*
* @access public
* @return string
*/
public function GetHash() {
$this->hash = sha1(json_encode($this->all).$this->new_message.$this->replyforward_message);
return $this->hash;
}
}
/**
* Helper class holding a signature.
*/
class KoeSignature {
public $id;
public $name;
public $content;
public $isHTML;
/**
* Creates a new KoeSignature object from a data array.
*
* @param string $id
* @param array $data
*
* @access public
* @return KoeSignature
*/
public static function GetSignatureFromArray($id, array $data) {
$sig = new KoeSignature();
$sig->id = $id;
$sig->name = $data['name'];
$sig->content = $data['content'];
$sig->isHTML = (bool) $data['isHTML'];
return $sig;
}
}
\ No newline at end of file
......@@ -247,6 +247,16 @@ abstract class Backend implements IBackend {
return "not implemented-".gmdate("Y-m-d-H");
}
/**
* Returns a KoeSignatures object.
*
* @access public
* @return KoeSignatures
*/
public function GetKoeSignatures() {
return new KoeSignatures();
}
/**----------------------------------------------------------------------------------------------------------
* Protected methods for BackendStorage
......
......@@ -333,4 +333,12 @@ interface IBackend {
* @return string|boolean
*/
public function GetKoeGabBackendFolderId($foldername);
/**
* Returns a KoeSignatures object.
*
* @access public
* @return KoeSignatures
*/
public function GetKoeSignatures();
}
......@@ -73,6 +73,8 @@ return array(
'IpcMemcachedProvider' => $baseDir . '/backend/ipcmemcached/ipcmemcachedprovider.php',
'IpcSharedMemoryProvider' => $baseDir . '/backend/ipcsharedmemory/ipcsharedmemoryprovider.php',
'ItemOperations' => $baseDir . '/lib/request/itemoperations.php',
'KoeSignature' => $baseDir . '/lib/core/koesignatures.php',
'KoeSignatures' => $baseDir . '/lib/core/koesignatures.php',
'KopanoChangesWrapper' => $baseDir . '/backend/kopano/kopanochangeswrapper.php',
'Log' => $baseDir . '/lib/log/log.php',
'LoopDetection' => $baseDir . '/lib/core/loopdetection.php',
......
......@@ -80,6 +80,8 @@ class ComposerStaticInitd6749fc2fb9944bbe86b2b7d79a7852f
'IpcMemcachedProvider' => __DIR__ . '/../..' . '/backend/ipcmemcached/ipcmemcachedprovider.php',
'IpcSharedMemoryProvider' => __DIR__ . '/../..' . '/backend/ipcsharedmemory/ipcsharedmemoryprovider.php',
'ItemOperations' => __DIR__ . '/../..' . '/lib/request/itemoperations.php',
'KoeSignature' => __DIR__ . '/../..' . '/lib/core/koesignatures.php',
'KoeSignatures' => __DIR__ . '/../..' . '/lib/core/koesignatures.php',
'KopanoChangesWrapper' => __DIR__ . '/../..' . '/backend/kopano/kopanochangeswrapper.php',
'Log' => __DIR__ . '/../..' . '/lib/log/log.php',
'LoopDetection' => __DIR__ . '/../..' . '/lib/core/loopdetection.php',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment