From 88f43819ee7ed17cabe5fc04f38b2d13c7eb17b9 Mon Sep 17 00:00:00 2001 From: Bjorn Post Date: Tue, 11 Mar 2014 20:17:02 +0100 Subject: [PATCH 1/2] Be more specific when fetching body sections, references #39 --- src/Fetch/Message.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index f61eddf..4b202af 100644 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -432,10 +432,12 @@ protected function processStructure($structure, $partIdentifier = null) $attachment = new Attachment($this, $structure, $partIdentifier); $this->attachments[] = $attachment; } elseif ($structure->type == 0 || $structure->type == 1) { - - $messageBody = isset($partIdentifier) ? - imap_fetchbody($this->imapStream, $this->uid, $partIdentifier, FT_UID) - : imap_body($this->imapStream, $this->uid, FT_UID); + if($partIdentifier !== null) { + $section = is_int($structure->ifsubtype) ? (string)$partIdentifier.".".$structure->ifsubtype : $partIdentifier; + $messageBody = imap_fetchbody($this->imapStream, $this->uid, $section, FT_UID); + } else { + $messageBody = imap_body($this->imapStream, $this->uid, FT_UID); + } $messageBody = self::decode($messageBody, $structure->encoding); From 7b42853eecb453f21accb2551236caa8f25de4d7 Mon Sep 17 00:00:00 2001 From: Bjorn Post Date: Tue, 11 Mar 2014 22:16:43 +0100 Subject: [PATCH 2/2] Rewrite fix as it broke other tests. This fixes my issue and the broken tests. --- src/Fetch/Message.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index 4b202af..3755869 100644 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -432,19 +432,16 @@ protected function processStructure($structure, $partIdentifier = null) $attachment = new Attachment($this, $structure, $partIdentifier); $this->attachments[] = $attachment; } elseif ($structure->type == 0 || $structure->type == 1) { - if($partIdentifier !== null) { - $section = is_int($structure->ifsubtype) ? (string)$partIdentifier.".".$structure->ifsubtype : $partIdentifier; - $messageBody = imap_fetchbody($this->imapStream, $this->uid, $section, FT_UID); - } else { - $messageBody = imap_body($this->imapStream, $this->uid, FT_UID); - } + $messageBody = isset($partIdentifier) ? + imap_fetchbody($this->imapStream, $this->uid, $partIdentifier, FT_UID) + : imap_body($this->imapStream, $this->uid, FT_UID); $messageBody = self::decode($messageBody, $structure->encoding); if (!empty($parameters['charset']) && $parameters['charset'] !== self::$charset) $messageBody = iconv($parameters['charset'], self::$charset, $messageBody); - if (strtolower($structure->subtype) == 'plain' || $structure->type == 1) { + if (strtolower($structure->subtype) === 'plain' || ($structure->type == 1 && strtolower($structure->subtype) !== 'alternative')) { if (isset($this->plaintextMessage)) { $this->plaintextMessage .= PHP_EOL . PHP_EOL; } else { @@ -453,7 +450,6 @@ protected function processStructure($structure, $partIdentifier = null) $this->plaintextMessage .= trim($messageBody); } else { - if (isset($this->htmlMessage)) { $this->htmlMessage .= '

'; } else {