protected function parseDocument( $string )
    {
        $document = array();

        // Read document headers
        while ( preg_match( '(\\A(?P<header>[A-Za-z0-9-]+):\s+(?P<value>.*)$)Sm', $string, $match ) )
        {
            $document[$match['header']] = trim( $match['value'] );
            $string = substr( $string, strlen( $match[0] ) + 1 );
        }

        if ( strpos( $document['Content-Type'], 'multipart/mixed' ) === 0 )
        {
            // Rebuild full document
            $body = fopen( 'string://', 'w' );
            foreach ( $document as $key => $value )
            {
                fwrite( $body, "$key: $value\r\n" );
            }
            fwrite( $body, $string );
            fseek( $body, 0 );

            $document['body'] = array();
            $parser = new phpillowToolMultipartParser( $body );
            while ( ( $part = $parser->getDocument() ) !== false )
            {
                $document['body'][] = $part;
            }
        }
        else
        {
            $document['body'] = trim( $string );
        }

        return $document;
    }
protected function parseDocument( $string )
    {
        $document = array();

        // Read document headers
        while ( preg_match( '(\\A(?P<header>[A-Za-z0-9-]+):\s+(?P<value>.*)$)Sm', $string, $match ) )
        {
            $document[$match['header']] = trim( $match['value'] );
            $string = substr( $string, strlen( $match[0] ) + 1 );
        }

        if ( strpos( $document['Content-Type'], 'multipart/mixed' ) === 0 )
        {
            // Rebuild full document
            $body = fopen( 'string://', 'w' );
            foreach ( $document as $key => $value )
            {
                fwrite( $body, "$key: $value\r\n" );
            }
            fwrite( $body, $string );
            fseek( $body, 0 );

            $document['body'] = array();
            $parser = new phpillowToolMultipartParser( $body );
            while ( ( $part = $parser->getDocument() ) !== false )
            {
                $document['body'][] = $part;
            }
        }
        else
        {
            $document['body'] = trim( $string );
        }

        return $document;
    }
protected function parseDocument ( $ string ) { $ document = array ( ) ; // Read document headers while ( preg_match ( '(\\A(?P<header>[A-Za-z0-9-]+):\s+(?P<value>.*)$)Sm' , $ string , $ match ) ) { $ document [ $ match [ 'header' ] ] = trim ( $ match [ 'value' ] ) ; $ string = substr ( $ string , strlen ( $ match [ 0 ] ) + 1 ) ; } if ( strpos ( $ document [ 'Content-Type' ] , 'multipart/mixed' ) === 0 ) { // Rebuild full document $ body = fopen ( 'string://' , 'w' ) ; foreach ( $ document as $ key => $ value ) { fwrite ( $ body , "$key: $value\r\n" ) ; } fwrite ( $ body , $ string ) ; fseek ( $ body , 0 ) ; $ document [ 'body' ] = array ( ) ; $ parser = new phpillowToolMultipartParser ( $ body ) ; while ( ( $ part = $ parser -> getDocument ( ) ) !== false ) { $ document [ 'body' ] [ ] = $ part ; } } else { $ document [ 'body' ] = trim ( $ string ) ; } return $ document ; }
Parse a single document

Parse a single document, and return an array with all headers and the
document body. If the parsed document is of the type "multipart/mixed",
an array with all parts is returned as the type.

@param string $string
@return array
Parse a single document