rewind() public méthode

public rewind ( )
Exemple #1
0
 /**
  * Auto-scan an incoming line to determine the response type.
  *
  * @param Horde_Imap_Client_Tokenize $t  Tokenized data returned from the
  *                                       server.
  *
  * @return Horde_Imap_Client_Interaction_Server  A server response object.
  */
 public static function create(Horde_Imap_Client_Tokenize $t)
 {
     $tag = $t->rewind();
     $t->next();
     switch ($tag) {
         case '+':
             return new Horde_Imap_Client_Interaction_Server_Continuation($t);
         case '*':
             return new Horde_Imap_Client_Interaction_Server_Untagged($t);
         default:
             return new Horde_Imap_Client_Interaction_Server_Tagged($t, $tag);
     }
 }
Exemple #2
0
 /**
  * @dataProvider clientSortProvider
  */
 public function testClientSortProvider($sort, $expected, $locale)
 {
     $ids = new Horde_Imap_Client_Ids();
     $pipeline = $this->socket_ob->pipeline();
     foreach ($this->fetch_data as $val) {
         $token = new Horde_Imap_Client_Tokenize($val);
         $token->rewind();
         $token->next();
         $ids->add($token->next());
         $this->socket_ob->doServerResponse($pipeline, $val);
     }
     $this->socket_ob->fetch_results = $pipeline->fetch;
     $sorted = $this->sort_ob->clientSort($ids, array('sort' => $sort));
     $this->assertEquals(count($expected), count($sorted));
     if (!$locale || class_exists('Collator')) {
         $this->assertEquals($expected, array_values($sorted));
     }
 }
Exemple #3
0
 /**
  * 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 array  The array of bodystructure information.
  */
 protected function _parseBodystructure(Horde_Imap_Client_Tokenize $data)
 {
     $ob = new Horde_Mime_Part();
     // If index 0 is an array, this is a multipart part.
     if (is_object($entry = $data->rewind())) {
         // Keep going through array values until we find a non-array.
         do {
             $ob->addPart($this->_parseBodystructure($entry));
         } while (is_object($entry = $data->next()));
         // The first string entry after an array entry gives us the
         // subpart type.
         $ob->setType('multipart/' . $entry);
         // After the subtype is further extension information. This
         // information MAY not appear for BODYSTRUCTURE requests.
         // This is parameter information.
         if (is_object($tmp = $data->next())) {
             foreach ($this->_parseStructureParams($tmp, 'content-type') as $key => $val) {
                 $ob->setContentTypeParameter($key, $val);
             }
         }
     } else {
         $ob->setType($entry . '/' . $data->next());
         if (is_object($tmp = $data->next())) {
             foreach ($this->_parseStructureParams($tmp, 'content-type') as $key => $val) {
                 $ob->setContentTypeParameter($key, $val);
             }
         }
         if (!is_null($tmp = $data->next())) {
             $ob->setContentId($tmp);
         }
         if (!is_null($tmp = $data->next())) {
             $ob->setDescription(Horde_Mime::decode($tmp));
         }
         if (!is_null($tmp = $data->next())) {
             $ob->setTransferEncoding($tmp);
         }
         $ob->setBytes($data->next());
         // If the type is 'message/rfc822' or 'text/*', several extra
         // fields are included
         switch ($ob->getPrimaryType()) {
             case 'message':
                 if ($ob->getSubType() == 'rfc822') {
                     $data->next();
                     // Ignore: envelope
                     $ob->addPart($this->_parseBodystructure($data->next()));
                     $data->next();
                     // Ignore: lines
                 }
                 break;
             case 'text':
                 $data->next();
                 // Ignore: lines
                 break;
         }
         // After the subtype is further extension information. This
         // information MAY appear for BODYSTRUCTURE requests.
         $data->next();
         // Ignore: MD5
     }
     // This is disposition information
     if (is_object($tmp = $data->next())) {
         $ob->setDisposition($tmp->rewind());
         foreach ($this->_parseStructureParams($tmp->next(), 'content-disposition') as $key => $val) {
             $ob->setDispositionParameter($key, $val);
         }
     }
     // This is language information. It is either a single value or a list
     // of values.
     if (($tmp = $data->next()) !== false) {
         $ob->setLanguage($tmp);
     }
     $data->next();
     // Ignore: location (RFC 2557)
     return $ob;
 }
Exemple #4
0
 public function testLiteralStream()
 {
     $token = new Horde_Imap_Client_Tokenize();
     $token->add('FOO {10}');
     $token->addLiteralStream('1234567890');
     $token->add(' BAR');
     $token->rewind();
     $this->assertEquals('FOO', $token->next());
     /* Internal stream is converted to string. */
     $this->assertEquals('1234567890', $token->next());
     $this->assertEquals('BAR', $token->next());
     $this->assertTrue($token->eos);
     /* Check to see stream is returned if nextStream() is called and
      * a literal is encountered. */
     $token->rewind();
     $this->assertEquals('FOO', $token->nextStream());
     $stream = $token->nextStream();
     $this->assertInstanceOf('Horde_Stream_Temp', $stream);
     $this->assertEquals('1234567890', strval($stream));
     $this->assertEquals('BAR', $token->nextStream());
     $token = new Horde_Imap_Client_Tokenize();
     $token->add('{200}' . str_repeat('Z', 200));
     $token->rewind();
     $this->assertEquals(str_repeat('Z', 200), $token->next());
     $token->rewind();
     $stream = $token->nextStream();
     $this->assertInstanceOf('Horde_Stream_Temp', $stream);
     $this->assertEquals(str_repeat('Z', 200), strval($stream));
 }
Exemple #5
0
 public function testFlushIterator()
 {
     $test = 'FOO (BAR (BAZ BAZ2) BAR2) FOO2';
     $token = new Horde_Imap_Client_Tokenize($test);
     $token->rewind();
     $token->next();
     // FOO
     $token->next();
     // Opening paren
     $this->assertEquals(array('BAR', 'BAR2'), $token->flushIterator());
     $this->assertEquals('FOO2', $token->next());
     $token->rewind();
     $token->next();
     // FOO
     $token->next();
     // Opening paren
     $this->assertEquals(array(), $token->flushIterator(false));
     $this->assertEquals('FOO2', $token->next());
     $token->rewind();
     $token->next();
     // FOO
     $token->next();
     // Opening paren
     $this->assertEquals(array(), $token->flushIterator(false, false));
     $this->assertTrue($token->eos);
 }