Skip to content

Commit

Permalink
Merge pull request #21 from linux-jedi/master
Browse files Browse the repository at this point in the history
Added the ability to mark messages as read
  • Loading branch information
rileydutton authored Mar 3, 2017
2 parents 408e3b2 + 20376b7 commit 693758f
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions lib/ExchangeClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,54 @@ public function move_message($ItemId, $FolderId) {
$this->lastError = $response->ResponseMessages->MoveItemResponseMessage->ResponseCode;
}
}

/**
* Mark message(s) as read
*
* @access public
* @param array $messages (the message or an array of messages to mark as read)
* @return boolean $response. (Returns true if successful and false on error).
*/
public function mark_message_as_read($messages) {
$this->setup();

if(!is_array($messages)) {
$messages = array($messages);
}

$request = new stdClass();
$request->MessageDisposition = 'SaveOnly';
$request->ConflictResolution = 'AlwaysOverwrite';
$request->ItemChanges = array();

foreach($messages as $message) {
$change = new stdClass();
$change->ItemId = new stdClass();
$change->ItemId->Id = $message->ItemId->Id;
$change->ItemId->ChangeKey = $message->ItemId->ChangeKey;

$field = new stdClass();
$field->FieldURI = new stdClass();
$field->FieldURI->FieldURI = 'message:IsRead';
$field->Message = new stdClass();
$field->Message->IsReadSpecified = true;
$field->Message->IsRead = true;

$change->Updates->SetItemField[] = $field;
$request->ItemChanges[] = $change;
}

$response = $this->client->UpdateItem($request);
$this->teardown();

if(response->ResponseMessages->UpdateItemResponseMessage->ResponseCode == 'NoError') {
return true;
}
else {
$this->lastError = $response->ResponseMessages->UpdateItemResponseMessage->ResponseCode;
return false;
}
}

public function getFolder($regex, $parent = 'inbox') {
foreach($this->get_subfolders($parent) as $folder) {
Expand Down

0 comments on commit 693758f

Please sign in to comment.