2017 © Pedro Peláez
 

library php-libimap

A PHP IMAP library in Pure OOP for ease and simplicity

image

razzbee/php-libimap

A PHP IMAP library in Pure OOP for ease and simplicity

  • Sunday, July 2, 2017
  • by razzbee
  • Repository
  • 1 Watchers
  • 0 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

php-libimap

php-libimap is a PHP imap library in pure OOP, the idea is to make the native php_imap functions easier to use with performance tunning in mind., (*1)

Installation

using composer , include this in your composer.json file :, (*2)

"razzbee/php-libimap" : "dev-master"

Usage

Initialize class

$imap = new \PHPLibImap\IMAP;

connect an imap server, (*3)

$imap->connectServer([
   'host' => 'localhost',
   'port' => 993,
   'imap_username' => 'username@domain.tld',
   'password' => 'secret',
   'mailbox_name' => 'INBOX',
   'enableSSL' => true,
]);

host : Your Imap mail server hostname , example : localhost , 19.10.10.2 , imap.domain.tld or domain.tld, (*4)

port : your mailserver's imap's port , the default for secure connection is 993 and no secure connection is 143, (*5)

imap_username : The full qualified email address of mail account , example: you@example.com, (*6)

password : your mail account password., (*7)

mailbox_name : (optional) , the mailbox to open on an initial connection, if non is specified, INBOX will be used., (*8)

enableSSL : (optional) , This is for those using a custom port, so that the library will know if the port needs a secure connection, (*9)

Switching Mailbox

After Connecting to the server, the optional mailbox_name supplied in the connection parameters is opened automatically , you can change or switch mailbox using, (*10)

$imap-> switchMailBox('mailbox_name');

the mailbox_name must be one of the names of the mailfolders or boxes in your mailserver , example: INBOX , Drafts , Spam or Trash, (*11)

Fetch MailBoxes (Mail Folders)

You can also list available mail boxes in mailserver, (*12)

$mailBoxes = $imap->getMailBoxes($pattern);

$pattern: (optional) This is either * or % where :, (*13)

* Means the library should fetch all the mailboxes including top level mail boxes and sub folders, (*14)

% Means the library should fetch all sub folders in the current mailbox, (*15)

read more here : http://php.net/manual/en/function.imap-getmailboxes.php, (*16)

Get Info About a mailbox

$mailBoxInfo = $imap->getMailBoxInfo($mailboxName=null,$forceNew=false);

$mailBoxName: (optional) the name of the mailbox you want the info about, it defaults to the current opened mailbox if not set, (*17)

$forceNew : (optional) The mailbox info is always prefetched and kept, but if you want a fresh copy of the info to be refetched , set this to true .., (*18)

Count Total Recent Messages, (*19)

$totalRecent = $imap->getMailBoxInfo()->recent;

Count Total Unread Messages In the MailBox

$totalMsgNo = $imap->getTotalMessages();

//or

$totalMsgNo = $imap->getMailBoxInfo()->messages;

Fetch Mails From a MailBox

This library has many ways to fetch mails from a mailbox , we have also optimized this particular feature for speed and performance .., (*20)

Fetch MailBox Items overview By UID

$mails = $imap->fetchMailBoxItems("mailbox_name")
              ->select(uid1,uid2,uid3,uid4...uidN)
              ->getResults();

mailbox_name : optional mailbox name , if none is supplied, the current opened mailboxed will be used, (*21)

select(uid1,uid2, ... ): Select mail headers by the uid or the integer id(s) of the mail(s) , you must provide a valid uid else an exception will be generated, (*22)

getResults : Generate and get the results, (*23)

Fetch Mail Overview using range

$mails = $imap->fetchMailBoxItems("mailbox_name")
              ->range(1,10)
              ->orderById('desc')
              ->getResults();

range(arg1,arg2) : The range of mail uid , the above example will pull mailbox item overview info of uid 1 to 10 , This method assumes you already know your range already.., (*24)

orderById : Order the results by the uid , the default is DESC (Descending Order), this means the latest mails overview info will be shown first, (*25)

Fetch Mail Overview using limit and Offset

Like mysql limit and offset , this library supports the limit and offset using the limit($limit,$offset) method.., (*26)

$mails = $imap->fetchMailBoxItems("mailbox_name")
              ->limit(1,10)
              ->orderById('desc')
              ->getResults();

limit($limit,$offset=0) : The limit method accepts two arguments the limit and offset ,internally , the limits and offsets are been calculated automatically to ranges , this method is safer to use if you have no idea about the range values or number of data in the mailbox. The offset is optional and defaults to 0, (*27)

Move Mail Between Mailboxes

This method moves email message between mailboxes or folder, on success true is returned else false,an exception will also occur on error .., (*28)

$move = $imap->moveMail($mails_uids_array,$source_mailbox,$destination_mailbox,$expunge=false);

$mails_uids_array : The mail(s) numeric uid in an array , it can contain 1 or more valid ids, (*29)

$source_mailbox : The name of the mailbox where the mail is currently located at , example : INBOX , Drafts ..., (*30)

$destination_mailbox : The Name of the new mail box you want to move the mail into , Example : Spam, drafts ...., (*31)

$expunge : Optional boolean which tells the library to perform immediate clean up or deletion of the email at the source mailbox after moving, (*32)

Mark as Mail as seen , answered , deleted , draft or flagged

$setFlag = $imap->setFlag($mails_uids_array,$flag,$mailBoxName);

$mails_uids_array : The mail(s) numeric uid in an array , it can contain 1 or more valid ids, (*33)

$flag: The flag to set to ,valid flags : seen , answered, deleted , draft or flagged, (*34)

$mailBoxName : Mailbox name of the mails you want to set the flags to if not provided , current opened mailbox will be used, (*35)

Search Mail

Search into mailbox using a given criteria , use the getResults() method to retrive the results, (*36)

        $keyword = "hello";

        //body must contain at least one occurrance of the keyword
        $searchCritiria['BODY'] = $keyword;

        //subject too must contain at least one occurrance of the keyword 
        $searchCritiria['SUBJECT'] = $keyword;

        $mailBoxName = "INBOX";

        $searchResults = $imap
            ->search($searchCritiria,$mailBoxName)
            ->limit(20)
            ->getResults();

$keyword The string we want to search for $searchCritiria : The search Criteria which will be used for the search , read more about the criteria here : http://php.net/manual/en/function.imap-search.php, (*37)

$mailBoxName: Optional Mailbox Name where you want to search into , if the mailbox name is omitted , the current opened mailbox will be used, (*38)

The Versions

02/07 2017

dev-master

9999999-dev https://github.com/razzbee/php-libimap

A PHP IMAP library in Pure OOP for ease and simplicity

  Sources   Download

Apache-2.0

The Requires

  • ext-imap *
  • php >=5.4

 

mail php php libimap php imap php-imap php imap library php imap mail imap client

05/09 2016

v1.0.1-alpha

1.0.1.0-alpha https://github.com/razzbee/php-libimap

A PHP IMAP library in Pure OOP for ease and simplicity

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4
  • ext-imap *

 

mail php php libimap php imap php-imap php imap library php imap mail imap client