Event
Available events
The following events are available and used:
MessageNewEvent($message)
— can get triggered byFolder::idle
MessageDeletedEvent($message)
— triggered byMessage::delete
MessageRestoredEvent($message)
— triggered byMessage::restore
MessageMovedEvent($old_message, $new_message)
— triggered byMessage::move
MessageCopiedEvent($old_message, $new_message)
— triggered byMessage::copy
FlagNewEvent($flag)
— triggered byMessage::setFlag
FlagDeletedEvent($flag)
— triggered byMessage::unsetFlag
FolderNewEvent($folder)
— can get triggered byClient::createFolder
FolderDeletedEvent($folder)
— triggered byFolder::delete
FolderMovedEvent($old_folder, $new_folder)
— triggered byFolder::move
Custom event
You can create and register your own events.
class CustomMessageNewEvent extends Webklex\PHPIMAP\Events\MessageNewEvent {
/**
* Create a new event instance.
* @var \Webklex\PHPIMAP\Message[] $messages
* @return void
*/
public function __construct($messages) {
$this->message = $messages[0];
echo "New message: ".$this->message->subject."\n";
}
}
You can now either register it as default inside your configuration or inject it directly:
/** @var \Webklex\PHPIMAP\Client $client */
/** @var \Webklex\PHPIMAP\Folder $folder */
$client->setEvent("message", "new", CustomMessageNewEvent::class);
$folder->setEvent("message", "new", CustomMessageNewEvent::class);