diff --git a/composer.json b/composer.json index d804739..8ba9c43 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "michaelesmith/email-parser", - "version": "0.2", + "version": "0.3", "description": "Parse an email into an object representation", "keywords": ["email", "parse"], "homepage": "https://github.com/michaelesmith/EmailParser", diff --git a/src/MS/Email/Parser/Parser.php b/src/MS/Email/Parser/Parser.php index 10d4594..d01442d 100644 --- a/src/MS/Email/Parser/Parser.php +++ b/src/MS/Email/Parser/Parser.php @@ -19,7 +19,7 @@ public function parse($email){ $this->getHeader('subject'), $this->getText(), $this->getHtml(), - $this->getAttachments(), + $this->getAllAttachments(), $this->getHeader('date') ); } @@ -39,8 +39,20 @@ protected function getText(){ } protected function getAttachments(){ + return $this->getAttachmentsFromPart('/attachment/'); + } + + protected function getInlineAttachments(){ + return $this->getAttachmentsFromPart('/inline/'); + } + + protected function getAllAttachments(){ + return array_merge($this->getAttachments(), $this->getInlineAttachments()); + } + + private function getAttachmentsFromPart($part){ if(!is_array($this->parts['body'])) return false; - $attachments = $this->searchByHeader('/content\-disposition/','/attachment/'); + $attachments = $this->searchByHeader('/content\-disposition/', $part); $attachments = $attachments ? $attachments : array(); $attachmentObjects = array();