XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
MimePart.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of SwiftMailer.
5  * (c) 2004-2009 Chris Corbyn
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10 
11 //@require 'Swift/Mime/SimpleMimeEntity.php';
12 //@require 'Swift/Mime/ContentEncoder.php';
13 //@require 'Swift/Mime/HeaderSet.php';
14 //@require 'Swift/KeyCache.php';
15 
24 {
25 
27  protected $_userFormat;
28 
30  protected $_userCharset;
31 
33  protected $_userDelSp;
34 
36  private $_nestingLevel = self::LEVEL_ALTERNATIVE;
37 
46  public function __construct(Swift_Mime_HeaderSet $headers,
47  Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, $charset = null)
48  {
49  parent::__construct($headers, $encoder, $cache);
50  $this->setContentType('text/plain');
51  if (!is_null($charset))
52  {
53  $this->setCharset($charset);
54  }
55  }
56 
65  public function setBody($body, $contentType = null, $charset = null)
66  {
67  parent::setBody($body, $contentType);
68  if (isset($charset))
69  {
70  $this->setCharset($charset);
71  }
72  return $this;
73  }
74 
80  public function getCharset()
81  {
82  return $this->_getHeaderParameter('Content-Type', 'charset');
83  }
84 
90  public function setCharset($charset)
91  {
92  $this->_setHeaderParameter('Content-Type', 'charset', $charset);
93  if ($charset !== $this->_userCharset)
94  {
95  $this->_clearCache();
96  }
97  $this->_userCharset = $charset;
98  parent::charsetChanged($charset);
99  return $this;
100  }
101 
107  public function getFormat()
108  {
109  return $this->_getHeaderParameter('Content-Type', 'format');
110  }
111 
117  public function setFormat($format)
118  {
119  $this->_setHeaderParameter('Content-Type', 'format', $format);
120  $this->_userFormat = $format;
121  return $this;
122  }
123 
129  public function getDelSp()
130  {
131  return ($this->_getHeaderParameter('Content-Type', 'delsp') == 'yes')
132  ? true
133  : false;
134  }
135 
141  public function setDelSp($delsp = true)
142  {
143  $this->_setHeaderParameter('Content-Type', 'delsp', $delsp ? 'yes' : null);
144  $this->_userDelSp = $delsp;
145  return $this;
146  }
147 
154  public function getNestingLevel()
155  {
156  return $this->_nestingLevel;
157  }
158 
165  public function charsetChanged($charset)
166  {
167  $this->setCharset($charset);
168  }
169 
170  // -- Protected methods
171 
173  protected function _fixHeaders()
174  {
175  parent::_fixHeaders();
176  if (count($this->getChildren()))
177  {
178  $this->_setHeaderParameter('Content-Type', 'charset', null);
179  $this->_setHeaderParameter('Content-Type', 'format', null);
180  $this->_setHeaderParameter('Content-Type', 'delsp', null);
181  }
182  else
183  {
184  $this->setCharset($this->_userCharset);
185  $this->setFormat($this->_userFormat);
186  $this->setDelSp($this->_userDelSp);
187  }
188  }
189 
191  protected function _setNestingLevel($level)
192  {
193  $this->_nestingLevel = $level;
194  }
195 
196 }