private function workAroundMissingBoundary(Part $part, $rawMailBody)
    {
        try {
            $part->countParts();
        } catch (RuntimeException $e) {
            if (count($part->getHeaders()) > 0
                && $part->getHeaders()->has('Content-Type')
                && array_key_exists('boundary', $this->getContentType($part)->getParameters())
            ) {
                $boundary = $part
                    ->getHeaders()
                    ->get('Content-Type')
                    ->getParameter('boundary');

                $content = trim($rawMailBody);
                $content .= "\n--{$boundary}--";

                $part = $this->partFactory->getPart($content);
            }
        }

        return $part;
    }
private function workAroundMissingBoundary(Part $part, $rawMailBody)
    {
        try {
            $part->countParts();
        } catch (RuntimeException $e) {
            if (count($part->getHeaders()) > 0
                && $part->getHeaders()->has('Content-Type')
                && array_key_exists('boundary', $this->getContentType($part)->getParameters())
            ) {
                $boundary = $part
                    ->getHeaders()
                    ->get('Content-Type')
                    ->getParameter('boundary');

                $content = trim($rawMailBody);
                $content .= "\n--{$boundary}--";

                $part = $this->partFactory->getPart($content);
            }
        }

        return $part;
    }
private function workAroundMissingBoundary ( Part $ part , $ rawMailBody ) { try { $ part -> countParts ( ) ; } catch ( RuntimeException $ e ) { if ( count ( $ part -> getHeaders ( ) ) > 0 && $ part -> getHeaders ( ) -> has ( 'Content-Type' ) && array_key_exists ( 'boundary' , $ this -> getContentType ( $ part ) -> getParameters ( ) ) ) { $ boundary = $ part -> getHeaders ( ) -> get ( 'Content-Type' ) -> getParameter ( 'boundary' ) ; $ content = trim ( $ rawMailBody ) ; $ content .= "\n--{$boundary}--" ; $ part = $ this -> partFactory -> getPart ( $ content ) ; } } return $ part ; }
Some emails are missing a MIME closing boundary. This violations the standard,
but most software still handles it well - except the Zend Framework, who rather
don't want to accommodate broken emails.

Since they don't provide any meaningful way to test if the message was decoded
correctly (like a $part->test() method or something), the only recourse is to
call some function on the part and handle the exception that's thrown when the
closing boundary is missing.

Then append the boundary and re-parse the email.

@param Part   $part
@param string $rawMailBody
@return Part
Some emails are missing a MIME closing boundary . This violations the standard but most software still handles it well - except the Zend Framework who rather don t want to accommodate broken emails .