/**
 * Function which recurring task to next occurrence.
 * It simply doesn't regenerate task
 @param array $action
 */
 function deleteOccurrence($action)
 {
     $this->tz = false;
     $this->action = $action;
     $result = $this->moveToNextOccurrence();
     mapi_savechanges($this->message);
     return $result;
 }
예제 #2
0
 /**
  * Copies attachments from one message to another.
  *
  * @param MAPIMessage $toMessage
  * @param MAPIMessage $fromMessage
  *
  * @return void
  */
 private function copyAttachments(&$toMessage, $fromMessage)
 {
     $attachtable = mapi_message_getattachmenttable($fromMessage);
     $rows = mapi_table_queryallrows($attachtable, array(PR_ATTACH_NUM));
     foreach ($rows as $row) {
         if (isset($row[PR_ATTACH_NUM])) {
             $attach = mapi_message_openattach($fromMessage, $row[PR_ATTACH_NUM]);
             $newattach = mapi_message_createattach($toMessage);
             // Copy all attachments from old to new attachment
             $attachprops = mapi_getprops($attach);
             mapi_setprops($newattach, $attachprops);
             if (isset($attachprops[mapi_prop_tag(PT_ERROR, mapi_prop_id(PR_ATTACH_DATA_BIN))])) {
                 // Data is in a stream
                 $srcstream = mapi_openpropertytostream($attach, PR_ATTACH_DATA_BIN);
                 $dststream = mapi_openpropertytostream($newattach, PR_ATTACH_DATA_BIN, MAPI_MODIFY | MAPI_CREATE);
                 while (1) {
                     $data = mapi_stream_read($srcstream, 4096);
                     if (strlen($data) == 0) {
                         break;
                     }
                     mapi_stream_write($dststream, $data);
                 }
                 mapi_stream_commit($dststream);
             }
             mapi_savechanges($newattach);
         }
     }
 }
예제 #3
0
 /**
  * Imports a change on a folder
  *
  * @param object        $folder     SyncFolder
  *
  * @access public
  * @return string       id of the folder
  * @throws StatusException
  */
 public function ImportFolderChange($folder)
 {
     $id = isset($folder->serverid) ? $folder->serverid : false;
     $parent = $folder->parentid;
     $displayname = u2wi($folder->displayname);
     $type = $folder->type;
     if (Utils::IsSystemFolder($type)) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, system folder can not be created/modified", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname), SYNC_FSSTATUS_SYSTEMFOLDER);
     }
     // create a new folder if $id is not set
     if (!$id) {
         // the root folder is "0" - get IPM_SUBTREE
         if ($parent == "0") {
             $parentprops = mapi_getprops($this->store, array(PR_IPM_SUBTREE_ENTRYID));
             if (isset($parentprops[PR_IPM_SUBTREE_ENTRYID])) {
                 $parentfentryid = $parentprops[PR_IPM_SUBTREE_ENTRYID];
             }
         } else {
             $parentfentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($parent));
         }
         if (!$parentfentryid) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open parent folder (no entry id)", Utils::PrintAsString(false), $folder->parentid, $displayname), SYNC_FSSTATUS_PARENTNOTFOUND);
         }
         $parentfolder = mapi_msgstore_openentry($this->store, $parentfentryid);
         if (!$parentfolder) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open parent folder (open entry)", Utils::PrintAsString(false), $folder->parentid, $displayname), SYNC_FSSTATUS_PARENTNOTFOUND);
         }
         //  mapi_folder_createfolder() fails if a folder with this name already exists -> MAPI_E_COLLISION
         $newfolder = mapi_folder_createfolder($parentfolder, $displayname, "");
         if (mapi_last_hresult()) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, mapi_folder_createfolder() failed: 0x%X", Utils::PrintAsString(false), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_FOLDEREXISTS);
         }
         mapi_setprops($newfolder, array(PR_CONTAINER_CLASS => MAPIUtils::GetContainerClassFromFolderType($type)));
         $props = mapi_getprops($newfolder, array(PR_SOURCE_KEY));
         if (isset($props[PR_SOURCE_KEY])) {
             $sourcekey = bin2hex($props[PR_SOURCE_KEY]);
             ZLog::Write(LOGLEVEL_DEBUG, sprintf("Created folder '%s' with id: '%s'", $displayname, $sourcekey));
             return $sourcekey;
         } else {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, folder created but PR_SOURCE_KEY not available: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR);
         }
         return false;
     }
     // update folder
     $entryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($id));
     if (!$entryid) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open folder (no entry id): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_PARENTNOTFOUND);
     }
     $folder = mapi_msgstore_openentry($this->store, $entryid);
     if (!$folder) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open folder (open entry): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_PARENTNOTFOUND);
     }
     $props = mapi_getprops($folder, array(PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY, PR_DISPLAY_NAME, PR_CONTAINER_CLASS));
     if (!isset($props[PR_SOURCE_KEY]) || !isset($props[PR_PARENT_SOURCE_KEY]) || !isset($props[PR_DISPLAY_NAME]) || !isset($props[PR_CONTAINER_CLASS])) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, folder data not available: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR);
     }
     if ($parent == "0") {
         $parentprops = mapi_getprops($this->store, array(PR_IPM_SUBTREE_ENTRYID));
         $parentfentryid = $parentprops[PR_IPM_SUBTREE_ENTRYID];
         $mapifolder = mapi_msgstore_openentry($this->store, $parentfentryid);
         $rootfolderprops = mapi_getprops($mapifolder, array(PR_SOURCE_KEY));
         $parent = bin2hex($rootfolderprops[PR_SOURCE_KEY]);
         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportChangesICS->ImportFolderChange(): resolved AS parent '0' to sourcekey '%s'", $parent));
     }
     // In theory the parent id could change, which means that the folder was moved.
     // It is unknown if any device supports this, so we do currently not implement it (no known device is able to do this)
     if (bin2hex($props[PR_PARENT_SOURCE_KEY]) !== $parent) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Folder was moved to another location, which is currently not supported. Please report this to the Z-Push dev team together with the WBXML log and your device details (model, firmware etc).", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_UNKNOWNERROR);
     }
     $props = array(PR_DISPLAY_NAME => $displayname);
     mapi_setprops($folder, $props);
     mapi_savechanges($folder);
     if (mapi_last_hresult()) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, mapi_savechanges() failed: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR);
     }
     ZLog::Write(LOGLEVEL_DEBUG, "Imported changes for folder: {$id}");
     return $id;
 }
예제 #4
0
파일: ics.php 프로젝트: nnaannoo/paskot
 function _storeAttachment($mapimessage, $part)
 {
     // attachment
     $attach = mapi_message_createattach($mapimessage);
     $filename = "";
     // Filename is present in both Content-Type: name=.. and in Content-Disposition: filename=
     if (isset($part->ctype_parameters["name"])) {
         $filename = $part->ctype_parameters["name"];
     } else {
         if (isset($part->d_parameters["name"])) {
             $filename = $part->d_parameters["filename"];
         } else {
             if (isset($part->d_parameters["filename"])) {
                 // sending appointment with nokia & android only filename is set
                 $filename = $part->d_parameters["filename"];
             } else {
                 if (isset($part->d_parameters["filename*0"])) {
                     for ($i = 0; $i < count($part->d_parameters); $i++) {
                         if (isset($part->d_parameters["filename*" . $i])) {
                             $filename .= $part->d_parameters["filename*" . $i];
                         }
                     }
                 } else {
                     $filename = "untitled";
                 }
             }
         }
     }
     // Android just doesn't send content-type, so mimeDecode doesn't performs base64 decoding
     // on meeting requests text/calendar somewhere inside content-transfer-encoding
     if (isset($part->headers['content-transfer-encoding']) && strpos($part->headers['content-transfer-encoding'], 'base64')) {
         if (strpos($part->headers['content-transfer-encoding'], 'text/calendar') !== false) {
             $part->ctype_primary = 'text';
             $part->ctype_secondary = 'calendar';
         }
         if (!isset($part->headers['content-type'])) {
             $part->body = base64_decode($part->body);
         }
     }
     // Set filename and attachment type
     mapi_setprops($attach, array(PR_ATTACH_LONG_FILENAME => u2wi($filename), PR_ATTACH_METHOD => ATTACH_BY_VALUE));
     // Set attachment data
     mapi_setprops($attach, array(PR_ATTACH_DATA_BIN => $part->body));
     // Set MIME type
     mapi_setprops($attach, array(PR_ATTACH_MIME_TAG => $part->ctype_primary . "/" . $part->ctype_secondary));
     mapi_savechanges($attach);
 }
예제 #5
0
 /**
  * Function which saves the exception data in an attachment.
  * @param array $exception_props the exception data (like any other MAPI appointment)
  * @param array $exception_recips list of recipients
  * @param mapi_message $copy_attach_from mapi message from which attachments should be copied
  * @return array properties of the exception
  */
 function createExceptionAttachment($exception_props, $exception_recips = array(), $copy_attach_from = false)
 {
     // Create new attachment.
     $attachment = mapi_message_createattach($this->message);
     $props = array();
     $props[PR_ATTACHMENT_FLAGS] = 2;
     $props[PR_ATTACHMENT_HIDDEN] = true;
     $props[PR_ATTACHMENT_LINKID] = 0;
     $props[PR_ATTACH_FLAGS] = 0;
     $props[PR_ATTACH_METHOD] = 5;
     $props[PR_DISPLAY_NAME] = "Exception";
     $props[PR_EXCEPTION_STARTTIME] = $this->fromGMT($this->tz, $exception_props[$this->proptags["startdate"]]);
     $props[PR_EXCEPTION_ENDTIME] = $this->fromGMT($this->tz, $exception_props[$this->proptags["duedate"]]);
     mapi_message_setprops($attachment, $props);
     $imessage = mapi_attach_openobj($attachment, MAPI_CREATE | MAPI_MODIFY);
     if ($copy_attach_from) {
         $attachmentTable = mapi_message_getattachmenttable($copy_attach_from);
         if ($attachmentTable) {
             $attachments = mapi_table_queryallrows($attachmentTable, array(PR_ATTACH_NUM, PR_ATTACH_SIZE, PR_ATTACH_LONG_FILENAME, PR_ATTACHMENT_HIDDEN, PR_DISPLAY_NAME, PR_ATTACH_METHOD));
             foreach ($attachments as $attach_props) {
                 $attach_old = mapi_message_openattach($copy_attach_from, (int) $attach_props[PR_ATTACH_NUM]);
                 $attach_newResourceMsg = mapi_message_createattach($imessage);
                 mapi_copyto($attach_old, array(), array(), $attach_newResourceMsg, 0);
                 mapi_savechanges($attach_newResourceMsg);
             }
         }
     }
     $props = $props + $exception_props;
     // FIXME: the following piece of code is written to fix the creation
     // of an exception. This is only a quickfix as it is not yet possible
     // to change an existing exception.
     // remove mv properties when needed
     foreach ($props as $propTag => $propVal) {
         if ((mapi_prop_type($propTag) & MV_FLAG) == MV_FLAG && is_null($propVal)) {
             unset($props[$propTag]);
         }
     }
     mapi_message_setprops($imessage, $props);
     $this->setExceptionRecipients($imessage, $exception_recips, true);
     mapi_message_savechanges($imessage);
     mapi_message_savechanges($attachment);
 }
 /**
  * Updates a card
  * 
  * @param mixed $addressBookId 
  * @param string $cardUri 
  * @param string $cardData 
  * @return bool 
  */
 public function updateCard($addressBookId, $cardUri, $cardData)
 {
     $this->logger->info("updateCard - {$cardUri}");
     if (READ_ONLY) {
         $this->logger->warn("Cannot update card: read-only");
         return false;
     }
     // Update object properties
     $entryId = $this->getContactEntryId($addressBookId, $cardUri);
     if ($entryId === 0) {
         $this->logger->warn("Cannot find contact");
         return false;
     }
     $mapiProperties = $this->bridge->vcardToMapiProperties($cardData);
     $contact = mapi_msgstore_openentry($this->bridge->getStore($addressBookId), $entryId);
     if (SAVE_RAW_VCARD) {
         // Save RAW vCard
         $this->logger->debug("Saving raw vcard");
         $mapiProperties[PR_CARDDAV_RAW_DATA] = $cardData;
         $mapiProperties[PR_CARDDAV_RAW_DATA_GENERATION_TIME] = time();
     } else {
         $this->logger->trace("Saving raw vcard skiped by config");
     }
     // Handle contact picture
     if (array_key_exists('ContactPicture', $mapiProperties)) {
         $this->logger->debug("Updating contact picture");
         $contactPicture = $mapiProperties['ContactPicture'];
         unset($mapiProperties['ContactPicture']);
         $this->bridge->setContactPicture($contact, $contactPicture);
     }
     // Remove NULL properties
     if (CLEAR_MISSING_PROPERTIES) {
         $this->logger->debug("Clearing missing properties");
         $nullProperties = array();
         foreach ($mapiProperties as $p => $v) {
             if ($v == NULL) {
                 $nullProperties[] = $p;
                 unset($mapiProperties[$p]);
             }
         }
         $dump = print_r($nullProperties, true);
         $this->logger->trace("Removing properties\n{$dump}");
         mapi_deleteprops($contact, $nullProperties);
     }
     // Set properties
     $mapiProperties[PR_LAST_MODIFICATION_TIME] = time();
     mapi_setprops($contact, $mapiProperties);
     // Save changes to backend
     mapi_savechanges($contact);
     return mapi_last_hresult() == 0;
 }
예제 #7
0
 /**
  * Imports a change on a folder
  *
  * @param object        $folder     SyncFolder
  *
  * @access public
  * @return string       id of the folder
  * @throws StatusException
  */
 public function ImportFolderChange($folder)
 {
     $id = isset($folder->serverid) ? $folder->serverid : false;
     $parent = $folder->parentid;
     $displayname = u2wi($folder->displayname);
     $type = $folder->type;
     if (Utils::IsSystemFolder($type)) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, system folder can not be created/modified", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname), SYNC_FSSTATUS_SYSTEMFOLDER);
     }
     // create a new folder if $id is not set
     if (!$id) {
         // the root folder is "0" - get IPM_SUBTREE
         if ($parent == "0") {
             $parentprops = mapi_getprops($this->store, array(PR_IPM_SUBTREE_ENTRYID));
             if (isset($parentprops[PR_IPM_SUBTREE_ENTRYID])) {
                 $parentfentryid = $parentprops[PR_IPM_SUBTREE_ENTRYID];
             }
         } else {
             $parentfentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($parent));
         }
         if (!$parentfentryid) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open parent folder (no entry id)", Utils::PrintAsString(false), $folder->parentid, $displayname), SYNC_FSSTATUS_PARENTNOTFOUND);
         }
         $parentfolder = mapi_msgstore_openentry($this->store, $parentfentryid);
         if (!$parentfolder) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open parent folder (open entry)", Utils::PrintAsString(false), $folder->parentid, $displayname), SYNC_FSSTATUS_PARENTNOTFOUND);
         }
         //  mapi_folder_createfolder() fails if a folder with this name already exists -> MAPI_E_COLLISION
         $newfolder = mapi_folder_createfolder($parentfolder, $displayname, "");
         if (mapi_last_hresult()) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, mapi_folder_createfolder() failed: 0x%X", Utils::PrintAsString(false), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_FOLDEREXISTS);
         }
         mapi_setprops($newfolder, array(PR_CONTAINER_CLASS => MAPIUtils::GetContainerClassFromFolderType($type)));
         $props = mapi_getprops($newfolder, array(PR_SOURCE_KEY));
         if (isset($props[PR_SOURCE_KEY])) {
             $sourcekey = bin2hex($props[PR_SOURCE_KEY]);
             ZLog::Write(LOGLEVEL_DEBUG, sprintf("Created folder '%s' with id: '%s'", $displayname, $sourcekey));
             return $sourcekey;
         } else {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, folder created but PR_SOURCE_KEY not available: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR);
         }
         return false;
     }
     // open folder for update
     $entryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($id));
     if (!$entryid) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open folder (no entry id): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_PARENTNOTFOUND);
     }
     // check if this is a MAPI default folder
     if ($this->mapiprovider->IsMAPIDefaultFolder($entryid)) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, MAPI default folder can not be created/modified", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname), SYNC_FSSTATUS_SYSTEMFOLDER);
     }
     $mfolder = mapi_msgstore_openentry($this->store, $entryid);
     if (!$mfolder) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open folder (open entry): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_PARENTNOTFOUND);
     }
     $props = mapi_getprops($mfolder, array(PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY, PR_DISPLAY_NAME, PR_CONTAINER_CLASS));
     if (!isset($props[PR_SOURCE_KEY]) || !isset($props[PR_PARENT_SOURCE_KEY]) || !isset($props[PR_DISPLAY_NAME]) || !isset($props[PR_CONTAINER_CLASS])) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, folder data not available: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR);
     }
     // get the real parent source key from mapi
     if ($parent == "0") {
         $parentprops = mapi_getprops($this->store, array(PR_IPM_SUBTREE_ENTRYID));
         $parentfentryid = $parentprops[PR_IPM_SUBTREE_ENTRYID];
         $mapifolder = mapi_msgstore_openentry($this->store, $parentfentryid);
         $rootfolderprops = mapi_getprops($mapifolder, array(PR_SOURCE_KEY));
         $parent = bin2hex($rootfolderprops[PR_SOURCE_KEY]);
         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportChangesICS->ImportFolderChange(): resolved AS parent '0' to sourcekey '%s'", $parent));
     }
     // a changed parent id means that the folder should be moved
     if (bin2hex($props[PR_PARENT_SOURCE_KEY]) !== $parent) {
         $sourceparentfentryid = mapi_msgstore_entryidfromsourcekey($this->store, $props[PR_PARENT_SOURCE_KEY]);
         if (!$sourceparentfentryid) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open parent source folder (no entry id): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_PARENTNOTFOUND);
         }
         $sourceparentfolder = mapi_msgstore_openentry($this->store, $sourceparentfentryid);
         if (!$sourceparentfolder) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open parent source folder (open entry): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_PARENTNOTFOUND);
         }
         $destparentfentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($parent));
         if (!$sourceparentfentryid) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open destination folder (no entry id): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR);
         }
         $destfolder = mapi_msgstore_openentry($this->store, $destparentfentryid);
         if (!$destfolder) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open destination folder (open entry): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR);
         }
         // mapi_folder_copyfolder() fails if a folder with this name already exists -> MAPI_E_COLLISION
         if (!mapi_folder_copyfolder($sourceparentfolder, $entryid, $destfolder, $displayname, FOLDER_MOVE)) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to move folder: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_FOLDEREXISTS);
         }
         $folderProps = mapi_getprops($mfolder, array(PR_SOURCE_KEY));
         return $folderProps[PR_SOURCE_KEY];
     }
     // update the display name
     $props = array(PR_DISPLAY_NAME => $displayname);
     mapi_setprops($mfolder, $props);
     mapi_savechanges($mfolder);
     if (mapi_last_hresult()) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, mapi_savechanges() failed: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR);
     }
     ZLog::Write(LOGLEVEL_DEBUG, "Imported changes for folder: {$id}");
     return $id;
 }
예제 #8
0
 function SendMail($rfc822, $forward = false, $reply = false, $parent = false)
 {
     $message = Mail_mimeDecode::decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'input' => $rfc822, 'crlf' => "\r\n", 'charset' => 'utf-8'));
     // Open the outbox and create the message there
     $storeprops = mapi_getprops($this->_defaultstore, array(PR_IPM_OUTBOX_ENTRYID, PR_IPM_SENTMAIL_ENTRYID));
     if (!isset($storeprops[PR_IPM_OUTBOX_ENTRYID])) {
         debugLog("Outbox not found to create message");
         return false;
     }
     $outbox = mapi_msgstore_openentry($this->_defaultstore, $storeprops[PR_IPM_OUTBOX_ENTRYID]);
     if (!$outbox) {
         debugLog("Unable to open outbox");
         return false;
     }
     $mapimessage = mapi_folder_createmessage($outbox);
     mapi_setprops($mapimessage, array(PR_SUBJECT => u2w($message->headers["subject"]), PR_SENTMAIL_ENTRYID => $storeprops[PR_IPM_SENTMAIL_ENTRYID], PR_MESSAGE_CLASS => "IPM.Note", PR_MESSAGE_DELIVERY_TIME => time()));
     if (isset($message->headers["x-priority"])) {
         switch ($message->headers["x-priority"]) {
             case 1:
             case 2:
                 $priority = PRIO_URGENT;
                 $importance = IMPORTANCE_HIGH;
                 break;
             case 4:
             case 5:
                 $priority = PRIO_NONURGENT;
                 $importance = IMPORTANCE_LOW;
                 break;
             case 3:
             default:
                 $priority = PRIO_NORMAL;
                 $importance = IMPORTANCE_NORMAL;
                 break;
         }
         mapi_setprops($mapimessage, array(PR_IMPORTANCE => $importance, PR_PRIORITY => $priority));
     }
     $addresses = array();
     $toaddr = $ccaddr = $bccaddr = array();
     if (isset($message->headers["to"])) {
         $toaddr = Mail_RFC822::parseAddressList($message->headers["to"]);
     }
     if (isset($message->headers["cc"])) {
         $ccaddr = Mail_RFC822::parseAddressList($message->headers["cc"]);
     }
     if (isset($message->headers["bcc"])) {
         $bccaddr = Mail_RFC822::parseAddressList($message->headers["bcc"]);
     }
     // Add recipients
     $recips = array();
     if (isset($toaddr)) {
         foreach (array(MAPI_TO => $toaddr, MAPI_CC => $ccaddr, MAPI_BCC => $bccaddr) as $type => $addrlist) {
             foreach ($addrlist as $addr) {
                 $mapirecip[PR_ADDRTYPE] = "SMTP";
                 $mapirecip[PR_EMAIL_ADDRESS] = $addr->mailbox . "@" . $addr->host;
                 if (isset($addr->personal) && strlen($addr->personal) > 0) {
                     $mapirecip[PR_DISPLAY_NAME] = u2w($addr->personal);
                 } else {
                     $mapirecip[PR_DISPLAY_NAME] = $mapirecip[PR_EMAIL_ADDRESS];
                 }
                 $mapirecip[PR_RECIPIENT_TYPE] = $type;
                 $mapirecip[PR_ENTRYID] = mapi_createoneoff($mapirecip[PR_DISPLAY_NAME], $mapirecip[PR_ADDRTYPE], $mapirecip[PR_EMAIL_ADDRESS]);
                 array_push($recips, $mapirecip);
             }
         }
     }
     mapi_message_modifyrecipients($mapimessage, 0, $recips);
     // Loop through subparts. We currently only support single-level
     // multiparts. The PDA currently only does this because you are adding
     // an attachment and the type will be multipart/mixed.
     if ($message->ctype_primary == "multipart" && $message->ctype_secondary == "mixed") {
         foreach ($message->parts as $part) {
             if ($part->ctype_primary == "text") {
                 $body = u2w($part->body);
             } else {
                 // attachment
                 $attach = mapi_message_createattach($mapimessage);
                 // Filename is present in both Content-Type: name=.. and in Content-Disposition: filename=
                 if (isset($part->ctype_parameters["name"])) {
                     $filename = $part->ctype_parameters["name"];
                 } else {
                     if (isset($part->d_parameters["name"])) {
                         $filename = $part->d_parameters["filename"];
                     } else {
                         $filename = "untitled";
                     }
                 }
                 // Set filename and attachment type
                 mapi_setprops($attach, array(PR_ATTACH_LONG_FILENAME => u2w($filename), PR_ATTACH_METHOD => ATTACH_BY_VALUE));
                 // Set attachment data
                 mapi_setprops($attach, array(PR_ATTACH_DATA_BIN => $part->body));
                 // Set MIME type
                 mapi_setprops($attach, array(PR_ATTACH_MIME_TAG => $part->ctype_primary . "/" . $part->ctype_secondary));
                 mapi_savechanges($attach);
             }
         }
     } else {
         $body = u2w($message->body);
     }
     if ($forward) {
         $orig = $forward;
     }
     if ($reply) {
         $orig = $reply;
     }
     if (isset($orig) && $orig) {
         // Append the original text body for reply/forward
         $entryid = mapi_msgstore_entryidfromsourcekey($this->_defaultstore, hex2bin($parent), hex2bin($orig));
         $fwmessage = mapi_msgstore_openentry($this->_defaultstore, $entryid);
         if ($fwmessage) {
             $messageprops = mapi_getprops($fwmessage, array(PR_BODY));
             if (isset($messageprops[PR_BODY])) {
                 if ($forward) {
                     // During a forward, we have to add the forward header ourselves. This is because
                     // normally the forwarded message is added as an attachment. However, we don't want this
                     // because it would be rather complicated to copy over the entire original message due
                     // to the lack of IMessage::CopyTo ..
                     $fwmessageprops = mapi_getprops($fwmessage, array(PR_SENT_REPRESENTING_NAME, PR_DISPLAY_TO, PR_DISPLAY_CC, PR_SUBJECT, PR_CLIENT_SUBMIT_TIME));
                     $body .= "\r\n\r\n";
                     $body .= "-----Original Message-----\r\n";
                     if (isset($fwmessageprops[PR_SENT_REPRESENTING_NAME])) {
                         $body .= "From: " . $fwmessageprops[PR_SENT_REPRESENTING_NAME] . "\r\n";
                     }
                     if (isset($fwmessageprops[PR_DISPLAY_TO]) && strlen($fwmessageprops[PR_DISPLAY_TO]) > 0) {
                         $body .= "To: " . $fwmessageprops[PR_DISPLAY_TO] . "\r\n";
                     }
                     if (isset($fwmessageprops[PR_DISPLAY_CC]) && strlen($fwmessageprops[PR_DISPLAY_CC]) > 0) {
                         $body .= "Cc: " . $fwmessageprops[PR_DISPLAY_CC] . "\r\n";
                     }
                     if (isset($fwmessageprops[PR_CLIENT_SUBMIT_TIME])) {
                         $body .= "Sent: " . strftime("%x %X", $fwmessageprops[PR_CLIENT_SUBMIT_TIME]) . "\r\n";
                     }
                     if (isset($fwmessageprops[PR_SUBJECT])) {
                         $body .= "Subject: " . $fwmessageprops[PR_SUBJECT] . "\r\n";
                     }
                     $body .= "\r\n";
                 }
                 $body .= $messageprops[PR_BODY];
             }
         } else {
             debugLog("Unable to open item with id {$orig} for forward/reply");
         }
     }
     if ($forward) {
         // Add attachments from the original message in a forward
         $entryid = mapi_msgstore_entryidfromsourcekey($this->_defaultstore, hex2bin($parent), hex2bin($orig));
         $fwmessage = mapi_msgstore_openentry($this->_defaultstore, $entryid);
         $attachtable = mapi_message_getattachmenttable($fwmessage);
         $rows = mapi_table_queryallrows($attachtable, array(PR_ATTACH_NUM));
         foreach ($rows as $row) {
             if (isset($row[PR_ATTACH_NUM])) {
                 $attach = mapi_message_openattach($fwmessage, $row[PR_ATTACH_NUM]);
                 $newattach = mapi_message_createattach($mapimessage);
                 // Copy all attachments from old to new attachment
                 $attachprops = mapi_getprops($attach);
                 mapi_setprops($newattach, $attachprops);
                 if (isset($attachprops[mapi_prop_tag(PT_ERROR, mapi_prop_id(PR_ATTACH_DATA_BIN))])) {
                     // Data is in a stream
                     $srcstream = mapi_openpropertytostream($attach, PR_ATTACH_DATA_BIN);
                     $dststream = mapi_openpropertytostream($newattach, PR_ATTACH_DATA_BIN, MAPI_MODIFY | MAPI_CREATE);
                     while (1) {
                         $data = mapi_stream_read($srcstream, 4096);
                         if (strlen($data) == 0) {
                             break;
                         }
                         mapi_stream_write($dststream, $data);
                     }
                     mapi_stream_commit($dststream);
                 }
                 mapi_savechanges($newattach);
             }
         }
     }
     mapi_setprops($mapimessage, array(PR_BODY => $body));
     mapi_savechanges($mapimessage);
     mapi_message_submitmessage($mapimessage);
     return true;
 }
예제 #9
0
파일: ics.php 프로젝트: jkreska/test1
 function _storeAttachment($mapimessage, $part)
 {
     // attachment
     $attach = mapi_message_createattach($mapimessage);
     // Filename is present in both Content-Type: name=.. and in Content-Disposition: filename=
     if (isset($part->ctype_parameters["name"])) {
         $filename = $part->ctype_parameters["name"];
     } else {
         if (isset($part->d_parameters["name"])) {
             $filename = $part->d_parameters["filename"];
         } else {
             if (isset($part->d_parameters["filename"])) {
                 //sending appointment with nokia only filename is set
                 $filename = $part->d_parameters["filename"];
             } else {
                 $filename = "untitled";
             }
         }
     }
     // Set filename and attachment type
     mapi_setprops($attach, array(PR_ATTACH_LONG_FILENAME => u2w($filename), PR_ATTACH_METHOD => ATTACH_BY_VALUE));
     // Set attachment data
     mapi_setprops($attach, array(PR_ATTACH_DATA_BIN => $part->body));
     // Set MIME type
     mapi_setprops($attach, array(PR_ATTACH_MIME_TAG => $part->ctype_primary . "/" . $part->ctype_secondary));
     mapi_savechanges($attach);
 }
예제 #10
0
        $props[$properties["mailing_address"]] = 2;
        setMailingAdress($props[$properties["business_address_street"]], $props[$properties["business_address_postal_code"]], $props[$properties["business_address_city"]], $props[$properties["business_address_state"]], $props[$properties["business_address_country"]], $props[$properties["business_address"]], $props, $properties);
    } elseif (isset($props[$properties["home_address"]])) {
        $props[$properties["mailing_address"]] = 1;
        setMailingAdress($props[$properties["home_address_street"]], $props[$properties["home_address_postal_code"]], $props[$properties["home_address_city"]], $props[$properties["home_address_state"]], $props[$properties["home_address_country"]], $props[$properties["home_address"]], $props, $properties);
    } elseif (isset($props[$properties["other_address"]])) {
        $props[$properties["mailing_address"]] = 3;
        setMailingAdress($props[$properties["other_address_street"]], $props[$properties["other_address_postal_code"]], $props[$properties["other_address_city"]], $props[$properties["other_address_state"]], $props[$properties["other_address_country"]], $props[$properties["other_address"]], $props, $properties);
    }
    // if the display name is set, then it is a valid contact: save it to the folder
    if (isset($props[$properties["display_name"]])) {
        $props[$properties["message_class"]] = "IPM.Contact";
        $props[$properties["icon_index"]] = "512";
        $message = mapi_folder_createmessage($folder);
        mapi_setprops($message, $props);
        mapi_savechanges($message);
        printf("New contact added \"%s\".\n", $props[$properties["display_name"]]);
    }
    $i++;
}
// EOF
function getPropIdsFromStrings($store, $mapping)
{
    $props = array();
    $ids = array("name" => array(), "id" => array(), "guid" => array(), "type" => array());
    // this array stores all the information needed to retrieve a named property
    $num = 0;
    // caching
    $guids = array();
    foreach ($mapping as $name => $val) {
        if (is_string($val)) {
예제 #11
0
 /**
  * Copies attachments from one message to another.
  *
  * @param MAPIMessage $toMessage
  * @param MAPIMessage $fromMessage
  *
  * @return void
  */
 private function copyAttachments(&$toMessage, $fromMessage)
 {
     $attachtable = mapi_message_getattachmenttable($fromMessage);
     $rows = mapi_table_queryallrows($attachtable, array(PR_ATTACH_NUM));
     foreach ($rows as $row) {
         if (isset($row[PR_ATTACH_NUM])) {
             $attach = mapi_message_openattach($fromMessage, $row[PR_ATTACH_NUM]);
             $newattach = mapi_message_createattach($toMessage);
             mapi_copyto($attach, array(), array(), $newattach, 0);
             mapi_savechanges($newattach);
         }
     }
 }
예제 #12
0
 /**
  * Assign a contact picture to a contact
  * @param entryId contact entry id
  * @param contactPicture must be a valid jpeg file. If contactPicture is NULL will remove contact picture from contact if exists
  */
 public function setContactPicture(&$contact, $contactPicture)
 {
     $this->logger->trace("setContactPicture");
     // Find if contact picture is already set
     $contactAttachment = -1;
     $hasattachProp = mapi_getprops($contact, array(PR_HASATTACH));
     if ($hasattachProp) {
         $attachmentTable = mapi_message_getattachmenttable($contact);
         $attachments = mapi_table_queryallrows($attachmentTable, array(PR_ATTACH_NUM, PR_ATTACH_SIZE, PR_ATTACH_LONG_FILENAME, PR_ATTACH_FILENAME, PR_ATTACHMENT_HIDDEN, PR_DISPLAY_NAME, PR_ATTACH_METHOD, PR_ATTACH_CONTENT_ID, PR_ATTACH_MIME_TAG, PR_ATTACHMENT_CONTACTPHOTO, PR_EC_WA_ATTACHMENT_HIDDEN_OVERRIDE));
         foreach ($attachments as $attachmentRow) {
             if (isset($attachmentRow[PR_ATTACHMENT_CONTACTPHOTO]) && $attachmentRow[PR_ATTACHMENT_CONTACTPHOTO]) {
                 $contactAttachment = $attachmentRow[PR_ATTACH_NUM];
                 break;
             }
         }
     }
     // Remove existing attachment if necessary
     if ($contactAttachment != -1) {
         $this->logger->trace("removing existing contact picture");
         $attach = mapi_message_deleteattach($contact, $contactAttachment);
     }
     if ($contactPicture !== NULL) {
         $this->logger->debug("Saving contact picture as attachment");
         // Create attachment
         $attach = mapi_message_createattach($contact);
         // Update contact attachment properties
         $properties = array(PR_ATTACH_SIZE => strlen($contactPicture), PR_ATTACH_LONG_FILENAME => 'ContactPicture.jpg', PR_ATTACHMENT_HIDDEN => false, PR_DISPLAY_NAME => 'ContactPicture.jpg', PR_ATTACH_METHOD => ATTACH_BY_VALUE, PR_ATTACH_MIME_TAG => 'image/jpeg', PR_ATTACHMENT_CONTACTPHOTO => true, PR_ATTACH_DATA_BIN => $contactPicture, PR_ATTACHMENT_FLAGS => 1, PR_ATTACH_EXTENSION_A => '.jpg', PR_ATTACH_NUM => 1);
         mapi_setprops($attach, $properties);
         mapi_savechanges($attach);
     }
     // Test
     if (mapi_last_hresult() > 0) {
         $this->logger->warn("Error saving contact picture: " . get_mapi_error_name());
     } else {
         $this->logger->trace("contact picture done");
     }
 }
function clearSuggestionList($session, $store, $userName)
{
    // create entryid of user's store
    $userStoreEntryId = mapi_msgstore_createentryid($store, $userName);
    if (!$userStoreEntryId) {
        print "Error in creating entryid for user's store - " . $userName . "\n";
        return false;
    }
    // open user's store
    $userStore = mapi_openmsgstore($session, $userStoreEntryId);
    if (!$userStore) {
        print "Error in opening user's store - " . $userName . "\n";
        return false;
    }
    // we are not checking here that property exists or not because it could happen that getprops will return
    // MAPI_E_NOT_ENOUGH_MEMORY for very large property, if property does not exists then it will be created
    // remove property data, overwirte existing data with a blank string (PT_STRING8)
    mapi_setprops($userStore, array(PR_EC_RECIPIENT_HISTORY => ""));
    $result = mapi_last_hresult();
    if ($result == NOERROR) {
        // Save changes
        mapi_savechanges($userStore);
        return mapi_last_hresult() == NOERROR ? true : false;
    }
    return false;
}
function import($store, $csv_file, $delete_old_items, $categories)
{
    $folder = getContactsFolder($store);
    // open the csv file and start reading
    $fh = fopen($csv_file, "r");
    if (!$fh) {
        trigger_error("Can't read CSV file \"" . $csv_file . "\".", E_USER_ERROR);
    }
    // Delete all existing items if requested.
    if ($delete_old_items) {
        mapi_folder_emptyfolder($folder, DEL_ASSOCIATED);
        printf("Old items deleted.\n");
    }
    $properties = getProperties();
    $properties = replaceStringPropertyTags($store, $properties);
    //composed properties which require more work
    $special_properties = getSpecialPropertyNames();
    $csv_mapping = getMapping();
    $i = 1;
    while (!feof($fh)) {
        $line = fgetcsv($fh, CSV_MAX_LENGTH, CSV_DELIMITER, CSV_ENCLOSURE);
        // print_r($line);
        if (!$line) {
            continue;
        }
        if ($i == 1 && defined('FIELD_NAMES') && FIELD_NAMES) {
            $i++;
            continue;
        }
        $propValues = array();
        //set "simple" properties
        foreach ($csv_mapping as $property => $cnt) {
            if (!in_array($property, $special_properties)) {
                setProperty($property, $line[$csv_mapping[$property]], $propValues, $properties);
            }
        }
        // set display name
        if (isset($csv_mapping["display_name"]) && isset($line[$csv_mapping["display_name"]])) {
            $name = to_windows1252($line[$csv_mapping["display_name"]]);
            $propValues[$properties["display_name"]] = $propValues[$properties["subject"]] = $propValues[$properties["fileas"]] = $name;
            $propValues[$properties["fileas_selection"]] = -1;
        } else {
            $propValues[$properties["display_name"]] = $propValues[$properties["subject"]] = $propValues[$properties["fileas"]] = "";
            if (isset($propValues[$properties["given_name"]])) {
                $propValues[$properties["display_name"]] .= $propValues[$properties["given_name"]];
                $propValues[$properties["subject"]] .= $propValues[$properties["given_name"]];
            }
            if (isset($propValues[$properties["surname"]])) {
                if (strlen($propValues[$properties["display_name"]]) > 0) {
                    $propValues[$properties["display_name"]] .= " " . $propValues[$properties["surname"]];
                    $propValues[$properties["subject"]] .= " " . $propValues[$properties["surname"]];
                } else {
                    $propValues[$properties["display_name"]] .= $propValues[$properties["surname"]];
                    $propValues[$properties["subject"]] .= $propValues[$properties["surname"]];
                }
            }
            if (isset($propValues[$properties["surname"]])) {
                $propValues[$properties["fileas"]] .= $propValues[$properties["surname"]];
            }
            if (isset($propValues[$properties["given_name"]])) {
                if (strlen($propValues[$properties["fileas"]]) > 0) {
                    $propValues[$properties["fileas"]] .= ", " . $propValues[$properties["given_name"]];
                } else {
                    $propValues[$properties["fileas"]] .= $propValues[$properties["given_name"]];
                }
            }
        }
        $nremails = array();
        $abprovidertype = 0;
        if (isset($csv_mapping["email_address_1"]) && isset($line[$csv_mapping["email_address_1"]])) {
            setEmailAddress($line[$csv_mapping["email_address_1"]], $propValues[$properties["display_name"]], 1, $propValues, $properties, $nremails, $abprovidertype);
        }
        if (isset($csv_mapping["email_address_2"]) && isset($line[$csv_mapping["email_address_2"]])) {
            setEmailAddress($line[$csv_mapping["email_address_2"]], $propValues[$properties["display_name"]], 2, $propValues, $properties, $nremails, $abprovidertype);
        }
        if (isset($csv_mapping["email_address_3"]) && isset($line[$csv_mapping["email_address_3"]])) {
            setEmailAddress($line[$csv_mapping["email_address_3"]], $propValues[$properties["display_name"]], 3, $propValues, $properties, $nremails, $abprovidertype);
        }
        if (!empty($nremails)) {
            $propValues[$properties["address_book_mv"]] = $nremails;
        }
        $propValues[$properties["address_book_long"]] = $abprovidertype;
        //set addresses
        if (isset($csv_mapping["home_address_street2"])) {
            mergeStreet("home", $line[$csv_mapping["home_address_street2"]], $propValues, $properties);
        }
        if (isset($csv_mapping["home_address_street3"])) {
            mergeStreet("home", $line[$csv_mapping["home_address_street3"]], $propValues, $properties);
        }
        if (!isset($propValues[$properties["home_address"]]) && isset($propValues[$properties["home_address_street"]]) && isset($propValues[$properties["home_address_postal_code"]]) && isset($propValues[$properties["home_address_city"]]) && isset($propValues[$properties["home_address_state"]]) && isset($propValues[$properties["home_address_country"]])) {
            buildAddressString("home", $propValues[$properties["home_address_street"]], $propValues[$properties["home_address_postal_code"]], $propValues[$properties["home_address_city"]], $propValues[$properties["home_address_state"]], $propValues[$properties["home_address_country"]], $propValues, $properties);
        }
        if (isset($csv_mapping["business_address_street2"])) {
            mergeStreet("business", $line[$csv_mapping["business_address_street2"]], $propValues, $properties);
        }
        if (isset($csv_mapping["business_address_street3"])) {
            mergeStreet("business", $line[$csv_mapping["business_address_street3"]], $propValues, $properties);
        }
        if (!isset($propValues[$properties["business_address"]]) && isset($propValues[$properties["business_address_street"]]) && isset($propValues[$properties["business_address_postal_code"]]) && isset($propValues[$properties["business_address_city"]]) && isset($propValues[$properties["business_address_state"]]) && isset($propValues[$properties["business_address_country"]])) {
            buildAddressString("business", $propValues[$properties["business_address_street"]], $propValues[$properties["business_address_postal_code"]], $propValues[$properties["business_address_city"]], $propValues[$properties["business_address_state"]], $propValues[$properties["business_address_country"]], $propValues, $properties);
        }
        if (isset($csv_mapping["other_address_street2"])) {
            mergeStreet("other", $line[$csv_mapping["other_address_street2"]], $propValues, $properties);
        }
        if (isset($csv_mapping["other_address_street3"])) {
            mergeStreet("other", $line[$csv_mapping["other_address_street3"]], $propValues, $properties);
        }
        if (!isset($propValues[$properties["other_address"]]) && isset($propValues[$properties["other_address_street"]]) && isset($propValues[$properties["other_address_postal_code"]]) && isset($propValues[$properties["other_address_city"]]) && isset($propValues[$properties["other_address_state"]]) && isset($propValues[$properties["other_address_country"]])) {
            buildAddressString("other", $propValues[$properties["other_address_street"]], $propValues[$properties["other_address_postal_code"]], $propValues[$properties["other_address_city"]], $propValues[$properties["other_address_state"]], $propValues[$properties["other_address_country"]], $propValues, $properties);
        }
        if (isset($propValues[$properties["home_address"]])) {
            $propValues[$properties["mailing_address"]] = 1;
            setMailingAdress($propValues[$properties["home_address_street"]], $propValues[$properties["home_address_postal_code"]], $propValues[$properties["home_address_city"]], $propValues[$properties["home_address_state"]], $propValues[$properties["home_address_country"]], $propValues[$properties["home_address"]], $propValues, $properties);
        } elseif (isset($propValues[$properties["business_address"]])) {
            $propValues[$properties["mailing_address"]] = 2;
            setMailingAdress($propValues[$properties["business_address_street"]], $propValues[$properties["business_address_postal_code"]], $propValues[$properties["business_address_city"]], $propValues[$properties["business_address_state"]], $propValues[$properties["business_address_country"]], $propValues[$properties["business_address"]], $propValues, $properties);
        } elseif (isset($propValues[$properties["other_address"]])) {
            $propValues[$properties["mailing_address"]] = 3;
            setMailingAdress($propValues[$properties["other_address_street"]], $propValues[$properties["other_address_postal_code"]], $propValues[$properties["other_address_city"]], $propValues[$properties["other_address_state"]], $propValues[$properties["other_address_country"]], $propValues[$properties["other_address"]], $propValues, $properties);
        }
        if (isset($categories) && !empty($categories)) {
            setProperty("categories", $categories, $propValues, $properties);
        }
        // if the display name is set, then it is a valid contact: save it to the folder
        if (isset($propValues[$properties["display_name"]])) {
            $propValues[$properties["message_class"]] = "IPM.Contact";
            $propValues[$properties["icon_index"]] = "512";
            $message = mapi_folder_createmessage($folder);
            mapi_setprops($message, $propValues);
            mapi_savechanges($message);
            printf("New contact added: \"%s\".\n", $propValues[$properties["display_name"]]);
        }
        $i++;
    }
}
 /**
  * Checks if there has been any significant changes on appointment/meeting item.
  * Significant changes be:
  * 1) startdate has been changed
  * 2) duedate has been changed OR
  * 3) recurrence pattern has been created, modified or removed
  *
  * @param Array oldProps old props before an update
  * @param Number basedate basedate
  * @param Boolean isRecurrenceChanged for change in recurrence pattern.
  * isRecurrenceChanged true means Recurrence pattern has been changed, so clear all attendees response
  */
 function checkSignificantChanges($oldProps, $basedate, $isRecurrenceChanged = false)
 {
     $message = null;
     $attach = null;
     // If basedate is specified then we need to open exception message to clear recipient responses
     if ($basedate) {
         $recurrence = new Recurrence($this->store, $this->message);
         if ($recurrence->isException($basedate)) {
             $attach = $recurrence->getExceptionAttachment($basedate);
             if ($attach) {
                 $message = mapi_attach_openobj($attach, MAPI_MODIFY);
             }
         }
     } else {
         // use normal message or recurring series message
         $message = $this->message;
     }
     if (!$message) {
         return;
     }
     $newProps = mapi_getprops($message, array($this->proptags['startdate'], $this->proptags['duedate'], $this->proptags['updatecounter']));
     // Check whether message is updated or not.
     if (isset($newProps[$this->proptags['updatecounter']]) && $newProps[$this->proptags['updatecounter']] == 0) {
         return;
     }
     if ($newProps[$this->proptags['startdate']] != $oldProps[$this->proptags['startdate']] || $newProps[$this->proptags['duedate']] != $oldProps[$this->proptags['duedate']] || $isRecurrenceChanged) {
         $this->clearRecipientResponse($message);
         mapi_setprops($message, array($this->proptags['owner_critical_change'] => time()));
         mapi_savechanges($message);
         if ($attach) {
             // Also save attachment Object.
             mapi_savechanges($attach);
         }
     }
 }
 function sendResponse($type, $prefix)
 {
     // Create a message in our outbox
     $outgoing = $this->createOutgoingMessage();
     $messageprops = mapi_getprops($this->message, array(PR_SUBJECT));
     $attach = mapi_message_createattach($outgoing);
     mapi_setprops($attach, array(PR_ATTACH_METHOD => ATTACH_EMBEDDED_MSG, PR_DISPLAY_NAME => $messageprops[PR_SUBJECT], PR_ATTACHMENT_HIDDEN => true));
     $sub = mapi_attach_openproperty($attach, PR_ATTACH_DATA_OBJ, IID_IMessage, 0, MAPI_CREATE | MAPI_MODIFY);
     mapi_copyto($this->message, array(), array(PR_SENT_REPRESENTING_NAME, PR_SENT_REPRESENTING_EMAIL_ADDRESS, PR_SENT_REPRESENTING_ADDRTYPE, PR_SENT_REPRESENTING_ENTRYID, PR_SENT_REPRESENTING_SEARCH_KEY), $outgoing);
     mapi_copyto($this->message, array(), array(), $sub);
     if (!$this->setRecipientsForResponse($outgoing, $type)) {
         return false;
     }
     switch ($type) {
         case tdmtTaskAcc:
             $messageclass = "IPM.TaskRequest.Accept";
             break;
         case tdmtTaskDec:
             $messageclass = "IPM.TaskRequest.Decline";
             break;
         case tdmtTaskUpd:
             $messageclass = "IPM.TaskRequest.Update";
             break;
     }
     mapi_savechanges($sub);
     mapi_savechanges($attach);
     // Set Body
     $body = $this->getBody();
     $stream = mapi_openpropertytostream($outgoing, PR_BODY, MAPI_CREATE | MAPI_MODIFY);
     mapi_stream_setsize($stream, strlen($body));
     mapi_stream_write($stream, $body);
     mapi_stream_commit($stream);
     // Set subject, taskmode, message class, icon index, response time
     mapi_setprops($outgoing, array(PR_SUBJECT => $prefix . $messageprops[PR_SUBJECT], $this->props['taskmode'] => $type, PR_MESSAGE_CLASS => $messageclass, PR_ICON_INDEX => 0xffffffff, $this->props['assignedtime'] => time()));
     mapi_savechanges($outgoing);
     mapi_message_submitmessage($outgoing);
     return true;
 }
예제 #17
0
 /**
  * Writes a SyncContact to MAPI
  *
  * @param mixed             $mapimessage
  * @param SyncContact       $contact
  *
  * @access private
  * @return boolean
  */
 private function setContact($mapimessage, $contact)
 {
     mapi_setprops($mapimessage, array(PR_MESSAGE_CLASS => "IPM.Contact"));
     // normalize email addresses
     if (isset($contact->email1address) && ($contact->email1address = $this->extractEmailAddress($contact->email1address)) === false) {
         unset($contact->email1address);
     }
     if (isset($contact->email2address) && ($contact->email2address = $this->extractEmailAddress($contact->email2address)) === false) {
         unset($contact->email2address);
     }
     if (isset($contact->email3address) && ($contact->email3address = $this->extractEmailAddress($contact->email3address)) === false) {
         unset($contact->email3address);
     }
     $contactmapping = MAPIMapping::GetContactMapping();
     $contactprops = MAPIMapping::GetContactProperties();
     $this->setPropsInMAPI($mapimessage, $contact, $contactmapping);
     ///set display name from contact's properties
     $cname = $this->composeDisplayName($contact);
     //get contact specific mapi properties and merge them with the AS properties
     $contactprops = array_merge($this->getPropIdsFromStrings($contactmapping), $this->getPropIdsFromStrings($contactprops));
     //contact specific properties to be set
     $props = array();
     //need to be set in order to show contacts properly in outlook and wa
     $nremails = array();
     $abprovidertype = 0;
     if (isset($contact->email1address)) {
         $this->setEmailAddress($contact->email1address, $cname, 1, $props, $contactprops, $nremails, $abprovidertype);
     }
     if (isset($contact->email2address)) {
         $this->setEmailAddress($contact->email2address, $cname, 2, $props, $contactprops, $nremails, $abprovidertype);
     }
     if (isset($contact->email3address)) {
         $this->setEmailAddress($contact->email3address, $cname, 3, $props, $contactprops, $nremails, $abprovidertype);
     }
     $props[$contactprops["addressbooklong"]] = $abprovidertype;
     $props[$contactprops["displayname"]] = $props[$contactprops["subject"]] = $cname;
     //pda multiple e-mail addresses bug fix for the contact
     if (!empty($nremails)) {
         $props[$contactprops["addressbookmv"]] = $nremails;
     }
     //set addresses
     $this->setAddress("home", $contact->homecity, $contact->homecountry, $contact->homepostalcode, $contact->homestate, $contact->homestreet, $props, $contactprops);
     $this->setAddress("business", $contact->businesscity, $contact->businesscountry, $contact->businesspostalcode, $contact->businessstate, $contact->businessstreet, $props, $contactprops);
     $this->setAddress("other", $contact->othercity, $contact->othercountry, $contact->otherpostalcode, $contact->otherstate, $contact->otherstreet, $props, $contactprops);
     //set the mailing address and its type
     if (isset($props[$contactprops["businessaddress"]])) {
         $props[$contactprops["mailingaddress"]] = 2;
         $this->setMailingAddress($contact->businesscity, $contact->businesscountry, $contact->businesspostalcode, $contact->businessstate, $contact->businessstreet, $props[$contactprops["businessaddress"]], $props, $contactprops);
     } elseif (isset($props[$contactprops["homeaddress"]])) {
         $props[$contactprops["mailingaddress"]] = 1;
         $this->setMailingAddress($contact->homecity, $contact->homecountry, $contact->homepostalcode, $contact->homestate, $contact->homestreet, $props[$contactprops["homeaddress"]], $props, $contactprops);
     } elseif (isset($props[$contactprops["otheraddress"]])) {
         $props[$contactprops["mailingaddress"]] = 3;
         $this->setMailingAddress($contact->othercity, $contact->othercountry, $contact->otherpostalcode, $contact->otherstate, $contact->otherstreet, $props[$contactprops["otheraddress"]], $props, $contactprops);
     }
     if (isset($contact->picture)) {
         $picbinary = base64_decode($contact->picture);
         $picsize = strlen($picbinary);
         if ($picsize < MAX_EMBEDDED_SIZE) {
             $props[$contactprops["haspic"]] = false;
             // TODO contact picture handling
             // check if contact has already got a picture. delete it first in that case
             // delete it also if it was removed on a mobile
             $picprops = mapi_getprops($mapimessage, array($props[$contactprops["haspic"]]));
             if (isset($picprops[$props[$contactprops["haspic"]]]) && $picprops[$props[$contactprops["haspic"]]]) {
                 ZLog::Write(LOGLEVEL_DEBUG, "Contact already has a picture. Delete it");
                 $attachtable = mapi_message_getattachmenttable($mapimessage);
                 mapi_table_restrict($attachtable, MAPIUtils::GetContactPicRestriction());
                 $rows = mapi_table_queryallrows($attachtable, array(PR_ATTACH_NUM));
                 if (isset($rows) && is_array($rows)) {
                     foreach ($rows as $row) {
                         mapi_message_deleteattach($mapimessage, $row[PR_ATTACH_NUM]);
                     }
                 }
             }
             // only set picture if there's data in the request
             if ($picbinary !== false && $picsize > 0) {
                 $props[$contactprops["haspic"]] = true;
                 $pic = mapi_message_createattach($mapimessage);
                 // Set properties of the attachment
                 $picprops = array(PR_ATTACH_LONG_FILENAME_A => "ContactPicture.jpg", PR_DISPLAY_NAME => "ContactPicture.jpg", 0x7fff000b => true, PR_ATTACHMENT_HIDDEN => false, PR_ATTACHMENT_FLAGS => 1, PR_ATTACH_METHOD => ATTACH_BY_VALUE, PR_ATTACH_EXTENSION_A => ".jpg", PR_ATTACH_NUM => 1, PR_ATTACH_SIZE => $picsize, PR_ATTACH_DATA_BIN => $picbinary);
                 mapi_setprops($pic, $picprops);
                 mapi_savechanges($pic);
             }
         }
     }
     if (isset($contact->asbody)) {
         $this->setASbody($contact->asbody, $props, $contactprops);
     }
     //set fileas
     if (defined('FILEAS_ORDER')) {
         $lastname = isset($contact->lastname) ? $contact->lastname : "";
         $firstname = isset($contact->firstname) ? $contact->firstname : "";
         $middlename = isset($contact->middlename) ? $contact->middlename : "";
         $company = isset($contact->companyname) ? $contact->companyname : "";
         $props[$contactprops["fileas"]] = Utils::BuildFileAs($lastname, $firstname, $middlename, $company);
     } else {
         ZLog::Write(LOGLEVEL_DEBUG, "FILEAS_ORDER not defined");
     }
     mapi_setprops($mapimessage, $props);
 }
예제 #18
0
 /**
  * Updates the chunk data in the hidden folder if it changed.
  * If the chunkId is not available, it's created.
  *
  * @param string    $folderid
  * @param string    $chunkName      The name of the chunk (used to find/update the chunk message).
  *                                  The name is to be saved in the 'subject' of the chunk message.
  * @param int       $amountEntries  Amount of entries in the chunkdata.
  * @param string    $chunkData      The data containing all the data.
  * @param string    $chunkCRC       A checksum of the chunk data. To be saved in the 'location' of
  *                                  the chunk message. Used to identify changed chunks.
  * @param string    $gabId          Id that uniquely identifies the GAB. If not set or null the default GAB is assumed.
  * @param string    $gabName        String that uniquely identifies the GAB. If not set the default GAB is assumed.
  *
  * @access protected
  * @return boolean
  */
 protected function setChunkData($folderid, $chunkName, $amountEntries, $chunkData, $chunkCRC, $gabId = null, $gabName = 'default')
 {
     $log = sprintf("Kopano->setChunkData: %s\tEntries: %d\t Size: %d B\tCRC: %s  -  ", $chunkName, $amountEntries, strlen($chunkData), $chunkCRC);
     // find the chunk message in the folder
     $store = $this->getStore($gabId, $gabName);
     if (!$store) {
         return false;
     }
     $chunkdata = $this->findChunk($store, $folderid, $chunkName);
     $message = false;
     // message not found, create it
     if (empty($chunkdata)) {
         $folder = $this->getFolder($store, $folderid);
         $message = mapi_folder_createmessage($folder);
         mapi_setprops($message, array(PR_MESSAGE_CLASS => "IPM.Appointment", $this->mapiprops['chunktype'] => $this->chunkType, PR_SUBJECT => $chunkName, $this->mapiprops['createtime'] => time(), $this->mapiprops['reminderset'] => 0, $this->mapiprops['isrecurring'] => 0, $this->mapiprops['busystatus'] => 0));
         $log .= "creating - ";
     } else {
         // we need to update the chunk if the CRC does not match!
         if ($chunkdata[$this->mapiprops['chunkCRC']] != $chunkCRC) {
             $message = mapi_msgstore_openentry($store, $chunkdata[PR_ENTRYID]);
             $log .= "opening - ";
         } else {
             $log .= "unchanged";
         }
     }
     // update chunk if necessary
     if ($message) {
         mapi_setprops($message, array($this->mapiprops['chunkCRC'] => $chunkCRC, PR_BODY => $chunkData, $this->mapiprops['updatetime'] => time()));
         @mapi_savechanges($message);
         if (mapi_last_hresult()) {
             $log .= sprintf("error saving: 0x%08X", mapi_last_hresult());
         } else {
             $log .= "saved";
         }
     }
     // output log
     $this->log($log);
     return true;
 }