Back to index

d-push  2.0
mapistreamwrapper.php
Go to the documentation of this file.
00001 <?php
00002 /***********************************************
00003 * File      :   mapistreamwrapper.php
00004 * Project   :   Z-Push
00005 * Descr     :   Wraps a mapi stream as a standard php stream
00006 *               The used method names are predefined and can not be altered.
00007 *
00008 * Created   :   24.11.2011
00009 *
00010 * Copyright 2007 - 2011 Zarafa Deutschland GmbH
00011 *
00012 * This program is free software: you can redistribute it and/or modify
00013 * it under the terms of the GNU Affero General Public License, version 3,
00014 * as published by the Free Software Foundation with the following additional
00015 * term according to sec. 7:
00016 *
00017 * According to sec. 7 of the GNU Affero General Public License, version 3,
00018 * the terms of the AGPL are supplemented with the following terms:
00019 *
00020 * "Zarafa" is a registered trademark of Zarafa B.V.
00021 * "Z-Push" is a registered trademark of Zarafa Deutschland GmbH
00022 * The licensing of the Program under the AGPL does not imply a trademark license.
00023 * Therefore any rights, title and interest in our trademarks remain entirely with us.
00024 *
00025 * However, if you propagate an unmodified version of the Program you are
00026 * allowed to use the term "Z-Push" to indicate that you distribute the Program.
00027 * Furthermore you may use our trademarks where it is necessary to indicate
00028 * the intended purpose of a product or service provided you use it in accordance
00029 * with honest practices in industrial or commercial matters.
00030 * If you want to propagate modified versions of the Program under the name "Z-Push",
00031 * you may only do so if you have a written permission by Zarafa Deutschland GmbH
00032 * (to acquire a permission please contact Zarafa at trademark@zarafa.com).
00033 *
00034 * This program is distributed in the hope that it will be useful,
00035 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00036 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00037 * GNU Affero General Public License for more details.
00038 *
00039 * You should have received a copy of the GNU Affero General Public License
00040 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00041 *
00042 * Consult LICENSE file for details
00043 ************************************************/
00044 
00045 class MAPIStreamWrapper {
00046     const PROTOCOL = "mapistream";
00047 
00048     private $mapistream;
00049     private $position;
00050     private $streamlength;
00051 
00065     public function stream_open($path, $mode, $options, &$opened_path) {
00066         $contextOptions = stream_context_get_options($this->context);
00067         if (!isset($contextOptions[self::PROTOCOL]['stream']))
00068             return false;
00069 
00070         $this->position = 0;
00071 
00072         // this is our stream!
00073         $this->mapistream = $contextOptions[self::PROTOCOL]['stream'];
00074 
00075         // get the data length from mapi
00076         $stat = mapi_stream_stat($this->mapistream);
00077         $this->streamlength = $stat["cb"];
00078         ZLog::Write(LOGLEVEL_DEBUG, sprintf("MAPIStreamWrapper::stream_open(): initialized mapistream: %s streamlength: %d", $this->mapistream, $this->streamlength));
00079 
00080         return true;
00081     }
00082 
00091     public function stream_read($len) {
00092         $data = mapi_stream_read($this->mapistream, $len);
00093         $this->position += strlen($data);
00094         return $data;
00095     }
00096 
00103     public function stream_tell() {
00104         return $this->position;
00105     }
00106 
00113     public function stream_eof() {
00114         return ($this->position >= $this->streamlength);
00115     }
00116 
00125      static public function Open($mapistream) {
00126         $context = stream_context_create(array(self::PROTOCOL => array('stream' => &$mapistream)));
00127         return fopen(self::PROTOCOL . "://",'r', false, $context);
00128     }
00129 }
00130 
00131 stream_wrapper_register(MAPIStreamWrapper::PROTOCOL, "MAPIStreamWrapper")
00132 
00133 ?>