Skip to content

Commit 6a9bc1c

Browse files
committed
Adjust property and method names
1 parent a2f74d4 commit 6a9bc1c

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

readme.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,11 @@ The `Message` class provides several methods to access basic properties:
388388

389389
**Headers and Contents**
390390

391-
- `$message->headers()`: Returns the raw headers as a string.
392-
- `$message->contents()`: Returns the raw message content.
393-
- `$message->hasHeaders()` / `hasContents()`: Determine whether the message has headers or contents.
391+
- `$message->head()`: Returns the raw message header.
392+
- `$message->body()`: Returns the raw message body.
393+
- `$message->header($name)`: Returns a specific header.
394+
- `$message->headers()`: Returns an array of all headers.
395+
- `$message->hasHead()` / `hasBody()`: Determine whether the message has headers or body.
394396

395397
**Metadata**
396398

src/Message.php

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public function __construct(
3030
protected Folder $folder,
3131
protected int $uid,
3232
protected array $flags,
33-
protected string $headers,
34-
protected string $contents,
33+
protected string $head,
34+
protected string $body,
3535
) {}
3636

3737
/**
@@ -62,33 +62,33 @@ public function flags(): array
6262
/**
6363
* Get the message's raw headers.
6464
*/
65-
public function headers(): string
65+
public function head(): string
6666
{
67-
return $this->headers;
67+
return $this->head;
6868
}
6969

7070
/**
7171
* Determine if the message has headers.
7272
*/
73-
public function hasHeaders(): bool
73+
public function hasHead(): bool
7474
{
75-
return ! empty($this->headers);
75+
return ! empty($this->head);
7676
}
7777

7878
/**
79-
* Get the message's raw contents.
79+
* Get the message's raw body.
8080
*/
81-
public function contents(): string
81+
public function body(): string
8282
{
83-
return $this->contents;
83+
return $this->body;
8484
}
8585

8686
/**
8787
* Determine if the message has contents.
8888
*/
89-
public function hasContents(): bool
89+
public function hasBody(): bool
9090
{
91-
return ! empty($this->contents);
91+
return ! empty($this->body);
9292
}
9393

9494
/**
@@ -297,6 +297,14 @@ public function hasFlag(BackedEnum|string $flag): bool
297297
return in_array(Str::prefix(Str::enum($flag), '\\'), $this->flags);
298298
}
299299

300+
/**
301+
* Get all headers from the message.
302+
*/
303+
public function headers(): array
304+
{
305+
return $this->parse()->getAllHeaders();
306+
}
307+
300308
/**
301309
* Get a header from the message.
302310
*/
@@ -483,7 +491,7 @@ public function restore(): void
483491
*/
484492
public function parse(): MailMimeMessage
485493
{
486-
if (! $this->hasHeaders() && ! $this->hasContents()) {
494+
if (! $this->hasHead() && ! $this->hasBody()) {
487495
throw new RuntimeException('Cannot parse an empty message');
488496
}
489497

@@ -498,8 +506,8 @@ public function toArray(): array
498506
return [
499507
'uid' => $this->uid,
500508
'flags' => $this->flags,
501-
'headers' => $this->headers,
502-
'contents' => $this->contents,
509+
'head' => $this->head,
510+
'body' => $this->body,
503511
];
504512
}
505513

@@ -509,8 +517,8 @@ public function toArray(): array
509517
public function __toString(): string
510518
{
511519
return implode("\r\n\r\n", array_filter([
512-
rtrim($this->headers),
513-
ltrim($this->contents),
520+
rtrim($this->head),
521+
ltrim($this->body),
514522
]));
515523
}
516524

0 commit comments

Comments
 (0)