Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/FileMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class FileMessage implements MessageInterface
{
use HasParsedMessage;
use HasFlags, HasParsedMessage;

/**
* Constructor.
Expand All @@ -23,6 +23,14 @@ public function uid(): int
throw new BadMethodCallException('FileMessage does not support a UID');
}

/**
* {@inheritDoc}
*/
public function flag(mixed $flag, string $operation, bool $expunge = false): void
{
throw new BadMethodCallException('FileMessage does not support flagging');
}

/**
* Get the string representation of the message.
*/
Expand All @@ -40,6 +48,14 @@ public function is(MessageInterface $message): bool
&& $this->contents === $message->contents;
}

/**
* Get the message flags.
*/
public function flags(): array
{
return [];
}

/**
* Determine if the message is empty.
*/
Expand Down
125 changes: 125 additions & 0 deletions src/FlaggableInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php

namespace DirectoryTree\ImapEngine;

use BackedEnum;

interface FlaggableInterface
{
/**
* Mark the message as read. Alias for markSeen.
*/
public function markRead(): void;

/**
* Mark the message as unread. Alias for unmarkSeen.
*/
public function markUnread(): void;

/**
* Mark the message as seen.
*/
public function markSeen(): void;

/**
* Unmark the seen flag.
*/
public function unmarkSeen(): void;

/**
* Mark the message as answered.
*/
public function markAnswered(): void;

/**
* Unmark the answered flag.
*/
public function unmarkAnswered(): void;

/**
* Mark the message as flagged.
*/
public function markFlagged(): void;

/**
* Unmark the flagged flag.
*/
public function unmarkFlagged(): void;

/**
* Mark the message as deleted.
*/
public function markDeleted(bool $expunge = false): void;

/**
* Unmark the deleted flag.
*/
public function unmarkDeleted(): void;

/**
* Mark the message as a draft.
*/
public function markDraft(): void;

/**
* Unmark the draft flag.
*/
public function unmarkDraft(): void;

/**
* Mark the message as recent.
*/
public function markRecent(): void;

/**
* Unmark the recent flag.
*/
public function unmarkRecent(): void;

/**
* Determine if the message is marked as seen.
*/
public function isSeen(): bool;

/**
* Determine if the message is marked as answered.
*/
public function isAnswered(): bool;

/**
* Determine if the message is flagged.
*/
public function isFlagged(): bool;

/**
* Determine if the message is marked as deleted.
*/
public function isDeleted(): bool;

/**
* Determine if the message is marked as a draft.
*/
public function isDraft(): bool;

/**
* Determine if the message is marked as recent.
*/
public function isRecent(): bool;

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

/**
* Determine if the message has the given flag.
*/
public function hasFlag(BackedEnum|string $flag): bool;

/**
* Add or remove a flag from the message.
*/
public function flag(mixed $flag, string $operation, bool $expunge = false): void;
}
188 changes: 188 additions & 0 deletions src/HasFlags.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<?php

namespace DirectoryTree\ImapEngine;

use BackedEnum;
use DirectoryTree\ImapEngine\Enums\ImapFlag;
use DirectoryTree\ImapEngine\Support\Str;

trait HasFlags
{
/**
* {@inheritDoc}
*/
public function markRead(): void
{
$this->markSeen();
}

/**
* {@inheritDoc}
*/
public function markUnread(): void
{
$this->unmarkSeen();
}

/**
* {@inheritDoc}
*/
public function markSeen(): void
{
$this->flag(ImapFlag::Seen, '+');
}

/**
* {@inheritDoc}
*/
public function unmarkSeen(): void
{
$this->flag(ImapFlag::Seen, '-');
}

/**
* {@inheritDoc}
*/
public function markAnswered(): void
{
$this->flag(ImapFlag::Answered, '+');
}

/**
* {@inheritDoc}
*/
public function unmarkAnswered(): void
{
$this->flag(ImapFlag::Answered, '-');
}

/**
* {@inheritDoc}
*/
public function markFlagged(): void
{
$this->flag(ImapFlag::Flagged, '+');
}

/**
* {@inheritDoc}
*/
public function unmarkFlagged(): void
{
$this->flag(ImapFlag::Flagged, '-');
}

/**
* {@inheritDoc}
*/
public function markDeleted(bool $expunge = false): void
{
$this->flag(ImapFlag::Deleted, '+', $expunge);
}

/**
* {@inheritDoc}
*/
public function unmarkDeleted(): void
{
$this->flag(ImapFlag::Deleted, '-');
}

/**
* {@inheritDoc}
*/
public function markDraft(): void
{
$this->flag(ImapFlag::Draft, '+');
}

/**
* {@inheritDoc}
*/
public function unmarkDraft(): void
{
$this->flag(ImapFlag::Draft, '-');
}

/**
* {@inheritDoc}
*/
public function markRecent(): void
{
$this->flag(ImapFlag::Recent, '+');
}

/**
* {@inheritDoc}
*/
public function unmarkRecent(): void
{
$this->flag(ImapFlag::Recent, '-');
}

/**
* {@inheritDoc}
*/
public function isSeen(): bool
{
return $this->hasFlag(ImapFlag::Seen);
}

/**
* {@inheritDoc}
*/
public function isAnswered(): bool
{
return $this->hasFlag(ImapFlag::Answered);
}

/**
* {@inheritDoc}
*/
public function isFlagged(): bool
{
return $this->hasFlag(ImapFlag::Flagged);
}

/**
* {@inheritDoc}
*/
public function isDeleted(): bool
{
return $this->hasFlag(ImapFlag::Deleted);
}

/**
* {@inheritDoc}
*/
public function isDraft(): bool
{
return $this->hasFlag(ImapFlag::Draft);
}

/**
* {@inheritDoc}
*/
public function isRecent(): bool
{
return $this->hasFlag(ImapFlag::Recent);
}

/**
* {@inheritDoc}
*/
public function hasFlag(BackedEnum|string $flag): bool
{
return in_array(Str::enum($flag), $this->flags());
}

/**
* {@inheritDoc}
*/
abstract public function flags(): array;

/**
* {@inheritDoc}
*/
abstract public function flag(mixed $flag, string $operation, bool $expunge = false): void;
}
Loading