Zend Framework  1.12
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Zend_Mail_Protocol_Imap Class Reference

Public Member Functions

 __construct ($host= '', $port=null, $ssl=false)
 Public constructor.
 
 __destruct ()
 Public destructor.
 
 connect ($host, $port=null, $ssl=false)
 Open connection to IMAP server.
 
 readLine (&$tokens=array(), $wantedTag= '*', $dontParse=false)
 read a response "line" (could also be more than one real line if response has {..}<NL>) and do a simple decode
 
 readResponse ($tag, $dontParse=false)
 read all lines of response until given tag is found (last line of response)
 
 sendRequest ($command, $tokens=array(), &$tag=null)
 send a request
 
 requestAndResponse ($command, $tokens=array(), $dontParse=false)
 send a request and get response at once
 
 escapeString ($string)
 escape one or more literals i.e.
 
 escapeList ($list)
 escape a list with literals or lists
 
 login ($user, $password)
 Login to IMAP server.
 
 logout ()
 logout of imap server
 
 capability ()
 Get capabilities from IMAP server.
 
 examineOrSelect ($command= 'EXAMINE', $box= 'INBOX')
 Examine and select have the same response.
 
 select ($box= 'INBOX')
 change folder
 
 examine ($box= 'INBOX')
 examine folder
 
 fetch ($items, $from, $to=null)
 fetch one or more items of one or more messages
 
 listMailbox ($reference= '', $mailbox= '*')
 get mailbox list
 
 store (array $flags, $from, $to=null, $mode=null, $silent=true)
 set flags
 
 append ($folder, $message, $flags=null, $date=null)
 append a new message to given folder
 
 copy ($folder, $from, $to=null)
 copy message set from current folder to other folder
 
 create ($folder)
 create a new folder (and parent folders if needed)
 
 rename ($old, $new)
 rename an existing folder
 
 delete ($folder)
 remove a folder
 
 expunge ()
 permanently remove messages
 
 noop ()
 send noop
 
 search (array $params)
 do a search request
 

Public Attributes

const TIMEOUT_CONNECTION = 30
 Default timeout in seconds for initiating session.
 

Protected Member Functions

 _nextLine ()
 get the next line from socket with error checking, but nothing else
 
 _assumedNextLine ($start)
 get next line and assume it starts with $start.
 
 _nextTaggedLine (&$tag)
 get next line and split the tag.
 
 _decodeLine ($line)
 split a given line in tokens.
 

Protected Attributes

 $_socket
 
 $_tagCount = 0
 

Constructor & Destructor Documentation

__construct (   $host = '',
  $port = null,
  $ssl = false 
)

Public constructor.

Parameters
string$hosthostname or IP address of IMAP server, if given connect() is called
int | null$portport of IMAP server, null for default (143 or 993 for ssl)
bool$ssluse ssl? 'SSL', 'TLS' or false
Exceptions
Zend_Mail_Protocol_Exception
__destruct ( )

Public destructor.

Member Function Documentation

_assumedNextLine (   $start)
protected

get next line and assume it starts with $start.

some requests give a simple feedback so we can quickly check if we can go on.

Parameters
string$startthe first bytes we assume to be in the next line
Returns
bool line starts with $start
Exceptions
Zend_Mail_Protocol_Exception
_decodeLine (   $line)
protected

split a given line in tokens.

a token is literal of any form or a list

Parameters
string$lineline to decode
Returns
array tokens, literals are returned as string, lists as array
Exceptions
Zend_Mail_Protocol_Exception
_nextLine ( )
protected

get the next line from socket with error checking, but nothing else

Returns
string next line
Exceptions
Zend_Mail_Protocol_Exception
See Also
Zend_Mail_Protocol_Exception
_nextTaggedLine ( $tag)
protected

get next line and split the tag.

that's the normal case for a response line

Parameters
string$tagtag of line is returned by reference
Returns
string next line
Exceptions
Zend_Mail_Protocol_Exception
append (   $folder,
  $message,
  $flags = null,
  $date = null 
)

append a new message to given folder

Parameters
string$foldername of target folder
string$messagefull message content
array$flagsflags for new message
string$datedate for new message
Returns
bool success
Exceptions
Zend_Mail_Protocol_Exception
capability ( )

Get capabilities from IMAP server.

Returns
array list of capabilities
Exceptions
Zend_Mail_Protocol_Exception
connect (   $host,
  $port = null,
  $ssl = false 
)

Open connection to IMAP server.

Parameters
string$hosthostname or IP address of IMAP server
int | null$portof IMAP server, default is 143 (993 for ssl)
string | bool$ssluse 'SSL', 'TLS' or false
Returns
string welcome message
Exceptions
Zend_Mail_Protocol_Exception
See Also
Zend_Mail_Protocol_Exception
Zend_Mail_Protocol_Exception
Zend_Mail_Protocol_Exception
copy (   $folder,
  $from,
  $to = null 
)

copy message set from current folder to other folder

Parameters
string$folderdestination folder
int | null$toif null only one message ($from) is fetched, else it's the last message, INF means last message avaible
Returns
bool success
Exceptions
Zend_Mail_Protocol_Exception
create (   $folder)

create a new folder (and parent folders if needed)

Parameters
string$folderfolder name
Returns
bool success
delete (   $folder)

remove a folder

Parameters
string$folderfolder name
Returns
bool success
escapeList (   $list)

escape a list with literals or lists

Parameters
array$listlist with literals or lists as PHP array
Returns
string escaped list for imap
escapeString (   $string)

escape one or more literals i.e.

for sendRequest

Parameters
string | array$stringthe literal/-s
Returns
string|array escape literals, literals with newline ar returned as array('{size}', 'string');
examine (   $box = 'INBOX')

examine folder

Parameters
string$boxexamine this folder
Returns
bool|array see examineOrselect()
Exceptions
Zend_Mail_Protocol_Exception
examineOrSelect (   $command = 'EXAMINE',
  $box = 'INBOX' 
)

Examine and select have the same response.

The common code for both is in this method

Parameters
string$commandcan be 'EXAMINE' or 'SELECT' and this is used as command
string$boxwhich folder to change to or examine
Returns
bool|array false if error, array with returned information otherwise (flags, exists, recent, uidvalidity)
Exceptions
Zend_Mail_Protocol_Exception
expunge ( )

permanently remove messages

Returns
bool success
fetch (   $items,
  $from,
  $to = null 
)

fetch one or more items of one or more messages

Parameters
string | array$itemsitems to fetch from message(s) as string (if only one item) or array of strings
int$frommessage for items or start message if $to !== null
int | null$toif null only one message ($from) is fetched, else it's the last message, INF means last message avaible
Returns
string|array if only one item of one message is fetched it's returned as string if items of one message are fetched it's returned as (name => value) if one items of messages are fetched it's returned as (msgno => value) if items of messages are fetchted it's returned as (msgno => (name => value))
Exceptions
Zend_Mail_Protocol_Exception
See Also
Zend_Mail_Protocol_Exception
listMailbox (   $reference = '',
  $mailbox = '*' 
)

get mailbox list

this method can't be named after the IMAP command 'LIST', as list is a reserved keyword

Parameters
string$referencemailbox reference for list
string$mailboxmailbox name match with wildcards
Returns
array mailboxes that matched $mailbox as array(globalName => array('delim' => .., 'flags' => ..))
Exceptions
Zend_Mail_Protocol_Exception
login (   $user,
  $password 
)

Login to IMAP server.

Parameters
string$userusername
string$passwordpassword
Returns
bool success
Exceptions
Zend_Mail_Protocol_Exception
logout ( )

logout of imap server

Returns
bool success
noop ( )

send noop

Returns
bool success
readLine ( $tokens = array(),
  $wantedTag = '*',
  $dontParse = false 
)

read a response "line" (could also be more than one real line if response has {..}<NL>) and do a simple decode

Parameters
array | string$tokensdecoded tokens are returned by reference, if $dontParse is true the unparsed line is returned here
string$wantedTagcheck for this tag for response code. Default '*' is continuation tag.
bool$dontParseif true only the unparsed line is returned $tokens
Returns
bool if returned tag matches wanted tag
Exceptions
Zend_Mail_Protocol_Exception
readResponse (   $tag,
  $dontParse = false 
)

read all lines of response until given tag is found (last line of response)

Parameters
string$tagthe tag of your request
string | array$filteryou can filter the response so you get only the given response lines
bool$dontParseif true every line is returned unparsed instead of the decoded tokens
Returns
null|bool|array tokens if success, false if error, null if bad request
Exceptions
Zend_Mail_Protocol_Exception
rename (   $old,
  $new 
)

rename an existing folder

Parameters
string$oldold name
string$newnew name
Returns
bool success
requestAndResponse (   $command,
  $tokens = array(),
  $dontParse = false 
)

send a request and get response at once

Parameters
string$commandcommand as in sendRequest()
array$tokensparameters as in sendRequest()
bool$dontParseif true unparsed lines are returned instead of tokens
Returns
mixed response as in readResponse()
Exceptions
Zend_Mail_Protocol_Exception
search ( array  $params)

do a search request

This method is currently marked as internal as the API might change and is not safe if you don't take precautions.

select (   $box = 'INBOX')

change folder

Parameters
string$boxchange to this folder
Returns
bool|array see examineOrselect()
Exceptions
Zend_Mail_Protocol_Exception
sendRequest (   $command,
  $tokens = array(),
$tag = null 
)

send a request

Parameters
string$commandyour request command
array$tokensadditional parameters to command, use escapeString() to prepare
string$tagprovide a tag otherwise an autogenerated is returned
Returns
null
Exceptions
Zend_Mail_Protocol_Exception
See Also
Zend_Mail_Protocol_Exception
Zend_Mail_Protocol_Exception
Zend_Mail_Protocol_Exception
store ( array  $flags,
  $from,
  $to = null,
  $mode = null,
  $silent = true 
)

set flags

Parameters
array$flagsflags to set, add or remove - see $mode
int$frommessage for items or start message if $to !== null
int | null$toif null only one message ($from) is fetched, else it's the last message, INF means last message avaible
string | null$mode'+' to add flags, '-' to remove flags, everything else sets the flags as given
bool$silentif false the return values are the new flags for the wanted messages
Returns
bool|array new flags if $silent is false, else true or false depending on success
Exceptions
Zend_Mail_Protocol_Exception

Member Data Documentation

$_socket
protected
$_tagCount = 0
protected
const TIMEOUT_CONNECTION = 30

Default timeout in seconds for initiating session.