private function parseMultiparts(string $pid, string $mimeType, string $lookFor = 'all', int $pidAdd = 1, bool $getAlternative = true)
{
// If the type is message/rfc822, gathers subparts that begin with the same Id
// Skips multipart/alternative or multipart/report
$excludeMime = $mimeType;
$mimeType = 'text/plain' == $excludeMime ? 'text/html' : 'text/plain';
$partLevel = count(explode('.', $pid));
$pidLength = strlen($pid);
foreach ($this->structure['pid'] as $partNo => $id) {
$level = count(explode('.', $this->structure['pid'][$partNo]));
switch ($lookFor) {
case 'all':
$condition = true;
break;
case 'subparts':
$condition = $level == $partLevel + 1 && $pid == substr($this->structure['pid'][$partNo], 0, $pidLength);
break;
case 'top':
// Break missing intentionally
// Break missing intentionally
default:
if ($this->isMultipart('related') || $this->isMultipart('mixed')) {
// Top level and second level, but the same parent
$condition = false === strpos($this->structure['pid'][$partNo], '.') || 2 == $level && substr($this->defaultPid, 0, 1) == substr($this->structure['pid'][$partNo], 0, 1);
} else {
// Top level
$condition = false === strpos($this->structure['pid'][$partNo], '.');
}
break;
}
if ($condition) {
if ($this->isPartMultipart($partNo, 'alternative') || $this->isPartMultipart($partNo, 'report') || $this->isPartMultipart($partNo, 'mixed')) {
$subLevel = count(explode('.', $this->structure['pid'][$partNo]));
foreach ($this->structure['pid'] as $multipartNo => $multipartPid) {
// Part must begin with the last tested Id and be in the next level
if ($this->structure['ftype'][$multipartNo] == $mimeType && $getAlternative && $subLevel == $partLevel + $pidAdd && $pid == substr($multipartPid, 0, strlen($this->structure['pid'][$partNo]))) {
$this->addPart($partNo, 'inline');
break;
}
}
} elseif ('inline' == $this->structure['disposition'][$partNo] && !$this->isPartMultipart($partNo, 'related') && !$this->isPartMultipart($partNo, 'mixed')) {
// It is inline, but not related or mixed type
if ($this->structure['ftype'][$partNo] != $excludeMime && $pid != $this->structure['pid'][$partNo] && ($getAlternative || !$this->isParentAlternative($partNo)) || $this->structure['ftype'][$partNo] == $excludeMime && isset($this->structure['fname'][$partNo]) && $pid != $this->structure['pid'][$partNo]) {
$this->addPart($partNo, 'inline');
}
} elseif ('attachment' == $this->structure['disposition'][$partNo]) {
// It is an attachment; add to the attachment list
$this->addPart($partNo, 'attach');
}
}
}
}