public function getRelatedParts(string $pid, array $types, bool $all = false) : array
{
try {
$this->checkIfParsed();
} catch (\Jyxo\Mail\Parser\EmailNotExistException $e) {
throw $e;
}
$related = [];
if (!empty($this->structure['pid'])) {
// Deals a problem with multipart/alternative and multipart/report, when they are as the first part and don't have any real Ids (they have a fake Id 0 assigned then)
if ('0' === $pid) {
for ($i = 1; $i < count($this->structure['pid']); $i++) {
// Subparts do not contain a dot because they are in the first level
if (false === strpos($this->structure['pid'][$i], '.') && ($all || in_array($this->structure['ftype'][$i], $types))) {
$related['pid'][] = $this->structure['pid'][$i];
$related['ftype'][] = $this->structure['ftype'][$i];
}
}
} else {
$level = count(explode('.', $pid));
foreach ($this->structure['pid'] as $i => $rpid) {
// Part is one level deeper and the first number equals to the parent
if (count(explode('.', $rpid)) == $level + 1 && $pid == substr($rpid, 0, strrpos($rpid, '.'))) {
if ($all || in_array($this->structure['ftype'][$i], $types)) {
$related['pid'][] = $this->structure['pid'][$i];
$related['ftype'][] = $this->structure['ftype'][$i];
}
}
}
}
}
return $related;
}