Event


Available events

The following events are available and used:

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);