Example #1
0
 /**
  * A wrapper for mapi_inetmapi_imtoinet function.
  *
  * @param MAPIMessage       $mapimessage
  * @param SyncObject        $message
  *
  * @access private
  * @return boolean
  */
 private function imtoinet($mapimessage, &$message)
 {
     if (function_exists("mapi_inetmapi_imtoinet")) {
         $addrbook = $this->getAddressbook();
         $stream = mapi_inetmapi_imtoinet($this->session, $addrbook, $mapimessage, array('use_tnef' => -1));
         if (is_resource($stream)) {
             $mstreamstat = mapi_stream_stat($stream);
             $streamsize = $mstreamstat["cb"];
             if (isset($streamsize)) {
                 if (Request::GetProtocolVersion() >= 12.0) {
                     if (!isset($message->asbody)) {
                         $message->asbody = new SyncBaseBody();
                     }
                     $message->asbody->data = MAPIStreamWrapper::Open($stream);
                     $message->asbody->estimatedDataSize = $streamsize;
                     $message->asbody->truncated = 0;
                 } else {
                     $message->mimedata = MAPIStreamWrapper::Open($stream);
                     $message->mimesize = $streamsize;
                     $message->mimetruncated = 0;
                 }
                 unset($message->body, $message->bodytruncated);
                 return true;
             }
         }
         ZLog::Write(LOGLEVEL_ERROR, sprintf("MAPIProvider->imtoinet(): got no stream or content from mapi_inetmapi_imtoinet()"));
     }
     return false;
 }
Example #2
0
 /**
  * Returns the content of the named attachment as stream
  *
  * @param string        $attname
  * @access public
  * @return SyncItemOperationsAttachment
  * @throws StatusException
  */
 public function GetAttachmentData($attname)
 {
     ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->GetAttachmentData('%s')", $attname));
     if (!strpos($attname, ":")) {
         throw new StatusException(sprintf("KopanoBackend->GetAttachmentData('%s'): Error, attachment requested for non-existing item", $attname), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT);
     }
     list($id, $attachnum, $parentEntryid) = explode(":", $attname);
     if (isset($parentEntryid)) {
         $this->Setup(ZPush::GetAdditionalSyncFolderStore($parentEntryid));
     }
     $entryid = hex2bin($id);
     $message = mapi_msgstore_openentry($this->store, $entryid);
     if (!$message) {
         throw new StatusException(sprintf("KopanoBackend->GetAttachmentData('%s'): Error, unable to open item for attachment data for id '%s' with: 0x%X", $attname, $id, mapi_last_hresult()), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT);
     }
     MAPIUtils::ParseSmime($this->session, $this->defaultstore, $this->getAddressbook(), $message);
     $attach = mapi_message_openattach($message, $attachnum);
     if (!$attach) {
         throw new StatusException(sprintf("KopanoBackend->GetAttachmentData('%s'): Error, unable to open attachment number '%s' with: 0x%X", $attname, $attachnum, mapi_last_hresult()), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT);
     }
     // get necessary attachment props
     $attprops = mapi_getprops($attach, array(PR_ATTACH_MIME_TAG, PR_ATTACH_MIME_TAG_W, PR_ATTACH_METHOD));
     $attachment = new SyncItemOperationsAttachment();
     // check if it's an embedded message and open it in such a case
     if (isset($attprops[PR_ATTACH_METHOD]) && $attprops[PR_ATTACH_METHOD] == ATTACH_EMBEDDED_MSG) {
         $embMessage = mapi_attach_openobj($attach);
         $addrbook = $this->getAddressbook();
         $stream = mapi_inetmapi_imtoinet($this->session, $addrbook, $embMessage, array('use_tnef' => -1));
         // set the default contenttype for this kind of messages
         $attachment->contenttype = "message/rfc822";
     } else {
         $stream = mapi_openpropertytostream($attach, PR_ATTACH_DATA_BIN);
     }
     if (!$stream) {
         throw new StatusException(sprintf("KopanoBackend->GetAttachmentData('%s'): Error, unable to open attachment data stream: 0x%X", $attname, mapi_last_hresult()), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT);
     }
     // put the mapi stream into a wrapper to get a standard stream
     $attachment->data = MAPIStreamWrapper::Open($stream);
     if (isset($attprops[PR_ATTACH_MIME_TAG])) {
         $attachment->contenttype = $attprops[PR_ATTACH_MIME_TAG];
     } elseif (isset($attprops[PR_ATTACH_MIME_TAG_W])) {
         $attachment->contenttype = $attprops[PR_ATTACH_MIME_TAG_W];
     }
     //TODO default contenttype
     return $attachment;
 }