Skip to content

Commit 584bba7

Browse files
committed
Small adjustments
1 parent b1ae29a commit 584bba7

File tree

3 files changed

+36
-33
lines changed

3 files changed

+36
-33
lines changed

src/HasMessageAccessors.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ abstract public function addresses(string $header): array;
3131
*/
3232
abstract public function header(string $name, int $offset = 0): ?IHeader;
3333

34-
/**
35-
* Determine if the attachment should be treated as an embedded forwarded message.
36-
*/
37-
abstract protected function isForwardedMessage(IMessagePart $part): bool;
38-
3934
/**
4035
* Get the message date and time.
4136
*/
@@ -105,9 +100,7 @@ public function inReplyTo(): array
105100
{
106101
$parts = $this->header(HeaderConsts::IN_REPLY_TO)?->getParts() ?? [];
107102

108-
$values = array_map(function (IHeaderPart $part) {
109-
return $part->getValue();
110-
}, $parts);
103+
$values = array_map(fn (IHeaderPart $part) => $part->getValue(), $parts);
111104

112105
return array_values(array_filter($values));
113106
}
@@ -199,4 +192,14 @@ public function attachmentCount(): int
199192
{
200193
return $this->parse()->getAttachmentCount();
201194
}
195+
196+
/**
197+
* Determine if the attachment should be treated as an embedded forwarded message.
198+
*/
199+
protected function isForwardedMessage(IMessagePart $part): bool
200+
{
201+
return empty($part->getFilename())
202+
&& strtolower((string) $part->getContentType()) === 'message/rfc822'
203+
&& strtolower((string) $part->getContentDisposition()) !== 'attachment';
204+
}
202205
}

src/HasParsedMessage.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use ZBateson\MailMimeParser\Header\Part\ContainerPart;
1010
use ZBateson\MailMimeParser\Header\Part\NameValuePart;
1111
use ZBateson\MailMimeParser\IMessage;
12-
use ZBateson\MailMimeParser\Message\IMessagePart;
1312

1413
trait HasParsedMessage
1514
{
@@ -53,16 +52,6 @@ public function addresses(string $header): array
5352
return array_filter($addresses);
5453
}
5554

56-
/**
57-
* Determine if the attachment should be treated as an embedded forwarded message.
58-
*/
59-
protected function isForwardedMessage(IMessagePart $part): bool
60-
{
61-
return empty($part->getFilename())
62-
&& strtolower((string) $part->getContentType()) === 'message/rfc822'
63-
&& strtolower((string) $part->getContentDisposition()) !== 'attachment';
64-
}
65-
6655
/**
6756
* Parse the message into a MailMimeMessage instance.
6857
*/

src/Message.php

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use ZBateson\MailMimeParser\Header\Part\AddressPart;
2020
use ZBateson\MailMimeParser\Header\Part\ContainerPart;
2121
use ZBateson\MailMimeParser\Header\Part\NameValuePart;
22+
use ZBateson\MailMimeParser\Message\IMessagePart;
2223

2324
class Message implements Arrayable, JsonSerializable, MessageInterface
2425
{
@@ -452,6 +453,25 @@ public function attachments(bool $lazy = false): array
452453
return $this->getParsedAttachments();
453454
}
454455

456+
/**
457+
* Get attachments using lazy loading from body structure.
458+
*
459+
* @return Attachment[]
460+
*/
461+
protected function getLazyAttachments(): array
462+
{
463+
return array_map(
464+
fn (BodyStructurePart $part) => new Attachment(
465+
$part->filename(),
466+
$part->id(),
467+
$part->contentType(),
468+
$part->disposition()?->type()?->value,
469+
new Support\LazyBodyPartStream($this, $part),
470+
),
471+
$this->bodyStructure(lazy: true)?->attachments() ?? []
472+
);
473+
}
474+
455475
/**
456476
* Get attachments from the parsed message.
457477
*
@@ -499,22 +519,13 @@ public function attachmentCount(): int
499519
}
500520

501521
/**
502-
* Get attachments using lazy loading from body structure.
503-
*
504-
* @return Attachment[]
522+
* Determine if the attachment should be treated as an embedded forwarded message.
505523
*/
506-
protected function getLazyAttachments(): array
524+
protected function isForwardedMessage(IMessagePart $part): bool
507525
{
508-
return array_map(
509-
fn (BodyStructurePart $part) => new Attachment(
510-
$part->filename(),
511-
$part->id(),
512-
$part->contentType(),
513-
$part->disposition()?->type()?->value,
514-
new Support\LazyBodyPartStream($this, $part),
515-
),
516-
$this->bodyStructure(lazy: true)?->attachments() ?? []
517-
);
526+
return empty($part->getFilename())
527+
&& strtolower((string) $part->getContentType()) === 'message/rfc822'
528+
&& strtolower((string) $part->getContentDisposition()) !== 'attachment';
518529
}
519530

520531
/**

0 commit comments

Comments
 (0)