* $textPart = new ezcMailText( "This is a text message" ); * * * Example: ezcMailText in a HTML message * * $textPart = new ezcMailText( "This is an HTML message" ); * $textPart->subType = 'html'; * * * property charset The characterset used for this text part. Defaults to * 'us-ascii' while creating mail, and is always 'utf-8' while * parsing mail. * property originalCharset * The characterset in which a text part originally was before * the conversion to UTF-8. (readonly) * property subType The subtype of this text part. Defaults to 'plain' for plain text. * Use 'html' for HTML messages. * property encoding The encoding of the text. Defaults to eight bit. * property text The main data of this text part. * * @package Mail * @version 1.1.1 */ class ezcMailText extends ezcMailPart { /** * Holds the properties of this class. * * @var array(string=>mixed) */ private $properties = array(); /** * Constructs a new TextPart with the given $text, $charset and $encoding. * * @param string $text * @param string $charset * @param int $encoding */ public function __construct( $text, $charset = "us-ascii", $encoding = ezcMail::EIGHT_BIT, $originalCharset = 'us-ascii' ) { parent::__construct(); $this->text = $text; $this->charset = $charset; $this->encoding = $encoding; $this->subType = 'plain'; // We need to set this directly in the array as it's a read-only property. $this->properties['originalCharset'] = $originalCharset; } /** * Sets the property $name to $value. * * @throws ezcBasePropertyNotFoundException if the property does not exist. * @param string $name * @param mixed $value * @return void */ public function __set( $name, $value ) { switch ( $name ) { case 'charset': $this->properties['charset'] = $value; break; case 'subType': $this->properties['subType'] = $value; break; case 'encoding': $this->properties['encoding'] = $value; break; case 'text': $this->properties['text'] = $value; break; case 'originalCharset': throw new ezcBasePropertyPermissionException( $name, ezcBasePropertyPermissionException::READ ); break; default: return parent::__set( $name, $value ); break; } } /** * Sets the property $name to $value. * * @throws ezcBasePropertyNotFoundException if the property does not exist. * @param string $name * @param mixed $value * @return void */ public function __get( $name ) { switch ( $name ) { case 'charset': return $this->properties['charset']; break; case 'originalCharset': return $this->properties['originalCharset']; break; case 'subType': return $this->properties['subType']; break; case 'encoding': return $this->properties['encoding']; break; case 'text': return $this->properties['text']; break; default: return parent::__get( $name ); break; } } /** * Returns the headers set for this part as a RFC822 compliant string. * * This method does not add the required two lines of space * to separate the headers from the body of the part. * * @see setHeader() * @return string */ public function generateHeaders() { $this->setHeader( "Content-Type", "text/" . $this->subType . "; charset=" . $this->charset ); $this->setHeader( "Content-Transfer-Encoding", $this->encoding ); return parent::generateHeaders(); } /** * Returns the generated text body of this part as a string. * * @return string */ public function generateBody() { // convert linebreaks to the correct type. return preg_replace( "/\r\n|\r|\n/", ezcMailTools::lineBreak(), $this->text ); } } ?>