src/MailMap/MailFactory.php
protected function parseHeaders($stream, $uid)
    {
        $rawHeaders = imap_fetchheader($stream, $uid, static::$fetchFlags);

        $headers = [];
        $key = null;

        foreach (explode("\n", $rawHeaders) as $line) {
            // Test if continutation
            if ($line !== '' && !preg_match('/^\s/', $line)) {
                list($key, $val) = explode(':', $line, 2);
                $headers[$key] = trim($val);
            } elseif (!is_null($key) && ($trimmed = trim($line)) !== '') {
                $headers[$key] = $headers[$key].$trimmed;
            }
        }

        foreach($headers as $headerKey => $headerValue) {
            if (preg_match('/(\w+)=(\S+);(?:\s|$)/', $headerValue)) {
                $headers[$headerKey] = $this->parseNestedKeyPairHeader($headerValue);
            }
        }

        return $headers;
    }
protected function parseHeaders($stream, $uid)
    {
        $rawHeaders = imap_fetchheader($stream, $uid, static::$fetchFlags);

        $headers = [];
        $key = null;

        foreach (explode("\n", $rawHeaders) as $line) {
            // Test if continutation
            if ($line !== '' && !preg_match('/^\s/', $line)) {
                list($key, $val) = explode(':', $line, 2);
                $headers[$key] = trim($val);
            } elseif (!is_null($key) && ($trimmed = trim($line)) !== '') {
                $headers[$key] = $headers[$key].$trimmed;
            }
        }

        foreach($headers as $headerKey => $headerValue) {
            if (preg_match('/(\w+)=(\S+);(?:\s|$)/', $headerValue)) {
                $headers[$headerKey] = $this->parseNestedKeyPairHeader($headerValue);
            }
        }

        return $headers;
    }
protected function parseHeaders ( $ stream , $ uid ) { $ rawHeaders = imap_fetchheader ( $ stream , $ uid , static :: $ fetchFlags ) ; $ headers = [ ] ; $ key = null ; foreach ( explode ( "\n" , $ rawHeaders ) as $ line ) { // Test if continutation if ( $ line !== '' && ! preg_match ( '/^\s/' , $ line ) ) { list ( $ key , $ val ) = explode ( ':' , $ line , 2 ) ; $ headers [ $ key ] = trim ( $ val ) ; } elseif ( ! is_null ( $ key ) && ( $ trimmed = trim ( $ line ) ) !== '' ) { $ headers [ $ key ] = $ headers [ $ key ] . $ trimmed ; } } foreach ( $ headers as $ headerKey => $ headerValue ) { if ( preg_match ( '/(\w+)=(\S+);(?:\s|$)/' , $ headerValue ) ) { $ headers [ $ headerKey ] = $ this -> parseNestedKeyPairHeader ( $ headerValue ) ; } } return $ headers ; }
Parse the email headers into array structure

@param  resource $stream
@param  int $uid
@return array
Parse the email headers into array structure