Skip to content

Commit 71a4394

Browse files
committed
Support lazy in bodyStructure
1 parent 676c781 commit 71a4394

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/Message.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,15 @@ public function hasBody(): bool
110110
}
111111

112112
/**
113-
* Get the message's body structure, fetching it from the server if necessary.
113+
* Get the message's body structure.
114114
*/
115-
public function bodyStructure(): ?BodyStructureCollection
115+
public function bodyStructure(bool $lazy = false): ?BodyStructureCollection
116116
{
117117
if ($this->bodyStructure) {
118118
return $this->bodyStructure;
119119
}
120120

121-
// If we don't have body structure data, lazy load it from the server.
122-
if (! $this->bodyStructureData) {
121+
if (! $this->bodyStructureData && $lazy) {
123122
$this->bodyStructureData = $this->fetchBodyStructureData();
124123
}
125124

@@ -233,7 +232,7 @@ public function move(string $folder, bool $expunge = false): ?int
233232
public function text(bool $lazy = false): ?string
234233
{
235234
if ($lazy && ! $this->hasBody()) {
236-
if ($part = $this->bodyStructure()?->text()) {
235+
if ($part = $this->bodyStructure(lazy: true)?->text()) {
237236
return Support\BodyPartDecoder::text($part, $this->bodyPart($part->partNumber()));
238237
}
239238
}
@@ -247,7 +246,7 @@ public function text(bool $lazy = false): ?string
247246
public function html(bool $lazy = false): ?string
248247
{
249248
if ($lazy && ! $this->hasBody()) {
250-
if ($part = $this->bodyStructure()?->html()) {
249+
if ($part = $this->bodyStructure(lazy: true)?->html()) {
251250
return Support\BodyPartDecoder::text($part, $this->bodyPart($part->partNumber()));
252251
}
253252
}
@@ -284,7 +283,7 @@ protected function getLazyAttachments(): array
284283
$part->disposition()?->type()?->value,
285284
new Support\LazyBodyPartStream($this, $part),
286285
),
287-
$this->bodyStructure()?->attachments() ?? []
286+
$this->bodyStructure(lazy: true)?->attachments() ?? []
288287
);
289288
}
290289

0 commit comments

Comments
 (0)