Author: Michael Slusarz (slusarz@horde.org)
Example #1
0
 /**
  * @param string $tag  Response tag.
  */
 public function __construct(Horde_Imap_Client_Tokenize $token, $tag)
 {
     $this->tag = $tag;
     parent::__construct($token);
     if (is_null($this->status)) {
         throw new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::t("Bad tagged response."));
     }
 }
Example #2
0
 /**
  * Gets data from the IMAP server stream and parses it.
  *
  * @param Horde_Imap_Client_Interaction_Pipeline $pipeline  Pipeline
  *                                                          object.
  *
  * @return Horde_Imap_Client_Interaction_Server  Server object.
  *
  * @throws Horde_Imap_Client_Exception
  */
 protected function _getLine(Horde_Imap_Client_Interaction_Pipeline $pipeline)
 {
     $server = Horde_Imap_Client_Interaction_Server::create($this->_connection->read());
     switch (get_class($server)) {
         case 'Horde_Imap_Client_Interaction_Server_Continuation':
             $this->_responseCode($pipeline, $server);
             break;
         case 'Horde_Imap_Client_Interaction_Server_Tagged':
             $cmd = $pipeline->complete($server);
             if ($timer = $cmd->getTimer()) {
                 $this->_debug->info(sprintf('Command %s took %s seconds.', $cmd->tag, $timer));
             }
             $this->_responseCode($pipeline, $server);
             break;
         case 'Horde_Imap_Client_Interaction_Server_Untagged':
             if (is_null($server->status)) {
                 $this->_serverResponse($pipeline, $server);
             } else {
                 $this->_responseCode($pipeline, $server);
             }
             break;
     }
     switch ($server->status) {
         case $server::BAD:
         case $server::NO:
             /* A tagged BAD response indicates that the tagged command caused
              * the error. This information is unknown if untagged (RFC 3501
              * [7.1.3]) - ignore these untagged responses.
              * An untagged NO response indicates a warning; ignore and assume
              * that it also included response text code that is handled
              * elsewhere. Throw exception if tagged; command handlers can
              * catch this if able to workaround this issue (RFC 3501
              * [7.1.2]). */
             if ($server instanceof Horde_Imap_Client_Interaction_Server_Tagged) {
                 throw new Horde_Imap_Client_Exception_ServerResponse(Horde_Imap_Client_Translation::r("IMAP error reported by server."), 0, $server, $pipeline);
             }
             break;
         case $server::BYE:
             /* A BYE response received as part of a logout command should be
              * be treated like a regular command: a client MUST process the
              * entire command until logging out (RFC 3501 [3.4; 7.1.5]). */
             if (empty($this->_temp['logout'])) {
                 $e = new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::r("IMAP Server closed the connection."), Horde_Imap_Client_Exception::DISCONNECT);
                 $e->details = strval($server);
                 throw $e;
             }
             break;
         case $server::PREAUTH:
             /* The user was pre-authenticated. (RFC 3501 [7.1.4]) */
             $this->_temp['preauth'] = true;
             break;
     }
     return $server;
 }
Example #3
0
 /**
  * Gets data from the IMAP server stream and parses it.
  *
  * @return Horde_Imap_Client_Interaction_Server  Server object.
  *
  * @throws Horde_Imap_Client_Exception
  */
 protected function _getLine()
 {
     $server = Horde_Imap_Client_Interaction_Server::create($this->_readStream());
     switch (get_class($server)) {
         case 'Horde_Imap_Client_Interaction_Server_Continuation':
             $this->_responseCode($server);
             break;
         case 'Horde_Imap_Client_Interaction_Server_Tagged':
             /* Update HIGHESTMODSEQ value. */
             if (!empty($this->_temp['modseqs'])) {
                 $this->_temp['mailbox']['highestmodseq'] = max($this->_temp['modseqs']);
             }
             /* Update FETCH items. */
             if (!is_null($this->_temp['fetchresp'])) {
                 $this->_updateCache($this->_temp['fetchresp']);
             }
             $this->_responseCode($server);
             break;
         case 'Horde_Imap_Client_Interaction_Server_Untagged':
             if (is_null($server->status)) {
                 $this->_serverResponse($server);
             } else {
                 $this->_responseCode($server);
             }
             break;
     }
     switch ($server->status) {
         case $server::BAD:
             /* A tagged BAD response indicates that the tagged command caused
              * the error. This information is unknown if untagged. (RFC 3501
              * [7.1.3]) */
             $cmd = $server instanceof Horde_Imap_Client_Interaction_Server_Tagged ? $this->_temp['lastcmd']->getCommand() : null;
             throw new Horde_Imap_Client_Exception_ServerResponse(Horde_Imap_Client_Translation::t("IMAP error reported by server."), 0, $server->status, strval($server->token), $cmd);
         case $server::BYE:
             /* A BYE response received as part of a logout command should be
              * be treated like a regular command: a client MUST process the
              * entire command until logging out (RFC 3501 [3.4; 7.1.5]). */
             if (empty($this->_temp['logout'])) {
                 $this->_temp['logout'] = true;
                 $this->logout();
                 $e = new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::t("IMAP Server closed the connection."), Horde_Imap_Client_Exception::DISCONNECT);
                 $e->details = strval($server);
                 throw $e;
             }
             break;
         case $server::NO:
             /* An untagged NO response indicates a warning; ignore and assume
              * that it also included response text code that is handled
              * elsewhere. Throw exception if tagged; command handlers can
              * catch this if able to workaround this issue. (RFC 3501
              * [7.1.2]) */
             if ($server instanceof Horde_Imap_Client_Interaction_Server_Tagged) {
                 throw new Horde_Imap_Client_Exception_ServerResponse(Horde_Imap_Client_Translation::t("IMAP error reported by server."), 0, $server->status, strval($server->token), $this->_temp['lastcmd']->getCommand());
             }
         case $server::PREAUTH:
             /* The user was pre-authenticated. (RFC 3501 [7.1.4]) */
             $this->_temp['preauth'] = true;
             break;
     }
     return $server;
 }
Example #4
0
 public function doResponseCode($data)
 {
     $server = Horde_Imap_Client_Interaction_Server::create(new Horde_Imap_Client_Tokenize($data));
     $this->_responseCode($this->_pipeline(), $server);
 }