Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
multipart.php
1
<?php
8
namespace
Bitrix\Main\Mail
;
9
14
class
Multipart
extends
Part
15
{
16
const
MIXED
=
'multipart/mixed'
;
17
const
ALTERNATIVE
=
'multipart/alternative'
;
18
const
RELATED
=
'multipart/related'
;
19
21
protected
$parts
= [];
22
24
protected
$uniqueString
;
25
27
protected
$eol
;
28
32
public
function
__construct
()
33
{
34
parent::__construct();
35
$this->uniqueString = mb_substr(uniqid(mt_rand(100, 999)), 0, 10);
36
$this->
setContentType
(self::MIXED);
37
}
38
45
public
function
setEol
(
$eol
)
46
{
47
parent::setEol(
$eol
);
48
foreach
($this->parts as $part)
49
{
50
$part->setEol($this->
getEol
());
51
}
52
return
$this;
53
}
54
61
public
function
setContentType
($type)
62
{
63
$boundary = $this->
getBoundary
($type);
64
$this->
addHeader
(
'Content-Type'
,
"$type; boundary=\"$boundary\""
);
65
return
$this;
66
}
67
74
public
function
addPart
(
Part
$part)
75
{
76
$part->
setEol
($this->
getEol
());
77
$this->parts[] = $part;
78
return
$this;
79
}
80
86
public
function
toStringHeaders
()
87
{
88
$count = count($this->parts);
89
if
($count === 0)
90
{
91
return
''
;
92
}
93
elseif ($count === 1)
94
{
95
return
current($this->parts)->toStringHeaders();
96
}
97
98
return
parent::toStringHeaders();
99
}
100
106
public
function
toStringBody
()
107
{
108
$count = count($this->parts);
109
if
($count === 0)
110
{
111
return
''
;
112
}
113
elseif ($count === 1)
114
{
115
return
current($this->parts)->toStringBody();
116
}
117
118
119
$result =
''
;
120
$boundary = $this->
getBoundary
();
121
foreach
($this->parts as $part)
122
{
123
$result .=
'--'
. $boundary .
$this->eol
;
124
$result .= (string) $part;
125
}
126
$result .=
'--'
. $boundary .
'--'
.
$this->eol
;
127
128
return
$result;
129
}
130
136
protected
function
getPartCount
()
137
{
138
$count = 0;
139
foreach
($this->parts as $part)
140
{
141
if
($part instanceof
Multipart
)
142
{
143
$count += $part->getPartCount();
144
}
145
else
146
{
147
$count += 1;
148
}
149
}
150
151
return
$count;
152
}
153
160
protected
function
getBoundary
($contentType =
null
)
161
{
162
$type = $contentType ?: $this->
getHeader
(
'Content-Type'
);
163
$type = explode(
';'
, $type);
164
$type = $type[0];
165
switch
($type)
166
{
167
case
self::MIXED
:
168
$prefix =
'mix'
;
169
break
;
170
171
case
self::ALTERNATIVE
:
172
$prefix =
'alt'
;
173
break
;
174
175
default
:
176
$prefix =
''
;
177
}
178
179
return
'-------'
. $prefix .
$this->uniqueString
;
180
}
181
}
Bitrix\Main\Mail\Multipart
Definition
multipart.php:15
Bitrix\Main\Mail\Multipart\__construct
__construct()
Definition
multipart.php:32
Bitrix\Main\Mail\Multipart\ALTERNATIVE
const ALTERNATIVE
Definition
multipart.php:17
Bitrix\Main\Mail\Multipart\RELATED
const RELATED
Definition
multipart.php:18
Bitrix\Main\Mail\Multipart\addPart
addPart(Part $part)
Definition
multipart.php:74
Bitrix\Main\Mail\Multipart\MIXED
const MIXED
Definition
multipart.php:16
Bitrix\Main\Mail\Multipart\$uniqueString
$uniqueString
Definition
multipart.php:24
Bitrix\Main\Mail\Multipart\setContentType
setContentType($type)
Definition
multipart.php:61
Bitrix\Main\Mail\Multipart\getPartCount
getPartCount()
Definition
multipart.php:136
Bitrix\Main\Mail\Multipart\getBoundary
getBoundary($contentType=null)
Definition
multipart.php:160
Bitrix\Main\Mail\Multipart\$parts
$parts
Definition
multipart.php:21
Bitrix\Main\Mail\Multipart\toStringHeaders
toStringHeaders()
Definition
multipart.php:86
Bitrix\Main\Mail\Multipart\$eol
$eol
Definition
multipart.php:27
Bitrix\Main\Mail\Multipart\setEol
setEol($eol)
Definition
multipart.php:45
Bitrix\Main\Mail\Multipart\toStringBody
toStringBody()
Definition
multipart.php:106
Bitrix\Main\Mail\Part
Definition
part.php:15
Bitrix\Main\Mail\Part\addHeader
addHeader($name, $value)
Definition
part.php:62
Bitrix\Main\Mail\Part\getHeader
getHeader($name)
Definition
part.php:100
Bitrix\Main\Mail\Part\getEol
getEol()
Definition
part.php:38
Bitrix\Main\Mail\Part\setEol
setEol($eol)
Definition
part.php:49
Bitrix\Main\Mail
Definition
address.php:8
modules
main
lib
mail
multipart.php
Создано системой
1.10.0