Imap class that connects to the mailbox and retrieves messages

Use this class to initiate a connection and then retrieve the data needed. Messages can be retrieved based on flags, limits, offsets, and sorted. Not all data is instantly downloaded, just the basic information to speed up usage where needed.

category Email
package Imap
author Tim Withers
copyright 2012 Tim Withers
license PHP License 3.01
version 1.0

 Methods

Opens a connection to an IMAP mailbox

__construct(array $params) 

Params are passed as an array when calling. Possible $params keys are: 'host' 'port' 'ssl' 'folder' 'username' 'password' 'options'

A parameter key not set will use the defaults from the class properties.

Parameters

$params

array

Closes the connection and purges/expunges deleted messages if set

__destruct() 

Base magic method get

__get(string $name) : resource
Inherited

Only function is to return the resource connection when requested rather than using the getConnection() function;

inherited_from \Imap_Base::__get()

Parameters

$name

string

Returns

resourceConnection resource. FALSE if $name!='connection'

Checks if variable is set in the class

__isset(string $name) : bool

Parameters

$name

string

Returns

bool

Sets a variable to a value in the class

__set(string $name, string $value) 

Parameters

$name

string

$value

string

Retrieves all messages based on filter set

get() : array

Returns

arrayMessages are Imap_Messages

Gets a literal version of the content type

getAttachmentType(int $type, string $subtype) : string
Inherited

Some examples would be: 'application/pdf' 'image/png' 'application/octet-stream'

inherited_from \Imap_Base::getAttachmentType()

Parameters

$type

int

Integer representing 1 of 8 main types

$subtype

string

Specified subtype

Returns

string

Sets the limit you want.

limit(int $start, int $count) : \Imap

Emails start with 1, not 0.

Parameters

$start

int

$count

int

If not set, will return everything after initial email

Returns

\ImapFor method chaining

Indicates where to purge deleted items on __destruct()

purgeOnExit(bool $bool) 

Parameters

$bool

bool

Default is true

Sets sort by filter.

sort(string $field, string $dir) : \Imap

Sortable fields are listed in possibleSort().

see \global\Imap::possibleSort()

Parameters

$field

string

$dir

string

Like MySQL ('ASC', 'DESC')

Returns

\ImapFor method chaining

Sets filter to only pull unread messages

unread() : \Imap

Returns

\ImapFor method chaining

Sets search criteria.

where(\type $array) : \Imap

Searchable fields are listed in possibleCriteria(). Array must be structured as below: where(array('subject'=>'My subject*'))

see \global\Imap::possibleCriteria()
link 6.4.4 deals with searching

Parameters

$array

\type

Returns

\ImapFor method chaining

Decodes a string based on encoding types.

decode(string $string, int $type) : string
Inherited

Types are declared in numeric format in the headers of each part. Each part has to be decoded for readability.

inherited_from \Imap_Base::decode()

Parameters

$string

string

To be decoded

$type

int

Returns

string

Called from get() and does a search based on criteria, no sorting needed

doSearch() : array

Returns

array$results Array of message ids

Called from get().

doSort() : array

Does sort and search based on criteria in filter

Returns

array$results Array of message ids

Returns static connection resource

getConnection() : resource
Inherited

Since connection is static, all subclasses do not need to reconnect and there is no need to pass the resource into the child classes from the main Imap class

inherited_from \Imap_Base::getConnection()

Returns

resourceConnection

Creates a criteria string for searching through messages

getCriteria() 

Data is from the filter array and can be set using functions or manually

Returns a spliced array based on the limits set

getLimited(array $results) : array

Parameters

$results

array

Array of message ids

Returns

array$results Array of message ids

Returns array of valid criteria for searching

possibleCriteria() : array

Returns

array

Returns array of valid reverse sort commands

possibleReverseSort() : array

Returns

array

Returns array of valid criteria for sorting

possibleSort() : array

Returns

array

Sets the connection property

setConnection(resource $con) 
Inherited
inherited_from \Imap_Base::setConnection()

Parameters

$con

resource

 Properties

 

$filter : array

Set to defaults upon __construct()

Holds the variables needed to filter through a result set and return the desired types of messages and in a particular order.

 

$info : \StdClass

Mailbox info contains information on the number of messages in the folder and the number of unread messages, etc.

 

$mail : array
 

$purge : bool
 

$connection 
Inherited

This is set from the Imap class

static Connection to Imap server
inherited_from \Imap_Base::$$connection
 

$folder : string

Set in __construct()

 

$host : string

Set in __construct()

 

$options : int

Set in __construct()

 

$password : string

Set in __construct()

 

$port : int

Set in __construct()

 

$protocol : \type

Set in __construct()

 

$ssl : bool

Set in __construct()

 

$username : string

Set in __construct()