Commit 350ac224 authored by Manfred Kutas's avatar Manfred Kutas

ZP-745 Added BodyPartPreference class. Read body part preference from

incoming WBXML and save it to content parameters.

Released under the Affero GNU General Public License (AGPL) version 3.
parent d6e0867c
<?php
/***********************************************
* File : bodypartpreference.php
* Project : Z-Push
* Descr : Holds body part preference data
*
* Created : 13.07.2017
*
* Copyright 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 BodyPartPreference extends StateObject {
protected $unsetdata = array( 'truncationsize' => false,
'allornone' => false,
'preview' => false,
);
/**
* Expected magic getters and setters.
*
* GetTruncationSize() + SetTruncationSize()
* GetAllOrNone() + SetAllOrNone()
* GetPreview() + SetPreview()
*/
/**
* Indicates if this object has values.
*
* @access public
* @return boolean
*/
public function HasValues() {
return (count($this->data) > 0);
}
}
...@@ -55,13 +55,19 @@ class ContentParameters extends StateObject { ...@@ -55,13 +55,19 @@ class ContentParameters extends StateObject {
/** /**
* Overwrite StateObject->__call so we are able to handle ContentParameters->BodyPreference() * Overwrite StateObject->__call so we are able to handle ContentParameters->BodyPreference()
* and ContentParameters->BodyPartPreference().
* *
* @access public * @access public
* @return mixed * @return mixed
*/ */
public function __call($name, $arguments) { public function __call($name, $arguments) {
if ($name === "BodyPreference") if ($name === "BodyPreference") {
return $this->BodyPreference($arguments[0]); return $this->BodyPreference($arguments[0]);
}
if ($name === "BodyPartPreference") {
return $this->BodyPartPreference($arguments[0]);
}
return parent::__call($name, $arguments); return parent::__call($name, $arguments);
} }
...@@ -90,6 +96,30 @@ class ContentParameters extends StateObject { ...@@ -90,6 +96,30 @@ class ContentParameters extends StateObject {
} }
} }
/**
* Instantiates/returns the bodypartpreference object for a type.
*
* @param int $type
*
* @access public
* @return int/boolean returns false if value is not defined
*/
public function BodyPartPreference($type) {
if (!isset($this->bodypartpref)) {
$this->bodypartpref = array();
}
if (isset($this->bodypartpref[$type])) {
return $this->bodypartpref[$type];
}
$asb = new BodyPartPreference();
$arr = (array)$this->bodypartpref;
$arr[$type] = $asb;
$this->bodypartpref = $arr;
return $asb;
}
/** /**
* Returns available body preference objects * Returns available body preference objects
* *
...@@ -104,6 +134,20 @@ class ContentParameters extends StateObject { ...@@ -104,6 +134,20 @@ class ContentParameters extends StateObject {
return array_keys($this->bodypref); return array_keys($this->bodypref);
} }
/**
* Returns available body part preference objects.
*
* @access public
* @return array/boolean returns false if the client's body preference is not available
*/
public function GetBodyPartPreference() {
if (!isset($this->bodypartpref) || !(is_array($this->bodypartpref) || empty($this->bodypartpref))) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ContentParameters->GetBodyPartPreference(): bodypartpref is empty or not set"));
return false;
}
return array_keys($this->bodypartpref);
}
/** /**
* Called before the StateObject is serialized * Called before the StateObject is serialized
* *
......
...@@ -151,6 +151,37 @@ class ItemOperations extends RequestProcessor { ...@@ -151,6 +151,37 @@ class ItemOperations extends RequestProcessor {
return false;//SYNC_AIRSYNCBASE_BODYPREFERENCE return false;//SYNC_AIRSYNCBASE_BODYPREFERENCE
} }
if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_BODYPARTPREFERENCE)) {
if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_TYPE)) {
$bpptype = self::$decoder->getElementContent();
$operation["cpo"]->BodyPartPreference($bpptype);
if (!self::$decoder->getElementEndTag()) {
return false;
}
}
if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_TRUNCATIONSIZE)) {
$operation["cpo"]->BodyPartPreference($bpptype)->SetTruncationSize(self::$decoder->getElementContent());
if(!self::$decoder->getElementEndTag())
return false;
}
if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_ALLORNONE)) {
$operation["cpo"]->BodyPartPreference($bpptype)->SetAllOrNone(self::$decoder->getElementContent());
if(!self::$decoder->getElementEndTag())
return false;
}
if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_PREVIEW)) {
$operation["cpo"]->BodyPartPreference($bpptype)->SetPreview(self::$decoder->getElementContent());
if(!self::$decoder->getElementEndTag())
return false;
}
if (!self::$decoder->getElementEndTag())
return false;
}
if(self::$decoder->getElementStartTag(SYNC_MIMESUPPORT)) { if(self::$decoder->getElementStartTag(SYNC_MIMESUPPORT)) {
$operation["cpo"]->SetMimeSupport(self::$decoder->getElementContent()); $operation["cpo"]->SetMimeSupport(self::$decoder->getElementContent());
if(!self::$decoder->getElementEndTag()) if(!self::$decoder->getElementEndTag())
......
...@@ -247,6 +247,37 @@ class Search extends RequestProcessor { ...@@ -247,6 +247,37 @@ class Search extends RequestProcessor {
return false; return false;
} }
if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_BODYPARTPREFERENCE)) {
if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_TYPE)) {
$bpptype = self::$decoder->getElementContent();
$cpo->BodyPartPreference($bpptype);
if (!self::$decoder->getElementEndTag()) {
return false;
}
}
if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_TRUNCATIONSIZE)) {
$cpo->BodyPartPreference($bpptype)->SetTruncationSize(self::$decoder->getElementContent());
if(!self::$decoder->getElementEndTag())
return false;
}
if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_ALLORNONE)) {
$cpo->BodyPartPreference($bpptype)->SetAllOrNone(self::$decoder->getElementContent());
if(!self::$decoder->getElementEndTag())
return false;
}
if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_PREVIEW)) {
$cpo->BodyPartPreference($bpptype)->SetPreview(self::$decoder->getElementContent());
if(!self::$decoder->getElementEndTag())
return false;
}
if (!self::$decoder->getElementEndTag())
return false;
}
if(self::$decoder->getElementStartTag(SYNC_RIGHTSMANAGEMENT_SUPPORT)) { if(self::$decoder->getElementStartTag(SYNC_RIGHTSMANAGEMENT_SUPPORT)) {
$cpo->SetRmSupport(self::$decoder->getElementContent()); $cpo->SetRmSupport(self::$decoder->getElementContent());
if(!self::$decoder->getElementEndTag()) if(!self::$decoder->getElementEndTag())
......
...@@ -369,6 +369,37 @@ class Sync extends RequestProcessor { ...@@ -369,6 +369,37 @@ class Sync extends RequestProcessor {
return false; return false;
} }
if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_BODYPARTPREFERENCE)) {
if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_TYPE)) {
$bpptype = self::$decoder->getElementContent();
$spa->BodyPartPreference($bpptype);
if (!self::$decoder->getElementEndTag()) {
return false;
}
}
if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_TRUNCATIONSIZE)) {
$spa->BodyPartPreference($bpptype)->SetTruncationSize(self::$decoder->getElementContent());
if(!self::$decoder->getElementEndTag())
return false;
}
if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_ALLORNONE)) {
$spa->BodyPartPreference($bpptype)->SetAllOrNone(self::$decoder->getElementContent());
if(!self::$decoder->getElementEndTag())
return false;
}
if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_PREVIEW)) {
$spa->BodyPartPreference($bpptype)->SetPreview(self::$decoder->getElementContent());
if(!self::$decoder->getElementEndTag())
return false;
}
if (!self::$decoder->getElementEndTag())
return false;
}
if (self::$decoder->getElementStartTag(SYNC_RIGHTSMANAGEMENT_SUPPORT)) { if (self::$decoder->getElementStartTag(SYNC_RIGHTSMANAGEMENT_SUPPORT)) {
$spa->SetRmSupport(self::$decoder->getElementContent()); $spa->SetRmSupport(self::$decoder->getElementContent());
if (!self::$decoder->getElementEndTag()) if (!self::$decoder->getElementEndTag())
......
...@@ -33,6 +33,7 @@ return array( ...@@ -33,6 +33,7 @@ return array(
'BackendZarafa' => $baseDir . '/backend/kopano/kopano.php', 'BackendZarafa' => $baseDir . '/backend/kopano/kopano.php',
'BaseException' => $baseDir . '/backend/kopano/mapi/class.baseexception.php', 'BaseException' => $baseDir . '/backend/kopano/mapi/class.baseexception.php',
'BaseRecurrence' => $baseDir . '/backend/kopano/mapi/class.baserecurrence.php', 'BaseRecurrence' => $baseDir . '/backend/kopano/mapi/class.baserecurrence.php',
'BodyPartPreference' => $baseDir . '/lib/core/bodypartpreference.php',
'BodyPreference' => $baseDir . '/lib/core/bodypreference.php', 'BodyPreference' => $baseDir . '/lib/core/bodypreference.php',
'CalDAVClient' => $baseDir . '/include/z_caldav.php', 'CalDAVClient' => $baseDir . '/include/z_caldav.php',
'CalendarInfo' => $baseDir . '/include/z_caldav.php', 'CalendarInfo' => $baseDir . '/include/z_caldav.php',
......
...@@ -40,6 +40,7 @@ class ComposerStaticInitd6749fc2fb9944bbe86b2b7d79a7852f ...@@ -40,6 +40,7 @@ class ComposerStaticInitd6749fc2fb9944bbe86b2b7d79a7852f
'BackendZarafa' => __DIR__ . '/../..' . '/backend/kopano/kopano.php', 'BackendZarafa' => __DIR__ . '/../..' . '/backend/kopano/kopano.php',
'BaseException' => __DIR__ . '/../..' . '/backend/kopano/mapi/class.baseexception.php', 'BaseException' => __DIR__ . '/../..' . '/backend/kopano/mapi/class.baseexception.php',
'BaseRecurrence' => __DIR__ . '/../..' . '/backend/kopano/mapi/class.baserecurrence.php', 'BaseRecurrence' => __DIR__ . '/../..' . '/backend/kopano/mapi/class.baserecurrence.php',
'BodyPartPreference' => __DIR__ . '/../..' . '/lib/core/bodypartpreference.php',
'BodyPreference' => __DIR__ . '/../..' . '/lib/core/bodypreference.php', 'BodyPreference' => __DIR__ . '/../..' . '/lib/core/bodypreference.php',
'CalDAVClient' => __DIR__ . '/../..' . '/include/z_caldav.php', 'CalDAVClient' => __DIR__ . '/../..' . '/include/z_caldav.php',
'CalendarInfo' => __DIR__ . '/../..' . '/include/z_caldav.php', 'CalendarInfo' => __DIR__ . '/../..' . '/include/z_caldav.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