[ Index ] |
MailPress 7.2 |
[ Index ] [ Classes ] [ Functions ] [ Variables ] [ Constants ] [ Statistics ] |
[Summary view] [Print] [Text view]
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 /** 12 * A MIME part, in a multipart message. 13 * 14 * @author Chris Corbyn 15 */ 16 class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity 17 { 18 /** The format parameter last specified by the user */ 19 protected $userFormat; 20 21 /** The charset last specified by the user */ 22 protected $userCharset; 23 24 /** The delsp parameter last specified by the user */ 25 protected $userDelSp; 26 27 /** The nesting level of this MimePart */ 28 private $nestingLevel = self::LEVEL_ALTERNATIVE; 29 30 /** 31 * Create a new MimePart with $headers, $encoder and $cache. 32 * 33 * @param string $charset 34 */ 35 public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $charset = null) 36 { 37 parent::__construct($headers, $encoder, $cache, $idGenerator); 38 $this->setContentType('text/plain'); 39 if (null !== $charset) { 40 $this->setCharset($charset); 41 } 42 } 43 44 /** 45 * Set the body of this entity, either as a string, or as an instance of 46 * {@link Swift_OutputByteStream}. 47 * 48 * @param mixed $body 49 * @param string $contentType optional 50 * @param string $charset optional 51 * 52 * @return $this 53 */ 54 public function setBody($body, $contentType = null, $charset = null) 55 { 56 if (isset($charset)) { 57 $this->setCharset($charset); 58 } 59 $body = $this->convertString($body); 60 61 parent::setBody($body, $contentType); 62 63 return $this; 64 } 65 66 /** 67 * Get the character set of this entity. 68 * 69 * @return string 70 */ 71 public function getCharset() 72 { 73 return $this->getHeaderParameter('Content-Type', 'charset'); 74 } 75 76 /** 77 * Set the character set of this entity. 78 * 79 * @param string $charset 80 * 81 * @return $this 82 */ 83 public function setCharset($charset) 84 { 85 $this->setHeaderParameter('Content-Type', 'charset', $charset); 86 if ($charset !== $this->userCharset) { 87 $this->clearCache(); 88 } 89 $this->userCharset = $charset; 90 parent::charsetChanged($charset); 91 92 return $this; 93 } 94 95 /** 96 * Get the format of this entity (i.e. flowed or fixed). 97 * 98 * @return string 99 */ 100 public function getFormat() 101 { 102 return $this->getHeaderParameter('Content-Type', 'format'); 103 } 104 105 /** 106 * Set the format of this entity (flowed or fixed). 107 * 108 * @param string $format 109 * 110 * @return $this 111 */ 112 public function setFormat($format) 113 { 114 $this->setHeaderParameter('Content-Type', 'format', $format); 115 $this->userFormat = $format; 116 117 return $this; 118 } 119 120 /** 121 * Test if delsp is being used for this entity. 122 * 123 * @return bool 124 */ 125 public function getDelSp() 126 { 127 return 'yes' === $this->getHeaderParameter('Content-Type', 'delsp'); 128 } 129 130 /** 131 * Turn delsp on or off for this entity. 132 * 133 * @param bool $delsp 134 * 135 * @return $this 136 */ 137 public function setDelSp($delsp = true) 138 { 139 $this->setHeaderParameter('Content-Type', 'delsp', $delsp ? 'yes' : null); 140 $this->userDelSp = $delsp; 141 142 return $this; 143 } 144 145 /** 146 * Get the nesting level of this entity. 147 * 148 * @see LEVEL_TOP, LEVEL_ALTERNATIVE, LEVEL_MIXED, LEVEL_RELATED 149 * 150 * @return int 151 */ 152 public function getNestingLevel() 153 { 154 return $this->nestingLevel; 155 } 156 157 /** 158 * Receive notification that the charset has changed on this document, or a 159 * parent document. 160 * 161 * @param string $charset 162 */ 163 public function charsetChanged($charset) 164 { 165 $this->setCharset($charset); 166 } 167 168 /** Fix the content-type and encoding of this entity */ 169 protected function fixHeaders() 170 { 171 parent::fixHeaders(); 172 if (count($this->getChildren())) { 173 $this->setHeaderParameter('Content-Type', 'charset', null); 174 $this->setHeaderParameter('Content-Type', 'format', null); 175 $this->setHeaderParameter('Content-Type', 'delsp', null); 176 } else { 177 $this->setCharset($this->userCharset); 178 $this->setFormat($this->userFormat); 179 $this->setDelSp($this->userDelSp); 180 } 181 } 182 183 /** Set the nesting level of this entity */ 184 protected function setNestingLevel($level) 185 { 186 $this->nestingLevel = $level; 187 } 188 189 /** Encode charset when charset is not utf-8 */ 190 protected function convertString($string) 191 { 192 $charset = strtolower($this->getCharset()); 193 if (!in_array($charset, ['utf-8', 'iso-8859-1', 'iso-8859-15', ''])) { 194 return mb_convert_encoding($string, $charset, 'utf-8'); 195 } 196 197 return $string; 198 } 199 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue May 19 15:55:14 2020 | Cross-referenced by PHPXref 0.7.1 |