Skip to content

Commit 82ded44

Browse files
committed
Add ability to determine if a message is the same as another
1 parent d867672 commit 82ded44

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

src/FileMessage.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ public function __toString(): string
3131
return $this->contents;
3232
}
3333

34+
/**
35+
* Determine if this message is equal to another.
36+
*/
37+
public function is(MessageInterface $message): bool
38+
{
39+
return $message instanceof self
40+
&& $this->contents === $message->contents;
41+
}
42+
3443
/**
3544
* Determine if the message is empty.
3645
*/

src/Message.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ public function hasBody(): bool
9090
return ! empty($this->body);
9191
}
9292

93+
/**
94+
* {@inheritDoc}
95+
*/
96+
public function is(MessageInterface $message): bool
97+
{
98+
return $message instanceof self
99+
&& $this->uid === $message->uid
100+
&& $this->folder->is($message->folder);
101+
}
102+
93103
/**
94104
* Determine if the message is marked as seen.
95105
*/

src/MessageInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ public function header(string $name, int $offset = 0): ?IHeader;
119119
*/
120120
public function parse(): MailMimeMessage;
121121

122+
/**
123+
* Determine if the message is the same as another message.
124+
*/
125+
public function is(MessageInterface $message): bool;
126+
122127
/**
123128
* Get the string representation of the message.
124129
*/

src/Testing/FakeMessage.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ public function uid(): int
2626
return $this->uid;
2727
}
2828

29+
/**
30+
* {@inheritDoc}
31+
*/
32+
public function is(MessageInterface $message): bool
33+
{
34+
return $message instanceof self
35+
&& $this->uid === $message->uid
36+
&& $this->flags === $message->flags
37+
&& $this->contents === $message->contents;
38+
}
39+
2940
/**
3041
* {@inheritDoc}
3142
*/

0 commit comments

Comments
 (0)