1

With php-ews is there a possibility to copy a message from an inbox to other user's inbox?

The goal is that a message is created by php-ews in a web interface, saved to a shared inbox and after this save a copy of the message to user's inbox.

My code so far:

$id = $mail_items[$i]->ItemId->Id;
$change_key = $mail_items[$i]->ItemId->ChangeKey;

$request = new EWSType_CopyItemType();
$request->ToFolderId->FolderId->Id = $user_folder_id;
$request->ToFolderId->FolderId->ChangeKey = $user_folder_ckey;
$request->ItemIds->ItemId->Id = $id;
$request->ItemIds->ItemId->ChangeKey = $change_key;
$response = $ews->CopyItem($request);

The message does not appear in the other user's inbox. Thanks!

S. Klicek
  • 55
  • 9
  • What response are you getting from that? – Gareth Parker Jun 03 '16 at 08:05
  • Response is:The EWS Id is in EwsLegacyId format which is not supoorted by the Exchange version specified by your request – S. Klicek Jun 03 '16 at 09:54
  • 1
    You're trying to use a Exchange 2007 ItemId with Exchange2010. You need to either convert the ID or get it again from the server – Gareth Parker Jun 03 '16 at 13:02
  • Do you have a short code example to convert the ID? – S. Klicek Jun 03 '16 at 13:39
  • I can only show you on my own library, which is similar to the one you're using but more modern. Using mine would look like this https://github.com/Garethp/php-ews/blob/master/examples/basic/convertItemIdFormat.php, but you can just perform a `ConvertId` operation (documentation here https://msdn.microsoft.com/en-us/library/office/bb799665(v=exchg.150).aspx ) – Gareth Parker Jun 03 '16 at 14:37
  • Thank you. I will have a look and give it a try. I tell you if it works. – S. Klicek Jun 06 '16 at 06:41
  • I don't get it work. What ID do i have to convert: the message-id or the folder-id...? I have installed garethp/php-ews directly from the repository but there I get an error message telling that EWSType_FindItemType is missing – S. Klicek Jun 07 '16 at 06:28
  • I found the error on missing class. I had a mixture of garethp/php-ews and the old one. But the ID problem is still there – S. Klicek Jun 07 '16 at 08:08
  • I think you should try converting both, see what happens? Or get the Item ID's fresh, instead of storing them in the DB? – Gareth Parker Jun 07 '16 at 08:56
  • I get an error saying 'Id is malformed': message-id is: AAMkAGNkOGRhZTMyLTBiNzAtNDhkNS05ZDhkLTg0Yjg3MDg2NTQ0NABGAAAAAACff7a4yIddSrJmA51rrq6YBwCmngR8iTVkSIs9XxAAR0L0AAAAAAEMAACmngR8iTVkSIs9XxAAR0L0AAAMM6NpAAA== The exchange-server is in version 2013. – S. Klicek Jun 07 '16 at 10:45
  • Okay, so try only converting the ItemId, not the FolderId – Gareth Parker Jun 07 '16 at 13:07
  • I have tried. But it does not work. I get error 'Id is malformed' in garethp/php-ews/src/api/exchangewebservices.php:426 – S. Klicek Jun 07 '16 at 14:27
  • Can you post your whole code that you've got that leads up to that? – Gareth Parker Jun 07 '16 at 14:38
  • My code: require_once "vendor/autoload.php"; use garethp\ews\API\Type; use garethp\ews\API\Enumeration; use garethp\ews\Mail\MailAPI as API; function convert_id($ews2007Id, $changeKey, $usermail){ $host = "xxx.xxx.xxx.xxx"; $usern = "xxx"; $pwd = "xxx"; $api = API::withUsernameAndPassword($host, $usern, $pwd); $ews2007ItemId = new Type\ItemIdType($ews2007Id, changeKey); $ews2010ItemId = $api->convertIdFormat($ews2007ItemId, Enumeration\IdFormatType::EWS_LEGACY_ID, Enumeration\IdFormatType::EWS_ID,$usermail); return $ews2010ItemId;} – S. Klicek Jun 08 '16 at 06:34
  • I mean the full code, from fetching the keys from the DB to converting them to trying to move the item. Also, can you post this as an issue on my Github? Comments in StackOverflow doesn't work too well for this – Gareth Parker Jun 08 '16 at 08:55
  • Hello Gareth. I've created the issue in Github [link](https://github.com/Garethp/php-ews/issues) – S. Klicek Jun 08 '16 at 12:49

1 Answers1

3

Thanks to Gareth Parker, my error was found. I had forgotten to give always the exchange version in my clients.

just specify the same Exchange version in every client you create:

$ews = new ExchangeWebServices($host, $username, $password, ExchangeWebServices::VERSION_2007_SP1);
S. Klicek
  • 55
  • 9