Skip to content

Commit 5f3e1e1

Browse files
committed
Treat eml attachments as attachments
1 parent fb187fb commit 5f3e1e1

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/HasParsedMessage.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use ZBateson\MailMimeParser\Header\Part\ContainerPart;
1414
use ZBateson\MailMimeParser\Header\Part\NameValuePart;
1515
use ZBateson\MailMimeParser\Message as MailMimeMessage;
16+
use ZBateson\MailMimeParser\Message\IMessagePart;
1617

1718
trait HasParsedMessage
1819
{
@@ -121,10 +122,7 @@ public function attachments(): array
121122
$attachments = [];
122123

123124
foreach ($this->parse()->getAllAttachmentParts() as $part) {
124-
// If the attachment's content type is message/rfc822, we're
125-
// working with a forwarded message. We will parse the
126-
// forwarded message and merge in its attachments.
127-
if (strtolower($part->getContentType()) === 'message/rfc822') {
125+
if ($this->isForwardedMessage($part)) {
128126
$message = new FileMessage($part->getContent());
129127

130128
$attachments = array_merge($attachments, $message->attachments());
@@ -157,6 +155,16 @@ public function attachmentCount(): int
157155
return $this->parse()->getAttachmentCount();
158156
}
159157

158+
/**
159+
* Determine if the attachment should be treated as an embedded forwarded message.
160+
*/
161+
protected function isForwardedMessage(IMessagePart $part): bool
162+
{
163+
return empty($part->getFilename())
164+
&& strtolower((string) $part->getContentType()) === 'message/rfc822'
165+
&& strtolower((string) $part->getContentDisposition()) !== 'attachment';
166+
}
167+
160168
/**
161169
* Get addresses from the given header.
162170
*

0 commit comments

Comments
 (0)