Skip to content

Commit

Permalink
Process root element of embedded emails
Browse files Browse the repository at this point in the history
An email with an embedded email can have the following structure:

1: "text/plain"
2: "message/rfc822"
2: "multipart/mixed"
2.1: "text/plain"
2.2: "application/octet-stream"
2.3, "application/octet-stream"

Before this fix this structure was parsed as

1: "text/plain"
2: "message/rfc822"
2.1: "multipart/mixed"
2.1.1: "text/plain"
2.1.2: "application/octet-stream"
2.1.3, "application/octet-stream"

Hence, downloading attachments was not possible due to wrong part
identifiers

resolves tedious#188, tedious#43
  • Loading branch information
Christian Bartels committed Oct 19, 2017
1 parent 9a1b0eb commit 1602b3d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Fetch/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,15 +562,21 @@ protected function processStructure($structure, $partIdentifier = null)
}
}

if (isset($structure->parts)) { // multipart: iterate through each part
if (! empty($structure->parts)) {

foreach ($structure->parts as $partIndex => $part) {
$partId = $partIndex + 1;
if (isset($structure->subtype) && strtolower($structure->subtype) === 'rfc822') {
// rfc822: The root part is processed with the current part identifier
$this->processStructure($structure->parts[0], $partIdentifier);
} else {
// multipart: iterate through each part
foreach ($structure->parts as $partIndex => $part) {
$partId = $partIndex + 1;

if (isset($partIdentifier))
$partId = $partIdentifier . '.' . $partId;
if (isset($partIdentifier))
$partId = $partIdentifier . '.' . $partId;

$this->processStructure($part, $partId);
$this->processStructure($part, $partId);
}
}
}
}
Expand Down

0 comments on commit 1602b3d

Please sign in to comment.