|
TYPO3 API
SVNRelease
|
00001 <?php 00002 00003 /* 00004 * This file is part of SwiftMailer. 00005 * (c) 2004-2009 Chris Corbyn 00006 * 00007 * For the full copyright and license information, please view the LICENSE 00008 * file that was distributed with this source code. 00009 */ 00010 00011 //@require 'Swift/Mime/SimpleMimeEntity.php'; 00012 //@require 'Swift/Mime/ContentEncoder.php'; 00013 //@require 'Swift/Mime/HeaderSet.php'; 00014 //@require 'Swift/KeyCache.php'; 00015 00016 /** 00017 * A MIME part, in a multipart message. 00018 * 00019 * @package Swift 00020 * @subpackage Mime 00021 * @author Chris Corbyn 00022 */ 00023 class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity 00024 { 00025 00026 /** The format parameter last specified by the user */ 00027 protected $_userFormat; 00028 00029 /** The charset last specified by the user */ 00030 protected $_userCharset; 00031 00032 /** The delsp parameter last specified by the user */ 00033 protected $_userDelSp; 00034 00035 /** The nesting level of this MimePart */ 00036 private $_nestingLevel = self::LEVEL_ALTERNATIVE; 00037 00038 /** 00039 * Create a new MimePart with $headers, $encoder and $cache. 00040 * 00041 * @param Swift_Mime_HeaderSet $headers 00042 * @param Swift_Mime_ContentEncoder $encoder 00043 * @param Swift_KeyCache $cache 00044 * @param string $charset 00045 */ 00046 public function __construct(Swift_Mime_HeaderSet $headers, 00047 Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, $charset = null) 00048 { 00049 parent::__construct($headers, $encoder, $cache); 00050 $this->setContentType('text/plain'); 00051 if (!is_null($charset)) 00052 { 00053 $this->setCharset($charset); 00054 } 00055 } 00056 00057 /** 00058 * Set the body of this entity, either as a string, or as an instance of 00059 * {@link Swift_OutputByteStream}. 00060 * 00061 * @param mixed $body 00062 * @param string $contentType optional 00063 * @param string $charset optional 00064 */ 00065 public function setBody($body, $contentType = null, $charset = null) 00066 { 00067 parent::setBody($body, $contentType); 00068 if (isset($charset)) 00069 { 00070 $this->setCharset($charset); 00071 } 00072 return $this; 00073 } 00074 00075 /** 00076 * Get the character set of this entity. 00077 * 00078 * @return string 00079 */ 00080 public function getCharset() 00081 { 00082 return $this->_getHeaderParameter('Content-Type', 'charset'); 00083 } 00084 00085 /** 00086 * Set the character set of this entity. 00087 * 00088 * @param string $charset 00089 */ 00090 public function setCharset($charset) 00091 { 00092 $this->_setHeaderParameter('Content-Type', 'charset', $charset); 00093 if ($charset !== $this->_userCharset) 00094 { 00095 $this->_clearCache(); 00096 } 00097 $this->_userCharset = $charset; 00098 parent::charsetChanged($charset); 00099 return $this; 00100 } 00101 00102 /** 00103 * Get the format of this entity (i.e. flowed or fixed). 00104 * 00105 * @return string 00106 */ 00107 public function getFormat() 00108 { 00109 return $this->_getHeaderParameter('Content-Type', 'format'); 00110 } 00111 00112 /** 00113 * Set the format of this entity (flowed or fixed). 00114 * 00115 * @param string $format 00116 */ 00117 public function setFormat($format) 00118 { 00119 $this->_setHeaderParameter('Content-Type', 'format', $format); 00120 $this->_userFormat = $format; 00121 return $this; 00122 } 00123 00124 /** 00125 * Test if delsp is being used for this entity. 00126 * 00127 * @return boolean 00128 */ 00129 public function getDelSp() 00130 { 00131 return ($this->_getHeaderParameter('Content-Type', 'delsp') == 'yes') 00132 ? true 00133 : false; 00134 } 00135 00136 /** 00137 * Turn delsp on or off for this entity. 00138 * 00139 * @param boolean $delsp 00140 */ 00141 public function setDelSp($delsp = true) 00142 { 00143 $this->_setHeaderParameter('Content-Type', 'delsp', $delsp ? 'yes' : null); 00144 $this->_userDelSp = $delsp; 00145 return $this; 00146 } 00147 00148 /** 00149 * Get the nesting level of this entity. 00150 * 00151 * @return int 00152 * @see LEVEL_TOP, LEVEL_ALTERNATIVE, LEVEL_MIXED, LEVEL_RELATED 00153 */ 00154 public function getNestingLevel() 00155 { 00156 return $this->_nestingLevel; 00157 } 00158 00159 /** 00160 * Receive notification that the charset has changed on this document, or a 00161 * parent document. 00162 * 00163 * @param string $charset 00164 */ 00165 public function charsetChanged($charset) 00166 { 00167 $this->setCharset($charset); 00168 } 00169 00170 // -- Protected methods 00171 00172 /** Fix the content-type and encoding of this entity */ 00173 protected function _fixHeaders() 00174 { 00175 parent::_fixHeaders(); 00176 if (count($this->getChildren())) 00177 { 00178 $this->_setHeaderParameter('Content-Type', 'charset', null); 00179 $this->_setHeaderParameter('Content-Type', 'format', null); 00180 $this->_setHeaderParameter('Content-Type', 'delsp', null); 00181 } 00182 else 00183 { 00184 $this->setCharset($this->_userCharset); 00185 $this->setFormat($this->_userFormat); 00186 $this->setDelSp($this->_userDelSp); 00187 } 00188 } 00189 00190 /** Set the nesting level of this entity */ 00191 protected function _setNestingLevel($level) 00192 { 00193 $this->_nestingLevel = $level; 00194 } 00195 00196 }
1.8.0