Horde_Imap_Client_Socket::_responseCode PHP Method

_responseCode() protected method

Handle status responses (see RFC 3501 [7.1]).
protected _responseCode ( Horde_Imap_Client_Interaction_Pipeline $pipeline, Horde_Imap_Client_Interaction_Server $ob )
$pipeline Horde_Imap_Client_Interaction_Pipeline Pipeline object.
$ob Horde_Imap_Client_Interaction_Server Server object.
    protected function _responseCode(Horde_Imap_Client_Interaction_Pipeline $pipeline, Horde_Imap_Client_Interaction_Server $ob)
    {
        if (is_null($ob->responseCode)) {
            return;
        }
        $rc = $ob->responseCode;
        switch ($rc->code) {
            case 'ALERT':
                // Defined by RFC 5530 [3] - Treat as an alert for now.
            // Defined by RFC 5530 [3] - Treat as an alert for now.
            case 'CONTACTADMIN':
                // Used by Gmail - Treat as an alert for now.
                // http://mailman13.u.washington.edu/pipermail/imap-protocol/2014-September/002324.html
            // Used by Gmail - Treat as an alert for now.
            // http://mailman13.u.washington.edu/pipermail/imap-protocol/2014-September/002324.html
            case 'WEBALERT':
                $this->_alerts->add(strval($ob->token), $rc->code);
                break;
            case 'BADCHARSET':
                /* Store valid search charsets if returned by server. */
                $s = $this->search_charset;
                foreach ($rc->data[0] as $val) {
                    $s->setValid($val, true);
                }
                throw new Horde_Imap_Client_Exception_ServerResponse(Horde_Imap_Client_Translation::r("Charset used in search query is not supported on the mail server."), Horde_Imap_Client_Exception::BADCHARSET, $ob, $pipeline);
            case 'CAPABILITY':
                $this->_parseCapability($pipeline, $rc->data);
                break;
            case 'PARSE':
                /* Only throw error on NO/BAD. Message is human readable. */
                switch ($ob->status) {
                    case Horde_Imap_Client_Interaction_Server::BAD:
                    case Horde_Imap_Client_Interaction_Server::NO:
                        $e = new Horde_Imap_Client_Exception_ServerResponse(Horde_Imap_Client_Translation::r("The mail server was unable to parse the contents of the mail message: %s"), Horde_Imap_Client_Exception::PARSEERROR, $ob, $pipeline);
                        $e->messagePrintf(strval($ob->token));
                        throw $e;
                }
                break;
            case 'READ-ONLY':
                $this->_mode = Horde_Imap_Client::OPEN_READONLY;
                break;
            case 'READ-WRITE':
                $this->_mode = Horde_Imap_Client::OPEN_READWRITE;
                break;
            case 'TRYCREATE':
                // RFC 3501 [7.1]
                $pipeline->data['trycreate'] = true;
                break;
            case 'PERMANENTFLAGS':
                $this->_mailboxOb()->setStatus(Horde_Imap_Client::STATUS_PERMFLAGS, array_map('Horde_String::lower', $rc->data[0]));
                break;
            case 'UIDNEXT':
                $this->_mailboxOb()->setStatus(Horde_Imap_Client::STATUS_UIDNEXT, $rc->data[0]);
                break;
            case 'UIDVALIDITY':
                $this->_mailboxOb()->setStatus(Horde_Imap_Client::STATUS_UIDVALIDITY, $rc->data[0]);
                break;
            case 'UNSEEN':
                /* This is different from the STATUS UNSEEN response - this item,
                 * if defined, returns the first UNSEEN message in the mailbox. */
                $this->_mailboxOb()->setStatus(Horde_Imap_Client::STATUS_FIRSTUNSEEN, $rc->data[0]);
                break;
            case 'REFERRAL':
                // Defined by RFC 2221
                $pipeline->data['referral'] = new Horde_Imap_Client_Url_Imap($rc->data[0]);
                break;
            case 'UNKNOWN-CTE':
                // Defined by RFC 3516
                throw new Horde_Imap_Client_Exception_ServerResponse(Horde_Imap_Client_Translation::r("The mail server was unable to parse the contents of the mail message."), Horde_Imap_Client_Exception::UNKNOWNCTE, $ob, $pipeline);
            case 'APPENDUID':
                // Defined by RFC 4315
                // APPENDUID: [0] = UIDVALIDITY, [1] = UID(s)
                $pipeline->data['appenduid'] = $this->getIdsOb($rc->data[1]);
                break;
            case 'COPYUID':
                // Defined by RFC 4315
                // COPYUID: [0] = UIDVALIDITY, [1] = UIDFROM, [2] = UIDTO
                $pipeline->data['copyuid'] = array_combine($this->getIdsOb($rc->data[1])->ids, $this->getIdsOb($rc->data[2])->ids);
                /* Use UIDPLUS information to move cached data to new mailbox (see
                 * RFC 4549 [4.2.2.1]). Need to move now, because a MOVE might
                 * EXPUNGE immediately afterwards. */
                $this->_moveCache($pipeline->data['copydest'], $pipeline->data['copyuid'], $rc->data[0]);
                break;
            case 'UIDNOTSTICKY':
                // Defined by RFC 4315 [3]
                $this->_mailboxOb()->setStatus(Horde_Imap_Client::STATUS_UIDNOTSTICKY, true);
                break;
            case 'BADURL':
                // Defined by RFC 4469 [4.1]
                throw new Horde_Imap_Client_Exception_ServerResponse(Horde_Imap_Client_Translation::r("Could not save message on server."), Horde_Imap_Client_Exception::CATENATE_BADURL, $ob, $pipeline);
            case 'TOOBIG':
                // Defined by RFC 4469 [4.2]
                throw new Horde_Imap_Client_Exception_ServerResponse(Horde_Imap_Client_Translation::r("Could not save message data because it is too large."), Horde_Imap_Client_Exception::CATENATE_TOOBIG, $ob, $pipeline);
            case 'HIGHESTMODSEQ':
                // Defined by RFC 7162 [3.1.2.1]
                $pipeline->data['modseqs'][] = $rc->data[0];
                break;
            case 'NOMODSEQ':
                // Defined by RFC 7162 [3.1.2.2]
                $pipeline->data['modseqs'][] = 0;
                break;
            case 'MODIFIED':
                // Defined by RFC 7162 [3.1.3]
                $pipeline->data['modified']->add($rc->data[0]);
                break;
            case 'CLOSED':
                // Defined by RFC 7162 [3.2.11]
                if (isset($pipeline->data['qresyncmbox'])) {
                    /* If there is any pending FETCH cache entries, flush them
                     * now before changing mailboxes. */
                    $this->_updateCache($pipeline->fetch);
                    $pipeline->fetch->clear();
                    $this->_changeSelected($pipeline->data['qresyncmbox'][0], $pipeline->data['qresyncmbox'][1]);
                    unset($pipeline->data['qresyncmbox']);
                }
                break;
            case 'NOTSAVED':
                // Defined by RFC 5182 [2.5]
                $pipeline->data['searchnotsaved'] = true;
                break;
            case 'BADCOMPARATOR':
                // Defined by RFC 5255 [4.9]
                throw new Horde_Imap_Client_Exception_ServerResponse(Horde_Imap_Client_Translation::r("The comparison algorithm was not recognized by the server."), Horde_Imap_Client_Exception::BADCOMPARATOR, $ob, $pipeline);
            case 'METADATA':
                $md = $rc->data[0];
                switch ($md[0]) {
                    case 'LONGENTRIES':
                        // Defined by RFC 5464 [4.2.1]
                        $pipeline->data['metadata']['*longentries'] = intval($md[1]);
                        break;
                    case 'MAXSIZE':
                        // Defined by RFC 5464 [4.3]
                        throw new Horde_Imap_Client_Exception_ServerResponse(Horde_Imap_Client_Translation::r("The metadata item could not be saved because it is too large."), Horde_Imap_Client_Exception::METADATA_MAXSIZE, $ob, $pipeline);
                    case 'NOPRIVATE':
                        // Defined by RFC 5464 [4.3]
                        throw new Horde_Imap_Client_Exception_ServerResponse(Horde_Imap_Client_Translation::r("The metadata item could not be saved because the server does not support private annotations."), Horde_Imap_Client_Exception::METADATA_NOPRIVATE, $ob, $pipeline);
                    case 'TOOMANY':
                        // Defined by RFC 5464 [4.3]
                        throw new Horde_Imap_Client_Exception_ServerResponse(Horde_Imap_Client_Translation::r("The metadata item could not be saved because the maximum number of annotations has been exceeded."), Horde_Imap_Client_Exception::METADATA_TOOMANY, $ob, $pipeline);
                }
                break;
            case 'UNAVAILABLE':
                // Defined by RFC 5530 [3]
                $pipeline->data['loginerr'] = new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::r("Remote server is temporarily unavailable."), Horde_Imap_Client_Exception::LOGIN_UNAVAILABLE);
                break;
            case 'AUTHENTICATIONFAILED':
                // Defined by RFC 5530 [3]
                $pipeline->data['loginerr'] = new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::r("Authentication failed."), Horde_Imap_Client_Exception::LOGIN_AUTHENTICATIONFAILED);
                break;
            case 'AUTHORIZATIONFAILED':
                // Defined by RFC 5530 [3]
                $pipeline->data['loginerr'] = new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::r("Authentication was successful, but authorization failed."), Horde_Imap_Client_Exception::LOGIN_AUTHORIZATIONFAILED);
                break;
            case 'EXPIRED':
                // Defined by RFC 5530 [3]
                $pipeline->data['loginerr'] = new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::r("Authentication credentials have expired."), Horde_Imap_Client_Exception::LOGIN_EXPIRED);
                break;
            case 'PRIVACYREQUIRED':
                // Defined by RFC 5530 [3]
                $pipeline->data['loginerr'] = new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::r("Operation failed due to a lack of a secure connection."), Horde_Imap_Client_Exception::LOGIN_PRIVACYREQUIRED);
                break;
            case 'NOPERM':
                // Defined by RFC 5530 [3]
                throw new Horde_Imap_Client_Exception_ServerResponse(Horde_Imap_Client_Translation::r("You do not have adequate permissions to carry out this operation."), Horde_Imap_Client_Exception::NOPERM, $ob, $pipeline);
            case 'INUSE':
                // Defined by RFC 5530 [3]
                throw new Horde_Imap_Client_Exception_ServerResponse(Horde_Imap_Client_Translation::r("There was a temporary issue when attempting this operation. Please try again later."), Horde_Imap_Client_Exception::INUSE, $ob, $pipeline);
            case 'EXPUNGEISSUED':
                // Defined by RFC 5530 [3]
                $pipeline->data['expungeissued'] = true;
                break;
            case 'CORRUPTION':
                // Defined by RFC 5530 [3]
                throw new Horde_Imap_Client_Exception_ServerResponse(Horde_Imap_Client_Translation::r("The mail server is reporting corrupt data in your mailbox."), Horde_Imap_Client_Exception::CORRUPTION, $ob, $pipeline);
            case 'SERVERBUG':
            case 'CLIENTBUG':
            case 'CANNOT':
                // Defined by RFC 5530 [3]
                $this->_debug->info('ERROR: mail server explicitly reporting an error.');
                break;
            case 'LIMIT':
                // Defined by RFC 5530 [3]
                throw new Horde_Imap_Client_Exception_ServerResponse(Horde_Imap_Client_Translation::r("The mail server has denied the request."), Horde_Imap_Client_Exception::LIMIT, $ob, $pipeline);
            case 'OVERQUOTA':
                // Defined by RFC 5530 [3]
                throw new Horde_Imap_Client_Exception_ServerResponse(Horde_Imap_Client_Translation::r("The operation failed because the quota has been exceeded on the mail server."), Horde_Imap_Client_Exception::OVERQUOTA, $ob, $pipeline);
            case 'ALREADYEXISTS':
                // Defined by RFC 5530 [3]
                throw new Horde_Imap_Client_Exception_ServerResponse(Horde_Imap_Client_Translation::r("The object could not be created because it already exists."), Horde_Imap_Client_Exception::ALREADYEXISTS, $ob, $pipeline);
            case 'NONEXISTENT':
                // Defined by RFC 5530 [3]
                throw new Horde_Imap_Client_Exception_ServerResponse(Horde_Imap_Client_Translation::r("The object could not be deleted because it does not exist."), Horde_Imap_Client_Exception::NONEXISTENT, $ob, $pipeline);
            case 'USEATTR':
                // Defined by RFC 6154 [3]
                throw new Horde_Imap_Client_Exception_ServerResponse(Horde_Imap_Client_Translation::r("The special-use attribute requested for the mailbox is not supported."), Horde_Imap_Client_Exception::USEATTR, $ob, $pipeline);
            case 'DOWNGRADED':
                // Defined by RFC 6858 [3]
                $downgraded = $this->getIdsOb($rc->data[0]);
                foreach ($pipeline->fetch as $val) {
                    if (in_array($val->getUid(), $downgraded)) {
                        $val->setDowngraded(true);
                    }
                }
                break;
            case 'XPROXYREUSE':
                // The proxy connection was reused, so no need to do login tasks.
                $pipeline->data['proxyreuse'] = true;
                break;
            default:
                // Unknown response codes SHOULD be ignored - RFC 3501 [7.1]
                break;
        }
    }