PHPackages                             mnapoli/imapi - 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. mnapoli/imapi

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

mnapoli/imapi
=============

IMAP API

0.2.7(8y ago)241.5k[1 PRs](https://github.com/mnapoli/imapi/pulls)MITPHP ~7.0

Since Jun 13Compare

[ Source](https://github.com/mnapoli/imapi)[ Packagist](https://packagist.org/packages/mnapoli/imapi)[ RSS](/packages/mnapoli-imapi/feed)WikiDiscussions Synced yesterday

READMEChangelog (9)Dependencies (4)Versions (9)Used By (0)

imapi
=====

[](#imapi)

**This library is experimental and not meant to be reused.**

imapi is a high level IMAP API for PHP.

It aims to be different from other implementations:

- **be very high level**: you don't have to know how IMAP works (because IMAP is very ugly)
- take care of related problems like **parse MIME email content** or **sanitize HTML in emails**
- based on Horde's IMAP library rather than on PHP's IMAP extension (explained below)
- be full featured, yet leave the door open for low-level calls to Horde's library for uncovered features
- be maintained (unfortunately IMAP is not a very active topic and many good projects are unfinished or dead)

It is not based on PHP's IMAP extension, but rather on the amazing Horde library. The reason is well explained on [Horde's library page](http://dev.horde.org/imap_client/):

> Horde/Imap\_Client is significantly faster, more feature-rich, and extensible when compared to PHP's imap (c-client) extension.

> Don't be confused: almost every so-called "PHP IMAP Library" out there is nothing more than a thin-wrapper around the imap extension, so NONE of these libraries can fix the basic limitations of that extension.

Getting started
---------------

[](#getting-started)

```
composer require mnapoli/imapi

```

The easy way:

```
$client = Imapi\Client::connect('imap.host.com', 'user', 'password');
```

If you want full control on the connection, you can use Horde's constructor:

```
$hordeClient = new Horde_Imap_Client_Socket([
    'username' => $username,
    'password' => $password,
    'hostspec' => $host,
    'port'     => '143',
    'secure'   => 'tls',
]);

$client = new Imapi\Client($hordeClient);
```

Reading
-------

[](#reading)

### Reading the inbox

[](#reading-the-inbox)

Fetching all the messages from the inbox:

```
$emails = $client->getEmails();

foreach ($emails as $email) {
    echo $email->getSubject();
}
```

Yes it's that easy. Emails are objects (`Imapi\Email`) that expose all the information of the email.

If you need to synchronize emails stored locally with the IMAP server, you will probably not want to fetch the emails, i.e. their content. You can fetch only their ID, which is much faster:

```
$ids = $client->getEmailIds();

foreach ($ids as $id) {
    if (/* this email needs to be synced */) {
        $email = $client->getEmailFromId($id);
        // ...
    }
}
```

### Advanced queries

[](#advanced-queries)

Both `getEmails()` and `getEmailIds()` can take an optional `Query` object.

```
// Read from the `INBOX.Sent` folder
$query = QueryBuilder::create('INBOX.Sent')
    ->youngerThan(3600) // 1 hour
    ->flagSeen(true) // return messages with \\seen flag set, or false for messages with seen flag off.
                     // more options are flagAnswered(boolean), flagDeleted(boolean),flagDraft(boolean),flagFlaged(boolean),flagRecent(boolean)
    ->getQuery();

$emails = $client->getEmails($query);
```

### Reading folders

[](#reading-folders)

```
$folders = $client->getFolders();
```

Operations
----------

[](#operations)

### Moving emails

[](#moving-emails)

```
$emailIds = ['123', '456'];

// Moving from the INBOX to the Archive folder
$client->moveEmails($emailIds, 'INBOX', 'Archive');
```

### Deleting emails

[](#deleting-emails)

"Deleting" means simply moving to the trash folder. Unfortunately, the trash folder is custom to each provider, so you need to explicitly provide it:

```
$emailIds = ['123', '456'];

$client->deleteEmails($emailIds, 'Deleted Messages');
```

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.3% 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 ~74 days

Recently: every ~133 days

Total

9

Last Release

3074d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/329a6111724074f5388e95dd41a03ccf3c43f4bfe1ecf27c94c9efc6f7823228?d=identicon)[mnapoli](/maintainers/mnapoli)

---

Top Contributors

[![mnapoli](https://avatars.githubusercontent.com/u/720328?v=4)](https://github.com/mnapoli "mnapoli (20 commits)")[![carusogabriel](https://avatars.githubusercontent.com/u/16328050?v=4)](https://github.com/carusogabriel "carusogabriel (1 commits)")[![DaveRandom](https://avatars.githubusercontent.com/u/2396425?v=4)](https://github.com/DaveRandom "DaveRandom (1 commits)")[![katwekibs](https://avatars.githubusercontent.com/u/6697565?v=4)](https://github.com/katwekibs "katwekibs (1 commits)")[![mallardduck](https://avatars.githubusercontent.com/u/619938?v=4)](https://github.com/mallardduck "mallardduck (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mnapoli-imapi/health.svg)

```
[![Health](https://phpackages.com/badges/mnapoli-imapi/health.svg)](https://phpackages.com/packages/mnapoli-imapi)
```

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k39](/packages/civicrm-civicrm-core)[jason-munro/cypht

Lightweight Open Source webmail written in PHP and JavaScript

1.6k157.9k](/packages/jason-munro-cypht)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M551](/packages/shopware-core)[oro/platform

Business Application Platform (BAP)

645143.5k114](/packages/oro-platform)[oat-sa/tao-core

TAO core extension

66143.7k116](/packages/oat-sa-tao-core)

PHPackages © 2026

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