Back to index

d-push  2.0
itemoperations.php
Go to the documentation of this file.
00001 <?php
00002 /***********************************************
00003 * File      :   itemoperations.php
00004 * Project   :   Z-Push
00005 * Descr     :   Provides the ItemOperations 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 ItemOperations extends RequestProcessor {
00045 
00055     public function Handle($commandCode) {
00056         // Parse input
00057         if(!self::$decoder->getElementStartTag(SYNC_ITEMOPERATIONS_ITEMOPERATIONS))
00058             return false;
00059 
00060         //TODO check if multiple item operations are possible in one request
00061         $el = self::$decoder->getElement();
00062 
00063         if($el[EN_TYPE] != EN_TYPE_STARTTAG)
00064             return false;
00065         //ItemOperations can either be Fetch, EmptyFolderContents or Move
00066         $fetch = $efc = $move = false;
00067         if($el[EN_TAG] == SYNC_ITEMOPERATIONS_FETCH)
00068             $fetch = true;
00069         else if($el[EN_TAG] == SYNC_ITEMOPERATIONS_EMPTYFOLDERCONTENTS)
00070             $efc = true;
00071         else if($el[EN_TAG] == SYNC_ITEMOPERATIONS_MOVE)
00072             $move = true;
00073 
00074         if(!$fetch && !$efc && !$move) {
00075             ZLog::Write(LOGLEVEL_DEBUG, "Unknown item operation:".print_r($el, 1));
00076             return false;
00077         }
00078 
00079         if ($fetch) {
00080             if(!self::$decoder->getElementStartTag(SYNC_ITEMOPERATIONS_STORE))
00081                 return false;
00082             $store = self::$decoder->getElementContent();
00083             if(!self::$decoder->getElementEndTag())
00084                 return false;//SYNC_ITEMOPERATIONS_STORE
00085 
00086             if(self::$decoder->getElementStartTag(SYNC_SEARCH_LONGID)) {
00087                 $longid = self::$decoder->getElementContent();
00088                 if(!self::$decoder->getElementEndTag())
00089                     return false;//SYNC_SEARCH_LONGID
00090             }
00091 
00092             if(self::$decoder->getElementStartTag(SYNC_FOLDERID)) {
00093                 $folderid = self::$decoder->getElementContent();
00094                 if(!self::$decoder->getElementEndTag())
00095                     return false;//SYNC_FOLDERID
00096             }
00097 
00098             if(self::$decoder->getElementStartTag(SYNC_SERVERENTRYID)) {
00099                 $serverid = self::$decoder->getElementContent();
00100                 if(!self::$decoder->getElementEndTag())
00101                     return false;//SYNC_SERVERENTRYID
00102             }
00103 
00104             if(self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_FILEREFERENCE)) {
00105                 $filereference = self::$decoder->getElementContent();
00106                 if(!self::$decoder->getElementEndTag())
00107                     return false;//SYNC_AIRSYNCBASE_FILEREFERENCE
00108             }
00109 
00110             if(self::$decoder->getElementStartTag(SYNC_ITEMOPERATIONS_OPTIONS)) {
00111                 //TODO other options
00112                 //schema
00113                 //range
00114                 //username
00115                 //password
00116                 //bodypartpreference
00117                 //rm:RightsManagementSupport
00118 
00119                 // Save all OPTIONS into a ContentParameters object
00120                 $collection["cpo"] = new ContentParameters();
00121                 while(1) {
00122                     while (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_BODYPREFERENCE)) {
00123                         if(self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_TYPE)) {
00124                             $bptype = self::$decoder->getElementContent();
00125                             $collection["cpo"]->BodyPreference($bptype);
00126                             if(!self::$decoder->getElementEndTag()) {
00127                                 return false;
00128                             }
00129                         }
00130 
00131                         if(self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_TRUNCATIONSIZE)) {
00132                             $collection["cpo"]->BodyPreference($bptype)->SetTruncationSize(self::$decoder->getElementContent());
00133                             if(!self::$decoder->getElementEndTag())
00134                                 return false;
00135                         }
00136 
00137                         if(self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_ALLORNONE)) {
00138                             $collection["cpo"]->BodyPreference($bptype)->SetAllOrNone(self::$decoder->getElementContent());
00139                             if(!self::$decoder->getElementEndTag())
00140                                 return false;
00141                         }
00142 
00143                         if(self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_PREVIEW)) {
00144                             $collection["cpo"]->BodyPreference($bptype)->SetPreview(self::$decoder->getElementContent());
00145                             if(!self::$decoder->getElementEndTag())
00146                                 return false;
00147                         }
00148 
00149                         if(!self::$decoder->getElementEndTag())
00150                             return false;//SYNC_AIRSYNCBASE_BODYPREFERENCE
00151                     }
00152 
00153                     if(self::$decoder->getElementStartTag(SYNC_MIMESUPPORT)) {
00154                         $collection["cpo"]->SetMimeSupport(self::$decoder->getElementContent());
00155                         if(!self::$decoder->getElementEndTag())
00156                         return false;
00157                     }
00158 
00159                     //break if it reached the endtag
00160                     $e = self::$decoder->peek();
00161                     if($e[EN_TYPE] == EN_TYPE_ENDTAG) {
00162                         self::$decoder->getElementEndTag();
00163                         break;
00164                     }
00165                 }
00166             }
00167         }
00168 
00169         if ($efc) {
00170             if(self::$decoder->getElementStartTag(SYNC_FOLDERID)) {
00171                 $folderid = self::$decoder->getElementContent();
00172                 if(!self::$decoder->getElementEndTag())
00173                     return false;//SYNC_FOLDERID
00174             }
00175             if(self::$decoder->getElementStartTag(SYNC_ITEMOPERATIONS_OPTIONS)) {
00176                 if(self::$decoder->getElementStartTag(SYNC_ITEMOPERATIONS_DELETESUBFOLDERS)) {
00177                     $deletesubfolders = true;
00178                     if (($dsf = self::$decoder->getElementContent()) !== false) {
00179                         $deletesubfolders = (boolean)$dsf;
00180                         if(!self::$decoder->getElementEndTag())
00181                             return false;
00182                     }
00183                 }
00184                 self::$decoder->getElementEndTag();
00185             }
00186         }
00187 
00188         //TODO EmptyFolderContents
00189         //TODO move
00190 
00191         if(!self::$decoder->getElementEndTag())
00192             return false;//SYNC_ITEMOPERATIONS_ITEMOPERATIONS
00193 
00194         $status = SYNC_ITEMOPERATIONSSTATUS_SUCCESS;
00195         //TODO status handling
00196 
00197         self::$encoder->startWBXML();
00198 
00199         self::$encoder->startTag(SYNC_ITEMOPERATIONS_ITEMOPERATIONS);
00200 
00201         self::$encoder->startTag(SYNC_ITEMOPERATIONS_STATUS);
00202         self::$encoder->content($status);
00203         self::$encoder->endTag();//SYNC_ITEMOPERATIONS_STATUS
00204 
00205         self::$encoder->startTag(SYNC_ITEMOPERATIONS_RESPONSE);
00206 
00207         // fetch response
00208         if ($fetch) {
00209             self::$encoder->startTag(SYNC_ITEMOPERATIONS_FETCH);
00210 
00211                 self::$encoder->startTag(SYNC_ITEMOPERATIONS_STATUS);
00212                 self::$encoder->content($status);
00213                 self::$encoder->endTag();//SYNC_ITEMOPERATIONS_STATUS
00214 
00215                 if (isset($folderid) && isset($serverid)) {
00216                     self::$encoder->startTag(SYNC_FOLDERID);
00217                     self::$encoder->content($folderid);
00218                     self::$encoder->endTag(); // end SYNC_FOLDERID
00219 
00220                     self::$encoder->startTag(SYNC_SERVERENTRYID);
00221                     self::$encoder->content($serverid);
00222                     self::$encoder->endTag(); // end SYNC_SERVERENTRYID
00223 
00224                     self::$encoder->startTag(SYNC_FOLDERTYPE);
00225                     self::$encoder->content("Email");
00226                     self::$encoder->endTag();
00227 
00228                     $data = self::$backend->Fetch($folderid, $serverid, $collection["cpo"]);
00229                 }
00230 
00231                 if (isset($longid)) {
00232                     self::$encoder->startTag(SYNC_SEARCH_LONGID);
00233                     self::$encoder->content($longid);
00234                     self::$encoder->endTag(); // end SYNC_FOLDERID
00235 
00236                     self::$encoder->startTag(SYNC_FOLDERTYPE);
00237                     self::$encoder->content("Email");
00238                     self::$encoder->endTag();
00239 
00240                     $tmp = explode(":", $longid);
00241                     $data = self::$backend->Fetch($tmp[0], $tmp[1], $collection["cpo"]);
00242                 }
00243 
00244                 if (isset($filereference)) {
00245                     self::$encoder->startTag(SYNC_AIRSYNCBASE_FILEREFERENCE);
00246                     self::$encoder->content($filereference);
00247                     self::$encoder->endTag(); // end SYNC_AIRSYNCBASE_FILEREFERENCE
00248 
00249                     $data = self::$backend->GetAttachmentData($filereference);
00250                 }
00251 
00252                 //TODO put it in try catch block
00253 
00254                 if (isset($data)) {
00255                     self::$encoder->startTag(SYNC_ITEMOPERATIONS_PROPERTIES);
00256                     $data->Encode(self::$encoder);
00257                     self::$encoder->endTag(); //SYNC_ITEMOPERATIONS_PROPERTIES
00258                 }
00259 
00260             self::$encoder->endTag();//SYNC_ITEMOPERATIONS_FETCH
00261         }
00262         // empty folder contents operation
00263         else if ($efc) {
00264             try {
00265                 // send request to backend
00266                 self::$backend-> EmptyFolder($folderid, $deletesubfolders);
00267             }
00268             catch (StatusException $stex) {
00269                $status = $stex->getCode();
00270             }
00271 
00272             self::$encoder->startTag(SYNC_ITEMOPERATIONS_EMPTYFOLDERCONTENTS);
00273 
00274                 self::$encoder->startTag(SYNC_ITEMOPERATIONS_STATUS);
00275                 self::$encoder->content($status);
00276                 self::$encoder->endTag();//SYNC_ITEMOPERATIONS_STATUS
00277 
00278                 if (isset($folderid)) {
00279                     self::$encoder->startTag(SYNC_FOLDERID);
00280                     self::$encoder->content($folderid);
00281                     self::$encoder->endTag(); // end SYNC_FOLDERID
00282                 }
00283             self::$encoder->endTag();//SYNC_ITEMOPERATIONS_EMPTYFOLDERCONTENTS
00284         }
00285         // TODO implement ItemOperations Move
00286         // move operation
00287         else {
00288             self::$encoder->startTag(SYNC_ITEMOPERATIONS_MOVE);
00289                 self::$encoder->startTag(SYNC_ITEMOPERATIONS_STATUS);
00290                 self::$encoder->content($status);
00291                 self::$encoder->endTag();//SYNC_ITEMOPERATIONS_STATUS
00292             self::$encoder->endTag();//SYNC_ITEMOPERATIONS_MOVE
00293         }
00294 
00295         self::$encoder->endTag();//SYNC_ITEMOPERATIONS_RESPONSE
00296         self::$encoder->endTag();//SYNC_ITEMOPERATIONS_ITEMOPERATIONS
00297 
00298         return true;
00299     }
00300 }
00301 ?>