From d9098aa0d66eb71dafdbb9a59570089899969e87 Mon Sep 17 00:00:00 2001 From: Garethp Date: Thu, 5 Nov 2015 15:36:34 +0100 Subject: [PATCH] Update changelog --- CHANGELOG.md | 3 ++ examples/mail/README.md | 1 + examples/mail/gettingEmailAttachments.php | 28 +++++++++++++++++++ .../Type/NonEmptyArrayOfAttachmentsType.php | 24 ++++++++++++++++ src/Mail/MailAPI.php | 12 ++++++++ 5 files changed, 68 insertions(+) create mode 100644 examples/mail/gettingEmailAttachments.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 47ca56ea..1110e3a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/examples/mail/README.md b/examples/mail/README.md index 818945a8..3cf8c6fa 100644 --- a/examples/mail/README.md +++ b/examples/mail/README.md @@ -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) diff --git a/examples/mail/gettingEmailAttachments.php b/examples/mail/gettingEmailAttachments.php new file mode 100644 index 00000000..8f37eb30 --- /dev/null +++ b/examples/mail/gettingEmailAttachments.php @@ -0,0 +1,28 @@ +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(); diff --git a/src/API/Type/NonEmptyArrayOfAttachmentsType.php b/src/API/Type/NonEmptyArrayOfAttachmentsType.php index 789000b1..6cd5d05b 100644 --- a/src/API/Type/NonEmptyArrayOfAttachmentsType.php +++ b/src/API/Type/NonEmptyArrayOfAttachmentsType.php @@ -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; + } } diff --git a/src/Mail/MailAPI.php b/src/Mail/MailAPI.php index e7122ce0..c23b51e3 100644 --- a/src/Mail/MailAPI.php +++ b/src/Mail/MailAPI.php @@ -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; + } }