Skip to content

Commit

Permalink
Update changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Garethp committed Nov 5, 2015
1 parent 1afe24f commit d9098aa
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.5.9 - 2015-11-05
* Adding ability to get the attachments of an eamil

## 0.5.8 - 2015-09-30
* Fixed a test for Travis to pass

Expand Down
1 change: 1 addition & 0 deletions examples/mail/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ been made much easier to work with
* [Get a list of all items from the inbox](listItems.php)
* [Check if an item is read or not](checkItemRead.php)
* [Check if an item is a reply to another email](checkItemIsAReply.php)
* [Get the attachments of an email](gettingEmailAttachments.php)
28 changes: 28 additions & 0 deletions examples/mail/gettingEmailAttachments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

require_once "vendor/autoload.php";

use jamesiarmes\PEWS\API\Type;
use jamesiarmes\PEWS\API\TypeTest;

$api = new \jamesiarmes\PEWS\Mail\MailAPI();
$api->buildClient('server', 'username', 'password');


$mail = $api->getMailItems();
$mailItem = $mail[1];

//When the item is first returned from getMailItems(), it doesn't have attachment information filled out. You need to
//get that mail item again directly
$mailItem = $api->getItem($mailItem->getItemId());

//getFileAttachment() always returns an array of file attachments, or null
$fileAttachment = $mailItem->getAttachments()->getFileAttachment()[0];

//Without this the content of the attachment is not returned, so we need to do another fetch to make sure we get the
//content
$attachment = $api->getAttachment($fileAttachment->getAttachmentId());

$name = $attachment->getName();
$contentType = $attachment->getContentType();
$content = $attachment->getContent();
24 changes: 24 additions & 0 deletions src/API/Type/NonEmptyArrayOfAttachmentsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,28 @@ class NonEmptyArrayOfAttachmentsType extends Type
* @var \jamesiarmes\PEWS\API\Type\FileAttachmentType[]
*/
protected $fileAttachment = null;

/**
* @return FileAttachmentType[]
*/
public function getFileAttachment()
{
if (!is_array($this->fileAttachment) && $this->fileAttachment !== null) {
return array($this->fileAttachment);
}

return $this->fileAttachment;
}

/**
* @return ItemAttachmentType[]
*/
public function getItemAttachment()
{
if (!is_array($this->itemAttachment) && $this->itemAttachment !== null) {
return array($this->itemAttachment);
}

return $this->itemAttachment;
}
}
12 changes: 12 additions & 0 deletions src/Mail/MailAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,16 @@ public function sendMail(MessageType $message, $options = array())

return $this->createItems($items, $options);
}

public function getAttachment(Type\AttachmentIdType $attachmentId)
{
$request = array (
'AttachmentIds' => array(
$attachmentId->toXmlObject()
)
);

$attachment = $this->getClient()->GetAttachment($request);
return $attachment;
}
}

0 comments on commit d9098aa

Please sign in to comment.