Skip to content

Commit 63d2f52

Browse files
fix imap_body
1 parent b1abd1c commit 63d2f52

File tree

1 file changed

+73
-5
lines changed

1 file changed

+73
-5
lines changed

src/BodyStructure.php

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ protected static function fromBodyStructure($structure)
9191
protected static function extractPart($item)
9292
{
9393
global $countParts;
94-
95-
$countParts++;
96-
file_put_contents('p'.$countParts.'.json', json_encode($item, JSON_PRETTY_PRINT));
97-
94+
9895
$attribute = null;
9996
$parameters = [];
10097

@@ -180,11 +177,82 @@ protected static function processSubParts($item, $part)
180177
}
181178

182179
$part->parts = [
183-
$item[8]
180+
self::processSubPartAsMessage($item)
184181
];
185182

186183
return $part;
187184
}
185+
186+
protected static function processSubPartAsMessage($item)
187+
{
188+
$message = (object) [
189+
'type' => 1,
190+
'encoding' => 0,
191+
'ifsubtype' => 1,
192+
'subtype' => 'MIXED',
193+
'ifdescription' => 0,
194+
'ifid' => 0,
195+
'ifdisposition' => 0,
196+
'ifdparameters' => 0,
197+
'ifparameters' => 1,
198+
'parameters' => [
199+
(object) [
200+
'attribute' => 'BOUNDARY',
201+
'value' => '=_995890bdbf8bd158f2cbae0e8d966000'
202+
]
203+
],
204+
'parts' => [
205+
206+
]
207+
];
208+
209+
foreach ($item[8] as $itemPart) {
210+
$part = (object) [
211+
'type' => 0,
212+
'encoding' => 0,
213+
'ifsubtype' => 1,
214+
'subtype' => 'PLAIN',
215+
'ifdescription' => 0,
216+
'ifid' => 0,
217+
'lines' => 1,
218+
'bytes' => 9,
219+
'ifdisposition' => 0,
220+
'ifdparameters' => 0,
221+
'ifparameters' => 1,
222+
'parameters' => []
223+
];
224+
225+
if (isset($itemPart[][0])) {
226+
$attribute = null;
227+
$dispositionParameters = [];
228+
$part->disposition = $item[$dispositionIndex][0];
229+
if (isset($item[$dispositionIndex][1]) && is_array($item[$dispositionIndex][1])) {
230+
foreach ($item[$dispositionIndex][1] as $value) {
231+
if (empty($attribute)) {
232+
$attribute = [
233+
'attribute' => $value,
234+
'value' => null,
235+
];
236+
} else {
237+
$attribute['value'] = $value;
238+
$dispositionParameters[] = (object)$attribute;
239+
$attribute = null;
240+
}
241+
}
242+
}
243+
$part->dparameters = $dispositionParameters;
244+
$part->ifdparameters = 1;
245+
$part->ifdisposition = 1;
246+
} else {
247+
unset($part->disposition);
248+
unset($part->dparameters);
249+
}
250+
251+
$message->parts[] = $part;
252+
}
253+
254+
return $message;
255+
}
188256

189257
protected static function extractParameters($attributes, $parameters)
190258
{

0 commit comments

Comments
 (0)