2017 © Pedro Peláez
 

library imap

A PHP wrapper class for PHP's IMAP-related email handling functions.

image

bigpaulie/imap

A PHP wrapper class for PHP's IMAP-related email handling functions.

  • Thursday, July 5, 2018
  • by bigpaulie
  • Repository
  • 1 Watchers
  • 0 Stars
  • 45 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 30 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Imap

This library is an improvement of Jeff Geerling's project tailored specifically for my needs at the moment., (*1)

Keep in mind that this is still a work in progress so radical changes may occurr in time., (*2)

Installation

You can install this library via composer by running the command bellow or you can clone the repository., (*3)

composer require bigpaulie/imap

Usage

A mailbox in the context of this library is referring to a directory of your email account., (*4)

Connect to an IMAP account by creating a new Imap object with the required parameters:, (*5)

$host = 'imap.example.com';
$user = 'johndoe';
$pass = '12345';
$port = 993;
$ssl = true;
$folder = 'INBOX';
$server = new Imap($host, $user, $pass, $port, $ssl, $folder);
Obtain a mailbox object
/** @var Mailbox $mailbox */
$mailbox = $server->getMailbox();

If you want to access another directory, (*6)

/** @var Mailbox $mailbox */
$mailbox = $server->getMailbox('SPAM');
Mailbox info
/** @var array $info */
$info = $mailbox->getInfo();
Obtain a list of messages within a specific mailbox
/** @var Message[] $messages */
$messages = $mailbox->getMessages();

You can then iterate through the array of messages, (*7)

/** @var Message $message */
foreach ($messages as $message) {
    $subject = $message->getSubject();
    $messageBody = $message->getBody();
}
Create a search criteria

You can obtain only certain messages if you want to., (*8)

Only undeleted messages, (*9)

/** @var Search $criteria */
$criteria = new Search();
$criteria->setCriteria(Search::UNDELETED);

/** @var Message[] $messages */
$messages = $mailbox->getMessages($criteria);

You can add multiple search criterias for example :, (*10)

/** @var Search $criteria */
$criteria = new Search();
$criteria->setCriteria(Search::UNDELETED);
$criteria->setCriteria(Search::FROM, "John Doe");
$criteria->setCriteria(Search::KEYWORD, "candy");

/** @var Message[] $messages */
$messages = $mailbox->getMessages($criteria);

Search criterias can be chained together:, (*11)

/** @var Search $criteria */
$criteria = new Search();
$criteria->setCriteria(Search::UNDELETED)
    ->setCriteria(Search::FROM, "John Doe")
    ->setCriteria(Search::KEYWORD, "candy");

/** @var Message[] $messages */
$messages = $mailbox->getMessages($criteria);
Moving messages

You can move messages from one mailbox to another very easily, (*12)

if ($mailbox->moveMessage($message, 'SPAM')) {
    echo "Message moved successfuly";
}
Copying messages

Copying messages is as easy as moving them, (*13)

if ($mailbox->copyMessage($message, 'SPAM')) {
    echo "Message moved successfuly";
}
Deleting messages
$mailbox->deleteMessage($message);
Disconnecting from the server
$server->disconnect();

Contributions

If you want to make a contribution and improve the library or you noticed a bug you are more than welcome to do so., (*14)

For contributors just fork, code and submit a pull request., (*15)

Please maintain the coding style and testing patterns., (*16)

The Versions

05/07 2018

dev-master

9999999-dev

A PHP wrapper class for PHP's IMAP-related email handling functions.

  Sources   Download

MIT

The Requires

  • php ^7.0
  • ext-imap *

 

The Development Requires

php wrapper imap