Skip to content

Commit 108b738

Browse files
committed
Use fetch language instead
1 parent 584bba7 commit 108b738

2 files changed

Lines changed: 58 additions & 58 deletions

File tree

src/Message.php

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ public function flags(): array
8787
/**
8888
* Get the message's raw headers.
8989
*/
90-
public function head(bool $lazy = false): string
90+
public function head(bool $fetch = false): string
9191
{
92-
if (! $this->head && $lazy) {
92+
if (! $this->head && $fetch) {
9393
$this->head = $this->fetchHead() ?? '';
9494
}
9595

@@ -146,13 +146,13 @@ public function hasBody(): bool
146146
/**
147147
* Get the message's body structure.
148148
*/
149-
public function bodyStructure(bool $lazy = false): ?BodyStructureCollection
149+
public function bodyStructure(bool $fetch = false): ?BodyStructureCollection
150150
{
151151
if ($this->bodyStructure) {
152152
return $this->bodyStructure;
153153
}
154154

155-
if (! $this->bodyStructureData && $lazy) {
155+
if (! $this->bodyStructureData && $fetch) {
156156
$this->bodyStructureData = $this->fetchBodyStructureData();
157157
}
158158

@@ -263,10 +263,10 @@ public function move(string $folder, bool $expunge = false): ?int
263263
/**
264264
* Get a header from the message.
265265
*/
266-
public function header(string $name, int $offset = 0, bool $lazy = false): ?IHeader
266+
public function header(string $name, int $offset = 0, bool $fetch = false): ?IHeader
267267
{
268-
if ($lazy && ! $this->hasHead()) {
269-
$this->head(lazy: true);
268+
if ($fetch && ! $this->hasHead()) {
269+
$this->head(fetch: true);
270270
}
271271

272272
if ($this->isEmpty()) {
@@ -279,9 +279,9 @@ public function header(string $name, int $offset = 0, bool $lazy = false): ?IHea
279279
/**
280280
* Get the message date and time.
281281
*/
282-
public function date(bool $lazy = false): ?CarbonInterface
282+
public function date(bool $fetch = false): ?CarbonInterface
283283
{
284-
if (! $header = $this->header(HeaderConsts::DATE, lazy: $lazy)) {
284+
if (! $header = $this->header(HeaderConsts::DATE, fetch: $fetch)) {
285285
return null;
286286
}
287287

@@ -299,51 +299,51 @@ public function date(bool $lazy = false): ?CarbonInterface
299299
/**
300300
* Get the message's message-id.
301301
*/
302-
public function messageId(bool $lazy = false): ?string
302+
public function messageId(bool $fetch = false): ?string
303303
{
304-
return $this->header(HeaderConsts::MESSAGE_ID, lazy: $lazy)?->getValue();
304+
return $this->header(HeaderConsts::MESSAGE_ID, fetch: $fetch)?->getValue();
305305
}
306306

307307
/**
308308
* Get the message's subject.
309309
*/
310-
public function subject(bool $lazy = false): ?string
310+
public function subject(bool $fetch = false): ?string
311311
{
312-
return $this->header(HeaderConsts::SUBJECT, lazy: $lazy)?->getValue();
312+
return $this->header(HeaderConsts::SUBJECT, fetch: $fetch)?->getValue();
313313
}
314314

315315
/**
316316
* Get the FROM address.
317317
*/
318-
public function from(bool $lazy = false): ?Address
318+
public function from(bool $fetch = false): ?Address
319319
{
320-
return head($this->addresses(HeaderConsts::FROM, lazy: $lazy)) ?: null;
320+
return head($this->addresses(HeaderConsts::FROM, fetch: $fetch)) ?: null;
321321
}
322322

323323
/**
324324
* Get the SENDER address.
325325
*/
326-
public function sender(bool $lazy = false): ?Address
326+
public function sender(bool $fetch = false): ?Address
327327
{
328-
return head($this->addresses(HeaderConsts::SENDER, lazy: $lazy)) ?: null;
328+
return head($this->addresses(HeaderConsts::SENDER, fetch: $fetch)) ?: null;
329329
}
330330

331331
/**
332332
* Get the REPLY-TO address.
333333
*/
334-
public function replyTo(bool $lazy = false): ?Address
334+
public function replyTo(bool $fetch = false): ?Address
335335
{
336-
return head($this->addresses(HeaderConsts::REPLY_TO, lazy: $lazy)) ?: null;
336+
return head($this->addresses(HeaderConsts::REPLY_TO, fetch: $fetch)) ?: null;
337337
}
338338

339339
/**
340340
* Get the IN-REPLY-TO message identifier(s).
341341
*
342342
* @return string[]
343343
*/
344-
public function inReplyTo(bool $lazy = false): array
344+
public function inReplyTo(bool $fetch = false): array
345345
{
346-
$parts = $this->header(HeaderConsts::IN_REPLY_TO, lazy: $lazy)?->getParts() ?? [];
346+
$parts = $this->header(HeaderConsts::IN_REPLY_TO, fetch: $fetch)?->getParts() ?? [];
347347

348348
$values = array_map(fn (IHeaderPart $part) => $part->getValue(), $parts);
349349

@@ -355,39 +355,39 @@ public function inReplyTo(bool $lazy = false): array
355355
*
356356
* @return Address[]
357357
*/
358-
public function to(bool $lazy = false): array
358+
public function to(bool $fetch = false): array
359359
{
360-
return $this->addresses(HeaderConsts::TO, lazy: $lazy);
360+
return $this->addresses(HeaderConsts::TO, fetch: $fetch);
361361
}
362362

363363
/**
364364
* Get the CC addresses.
365365
*
366366
* @return Address[]
367367
*/
368-
public function cc(bool $lazy = false): array
368+
public function cc(bool $fetch = false): array
369369
{
370-
return $this->addresses(HeaderConsts::CC, lazy: $lazy);
370+
return $this->addresses(HeaderConsts::CC, fetch: $fetch);
371371
}
372372

373373
/**
374374
* Get the BCC addresses.
375375
*
376376
* @return Address[]
377377
*/
378-
public function bcc(bool $lazy = false): array
378+
public function bcc(bool $fetch = false): array
379379
{
380-
return $this->addresses(HeaderConsts::BCC, lazy: $lazy);
380+
return $this->addresses(HeaderConsts::BCC, fetch: $fetch);
381381
}
382382

383383
/**
384384
* Get addresses from the given header.
385385
*
386386
* @return Address[]
387387
*/
388-
public function addresses(string $header, bool $lazy = false): array
388+
public function addresses(string $header, bool $fetch = false): array
389389
{
390-
$parts = $this->header($header, lazy: $lazy)?->getParts() ?? [];
390+
$parts = $this->header($header, fetch: $fetch)?->getParts() ?? [];
391391

392392
$addresses = array_map(fn (IHeaderPart $part) => match (true) {
393393
$part instanceof AddressPart => new Address($part->getEmail(), $part->getName()),
@@ -402,10 +402,10 @@ public function addresses(string $header, bool $lazy = false): array
402402
/**
403403
* Get the message's text content.
404404
*/
405-
public function text(bool $lazy = false): ?string
405+
public function text(bool $fetch = false): ?string
406406
{
407-
if ($lazy && ! $this->hasBody()) {
408-
if ($part = $this->bodyStructure(lazy: true)?->text()) {
407+
if ($fetch && ! $this->hasBody()) {
408+
if ($part = $this->bodyStructure(fetch: true)?->text()) {
409409
return Support\BodyPartDecoder::text($part, $this->bodyPart($part->partNumber()));
410410
}
411411
}
@@ -420,10 +420,10 @@ public function text(bool $lazy = false): ?string
420420
/**
421421
* Get the message's HTML content.
422422
*/
423-
public function html(bool $lazy = false): ?string
423+
public function html(bool $fetch = false): ?string
424424
{
425-
if ($lazy && ! $this->hasBody()) {
426-
if ($part = $this->bodyStructure(lazy: true)?->html()) {
425+
if ($fetch && ! $this->hasBody()) {
426+
if ($part = $this->bodyStructure(fetch: true)?->html()) {
427427
return Support\BodyPartDecoder::text($part, $this->bodyPart($part->partNumber()));
428428
}
429429
}
@@ -440,10 +440,10 @@ public function html(bool $lazy = false): ?string
440440
*
441441
* @return Attachment[]
442442
*/
443-
public function attachments(bool $lazy = false): array
443+
public function attachments(bool $fetch = false): array
444444
{
445-
if ($lazy && ! $this->hasBody()) {
446-
return $this->getLazyAttachments();
445+
if ($fetch && ! $this->hasBody()) {
446+
return $this->getAttachmentsFromBodyStructure();
447447
}
448448

449449
if ($this->isEmpty()) {
@@ -454,11 +454,11 @@ public function attachments(bool $lazy = false): array
454454
}
455455

456456
/**
457-
* Get attachments using lazy loading from body structure.
457+
* Get attachments from the body structure.
458458
*
459459
* @return Attachment[]
460460
*/
461-
protected function getLazyAttachments(): array
461+
protected function getAttachmentsFromBodyStructure(): array
462462
{
463463
return array_map(
464464
fn (BodyStructurePart $part) => new Attachment(
@@ -468,7 +468,7 @@ protected function getLazyAttachments(): array
468468
$part->disposition()?->type()?->value,
469469
new Support\LazyBodyPartStream($this, $part),
470470
),
471-
$this->bodyStructure(lazy: true)?->attachments() ?? []
471+
$this->bodyStructure(fetch: true)?->attachments() ?? []
472472
);
473473
}
474474

tests/Unit/MessageTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
expect($unserializedMessage->size())->toBe(1024);
179179
});
180180

181-
test('it lazy loads text content from body structure when body is not loaded', function () {
181+
test('it fetches text content from body structure when body is not loaded', function () {
182182
$mailbox = Mailbox::make([
183183
'username' => 'foo',
184184
'password' => 'bar',
@@ -203,10 +203,10 @@
203203

204204
expect($message->hasBody())->toBeFalse();
205205
expect($message->hasBodyStructure())->toBeTrue();
206-
expect($message->text(lazy: true))->toBe('Hello World!');
206+
expect($message->text(fetch: true))->toBe('Hello World!');
207207
});
208208

209-
test('it lazy loads html content from body structure when body is not loaded', function () {
209+
test('it fetches html content from body structure when body is not loaded', function () {
210210
$mailbox = Mailbox::make([
211211
'username' => 'foo',
212212
'password' => 'bar',
@@ -231,7 +231,7 @@
231231

232232
expect($message->hasBody())->toBeFalse();
233233
expect($message->hasBodyStructure())->toBeTrue();
234-
expect($message->html(lazy: true))->toBe('<p>Hello World!</p>');
234+
expect($message->html(fetch: true))->toBe('<p>Hello World!</p>');
235235
});
236236

237237
test('it decodes base64 encoded content when lazy loading', function () {
@@ -259,7 +259,7 @@
259259

260260
$message = new Message($folder, 1, [], 'From: test@example.com', '', null, $bodyStructureData);
261261

262-
expect($message->text(lazy: true))->toBe('Hello World!');
262+
expect($message->text(fetch: true))->toBe('Hello World!');
263263
});
264264

265265
test('it decodes quoted-printable encoded content when lazy loading', function () {
@@ -287,7 +287,7 @@
287287

288288
$message = new Message($folder, 1, [], 'From: test@example.com', '', null, $bodyStructureData);
289289

290-
expect($message->text(lazy: true))->toBe('Hello World!');
290+
expect($message->text(fetch: true))->toBe('Hello World!');
291291
});
292292

293293
test('it converts charset to utf-8 when lazy loading', function () {
@@ -317,7 +317,7 @@
317317

318318
$message = new Message($folder, 1, [], 'From: test@example.com', '', null, $bodyStructureData);
319319

320-
expect($message->text(lazy: true))->toBe($originalContent);
320+
expect($message->text(fetch: true))->toBe($originalContent);
321321
});
322322

323323
test('it uses parsed body when body is already loaded', function () {
@@ -349,7 +349,7 @@
349349
expect($message->text())->toBe('Hello from parsed body!');
350350
});
351351

352-
test('it lazy loads text from multipart message body structure', function () {
352+
test('it fetches text from multipart message body structure', function () {
353353
$mailbox = Mailbox::make([
354354
'username' => 'foo',
355355
'password' => 'bar',
@@ -375,10 +375,10 @@
375375

376376
expect($message->hasBody())->toBeFalse();
377377
expect($message->hasBodyStructure())->toBeTrue();
378-
expect($message->text(lazy: true))->toBe('Hello World!');
378+
expect($message->text(fetch: true))->toBe('Hello World!');
379379
});
380380

381-
test('it lazy loads html from multipart message body structure', function () {
381+
test('it fetches html from multipart message body structure', function () {
382382
$mailbox = Mailbox::make([
383383
'username' => 'foo',
384384
'password' => 'bar',
@@ -402,7 +402,7 @@
402402

403403
$message = new Message($folder, 1, [], 'From: test@example.com', '', null, $bodyStructureData);
404404

405-
expect($message->html(lazy: true))->toBe('<p>Hello World!</p>');
405+
expect($message->html(fetch: true))->toBe('<p>Hello World!</p>');
406406
});
407407

408408
test('it fetches body structure automatically when not preloaded', function () {
@@ -435,7 +435,7 @@
435435
expect($message->hasBodyStructure())->toBeFalse();
436436

437437
// This should automatically fetch body structure, then fetch and decode the text part
438-
expect($message->text(lazy: true))->toBe('Hello World!');
438+
expect($message->text(fetch: true))->toBe('Hello World!');
439439
});
440440

441441
test('it fetches body structure automatically for html when not preloaded', function () {
@@ -462,10 +462,10 @@
462462
$message = new Message($folder, 1, [], 'From: test@example.com', '');
463463

464464
expect($message->hasBodyStructure())->toBeFalse();
465-
expect($message->html(lazy: true))->toBe('<p>Hello World!</p>');
465+
expect($message->html(fetch: true))->toBe('<p>Hello World!</p>');
466466
});
467467

468-
test('it lazy loads attachments from body structure', function () {
468+
test('it fetches attachments from body structure', function () {
469469
$mailbox = Mailbox::make([
470470
'username' => 'foo',
471471
'password' => 'bar',
@@ -494,7 +494,7 @@
494494
expect($message->hasBody())->toBeFalse();
495495
expect($message->hasBodyStructure())->toBeTrue();
496496

497-
$attachments = $message->attachments(lazy: true);
497+
$attachments = $message->attachments(fetch: true);
498498

499499
expect($attachments)->toHaveCount(1);
500500
expect($attachments[0]->filename())->toBe('document.pdf');
@@ -504,7 +504,7 @@
504504
expect($attachments[0]->contents())->toBe('Hello World!');
505505
});
506506

507-
test('it lazy loads headers from server', function () {
507+
test('it fetches headers from server', function () {
508508
$mailbox = Mailbox::make([
509509
'username' => 'foo',
510510
'password' => 'bar',
@@ -533,7 +533,7 @@
533533
expect($message->header('Subject'))->toBeNull();
534534

535535
// With lazy, fetches headers from server
536-
$header = $message->header('Subject', lazy: true);
536+
$header = $message->header('Subject', fetch: true);
537537

538538
expect($header)->not->toBeNull();
539539
expect($header->getValue())->toBe('Test Subject');

0 commit comments

Comments
 (0)