Esempio n. 1
0
 public function testUsage()
 {
     $fp = fopen('php://temp', 'r+');
     fwrite($fp, '12345');
     $data = array('ABCDE', $fp, 'fghij');
     $ob = new Horde_Support_CombineStream($data);
     $stream = $ob->fopen();
     $this->assertEquals('ABCDE12345fghij', fread($stream, 1024));
     $this->assertEquals(true, feof($stream));
     $this->assertEquals(0, fseek($stream, 0));
     $this->assertEquals(-1, fseek($stream, 0));
     $this->assertEquals(0, ftell($stream));
     $this->assertEquals(0, fseek($stream, 5, SEEK_CUR));
     $this->assertEquals(5, ftell($stream));
     $this->assertEquals(10, fwrite($stream, '0000000000'));
     $this->assertEquals(0, fseek($stream, 0, SEEK_END));
     $this->assertEquals(20, ftell($stream));
     $this->assertEquals(false, feof($stream));
     fclose($stream);
 }
Esempio n. 2
0
 /**
  * Gets the raw text for one section of the message.
  *
  * @param integer $id     The ID of the MIME part.
  * @param array $options  Additional options:
  *   - decode: (boolean) Attempt to decode the bodypart on the remote
  *             server. If successful, sets self::$_lastBodyPartDecode to
  *             the content-type of the decoded data.
  *             DEFAULT: No
  *   - length: (integer) If set, only download this many bytes of the
  *             bodypart from the server.
  *             DEFAULT: All data is retrieved.
  *   - mimeheaders: (boolean) Include the MIME headers also?
  *                  DEFAULT: No
  *   - stream: (boolean) If true, return a stream.
  *             DEFAULT: No
  *
  * @return mixed  The text of the part or a stream resource if 'stream'
  *                is true.
  * @todo Simplify by removing 'mimeheaders' parameter (not used).
  */
 public function getBodyPart($id, $options)
 {
     $options = array_merge(array('decode' => false, 'mimeheaders' => false, 'stream' => false), $options);
     $this->_lastBodyPartDecode = null;
     $query = new Horde_Imap_Client_Fetch_Query();
     if (!isset($options['length']) || !empty($options['length'])) {
         $bodypart_params = array('decode' => true, 'peek' => true);
         if (isset($options['length'])) {
             $bodypart_params['start'] = 0;
             $bodypart_params['length'] = $options['length'];
         }
         $query->bodyPart($id, $bodypart_params);
     }
     if (!empty($options['mimeheaders'])) {
         $query->mimeHeader($id, array('peek' => true));
     }
     $fetch_res = $this->_imap->fetch($this->_mbox, $query, array('ids' => new Horde_Imap_Client_Ids(array($this->uid))));
     if (empty($options['mimeheaders'])) {
         $this->_lastBodyPartDecode = $fetch_res[$this->uid]->getBodyPartDecode($id);
         return $fetch_res[$this->uid]->getBodyPart($id, $options['stream']);
     } elseif (empty($options['stream'])) {
         return $fetch_res[$this->uid]->getMimeHeader($id) . $fetch_res[$this->uid]->getBodyPart($id);
     } else {
         $swrapper = new Horde_Support_CombineStream(array($fetch_res[$this->uid]->getMimeHeader($id, Horde_Imap_Client_Data_Fetch::HEADER_STREAM), $fetch_res[$this->uid]->getBodyPart($id, true)));
         return $swrapper->fopen();
     }
 }