Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

Copyright 2005-2017 Horde LLC (http://www.horde.org/) See the enclosed file LICENSE for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.

Copyright: 1999-2007 The SquirrelMail Project Team
Copyright: 2005-2017 Horde LLC
License: http://www.horde.org/licenses/lgpl21 LGPL 2.1
File Size: 5166 lines (185 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Horde_Imap_Client_Socket:: (89 methods):
  __construct()
  __get()
  getParam()
  update()
  _initCapability()
  _parseCapability()
  _noop()
  _getNamespaces()
  _parseNamespace()
  _login()
  _connect()
  _tryLogin()
  _authInitialResponse()
  _loginTasks()
  _logout()
  _sendID()
  _parseID()
  _getID()
  _setLanguage()
  _getLanguage()
  _parseLanguage()
  _enable()
  _parseEnabled()
  _openMailbox()
  _createMailbox()
  _deleteMailbox()
  _renameMailbox()
  _subscribeMailbox()
  _listMailboxes()
  _getMailboxList()
  _parseList()
  _status()
  _parseStatus()
  _prepareStatusResponse()
  _append()
  _appendData()
  _convertCatenateUrl()
  _check()
  _close()
  _expunge()
  _parseVanished()
  _search()
  _parseSearch()
  _parseEsearch()
  _setComparator()
  _getComparator()
  _parseComparator()
  _thread()
  _parseThread()
  _parseThreadLevel()
  _fetch()
  _fetchCmd()
  _partialAtom()
  _parseFetch()
  _parseBodystructure()
  _parseStructureParams()
  _parseEnvelope()
  _vanished()
  _store()
  _storeCmd()
  _copy()
  _setQuota()
  _getQuota()
  _parseQuota()
  _getQuotaRoot()
  _setACL()
  _deleteACL()
  _getACL()
  _parseACL()
  _listACLRights()
  _parseListRights()
  _getMyACLRights()
  _parseMyRights()
  _getMetadata()
  _getAnnotateMoreEntry()
  _setMetadata()
  _parseAnnotation()
  _parseMetadata()
  _deleteMsgs()
  _getMboxFormatOb()
  _sendCmd()
  _sendCmdChunk()
  _processCmd()
  _processCmdContinuation()
  _command()
  _pipeline()
  _getLine()
  _serverResponse()
  _responseCode()


Class: Horde_Imap_Client_Socket  - X-Ref

An interface to an IMAP4rev1 server (RFC 3501) using standard PHP code.

Implements the following IMAP-related RFCs (see
http://www.iana.org/assignments/imap4-capabilities):
<pre>
- RFC 2086/4314: ACL
- RFC 2087: QUOTA
- RFC 2088: LITERAL+
- RFC 2195: AUTH=CRAM-MD5
- RFC 2221: LOGIN-REFERRALS
- RFC 2342: NAMESPACE
- RFC 2595/4616: TLS & AUTH=PLAIN
- RFC 2831: DIGEST-MD5 authentication mechanism (obsoleted by RFC 6331)
- RFC 2971: ID
- RFC 3348: CHILDREN
- RFC 3501: IMAP4rev1 specification
- RFC 3502: MULTIAPPEND
- RFC 3516: BINARY
- RFC 3691: UNSELECT
- RFC 4315: UIDPLUS
- RFC 4422: SASL Authentication (for DIGEST-MD5)
- RFC 4466: Collected extensions (updates RFCs 2088, 3501, 3502, 3516)
- RFC 4469/5550: CATENATE
- RFC 4731: ESEARCH
- RFC 4959: SASL-IR
- RFC 5032: WITHIN
- RFC 5161: ENABLE
- RFC 5182: SEARCHRES
- RFC 5255: LANGUAGE/I18NLEVEL
- RFC 5256: THREAD/SORT
- RFC 5258: LIST-EXTENDED
- RFC 5267: ESORT; PARTIAL search return option
- RFC 5464: METADATA
- RFC 5530: IMAP Response Codes
- RFC 5802: AUTH=SCRAM-SHA-1
- RFC 5819: LIST-STATUS
- RFC 5957: SORT=DISPLAY
- RFC 6154: SPECIAL-USE/CREATE-SPECIAL-USE
- RFC 6203: SEARCH=FUZZY
- RFC 6851: MOVE
- RFC 6855: UTF8=ACCEPT/UTF8=ONLY
- RFC 6858: DOWNGRADED response code
- RFC 7162: CONDSTORE/QRESYNC
</pre>

Implements the following non-RFC extensions:
<pre>
- draft-ietf-morg-inthread-01: THREAD=REFS
- draft-daboo-imap-annotatemore-07: ANNOTATEMORE
- draft-daboo-imap-annotatemore-08: ANNOTATEMORE2
- XIMAPPROXY
Requires imapproxy v1.2.7-rc1 or later
See https://squirrelmail.svn.sourceforge.net/svnroot/squirrelmail/trunk/imap_proxy/README
- AUTH=XOAUTH2
https://developers.google.com/gmail/xoauth2_protocol
</pre>

TODO (or not necessary?):
<pre>
- RFC 2177: IDLE
- RFC 2193: MAILBOX-REFERRALS
- RFC 4467/5092/5524/5550/5593: URLAUTH, URLAUTH=BINARY, URL-PARTIAL
- RFC 4978: COMPRESS=DEFLATE
See: http://bugs.php.net/bug.php?id=48725
- RFC 5257: ANNOTATE (Experimental)
- RFC 5259: CONVERT
- RFC 5267: CONTEXT=SEARCH; CONTEXT=SORT
- RFC 5465: NOTIFY
- RFC 5466: FILTERS
- RFC 6785: IMAPSIEVE
- RFC 7377: MULTISEARCH
</pre>

__construct(array $params = array()   X-Ref

param: array $params  A hash containing configuration parameters.

__get($name)   X-Ref
No description

getParam($key)   X-Ref
No description

update(SplSubject $subject)   X-Ref
No description

_initCapability()   X-Ref
No description

_parseCapability(Horde_Imap_Client_Interaction_Pipeline $pipeline,$data)   X-Ref
Parse a CAPABILITY Response (RFC 3501 [7.2.1]).

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  Pipeline
param: array $data  An array of CAPABILITY strings.

_noop()   X-Ref
No description

_getNamespaces()   X-Ref
No description

_parseNamespace(Horde_Imap_Client_Interaction_Pipeline $pipeline,Horde_Imap_Client_Tokenize $data)   X-Ref
Parse a NAMESPACE response (RFC 2342 [5] & RFC 5255 [3.4]).

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  Pipeline
param: Horde_Imap_Client_Tokenize $data  The NAMESPACE data.

_login()   X-Ref
No description

_connect()   X-Ref
Connects to the IMAP server.


_tryLogin($method)   X-Ref
Authenticate to the IMAP server.

param: string $method  IMAP login method.
return: Horde_Imap_Client_Interaction_Pipeline  Pipeline object.

_authInitialResponse($method, $ir, $username = null)   X-Ref
No description

_loginTasks($firstlogin = true, array $resp = array()   X-Ref
Perform login tasks.

param: boolean $firstlogin  Is this the first login?
param: array $resp          The data response from the login command.
return: boolean  True if global login tasks should be performed.

_logout()   X-Ref
No description

_sendID($info)   X-Ref
No description

_parseID(Horde_Imap_Client_Interaction_Pipeline $pipeline,Horde_Imap_Client_Tokenize $data)   X-Ref
Parse an ID response (RFC 2971 [3.2]).

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  Pipeline
param: Horde_Imap_Client_Tokenize $data  The server response.

_getID()   X-Ref
No description

_setLanguage($langs)   X-Ref
No description

_getLanguage($list)   X-Ref
No description

_parseLanguage(Horde_Imap_Client_Tokenize $data)   X-Ref
Parse a LANGUAGE response (RFC 5255 [3.3]).

param: Horde_Imap_Client_Tokenize $data  The server response.

_enable($exts)   X-Ref
Enable an IMAP extension (see RFC 5161).

param: array $exts  The extensions to enable.

_parseEnabled(Horde_Imap_Client_Tokenize $data)   X-Ref
Parse an ENABLED response (RFC 5161 [3.2]).

param: Horde_Imap_Client_Tokenize $data  The server response.

_openMailbox(Horde_Imap_Client_Mailbox $mailbox, $mode)   X-Ref
No description

_createMailbox(Horde_Imap_Client_Mailbox $mailbox, $opts)   X-Ref
No description

_deleteMailbox(Horde_Imap_Client_Mailbox $mailbox)   X-Ref
No description

_renameMailbox(Horde_Imap_Client_Mailbox $old,Horde_Imap_Client_Mailbox $new)   X-Ref
No description

_subscribeMailbox(Horde_Imap_Client_Mailbox $mailbox,$subscribe)   X-Ref
No description

_listMailboxes($pattern, $mode, $options)   X-Ref
No description

_getMailboxList($pattern, $mode, $options,$subscribed = null)   X-Ref
Obtain a list of mailboxes.

param: array $pattern     The mailbox search pattern(s).
param: integer $mode      Which mailboxes to return.
param: array $options     Additional options. 'no_listext' will skip
param: array $subscribed  A list of subscribed mailboxes.
return: array  See listMailboxes(().

_parseList(Horde_Imap_Client_Interaction_Pipeline $pipeline,Horde_Imap_Client_Tokenize $data)   X-Ref
Parse a LIST/LSUB response (RFC 3501 [7.2.2 & 7.2.3]).

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  Pipeline
param: Horde_Imap_Client_Tokenize $data  The server response (includes

_status($mboxes, $flags)   X-Ref
No description

_parseStatus(Horde_Imap_Client_Tokenize $data)   X-Ref
Parse a STATUS response (RFC 3501 [7.2.4]).

param: Horde_Imap_Client_Tokenize $data  Token data

_prepareStatusResponse($request, $mailbox)   X-Ref
Prepares a status response for a mailbox.

param: array $request   The status keys to return.
param: string $mailbox  The mailbox to query.

_append(Horde_Imap_Client_Mailbox $mailbox, $data,$options)   X-Ref
No description

_appendData($data, &$asize)   X-Ref
Prepares append message data for insertion into the IMAP command
string.

param: mixed $data      Either a resource or a string.
param: integer &$asize  Total append size.
return: Horde_Imap_Client_Data_Format_String_Nonascii  The data object.

_convertCatenateUrl($url)   X-Ref
Converts a CATENATE URL to stream data.

param: string $url  The CATENATE URL.
return: resource  A stream containing the data.

_check()   X-Ref
No description

_close($options)   X-Ref
No description

_expunge($options)   X-Ref
No description

_parseVanished(Horde_Imap_Client_Interaction_Pipeline $pipeline,Horde_Imap_Client_Tokenize $data)   X-Ref
Parse a VANISHED response (RFC 7162 [3.2.10]).

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  Pipeline
param: Horde_Imap_Client_Tokenize $data  The response data.

_search($query, $options)   X-Ref
Search a mailbox.  This driver supports all IMAP4rev1 search criteria
as defined in RFC 3501.


_parseSearch(Horde_Imap_Client_Interaction_Pipeline $pipeline,$data)   X-Ref
Parse a SEARCH/SORT response (RFC 3501 [7.2.5]; RFC 4466 [3];
RFC 5256 [4]; RFC 5267 [3]).

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  Pipeline
param: array $data  A list of IDs (message sequence numbers or UIDs).

_parseEsearch(Horde_Imap_Client_Interaction_Pipeline $pipeline,Horde_Imap_Client_Tokenize $data)   X-Ref
Parse an ESEARCH response (RFC 4466 [2.6.2])
Format: (TAG "a567") UID COUNT 5 ALL 4:19,21,28

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  Pipeline
param: Horde_Imap_Client_Tokenize $data  The server response.

_setComparator($comparator)   X-Ref
No description

_getComparator()   X-Ref
No description

_parseComparator(Horde_Imap_Client_Interaction_Pipeline $pipeline,$data)   X-Ref
Parse a COMPARATOR response (RFC 5255 [4.8])

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  Pipeline
param: Horde_Imap_Client_Tokenize $data  The server response.

_thread($options)   X-Ref


_parseThread(Horde_Imap_Client_Interaction_Pipeline $pipeline,Horde_Imap_Client_Tokenize $data)   X-Ref
Parse a THREAD response (RFC 5256 [4]).

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  Pipeline
param: Horde_Imap_Client_Tokenize $data  Thread data.

_parseThreadLevel(&$thread,Horde_Imap_Client_Tokenize $data,$level = 0)   X-Ref
Parse a level of a THREAD response (RFC 5256 [4]).

param: array $thread                     Results.
param: Horde_Imap_Client_Tokenize $data  Thread data.
param: integer $level                    The current tree level.

_fetch(Horde_Imap_Client_Fetch_Results $results,$queries)   X-Ref
No description

_fetchCmd(Horde_Imap_Client_Interaction_Pipeline $pipeline,$options)   X-Ref
Add a FETCH command to the given pipeline.

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  Pipeline
param: array $options                                    Fetch query

_partialAtom($opts)   X-Ref
Add a partial atom to an IMAP command based on the criteria options.

param: array $opts  Criteria options.
return: string  The partial atom.

_parseFetch(Horde_Imap_Client_Interaction_Pipeline $pipeline,$id,Horde_Imap_Client_Tokenize $data)   X-Ref
Parse a FETCH response (RFC 3501 [7.4.2]). A FETCH response may occur
due to a FETCH command, or due to a change in a message's state (i.e.
the flags change).

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  Pipeline
param: integer $id                       The message sequence number.
param: Horde_Imap_Client_Tokenize $data  The server response.

_parseBodystructure(Horde_Imap_Client_Tokenize $data)   X-Ref
Recursively parse BODYSTRUCTURE data from a FETCH return (see
RFC 3501 [7.4.2]).

param: Horde_Imap_Client_Tokenize $data  Data returned from the server.
return: Horde_Mime_Part  Mime part object.

_parseStructureParams($data)   X-Ref
Helper function to parse a parameters-like tokenized array.

param: mixed $data  Message data. Either a Horde_Imap_Client_Tokenize
return: array  The parameter array.

_parseEnvelope(Horde_Imap_Client_Tokenize $data)   X-Ref
Parse ENVELOPE data from a FETCH return (see RFC 3501 [7.4.2]).

param: Horde_Imap_Client_Tokenize $data  Data returned from the server.
return: Horde_Imap_Client_Data_Envelope  An envelope object.

_vanished($modseq, Horde_Imap_Client_Ids $ids)   X-Ref
No description

_store($options)   X-Ref
No description

_storeCmd($options)   X-Ref
Create a store command.

param: array $options  See Horde_Imap_Client_Base#_store().
return: Horde_Imap_Client_Interaction_Pipeline  Pipeline object.

_copy(Horde_Imap_Client_Mailbox $dest, $options)   X-Ref
No description

_setQuota(Horde_Imap_Client_Mailbox $root, $resources)   X-Ref
No description

_getQuota(Horde_Imap_Client_Mailbox $root)   X-Ref
No description

_parseQuota(Horde_Imap_Client_Interaction_Pipeline $pipeline,Horde_Imap_Client_Tokenize $data)   X-Ref
Parse a QUOTA response (RFC 2087 [5.1]).

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  Pipeline
param: Horde_Imap_Client_Tokenize $data  The server response.

_getQuotaRoot(Horde_Imap_Client_Mailbox $mailbox)   X-Ref
No description

_setACL(Horde_Imap_Client_Mailbox $mailbox, $identifier,$options)   X-Ref
No description

_deleteACL(Horde_Imap_Client_Mailbox $mailbox, $identifier)   X-Ref
No description

_getACL(Horde_Imap_Client_Mailbox $mailbox)   X-Ref
No description

_parseACL(Horde_Imap_Client_Interaction_Pipeline $pipeline,Horde_Imap_Client_Tokenize $data)   X-Ref
Parse an ACL response (RFC 4314 [3.6]).

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  Pipeline
param: Horde_Imap_Client_Tokenize $data  The server response.

_listACLRights(Horde_Imap_Client_Mailbox $mailbox,$identifier)   X-Ref
No description

_parseListRights(Horde_Imap_Client_Interaction_Pipeline $pipeline,Horde_Imap_Client_Tokenize $data)   X-Ref
Parse a LISTRIGHTS response (RFC 4314 [3.7]).

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  Pipeline
param: Horde_Imap_Client_Tokenize $data  The server response.

_getMyACLRights(Horde_Imap_Client_Mailbox $mailbox)   X-Ref
No description

_parseMyRights(Horde_Imap_Client_Interaction_Pipeline $pipeline,Horde_Imap_Client_Tokenize $data)   X-Ref
Parse a MYRIGHTS response (RFC 4314 [3.8]).

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  Pipeline
param: Horde_Imap_Client_Tokenize $data  The server response.

_getMetadata(Horde_Imap_Client_Mailbox $mailbox,$entries, $options)   X-Ref
No description

_getAnnotateMoreEntry($name)   X-Ref
Split a name for the METADATA extension into the correct syntax for the
older ANNOTATEMORE version.

param: string $name  A name for a metadata entry.
return: array  A list of two elements: The entry name and the value

_setMetadata(Horde_Imap_Client_Mailbox $mailbox, $data)   X-Ref
No description

_parseAnnotation(Horde_Imap_Client_Interaction_Pipeline $pipeline,Horde_Imap_Client_Tokenize $data)   X-Ref
Parse an ANNOTATION response (ANNOTATEMORE/ANNOTATEMORE2).

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  Pipeline
param: Horde_Imap_Client_Tokenize $data  The server response.

_parseMetadata(Horde_Imap_Client_Interaction_Pipeline $pipeline,Horde_Imap_Client_Tokenize $data)   X-Ref
Parse a METADATA response (RFC 5464 [4.4]).

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  Pipeline
param: Horde_Imap_Client_Tokenize $data  The server response.

_deleteMsgs(Horde_Imap_Client_Mailbox $mailbox,Horde_Imap_Client_Ids $ids,array $opts = array()   X-Ref

param: array $opts  Options:

_getMboxFormatOb($mailbox, $list = false)   X-Ref
Return the proper mailbox format object based on the server's
capabilities.

param: string $mailbox  The mailbox.
param: boolean $list    Is this object used in a LIST command?
return: Horde_Imap_Client_Data_Format_Mailbox  A mailbox format object.

_sendCmd($cmd)   X-Ref
Sends command(s) to the IMAP server. A connection to the server must
have already been made.

param: mixed $cmd  Either a Command object or a Pipeline object.
return: Horde_Imap_Client_Interaction_Pipeline  A pipeline object.

_sendCmdChunk($pipeline, $chunk)   X-Ref
Send a chunk of commands and/or continuation fragments to the server.

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  The pipeline
param: array $chunk  List of commands to send.

_processCmd($pipeline, $cmd, $data)   X-Ref
Process/send a command to the remote server.

param: Horde_Imap_Client_Interaction_Pipeline $pipeline The pipeline
param: Horde_Imap_Client_Interaction_Command $cmd  The master command.
param: Horde_Imap_Client_Data_Format_List $data    Commands to send.
return: boolean  True if EOL needed to finish command.

_processCmdContinuation($pipeline, $noexception = false)   X-Ref
Process a command continuation response.

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  The pipeline
param: boolean $noexception                              Don't throw
return: mixed  A Horde_Imap_Client_Interaction_Server_Continuation

_command($cmd)   X-Ref
Shortcut to creating a new IMAP client command object.

param: string $cmd  The IMAP command.
return: Horde_Imap_Client_Interaction_Command  A command object.

_pipeline($cmd = null)   X-Ref
Shortcut to creating a new pipeline object.

param: Horde_Imap_Client_Interaction_Command $cmd  An IMAP command to
return: Horde_Imap_Client_Interaction_Pipeline  A pipeline object.

_getLine(Horde_Imap_Client_Interaction_Pipeline $pipeline)   X-Ref
Gets data from the IMAP server stream and parses it.

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  Pipeline
return: Horde_Imap_Client_Interaction_Server  Server object.

_serverResponse(Horde_Imap_Client_Interaction_Pipeline $pipeline,Horde_Imap_Client_Interaction_Server $ob)   X-Ref
Handle untagged server responses (see RFC 3501 [2.2.2]).

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  Pipeline
param: Horde_Imap_Client_Interaction_Server $ob          Server

_responseCode(Horde_Imap_Client_Interaction_Pipeline $pipeline,Horde_Imap_Client_Interaction_Server $ob)   X-Ref
Handle status responses (see RFC 3501 [7.1]).

param: Horde_Imap_Client_Interaction_Pipeline $pipeline  Pipeline
param: Horde_Imap_Client_Interaction_Server $ob          Server object.