2017 © Pedro Peláez
 

library imap

Object-oriented IMAP for PHP

image

hrodrigues1984/imap

Object-oriented IMAP for PHP

  • Thursday, March 16, 2017
  • by hrodrigues1984
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 186 Forks
  • 0 Open issues
  • 13 Versions
  • 0 % Grown

The README.md

IMAP library

Build Status Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

A PHP 5.5+ library to read and process e-mails over IMAP., (*2)

Installation

Make sure the PHP IMAP extension is installed. For instance on Debian:, (*3)

The recommended way to install the IMAP library is through Composer:, (*4)

$ composer require hrodrigues1984/imap

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation., (*5)

Usage

Connect and Authenticate

use Ddeboer\Imap\Server;

$server = new Server('imap.mail.com');

// $connection is instance of \Ddeboer\Imap\Connection
$connection = $server->authenticate('my_username', 'my_password');

Options

You can specify port, flags and parameters to the server:, (*6)

$server = new Server(
    $hostname, // required
    $port,     // defaults to 993
    $flags,    // defaults to '/imap/ssl/validate-cert'
    $parameters
);

Mailboxes

Retrieve mailboxes (also known as mail folders) from the mail server and iterate over them:, (*7)

$mailboxes = $connection->getMailboxes();

foreach ($mailboxes as $mailbox) {
    // $mailbox is instance of \Ddeboer\Imap\Mailbox
    printf('Mailbox %s has %s messages', $mailbox->getName(), $mailbox->count());
}

Or retrieve a specific mailbox:, (*8)

$mailbox = $connection->getMailbox('Inbox');

Delete a mailbox:, (*9)

$mailbox->delete();

Messages

Retrieve messages (e-mails) from a mailbox and iterate over them:, (*10)

$messages = $mailbox->getMessages();

foreach ($messages as $message) {
    // $message is instance of \Ddeboer\Imap\Message
}

Searching for Messages

use Ddeboer\Imap\SearchExpression;
use Ddeboer\Imap\Search\Email\To;
use Ddeboer\Imap\Search\Text\Body;

$search = new SearchExpression();
$search->addCondition(new To('me@here.com'))
    ->addCondition(new Body('contents'))
;

$messages = $mailbox->getMessages($search);

Message Properties and Operations

Get message number and unique message id in the form ...:, (*11)

$message->getNumber();
$message->getId();

Get other message properties:, (*12)

$message->getSubject();
$message->getFrom();
$message->getTo();
$message->getDate();
$message->isAnswered();
$message->isDeleted();
$message->isDraft();
$message->isSeen();

Get message headers as a \Ddeboer\Imap\Message\Headers object:, (*13)

$message->getHeaders();

Get message body as HTML or plain text:, (*14)

$message->getBodyHtml();
$message->getBodyText();

Reading the message body marks the message as seen. If you want to keep the message unseen:, (*15)

$message->keepUnseen()->getBodyHtml();

Move a message to another mailbox:, (*16)

$mailbox = $connection->getMailbox('another-mailbox');
$message->move($mailbox);

Deleting messages:, (*17)

$mailbox->getMessage(1)->delete();
$mailbox->getMessage(2)->delete();
$mailbox->expunge();

Message Attachments

Get message attachments (both inline and attached) and iterate over them:, (*18)

$attachments = $message->getAttachments();

foreach ($attachments as $attachment) {
    // $attachment is instance of \Ddeboer\Imap\Message\Attachment
}

Download a message attachment to a local file:, (*19)

// getDecodedContent() decodes the attachment’s contents automatically:
file_put_contents(
    '/my/local/dir/' . $attachment->getFilename(),
    $attachment->getDecodedContent()
);

Running the Tests

If you have your own IMAP (test) account, you can run the tests locally by providing your IMAP (e.g., Email Provider) credentials:, (*20)

$ composer install --dev
$ EMAIL_USERNAME="your_username" EMAIL_PASSWORD="your_password" EMAIL_SERVER="imap.mail.com" vendor/bin/phpunit

The Versions

16/03 2017

dev-master

9999999-dev

Object-oriented IMAP for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

mail email imap

16/03 2017

0.5.32

0.5.32.0

Object-oriented IMAP for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

mail email imap

14/03 2017

0.5.31

0.5.31.0

Object-oriented IMAP for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

mail email imap

14/03 2017

0.5.3

0.5.3.0

Object-oriented IMAP for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

mail email imap

06/05 2016

dev-travis-hhvm-php7

dev-travis-hhvm-php7

Object-oriented IMAP for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

mail email imap

03/12 2015

0.5.2

0.5.2.0

Object-oriented IMAP for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

mail email imap

01/02 2015

0.5.1

0.5.1.0

Object-oriented IMAP for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

mail email imap

24/01 2015

0.5.0

0.5.0.0

Object-oriented IMAP for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

mail email imap

04/01 2015

0.4.0

0.4.0.0

Object-oriented IMAP library for PHP 5.3+

  Sources   Download

MIT

The Requires

 

The Development Requires

11/08 2014

0.3.1

0.3.1.0

Receive and send e-mails over IMAP

  Sources   Download

MIT

The Requires

 

The Development Requires

10/08 2014

0.3.0

0.3.0.0

Receive and send e-mails over IMAP

  Sources   Download

MIT

The Requires

 

The Development Requires

24/11 2013

0.2

0.2.0.0

Receive and send e-mails over IMAP

  Sources   Download

MIT

The Requires

 

The Development Requires

23/11 2013

0.1

0.1.0.0

Receive and send e-mails over IMAP

  Sources   Download

MIT

The Requires

 

The Development Requires