/usr/share/z-push/backend/kopano/mapiphpwrapper.php is in z-push-backend-kopano 2.3.8-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | <?php
/***********************************************
* File : mapiphpwrapper.php
* Project : Z-Push
* Descr : The ICS importer is very MAPI specific
* and needs to be wrapped, because we
* want all MAPI code to be separate from
* the rest of z-push. To do so all
* MAPI dependency are removed in this class.
* All the other importers are based on
* IChanges, not MAPI.
*
* Created : 14.02.2011
*
* Copyright 2007 - 2016 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
************************************************/
/**
* This is the PHP wrapper which strips MAPI information from
* the import interface of ICS. We get all the information about messages
* from MAPI here which are sent to the next importer, which will
* convert the data into WBXML which is streamed to the PDA
*/
class PHPWrapper {
private $importer;
private $mapiprovider;
private $store;
private $contentparameters;
private $folderid;
private $prefix;
/**
* Constructor of the PHPWrapper
*
* @param ressource $session
* @param ressource $store
* @param IImportChanges $importer incoming changes from ICS are forwarded here.
* @param string $folderid the folder this wrapper was configured for.
*
* @access public
* @return
*/
public function __construct($session, $store, $importer, $folderid) {
$this->importer = &$importer;
$this->store = $store;
$this->mapiprovider = new MAPIProvider($session, $this->store);
$this->folderid = $folderid;
$this->prefix = '';
if ($folderid) {
$folderidHex = bin2hex($folderid);
$folderid = ZPush::GetDeviceManager()->GetFolderIdForBackendId($folderidHex);
if ($folderid != $folderidHex) {
$this->prefix = $folderid . ':';
}
}
}
/**
* Configures additional parameters used for content synchronization
*
* @param ContentParameters $contentparameters
*
* @access public
* @return boolean
* @throws StatusException
*/
public function ConfigContentParameters($contentparameters) {
$this->contentparameters = $contentparameters;
}
/**
* Implement MAPI interface
*/
public function Config($stream, $flags = 0) {}
public function GetLastError($hresult, $ulflags, &$lpmapierror) {}
public function UpdateState($stream) { }
/**
* Imports a single message
*
* @param array $props
* @param long $flags
* @param object $retmapimessage
*
* @access public
* @return long
*/
public function ImportMessageChange($props, $flags, $retmapimessage) {
$sourcekey = $props[PR_SOURCE_KEY];
$parentsourcekey = $props[PR_PARENT_SOURCE_KEY];
$entryid = mapi_msgstore_entryidfromsourcekey($this->store, $parentsourcekey, $sourcekey);
if(!$entryid)
return SYNC_E_IGNORE;
$mapimessage = mapi_msgstore_openentry($this->store, $entryid);
try {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("PHPWrapper->ImportMessageChange(): Getting message from MAPIProvider, sourcekey: '%s', parentsourcekey: '%s', entryid: '%s'", bin2hex($sourcekey), bin2hex($parentsourcekey), bin2hex($entryid)));
$message = $this->mapiprovider->GetMessage($mapimessage, $this->contentparameters);
// strip or do not send private messages from shared folders to the device
if (MAPIUtils::IsMessageSharedAndPrivate($this->folderid, $mapimessage)) {
if ($message->SupportsPrivateStripping()) {
ZLog::Write(LOGLEVEL_DEBUG, "PHPWrapper->ImportMessageChange(): stripping data of private message from a shared folder");
$message->StripData(Streamer::STRIP_PRIVATE_DATA);
}
else {
ZLog::Write(LOGLEVEL_DEBUG, "PHPWrapper->ImportMessageChange(): ignoring private message from a shared folder");
return SYNC_E_IGNORE;
}
}
}
catch (SyncObjectBrokenException $mbe) {
$brokenSO = $mbe->GetSyncObject();
if (!$brokenSO) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("PHPWrapper->ImportMessageChange(): Catched SyncObjectBrokenException but broken SyncObject available"));
}
else {
if (!isset($brokenSO->id)) {
$brokenSO->id = "Unknown ID";
ZLog::Write(LOGLEVEL_ERROR, sprintf("PHPWrapper->ImportMessageChange(): Catched SyncObjectBrokenException but no ID of object set"));
}
ZPush::GetDeviceManager()->AnnounceIgnoredMessage(false, $brokenSO->id, $brokenSO);
}
// tell MAPI to ignore the message
return SYNC_E_IGNORE;
}
// substitute the MAPI SYNC_NEW_MESSAGE flag by a z-push proprietary flag
if ($flags == SYNC_NEW_MESSAGE) $message->flags = SYNC_NEWMESSAGE;
else $message->flags = $flags;
$this->importer->ImportMessageChange($this->prefix.bin2hex($sourcekey), $message);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("PHPWrapper->ImportMessageChange(): change for: '%s'", $this->prefix.bin2hex($sourcekey)));
// Tell MAPI it doesn't need to do anything itself, as we've done all the work already.
return SYNC_E_IGNORE;
}
/**
* Imports a list of messages to be deleted
*
* @param long $flags
* @param array $sourcekeys array with sourcekeys
*
* @access public
* @return
*/
public function ImportMessageDeletion($flags, $sourcekeys) {
$amount = count($sourcekeys);
if ($amount > 1000) {
throw new StatusException(sprintf("PHPWrapper->ImportMessageDeletion(): Received %d remove requests from ICS for folder '%s' (max. 1000 allowed). Triggering folder re-sync.", $amount, bin2hex($this->folderid)), SYNC_STATUS_INVALIDSYNCKEY, null, LOGLEVEL_ERROR);
}
else {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("PHPWrapper->ImportMessageDeletion(): Received %d remove requests from ICS", $amount));
}
foreach($sourcekeys as $sourcekey) {
// TODO if we would know that ICS is removing the message because it's outside the sync interval, we could send a $asSoftDelete = true to the importer. Could they pass that via $flags?
$this->importer->ImportMessageDeletion($this->prefix.bin2hex($sourcekey));
ZLog::Write(LOGLEVEL_DEBUG, sprintf("PHPWrapper->ImportMessageDeletion(): delete for :'%s'", $this->prefix.bin2hex($sourcekey)));
}
}
/**
* Imports a list of messages to be deleted
*
* @param mixed $readstates sourcekeys and message flags
*
* @access public
* @return
*/
public function ImportPerUserReadStateChange($readstates) {
foreach($readstates as $readstate) {
$this->importer->ImportMessageReadFlag($this->prefix.bin2hex($readstate["sourcekey"]), $readstate["flags"] & MSGFLAG_READ);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("PHPWrapper->ImportPerUserReadStateChange(): read for :'%s'", $this->prefix.bin2hex($readstate["sourcekey"])));
}
}
/**
* Imports a message move
* this is never called by ICS
*
* @access public
* @return
*/
public function ImportMessageMove($sourcekeysrcfolder, $sourcekeysrcmessage, $message, $sourcekeydestmessage, $changenumdestmessage) {
// Never called
}
/**
* Imports a single folder change
*
* @param array $props properties of the changed folder
*
* @access public
* @return
*/
function ImportFolderChange($props) {
$folder = $this->mapiprovider->GetFolder($props);
// do not import folder if there is something "wrong" with it
if ($folder === false)
return 0;
$this->importer->ImportFolderChange($folder);
return 0;
}
/**
* Imports a list of folders which are to be deleted
*
* @param long $flags
* @param mixed $sourcekeys array with sourcekeys
*
* @access public
* @return
*/
function ImportFolderDeletion($flags, $sourcekeys) {
foreach ($sourcekeys as $sourcekey) {
$this->importer->ImportFolderDeletion(SyncFolder::GetObject(ZPush::GetDeviceManager()->GetFolderIdForBackendId(bin2hex($sourcekey))));
}
return 0;
}
}
|