Download the PHP package php-experts/imap without Composer
On this page you can find all versions of the php package php-experts/imap. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download php-experts/imap
More information about php-experts/imap
Files in php-experts/imap
Informations about the package imap
IMAP library
A PHP 7.1+ library to read and process e-mails over IMAP.
This library requires IMAP, iconv and Multibyte String extensions installed.
Table of Contents
- Feature Requests
- Installation
- Usage
- Connect and Authenticate
- Mailboxes
- Messages
- Searching for Messages
- Unknown search criterion: OR
- Message Properties and Operations
- Message Attachments
- Embedded Messages
- Timeouts
- Mock the library
- Running the Tests
- Running Tests using Docker
Feature Requests
Installation
The recommended way to install the IMAP library is through Composer:
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Usage
Connect and Authenticate
You can specify port, flags and parameters to the server:
Mailboxes
Retrieve mailboxes (also known as mail folders) from the mail server and iterate over them:
Or retrieve a specific mailbox:
Delete a mailbox:
You can bulk set, or clear, any flag of mailbox messages (by UIDs):
WARNING You must retrieve new Message instances in case of bulk modify flags to refresh the single Messages flags.
Messages
Retrieve messages (e-mails) from a mailbox and iterate over them:
To insert a new message (that just has been sent) into the Sent mailbox and flag it as seen:
Note that the message should be a string at MIME format (as described in the RFC2045).
Searching for Messages
WARNING We are currently unable to have both spaces and double-quotes
escaped together. Only spaces are currently escaped correctly.
You can use Ddeboer\Imap\Search\RawExpression
to write the complete search
condition by yourself.
Messages can also be retrieved sorted as per imap_sort function:
Unknown search criterion: OR
Note that PHP imap library relies on the c-client
library available at https://www.washington.edu/imap/
which doesn't fully support some IMAP4 search criteria like OR
. If you want those unsupported criteria,
you need to manually patch the latest version (imap-2007f
of 23-Jul-2011 at the time of this commit)
and recompile PHP onto your patched c-client
library.
By the way most of the common search criteria are available and functioning, browse them in ./src/Search
.
References:
- https://stackoverflow.com/questions/36356715/imap-search-unknown-search-criterion-or
- imap-2007f.tar.gz:
./src/c-client/mail.c
and./docs/internal.txt
Message Properties and Operations
Get message number and unique message id in the form <...>:
Get other message properties:
Get message headers as a \Ddeboer\Imap\Message\Headers object:
Get message body as HTML or plain text:
Reading the message body keeps the message as unseen. If you want to mark the message as seen:
Or you can set, or clear, any flag:
Move a message to another mailbox:
Deleting messages:
Message Attachments
Get message attachments (both inline and attached) and iterate over them:
Download a message attachment to a local file:
Embedded Messages
Check if attachment is embedded message and get it:
An EmbeddedMessage has the same API as a normal Message, apart from flags and operations like copy, move or delete.
Timeouts
The IMAP extension provides the imap_timeout function to adjust the timeout seconds for various operations.
However the extension's implementation doesn't link the functionality to a
specific context or connection, instead they are global. So in order to not
affect functionalities outside this library, we had to choose whether wrap
every imap_*
call around an optional user-provided timeout or leave this
task to the user.
Because of the heterogeneous world of IMAP servers and the high complexity burden cost for such a little gain of the former, we chose the latter.
Mock the library
Mockability is granted by interfaces present for each API. Dig into MockabilityTest for an example of a mocked workflow.
Running the Tests
This library is functionally tested on Travis CI against a local Dovecot server.
If you have your own IMAP (test) account, you can run the tests locally by providing your IMAP credentials:
You can also copy phpunit.xml.dist
file to a custom phpunit.xml
and put
these environment variables in it:
WARNING Tests create new mailboxes without removing them.
Running Tests using Docker
If you have Docker installed you can run the tests locally with the following command:
All versions of imap with dependencies
ext-iconv Version *
ext-imap Version *
ext-mbstring Version *