0 ) { $mainType = strtolower( $matches[0][1] ); $subType = strtolower( $matches[0][2] ); } } $bodyParser = null; // create the correct type parser for this the detected type of part switch ( $mainType ) { /* RFC 2045 defined types */ case 'image': case 'audio': case 'video': case 'application': $bodyParser = new ezcMailFileParser( $mainType, $subType, $headers ); break; case 'message': if ( $subType == "rfc822" ) { $bodyParser = new ezcMailRfc822DigestParser( $headers ); } else { $bodyParser = new ezcMailTextParser( $subType, $headers ); } break; case 'text': $bodyParser = new ezcMailTextParser( $subType, $headers ); break; case 'multipart': switch ( $subType ) { case 'mixed': $bodyParser = new ezcMailMultipartMixedParser( $headers ); break; case 'alternative': $bodyParser = new ezcMailMultipartAlternativeParser( $headers ); break; case 'related': $bodyParser = new ezcMailMultipartRelatedParser( $headers ); break; case 'digest': $bodyParser = new ezcMailMultipartDigestParser( $headers ); break; default: $bodyParser = new ezcMailMultipartMixedParser( $headers ); break; } break; /* extensions */ default: // we treat the body as text if no main content type is set // or if it is unknown $bodyParser = new ezcMailTextParser( $headers ); break; } return $bodyParser; } /** * Parses the header given by $line and adds to $headers. * * This method is usually used to parse the headers for a subpart. The * only exception is RFC822 parts since you know the type in advance. * * @todo deal with headers that are listed several times * @param string $line * @param ezcMailHeadersHolder $headers */ protected function parseHeader( $line, ezcMailHeadersHolder $headers ) { $matches = array(); preg_match_all( "/^([\w-_]*): (.*)/", $line, $matches, PREG_SET_ORDER ); if ( count( $matches ) > 0 ) { $headers[$matches[0][1]] = trim( $matches[0][2] ); $this->lastParsedHeader = $matches[0][1]; } else if ( $this->lastParsedHeader !== null ) // take care of folding { $headers[$this->lastParsedHeader] .= $line; } // else -invalid syntax, this should never happen. } /** * Scans through $headers and sets any specific header properties on $part. * * Currently we only have Content-Disposition on the ezcMailPart level. * All parser parts must call this method once. * * @param ezcMailHeadersHolder $headers * @param ezcMailPart $part */ static public function parsePartHeaders( ezcMailHeadersHolder $headers, ezcMailPart $part ) { if ( isset( $headers['Content-Disposition'] ) ) { $part->contentDisposition = ezcMailRfc2231Implementation::parseContentDisposition( $headers['Content-Disposition'] ); } } } ?>