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

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

phps-cans/imapi
===============

IMAP API

0.2.4(9y ago)01MITPHPPHP ~7.0

Since Jun 13Pushed 9y ago2 watchersCompare

[ Source](https://github.com/phps-cans/imapi)[ Packagist](https://packagist.org/packages/phps-cans/imapi)[ RSS](/packages/phps-cans-imapi/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (4)Versions (6)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
    ->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

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.1% 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 ~16 days

Total

6

Last Release

3587d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/988fb049e7b031fc14b8ce38b8f5bc3e40dbd6bfb3b5bc7f7061b68c41ba39f1?d=identicon)[xhuberty](/maintainers/xhuberty)

---

Top Contributors

[![mnapoli](https://avatars.githubusercontent.com/u/720328?v=4)](https://github.com/mnapoli "mnapoli (16 commits)")[![xhuberty](https://avatars.githubusercontent.com/u/8350192?v=4)](https://github.com/xhuberty "xhuberty (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[magento/community-edition

Magento 2 (Open Source)

12.1k53.0k12](/packages/magento-community-edition)[civicrm/civicrm-core

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

751284.3k37](/packages/civicrm-civicrm-core)[jason-munro/cypht

Lightweight Open Source webmail written in PHP and JavaScript

1.6k154.8k](/packages/jason-munro-cypht)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.4M524](/packages/shopware-core)[oro/platform

Business Application Platform (BAP)

642140.7k104](/packages/oro-platform)

PHPackages © 2026

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