Back to index

d-push  2.0
getattachment.php
Go to the documentation of this file.
00001 <?php
00002 /***********************************************
00003 * File      :   getattachment.php
00004 * Project   :   Z-Push
00005 * Descr     :   Provides the GETATTACHMENT command
00006 *
00007 * Created   :   16.02.2012
00008 *
00009 * Copyright 2007 - 2012 Zarafa Deutschland GmbH
00010 *
00011 * This program is free software: you can redistribute it and/or modify
00012 * it under the terms of the GNU Affero General Public License, version 3,
00013 * as published by the Free Software Foundation with the following additional
00014 * term according to sec. 7:
00015 *
00016 * According to sec. 7 of the GNU Affero General Public License, version 3,
00017 * the terms of the AGPL are supplemented with the following terms:
00018 *
00019 * "Zarafa" is a registered trademark of Zarafa B.V.
00020 * "Z-Push" is a registered trademark of Zarafa Deutschland GmbH
00021 * The licensing of the Program under the AGPL does not imply a trademark license.
00022 * Therefore any rights, title and interest in our trademarks remain entirely with us.
00023 *
00024 * However, if you propagate an unmodified version of the Program you are
00025 * allowed to use the term "Z-Push" to indicate that you distribute the Program.
00026 * Furthermore you may use our trademarks where it is necessary to indicate
00027 * the intended purpose of a product or service provided you use it in accordance
00028 * with honest practices in industrial or commercial matters.
00029 * If you want to propagate modified versions of the Program under the name "Z-Push",
00030 * you may only do so if you have a written permission by Zarafa Deutschland GmbH
00031 * (to acquire a permission please contact Zarafa at trademark@zarafa.com).
00032 *
00033 * This program is distributed in the hope that it will be useful,
00034 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00035 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00036 * GNU Affero General Public License for more details.
00037 *
00038 * You should have received a copy of the GNU Affero General Public License
00039 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00040 *
00041 * Consult LICENSE file for details
00042 ************************************************/
00043 
00044 class GetAttachment extends RequestProcessor {
00045 
00054     public function Handle($commandCode) {
00055         $attname = Request::GetGETAttachmentName();
00056         if(!$attname)
00057             return false;
00058 
00059         try {
00060             $attachment = self::$backend->GetAttachmentData($attname);
00061             $stream = $attachment->data;
00062             ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandleGetAttachment(): attachment stream from backend: %s", $stream));
00063 
00064             header("Content-Type: application/octet-stream");
00065             $l = 0;
00066             while (!feof($stream)) {
00067                 $d = fgets($stream, 4096);
00068                 $l += strlen($d);
00069                 echo $d;
00070 
00071                 // announce an update every 100K
00072                 if (($l/1024) % 100 == 0)
00073                     self::$topCollector->AnnounceInformation(sprintf("Streaming attachment: %d KB sent", round($l/1024)));
00074             }
00075             fclose($stream);
00076             self::$topCollector->AnnounceInformation(sprintf("Streamed %d KB attachment", $l/1024), true);
00077             ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandleGetAttachment(): attachment with %d KB sent to mobile", $l/1024));
00078 
00079         }
00080         catch (StatusException $s) {
00081             // StatusException already logged so we just need to pass it upwards to send a HTTP error
00082             throw new HTTPReturnCodeException($s->getMessage(), HTTP_CODE_500, null, LOGLEVEL_DEBUG);
00083         }
00084 
00085         return true;
00086     }
00087 }
00088 ?>