Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
part.php
1<?php
8namespace Bitrix\Main\Mail;
9
14class Part
15{
17 protected $headers = [];
18
20 protected $body = '';
21
23 protected $eol;
24
28 public function __construct()
29 {
30 $this->eol = Mail::getMailEol();
31 }
32
38 public function getEol()
39 {
40 return $this->eol;
41 }
42
49 public function setEol($eol)
50 {
51 $this->eol = $eol;
52 return $this;
53 }
54
62 public function addHeader($name, $value)
63 {
64 $this->headers[$name] = $value;
65 return $this;
66 }
67
74 public function setHeaders(array $headers)
75 {
76 $this->headers = [];
77 foreach ($headers as $name => $value)
78 {
79 $this->addHeader($name, $value);
80 }
81 return $this;
82 }
83
89 public function getHeaders()
90 {
91 return $this->headers;
92 }
93
100 public function getHeader($name)
101 {
102 return $this->headers[$name] ?? null;
103 }
104
111 public function setBody($body)
112 {
113 $this->body = $body;
114 return $this;
115 }
116
122 public function getBody()
123 {
124 return $this->body;
125 }
126
132 public function toStringBody()
133 {
134 return $this->splitBody($this->body) . $this->eol . $this->eol;
135 }
136
142 public function toStringHeaders()
143 {
144 $result = '';
145 foreach ($this->headers as $name => $value)
146 {
147 $result .= $name . ': '. $value . $this->eol;
148 }
149
150 return $result ? $result : '';
151 }
152
158 public function toString()
159 {
160 return $this->toStringHeaders() . $this->eol . $this->toStringBody();
161 }
162
168 public function __toString()
169 {
170 return $this->toString();
171 }
172
173 protected function splitBody(&$body)
174 {
175 if ($this->getHeader('Content-Transfer-Encoding') === 'base64')
176 {
177 return rtrim(chunk_split(base64_encode($body), 76, $this->eol));
178 }
179 elseif ($this->getHeader('Content-Transfer-Encoding') === 'quoted-printable')
180 {
181 return str_replace(
182 $this->eol !== "\r\n" ? "=\r\n" : '',
183 '=' . $this->eol,
184 quoted_printable_encode($body)
185 );
186 }
187 else
188 {
189 return preg_replace(
190 '/(.{1,990})(?:\s|$)|(.{990})/S',
191 '$1$2' . $this->eol,
192 $body
193 );
194 }
195 }
196}
addHeader($name, $value)
Definition part.php:62
setHeaders(array $headers)
Definition part.php:74