PHPackages                             kqtec/laravel-imap - 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. [Mail &amp; Notifications](/categories/mail)
4. /
5. kqtec/laravel-imap

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

kqtec/laravel-imap
==================

Laravel IMAP client

1.4.1(7y ago)15MITPHPPHP &gt;=5.5.9

Since Jan 19Pushed 6y agoCompare

[ Source](https://github.com/kqtec/laravel-imap)[ Packagist](https://packagist.org/packages/kqtec/laravel-imap)[ Docs](https://github.com/webklex/laravel-imap)[ RSS](/packages/kqtec-laravel-imap/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (57)Used By (0)

IMAP Library for Laravel
========================

[](#imap-library-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8a1edc263331e0ab34ad7554bc17744ca0b654ca957b90ec688483cbfa2e4a2f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f5765626b6c65782f6c61726176656c2d696d61702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Webklex/laravel-imap)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/cece068b3cf5186e6baae1dcf2b550ffa1a51291136c7226fc4a00e324e17798/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f5765626b6c65782f6c61726176656c2d696d61702f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/Webklex/laravel-imap)[![Total Downloads](https://camo.githubusercontent.com/8dd8f99d06e38b388cf8a6dbd0f1a993a8e999fa9184bf49b832d2c45c987879/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f5765626b6c65782f6c61726176656c2d696d61702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Webklex/laravel-imap)

Description
-----------

[](#description)

Laravel IMAP is an easy way to integrate the native php imap library into your **Laravel** app.

> If you want to use this library outside of Laravel, please head over to [webklex/php-imap](https://github.com/Webklex/php-imap)

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Basic usage example](#basic-usage-example)
    - [Facade](#facade)
    - [Folder / Mailbox](#folder--mailbox)
    - [Search](#search-for-messages)
    - [Result limiting](#result-limiting)
    - [Pagination](#pagination)
    - [View examples](#view-examples)
    - [Fetch a specific message](#fetch-a-specific-message)
    - [Message flags](#message-flags)
    - [Attachments](#attachments)
    - [Advanced fetching](#advanced-fetching)
    - [Masking](#masking)
    - [Specials](#specials)
- [Support](#support)
- [Documentation](#documentation)
    - [Client::class](#clientclass)
    - [Message::class](#messageclass)
    - [Folder::class](#folderclass)
    - [Query::class](#queryclass)
    - [Attachment::class](#attachmentclass)
    - [Mask::class](#maskclass)
        - [MessageMask::class](#messagemaskclass)
        - [AttachmentMask::class](#attachmentmaskclass)
    - [MessageCollection::class](#messagecollectionclass)
    - [AttachmentCollection::class](#attachmentcollectionclass)
    - [FolderCollection::class](#foldercollectionclass)
    - [FlagCollection::class](#flagcollectionclass)
- [Known issues](#known-issues)
- [Milestones &amp; upcoming features](#milestones--upcoming-features)
- [Security](#security)
- [Credits](#credits)
- [Supporters](#supporters)
- [License](#license)

Installation
------------

[](#installation)

1. Install the php-imap library if it isn't already installed:

```
sudo apt-get install php*-imap php*-mbstring php*-mcrypt && sudo apache2ctl graceful
```

You might also want to check `phpinfo()` if the extension is enabled.

2. Now install the Laravel IMAP package by running the following command:

```
composer require webklex/laravel-imap
```

3. If you're running Laravel &gt;= 5.5, package discovery will configure the service provider and `Client` alias out of the box.

    Otherwise, for Laravel &lt;= 5.4, edit your `config/app.php` file and:

    - add the following to the `providers` array: ```
        Webklex\IMAP\Providers\LaravelServiceProvider::class,
        ```
    - add the following to the `aliases` array: ```
        'Client' => Webklex\IMAP\Facades\Client::class,
        ```
4. Run the command below to publish the package config file [config/imap.php](src/config/imap.php):

```
php artisan vendor:publish --provider="Webklex\IMAP\Providers\LaravelServiceProvider"
```

Configuration
-------------

[](#configuration)

If you are planning to use a single account, you might want to add the following to your `.env` file.

```
IMAP_HOST=somehost.com
IMAP_PORT=993
IMAP_ENCRYPTION=ssl
IMAP_VALIDATE_CERT=true
IMAP_USERNAME=root@example.com
IMAP_PASSWORD=secret
IMAP_DEFAULT_ACCOUNT=default
IMAP_PROTOCOL=imap

```

Supported protocols:

- `imap` — Use IMAP \[default\]
- `pop3` — Use POP3
- `nntp` — Use NNTP

The following encryption methods are supported:

- `false` — Disable encryption
- `ssl` — Use SSL
- `tls` — Use TLS

Detailed [config/imap.php](src/config/imap.php) configuration:

- `default` — used default account. It will be used as default for any missing account parameters. If however the default account is missing a parameter the package default will be used. Set to `false` to disable this functionality.
- `accounts` — all available accounts
    - `default` — The account identifier (in this case `default` but could also be `fooBar` etc).
        - `host` — imap host
        - `port` — imap port
        - `encryption` — desired encryption method
        - `validate_cert` — decide weather you want to verify the certificate or not
        - `username` — imap account username
        - `password` — imap account password
- `options` — additional fetch options
    - `delimiter` — you can use any supported char such as ".", "/", etc
    - `fetch` — `IMAP::FT_UID` (message marked as read by fetching the message) or `IMAP::FT_PEEK` (fetch the message without setting the "read" flag)
    - `fetch_body` — If set to `false` all messages will be fetched without the body and any potential attachments
    - `fetch_attachment` — If set to `false` all messages will be fetched without any attachments
    - `fetch_flags` — If set to `false` all messages will be fetched without any flags
    - `message_key` — Message key identifier option
    - `fetch_order` — Message fetch order
    - `open` — special configuration for imap\_open()
        - `DISABLE_AUTHENTICATOR` — Disable authentication properties.
    - `decoder` — Currently only the message subject and attachment name decoder can be set
    - `masks` — Default [masking](#masking) config
        - `message` — Default message mask
        - `attachment` — Default attachment mask

Usage
-----

[](#usage)

#### Basic usage example

[](#basic-usage-example)

This is a basic example, which will echo out all Mails within all imap folders and will move every message into INBOX.read. Please be aware that this should not ben tested in real live but it gives an impression on how things work.

```
use Webklex\IMAP\Client;

$oClient = new Client([
    'host'          => 'somehost.com',
    'port'          => 993,
    'encryption'    => 'ssl',
    'validate_cert' => true,
    'username'      => 'username',
    'password'      => 'password',
    'protocol'      => 'imap'
]);
/* Alternative by using the Facade
$oClient = Webklex\IMAP\Facades\Client::account('default');
*/

//Connect to the IMAP Server
$oClient->connect();

//Get all Mailboxes
/** @var \Webklex\IMAP\Support\FolderCollection $aFolder */
$aFolder = $oClient->getFolders();

//Loop through every Mailbox
/** @var \Webklex\IMAP\Folder $oFolder */
foreach($aFolder as $oFolder){

    //Get all Messages of the current Mailbox $oFolder
    /** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
    $aMessage = $oFolder->messages()->all()->get();

    /** @var \Webklex\IMAP\Message $oMessage */
    foreach($aMessage as $oMessage){
        echo $oMessage->getSubject().'';
        echo 'Attachments: '.$oMessage->getAttachments()->count().'';
        echo $oMessage->getHTMLBody(true);

        //Move the current Message to 'INBOX.read'
        if($oMessage->moveToFolder('INBOX.read') == true){
            echo 'Message has ben moved';
        }else{
            echo 'Message could not be moved';
        }
    }
}
```

#### Facade

[](#facade)

If you use the Facade [\\Webklex\\IMAP\\Facades\\Client::class](src/IMAP/Facades/Client.php) please select an account first:

```
use Webklex\IMAP\Facades\Client;

$oClient = Client::account('default');
$oClient->connect();
```

#### Folder / Mailbox

[](#folder--mailbox)

There is an experimental function available to get a Folder instance by name. For an easier access please take a look at the new config option `imap.options.delimiter` however the `getFolder`method takes three options: the required (string) $folder\_name and two optional variables. An integer $attributes which seems to be sometimes 32 or 64 (I honestly have no clue what this number does, so feel free to enlighten me and anyone else) and a delimiter which if it isn't set will use the default option configured inside the [config/imap.php](src/config/imap.php) file.

```
/** @var \Webklex\IMAP\Client $oClient */

/** @var \Webklex\IMAP\Folder $oFolder */
$oFolder = $oClient->getFolder('INBOX.name');
```

List all available folders:

```
/** @var \Webklex\IMAP\Client $oClient */

/** @var \Webklex\IMAP\Support\FolderCollection $aFolder */
$aFolder = $oClient->getFolders();
```

#### Search for messages

[](#search-for-messages)

Search for specific emails:

```
/** @var \Webklex\IMAP\Folder $oFolder */

//Get all messages
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->query()->all()->get();

//Get all messages from example@domain.com
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->query()->from('example@domain.com')->get();

//Get all messages since march 15 2018
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->query()->since('15.03.2018')->get();

//Get all messages within the last 5 days
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->query()->since(now()->subDays(5))->get();
//Or for older laravel versions..
$aMessage = $oFolder->query()->since(\Carbon::now()->subDays(5))->get();

//Get all messages containing "hello world"
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->query()->text('hello world')->get();

//Get all unseen messages containing "hello world"
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->query()->unseen()->text('hello world')->get();

//Extended custom search query for all messages containing "hello world"
//and have been received since march 15 2018
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->query()->text('hello world')->since('15.03.2018')->get();
$aMessage = $oFolder->query()->Text('hello world')->Since('15.03.2018')->get();
$aMessage = $oFolder->query()->whereText('hello world')->whereSince('15.03.2018')->get();

// Build a custom search query
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->query()
->where([['TEXT', 'Hello world'], ['SINCE', \Carbon::parse('15.03.2018')]])
->get();

//!EXPERIMENTAL!
//Get all messages NOT containing "hello world"
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->query()->notText('hello world')->get();
$aMessage = $oFolder->query()->not_text('hello world')->get();
$aMessage = $oFolder->query()->not()->text('hello world')->get();
```

Available search aliases for a better code reading:

```
// Folder::search() is just an alias for Folder::query()
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->search()->text('hello world')->since('15.03.2018')->get();

// Folder::messages() is just an alias for Folder::query()
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->messages()->text('hello world')->since('15.03.2018')->get();
```

All available query / search methods can be found here: [Query::class](src/IMAP/Query/WhereQuery.php)

Available search criteria:

- `ALL` — return all messages matching the rest of the criteria
- `ANSWERED` — match messages with the \\ANSWERED flag set
- `BCC` "string" — match messages with "string" in the Bcc: field
- `BEFORE` "date" — match messages with Date: before "date"
- `BODY` "string" — match messages with "string" in the body of the message
- `CC` "string" — match messages with "string" in the Cc: field
- `DELETED` — match deleted messages
- `FLAGGED` — match messages with the \\FLAGGED (sometimes referred to as Important or Urgent) flag set
- `FROM` "string" — match messages with "string" in the From: field
- `KEYWORD` "string" — match messages with "string" as a keyword
- `NEW` — match new messages
- `NOT` — not matching
- `OLD` — match old messages
- `ON` "date" — match messages with Date: matching "date"
- `RECENT` — match messages with the \\RECENT flag set
- `SEEN` — match messages that have been read (the \\SEEN flag is set)
- `SINCE` "date" — match messages with Date: after "date"
- `SUBJECT` "string" — match messages with "string" in the Subject:
- `TEXT` "string" — match messages with text "string"
- `TO` "string" — match messages with "string" in the To:
- `UNANSWERED` — match messages that have not been answered
- `UNDELETED` — match messages that are not deleted
- `UNFLAGGED` — match messages that are not flagged
- `UNKEYWORD` "string" — match messages that do not have the keyword "string"
- `UNSEEN` — match messages which have not been read yet

Further information:

-
-
-
-
-

#### Result limiting

[](#result-limiting)

Limiting the request emails:

```
/** @var \Webklex\IMAP\Folder $oFolder */

//Get all messages for page 2 since march 15 2018 where each apge contains 10 messages
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->query()->since('15.03.2018')->limit(10, 2)->get();
```

#### Pagination

[](#pagination)

Paginate a query:

```
/** @var \Webklex\IMAP\Folder $oFolder */

/** @var \Illuminate\Pagination\LengthAwarePaginator $paginator */
$paginator = $oFolder->query()->since('15.03.2018')->paginate();
```

Paginate a message collection:

```
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */

/** @var \Illuminate\Pagination\LengthAwarePaginator $paginator */
$paginator = $aMessage->paginate();
```

Blade example for a paginated list:

```
/** @var \Webklex\IMAP\Folder $oFolder */

/** @var \Illuminate\Pagination\LengthAwarePaginator $paginator */
$paginator = $oFolder->search()
->since(\Carbon::now()->subDays(14))->get()
->paginate($perPage = 5, $page = null, $pageName = 'imap_blade_example');
```

```

            UID
            Subject
            From
            Attachments

        @if($paginator->count() > 0)
            @foreach($paginator as $oMessage)

                    {{$oMessage->getUid()}}
                    {{$oMessage->getSubject()}}
                    {{$oMessage->getFrom()[0]->mail}}
                    {{$oMessage->getAttachments()->count() > 0 ? 'yes' : 'no'}}

            @endforeach
        @else

                No messages found

        @endif

{{$paginator->links()}}
```

> You can also paginate a Folder-, Attachment- or FlagCollection instance.

#### View examples

[](#view-examples)

You can find a few blade examples under [/examples](https://github.com/Webklex/laravel-imap/tree/master/examples).

#### Fetch a specific message

[](#fetch-a-specific-message)

Get a specific message by uid (Please note that the uid is not unique and can change):

```
/** @var \Webklex\IMAP\Folder $oFolder */

/** @var \Webklex\IMAP\Message $oMessage */
$oMessage = $oFolder->getMessage($uid = 1);
```

#### Message flags

[](#message-flags)

Flag or "unflag" a message:

```
/** @var \Webklex\IMAP\Message $oMessage */
$oMessage->setFlag(['Seen', 'Spam']);
$oMessage->unsetFlag('Spam');
```

Mark all messages as "read" while fetching:

```
/** @var \Webklex\IMAP\Folder $oFolder */
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->query()->text('Hello world')->markAsRead()->get();
```

Don't mark all messages as "read" while fetching:

```
/** @var \Webklex\IMAP\Folder $oFolder */
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->query()->text('Hello world')->leaveUnread()->get();
```

#### Attachments

[](#attachments)

Save message attachments:

```
/** @var \Webklex\IMAP\Message $oMessage */

/** @var \Webklex\IMAP\Support\AttachmentCollection $aAttachment */
$aAttachment = $oMessage->getAttachments();

$aAttachment->each(function ($oAttachment) {
    /** @var \Webklex\IMAP\Attachment $oAttachment */
    $oAttachment->save();
});
```

#### Advanced fetching

[](#advanced-fetching)

Fetch messages without body fetching (decrease load):

```
/** @var \Webklex\IMAP\Folder $oFolder */

/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->query()->whereText('Hello world')->setFetchBody(false)->get();

/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->query()->whereAll()->setFetchBody(false)->setFetchAttachment();
```

Fetch messages without body, flag and attachment fetching (decrease load):

```
/** @var \Webklex\IMAP\Folder $oFolder */

/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->query()->whereText('Hello world')
->setFetchFlags(false)
->setFetchBody(false)
->setFetchAttachment(false)
->get();

/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->query()->whereAll()
->setFetchFlags(false)
->setFetchBody(false)
->setFetchAttachment(false)
->get();
```

#### Masking

[](#masking)

Laravel-IMAP already comes with two default masks [MessageMask::class](#messagemaskclass) and [AttachmentMask::class](#attachmentmaskclass).

The masked instance has to be called manually and is designed to add custom functionality.

You can call the default mask by calling the mask method without any arguments.

```
/** @var \Webklex\IMAP\Message $oMessage */
$mask = $oMessage->mask();
```

There are several methods available to set the default mask:

```
/** @var \Webklex\IMAP\Client $oClient */
/** @var \Webklex\IMAP\Message $oMessage */

$message_mask = \Webklex\IMAP\Support\Masks\MessageMask::class;

$oClient->setDefaultMessageMask($message_mask);
$oMessage->setMask($message_mask);
$mask = $oMessage->mask($message_mask);
```

The last one wont set the mask but generate a masked instance using the provided mask.

You could also set the default masks inside your `config/imap.php` file under `masks`.

You can also apply a mask on [attachments](#attachmentclass):

```
/** @var \Webklex\IMAP\Client $oClient */
/** @var \Webklex\IMAP\Attachment $oAttachment */
$attachment_mask = \Webklex\IMAP\Support\Masks\AttachmentMask::class;

$oClient->setDefaultAttachmentMask($attachment_mask);
$oAttachment->setMask($attachment_mask);
$mask = $oAttachment->mask($attachment_mask);
```

If you want to implement your own mask just extend [MessageMask::class](#messagemaskclass), [AttachmentMask::class](#attachmentmaskclass)or [Mask::class](#maskclass) and implement your desired logic:

```
/** @var \Webklex\IMAP\Message $oMessage */
class CustomMessageMask extends \Webklex\IMAP\Support\Masks\MessageMask {

    /**
     * New custom method which can be called through a mask
     * @return string
     */
    public function token(){
        return implode('-', [$this->message_id, $this->uid, $this->message_no]);
    }
}

$mask = $oMessage->mask(CustomMessageMask::class);

echo $mask->token().'@'.$mask->uid;
```

Additional examples can be found here:

- [Custom message mask](https://github.com/Webklex/laravel-imap/blob/master/examples/custom_message_mask.php)
- [Custom attachment mask](https://github.com/Webklex/laravel-imap/blob/master/examples/custom_attachment_mask.php)

#### Specials

[](#specials)

Find the folder containing a message:

```
$oFolder = $aMessage->getContainingFolder();
```

Support
-------

[](#support)

If you encounter any problems or if you find a bug, please don't hesitate to create a new [issue](https://github.com/Webklex/laravel-imap/issues). However please be aware that it might take some time to get an answer.

If you need **immediate** or **commercial** support, feel free to send me a mail at .

##### A little notice

[](#a-little-notice)

If you write source code in your issue, please consider to format it correctly. This makes it so much nicer to read and people are more likely to comment and help :)

``` php

echo 'your php code...';

```

will turn into:

```
echo 'your php code...';
```

### Features &amp; pull requests

[](#features--pull-requests)

Everyone can contribute to this project. Every pull request will be considered but it can also happen to be declined. To prevent unnecessary work, please consider to create a [feature issue](https://github.com/Webklex/laravel-imap/issues/new?template=feature_request.md)first, if you're planning to do bigger changes. Of course you can also create a new [feature issue](https://github.com/Webklex/laravel-imap/issues/new?template=feature_request.md)if you're just wishing a feature ;)

> Off topic, rude or abusive issues will be deleted without any notice.

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

[](#documentation)

### [Client::class](src/IMAP/Client.php)

[](#clientclass)

MethodArgumentsReturnDescriptionsetConfigarray $configselfSet the Client configuration. Take a look at `config/imap.php` for more inspiration.getConnectionresource $connectionresourceGet the current imap resourcesetReadOnlybool $readOnlyselfSet read only property and reconnect if it's necessary.isReadOnlyboolDetermine if connection is in read only mode.isConnectedboolDetermine if connection was established.checkConnectionDetermine if connection was established and connect if not.connectint $attemptsConnect to server.disconnectDisconnect from server.getFolderstring $folder\_name, int $attributes = 32, int or null $delimiterFolderGet a Folder instance by namegetFoldersbool $hierarchical, string or null $parent\_folderFolderCollectionGet folders list. If hierarchical order is set to true, it will make a tree of folders, otherwise it will return flat array.openFolderstring or Folder $folder, integer $attemptsOpen a given folder.createFolderstring $namebooleanCreate a new folder.renameFolderstring $old\_name, string $new\_namebooleanRename a folder.deleteFolderstring $namebooleanDelete a folder.getMessagesFolder $folder, string $criteria, bool $fetch\_body, bool $fetch\_attachment, bool $fetch\_flagsMessageCollectionGet messages from folder.getUnseenMessagesFolder $folder, string $criteria, bool $fetch\_body, bool $fetch\_attachment, bool $fetch\_flagsMessageCollectionGet Unseen messages from folder.searchMessagesarray $where, Folder $folder, $fetch\_options, bool $fetch\_body, string $charset, bool $fetch\_attachment, bool $fetch\_flagsMessageCollectionGet specific messages from a given folder.getQuotaarrayRetrieve the quota level settings, and usage statics per mailboxgetQuotaRootstring $quota\_rootarrayRetrieve the quota settings per usercountMessagesintGets the number of messages in the current mailboxcountRecentMessagesintGets the number of recent messages in current mailboxgetAlertsarrayReturns all IMAP alert messages that have occurredgetErrorsarrayReturns all of the IMAP errors that have occurredgetLastErrorstringGets the last IMAP error that occurred during this page requestexpungeboolDelete all messages marked for deletioncheckCurrentMailboxobjectCheck current mailboxsetTimeoutstring or int $type, int $timeoutbooleanSet the timeout for certain imap operations: 1: Open, 2: Read, 3: Write, 4: ClosegetTimeoutstring or int $typeintCheck current mailboxsetDefaultMessageMaskstring $maskselfSet the default message mask classgetDefaultMessageMaskstringGet the current default message mask class namesetDefaultAttachmentMaskstring $maskselfSet the default attachment mask classgetDefaultAttachmentMaskstringGet the current default attachment mask class namegetFolderPathstringGet the current folder path### [Message::class](src/IMAP/Message.php)

[](#messageclass)

MethodArgumentsReturnDescriptionparseBodyMessageParse the Message bodydeleteboolean $expungebooleanDelete the current Messagerestoreboolean $expungebooleanRestore a deleted Messagecopystring $mailbox, int $optionsbooleanCopy the current Messages to a mailboxmovestring $mailbox, int $optionsbooleanMove the current Messages to a mailboxgetContainingFolderFolder or null $folderFolder or nullGet the folder containing the messagemoveToFolderstring $mailbox, boolean $expunge, boolean $create\_folderMessageMove the Message into an other FoldersetFlagstring or array $flagbooleanSet one or many flagsunsetFlagstring or array $flagbooleanUnset one or many flagshasTextBodyCheck if the Message has a text bodyhasHTMLBodyCheck if the Message has a html bodygetTextBodystringGet the Message text bodygetHTMLBodystringGet the Message html bodygetAttachmentsAttachmentCollectionGet all message attachmentshasAttachmentsbooleanChecks if there are any attachments presentgetClientClientGet the current Client instancegetUidstringGet the current UIDgetFetchOptionsstringGet the current fetch optiongetMsglistintegerGet the current message listgetHeaderInfoobjectGet the current header\_info objectgetHeaderstringGet the current raw headergetMessageIdstringGet the current message IDgetMessageNointegerGet the current message numbergetPriorityintegerGet the current message prioritygetSubjectstringGet the current subjectgetReferencesmixedGet any potentially present referencesgetDateCarbonGet the current date objectgetFromarrayGet the current from informationgetToarrayGet the current to informationgetCcarrayGet the current cc informationgetBccarrayGet the current bcc informationgetReplyToarrayGet the current reply to informationgetInReplyTostringGet the current In-Reply-TogetSenderarrayGet the current sender informationgetBodiesmixedGet the current bodiesgetRawBodymixedGet the current raw message bodygetFlagsFlagCollectionGet the current message flagsisbooleanDoes this message match another one?getStructureobjectThe raw message structuremaskstring $mask = nullMaskGet a masked instancesetMaskstring $maskMessageSet the mask classgetMaskstringGet the current mask class name### [Folder::class](src/IMAP/Folder.php)

[](#folderclass)

MethodArgumentsReturnDescriptionhasChildrenboolDetermine if folder has children.setChildrenarray $childrenselfSet children.getMessageinteger $uid, integer or null $msglist, int or null fetch\_options, bool $fetch\_body, bool $fetch\_attachment, bool $fetch\_flagsMessageGet a specific message from folder.getMessagesstring $criteria, int or null $fetch\_options, bool $fetch\_body, bool $fetch\_attachment, bool $fetch\_flagsMessageCollectionGet messages from folder.getUnseenMessagesstring $criteria, int or null $fetch\_options, bool $fetch\_body, bool $fetch\_attachment, bool $fetch\_flagsMessageCollectionGet Unseen messages from folder.searchMessagesarray $where, int or null $fetch\_options, bool $fetch\_body, string $charset, bool $fetch\_attachment, bool $fetch\_flagsMessageCollectionGet specific messages from a given folder.deleteDelete the current Mailboxmovestring $mailboxMove or Rename the current MailboxgetStatusinteger $optionsobjectReturns status information on a mailboxappendMessagestring $message, string $options, string $internal\_dateboolAppend a string message to the current mailboxgetClientClientGet the current Client instancequerystring $charset = 'UTF-8'WhereQueryGet the current Client instancemessagesstring $charset = 'UTF-8'WhereQueryAlias for Folder::query()searchstring $charset = 'UTF-8'WhereQueryAlias for Folder::query()### [Query::class](src/IMAP/Query/WhereQuery.php)

[](#queryclass)

MethodArgumentsReturnDescriptionwheremixed $criteria, $value = nullWhereQueryAdd new criteria to the current queryorWhereClosure $closureWhereQueryIf supported you can perform extended search requestsandWhereClosure $closureWhereQueryIf supported you can perform extended search requestsallWhereQuerySelect all available messagesansweredWhereQuerySelect answered messagesdeletedWhereQuerySelect deleted messagesnewWhereQuerySelect new messagesnotWhereQueryNot select messagesoldWhereQuerySelect old messagesrecentWhereQuerySelect recent messagesseenWhereQuerySelect seen messagesunansweredWhereQuerySelect unanswered messagesundeletedWhereQuerySelect undeleted messagesunflaggedWhereQuerySelect unflagged messagesunseenWhereQuerySelect unseen messagesnoXSpamWhereQuerySelect as no xspam flagged messagesisXSpamWhereQuerySelect as xspam flagged messageslanguagestring $valueWhereQuerySelect messages matching a given languageunkeywordstring $valueWhereQuerySelect messages matching a given unkeywordmessageIdstring $valueWhereQuerySelect messages matching a given message idtostring $valueWhereQuerySelect messages matching a given receiver (To:)textstring $valueWhereQuerySelect messages matching a given text bodysubjectstring $valueWhereQuerySelect messages matching a given subjectsincestring $valueWhereQuerySelect messages since a given dateonstring $valueWhereQuerySelect messages on a given datekeywordstring $valueWhereQuerySelect messages matching a given keywordfromstring $valueWhereQuerySelect messages matching a given sender (From:)flaggedstring $valueWhereQuerySelect messages matching a given flagccstring $valueWhereQuerySelect messages matching a given receiver (CC:)bodystring $valueWhereQuerySelect messages matching a given HTML bodybeforestring $valueWhereQuerySelect messages before a given datebccstring $valueWhereQuerySelect messages matching a given receiver (BCC:)getMessageCollectionFetch messages with the current querylimitinteger $limit, integer $page = 1WhereQueryLimit the amount of messages being fetchedsetFetchOptionsboolean $fetch\_optionsWhereQuerySet the fetch optionssetFetchBodyboolean $fetch\_bodyWhereQuerySet the fetch body optiongetFetchAttachmentboolean $fetch\_attachmentWhereQuerySet the fetch attachment optionsetFetchFlagsboolean $fetch\_flagsWhereQuerySet the fetch flags optionleaveUnreadWhereQueryDon't mark all messages as "read" while fetching:markAsReadWhereQueryMark all messages as "read" while fetchingpaginateint $perPage = 5, $page = null, $pageName = 'imap\_page'LengthAwarePaginatorPaginate the current query.### [Attachment::class](src/IMAP/Attachment.php)

[](#attachmentclass)

MethodArgumentsReturnDescriptiongetContentstring or nullGet attachment contentgetMimeTypestring or nullGet attachment mime typegetExtensionstring or nullGet a guessed attachment extensiongetNamestring or nullGet attachment namegetTypestring or nullGet attachment typegetDispositionstring or nullGet attachment dispositiongetContentTypestring or nullGet attachment content typegetImgSrcstring or nullGet attachment image source as base64 encoded data urlsavestring $path, string $filenamebooleanSave the attachment content to your filesystemmaskstring $mask = nullMaskGet a masked instancesetMaskstring $maskAttachmentSet the mask classgetMaskstringGet the current mask class name### [Mask::class](src/IMAP/Support/Masks/Mask.php)

[](#maskclass)

MethodArgumentsReturnDescriptiongetParentMasked parentGet the masked parent objectgetAttributesarrayGet all cloned attributes\_\_getmixedAccess any cloned parent attribute\_\_setmixedSet any cloned parent attribute\_\_inheritmixedAll public methods of the given parent are callable### [MessageMask::class](src/IMAP/Support/Masks/MessageMask.php)

[](#messagemaskclass)

MethodArgumentsReturnDescriptiongetHtmlBodystring or nullGet HTML bodygetCustomHTMLBodycallable or bool $callbackstring or nullGet a custom HTML bodygetHTMLBodyWithEmbeddedBase64Imagesstring or nullGet HTML body with embedded base64 imagesgetHTMLBodyWithEmbeddedUrlImagesstring $route\_name, array $params = \[\]string or nullGet HTML body with embedded routed images### [AttachmentMask::class](src/IMAP/Support/Masks/AttachmentMask.php)

[](#attachmentmaskclass)

MethodArgumentsReturnDescriptiongetContentBase64Encodedstring or nullGet attachment contentgetImageSrcstring or nullGet attachment mime type### [MessageCollection::class](src/IMAP/Support/MessageCollection.php)

[](#messagecollectionclass)

Extends [Illuminate\\Support\\Collection::class](https://laravel.com/api/5.4/Illuminate/Support/Collection.html)

MethodArgumentsReturnDescriptionpaginateint $perPage = 15, $page = null, $pageName = 'page'LengthAwarePaginatorPaginate the current collection.### [FlagCollection::class](src/IMAP/Support/FlagCollection.php)

[](#flagcollectionclass)

Extends [Illuminate\\Support\\Collection::class](https://laravel.com/api/5.4/Illuminate/Support/Collection.html)

MethodArgumentsReturnDescriptionpaginateint $perPage = 15, $page = null, $pageName = 'page'LengthAwarePaginatorPaginate the current collection.### [AttachmentCollection::class](src/IMAP/Support/AttachmentCollection.php)

[](#attachmentcollectionclass)

Extends [Illuminate\\Support\\Collection::class](https://laravel.com/api/5.4/Illuminate/Support/Collection.html)

MethodArgumentsReturnDescriptionpaginateint $perPage = 15, $page = null, $pageName = 'page'LengthAwarePaginatorPaginate the current collection.### [FolderCollection::class](src/IMAP/Support/FolderCollection.php)

[](#foldercollectionclass)

Extends [Illuminate\\Support\\Collection::class](https://laravel.com/api/5.4/Illuminate/Support/Collection.html)

MethodArgumentsReturnDescriptionpaginateint $perPage = 15, $page = null, $pageName = 'page'LengthAwarePaginatorPaginate the current collection.### Known issues

[](#known-issues)

ErrorSolutionKerberos error: No credentials cache file found (try running kinit) (...)Uncomment "DISABLE\_AUTHENTICATOR" inside `config/imap.php`imap\_fetchbody() expects parameter 4 to be long, string given (...)Make sure that `imap.options.fetch` is a valid integerUse of undefined constant FT\_UID - assumed 'FT\_UID' (...)Please take a look at [\#14](https://github.com/Webklex/laravel-imap/issues/14) [\#30](https://github.com/Webklex/laravel-imap/issues/30)DateTime::\_\_construct(): Failed to parse time string (...)Please report any new invalid timestamps to [\#45](https://github.com/Webklex/laravel-imap/issues/45)imap\_open(): Couldn't open (...) Please log in your web browser: (...)In order to use IMAP on some services (such as Gmail) you need to enable it first. [Google help page](https://support.google.com/mail/answer/7126229?hl=en)imap\_headerinfo(): Bad message numberThis happens if no Message number is available. Please make sure Message::parseHeader() has run beforeimap\_open(): Couldn't open stream {outlook.office365.com:993/imap/s (...)Can be caused by a lot of things: head over to these issues for more information: [\#153](https://github.com/Webklex/laravel-imap/issues/153) [\#100](https://github.com/Webklex/laravel-imap/issues/100) [\#78](https://github.com/Webklex/laravel-imap/issues/78)Milestones &amp; upcoming features
----------------------------------

[](#milestones--upcoming-features)

- Wiki!!

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Webklex](https://github.com/webklex)
- [All Contributors](https://github.com/Webklex/laravel-imap/graphs/contributors)

Supporters
----------

[](#supporters)

A special thanks to Jetbrains for supporting this project through their [open source license program](https://www.jetbrains.com/buy/opensource/).

[![Jetbrains](https://camo.githubusercontent.com/aa7dfb96fea37e644beb3827de9ace8b53284ffdcaab9a091ea5a6e652bc65de/68747470733a2f2f7777772e7765626b6c65782e636f6d2f6a6574627261696e732e706e67)](https://www.jetbrains.com)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 88.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 ~14 days

Recently: every ~52 days

Total

56

Last Release

2587d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e963bc9a9ef7afa97330b6028b3a781c065bd3683714701afaac39900efe27a4?d=identicon)[zhichen92](/maintainers/zhichen92)

---

Top Contributors

[![Webklex](https://avatars.githubusercontent.com/u/2884144?v=4)](https://github.com/Webklex "Webklex (288 commits)")[![radicalloop](https://avatars.githubusercontent.com/u/20556881?v=4)](https://github.com/radicalloop "radicalloop (6 commits)")[![Limman](https://avatars.githubusercontent.com/u/9432322?v=4)](https://github.com/Limman "Limman (4 commits)")[![emtudo](https://avatars.githubusercontent.com/u/191396?v=4)](https://github.com/emtudo "emtudo (3 commits)")[![dansleboby](https://avatars.githubusercontent.com/u/4716382?v=4)](https://github.com/dansleboby "dansleboby (3 commits)")[![parshikov](https://avatars.githubusercontent.com/u/983028?v=4)](https://github.com/parshikov "parshikov (2 commits)")[![tiacardoso](https://avatars.githubusercontent.com/u/36483226?v=4)](https://github.com/tiacardoso "tiacardoso (2 commits)")[![freescout-helpdesk](https://avatars.githubusercontent.com/u/40499291?v=4)](https://github.com/freescout-helpdesk "freescout-helpdesk (2 commits)")[![GeoSot](https://avatars.githubusercontent.com/u/22406063?v=4)](https://github.com/GeoSot "GeoSot (2 commits)")[![alfonsobries](https://avatars.githubusercontent.com/u/17262776?v=4)](https://github.com/alfonsobries "alfonsobries (2 commits)")[![sparavalo](https://avatars.githubusercontent.com/u/7484077?v=4)](https://github.com/sparavalo "sparavalo (1 commits)")[![todorowww](https://avatars.githubusercontent.com/u/4169512?v=4)](https://github.com/todorowww "todorowww (1 commits)")[![zhichen92](https://avatars.githubusercontent.com/u/18463213?v=4)](https://github.com/zhichen92 "zhichen92 (1 commits)")[![ascweb](https://avatars.githubusercontent.com/u/3051143?v=4)](https://github.com/ascweb "ascweb (1 commits)")[![eidng8](https://avatars.githubusercontent.com/u/787265?v=4)](https://github.com/eidng8 "eidng8 (1 commits)")[![FlashWS](https://avatars.githubusercontent.com/u/9982293?v=4)](https://github.com/FlashWS "FlashWS (1 commits)")[![gareth-ib](https://avatars.githubusercontent.com/u/29517750?v=4)](https://github.com/gareth-ib "gareth-ib (1 commits)")[![k9uma](https://avatars.githubusercontent.com/u/12296763?v=4)](https://github.com/k9uma "k9uma (1 commits)")[![lomotech](https://avatars.githubusercontent.com/u/7269466?v=4)](https://github.com/lomotech "lomotech (1 commits)")[![madbob](https://avatars.githubusercontent.com/u/166089?v=4)](https://github.com/madbob "madbob (1 commits)")

---

Tags

laravelmailimapwebklexlaravel-imap

### Embed Badge

![Health badge](/badges/kqtec-laravel-imap/health.svg)

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

###  Alternatives

[webklex/laravel-imap

Laravel IMAP client

7164.2M13](/packages/webklex-laravel-imap)[webklex/php-imap

PHP IMAP client

4365.5M14](/packages/webklex-php-imap)[vemcogroup/laravel-sparkpost-driver

SparkPost driver to use with Laravel 6.x|7.x|8.x|9.x|10.x

421.7M1](/packages/vemcogroup-laravel-sparkpost-driver)[zalazdi/laravel-imap

Laravel 5 IMAP client.

5112.8k](/packages/zalazdi-laravel-imap)

PHPackages © 2026

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