* $mail = new ezcMail(); * $mail->from = new ezcMailAddress( 'sender@example.com', 'Adrian Ripburger' ); * $mail->addTo( new ezcMailAddress( 'receiver@example.com', 'Maureen Corley' ) ); * $mail->subject = "Example of an HTML email with attachments"; * $htmlText = new ezcMailText( "Image " ); * $htmlText->subType = 'html'; * $image = new ezcMailFile( "path_to_my_image.jpg" ); * $image->contentId = 'image@12345'; * $mail->body = new ezcMailMultipartRelated( $htmlText, $image ); * * * @package Mail * @version 1.1.1 */ class ezcMailMultipartRelated extends ezcMailMultipart { /** * Constructs a new ezcMailMultipartRelated. * * The constructor accepts an arbitrary number of ezcMailParts or arrays with ezcMailparts. * Parts are added in the order provided and the first part will be recognized * as the main body. Parameters of the wrong type are ignored. * * @param ezcMailPart|array(ezcMailPart) * @return void */ public function __construct() { $args = func_get_args(); parent::__construct( $args ); } /** * Sets the main part $part of this alternative multipart. * * @param ezcMailPart $part * @return void */ public function setMainPart( ezcMailPart $part ) { $this->parts[0] = $part; } /** * Adds $part to the list of parts and returns the Content-ID of the part. * * @param ezcMailPart $part * @return string */ public function addRelatedPart( ezcMailPart $part ) { // it doesn't have a Content-ID, we must set one. $contentId = ''; if ( $part->getHeader( 'Content-ID' ) == '' ) { if ( $part instanceof ezcMailFile ) { $part->contentId = ezcMailTools::generateContentId( basename( $part->fileName ) ); } else { $part->setHeader( 'Content-ID', ezcMailTools::generateContentId( 'part' ) ); } } $contentId = trim( $part->getHeader( 'Content-ID' ), '<>' ); if ( count( $this->parts ) > 0 ) { $this->parts[] = $part; } else { $this->parts[1] = $part; } return $contentId; } /** * Returns the main part of this multipart or null if there is no such part. * * @return array(ezcMailPart) */ public function getMainPart() { if ( isset( $this->parts[0] ) ) { return $this->parts[0]; } return null; } /** * Returns the mail parts associated with this multipart. * * @return array(ezcMailPart) */ public function getRelatedParts() { return array_slice( $this->parts, 1 ); } /** * Returns the part associated with the passed Content-ID. * * @param string $cid * @return ezcMailPart */ public function getRelatedPartByID( $cid ) { foreach ( array_slice( $this->parts, 1 ) as $part ) { if ( ( $part->getHeader( 'Content-ID' ) !== '' ) && ( $part->getHeader( 'Content-ID' ) == "<$cid>" ) ) { return $part; } } return false; } /** * Returns "related". * * @return string */ public function multipartType() { return "related"; } /** * Substitutes links in all ezcMailText parts with the subType HTML in this multipart/alternative. * * This method will perform substitution of CID's and absolute and relative links as specified by * RFC 2557 for links that resolve to files. Links to other message parts must be resolved when * displaying the message. * * - provide methods for substitution of these as well (inclusive listing of which they are) * @todo Move to separate class. */ private function resolveHtmlLinks() { // 1. Check that the main part is a html part // 2. Go through the related parts and build up a structure of available // CIDS and locations // 3. Substitute in this message. } } ?>