gricob/imap

IMAP client for PHP without php-imap extension dependency

0.0.3 2024-05-02 11:14 UTC

This package is auto-updated.

Last update: 2024-05-12 07:20:57 UTC


README

Install

composer require gricob/imap

Usage

$client = \Gricob\IMAP\Client::create(
    new \Gricob\IMAP\Configuration(
        transport: 'ssl',
        host: 'imap.example.com',
        port: 993,
        timeout: 60,
        verifyPeer: true,
        verifyPeerName: true,
        allowSelfSigned: false,
        useUid: true,
    )
);

$client->logIn('username', 'password');

// List available mailbox
$mailboxes = $client->list();

// Select an specific mailbox
$client->select($mailboxes[0]->name);

// Fetch message by sequence number or uid (depends on useUid configuration)
$message = $client->fetch(1);

// Or search messages by criteria
$messages = $client->search()
    ->since(new DateTime('yesterday'))
    ->get();

Testing

Greenmail standalone IMAP server is configured in the docker compose file for testing. To start it, run the following command:

docker compose up

Once the IMAP server is up and running, run the following command to execute tests:

composer test