d4ry/imap-client

Socketbased IMAP Client for PHP

Maintainers

Package info

github.com/D4ryB3rry/PHP-Imap

pkg:composer/d4ry/imap-client

Statistics

Installs: 22

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v1.0.9 2026-04-17 13:04 UTC

This package is auto-updated.

Last update: 2026-05-17 13:20:22 UTC


README

Tests codecov Mutation testing badge Packagist Version Packagist Downloads License Apache 2.0

Raw-socket IMAP client for PHP 8.4+ — zero dependencies, full IMAPv4rev2 support.

Designed from scratch for modern PHP: speaks IMAP directly over sockets, fetches only what you ask for, and gives you full control over the protocol when you need it.

  • 🔌 Raw socket connection with TLS / STARTTLS
  • ðŸ“Ķ Zero runtime dependencies (only ext-mbstring + ext-openssl)
  • 📜 IMAPv4rev2 (RFC 9051) with 18+ extensions
  • ðŸŠķ Lazy loading — bodies and attachments fetched on demand
  • ðŸŽŊ BODYSTRUCTURE-first — 50 MB email with a 12 KB text body? You download 12 KB
  • 🔎 Fluent search builder, IDLE + NOTIFY push, OAuth2 with token refresh

Installation

composer require d4ry/imap-client

Requirements: PHP 8.4+, ext-openssl, ext-mbstring

Quick Start

use D4ry\ImapClient\Auth\PlainCredential;
use D4ry\ImapClient\Config;
use D4ry\ImapClient\Mailbox;

$mailbox = Mailbox::connect(new Config(
    host: 'imap.example.com',
    credential: new PlainCredential('user@example.com', 'password'),
));

foreach ($mailbox->inbox()->messages() as $message) {
    echo $message->envelope()->subject . "\n";

    foreach ($message->attachments()->nonInline() as $attachment) {
        $attachment->save('/tmp');
    }
}

$mailbox->disconnect();

Search Example

use D4ry\ImapClient\Search\Search;

$search = (new Search())
    ->unread()
    ->from('notifications@github.com')
    ->after(new DateTime('-7 days'));

foreach ($mailbox->inbox()->messages($search) as $message) {
    printf("[%s] %s\n", $message->envelope()->from[0], $message->envelope()->subject);
    echo $message->hasHtml() ? $message->html() : $message->text();
}

More examples and the full API are in the documentation.

Benchmarks

Head-to-head benchmarks against webklex/php-imap and ddeboer/imap, run against a local Dovecot in Docker with 1 warmup + 10 measured runs per scenario. Time = median ms, memory = per-scenario delta in MB. Bold marks the row winner.

Scenario d4ry (ms / MB) webklex (ms / MB) ddeboer (ms / MB)
Fetch text body of large-attachment message 40.8 / 0.50 9,123.8 / 374.64 45.2 / 0.42
Search UNSEEN FROM x SINCE y 107.6 / 0.59 165.8 / 5.26 114.5 / 0.40
Cold open + read first 10 53.8 / 0.76 211.5 / 6.21 90.9 / 0.68

Results depend heavily on how each library is called — see docs/benchmarks.md for the full 7-scenario table and methodology. The adapters and raw data are auditable in D4ryB3rry/imap-client-benchmarks; PRs that improve any adapter are welcome.

Documentation

Guides

Reference

Advanced

License

Licensed under the Apache License 2.0.