Mail/Protocol/Imap.php
Zend Framework
LICENSE
This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to [email protected] so we can send you a copy immediately.
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Package
- Zend_Mail
- Subpackage
- Protocol
- Version
- $Id: Imap.php 24593 2012-01-05 20:35:02Z matthew $
\Zend_Mail_Protocol_Imap
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
Constants
Properties
Methods


__construct(string $host = '', int | null $port = null, bool $ssl = false) : void
Public constructor
Name | Type | Description |
---|---|---|
$host | string | hostname or IP address of IMAP server, if given connect() is called |
$port | int | null | port of IMAP server, null for default (143 or 993 for ssl) |
$ssl | bool | use ssl? 'SSL', 'TLS' or false |
Exception | Description |
---|---|
\Zend_Mail_Protocol_Exception |


_assumedNextLine(string $start) : bool
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.
Name | Type | Description |
---|---|---|
$start | string | the first bytes we assume to be in the next line |
Type | Description |
---|---|
bool | line starts with $start |
Exception | Description |
---|---|
\Zend_Mail_Protocol_Exception |


_decodeLine(string $line) : array
split a given line in tokens.
a token is literal of any form or a list
Name | Type | Description |
---|---|---|
$line | string | line to decode |
Type | Description |
---|---|
array | tokens, literals are returned as string, lists as array |
Exception | Description |
---|---|
\Zend_Mail_Protocol_Exception |


_nextLine() : string
get the next line from socket with error checking, but nothing else
Type | Description |
---|---|
string | next line |
Exception | Description |
---|---|
\Zend_Mail_Protocol_Exception |


_nextTaggedLine(string $tag) : string
get next line and split the tag.
that's the normal case for a response line
Name | Type | Description |
---|---|---|
$tag | string | tag of line is returned by reference |
Type | Description |
---|---|
string | next line |
Exception | Description |
---|---|
\Zend_Mail_Protocol_Exception |


append(string $folder, string $message, array $flags = null, string $date = null) : bool
append a new message to given folder
Name | Type | Description |
---|---|---|
$folder | string | name of target folder |
$message | string | full message content |
$flags | array | flags for new message |
$date | string | date for new message |
Type | Description |
---|---|
bool | success |
Exception | Description |
---|---|
\Zend_Mail_Protocol_Exception |


capability() : array
Get capabilities from IMAP server
Type | Description |
---|---|
array | list of capabilities |
Exception | Description |
---|---|
\Zend_Mail_Protocol_Exception |


connect(string $host, int | null $port = null, string | bool $ssl = false) : string
Open connection to IMAP server
Name | Type | Description |
---|---|---|
$host | string | hostname or IP address of IMAP server |
$port | int | null | of IMAP server, default is 143 (993 for ssl) |
$ssl | string | bool | use 'SSL', 'TLS' or false |
Type | Description |
---|---|
string | welcome message |
Exception | Description |
---|---|
\Zend_Mail_Protocol_Exception |


copy(string $folder, $from, int | null $to = null) : bool
copy message set from current folder to other folder
Name | Type | Description |
---|---|---|
$folder | string | destination folder |
$from | ||
$to | int | null | if null only one message ($from) is fetched, else it's the last message, INF means last message avaible |
Type | Description |
---|---|
bool | success |
Exception | Description |
---|---|
\Zend_Mail_Protocol_Exception |


create(string $folder) : bool
create a new folder (and parent folders if needed)
Name | Type | Description |
---|---|---|
$folder | string | folder name |
Type | Description |
---|---|
bool | success |


delete(string $folder) : bool
remove a folder
Name | Type | Description |
---|---|---|
$folder | string | folder name |
Type | Description |
---|---|
bool | success |


escapeList(array $list) : string
escape a list with literals or lists
Name | Type | Description |
---|---|---|
$list | array | list with literals or lists as PHP array |
Type | Description |
---|---|
string | escaped list for imap |


escapeString(string | array $string) : string | array
escape one or more literals i.e.
for sendRequest
Name | Type | Description |
---|---|---|
$string | string | array | the literal/-s |
Type | Description |
---|---|
string | array | escape literals, literals with newline ar returned as array('{size}', 'string'); |


examine(string $box = 'INBOX') : bool | array
examine folder
Name | Type | Description |
---|---|---|
$box | string | examine this folder |
Type | Description |
---|---|
bool | array | see examineOrselect() |
Exception | Description |
---|---|
\Zend_Mail_Protocol_Exception |


examineOrSelect(string $command = 'EXAMINE', string $box = 'INBOX') : bool | array
Examine and select have the same response.
The common code for both is in this method
Name | Type | Description |
---|---|---|
$command | string | can be 'EXAMINE' or 'SELECT' and this is used as command |
$box | string | which folder to change to or examine |
Type | Description |
---|---|
bool | array | false if error, array with returned information otherwise (flags, exists, recent, uidvalidity) |
Exception | Description |
---|---|
\Zend_Mail_Protocol_Exception |


fetch(string | array $items, int $from, int | null $to = null) : string | array
fetch one or more items of one or more messages
Name | Type | Description |
---|---|---|
$items | string | array | items to fetch from message(s) as string (if only one item) or array of strings |
$from | int | message for items or start message if $to !== null |
$to | int | null | if null only one message ($from) is fetched, else it's the last message, INF means last message avaible |
Type | Description |
---|---|
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)) |
Exception | Description |
---|---|
\Zend_Mail_Protocol_Exception |


listMailbox(string $reference = '', string $mailbox = '*') : array
get mailbox list
this method can't be named after the IMAP command 'LIST', as list is a reserved keyword
Name | Type | Description |
---|---|---|
$reference | string | mailbox reference for list |
$mailbox | string | mailbox name match with wildcards |
Type | Description |
---|---|
array | mailboxes that matched $mailbox as array(globalName => array('delim' => .., 'flags' => ..)) |
Exception | Description |
---|---|
\Zend_Mail_Protocol_Exception |


login(string $user, string $password) : bool
Login to IMAP server.
Name | Type | Description |
---|---|---|
$user | string | username |
$password | string | password |
Type | Description |
---|---|
bool | success |
Exception | Description |
---|---|
\Zend_Mail_Protocol_Exception |


readLine(array | string $tokens = array(), string $wantedTag = '*', bool $dontParse = false) : bool
read a response "line" (could also be more than one real line if response has {.
.}
Name | Type | Description |
---|---|---|
$tokens | array | string | decoded tokens are returned by reference, if $dontParse is true the unparsed line is returned here |
$wantedTag | string | check for this tag for response code. Default '*' is continuation tag. |
$dontParse | bool | if true only the unparsed line is returned $tokens |
Type | Description |
---|---|
bool | if returned tag matches wanted tag |
Exception | Description |
---|---|
\Zend_Mail_Protocol_Exception |


readResponse(string $tag, bool $dontParse = false) : null | bool | array
read all lines of response until given tag is found (last line of response)
Name | Type | Description |
---|---|---|
$tag | string | the tag of your request |
$dontParse | bool | if true every line is returned unparsed instead of the decoded tokens |
Type | Description |
---|---|
null | bool | array | tokens if success, false if error, null if bad request |
Exception | Description |
---|---|
\Zend_Mail_Protocol_Exception |


rename(string $old, string $new) : bool
rename an existing folder
Name | Type | Description |
---|---|---|
$old | string | old name |
$new | string | new name |
Type | Description |
---|---|
bool | success |


requestAndResponse(string $command, array $tokens = array(), bool $dontParse = false) : mixed
send a request and get response at once
Name | Type | Description |
---|---|---|
$command | string | command as in sendRequest() |
$tokens | array | parameters as in sendRequest() |
$dontParse | bool | if true unparsed lines are returned instead of tokens |
Type | Description |
---|---|
mixed | response as in readResponse() |
Exception | Description |
---|---|
\Zend_Mail_Protocol_Exception |


select(string $box = 'INBOX') : bool | array
change folder
Name | Type | Description |
---|---|---|
$box | string | change to this folder |
Type | Description |
---|---|
bool | array | see examineOrselect() |
Exception | Description |
---|---|
\Zend_Mail_Protocol_Exception |


sendRequest(string $command, array $tokens = array(), string $tag = null) : null
send a request
Name | Type | Description |
---|---|---|
$command | string | your request command |
$tokens | array | additional parameters to command, use escapeString() to prepare |
$tag | string | provide a tag otherwise an autogenerated is returned |
Type | Description |
---|---|
null |
Exception | Description |
---|---|
\Zend_Mail_Protocol_Exception |


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