Example #1
0
 /**
  * Get all mail items in the inbox
  *
  * @param array $options
  * @return Type\Message[]
  */
 public function getMailItems($options = array())
 {
     $request = array('Traversal' => 'Shallow', 'ItemShape' => array('BaseShape' => 'AllProperties'), 'ParentFolderIds' => array('FolderId' => array('Id' => $this->getFolderId()->Id, 'ChangeKey' => $this->getFolderId()->ChangeKey)));
     $request = array_merge($request, $options);
     $request = Type::buildFromArray($request);
     $response = $this->getClient()->FindItem($request);
     $items = $response;
     if (!isset($items->Message)) {
         return array();
     }
     if (!is_array($items->Message)) {
         $items->Message = array($items->Message);
     }
     return $items->Message;
 }
Example #2
0
 /**
  * Get all mail items in the inbox
  *
  * @param Type\FolderIdType
  * @param array $options
  * @return Type\MessageType[]
  */
 public function getMailItems($folderId = null, $options = array())
 {
     if (!$folderId) {
         $folderId = $this->getFolderId();
     }
     $request = array('Traversal' => 'Shallow', 'ItemShape' => array('BaseShape' => 'AllProperties'), 'ParentFolderIds' => array('FolderId' => $folderId->toXmlObject()));
     if (!empty($options['Restriction'])) {
         $options['Restriction'] = $this->formatRestrictions($options['Restriction']);
     }
     $request = array_replace_recursive($request, $options);
     $request = Type::buildFromArray($request);
     $response = $this->getClient()->FindItem($request);
     $messages = $response->getItems()->getMessage();
     if ($messages === null) {
         $messages = array();
     }
     if (!is_array($messages)) {
         $messages = array($messages);
     }
     return $messages;
 }
Example #3
0
 /**
  * Get a list of calendar items between two dates/times
  *
  * @param string|DateTime $start
  * @param string|DateTime $end
  * @param array $options
  * @return mixed
  */
 public function getCalendarItems($start = '12:00 AM', $end = '11:59 PM', $options = array())
 {
     if (!$start instanceof DateTime) {
         $start = new DateTime($start);
     }
     if (!$end instanceof DateTime) {
         $end = new DateTime($end);
     }
     $request = array('Traversal' => 'Shallow', 'ItemShape' => array('BaseShape' => 'AllProperties'), 'CalendarView' => array('MaxEntriesReturned' => 100, 'StartDate' => $start->format('c'), 'EndDate' => $end->format('c')), 'ParentFolderIds' => $this->getFolderIdsArray());
     $request = array_merge($request, $options);
     $request = Type::buildFromArray($request);
     $response = $this->getClient()->FindItem($request);
     $items = $response;
     if (!isset($items->CalendarItem)) {
         return array();
     }
     if (!is_array($items->CalendarItem)) {
         $items->CalendarItem = array($items->CalendarItem);
     }
     return $items->CalendarItem;
 }
Example #4
0
 public function createTestMail($message = null)
 {
     $client = $this->getClient();
     if (!$message) {
         //Create a new message
         $message = new Type\MessageType();
         $message->setSubject('Test Message');
         $message->setBody('Test Draft Body');
     }
     //Set the message as not a draft
     $extended = new Type\ExtendedPropertyType();
     $fieldUri = new Type\ExtendedFieldURI();
     $fieldUri->setPropertyTag("0x0E07");
     $fieldUri->setPropertyType(Enumeration\MapiPropertyTypeType::INTEGER);
     $extended->setExtendedFieldURI($fieldUri);
     $extended->setValue(1);
     $message->addExtendedProperty($extended);
     //Save the message to our Test Folder
     $itemId = $client->sendMail($message, array('MessageDisposition' => 'SaveOnly'));
     $client->getClient()->MoveItem(Type::buildFromArray(array('ToFolderId' => array('FolderId' => $this->getTestFolder()->getFolderId()->toArray()), 'ItemIds' => array('ItemId' => $itemId->toArray()))));
     return $itemId;
 }
Example #5
0
 public function testClone()
 {
     $start = new DateTime('8:00 AM');
     $end = new DateTime('9:00 AM');
     $request = array('Items' => array('CalendarItem' => array('Start' => $start->format('c'), 'End' => $end->format('c'), 'Body' => array('BodyType' => Enumeration\BodyTypeType::HTML, '_value' => 'This is <b>the</b> body'), 'ItemClass' => Enumeration\ItemClassType::APPOINTMENT, 'Sensitivity' => Enumeration\SensitivityChoicesType::NORMAL, 'Categories' => array('Testing', 'php-ews'), 'Importance' => Enumeration\ImportanceChoicesType::NORMAL)), 'SendMeetingInvitations' => Enumeration\CalendarItemCreateOrDeleteOperationType::SEND_TO_NONE);
     $request = Type::buildFromArray($request);
     $this->assertEquals($request, clone $request);
 }
Example #6
0
<?php

/**
 * Building Requests
 *
 * This file is an example on how to build requests manually and execute them directly instead of relying on the
 * simple use section of the library. Essentially, you can create your requests in arrays, pass them through
 * Type::buildFromArray($array) and then post them straight to the API Client.
 */
//Include the API
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');
//Build the request as an array
$request = array('FolderShape' => array('BaseShape' => array('_' => 'Default')), 'FolderIds' => array('DistinguishedFolderId' => array('Id' => 'calendar')));
//Turn the array in to an object to pass to the API
$request = Type::buildFromArray($request);
//Send the request and get the response
$response = $api->getClient()->GetFolder($request);
<?php

require_once "vendor/autoload.php";
use jamesiarmes\PEWS\API\Type;
use jamesiarmes\PEWS\Mail\MailAPI;
$api = MailApi::withUsernameAndPassword('server', 'username', 'password');
//Create the message item
$message = new Type\MessageType();
$message->setSubject('Test Message');
$message->setBody('Test Draft Body');
//Set the message as not a draft using extended property types
$extended = new Type\ExtendedPropertyType();
$fieldUri = new Type\ExtendedFieldURI();
$fieldUri->setPropertyTag("0x0E07");
$fieldUri->setPropertyType(\jamesiarmes\PEWS\API\Enumeration\MapiPropertyTypeType::INTEGER);
$extended->setExtendedFieldURI($fieldUri);
$extended->setValue(1);
$message->addExtendedProperty($extended);
//Pass it to the Send Mail function, but to SaveOnly without actually sending the email
$itemId = $api->sendMail($message, array('MessageDisposition' => 'SaveOnly'));
//Move the mail message from the sent folder to whatever folder we want to send it to
$api->getClient()->MoveItem(Type::buildFromArray(array('ToFolderId' => array('FolderId' => $folderId->toArray()), 'ItemIds' => array('ItemId' => $itemId->toArray()))));
Example #8
0
 /**
  * Get a list of sync changes on a folder
  *
  * @param Type\FolderIdType $folderId
  * @param null $syncState
  * @param array $options
  * @return mixed
  */
 public function listItemChanges($folderId, $syncState = null, $options = array())
 {
     $request = array('ItemShape' => array('BaseShape' => 'IdOnly'), 'SyncFolderId' => array('FolderId' => $folderId->toXmlObject()), 'SyncScope' => 'NormalItems', 'MaxChangesReturned' => '10');
     if ($syncState != null) {
         $request['SyncState'] = $syncState;
         $request['ItemShape']['BaseShape'] = 'AllProperties';
     }
     $request = array_replace_recursive($request, $options);
     $request = Type::buildFromArray($request);
     $response = $this->getClient()->SyncFolderItems($request);
     return $response;
 }
Example #9
0
 public function setImpersonation($email)
 {
     $this->_email = $email;
     $request = array('ExchangeImpersonation' => array('ConnectingSID' => array('PrimarySmtpAddress' => $email)));
     $request = Type::buildFromArray($request);
     $this->getClient()->setImpersonation($request->ExchangeImpersonation);
     return $this;
 }