Skip to content

Commit

Permalink
Merge pull request #24 from DirectoryTree/message-interface
Browse files Browse the repository at this point in the history
Unify common message methods in `MessageInterface`
  • Loading branch information
stevebauman authored Feb 21, 2025
2 parents 9a34cb8 + 0cf448f commit 6865679
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/FileMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace DirectoryTree\ImapEngine;

use Stringable;

class FileMessage implements Stringable
class FileMessage implements MessageInterface
{
use HasParsedMessage;

Expand Down
3 changes: 1 addition & 2 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
use DirectoryTree\ImapEngine\Support\Str;
use Illuminate\Contracts\Support\Arrayable;
use JsonSerializable;
use Stringable;

class Message implements Arrayable, JsonSerializable, Stringable
class Message implements Arrayable, JsonSerializable, MessageInterface
{
use HasParsedMessage;

Expand Down
121 changes: 121 additions & 0 deletions src/MessageInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php

namespace DirectoryTree\ImapEngine;

use Carbon\Carbon;
use Stringable;
use ZBateson\MailMimeParser\Header\IHeader;
use ZBateson\MailMimeParser\Message as MailMimeMessage;

interface MessageInterface extends Stringable
{
/**
* Get the message date and time.
*/
public function date(): ?Carbon;

/**
* Get the message's subject.
*/
public function subject(): ?string;

/**
* Get the 'From' address.
*/
public function from(): ?Address;

/**
* Get the 'Sender' address.
*/
public function sender(): ?Address;

/**
* Get the message's 'Message-ID'.
*/
public function messageId(): ?string;

/**
* Get the 'Reply-To' address.
*/
public function replyTo(): ?Address;

/**
* Get the 'In-Reply-To' address.
*/
public function inReplyTo(): ?Address;

/**
* Get the 'To' addresses.
*
* @return Address[]
*/
public function to(): array;

/**
* Get the 'CC' addresses.
*
* @return Address[]
*/
public function cc(): array;

/**
* Get the 'BCC' addresses.
*
* @return Address[]
*/
public function bcc(): array;

/**
* Get the message's attachments.
*
* @return Attachment[]
*/
public function attachments(): array;

/**
* Determine if the message has attachments.
*/
public function hasAttachments(): bool;

/**
* Get the count of attachments.
*/
public function attachmentCount(): int;

/**
* Get addresses from the given header.
*
* @return Address[]
*/
public function addresses(string $header): array;

/**
* Get the message's HTML content.
*/
public function html(): ?string;

/**
* Get the message's text content.
*/
public function text(): ?string;

/**
* Get all headers from the message.
*/
public function headers(): array;

/**
* Get a header from the message.
*/
public function header(string $name, int $offset = 0): ?IHeader;

/**
* Parse the message into a MailMimeMessage instance.
*/
public function parse(): MailMimeMessage;

/**
* Get the string representation of the message.
*/
public function __toString(): string;
}

0 comments on commit 6865679

Please sign in to comment.