Example #1
0
 /**
  * Constructor.
  *
  * @param mixed $text  Either the text to parse or a Horde_Stream object.
  */
 public function __construct($data)
 {
     if ($data instanceof Horde_Stream) {
         $this->_data = $data;
     } else {
         $this->_data = new Horde_Stream_Temp();
         $this->_data->add($data, true);
     }
 }
Example #2
0
 /**
  * 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;
 }
Example #3
0
 /**
  * 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();
 }
Example #4
0
 /**
  * Add data to buffer.
  *
  * @param mixed $data  Data to add (string, resource, or Horde_Stream
  *                     object).
  */
 public function add($data)
 {
     $this->_stream->add($data);
 }
Example #5
0
 /**
  * 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();
 }
Example #6
0
 /**
  * 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;
 }
Example #7
0
 /**
  * Add data to buffer.
  *
  * @param mixed $data  Data to add (string, resource, or Horde_Stream
  *                     object).
  */
 public function add($data)
 {
     if (!$this->_parent) {
         $this->stream->add($data);
     }
 }