Ejemplo n.º 1
0
 /**
  * Process/send a command to the remote server.
  *
  * @param Horde_Imap_Client_Interaction_Pipeline $pipeline The pipeline
  *                                                         object.
  * @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.
  * @throws Horde_Imap_Client_Exception
  * @throws Horde_Imap_Client_Exception_NoSupport
  */
 protected function _processCmd($pipeline, $cmd, $data)
 {
     if ($this->_debug->debug && $data instanceof Horde_Imap_Client_Interaction_Command) {
         $data->startTimer();
     }
     foreach ($data as $key => $val) {
         if ($val instanceof Horde_Imap_Client_Interaction_Command_Continuation) {
             $this->_connection->write('', true);
             /* Check for optional continuation responses when the command
              * has already finished. */
             if (!($cmd_continuation = $this->_processCmdContinuation($pipeline, $val->optional))) {
                 return false;
             }
             $this->_processCmd($pipeline, $cmd, $val->getCommands($cmd_continuation));
             continue;
         }
         if ($key) {
             $this->_connection->write(' ');
         }
         if ($val instanceof Horde_Imap_Client_Data_Format_List) {
             $this->_connection->write('(');
             $this->_processCmd($pipeline, $cmd, $val);
             $this->_connection->write(')');
         } elseif ($val instanceof Horde_Imap_Client_Data_Format_String && $val->literal()) {
             /* RFC 3516/4466: Send literal8 if we have binary data. */
             if ($cmd->literal8 && $val->binary() && $this->queryCapability('BINARY')) {
                 $binary = true;
                 $this->_connection->write('~');
             } else {
                 $binary = false;
             }
             $literal_len = $val->length();
             $this->_connection->write('{' . $literal_len);
             /* RFC 2088 - If LITERAL+ is available, saves a roundtrip from
              * the server. */
             if ($cmd->literalplus && $this->queryCapability('LITERAL+')) {
                 $this->_connection->write('+}', true);
             } else {
                 $this->_connection->write('}', true);
                 $this->_processCmdContinuation($pipeline);
             }
             $this->_connection->writeLiteral($val->getStream(), $literal_len, $binary);
         } else {
             $this->_connection->write($val->escape());
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Process/send a command to the remote server.
  *
  * @param Horde_Imap_Client_Interaction_Pipeline $pipeline The pipeline
  *                                                         object.
  * @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.
  * @throws Horde_Imap_Client_Exception
  * @throws Horde_Imap_Client_Exception_NoSupport
  */
 protected function _processCmd($pipeline, $cmd, $data)
 {
     if ($this->_debug->debug && $data instanceof Horde_Imap_Client_Interaction_Command) {
         $data->startTimer();
     }
     foreach ($data as $key => $val) {
         if ($val instanceof Horde_Imap_Client_Interaction_Command_Continuation) {
             $this->_connection->write('', true);
             /* Check for optional continuation responses when the command
              * has already finished. */
             if (!($cmd_continuation = $this->_processCmdContinuation($pipeline, $val->optional))) {
                 return false;
             }
             $this->_processCmd($pipeline, $cmd, $val->getCommands($cmd_continuation));
             continue;
         }
         if (!is_null($debug_msg = array_shift($cmd->debug))) {
             $this->_debug->client(($cmd == $data ? $cmd->tag . ' ' : '') . $debug_msg);
             $this->_connection->client_debug = false;
         }
         if ($key) {
             $this->_connection->write(' ');
         }
         if ($val instanceof Horde_Imap_Client_Data_Format_List) {
             $this->_connection->write('(');
             $this->_processCmd($pipeline, $cmd, $val);
             $this->_connection->write(')');
         } elseif ($val instanceof Horde_Imap_Client_Data_Format_String && $val->literal()) {
             $c = $this->_capability();
             /* RFC 6855: If UTF8 extension is available, quote short
              * strings instead of sending as literal. */
             if ($c->isEnabled('UTF8=ACCEPT') && $val->length() < 100) {
                 $val->forceQuoted();
                 $this->_connection->write($val->escape());
             } else {
                 /* RFC 3516/4466: Send literal8 if we have binary data. */
                 if ($cmd->literal8 && $val->binary() && ($c->query('BINARY') || $c->query('UTF8=ACCEPT'))) {
                     $binary = true;
                     $this->_connection->write('~');
                 } else {
                     $binary = false;
                 }
                 $literal_len = $val->length();
                 $this->_connection->write('{' . $literal_len);
                 /* RFC 2088 - If LITERAL+ is available, saves a roundtrip
                  * from the server. */
                 if ($cmd->literalplus && $c->query('LITERAL+')) {
                     $this->_connection->write('+}', true);
                 } else {
                     $this->_connection->write('}', true);
                     $this->_processCmdContinuation($pipeline);
                 }
                 if ($debug_msg) {
                     $this->_connection->client_debug = false;
                 }
                 $this->_connection->writeLiteral($val->getStream(), $literal_len, $binary);
             }
         } else {
             $this->_connection->write($val->escape());
         }
     }
     return true;
 }