PHPackages                             d4ry/imap-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. d4ry/imap-client

ActiveLibrary[HTTP &amp; Networking](/categories/http)

d4ry/imap-client
================

Socketbased IMAP Client for PHP

v1.0.9(2mo ago)122↓90.9%Apache-2.0PHPCI passing

Since Apr 2Pushed 2mo agoCompare

[ Source](https://github.com/D4ryB3rry/PHP-Imap)[ Packagist](https://packagist.org/packages/d4ry/imap-client)[ RSS](/packages/d4ry-imap-client/feed)WikiDiscussions main Synced 4w ago

READMEChangelogDependencies (2)Versions (12)Used By (0)

PHP IMAP Client
===============

[](#php-imap-client)

[![Tests](https://github.com/D4ryB3rry/PHP-Imap-/actions/workflows/tests.yml/badge.svg)](https://github.com/D4ryB3rry/PHP-Imap-/actions/workflows/tests.yml)[![codecov](https://camo.githubusercontent.com/0784366a2f9160d5e52166dd6e44968077cf3716581a2230567ebdd8a8fdb995/68747470733a2f2f636f6465636f762e696f2f67682f4434727942337272792f5048502d496d61702f67726170682f62616467652e7376673f746f6b656e3d30375a334d3649445252)](https://codecov.io/gh/D4ryB3rry/PHP-Imap)[![Mutation testing badge](https://camo.githubusercontent.com/7184f0a5d5b63c67aa009cb2dc8da1466e60b466ef1739c9d85504e3465545df/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d2532464434727942337272792532465048502d496d61702532466d61696e)](https://dashboard.stryker-mutator.io/reports/github.com/D4ryB3rry/PHP-Imap/main)[![Packagist Version](https://camo.githubusercontent.com/c13352b3f17a26ed876c6d0a4f2d540c451e88da727b9bd4a65668c916d9dc6c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f643472792f696d61702d636c69656e74)](https://packagist.org/packages/d4ry/imap-client)[![Packagist Downloads](https://camo.githubusercontent.com/b2334eba2ac84ac7bc2bd6ddde82af7d1fff198dd15aff8fef28e6d213acdeb4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f643472792f696d61702d636c69656e74)](https://packagist.org/packages/d4ry/imap-client/stats)[![License Apache 2.0](https://camo.githubusercontent.com/53aec1ae7394521e2af38df6c1560d97fcb8152f5edd45d87563432eed72bf7a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d417061636865253230322e302d626c7565)](https://camo.githubusercontent.com/53aec1ae7394521e2af38df6c1560d97fcb8152f5edd45d87563432eed72bf7a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d417061636865253230322e302d626c7565)

**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
------------

[](#installation)

```
composer require d4ry/imap-client
```

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

Quick Start
-----------

[](#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
--------------

[](#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](docs/README.md).

Benchmarks
----------

[](#benchmarks)

Head-to-head benchmarks against [`webklex/php-imap`](https://github.com/Webklex/php-imap) and [`ddeboer/imap`](https://github.com/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.

Scenariod4ry (ms / MB)webklex (ms / MB)ddeboer (ms / MB)Fetch text body of large-attachment message**40.8** / 0.509,123.8 / 374.6445.2 / **0.42**Search UNSEEN FROM x SINCE y**107.6** / 0.59165.8 / 5.26114.5 / **0.40**Cold open + read first 10**53.8** / 0.76211.5 / 6.2190.9 / **0.68**Results depend heavily on how each library is called — see **[docs/benchmarks.md](docs/benchmarks.md)** for the full 7-scenario table and methodology. The adapters and raw data are auditable in **[D4ryB3rry/imap-client-benchmarks](https://github.com/D4ryB3rry/imap-client-benchmarks)**; PRs that improve any adapter are welcome.

Documentation
-------------

[](#documentation)

**Guides**

- [Getting Started](docs/getting-started.md)
- [Configuration](docs/configuration.md)
- [Authentication](docs/authentication.md) (Plain, Login, OAuth2)
- [Folders](docs/folders.md)
- [Messages](docs/messages.md)
- [Attachments](docs/attachments.md)
- [Search](docs/search.md)
- [IDLE (Push Notifications)](docs/idle.md)
- [Error Handling](docs/error-handling.md)

**Reference**

- [Architecture](docs/architecture.md)
- [Supported Extensions](docs/extensions.md)
- [Benchmarks](docs/benchmarks.md)
- [Testing](docs/testing.md)

**Advanced**

- [Raw Connection Access](docs/advanced/raw-connection.md)
- [Namespace](docs/advanced/namespace.md)
- [Recording &amp; Replay](docs/advanced/recording-replay.md)

License
-------

[](#license)

Licensed under the [Apache License 2.0](LICENSE).

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance85

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

10

Last Release

76d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3f5cf26e766703d5b50c26c91ad1c26e8f7683e9b77ac93060a486bbaabe8866?d=identicon)[D4ryB3rry](/maintainers/D4ryB3rry)

---

Top Contributors

[![D4ryB3rry](https://avatars.githubusercontent.com/u/22527253?v=4)](https://github.com/D4ryB3rry "D4ryB3rry (35 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/d4ry-imap-client/health.svg)

```
[![Health](https://phpackages.com/badges/d4ry-imap-client/health.svg)](https://phpackages.com/packages/d4ry-imap-client)
```

###  Alternatives

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25126.1M81](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.9M6.8k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k24.3k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87965.9k114](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.4M89](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69127.2k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
