Skip to content

Commit

Permalink
New convertIdFormat function
Browse files Browse the repository at this point in the history
  • Loading branch information
Garethp committed Apr 19, 2016
1 parent 64f90f8 commit 31bc6f0
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.7.6 - 2016-04-19
* Added a `API::convertIdFormat($itemId, $oldFormat, $destinationFormat, $mailbox)` function

## 0.7.5 - 2016-04-18
* Removed `NTLMSoapClient\Exchange`. Folded the few lines of functionality in to `NTLMSoapClient`
* Added `API::getServerTimezones($timezoneIDs = array(), $fullTimezoneData = false)`
Expand Down
1 change: 1 addition & 0 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ libraries, so that you can utilize the API beyond what has been simplified.
* [Impersonating Other Users](impersonation.php)
* [Accessing a Primary SMTP Mailbox](primarySmtpAddress.php)
* [Using the EWS Library with Office 365 and OAuth](authenticatingWithOAuth.php)
* [Converting EWS ID Formats](convertItemIdFormat.php)
16 changes: 16 additions & 0 deletions examples/basic/convertItemIdFormat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use jamesiarmes\PEWS\API;
use jamesiarmes\PEWS\API\Enumeration;
use jamesiarmes\PEWS\API\Type;

//Create and build the client
$api = API::withUsernameAndPassword('server', 'username', 'password');

$ews2007ItemId = new Type\ItemIdType($ews2007Id, $changeKey);
$ews2010ItemId = $api->convertIdFormat(
$ews2007ItemId,
Enumeration\IdFormatType::EWS_LEGACY_ID,
Enumeration\IdFormatType::EWS_ID,
'[email protected]'
);
26 changes: 26 additions & 0 deletions src/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,4 +565,30 @@ public function getServerTimezones($timezoneIDs = array(), $fullTimezoneData = f

return $timezones;
}

/**
* @param Type\ItemIdType $itemId
* @param $fromType
* @param $destinationType
* @param $mailbox
*
* @return Type\ItemIdType
*/
public function convertIdFormat(Type\ItemIdType $itemId, $fromType, $destinationType, $mailbox)
{
$result = $this->getClient()->ConvertId(array(
'DestinationFormat' => $destinationType,
'SourceIds' => array (
'AlternateId' => array(
'Format' => $fromType,
'Id' => $itemId->getId(),
'Mailbox' => $mailbox
)
)
));

$itemId->setId($result->getId());

return $itemId;
}
}
9 changes: 8 additions & 1 deletion src/API/NTLMSoapClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ class NTLMSoapClient extends SoapClient

protected $auth;

protected $callsWithoutTimezone = array(
'DeleteItem',
'SyncFolderItems',
'GetServerTimeZones',
'ConvertId'
);

/**
* @TODO: Make this smarter. It should know and search what headers to remove on what actions
*
Expand All @@ -104,7 +111,7 @@ public function __call($name, $args)
$this->ewsHeaders['impersonation']
);

if ($name != "DeleteItem" && $name != "SyncFolderItems" && $name != "GetServerTimeZones") {
if (!in_array($name, $this->callsWithoutTimezone)) {
$this->__default_headers[] = $this->ewsHeaders['timezone'];
}

Expand Down

0 comments on commit 31bc6f0

Please sign in to comment.