Avail feature updated
[ninja.git] / application / vendor / swiftmailer / classes / Swift / Mime / MimePart.php
blob78c6fe09f4cdd325c09c3a62b42669907d7de8fc
1 <?php
3 /*
4 * This file is part of SwiftMailer.
5 * (c) 2004-2009 Chris Corbyn
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
11 //@require 'Swift/Mime/SimpleMimeEntity.php';
12 //@require 'Swift/Mime/ContentEncoder.php';
13 //@require 'Swift/Mime/HeaderSet.php';
14 //@require 'Swift/KeyCache.php';
16 /**
17 * A MIME part, in a multipart message.
19 * @package Swift
20 * @subpackage Mime
21 * @author Chris Corbyn
23 class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
26 /** The format parameter last specified by the user */
27 protected $_userFormat;
29 /** The charset last specified by the user */
30 protected $_userCharset;
32 /** The delsp parameter last specified by the user */
33 protected $_userDelSp;
35 /** The nesting level of this MimePart */
36 private $_nestingLevel = self::LEVEL_ALTERNATIVE;
38 /**
39 * Create a new MimePart with $headers, $encoder and $cache.
41 * @param Swift_Mime_HeaderSet $headers
42 * @param Swift_Mime_ContentEncoder $encoder
43 * @param Swift_KeyCache $cache
44 * @param string $charset
46 public function __construct(Swift_Mime_HeaderSet $headers,
47 Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, $charset = null)
49 parent::__construct($headers, $encoder, $cache);
50 $this->setContentType('text/plain');
51 if (!is_null($charset))
53 $this->setCharset($charset);
57 /**
58 * Set the body of this entity, either as a string, or as an instance of
59 * {@link Swift_OutputByteStream}.
61 * @param mixed $body
62 * @param string $contentType optional
63 * @param string $charset optional
65 public function setBody($body, $contentType = null, $charset = null)
67 parent::setBody($body, $contentType);
68 if (isset($charset))
70 $this->setCharset($charset);
72 return $this;
75 /**
76 * Get the character set of this entity.
78 * @return string
80 public function getCharset()
82 return $this->_getHeaderParameter('Content-Type', 'charset');
85 /**
86 * Set the character set of this entity.
88 * @param string $charset
90 public function setCharset($charset)
92 $this->_setHeaderParameter('Content-Type', 'charset', $charset);
93 if ($charset !== $this->_userCharset)
95 $this->_clearCache();
97 $this->_userCharset = $charset;
98 parent::charsetChanged($charset);
99 return $this;
103 * Get the format of this entity (i.e. flowed or fixed).
105 * @return string
107 public function getFormat()
109 return $this->_getHeaderParameter('Content-Type', 'format');
113 * Set the format of this entity (flowed or fixed).
115 * @param string $format
117 public function setFormat($format)
119 $this->_setHeaderParameter('Content-Type', 'format', $format);
120 $this->_userFormat = $format;
121 return $this;
125 * Test if delsp is being used for this entity.
127 * @return boolean
129 public function getDelSp()
131 return ($this->_getHeaderParameter('Content-Type', 'delsp') == 'yes')
132 ? true
133 : false;
137 * Turn delsp on or off for this entity.
139 * @param boolean $delsp
141 public function setDelSp($delsp = true)
143 $this->_setHeaderParameter('Content-Type', 'delsp', $delsp ? 'yes' : null);
144 $this->_userDelSp = $delsp;
145 return $this;
149 * Get the nesting level of this entity.
151 * @return int
152 * @see LEVEL_TOP, LEVEL_ALTERNATIVE, LEVEL_MIXED, LEVEL_RELATED
154 public function getNestingLevel()
156 return $this->_nestingLevel;
160 * Receive notification that the charset has changed on this document, or a
161 * parent document.
163 * @param string $charset
165 public function charsetChanged($charset)
167 $this->setCharset($charset);
170 // -- Protected methods
172 /** Fix the content-type and encoding of this entity */
173 protected function _fixHeaders()
175 parent::_fixHeaders();
176 if (count($this->getChildren()))
178 $this->_setHeaderParameter('Content-Type', 'charset', null);
179 $this->_setHeaderParameter('Content-Type', 'format', null);
180 $this->_setHeaderParameter('Content-Type', 'delsp', null);
182 else
184 $this->setCharset($this->_userCharset);
185 $this->setFormat($this->_userFormat);
186 $this->setDelSp($this->_userDelSp);
190 /** Set the nesting level of this entity */
191 protected function _setNestingLevel($level)
193 $this->_nestingLevel = $level;