ERROR_OK
ERROR_OK = 0
PHP based wrapper class to connect to an IMAP server
connect(string $host, string $user, string $password, array $options = []) : bool
Connects to IMAP server and authenticates.
| string | $host | Server hostname or IP |
| string | $user | User name |
| string | $password | Password |
| array | $options | Connection and class options |
True on success, False on failure
status(string $mailbox, array $items = []) : array
Executes STATUS command
| string | $mailbox | Mailbox name |
| array | $items | Additional requested item names. By default MESSAGES and UNSEEN are requested. Other defined in RFC3501: UIDNEXT, UIDVALIDITY, RECENT |
Status item-value hash
listMailboxes(string $ref, string $mailbox, array $return_opts = [], array $select_opts = []) : array|bool
Returns list of mailboxes
| string | $ref | Reference name |
| string | $mailbox | Mailbox name |
| array | $return_opts | (see self::_listMailboxes) |
| array | $select_opts | (see self::_listMailboxes) |
List of mailboxes or hash of options if STATUS/MYRIGHTS response is requested, False on error.
listSubscribed(string $ref, string $mailbox, array $return_opts = []) : array|bool
Returns list of subscribed mailboxes
| string | $ref | Reference name |
| string | $mailbox | Mailbox name |
| array | $return_opts | (see self::_listMailboxes) |
List of mailboxes or hash of options if STATUS/MYRIGHTS response is requested, False on error.
sort(string $mailbox, string $field = 'ARRIVAL', string $criteria = '', bool $return_uid = false, string $encoding = 'US-ASCII') : \rcube_result_index
Executes SORT command
| string | $mailbox | Mailbox name |
| string | $field | Field to sort by (ARRIVAL, CC, DATE, FROM, SIZE, SUBJECT, TO) |
| string | $criteria | Searching criteria |
| bool | $return_uid | Enables UID SORT usage |
| string | $encoding | Character set |
Response data
thread(string $mailbox, string $algorithm = 'REFERENCES', string $criteria = '', bool $return_uid = false, string $encoding = 'US-ASCII') : \rcube_result_thread
Executes THREAD command
| string | $mailbox | Mailbox name |
| string | $algorithm | Threading algorithm (ORDEREDSUBJECT, REFERENCES, REFS) |
| string | $criteria | Searching criteria |
| bool | $return_uid | Enables UIDs in result instead of sequence numbers |
| string | $encoding | Character set |
Thread data
search(string $mailbox, string $criteria, bool $return_uid = false, array $items = []) : \rcube_result_index
Executes SEARCH command
| string | $mailbox | Mailbox name |
| string | $criteria | Searching criteria |
| bool | $return_uid | Enable UID in result instead of sequence ID |
| array | $items | Return items (MIN, MAX, COUNT, ALL) |
Result data
index(string $mailbox, string|array $message_set, string $index_field = '', bool $skip_deleted = true, bool $uidfetch = false, bool $return_uid = false) : \rcube_result_index
Simulates SORT command by using FETCH and sorting.
| string | $mailbox | Mailbox name |
| string|array | $message_set | Searching criteria (list of messages to return) |
| string | $index_field | Field to sort by (ARRIVAL, CC, DATE, FROM, SIZE, SUBJECT, TO) |
| bool | $skip_deleted | Makes that DELETED messages will be skipped |
| bool | $uidfetch | Enables UID FETCH usage |
| bool | $return_uid | Enables returning UIDs instead of IDs |
Response data
fetchHeaderIndex(string $mailbox, string|array $message_set, string $index_field = '', bool $skip_deleted = true, bool $uidfetch = false, bool $return_uid = false) : array|bool
Fetches specified header/data value for a set of messages.
| string | $mailbox | Mailbox name |
| string|array | $message_set | Searching criteria (list of messages to return) |
| string | $index_field | Field to sort by (ARRIVAL, CC, DATE, FROM, SIZE, SUBJECT, TO) |
| bool | $skip_deleted | Makes that DELETED messages will be skipped |
| bool | $uidfetch | Enables UID FETCH usage |
| bool | $return_uid | Enables returning UIDs instead of IDs |
List of header values or False on failure
fetch(string $mailbox, mixed $message_set, bool $is_uid = false, array $query_items = [], string $mod_seq = null, bool $vanished = false) : array
FETCH command (RFC3501)
| string | $mailbox | Mailbox name |
| mixed | $message_set | Message(s) sequence identifier(s) or UID(s) |
| bool | $is_uid | True if $message_set contains UIDs |
| array | $query_items | FETCH command data items |
| string | $mod_seq | Modification sequence for CHANGEDSINCE (RFC4551) query |
| bool | $vanished | Enables VANISHED parameter (RFC5162) for CHANGEDSINCE query |
List of rcube_message_header elements, False on error
fetchHeaders(string $mailbox, mixed $message_set, bool $is_uid = false, bool $bodystr = false, array $add_headers = []) : bool|array
Returns message(s) data (flags, headers, etc.)
| string | $mailbox | Mailbox name |
| mixed | $message_set | Message(s) sequence identifier(s) or UID(s) |
| bool | $is_uid | True if $message_set contains UIDs |
| bool | $bodystr | Enable to add BODYSTRUCTURE data to the result |
| array | $add_headers | List of additional headers |
List of rcube_message_header elements, False on error
fetchHeader(string $mailbox, int $id, bool $is_uid = false, bool $bodystr = false, array $add_headers = []) : bool|\rcube_message_header
Returns message data (flags, headers, etc.)
| string | $mailbox | Mailbox name |
| int | $id | Message sequence identifier or UID |
| bool | $is_uid | True if $id is an UID |
| bool | $bodystr | Enable to add BODYSTRUCTURE data to the result |
| array | $add_headers | List of additional headers |
Message data, False on error
sortHeaders(array $messages, string $field, string $order = 'ASC') : array
Sort messages by specified header field
| array | $messages | Array of rcube_message_header objects |
| string | $field | Name of the property to sort by |
| string | $order | Sorting order (ASC|DESC) |
Sorted input array
fetchMIMEHeaders(string $mailbox, int $uid, array $parts, bool $mime = true) : array|bool
Fetch MIME headers of specified message parts
| string | $mailbox | Mailbox name |
| int | $uid | Message UID |
| array | $parts | Message part identifiers |
| bool | $mime | Use MIME instead of HEADER |
Array containing headers string for each specified body False on failure.
handlePartBody(mixed $mailbox, mixed $id, mixed $is_uid = false, mixed $part = '', mixed $encoding = null, mixed $print = null, mixed $file = null, mixed $formatted = false, mixed $max_bytes) : mixed
Fetches body of the specified message part
| mixed | $mailbox | |
| mixed | $id | |
| mixed | $is_uid | |
| mixed | $part | |
| mixed | $encoding | |
| mixed | ||
| mixed | $file | |
| mixed | $formatted | |
| mixed | $max_bytes |
append(string $mailbox, string|array $message, array $flags = [], string $date = null, bool $binary = false) : string|bool
Handler for IMAP APPEND command
| string | $mailbox | Mailbox name |
| string|array | $message | The message source string or array (of strings and file pointers) |
| array | $flags | Message flags |
| string | $date | Message internal date |
| bool | $binary | Enable BINARY append (RFC3516) |
On success APPENDUID response (if available) or True, False on failure
appendFromFile(string $mailbox, string $path, string $headers = null, array $flags = [], string $date = null, bool $binary = false) : string|bool
Handler for IMAP APPEND command.
| string | $mailbox | Mailbox name |
| string | $path | Path to the file with message body |
| string | $headers | Message headers |
| array | $flags | Message flags |
| string | $date | Message internal date |
| bool | $binary | Enable BINARY append (RFC3516) |
On success APPENDUID response (if available) or True, False on failure
getMetadata(string $mailbox, array $entries, array $options = []) : array
Send the GETMETADATA command (RFC5464)
| string | $mailbox | Mailbox name |
| array | $entries | Entries |
| array | $options | Command options (with MAXSIZE and DEPTH keys) |
GETMETADATA result on success, NULL on error
setAnnotation(string $mailbox, array $data) : bool
Send the SETANNOTATION command (draft-daboo-imap-annotatemore)
| string | $mailbox | Mailbox name |
| array | $data | Data array where each item is an array with three elements: entry name, attribute name, value |
True on success, False on failure
deleteAnnotation(string $mailbox, array $data) : bool
Send the SETANNOTATION command with NIL values (draft-daboo-imap-annotatemore)
| string | $mailbox | Mailbox name |
| array | $data | Data array where each item is an array with two elements: entry name and attribute name |
True on success, False on failure
getAnnotation(string $mailbox, array $entries, array $attribs) : array
Send the GETANNOTATION command (draft-daboo-imap-annotatemore)
| string | $mailbox | Mailbox name |
| array | $entries | Entries names |
| array | $attribs | Attribs names |
Annotations result on success, NULL on error
getStructure(string $mailbox, int $id, bool $is_uid = false) : array|bool
Returns BODYSTRUCTURE for the specified message.
| string | $mailbox | Folder name |
| int | $id | Message sequence number or UID |
| bool | $is_uid | True if $id is an UID |
Body structure array or False on error.
getStructurePartData(array $structure, string $part) : array
Returns data of a message part according to specified structure.
| array | $structure | Message structure (getStructure() result) |
| string | $part | Message part identifier |
Part data as hash array (type, encoding, charset, size)
execute(string $command, array $arguments = [], int $options, string $filter = null) : mixed
Sends IMAP command and parses result
| string | $command | IMAP command |
| array | $arguments | Command arguments |
| int | $options | Execution options |
| string | $filter | Line filter (regexp) |
Response code or list of response code and data
putLine(string $string, bool $endln = true, bool $anonymized = false) : int
Send simple (one line) command to the connection stream
| string | $string | Command string |
| bool | $endln | True if CRLF need to be added at the end of command |
| bool | $anonymized | Don't write the given data to log but a placeholder |
Number of bytes sent, False on error
putLineC(string $string, bool $endln = true, bool $anonymized = false) : int|bool
Send command to the connection stream with Command Continuation Requests (RFC3501 7.5) and LITERAL+ (RFC2088) and LITERAL- (RFC7888) support.
| string | $string | Command string |
| bool | $endln | True if CRLF need to be added at the end of command |
| bool | $anonymized | Don't write the given data to log but a placeholder |
Number of bytes sent, False on error
startsWith(string $string, string $match, bool $error = false, bool $nonempty = false) : bool
Checks response status.
Checks if command response line starts with specified prefix (or * BYE/BAD)
| string | $string | Response text |
| string | $match | Prefix to match with (case-sensitive) |
| bool | $error | Enables BYE/BAD checking |
| bool | $nonempty | Enables empty response checking |
True any check is true or connection is closed.
authenticate(string $user, string $pass, string $type = 'PLAIN') : resource|int
DIGEST-MD5/CRAM-MD5/PLAIN Authentication
| string | $user | Username |
| string | $pass | Password |
| string | $type | Authentication type (PLAIN/CRAM-MD5/DIGEST-MD5) |
Connection resource on success, error code on error
_listMailboxes(string $ref, string $mailbox, bool $subscribed = false, array $return_opts = [], array $select_opts = []) : array|bool
IMAP LIST/LSUB command
| string | $ref | Reference name |
| string | $mailbox | Mailbox name |
| bool | $subscribed | Enables returning subscribed mailboxes only |
| array | $return_opts | List of RETURN options (RFC5819: LIST-STATUS, RFC5258: LIST-EXTENDED) Possible: MESSAGES, RECENT, UIDNEXT, UIDVALIDITY, UNSEEN, MYRIGHTS, SUBSCRIBED, CHILDREN |
| array | $select_opts | List of selection options (RFC5258: LIST-EXTENDED) Possible: SUBSCRIBED, RECURSIVEMATCH, REMOTE, SPECIAL-USE (RFC6154) |
List of mailboxes or hash of options if STATUS/MYRIGHTS response is requested, False on error.
modFlag(string $mailbox, string|array $messages, string $flag, string $mod = '+') : bool
Changes flag of the message(s)
| string | $mailbox | Mailbox name |
| string|array | $messages | Message UID(s) |
| string | $flag | Flag name |
| string | $mod | Modifier [+|-]. Default: "+". |
True on success, False on failure
decodeContent(string $chunk, int $mode, bool $is_last = false, string $prev = '') : string
Decodes a chunk of a message part content from a FETCH response.
| string | $chunk | Content |
| int | $mode | Encoding mode |
| bool | $is_last | Whether it is a last chunk of data |
| string | $prev | Extra content from the previous chunk |
Encoded string