diff --git a/README.md b/README.md index de92306..06c5980 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ foreach($aMailboxes as $oMailbox){ /** @var \Webklex\IMAP\Message $oMessage */ foreach($oMailbox->getMessages() as $oMessage){ echo $oMessage->subject.'
'; + echo 'Attachments: '.$oMessage->getAttachments()->count().'
'; echo $oMessage->getHTMLBody(true); //Move the current Message to 'INBOX.read' @@ -157,17 +158,18 @@ You can define your accounts inside the `config/imap.php` file: | checkCurrentMailbox | | object | Check current mailbox | ### \Webklex\IMAP\Message -| Method | Arguments | Return | Description | -| ------------ | ----------------------------- | :-----: | -------------------------------------- | -| delete | | | Delete the current Message | -| restore | | | Restore a deleted Message | -| copy | string $mailbox, int $options | | Copy the current Messages to a mailbox | -| move | string $mailbox, int $options | | Move the current Messages to a mailbox | -| moveToFolder | string $mailbox | | Move the Message into an other Folder | -| hasTextBody | | | Check if the Message has a text body | -| hasHTMLBody | | | Check if the Message has a html body | -| getTextBody | | string | Get the Message text body | -| getHTMLBody | | string | Get the Message html body | +| Method | Arguments | Return | Description | +| -------------- | ----------------------------- | :---------: | -------------------------------------- | +| delete | | | Delete the current Message | +| restore | | | Restore a deleted Message | +| copy | string $mailbox, int $options | | Copy the current Messages to a mailbox | +| move | string $mailbox, int $options | | Move the current Messages to a mailbox | +| moveToFolder | string $mailbox | | Move the Message into an other Folder | +| hasTextBody | | | Check if the Message has a text body | +| hasHTMLBody | | | Check if the Message has a html body | +| getTextBody | | string | Get the Message text body | +| getHTMLBody | | string | Get the Message html body | +| getAttachments | | collection | Get all message attachments | ### \Webklex\IMAP\Folder | Method | Arguments | Return | Description | diff --git a/src/IMAP/Folder.php b/src/IMAP/Folder.php index e143546..7f2f36d 100644 --- a/src/IMAP/Folder.php +++ b/src/IMAP/Folder.php @@ -12,6 +12,8 @@ namespace Webklex\IMAP; +use Guzzle\Common\Collection; + class Folder { /** * Client instance @@ -139,10 +141,10 @@ public function setChildren($children = []) { * * @param string $criteria * - * @return array + * @return \Illuminate\Support\Collection */ public function getMessages($criteria = 'ALL') { - return $this->client->getMessages($this, $criteria); + return collect($this->client->getMessages($this, $criteria)); } /** diff --git a/src/IMAP/Message.php b/src/IMAP/Message.php index f58eebe..9866fca 100644 --- a/src/IMAP/Message.php +++ b/src/IMAP/Message.php @@ -306,7 +306,7 @@ private function parseBody() { * @param mixed $partNumber */ private function fetchStructure($structure, $partNumber = null) { - if ($structure->type == self::TYPE_TEXT) { + if ($structure->type == self::TYPE_TEXT && $partNumber == null) { if ($structure->subtype == "PLAIN") { if (!$partNumber) { $partNumber = 1; @@ -347,7 +347,7 @@ private function fetchStructure($structure, $partNumber = null) { if ($partNumber) { $prefix = $partNumber . "."; } - + var_dump($structure); $this->fetchStructure($subStruct, $prefix . ($index + 1)); } } else { @@ -410,10 +410,14 @@ private function fetchStructure($structure, $partNumber = null) { $attachment->img_src = 'data:'.$attachment->content_type.';base64,'.base64_encode($attachment->content); } - if ($attachment->id) { - $this->attachments[$attachment->id] = $attachment; - } else { - $this->attachments[] = $attachment; + if(property_exists($attachment, 'name')){ + if($attachment->name != false){ + if ($attachment->id) { + $this->attachments[$attachment->id] = $attachment; + } else { + $this->attachments[] = $attachment; + } + } } } } @@ -515,4 +519,13 @@ public function delete(){ public function restore(){ return imap_undelete($this->client->connection, $this->message_no); } + + /** + * Get all message attachments. + * + * @return \Illuminate\Support\Collection + */ + public function getAttachments(){ + return collect($this->attachments); + } }