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 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);
$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;
}
开发者ID:nnaannoo,项目名称:paskot,代码行数:74,代码来源:ics.php
示例6: GetMessage
/**
* Returns the actual SyncXXX object type.
*
* @param string $folderid id of the parent folder
* @param string $id id of the message
* @param ContentParameters $contentparameters parameters of the requested message (truncation, mimesupport etc)
*
* @access public
* @return object/false false if the message could not be retrieved
*/
public function GetMessage($folderid, $id, $truncsize, $mimesupport = 0)
{
if ($folderid != 'root') {
return false;
}
$fn = $this->findMessage($id);
// Get flags, etc
$stat = $this->StatMessage($folderid, $id);
// Parse e-mail
$rfc822 = file_get_contents($this->getPath() . "/" . $fn);
$message = Mail_mimeDecode::decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'input' => $rfc822, 'crlf' => "\n", 'charset' => 'utf-8'));
$output = new SyncMail();
$output->body = str_replace("\n", "\r\n", $this->getBody($message));
$output->bodysize = strlen($output->body);
$output->bodytruncated = 0;
// We don't implement truncation in this backend
$output->datereceived = $this->parseReceivedDate($message->headers["received"][0]);
$output->messageclass = "IPM.Note";
$output->subject = $message->headers["subject"];
$output->read = $stat["flags"];
$output->from = $message->headers["from"];
$Mail_RFC822 = new Mail_RFC822();
$toaddr = $ccaddr = $replytoaddr = 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["reply_to"])) {
$replytoaddr = $Mail_RFC822->parseAddressList($message->headers["reply_to"]);
}
$output->to = array();
$output->cc = array();
$output->reply_to = array();
foreach (array("to" => $toaddr, "cc" => $ccaddr, "reply_to" => $replytoaddr) as $type => $addrlist) {
foreach ($addrlist as $addr) {
$address = $addr->mailbox . "@" . $addr->host;
$name = $addr->personal;
if (!isset($output->displayto) && $name != "") {
$output->displayto = $name;
}
if ($name == "" || $name == $address) {
$fulladdr = w2u($address);
} else {
if (substr($name, 0, 1) != '"' && substr($name, -1) != '"') {
$fulladdr = "\"" . w2u($name) . "\" <" . w2u($address) . ">";
} else {
$fulladdr = w2u($name) . " <" . w2u($address) . ">";
}
}
array_push($output->{$type}, $fulladdr);
}
}
// convert mime-importance to AS-importance
if (isset($message->headers["x-priority"])) {
$mimeImportance = preg_replace("/\\D+/", "", $message->headers["x-priority"]);
if ($mimeImportance > 3) {
$output->importance = 0;
}
if ($mimeImportance == 3) {
$output->importance = 1;
}
if ($mimeImportance < 3) {
$output->importance = 2;
}
}
// Attachments are only searched in the top-level part
$n = 0;
if (isset($message->parts)) {
foreach ($message->parts as $part) {
if ($part->ctype_primary == "application") {
$attachment = new SyncAttachment();
$attachment->attsize = strlen($part->body);
if (isset($part->d_parameters['filename'])) {
$attname = $part->d_parameters['filename'];
} else {
if (isset($part->ctype_parameters['name'])) {
$attname = $part->ctype_parameters['name'];
} else {
if (isset($part->headers['content-description'])) {
$attname = $part->headers['content-description'];
} else {
$attname = "unknown attachment";
}
}
}
$attachment->displayname = $attname;
$attachment->attname = $id . ":" . $n;
$attachment->attmethod = 1;
//.........这里部分代码省略.........
/**
* Gets the out of office settings
*
* @param SyncObject $oof
*
* @access private
* @return void
*/
private function settingsOofGet(&$oof)
{
$oofprops = mapi_getprops($this->defaultstore, array(PR_EC_OUTOFOFFICE, PR_EC_OUTOFOFFICE_MSG, PR_EC_OUTOFOFFICE_SUBJECT, PR_EC_OUTOFOFFICE_FROM, PR_EC_OUTOFOFFICE_UNTIL));
$oof->oofstate = SYNC_SETTINGSOOF_DISABLED;
$oof->Status = SYNC_SETTINGSSTATUS_SUCCESS;
if ($oofprops != false) {
$oof->oofstate = isset($oofprops[PR_EC_OUTOFOFFICE]) ? $oofprops[PR_EC_OUTOFOFFICE] ? SYNC_SETTINGSOOF_GLOBAL : SYNC_SETTINGSOOF_DISABLED : SYNC_SETTINGSOOF_DISABLED;
//TODO external and external unknown
$oofmessage = new SyncOOFMessage();
$oofmessage->appliesToInternal = "";
$oofmessage->enabled = $oof->oofstate;
$oofmessage->replymessage = isset($oofprops[PR_EC_OUTOFOFFICE_MSG]) ? w2u($oofprops[PR_EC_OUTOFOFFICE_MSG]) : "";
$oofmessage->bodytype = $oof->bodytype;
unset($oofmessage->appliesToExternal, $oofmessage->appliesToExternalUnknown);
$oof->oofmessage[] = $oofmessage;
// check whether time based out of office is set
if ($oof->oofstate == SYNC_SETTINGSOOF_GLOBAL && isset($oofprops[PR_EC_OUTOFOFFICE_FROM]) && isset($oofprops[PR_EC_OUTOFOFFICE_UNTIL])) {
if ($oofprops[PR_EC_OUTOFOFFICE_FROM] < $oofprops[PR_EC_OUTOFOFFICE_UNTIL]) {
$oof->oofstate = SYNC_SETTINGSOOF_TIMEBASED;
$oof->starttime = $oofprops[PR_EC_OUTOFOFFICE_FROM];
$oof->endtime = $oofprops[PR_EC_OUTOFOFFICE_UNTIL];
} else {
ZLog::Write(LOGLEVEL_WARN, sprintf("BackendKopano->settingsOofGet(): Time based out of office set but end time ('%s') is before startime ('%s').", date("Y-m-d H:i:s", $oofprops[PR_EC_OUTOFOFFICE_FROM]), date("Y-m-d H:i:s", $oofprops[PR_EC_OUTOFOFFICE_UNTIL])));
$oof->Status = SYNC_SETTINGSSTATUS_PROTOCOLLERROR;
}
} elseif ($oof->oofstate == SYNC_SETTINGSOOF_GLOBAL && (isset($oofprops[PR_EC_OUTOFOFFICE_FROM]) || isset($oofprops[PR_EC_OUTOFOFFICE_UNTIL]))) {
ZLog::Write(LOGLEVEL_WARN, sprintf("Kopano->settingsOofGet(): Time based out of office set but either start time ('%s') or end time ('%s') is missing.", isset($oofprops[PR_EC_OUTOFOFFICE_FROM]) ? date("Y-m-d H:i:s", $oofprops[PR_EC_OUTOFOFFICE_FROM]) : 'empty', isset($oofprops[PR_EC_OUTOFOFFICE_UNTIL]) ? date("Y-m-d H:i:s", $oofprops[PR_EC_OUTOFOFFICE_UNTIL]) : 'empty'));
$oof->Status = SYNC_SETTINGSSTATUS_PROTOCOLLERROR;
}
} else {
ZLog::Write(LOGLEVEL_WARN, "Unable to get out of office information");
}
//unset body type for oof in order not to stream it
unset($oof->bodytype);
}
请发表评论