class ImapConnection implements ConnectionInterface (View source)

Properties

protected int $sequence

Sequence number used to generate unique command tags.

protected Result|null $result

The result instance.

protected ImapParser|null $parser

The parser instance.

Methods

__construct(StreamInterface $stream, LoggerInterface|null $logger = null)

Constructor.

static ImapConnection
fake(array $responses = [])

Create a new connection with a fake stream.

__destruct()

Tear down the connection.

void
connect(string $host, int|null $port = null, array $options = [])

Open a new connection.

array
getDefaultSocketOptions(string $transport, array $proxy = [], bool $validateCert = true)

Get the default socket options for the given transport.

void
disconnect()

Close the current connection.

bool
connected()

Determine if the current session is connected.

login(string $user, string $password)

Send a "LOGIN" command.

void
logout()

Send a "LOGOUT" command.

authenticate(string $user, string $token)

Send an "AUTHENTICATE" command.

void
startTls()

Send a "STARTTLS" command.

select(string $folder = 'INBOX')

Send a "SELECT" command.

examine(string $folder = 'INBOX')

Send a "EXAMINE" command.

examineOrSelect(string $command = 'EXAMINE', string $folder = 'INBOX')

Examine and select have the same response.

status(string $folder = 'INBOX', array $arguments = ['MESSAGES', 'UNSEEN', 'RECENT', 'UIDNEXT', 'UIDVALIDITY'])

Send a "STATUS" command.

create(string $folder)

Send a "CREATE" command.

delete(string $folder)

Send a "DELETE" command.

rename(string $oldPath, string $newPath)

Send a "RENAME" command.

subscribe(string $folder)

Send a "SUBSCRIBE" command.

unsubscribe(string $folder)

Send a "UNSUBSCRIBE" command.

quota(string $root)

Send a "GETQUOTA" command.

quotaRoot(string $mailbox)

Send a "GETQUOTAROOT" command.

list(string $reference = '', string $folder = '*')

Send a "LIST" command.

append(string $folder, string $message, array|null $flags = null)

Send a "APPEND" command.

copy(string $folder, array|int $from, int|null $to = null)

Send a "UID COPY" command.

move(string $folder, array|int $from, int|null $to = null)

Send a "UID MOVE" command.

store(array|string $flags, array|int $from, int|null $to = null, string|null $mode = null, bool $silent = true, string|null $item = null)

Send a "STORE" command.

uid(int|array $ids, ImapFetchIdentifier $identifier)

Send a "FETCH UID" command.

bodyText(int|array $ids, bool $peek = true)

Send a "FETCH BODY[TEXT]" command.

bodyHeader(int|array $ids, bool $peek = true)

Send a "FETCH BODY[HEADER]" command.

bodyStructure(int|array $ids)

Fetch the BODYSTRUCTURE for the given message(s).

bodyPart(string $partIndex, int|array $ids, bool $peek = false)

Fetch a specific part of the message BODY, such as BODY[1], BODY[1.2], etc.

flags(int|array $ids)

Send a "FETCH FLAGS" command.

size(int|array $ids)

Send a "RFC822.SIZE" command.

search(array $params)

Send a "SEARCH" command.

capability()

Send a "CAPABILITY" command.

id(array|null $ids = null)

Send a "FETCH" command.

expunge()

Send a "EXPUNGE" command.

noop()

Send a "NOOP" command.

idle(int $timeout)

Send an "IDLE" command.

void
done()

Send a "DONE" command.

void
send(string $name, array $tokens = [], string|null $tag = null)

Send an IMAP command.

void
write(string $data)

Write data to the connected stream.

fetch(array|string $items, array|int $from, mixed $to = null, ImapFetchIdentifier $identifier = ImapFetchIdentifier::Uid)

Fetch one or more items for one or more messages.

void
setResult(Result $result)

Set the current result instance.

void
setParser(ImapParser $parser)

Set the current parser instance.

newParser(StreamInterface $stream)

Create a new parser instance.

newTokenizer(StreamInterface $stream)

Create a new tokenizer instance.

assertTaggedResponse(string $tag, callable|null $exception = null)

Assert the next response is a successful tagged response.

assertNextResponse(callable $filter, callable $assertion, callable $exception)

Assert the next response matches the given filter and assertion.

Response|null
nextResponse(callable $filter)

Returns the next response matching the given filter.

nextReply()

Read the next reply from the stream.

Details

__construct(StreamInterface $stream, LoggerInterface|null $logger = null)

Constructor.

Parameters

StreamInterface $stream
LoggerInterface|null $logger

static ImapConnection fake(array $responses = [])

Create a new connection with a fake stream.

Parameters

array $responses

Return Value

ImapConnection

__destruct()

Tear down the connection.

void connect(string $host, int|null $port = null, array $options = [])

Open a new connection.

Parameters

string $host
int|null $port
array $options

Return Value

void

protected array getDefaultSocketOptions(string $transport, array $proxy = [], bool $validateCert = true)

Get the default socket options for the given transport.

Parameters

string $transport
array $proxy
bool $validateCert

Return Value

array

void disconnect()

Close the current connection.

Return Value

void

bool connected()

Determine if the current session is connected.

Return Value

bool

TaggedResponse login(string $user, string $password)

Send a "LOGIN" command.

Login to a new session.

Parameters

string $user
string $password

Return Value

TaggedResponse

void logout()

Send a "LOGOUT" command.

Logout of the current server session.

Return Value

void

TaggedResponse authenticate(string $user, string $token)

Send an "AUTHENTICATE" command.

Authenticate the current session.

Parameters

string $user
string $token

Return Value

TaggedResponse

void startTls()

Send a "STARTTLS" command.

Upgrade the current plaintext connection to a secure TLS-encrypted connection.

Return Value

void

ResponseCollection select(string $folder = 'INBOX')

Send a "SELECT" command.

Select the specified folder.

Parameters

string $folder

Return Value

ResponseCollection

ResponseCollection examine(string $folder = 'INBOX')

Send a "EXAMINE" command.

Examine a given folder.

Parameters

string $folder

Return Value

ResponseCollection

protected ResponseCollection examineOrSelect(string $command = 'EXAMINE', string $folder = 'INBOX')

Examine and select have the same response.

Parameters

string $command
string $folder

Return Value

ResponseCollection

UntaggedResponse status(string $folder = 'INBOX', array $arguments = ['MESSAGES', 'UNSEEN', 'RECENT', 'UIDNEXT', 'UIDVALIDITY'])

Send a "STATUS" command.

Get the status of a given folder.

Parameters

string $folder
array $arguments

Return Value

UntaggedResponse

ResponseCollection create(string $folder)

Send a "CREATE" command.

Create a new folder.

Parameters

string $folder

Return Value

ResponseCollection

TaggedResponse delete(string $folder)

Send a "DELETE" command.

Delete a folder.

Parameters

string $folder

Return Value

TaggedResponse

TaggedResponse rename(string $oldPath, string $newPath)

Send a "RENAME" command.

Rename an existing folder.

Parameters

string $oldPath
string $newPath

Return Value

TaggedResponse

TaggedResponse subscribe(string $folder)

Send a "SUBSCRIBE" command.

Subscribe to a folder.

Parameters

string $folder

Return Value

TaggedResponse

TaggedResponse unsubscribe(string $folder)

Send a "UNSUBSCRIBE" command.

Unsubscribe from a folder.

Parameters

string $folder

Return Value

TaggedResponse

UntaggedResponse quota(string $root)

Send a "GETQUOTA" command.

Retrieve quota information about a specific quota root.

Parameters

string $root

Return Value

UntaggedResponse

ResponseCollection quotaRoot(string $mailbox)

Send a "GETQUOTAROOT" command.

Retrieve quota root information about a mailbox.

Parameters

string $mailbox

Return Value

ResponseCollection

ResponseCollection list(string $reference = '', string $folder = '*')

Send a "LIST" command.

Get a list of available folders.

Parameters

string $reference
string $folder

Return Value

ResponseCollection

TaggedResponse append(string $folder, string $message, array|null $flags = null)

Send a "APPEND" command.

Append a new message to given folder.

Parameters

string $folder
string $message
array|null $flags

Return Value

TaggedResponse

TaggedResponse copy(string $folder, array|int $from, int|null $to = null)

Send a "UID COPY" command.

Copy message set from current folder to other folder.

Parameters

string $folder
array|int $from
int|null $to

Return Value

TaggedResponse

TaggedResponse move(string $folder, array|int $from, int|null $to = null)

Send a "UID MOVE" command.

Move a message set from current folder to another folder.

Parameters

string $folder
array|int $from
int|null $to

Return Value

TaggedResponse

ResponseCollection store(array|string $flags, array|int $from, int|null $to = null, string|null $mode = null, bool $silent = true, string|null $item = null)

Send a "STORE" command.

Set message flags.

Parameters

array|string $flags
array|int $from
int|null $to
string|null $mode
bool $silent
string|null $item

Return Value

ResponseCollection

ResponseCollection uid(int|array $ids, ImapFetchIdentifier $identifier)

Send a "FETCH UID" command.

Fetch message UIDs using the given message numbers.

Parameters

int|array $ids
ImapFetchIdentifier $identifier

Return Value

ResponseCollection

ResponseCollection bodyText(int|array $ids, bool $peek = true)

Send a "FETCH BODY[TEXT]" command.

Fetch message text contents.

Parameters

int|array $ids
bool $peek

Return Value

ResponseCollection

ResponseCollection bodyHeader(int|array $ids, bool $peek = true)

Send a "FETCH BODY[HEADER]" command.

Fetch message headers.

Parameters

int|array $ids
bool $peek

Return Value

ResponseCollection

ResponseCollection bodyStructure(int|array $ids)

Fetch the BODYSTRUCTURE for the given message(s).

Parameters

int|array $ids

Return Value

ResponseCollection

ResponseCollection bodyPart(string $partIndex, int|array $ids, bool $peek = false)

Fetch a specific part of the message BODY, such as BODY[1], BODY[1.2], etc.

Parameters

string $partIndex
int|array $ids
bool $peek

Return Value

ResponseCollection

ResponseCollection flags(int|array $ids)

Send a "FETCH FLAGS" command.

Fetch a message flags.

Parameters

int|array $ids

Return Value

ResponseCollection

ResponseCollection size(int|array $ids)

Send a "RFC822.SIZE" command.

Fetch message sizes for one or more messages.

Parameters

int|array $ids

Return Value

ResponseCollection

Send a "SEARCH" command.

Execute a search request.

Parameters

array $params

Return Value

UntaggedResponse

UntaggedResponse capability()

Send a "CAPABILITY" command.

Get the mailbox's available capabilities.

Return Value

UntaggedResponse

UntaggedResponse id(array|null $ids = null)

Send a "FETCH" command.

Exchange identification information.

Parameters

array|null $ids

Return Value

UntaggedResponse

ResponseCollection expunge()

Send a "EXPUNGE" command.

Apply session saved changes to the server.

Return Value

ResponseCollection

TaggedResponse noop()

Send a "NOOP" command.

Return Value

TaggedResponse

Generator idle(int $timeout)

Send an "IDLE" command.

Parameters

int $timeout

Return Value

Generator

void done()

Send a "DONE" command.

Return Value

void

void send(string $name, array $tokens = [], string|null $tag = null)

Send an IMAP command.

Parameters

string $name
array $tokens
string|null $tag

Return Value

void

protected void write(string $data)

Write data to the connected stream.

Parameters

string $data

Return Value

void

ResponseCollection fetch(array|string $items, array|int $from, mixed $to = null, ImapFetchIdentifier $identifier = ImapFetchIdentifier::Uid)

Fetch one or more items for one or more messages.

Parameters

array|string $items
array|int $from
mixed $to
ImapFetchIdentifier $identifier

Return Value

ResponseCollection

protected void setResult(Result $result)

Set the current result instance.

Parameters

Result $result

Return Value

void

protected void setParser(ImapParser $parser)

Set the current parser instance.

Parameters

ImapParser $parser

Return Value

void

protected ImapParser newParser(StreamInterface $stream)

Create a new parser instance.

Parameters

StreamInterface $stream

Return Value

ImapParser

protected ImapTokenizer newTokenizer(StreamInterface $stream)

Create a new tokenizer instance.

Parameters

StreamInterface $stream

Return Value

ImapTokenizer

protected TaggedResponse assertTaggedResponse(string $tag, callable|null $exception = null)

Assert the next response is a successful tagged response.

Parameters

string $tag
callable|null $exception

Return Value

TaggedResponse

protected Response assertNextResponse(callable $filter, callable $assertion, callable $exception)

Assert the next response matches the given filter and assertion.

Parameters

callable $filter
callable $assertion
callable $exception

Return Value

Response

Exceptions

ImapResponseException

protected Response|null nextResponse(callable $filter)

Returns the next response matching the given filter.

Parameters

callable $filter

Return Value

Response|null

protected Data|Token|Response|null nextReply()

Read the next reply from the stream.

Return Value

Data|Token|Response|null