I am using php-ews to get attachment and save them to specific directory and now i need to move the mail into another folder. Im stuck in here :
$client = new Client($host, $username, $password, $version);
$request = new FindItemType();
$request->ParentFolderIds = new NonEmptyArrayOfBaseFolderIdsType();
// Return all message properties.
$request->ItemShape = new ItemResponseShapeType();
$request->ItemShape->BaseShape = DefaultShapeNamesType::ALL_PROPERTIES;
// Search in the user's inbox.
$folder_id = new DistinguishedFolderIdType();
$folder_id->Id = DistinguishedFolderIdNameType::INBOX;
$request->ParentFolderIds->DistinguishedFolderId[] = $folder_id;
$response = $client->FindItem($request);
// Iterate over the results, printing any error messages or message subjects.
$response_messages = $response->ResponseMessages->FindItemResponseMessage;
foreach ($response_messages as $response_message) {
// Make sure the request succeeded.
if ($response_message->ResponseClass != ResponseClassType::SUCCESS) {
$code = $response_message->ResponseCode;
$message = $response_message->MessageText;
continue;
}
$items = $response_message->RootFolder->Items->Message;
foreach ($items as $item) {
$subject = $item->Subject;
$sender = $item->From->Mailbox->EmailAddress;
//move mail item from folder "INBOX" to folder "DONE"
}
}
Here is a working solution, using php-ews 1.0
You can use the existing class MoveItemType
$request = new MoveItemType();
$request->ItemIds = new NonEmptyArrayOfBaseItemIdsType();
$item_id = new ItemIdType();
$item_id->Id = 'foobarfoobar';
$request->ItemIds->ItemId[] = $item_id;
$request->ToFolderId = new TargetFolderIdType();
$folder_id = new FolderIdType();
$folder_id->Id = $this->treatedFolderId;
$request->ToFolderId->FolderId = 'barbar';
$response = $this->client->MoveItem($request);
$response_messages = $response->ResponseMessages->MoveItemResponseMessage;
foreach ($response_messages as $response_message) {
// Make sure the request succeeded.
if ($response_message->ResponseClass != ResponseClassType::SUCCESS) {
// Error treatment .....
continue;
}
$items = $response_message->Items->Message;
foreach ($items as $item) {
// ...
}
}