/** */ public function rewind() { $this->_stream->rewind(); $this->_current = false; $this->_key = -1; $this->_level = 0; }
/** * Constructor. * * @param array $opts Additional configuration options: * - max_memory: (integer) The maximum amount of memory to allocate to * the PHP temporary stream. * * @throws Horde_Stream_Exception */ public function __construct(array $opts = array()) { $opts = array_merge(array('max_memory' => 2097152), $opts); if (($this->stream = @fopen('php://temp/maxmemory:' . $opts['max_memory'], 'r+')) === false) { throw new Horde_Stream_Exception('Failed to open temporary memory stream.'); } parent::__construct($opts); }
/** * Constructor. * * @param array $opts Additional configuration options: * - stream: (resource) [REQUIRED] The stream resource. * * @throws Horde_Stream_Exception */ public function __construct(array $opts = array()) { if (!isset($opts['stream']) || !is_resource($opts['stream'])) { throw new Horde_Stream_Exception('Need a stream resource.'); } $this->stream = $opts['stream']; unset($opts['stream']); parent::__construct($opts); }
/** * Constructor. * * @param array $opts Additional configuration options: * <pre> * - string: (string) [REQUIRED] The PHP string. * </pre> * * @throws InvalidArgumentException */ public function __construct(array $opts = array()) { if (!isset($opts['string']) || !is_string($opts['string'])) { throw new InvalidArgumentException('Need a PHP string.'); } $this->stream = Horde_Stream_Wrapper_String::getStream($opts['string']); unset($opts['string']); parent::__construct($opts); }
/** * Find the location of the end of the header text. * * @return array 1st element: Header position, 2nd element: Length of * trailing EOL. */ protected function _findHeader() { // Look for the EOL that is found first in the message. Some clients // are sending mixed EOL in S/MIME signed messages. This still doesn't // fix "Nine" currently, as they first send \r\n, but use \n\n to // separate the headers. // See: https://ninefolders.plan.io/track/10606/1dcfed switch ($this->_stream->getEOL()) { case "\n": return array($this->_stream->search("\n\n"), 2); case "\r\n": return array($this->_stream->search("\r\n\r\n"), 4); } }
/** * Find the location of the end of the header text. * * @return array 1st element: Header position, 2nd element: Length of * trailing EOL. */ protected function _findHeader() { $i = 0; while (!$this->_stream->eof()) { $data = $this->_stream->substring(0, 8192); $hdr_pos = strpos($data, "\r\n\r\n"); if ($hdr_pos !== false) { return array($hdr_pos + $i * 8192, 4); } $hdr_pos = strpos($data, "\n\n"); if ($hdr_pos !== false) { return array($hdr_pos + $i * 8192, 2); } $i++; } $this->_stream->end(); return array($this->_stream->pos(), 0); }
/** */ public function rewind() { $this->_data->rewind(); $this->_current = $this->_key = null; $this->next(); }
/** * Browse VFS backend. * * @param string $path The path to browse/fetch. This should be in UNC * format with the "server" portion specifying * backend name. e.g., \\file\mike\file.txt or * \\sql\mike\file.txt * * @return array An array of data arrays with the following structure: * linkid: (string) The UNC path for this resource. * name: (string) The display name of the resource. * content-length: (integer) The byte size of the resource (if a file). * modified: (Horde_Date) The modification time of the resource, if * available. * create: (Horde_Date) The creation time of the resource, if * available. * is_folder: (boolean) True if the resource is a folder. * data: (Horde_Stream) The data, if resource is a file. * content-type: (string) The MIME type of the file resource, if * available. * @since 2.12.0 */ public function files_browse($path) { if (!($app = $this->_registry->hasInterface('files'))) { return false; } // Save for later. $original_path = $path; // Normalize $path = str_replace('\\', '/', $path); // Get the "server" name. $regex = '=^//([a-zA-Z0-9-]+)/(.*)='; if (preg_match($regex, $path, $results) === false) { return false; } $backend = $app . '/' . $results[1]; $path = $backend . '//' . $results[2]; try { $results = $this->_registry->files->browse($path); } catch (Horde_Exception $e) { throw new Horde_ActiveSync_Exception($e); } $files = array(); // An explicit file requested? if (!empty($results['data'])) { $data = new Horde_Stream(); $data->add($results['data']); $files[] = array('linkid' => $original_path, 'name' => $results['name'], 'content-length' => $results['contentlength'], 'modified' => new Horde_Date($results['mtime']), 'created' => new Horde_Date($results['mtime']), 'is_folder' => false, 'data' => $data); } else { foreach ($results as $id => $result) { $file = array('name' => $result['name']); $file['is_folder'] = $result['browseable']; $file['modified'] = new Horde_Date($result['modified']); $file['created'] = clone $file['modified']; $file['linkid'] = str_replace($backend, '', $id); if (!empty($result['contentlength'])) { $file['content-length'] = $result['contentlength']; } $files[] = $file; } } return $files; }
/** * Get the raw email data sent by this object. * * @param boolean $stream If true, return a stream resource, otherwise * a string is returned. * * @return stream|string The raw email data. * @since 2.4.0 */ public function getRaw($stream = true) { if ($stream) { $hdr = new Horde_Stream(); $hdr->add($this->_headers->toString(), true); return Horde_Stream_Wrapper_Combine::getStream(array($hdr->stream, $this->getBasePart()->toString(array('stream' => true)))); } return $this->_headers->toString() . $this->_getBasePart->toString(); }
/** * Constructor. * * @param array $opts Additional configuration options: * <pre> * - max_memory: (integer) The maximum amount of memory to allocate to * the PHP temporary stream. * </pre> * * @throws Horde_Stream_Exception */ public function __construct(array $opts = array()) { parent::__construct($opts); }
/** * Get the raw email data sent by this object. * * @param boolean $stream If true, return a stream resource, otherwise * a string is returned. * * @return stream|string The raw email data. * @since 2.4.0 */ public function getRaw($stream = true) { if ($stream) { $hdr = new Horde_Stream(); $hdr->add($this->_headers->toString(), true); return Horde_Stream_Wrapper_Combine::getStream(array($hdr->stream, $this->getBasePart()->toString(array('stream' => true, 'encode' => Horde_Mime_Part::ENCODE_7BIT | Horde_Mime_Part::ENCODE_8BIT | Horde_Mime_Part::ENCODE_BINARY)))); } return $this->_headers->toString() . $this->getBasePart()->toString(); }
/** * Converts a string or resource into a Horde_Stream object. * * @param string|resource $val Some content. * * @return Horde_Stream A Horde_Stream object with the content. */ protected function _makeStream($val) { if (is_resource($val)) { return new Horde_Stream_Existing(array('stream' => $val)); } $tmp = new Horde_Stream(); $tmp->add($val); return $tmp; }
/** * Returns the next token and increments the internal stream pointer. * * @return mixed Either a string, array, false, or null. */ protected function _parseStream() { $in_quote = false; $text = ''; /* If active is false, we delegated the stream to a child tokenizer, * which did not reach the end of the list. Thus, we have to manually * iterate through until we reach a closing paren. */ if (!$this->active) { $this->active = true; $old_parent = $this->_parent; $this->_parent = null; while ($this->next() !== false) { } $this->_parent = $old_parent; } while (($c = fgetc($this->stream->stream)) !== false) { switch ($c) { case '\\': $text .= $in_quote ? fgetc($this->stream->stream) : $c; break; case '"': if ($in_quote) { return $text; } else { $in_quote = true; } break; default: if ($in_quote) { $text .= $c; break; } switch ($c) { case '(': $this->active = false; return new Horde_Imap_Client_Tokenize($this); case ')': if (strlen($text)) { fseek($this->stream->stream, -1, SEEK_CUR); break 3; } if ($this->_parent) { $this->_parent->active = true; $this->_current = $this->_key = false; } return false; case '~': // Ignore binary string identifier. PHP strings are // binary-safe. break; case '{': $literal_len = $this->stream->getToChar('}'); return stream_get_contents($this->stream->stream, $literal_len); case ' ': if (strlen($text)) { break 3; } break; default: $text .= $c; break; } break; } } return strlen($text) ? strcasecmp($text, 'NIL') === 0 ? null : $text : false; }