function resolve($session, $name) { $ab = mapi_openaddressbook($session); $resolved = mapi_ab_resolvename($ab, array(array(PR_DISPLAY_NAME => $name)), EMS_AB_ADDRESS_LOOKUP); $id = false; if ($resolved) { $id = $resolved[0][PR_ENTRYID]; } return $id; }
/** * Get MAPI addressbook object * * @access private * @return MAPIAddressbook object to be used with mapi_ab_* or false on failure */ private function getAddressbook() { if (isset($this->addressbook) && $this->addressbook) { return $this->addressbook; } $this->addressbook = mapi_openaddressbook($this->session); $result = mapi_last_hresult(); if ($result && $this->addressbook === false) { ZLog::Write(LOGLEVEL_ERROR, sprintf("MAPIProvider->getAddressbook error opening addressbook 0x%X", $result)); return false; } return $this->addressbook; }
function getDelegatorStore($messageprops) { // Find the organiser of appointment in addressbook $delegatorName = array(array(PR_DISPLAY_NAME => $messageprops[PR_RCVD_REPRESENTING_NAME])); $ab = mapi_openaddressbook($this->session); $user = mapi_ab_resolvename($ab, $delegatorName, EMS_AB_ADDRESS_LOOKUP); // Get StoreEntryID by username $delegatorEntryid = mapi_msgstore_createentryid($this->store, $user[0][PR_EMAIL_ADDRESS]); // Open store of the delegator $delegatorStore = mapi_openmsgstore($this->session, $delegatorEntryid); // Open root folder $delegatorRoot = mapi_msgstore_openentry($delegatorStore, null); // Get calendar entryID $delegatorRootProps = mapi_getprops($delegatorRoot, array(PR_IPM_APPOINTMENT_ENTRYID)); // Open the calendar Folder $calFolder = mapi_msgstore_openentry($delegatorStore, $delegatorRootProps[PR_IPM_APPOINTMENT_ENTRYID]); return array('store' => $delegatorStore, 'calFolder' => $calFolder); }
/** * Get the private contact folder of all users */ function getPrivateContactFolders($session, $defaultstore) { $addrbook = mapi_openaddressbook($session); $addr_entryid = mapi_ab_getdefaultdir($addrbook); $abcontainer = mapi_ab_openentry($addrbook, $addr_entryid); $contentstable = mapi_folder_getcontentstable($abcontainer); // restrict table on only MAPI_MAILUSER accounts mapi_table_restrict($contentstable, array(RES_PROPERTY, array(RELOP => RELOP_EQ, ULPROPTAG => PR_OBJECT_TYPE, VALUE => array(PR_OBJECT_TYPE => MAPI_MAILUSER)))); // sort table on display name mapi_table_sort($contentstable, array(PR_DISPLAY_NAME => TABLE_SORT_ASCEND)); $users = mapi_table_queryrows($contentstable, array(PR_ACCOUNT, PR_ENTRYID, PR_DISPLAY_NAME), 0, mapi_table_getrowcount($contentstable)); $contactArray = array(); for ($i = 0; $i < sizeof($users); $i++) { $store_entryid = mapi_msgstore_createentryid($defaultstore, $users[$i][PR_ACCOUNT]); $store = mapi_openmsgstore($session, $store_entryid); $rootcontainer = mapi_msgstore_openentry($store); if ($rootcontainer) { $props = mapi_getprops($rootcontainer, array(PR_IPM_CONTACT_ENTRYID)); if (isset($props[PR_IPM_CONTACT_ENTRYID])) { $entryid = $props[PR_IPM_CONTACT_ENTRYID]; $folder = mapi_msgstore_openentry($store, $entryid); if ($folder) { $table = mapi_folder_getcontentstable($folder); $totalrow = mapi_table_getrowcount($table); $rows = array(); $contacts = array(); $properties = getContactProperties($defaultstore); if ($totalrow > 0) { $rows = mapi_table_queryrows($table, $properties, 0, $totalrow); for ($j = 0; $j < sizeof($rows); $j++) { $rows[$j][268370178] = md5($rows[$j][268370178]); } for ($k = 0; $k < sizeof($rows); $k++) { // do not add private contacts if (!array_key_exists(-2119827445, $rows[$k]) || array_key_exists(-2119827445, $rows[$k]) && $rows[$k][-2119827445] != 1) { foreach ($rows[$k] as $key => $value) { $attribute = mapKey($key); if ($attribute != "") { $contacts[$k][$attribute] = $value; } } } } $contactArray[] = array("username" => $users[$i][PR_ACCOUNT], "contacts" => $contacts); } } } } } // print_r($contactArray); return $contactArray; }
/** * Function adds recipients in recips array from the string. * * @param array $recips recipient array. * @param string $recipString recipient string attendees. * @param int $type type of the recipient, MAPI_TO/MAPI_CC. */ function setRecipsFromString(&$recips, $recipString, $recipType = MAPI_TO) { $ab = mapi_openaddressbook($this->session); $recipArray = explode(';', $recipString); foreach ($recipArray as $recip) { $recip = trim($recip); if (!empty($recip)) { try { $userName = array(array(PR_DISPLAY_NAME => $recip)); $user = mapi_ab_resolvename($ab, $userName, EMS_AB_ADDRESS_LOOKUP); $extraRecipient = array(); $extraRecipient[PR_RECIPIENT_TYPE] = $recipType; $extraRecipient[PR_ENTRYID] = $user[0][PR_ENTRYID]; $extraRecipient[PR_DISPLAY_NAME] = $user[0][PR_DISPLAY_NAME]; $extraRecipient[PR_OBJECT_TYPE] = $user[0][PR_OBJECT_TYPE]; $extraRecipient[PR_EMAIL_ADDRESS] = $user[0][PR_EMAIL_ADDRESS]; $extraRecipient[PR_SMTP_ADDRESS] = $user[0][PR_SMTP_ADDRESS]; $extraRecipient[PR_ADDRTYPE] = $user[0][PR_ADDRTYPE]; array_push($recips, $extraRecipient); } catch (MAPIException $e) { // We couldn't resolve the user, fallback to filling // in the properties which we do know. $extraRecipient = array(); $extraRecipient[PR_RECIPIENT_TYPE] = $recipType; $extraRecipient[PR_DISPLAY_NAME] = $recip; array_push($recips, $extraRecipient); } } } }
/** * Searches the GAB of Zarafa * Can be overwitten globally by configuring a SearchBackend * * @param string $searchquery * @param string $searchrange * * @access public * @return array * @throws StatusException */ public function GetGALSearchResults($searchquery, $searchrange) { // only return users from who the displayName or the username starts with $name //TODO: use PR_ANR for this restriction instead of PR_DISPLAY_NAME and PR_ACCOUNT $addrbook = mapi_openaddressbook($this->session); if ($addrbook) { $ab_entryid = mapi_ab_getdefaultdir($addrbook); } if ($ab_entryid) { $ab_dir = mapi_ab_openentry($addrbook, $ab_entryid); } if ($ab_dir) { $table = mapi_folder_getcontentstable($ab_dir); } if (!$table) { throw new StatusException(sprintf("ZarafaBackend->GetGALSearchResults(): could not open addressbook: 0x%X", mapi_last_hresult()), SYNC_SEARCHSTATUS_STORE_CONNECTIONFAILED); } $restriction = MAPIUtils::GetSearchRestriction(u2w($searchquery)); mapi_table_restrict($table, $restriction); mapi_table_sort($table, array(PR_DISPLAY_NAME => TABLE_SORT_ASCEND)); if (mapi_last_hresult()) { throw new StatusException(sprintf("ZarafaBackend->GetGALSearchResults(): could not apply restriction: 0x%X", mapi_last_hresult()), SYNC_SEARCHSTATUS_STORE_TOOCOMPLEX); } //range for the search results, default symbian range end is 50, wm 99, //so we'll use that of nokia $rangestart = 0; $rangeend = 50; if ($searchrange != '0') { $pos = strpos($searchrange, '-'); $rangestart = substr($searchrange, 0, $pos); $rangeend = substr($searchrange, $pos + 1); } $items = array(); $querycnt = mapi_table_getrowcount($table); //do not return more results as requested in range $querylimit = $rangeend + 1 < $querycnt ? $rangeend + 1 : $querycnt; $items['range'] = $querylimit > 0 ? $rangestart . '-' . ($querylimit - 1) : '0-0'; $items['searchtotal'] = $querycnt; if ($querycnt > 0) { $abentries = mapi_table_queryrows($table, array(PR_ACCOUNT, PR_DISPLAY_NAME, PR_SMTP_ADDRESS, PR_BUSINESS_TELEPHONE_NUMBER, PR_GIVEN_NAME, PR_SURNAME, PR_MOBILE_TELEPHONE_NUMBER, PR_HOME_TELEPHONE_NUMBER, PR_TITLE, PR_COMPANY_NAME, PR_OFFICE_LOCATION), $rangestart, $querylimit); } for ($i = 0; $i < $querylimit; $i++) { $items[$i][SYNC_GAL_DISPLAYNAME] = w2u($abentries[$i][PR_DISPLAY_NAME]); if (strlen(trim($items[$i][SYNC_GAL_DISPLAYNAME])) == 0) { $items[$i][SYNC_GAL_DISPLAYNAME] = w2u($abentries[$i][PR_ACCOUNT]); } $items[$i][SYNC_GAL_ALIAS] = w2u($abentries[$i][PR_ACCOUNT]); //it's not possible not get first and last name of an user //from the gab and user functions, so we just set lastname //to displayname and leave firstname unset //this was changed in Zarafa 6.40, so we try to get first and //last name and fall back to the old behaviour if these values are not set if (isset($abentries[$i][PR_GIVEN_NAME])) { $items[$i][SYNC_GAL_FIRSTNAME] = w2u($abentries[$i][PR_GIVEN_NAME]); } if (isset($abentries[$i][PR_SURNAME])) { $items[$i][SYNC_GAL_LASTNAME] = w2u($abentries[$i][PR_SURNAME]); } if (!isset($items[$i][SYNC_GAL_LASTNAME])) { $items[$i][SYNC_GAL_LASTNAME] = $items[$i][SYNC_GAL_DISPLAYNAME]; } $items[$i][SYNC_GAL_EMAILADDRESS] = w2u($abentries[$i][PR_SMTP_ADDRESS]); //check if an user has an office number or it might produce warnings in the log if (isset($abentries[$i][PR_BUSINESS_TELEPHONE_NUMBER])) { $items[$i][SYNC_GAL_PHONE] = w2u($abentries[$i][PR_BUSINESS_TELEPHONE_NUMBER]); } //check if an user has a mobile number or it might produce warnings in the log if (isset($abentries[$i][PR_MOBILE_TELEPHONE_NUMBER])) { $items[$i][SYNC_GAL_MOBILEPHONE] = w2u($abentries[$i][PR_MOBILE_TELEPHONE_NUMBER]); } //check if an user has a home number or it might produce warnings in the log if (isset($abentries[$i][PR_HOME_TELEPHONE_NUMBER])) { $items[$i][SYNC_GAL_HOMEPHONE] = w2u($abentries[$i][PR_HOME_TELEPHONE_NUMBER]); } if (isset($abentries[$i][PR_COMPANY_NAME])) { $items[$i][SYNC_GAL_COMPANY] = w2u($abentries[$i][PR_COMPANY_NAME]); } if (isset($abentries[$i][PR_TITLE])) { $items[$i][SYNC_GAL_TITLE] = w2u($abentries[$i][PR_TITLE]); } if (isset($abentries[$i][PR_OFFICE_LOCATION])) { $items[$i][SYNC_GAL_OFFICE] = w2u($abentries[$i][PR_OFFICE_LOCATION]); } } return $items; }
function openaddressbook() { $this->addressbook = mapi_openaddressbook($this->session); if (!$this->addressbook) { print "Unable to open addressbook\n"; exit(RESULT_ERROR_ADDRESSBOOK); } }
/** Returns user information who has task request */ function retrieveUserData() { // get user entryid $storeProps = mapi_getprops($this->store, array(PR_USER_ENTRYID)); if (!$storeProps[PR_USER_ENTRYID]) { return false; } $ab = mapi_openaddressbook($this->session); // open the user entry $user = mapi_ab_openentry($ab, $storeProps[PR_USER_ENTRYID]); if (!$user) { return false; } // receive userdata $userProps = mapi_getprops($user, array(PR_DISPLAY_NAME)); if (!$userProps[PR_DISPLAY_NAME]) { return false; } return $userProps; }
function _getSMTPAddressFromEntryID($entryid) { $ab = mapi_openaddressbook($this->_session); $mailuser = mapi_ab_openentry($ab, $entryid); if (!$mailuser) { return ""; } $props = mapi_getprops($mailuser, array(PR_ADDRTYPE, PR_SMTP_ADDRESS, PR_EMAIL_ADDRESS)); $addrtype = isset($props[PR_ADDRTYPE]) ? $props[PR_ADDRTYPE] : ""; if (isset($props[PR_SMTP_ADDRESS])) { return $props[PR_SMTP_ADDRESS]; } if ($addrtype == "SMTP" && isset($props[PR_EMAIL_ADDRESS])) { return $props[PR_EMAIL_ADDRESS]; } return ""; }
function getSearchResults($searchquery, $searchrange) { // only return users from who the displayName or the username starts with $name //TODO: use PR_ANR for this restriction instead of PR_DISPLAY_NAME and PR_ACCOUNT $addrbook = mapi_openaddressbook($this->_session); $ab_entryid = mapi_ab_getdefaultdir($addrbook); $ab_dir = mapi_ab_openentry($addrbook, $ab_entryid); $table = mapi_folder_getcontentstable($ab_dir); $restriction = $this->_getSearchRestriction(u2w($searchquery)); mapi_table_restrict($table, $restriction); mapi_table_sort($table, array(PR_DISPLAY_NAME => TABLE_SORT_ASCEND)); //range for the search results, default symbian range end is 50, wm 99, //so we'll use that of nokia $rangestart = 0; $rangeend = 50; if ($searchrange != '0') { $pos = strpos($searchrange, '-'); $rangestart = substr($searchrange, 0, $pos); $rangeend = substr($searchrange, $pos + 1); } $items = array(); $querycnt = mapi_table_getrowcount($table); //do not return more results as requested in range $querylimit = $rangeend + 1 < $querycnt ? $rangeend + 1 : $querycnt; $items['range'] = $rangestart . '-' . ($querylimit - 1); $abentries = mapi_table_queryrows($table, array(PR_ACCOUNT, PR_DISPLAY_NAME, PR_SMTP_ADDRESS, PR_BUSINESS_TELEPHONE_NUMBER), $rangestart, $querylimit); for ($i = 0; $i < $querylimit; $i++) { $items[$i]["username"] = w2u($abentries[$i][PR_ACCOUNT]); $items[$i]["fullname"] = w2u($abentries[$i][PR_DISPLAY_NAME]); if (strlen(trim($items[$i]["fullname"])) == 0) { $items[$i]["fullname"] = $items[$i]["username"]; } $items[$i]["emailaddress"] = w2u($abentries[$i][PR_SMTP_ADDRESS]); $items[$i]["nameid"] = $searchquery; //check if an user has a business phone or it might produce warnings in the log $items[$i]["businessphone"] = isset($abentries[$i][PR_BUSINESS_TELEPHONE_NUMBER]) ? w2u($abentries[$i][PR_BUSINESS_TELEPHONE_NUMBER]) : ""; } return $items; }
function readResolveRecipientfromGAL($emailaddress) { $ab = mapi_openaddressbook($this->_session); $ab_entryid = mapi_ab_getdefaultdir($ab); $ab_dir = mapi_ab_openentry($ab, $ab_entryid); $table = mapi_folder_getcontentstable($ab_dir); $restriction = array(RES_PROPERTY, array(RELOP => RELOP_EQ, ULPROPTAG => PR_SMTP_ADDRESS, VALUE => $emailaddress)); mapi_table_restrict($table, $restriction); $rows = mapi_table_queryrows($table, array(PR_ENTRYID, PR_DISPLAY_NAME, PR_SMTP_ADDRESS, PR_USER_CERTIFICATE), 0, 999); return $rows; }
/** * 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 = mapi_openaddressbook($this->session); $mstream = mapi_inetmapi_imtoinet($this->session, $addrBook, $mapimessage, array()); $mstreamstat = mapi_stream_stat($mstream); if ($mstreamstat['cb'] < MAX_EMBEDDED_SIZE) { if (Request::GetProtocolVersion() >= 12.0) { if (!isset($message->asbody)) { $message->asbody = new SyncBaseBody(); } //TODO data should be wrapped in a MapiStreamWrapper $message->asbody->data = mapi_stream_read($mstream, MAX_EMBEDDED_SIZE); $message->asbody->estimatedDataSize = $mstreamstat["cb"]; $message->asbody->truncated = 0; } else { $message->mimetruncated = 0; //TODO mimedata should be a wrapped in a MapiStreamWrapper $message->mimedata = mapi_stream_read($mstream, MAX_EMBEDDED_SIZE); $message->mimesize = $mstreamstat["cb"]; } unset($message->body, $message->bodytruncated); return true; } } return false; }
function SendMail($rfc822, $forward = false, $reply = false, $parent = false) { if (WBXML_DEBUG == true) { debugLog("SendMail: forward: {$forward} reply: {$reply} parent: {$parent}\n" . $rfc822); } // 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); //message properties to be set $mapiprops = array(); // only save the outgoing in sent items folder if the mobile requests it if (isset($storeprops[PR_IPM_SENTMAIL_ENTRYID])) { $mapiprops[PR_SENTMAIL_ENTRYID] = $storeprops[PR_IPM_SENTMAIL_ENTRYID]; } else { debugLog("PR_SENTMAIL_ENTRYID is not set. The sent message will not be moved to Sent Items."); } if ($forward) { $orig = $forward; } if ($reply) { $orig = $reply; } // Check if imtomapi function is available and use it to send the mime message. // It is available since ZCP 7.0.6 // @see http://jira.zarafa.com/browse/ZCP-9508 if (function_exists('mapi_feature') && mapi_feature('INETMAPI_IMTOMAPI')) { debugLog("Use the mapi_inetmapi_imtomapi function"); $ab = mapi_openaddressbook($this->_session); mapi_inetmapi_imtomapi($this->_session, $this->_defaultstore, $ab, $mapimessage, $rfc822, array()); // Delete the PR_SENT_REPRESENTING_* properties because some android devices // do not send neither From nor Sender header causing empty PR_SENT_REPRESENTING_NAME and // PR_SENT_REPRESENTING_EMAIL_ADDRESS properties and "broken" PR_SENT_REPRESENTING_ENTRYID // which results in spooler not being able to send the message. // @see http://jira.zarafa.com/browse/ZP-85 mapi_deleteprops($mapimessage, array(PR_SENT_REPRESENTING_NAME, PR_SENT_REPRESENTING_EMAIL_ADDRESS, PR_SENT_REPRESENTING_ENTRYID, PR_SENT_REPRESENTING_ADDRTYPE, PR_SENT_REPRESENTING_SEARCH_KEY)); if (isset($orig) && $orig) { $entryid = mapi_msgstore_entryidfromsourcekey($this->_defaultstore, hex2bin($parent), hex2bin($orig)); $fwmessage = mapi_msgstore_openentry($this->_defaultstore, $entryid); if ($fwmessage) { //update icon when forwarding or replying message if ($forward) { mapi_setprops($fwmessage, array(PR_ICON_INDEX => 262)); } elseif ($reply) { mapi_setprops($fwmessage, array(PR_ICON_INDEX => 261)); } mapi_savechanges($fwmessage); if ($forward) { $this->_copyAttachments($mapimessage, $fwmessage); } $body = $this->_readPropStream($mapimessage, PR_BODY); $body_html = $this->_readPropStream($mapimessage, PR_HTML); if (strlen($body) > 0) { $fwbody = $this->_readPropStream($fwmessage, PR_BODY); $body .= $fwbody; } if (strlen($body_html) > 0) { $fwbody_html = $this->_readPropStream($fwmessage, PR_HTML); $body_html .= $fwbody_html; } mapi_setprops($mapimessage, array(PR_BODY => $body)); if (strlen($body_html) > 0) { mapi_setprops($mapimessage, array(PR_HTML => $body_html)); } } } if (!empty($mapiprops)) { mapi_setprops($mapimessage, $mapiprops); } mapi_message_savechanges($mapimessage); mapi_message_submitmessage($mapimessage); $hr = mapi_last_hresult(); if ($hr) { debugLog(sprintf("SendMail(): Error saving/submitting the message to the Outbox: 0x%X", mapi_last_hresult())); return false; } return true; } $mimeParams = array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'charset' => 'utf-8'); $mimeObject = new Mail_mimeDecode($rfc822); $message = $mimeObject->decode($mimeParams); mapi_setprops($mapimessage, array(PR_SUBJECT => u2wi(isset($message->headers["subject"]) ? $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(); $Mail_RFC822 = new Mail_RFC822(); 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] = u2wi($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 message subparts. $body = ""; $body_html = ""; if ($message->ctype_primary == "multipart" && ($message->ctype_secondary == "mixed" || $message->ctype_secondary == "alternative")) { $mparts = $message->parts; for ($i = 0; $i < count($mparts); $i++) { $part = $mparts[$i]; // palm pre & iPhone send forwarded messages in another subpart which are also parsed if ($part->ctype_primary == "multipart" && ($part->ctype_secondary == "mixed" || $part->ctype_secondary == "alternative" || $part->ctype_secondary == "related")) { foreach ($part->parts as $spart) { $mparts[] = $spart; } continue; } // standard body if ($part->ctype_primary == "text" && $part->ctype_secondary == "plain" && isset($part->body) && (!isset($part->disposition) || $part->disposition != "attachment")) { $body .= u2wi($part->body); // assume only one text body } elseif ($part->ctype_primary == "text" && $part->ctype_secondary == "html") { $body_html .= u2wi($part->body); } elseif ($part->ctype_primary == "ms-tnef" || $part->ctype_secondary == "ms-tnef") { $zptnef = new ZPush_tnef($this->_defaultstore); $mapiprops = array(); $zptnef->extractProps($part->body, $mapiprops); if (is_array($mapiprops) && !empty($mapiprops)) { //check if it is a recurring item $tnefrecurr = GetPropIDFromString($this->_defaultstore, "PT_BOOLEAN:{6ED8DA90-450B-101B-98DA-00AA003F1305}:0x5"); if (isset($mapiprops[$tnefrecurr])) { $this->_handleRecurringItem($mapimessage, $mapiprops); } mapi_setprops($mapimessage, $mapiprops); } else { debugLog("TNEF: Mapi props array was empty"); } } elseif ($part->ctype_primary == "text" && $part->ctype_secondary == "calendar") { $zpical = new ZPush_ical($this->_defaultstore); $mapiprops = array(); $zpical->extractProps($part->body, $mapiprops); // iPhone sends a second ICS which we ignore if we can if (!isset($mapiprops[PR_MESSAGE_CLASS]) && strlen(trim($body)) == 0) { debugLog("Secondary iPhone response is being ignored!! Mail dropped!"); return true; } if (!checkMapiExtVersion("6.30") && is_array($mapiprops) && !empty($mapiprops)) { mapi_setprops($mapimessage, $mapiprops); } else { // store ics as attachment //see icalTimezoneFix function in compat.php for more information $part->body = icalTimezoneFix($part->body); $this->_storeAttachment($mapimessage, $part); debugLog("Sending ICS file as attachment"); } } else { $this->_storeAttachment($mapimessage, $part); } } } else { if ($message->ctype_primary == "text" && $message->ctype_secondary == "html") { $body_html .= u2wi($message->body); } else { $body = u2wi($message->body); } } // some devices only transmit a html body if (strlen($body) == 0 && strlen($body_html) > 0) { debugLog("only html body sent, transformed into plain text"); $body = strip_tags($body_html); } 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) { //update icon when forwarding or replying message if ($forward) { mapi_setprops($fwmessage, array(PR_ICON_INDEX => 262)); } elseif ($reply) { mapi_setprops($fwmessage, array(PR_ICON_INDEX => 261)); } mapi_savechanges($fwmessage); $fwbody = $this->_readPropStream($fwmessage, PR_BODY); $fwbody_html = $this->_readPropStream($fwmessage, PR_HTML); 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)); $fwheader = "\r\n\r\n"; $fwheader .= "-----Original Message-----\r\n"; if (isset($fwmessageprops[PR_SENT_REPRESENTING_NAME])) { $fwheader .= "From: " . $fwmessageprops[PR_SENT_REPRESENTING_NAME] . "\r\n"; } if (isset($fwmessageprops[PR_DISPLAY_TO]) && strlen($fwmessageprops[PR_DISPLAY_TO]) > 0) { $fwheader .= "To: " . $fwmessageprops[PR_DISPLAY_TO] . "\r\n"; } if (isset($fwmessageprops[PR_DISPLAY_CC]) && strlen($fwmessageprops[PR_DISPLAY_CC]) > 0) { $fwheader .= "Cc: " . $fwmessageprops[PR_DISPLAY_CC] . "\r\n"; } if (isset($fwmessageprops[PR_CLIENT_SUBMIT_TIME])) { $fwheader .= "Sent: " . strftime("%x %X", $fwmessageprops[PR_CLIENT_SUBMIT_TIME]) . "\r\n"; } if (isset($fwmessageprops[PR_SUBJECT])) { $fwheader .= "Subject: " . $fwmessageprops[PR_SUBJECT] . "\r\n"; } $fwheader .= "\r\n"; // add fwheader to body and body_html $body .= $fwheader; if (strlen($body_html) > 0) { $body_html .= str_ireplace("\r\n", "<br>", $fwheader); } } if (strlen($body) > 0) { $body .= $fwbody; } if (strlen($body_html) > 0) { $body_html .= $fwbody_html; } } 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); } } } //set PR_INTERNET_CPID to 65001 (utf-8) if store supports it and to 1252 otherwise $internetcpid = 1252; if (defined('STORE_SUPPORTS_UNICODE') && STORE_SUPPORTS_UNICODE == true) { $internetcpid = 65001; } mapi_setprops($mapimessage, array(PR_BODY => $body, PR_INTERNET_CPID => $internetcpid)); if (strlen($body_html) > 0) { mapi_setprops($mapimessage, array(PR_HTML => $body_html)); } mapi_savechanges($mapimessage); mapi_message_submitmessage($mapimessage); return true; }
/** * Returns a list with all GAB entries or a single entry specified by $uniqueId. * The search for that single entry is done using the configured UNIQUEID parameter. * If no entry is found for a $uniqueId an empty array() must be returned. * * @param string $uniqueId A value to be found in the configured UNIQUEID. * If set, only one item is returned. If false or not set, the entire GAB is returned. * Default: false * @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 array of GABEntry */ protected function getGAB($uniqueId = false, $gabId = null, $gabName = 'default') { $data = array(); $addrbook = mapi_openaddressbook($this->session); if (mapi_last_hresult()) { $this->Terminate(sprintf("Kopano->getGAB: Error opening addressbook 0x%08X", mapi_last_hresult())); } if ($gabId == null) { $ab_entryid = mapi_ab_getdefaultdir($addrbook); if (mapi_last_hresult()) { $this->Terminate(sprintf("Kopano->getGAB: Error, could not get '%s' address directory: 0x%08X", $gabName, mapi_last_hresult())); } } else { $ab_entryid = hex2bin($gabId); } $ab_dir = mapi_ab_openentry($addrbook, $ab_entryid); if (mapi_last_hresult()) { $this->Terminate(sprintf("Kopano->getGAB: Error, could not open '%s' address directory: 0x%08X", $gabName, mapi_last_hresult())); } $table = mapi_folder_getcontentstable($ab_dir); if (mapi_last_hresult()) { $this->Terminate(sprintf("Kopano->getGAB: error, could not open '%s' addressbook content table: 0x%08X", $gabName, mapi_last_hresult())); } // get all the groups $groups = mapi_zarafa_getgrouplist($this->store, $ab_entryid); // restrict the table if we should only return one if ($uniqueId) { $prop = $this->getPropertyForGABvalue(UNIQUEID); $restriction = array(RES_PROPERTY, array(RELOP => RELOP_EQ, ULPROPTAG => $prop, VALUE => $uniqueId)); mapi_table_restrict($table, $restriction); $querycnt = mapi_table_getrowcount($table); if ($querycnt == 0) { $this->Log(sprintf("Kopano->getGAB(): Single GAB entry '%s' requested but could not be found.", $uniqueId)); } elseif ($querycnt > 1) { $this->Terminate(sprintf("Kopano->getGAB(): Single GAB entry '%s' requested but %d entries found. Aborting.", $uniqueId, $querycnt)); } } $gabentries = mapi_table_queryallrows($table, array(PR_ENTRYID, PR_ACCOUNT, PR_DISPLAY_NAME, PR_SMTP_ADDRESS, PR_BUSINESS_TELEPHONE_NUMBER, PR_GIVEN_NAME, PR_SURNAME, PR_MOBILE_TELEPHONE_NUMBER, PR_HOME_TELEPHONE_NUMBER, PR_TITLE, PR_COMPANY_NAME, PR_OFFICE_LOCATION, PR_BEEPER_TELEPHONE_NUMBER, PR_PRIMARY_FAX_NUMBER, PR_ORGANIZATIONAL_ID_NUMBER, PR_POSTAL_ADDRESS, PR_BUSINESS_ADDRESS_CITY, PR_BUSINESS_ADDRESS_POSTAL_CODE, PR_BUSINESS_ADDRESS_POST_OFFICE_BOX, PR_BUSINESS_ADDRESS_STATE_OR_PROVINCE, PR_INITIALS, PR_LANGUAGE, PR_EMS_AB_THUMBNAIL_PHOTO, PR_DISPLAY_TYPE_EX)); foreach ($gabentries as $entry) { // do not add SYSTEM user to the GAB if (strtoupper($entry[PR_DISPLAY_NAME]) == "SYSTEM") { continue; } $a = new GABEntry(); $a->type = GABEntry::CONTACT; $a->memberOf = array(); $memberOf = mapi_zarafa_getgrouplistofuser($this->store, $entry[PR_ENTRYID]); if (is_array($memberOf)) { $a->memberOf = array_keys($memberOf); } // the company name is 'Everyone' if ($gabId != null && $entry[PR_DISPLAY_NAME] == $gabName) { $entry[PR_ACCOUNT] = "Everyone"; $entry[PR_DISPLAY_NAME] = "Everyone"; } // is this a group? if (array_key_exists($entry[PR_ACCOUNT], $groups)) { $a->type = GABEntry::GROUP; $groupentry = mapi_ab_openentry($addrbook, $entry[PR_ENTRYID]); $grouptable = mapi_folder_getcontentstable($groupentry, MAPI_DEFERRED_ERRORS); $users = mapi_table_queryallrows($grouptable, array(PR_ENTRYID, PR_ACCOUNT, PR_SMTP_ADDRESS)); $a->members = array(); if (is_array($users)) { foreach ($users as $user) { if ($user[PR_ENTRYID] == $entry[PR_ENTRYID]) { if (isset($user[PR_SMTP_ADDRESS])) { $a->smtpAddress = $user[PR_SMTP_ADDRESS]; } // don't add the group recursively continue; } $a->members[] = $user[PR_ACCOUNT]; } } } else { if (isset($entry[PR_DISPLAY_TYPE_EX]) && $entry[PR_DISPLAY_TYPE_EX] == DT_ROOM) { $a->type = GABEntry::ROOM; } else { if (isset($entry[PR_DISPLAY_TYPE_EX]) && $entry[PR_DISPLAY_TYPE_EX] == DT_EQUIPMENT) { $a->type = GABEntry::EQUIPMENT; } } } if (isset($entry[PR_ACCOUNT])) { $a->account = $entry[PR_ACCOUNT]; } if (isset($entry[PR_DISPLAY_NAME])) { $a->displayName = $entry[PR_DISPLAY_NAME]; } if (isset($entry[PR_GIVEN_NAME])) { $a->givenName = $entry[PR_GIVEN_NAME]; } if (isset($entry[PR_SURNAME])) { $a->surname = $entry[PR_SURNAME]; } if (isset($entry[PR_SMTP_ADDRESS])) { $a->smtpAddress = $entry[PR_SMTP_ADDRESS]; } if (isset($entry[PR_TITLE])) { $a->title = $entry[PR_TITLE]; } if (isset($entry[PR_COMPANY_NAME])) { $a->companyName = $entry[PR_COMPANY_NAME]; } if (isset($entry[PR_OFFICE_LOCATION])) { $a->officeLocation = $entry[PR_OFFICE_LOCATION]; } if (isset($entry[PR_BUSINESS_TELEPHONE_NUMBER])) { $a->businessTelephoneNumber = $entry[PR_BUSINESS_TELEPHONE_NUMBER]; } if (isset($entry[PR_MOBILE_TELEPHONE_NUMBER])) { $a->mobileTelephoneNumber = $entry[PR_MOBILE_TELEPHONE_NUMBER]; } if (isset($entry[PR_HOME_TELEPHONE_NUMBER])) { $a->homeTelephoneNumber = $entry[PR_HOME_TELEPHONE_NUMBER]; } if (isset($entry[PR_BEEPER_TELEPHONE_NUMBER])) { $a->beeperTelephoneNumber = $entry[PR_BEEPER_TELEPHONE_NUMBER]; } if (isset($entry[PR_PRIMARY_FAX_NUMBER])) { $a->primaryFaxNumber = $entry[PR_PRIMARY_FAX_NUMBER]; } if (isset($entry[PR_ORGANIZATIONAL_ID_NUMBER])) { $a->organizationalIdNumber = $entry[PR_ORGANIZATIONAL_ID_NUMBER]; } if (isset($entry[PR_POSTAL_ADDRESS])) { $a->postalAddress = $entry[PR_POSTAL_ADDRESS]; } if (isset($entry[PR_BUSINESS_ADDRESS_CITY])) { $a->businessAddressCity = $entry[PR_BUSINESS_ADDRESS_CITY]; } if (isset($entry[PR_BUSINESS_ADDRESS_POSTAL_CODE])) { $a->businessAddressPostalCode = $entry[PR_BUSINESS_ADDRESS_POSTAL_CODE]; } if (isset($entry[PR_BUSINESS_ADDRESS_POST_OFFICE_BOX])) { $a->businessAddressPostOfficeBox = $entry[PR_BUSINESS_ADDRESS_POST_OFFICE_BOX]; } if (isset($entry[PR_BUSINESS_ADDRESS_STATE_OR_PROVINCE])) { $a->businessAddressStateOrProvince = $entry[PR_BUSINESS_ADDRESS_STATE_OR_PROVINCE]; } if (isset($entry[PR_INITIALS])) { $a->initials = $entry[PR_INITIALS]; } if (isset($entry[PR_LANGUAGE])) { $a->language = $entry[PR_LANGUAGE]; } if (isset($entry[PR_EMS_AB_THUMBNAIL_PHOTO])) { $a->thumbnailPhoto = base64_encode($entry[PR_EMS_AB_THUMBNAIL_PHOTO]); } $data[] = $a; } return $data; }
function getSearchResultsGAL($searchquery) { // only return users from who the displayName or the username starts with $name //TODO: use PR_ANR for this restriction instead of PR_DISPLAY_NAME and PR_ACCOUNT $addrbook = mapi_openaddressbook($this->_session); $ab_entryid = mapi_ab_getdefaultdir($addrbook); $ab_dir = mapi_ab_openentry($addrbook, $ab_entryid); $table = mapi_folder_getcontentstable($ab_dir); $restriction = $this->_getSearchRestriction(u2w($searchquery)); mapi_table_restrict($table, $restriction); mapi_table_sort($table, array(PR_DISPLAY_NAME => TABLE_SORT_ASCEND)); // CHANGED dw2412 AS V12.0 Support (to menetain single return way... $items['rows'] = array(); for ($i = 0; $i < mapi_table_getrowcount($table); $i++) { $user_data = mapi_table_queryrows($table, array(PR_ACCOUNT, PR_DISPLAY_NAME, PR_SMTP_ADDRESS, PR_BUSINESS_TELEPHONE_NUMBER), $i, 1); $item = array(); $item["username"] = w2u($user_data[0][PR_ACCOUNT]); $item["fullname"] = w2u($user_data[0][PR_DISPLAY_NAME]); if (strlen(trim($item["fullname"])) == 0) { $item["fullname"] = $item["username"]; } $item["emailaddress"] = w2u($user_data[0][PR_SMTP_ADDRESS]); $item["nameid"] = $searchquery; $item["businessphone"] = isset($user_data[0][PR_BUSINESS_TELEPHONE_NUMBER]) ? w2u($user_data[0][PR_BUSINESS_TELEPHONE_NUMBER]) : ""; //do not return users without email if (strlen(trim($item["emailaddress"])) == 0) { continue; } // CHANGED dw2412 AS V12.0 Support (to menetain single return way... array_push($items['rows'], $item); } $items['status'] = 1; return $items; }