Commit 220672cb authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #200 in ZP/z-push from...

Merge pull request #200 in ZP/z-push from bugfix/ZP-779-message-is-suddenly-unread-after-moving to develop

* commit '60b8fbe5':
  ZP-779 Remove unnecessary code.
  ZP-779 Only use folderid prefix in importer if it is the new int one. Fix Fetch() in Zarafa backend to work with new longids.
  ZP-779 Use folderid (if available) in serverentryid to identify message.
  ZP-779 Quick & dirty fix, by prepending the folder sourcekey to each message id. "Fixes" the issue, but is ugly.
parents 65dfd2eb 60b8fbe5
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
class ImportChangesICS implements IImportChanges { class ImportChangesICS implements IImportChanges {
private $folderid; private $folderid;
private $folderidHex;
private $store; private $store;
private $session; private $session;
private $flags; private $flags;
...@@ -71,6 +72,7 @@ class ImportChangesICS implements IImportChanges { ...@@ -71,6 +72,7 @@ class ImportChangesICS implements IImportChanges {
private $conflictsState; private $conflictsState;
private $cutoffdate; private $cutoffdate;
private $contentClass; private $contentClass;
private $prefix;
/** /**
* Constructor * Constructor
...@@ -86,12 +88,19 @@ class ImportChangesICS implements IImportChanges { ...@@ -86,12 +88,19 @@ class ImportChangesICS implements IImportChanges {
$this->session = $session; $this->session = $session;
$this->store = $store; $this->store = $store;
$this->folderid = $folderid; $this->folderid = $folderid;
$this->folderidHex = bin2hex($folderid);
$this->conflictsLoaded = false; $this->conflictsLoaded = false;
$this->cutoffdate = false; $this->cutoffdate = false;
$this->contentClass = false; $this->contentClass = false;
$this->prefix = '';
if ($folderid) { if ($folderid) {
$entryid = mapi_msgstore_entryidfromsourcekey($store, $folderid); $entryid = mapi_msgstore_entryidfromsourcekey($store, $folderid);
$folderidForBackendId = ZPush::GetDeviceManager()->GetFolderIdForBackendId($this->folderidHex);
// Only append backend id if the mapping backendid<->folderid is available.
if ($folderidForBackendId != $this->folderidHex) {
$this->prefix = $folderidForBackendId . ':';
}
} }
else { else {
$storeprops = mapi_getprops($store, array(PR_IPM_SUBTREE_ENTRYID)); $storeprops = mapi_getprops($store, array(PR_IPM_SUBTREE_ENTRYID));
...@@ -116,6 +125,9 @@ class ImportChangesICS implements IImportChanges { ...@@ -116,6 +125,9 @@ class ImportChangesICS implements IImportChanges {
$this->importer = mapi_openproperty($folder, PR_COLLECTOR, IID_IExchangeImportContentsChanges, 0 , 0); $this->importer = mapi_openproperty($folder, PR_COLLECTOR, IID_IExchangeImportContentsChanges, 0 , 0);
else else
$this->importer = mapi_openproperty($folder, PR_COLLECTOR, IID_IExchangeImportHierarchyChanges, 0 , 0); $this->importer = mapi_openproperty($folder, PR_COLLECTOR, IID_IExchangeImportHierarchyChanges, 0 , 0);
// TODO remove this log output in 2.3.X
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportChangesICS: prefix:'%s'", $this->prefix));
} }
/** /**
...@@ -348,20 +360,17 @@ class ImportChangesICS implements IImportChanges { ...@@ -348,20 +360,17 @@ class ImportChangesICS implements IImportChanges {
* @throws StatusException * @throws StatusException
*/ */
public function ImportMessageChange($id, $message) { public function ImportMessageChange($id, $message) {
$parentsourcekey = $this->folderid;
if($id)
$sourcekey = hex2bin($id);
$flags = 0; $flags = 0;
$props = array(); $props = array();
$props[PR_PARENT_SOURCE_KEY] = $parentsourcekey; $props[PR_PARENT_SOURCE_KEY] = $this->folderid;
// set the PR_SOURCE_KEY if available or mark it as new message // set the PR_SOURCE_KEY if available or mark it as new message
if($id) { if($id) {
$props[PR_SOURCE_KEY] = $sourcekey; list(, $sk) = MAPIUtils::SplitMessageId($id);
$props[PR_SOURCE_KEY] = hex2bin($sk);
// on editing an existing message, check if it is in the synchronization interval // on editing an existing message, check if it is in the synchronization interval
if (!$this->isMessageInSyncInterval($id)) if (!$this->isMessageInSyncInterval($sk))
throw new StatusException(sprintf("ImportChangesICS->ImportMessageChange('%s','%s'): Message is outside the sync interval. Data not saved.", $id, get_class($message)), SYNC_STATUS_SYNCCANNOTBECOMPLETED); throw new StatusException(sprintf("ImportChangesICS->ImportMessageChange('%s','%s'): Message is outside the sync interval. Data not saved.", $id, get_class($message)), SYNC_STATUS_SYNCCANNOTBECOMPLETED);
// check for conflicts // check for conflicts
...@@ -391,7 +400,8 @@ class ImportChangesICS implements IImportChanges { ...@@ -391,7 +400,8 @@ class ImportChangesICS implements IImportChanges {
throw new StatusException(sprintf("ImportChangesICS->ImportMessageChange('%s','%s'): Error, mapi_message_savechanges() failed: 0x%X", $id, get_class($message), mapi_last_hresult()), SYNC_STATUS_SYNCCANNOTBECOMPLETED); throw new StatusException(sprintf("ImportChangesICS->ImportMessageChange('%s','%s'): Error, mapi_message_savechanges() failed: 0x%X", $id, get_class($message), mapi_last_hresult()), SYNC_STATUS_SYNCCANNOTBECOMPLETED);
$sourcekeyprops = mapi_getprops($mapimessage, array (PR_SOURCE_KEY)); $sourcekeyprops = mapi_getprops($mapimessage, array (PR_SOURCE_KEY));
return bin2hex($sourcekeyprops[PR_SOURCE_KEY]);
return $this->prefix . bin2hex($sourcekeyprops[PR_SOURCE_KEY]);
} }
else else
throw new StatusException(sprintf("ImportChangesICS->ImportMessageChange('%s','%s'): Error updating object: 0x%X", $id, get_class($message), mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND); throw new StatusException(sprintf("ImportChangesICS->ImportMessageChange('%s','%s'): Error updating object: 0x%X", $id, get_class($message), mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND);
...@@ -407,8 +417,9 @@ class ImportChangesICS implements IImportChanges { ...@@ -407,8 +417,9 @@ class ImportChangesICS implements IImportChanges {
* @throws StatusException * @throws StatusException
*/ */
public function ImportMessageDeletion($id) { public function ImportMessageDeletion($id) {
list(,$sk) = MAPIUtils::SplitMessageId($id);
// check if the message is in the current syncinterval // check if the message is in the current syncinterval
if (!$this->isMessageInSyncInterval($id)) if (!$this->isMessageInSyncInterval($sk))
throw new StatusException(sprintf("ImportChangesICS->ImportMessageDeletion('%s'): Message is outside the sync interval and so far not deleted.", $id), SYNC_STATUS_OBJECTNOTFOUND); throw new StatusException(sprintf("ImportChangesICS->ImportMessageDeletion('%s'): Message is outside the sync interval and so far not deleted.", $id), SYNC_STATUS_OBJECTNOTFOUND);
// check for conflicts // check for conflicts
...@@ -422,8 +433,8 @@ class ImportChangesICS implements IImportChanges { ...@@ -422,8 +433,8 @@ class ImportChangesICS implements IImportChanges {
} }
// do a 'soft' delete so people can un-delete if necessary // do a 'soft' delete so people can un-delete if necessary
if(mapi_importcontentschanges_importmessagedeletion($this->importer, 1, array(hex2bin($id)))) if(mapi_importcontentschanges_importmessagedeletion($this->importer, 1, array(hex2bin($sk))))
throw new StatusException(sprintf("ImportChangesICS->ImportMessageDeletion('%s'): Error updating object: 0x%X", $id, mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND); throw new StatusException(sprintf("ImportChangesICS->ImportMessageDeletion('%s'): Error updating object: 0x%X", $sk, mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND);
return true; return true;
} }
...@@ -440,27 +451,45 @@ class ImportChangesICS implements IImportChanges { ...@@ -440,27 +451,45 @@ class ImportChangesICS implements IImportChanges {
* @throws StatusException * @throws StatusException
*/ */
public function ImportMessageReadFlag($id, $flags) { public function ImportMessageReadFlag($id, $flags) {
// check if the message is in the current syncinterval list($fsk,$sk) = MAPIUtils::SplitMessageId($id);
if (!$this->isMessageInSyncInterval($id))
throw new StatusException(sprintf("ImportChangesICS->ImportMessageReadFlag('%s','%d'): Message is outside the sync interval. Flags not updated.", $id, $flags), SYNC_STATUS_OBJECTNOTFOUND);
// check for conflicts // read flag change for our current folder
/* if ($this->folderidHex == $fsk || empty($fsk)) {
* Checking for conflicts is correct at this point, but is a very expensive operation.
* If the message was deleted, only an error will be shown.
*
$this->lazyLoadConflicts();
if($this->memChanges->IsDeleted($id)) {
ZLog::Write(LOGLEVEL_INFO, sprintf("ImportChangesICS->ImportMessageReadFlag('%s'): Conflict detected. Data is already deleted. Request will be ignored.", $id));
return true;
}
*/
$readstate = array ( "sourcekey" => hex2bin($id), "flags" => $flags); // check if the message is in the current syncinterval
if (!$this->isMessageInSyncInterval($sk))
throw new StatusException(sprintf("ImportChangesICS->ImportMessageReadFlag('%s','%d'): Message is outside the sync interval. Flags not updated.", $id, $flags), SYNC_STATUS_OBJECTNOTFOUND);
if(!mapi_importcontentschanges_importperuserreadstatechange($this->importer, array($readstate) )) // check for conflicts
throw new StatusException(sprintf("ImportChangesICS->ImportMessageReadFlag('%s','%d'): Error setting read state: 0x%X", $id, $flags, mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND); /*
* Checking for conflicts is correct at this point, but is a very expensive operation.
* If the message was deleted, only an error will be shown.
*
$this->lazyLoadConflicts();
if($this->memChanges->IsDeleted($id)) {
ZLog::Write(LOGLEVEL_INFO, sprintf("ImportChangesICS->ImportMessageReadFlag('%s'): Conflict detected. Data is already deleted. Request will be ignored.", $id));
return true;
}
*/
$readstate = array ( "sourcekey" => hex2bin($sk), "flags" => $flags);
if(!mapi_importcontentschanges_importperuserreadstatechange($this->importer, array($readstate) ))
throw new StatusException(sprintf("ImportChangesICS->ImportMessageReadFlag('%s','%d'): Error setting read state: 0x%X", $id, $flags, mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND);
}
// yeah OL sucks - ZP-779
else {
if (ctype_digit($fsk)) {
$fsk = ZPush::GetDeviceManager()->GetBackendIdForFolderId($fsk);
}
$entryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($fsk), hex2bin($sk));
$realMessage = mapi_msgstore_openentry($this->store, $entryid);
$flag = 0;
if ($flags == 0)
$flag |= CLEAR_READ_FLAG;
$p = mapi_message_setreadflag($realMessage, $flag);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportChangesICS->ImportMessageReadFlag('%s','%d'): setting readflag on message: 0x%X", $id, $flags, mapi_last_hresult()));
}
return true; return true;
} }
...@@ -482,13 +511,14 @@ class ImportChangesICS implements IImportChanges { ...@@ -482,13 +511,14 @@ class ImportChangesICS implements IImportChanges {
* @throws StatusException * @throws StatusException
*/ */
public function ImportMessageMove($id, $newfolder) { public function ImportMessageMove($id, $newfolder) {
list(,$sk) = MAPIUtils::SplitMessageId($id);
if (strtolower($newfolder) == strtolower(bin2hex($this->folderid)) ) if (strtolower($newfolder) == strtolower(bin2hex($this->folderid)) )
throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, source and destination are equal", $id, $newfolder), SYNC_MOVEITEMSSTATUS_SAMESOURCEANDDEST); throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, source and destination are equal", $id, $newfolder), SYNC_MOVEITEMSSTATUS_SAMESOURCEANDDEST);
// Get the entryid of the message we're moving // Get the entryid of the message we're moving
$entryid = mapi_msgstore_entryidfromsourcekey($this->store, $this->folderid, hex2bin($id)); $entryid = mapi_msgstore_entryidfromsourcekey($this->store, $this->folderid, hex2bin($sk));
if(!$entryid) if(!$entryid)
throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to resolve source message id", $id, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID); throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to resolve source message id", $sk, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID);
//open the source message //open the source message
$srcmessage = mapi_msgstore_openentry($this->store, $entryid); $srcmessage = mapi_msgstore_openentry($this->store, $entryid);
...@@ -498,55 +528,55 @@ class ImportChangesICS implements IImportChanges { ...@@ -498,55 +528,55 @@ class ImportChangesICS implements IImportChanges {
if ($newfolder == ZPush::GetBackend()->GetWasteBasket()) { if ($newfolder == ZPush::GetBackend()->GetWasteBasket()) {
$code = SYNC_MOVEITEMSSTATUS_SUCCESS; $code = SYNC_MOVEITEMSSTATUS_SUCCESS;
} }
throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to open source message: 0x%X", $id, $newfolder, mapi_last_hresult()), $code); throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to open source message: 0x%X", $sk, $newfolder, mapi_last_hresult()), $code);
} }
// check if the source message is in the current syncinterval // check if the source message is in the current syncinterval
if (!$this->isMessageInSyncInterval($id)) if (!$this->isMessageInSyncInterval($sk))
throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Source message is outside the sync interval. Move not performed.", $id, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID); throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Source message is outside the sync interval. Move not performed.", $sk, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID);
// get correct mapi store for the destination folder // get correct mapi store for the destination folder
$dststore = ZPush::GetBackend()->GetMAPIStoreForFolderId(ZPush::GetAdditionalSyncFolderStore($newfolder), $newfolder); $dststore = ZPush::GetBackend()->GetMAPIStoreForFolderId(ZPush::GetAdditionalSyncFolderStore($newfolder), $newfolder);
if ($dststore === false) if ($dststore === false)
throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to open store of destination folder", $id, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDDESTID); throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to open store of destination folder", $sk, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDDESTID);
$dstentryid = mapi_msgstore_entryidfromsourcekey($dststore, hex2bin($newfolder)); $dstentryid = mapi_msgstore_entryidfromsourcekey($dststore, hex2bin($newfolder));
if(!$dstentryid) if(!$dstentryid)
throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to resolve destination folder", $id, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDDESTID); throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to resolve destination folder", $sk, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDDESTID);
$dstfolder = mapi_msgstore_openentry($dststore, $dstentryid); $dstfolder = mapi_msgstore_openentry($dststore, $dstentryid);
if(!$dstfolder) if(!$dstfolder)
throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to open destination folder", $id, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDDESTID); throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to open destination folder", $sk, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDDESTID);
$newmessage = mapi_folder_createmessage($dstfolder); $newmessage = mapi_folder_createmessage($dstfolder);
if (!$newmessage) if (!$newmessage)
throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to create message in destination folder: 0x%X", $id, $newfolder, mapi_last_hresult()), SYNC_MOVEITEMSSTATUS_INVALIDDESTID); throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to create message in destination folder: 0x%X", $sk, $newfolder, mapi_last_hresult()), SYNC_MOVEITEMSSTATUS_INVALIDDESTID);
// Copy message // Copy message
mapi_copyto($srcmessage, array(), array(), $newmessage); mapi_copyto($srcmessage, array(), array(), $newmessage);
if (mapi_last_hresult()) if (mapi_last_hresult())
throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, copy to destination message failed: 0x%X", $id, $newfolder, mapi_last_hresult()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE); throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, copy to destination message failed: 0x%X", $sk, $newfolder, mapi_last_hresult()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE);
$srcfolderentryid = mapi_msgstore_entryidfromsourcekey($this->store, $this->folderid); $srcfolderentryid = mapi_msgstore_entryidfromsourcekey($this->store, $this->folderid);
if(!$srcfolderentryid) if(!$srcfolderentryid)
throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to resolve source folder", $id, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID); throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to resolve source folder", $sk, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID);
$srcfolder = mapi_msgstore_openentry($this->store, $srcfolderentryid); $srcfolder = mapi_msgstore_openentry($this->store, $srcfolderentryid);
if (!$srcfolder) if (!$srcfolder)
throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to open source folder: 0x%X", $id, $newfolder, mapi_last_hresult()), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID); throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to open source folder: 0x%X", $sk, $newfolder, mapi_last_hresult()), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID);
// Save changes // Save changes
mapi_savechanges($newmessage); mapi_savechanges($newmessage);
if (mapi_last_hresult()) if (mapi_last_hresult())
throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, mapi_savechanges() failed: 0x%X", $id, $newfolder, mapi_last_hresult()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE); throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, mapi_savechanges() failed: 0x%X", $sk, $newfolder, mapi_last_hresult()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE);
// Delete the old message // Delete the old message
if (!mapi_folder_deletemessages($srcfolder, array($entryid))) if (!mapi_folder_deletemessages($srcfolder, array($entryid)))
throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, delete of source message failed: 0x%X. Possible duplicates.", $id, $newfolder, mapi_last_hresult()), SYNC_MOVEITEMSSTATUS_SOURCEORDESTLOCKED); throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, delete of source message failed: 0x%X. Possible duplicates.", $sk, $newfolder, mapi_last_hresult()), SYNC_MOVEITEMSSTATUS_SOURCEORDESTLOCKED);
$sourcekeyprops = mapi_getprops($newmessage, array (PR_SOURCE_KEY)); $sourcekeyprops = mapi_getprops($newmessage, array (PR_SOURCE_KEY));
if (isset($sourcekeyprops[PR_SOURCE_KEY]) && $sourcekeyprops[PR_SOURCE_KEY]) if (isset($sourcekeyprops[PR_SOURCE_KEY]) && $sourcekeyprops[PR_SOURCE_KEY])
return bin2hex($sourcekeyprops[PR_SOURCE_KEY]); return $this->prefix . bin2hex($sourcekeyprops[PR_SOURCE_KEY]);
return false; return false;
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* *
* Created : 14.02.2011 * Created : 14.02.2011
* *
* Copyright 2007 - 2015 Zarafa Deutschland GmbH * Copyright 2007 - 2016 Zarafa Deutschland GmbH
* *
* This program is free software: you can redistribute it and/or modify * 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, * it under the terms of the GNU Affero General Public License, version 3,
...@@ -60,6 +60,7 @@ class PHPWrapper { ...@@ -60,6 +60,7 @@ class PHPWrapper {
private $store; private $store;
private $contentparameters; private $contentparameters;
private $folderid; private $folderid;
private $prefix;
/** /**
...@@ -78,6 +79,15 @@ class PHPWrapper { ...@@ -78,6 +79,15 @@ class PHPWrapper {
$this->store = $store; $this->store = $store;
$this->mapiprovider = new MAPIProvider($session, $this->store); $this->mapiprovider = new MAPIProvider($session, $this->store);
$this->folderid = $folderid; $this->folderid = $folderid;
$folderidHex = bin2hex($folderid);
$this->prefix = '';
$folderid = ZPush::GetDeviceManager()->GetFolderIdForBackendId($folderidHex);
if ($folderid != $folderidHex) {
$this->prefix = $folderid . ':';
}
// TODO remove this log output in 2.3.X
ZLog::Write(LOGLEVEL_DEBUG, sprintf("PHPWrapper: prefix:'%s'", $this->prefix));
} }
/** /**
...@@ -144,7 +154,8 @@ class PHPWrapper { ...@@ -144,7 +154,8 @@ class PHPWrapper {
if ($flags == SYNC_NEW_MESSAGE) $message->flags = SYNC_NEWMESSAGE; if ($flags == SYNC_NEW_MESSAGE) $message->flags = SYNC_NEWMESSAGE;
else $message->flags = $flags; else $message->flags = $flags;
$this->importer->ImportMessageChange(bin2hex($sourcekey), $message); $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. // Tell MAPI it doesn't need to do anything itself, as we've done all the work already.
return SYNC_E_IGNORE; return SYNC_E_IGNORE;
...@@ -168,7 +179,8 @@ class PHPWrapper { ...@@ -168,7 +179,8 @@ class PHPWrapper {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("PHPWrapper->ImportMessageDeletion(): Received %d remove requests from ICS", $amount)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("PHPWrapper->ImportMessageDeletion(): Received %d remove requests from ICS", $amount));
} }
foreach($sourcekeys as $sourcekey) { foreach($sourcekeys as $sourcekey) {
$this->importer->ImportMessageDeletion(bin2hex($sourcekey)); $this->importer->ImportMessageDeletion($this->prefix.bin2hex($sourcekey));
ZLog::Write(LOGLEVEL_DEBUG, sprintf("PHPWrapper->ImportMessageDeletion(): delete for :'%s'", $this->prefix.bin2hex($sourcekey)));
} }
} }
...@@ -182,7 +194,8 @@ class PHPWrapper { ...@@ -182,7 +194,8 @@ class PHPWrapper {
*/ */
public function ImportPerUserReadStateChange($readstates) { public function ImportPerUserReadStateChange($readstates) {
foreach($readstates as $readstate) { foreach($readstates as $readstate) {
$this->importer->ImportMessageReadFlag(bin2hex($readstate["sourcekey"]), $readstate["flags"] & MSGFLAG_READ); $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"])));
} }
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Created : 14.02.2011 * Created : 14.02.2011
* *
* Copyright 2007 - 2013 Zarafa Deutschland GmbH * Copyright 2007 - 2013, 2016 Zarafa Deutschland GmbH
* *
* This program is free software: you can redistribute it and/or modify * 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, * it under the terms of the GNU Affero General Public License, version 3,
...@@ -619,4 +619,20 @@ class MAPIUtils { ...@@ -619,4 +619,20 @@ class MAPIUtils {
} }
// TODO check if we need to do this for encrypted (and signed?) message as well // TODO check if we need to do this for encrypted (and signed?) message as well
} }
/**
* Splits the id into folder id and message id parts. A colon in the $id indicates
* that the id has folderid:messageid format.
*
* @param string $id
*
* @access public
* @return array
*/
public static function SplitMessageId($id) {
if (strpos($id, ':') !== false) {
return explode(':', $id);
}
return array(null, $id);
}
} }
...@@ -595,15 +595,17 @@ class BackendZarafa implements IBackend, ISearchProvider { ...@@ -595,15 +595,17 @@ class BackendZarafa implements IBackend, ISearchProvider {
* @throws StatusException * @throws StatusException
*/ */
public function Fetch($folderid, $id, $contentparameters) { public function Fetch($folderid, $id, $contentparameters) {
// id might be in the new longid format, so we have to split it here
list($fsk, $sk) = MAPIUtils::SplitMessageId($id);
// get the entry id of the message // get the entry id of the message
$entryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($folderid), hex2bin($id)); $entryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($folderid), hex2bin($sk));
if(!$entryid) if(!$entryid)
throw new StatusException(sprintf("BackendZarafa->Fetch('%s','%s'): Error getting entryid: 0x%X", $folderid, $id, mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND); throw new StatusException(sprintf("BackendZarafa->Fetch('%s','%s'): Error getting entryid: 0x%X", $folderid, $sk, mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND);
// open the message // open the message
$message = mapi_msgstore_openentry($this->store, $entryid); $message = mapi_msgstore_openentry($this->store, $entryid);
if(!$message) if(!$message)
throw new StatusException(sprintf("BackendZarafa->Fetch('%s','%s'): Error, unable to open message: 0x%X", $folderid, $id, mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND); throw new StatusException(sprintf("BackendZarafa->Fetch('%s','%s'): Error, unable to open message: 0x%X", $folderid, $sk, mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND);
// convert the mapi message into a SyncObject and return it // convert the mapi message into a SyncObject and return it
$mapiprovider = new MAPIProvider($this->session, $this->store); $mapiprovider = new MAPIProvider($this->session, $this->store);
......
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