Example #1
0
 private function KolabReadTask($message, $id, $disableAlarm = false, $with_uid = false)
 {
     $task = NULL;
     if (isset($message->parts)) {
         foreach ($message->parts as $part) {
             if (isset($part->disposition) && ($part->disposition == "attachment" || $part->disposition == "inline")) {
                 $type = $part->headers;
                 //kolab contact attachment ?
                 $ctype = explode(";", $type["content-type"]);
                 if ($ctype[0] == " application/x-vnd.kolab.task") {
                     $format = Horde_Kolab_Format::factory('XML', 'task');
                     $body = $part->body;
                     $ktask = $format->load($body);
                     unset($format);
                     if ($ktask instanceof PEAR_Error) {
                         //parsing error
                         debugLog("ERROR " . $ktask->message);
                         debugLog("Xml kolab :     {$body}");
                         $this->Log("ERROR " . $ktask->message);
                         $this->Log("XML : {$body}");
                         unset($ktask);
                         return "";
                     }
                     //mappage
                     $task = new SyncTask();
                     if ($with_uid != 0) {
                         $task->uid = hex2bin($ktask['uid']);
                     }
                     $task->subject = w2u($ktask['name']);
                     if ($ktask['start']) {
                         $offset = date('Z', $ktask['start']);
                         $task->utcstartdate = $kstart['start'];
                         $task->startdate = $ktask['start'] + $offset;
                     }
                     if ($ktask['due']) {
                         $offset = date('Z', $ktask['due']);
                         $task->utcduedate = $ktask['due'];
                         $task->duedate = $ktask['due'] + $offset;
                     }
                     $task->complete = $ktask['completed'];
                     if (isset($ktask['completed_date'])) {
                         $task->datecompleted = $ktask['completed_date'];
                     }
                     //categories
                     if (isset($ktask['categories'])) {
                         $cat = split(',', w2u($ktask['categories']));
                         $task->categories = $cat;
                     }
                     switch ($ktask['priority']) {
                         case 1:
                             $task->importance = 2;
                             break;
                         case 2:
                         case 3:
                         case 4:
                             $task->importance = 1;
                             break;
                         case 5:
                             $task->importance = 0;
                     }
                     switch (strtolower($ktask['sensitivity'])) {
                         case "public":
                             $task->sensitivity = 0;
                             break;
                         case "private":
                             $task->sensitivity = 2;
                             break;
                         case "confidential":
                             $task->sensitivity = 3;
                     }
                     //bug #9 Alarm mus not be shown for all folders
                     if ($disableAlarm == false) {
                         if ($ktask['alarm'] > 0) {
                             $task->remindertime = $ktask["start"] + $ktask['alarm'] * 60;
                             $task->reminderset = 1;
                         }
                     } else {
                         $task->reminderset = NULL;
                         $task->remindertime = NULL;
                     }
                     $task->body = w2u($ktask['body']);
                     //timezone must be fixed
                     $task->bodytruncated = 0;
                     //reccurence process
                     if (isset($ktask["recurrence"])) {
                         $task->reccurence = $this->kolabReadRecurrence($ktask, 1);
                     }
                     return $task;
                 }
                 $n++;
             }
         }
     }
     return "";
 }
Example #2
0
 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;
 }
Example #3
0
 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;
 }
Example #4
0
 function getSettings($request, $devid)
 {
     if (isset($request["userinformation"])) {
         $response["userinformation"]["status"] = true;
         $response["userinformation"]["emailaddresses"][] = $userdetails["emailaddress"];
     }
     if (isset($request["oof"])) {
         if ($props != false) {
             $response["oof"]["status"] = 1;
             // return oof messsage and where it should apply here
             $response["oof"]["oofstate"] = 0;
             $oofmsg["appliesto"] = SYNC_SETTINGS_APPLIESTOINTERNAL;
             $oofmsg["replymessage"] = w2u("");
             $oofmsg["enabled"] = 0;
             $oofmsg["bodytype"] = $request["oof"]["bodytype"];
             $response["oof"]["oofmsgs"][] = $oofmsg;
             // $this->settings["outofoffice"]["subject"] = windows1252_to_utf8(isset($props[PR_EC_OUTOFOFFICE_SUBJECT]) ? $props[PR_EC_OUTOFOFFICE_SUBJECT] : "");
         } else {
             $response["oof"]["status"] = 0;
         }
     }
     return $response;
 }
Example #5
0
 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;
 }
Example #6
0
 /**
  * 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;
                 $attachment->attoid = isset($part->headers['content-id']) ? $part->headers['content-id'] : "";
                 array_push($output->attachments, $attachment);
             }
             $n++;
         }
     }
     return $output;
 }
Example #7
0
 function GetMessage($folderid, $id, $truncsize, $bodypreference = false, $optionbodypreference = false, $mimesupport = 0)
 {
     debugLog('iConDir::GetMessage(' . $folderid . ', ' . $this->_items[$id] . ', ..)');
     if ($folderid != "root") {
         return;
     }
     $types = array('dom' => 'type', 'intl' => 'type', 'postal' => 'type', 'parcel' => 'type', 'home' => 'type', 'work' => 'type', 'pref' => 'type', 'voice' => 'type', 'fax' => 'type', 'msg' => 'type', 'cell' => 'type', 'pager' => 'type', 'bbs' => 'type', 'modem' => 'type', 'car' => 'type', 'isdn' => 'type', 'video' => 'type', 'aol' => 'type', 'applelink' => 'type', 'attmail' => 'type', 'cis' => 'type', 'eworld' => 'type', 'internet' => 'type', 'ibmmail' => 'type', 'mcimail' => 'type', 'powershare' => 'type', 'prodigy' => 'type', 'tlx' => 'type', 'x400' => 'type', 'gif' => 'type', 'cgm' => 'type', 'wmf' => 'type', 'bmp' => 'type', 'met' => 'type', 'pmb' => 'type', 'dib' => 'type', 'pict' => 'type', 'tiff' => 'type', 'pdf' => 'type', 'ps' => 'type', 'jpeg' => 'type', 'qtime' => 'type', 'mpeg' => 'type', 'mpeg2' => 'type', 'avi' => 'type', 'wave' => 'type', 'aiff' => 'type', 'pcm' => 'type', 'x509' => 'type', 'pgp' => 'type', 'text' => 'value', 'inline' => 'value', 'url' => 'value', 'cid' => 'value', 'content-id' => 'value', '7bit' => 'encoding', '8bit' => 'encoding', 'quoted-printable' => 'encoding', 'base64' => 'encoding');
     // Parse the vcard
     $message = new SyncContact();
     $data = file_get_contents($this->_path . "/" . $this->_items[$id]);
     $data = str_replace("", '', $data);
     $data = str_replace("\r\n", "\n", $data);
     $data = str_replace("\r", "\n", $data);
     $data = preg_replace('/(\\n)([ \\t])/i', '', $data);
     $data = utf8_decode($data);
     $lines = explode("\n", $data);
     $vcard = array();
     foreach ($lines as $line) {
         if (trim($line) == '') {
             continue;
         }
         $pos = strpos($line, ':');
         if ($pos === false) {
             continue;
         }
         $field = trim(substr($line, 0, $pos));
         $value = trim(substr($line, $pos + 1));
         $fieldparts = preg_split('/(?<!\\\\)(\\;)/i', $field, -1, PREG_SPLIT_NO_EMPTY);
         $type = strtolower(array_shift($fieldparts));
         $fieldvalue = array();
         foreach ($fieldparts as $fieldpart) {
             if (preg_match('/([^=]+)=(.+)/', $fieldpart, $matches)) {
                 if (!in_array(strtolower($matches[1]), array('value', 'type', 'encoding', 'language'))) {
                     continue;
                 }
                 if (isset($fieldvalue[strtolower($matches[1])]) && is_array($fieldvalue[strtolower($matches[1])])) {
                     $fieldvalue[strtolower($matches[1])] = array_merge($fieldvalue[strtolower($matches[1])], preg_split('/(?<!\\\\)(\\,)/i', $matches[2], -1, PREG_SPLIT_NO_EMPTY));
                 } else {
                     $fieldvalue[strtolower($matches[1])] = preg_split('/(?<!\\\\)(\\,)/i', $matches[2], -1, PREG_SPLIT_NO_EMPTY);
                 }
             } else {
                 if (!isset($types[strtolower($fieldpart)])) {
                     continue;
                 }
                 $fieldvalue[$types[strtolower($fieldpart)]][] = $fieldpart;
             }
         }
         //
         switch ($type) {
             case 'categories':
                 //case 'nickname':
                 $val = preg_split('/(?<!\\\\)(\\,)/i', $value);
                 $val = array_map("w2ui", $val);
                 break;
             default:
                 $val = preg_split('/(?<!\\\\)(\\;)/i', $value);
                 break;
         }
         if (isset($fieldvalue['encoding'][0])) {
             switch (strtolower($fieldvalue['encoding'][0])) {
                 case 'q':
                 case 'quoted-printable':
                     foreach ($val as $i => $v) {
                         $val[$i] = quoted_printable_decode($v);
                     }
                     break;
                 case 'b':
                 case 'base64':
                     foreach ($val as $i => $v) {
                         $val[$i] = base64_decode($v);
                     }
                     break;
             }
         } else {
             foreach ($val as $i => $v) {
                 $val[$i] = $this->unescape($v);
             }
         }
         $fieldvalue['val'] = $val;
         $vcard[$type][] = $fieldvalue;
     }
     $fieldmapping = $this->_mapping;
     foreach ($fieldmapping as $k => $v) {
         switch ($v) {
             case 'body':
                 if ($bodypreference == false) {
                     $message->body = w2u(str_replace("\n", "\r\n", str_replace("\r", "", $vcard[$k][0]['val'][0])));
                     $message->bodysize = strlen($message->body);
                     $message->bodytruncated = 0;
                 } else {
                     $message->airsyncbasebody = new SyncAirSyncBaseBody();
                     debugLog("airsyncbasebody!");
                     $message->airsyncbasenativebodytype = 1;
                     if (isset($bodypreference[2])) {
                         debugLog("HTML Body");
                         // Send HTML if requested and native type was html
                         $message->airsyncbasebody->type = 2;
                         $html = '<html>' . '<head>' . '<meta name="Generator" content="Z-Push">' . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . '</head>' . '<body>' . str_replace("\n", "<BR>", str_replace("\r", "<BR>", str_replace("\r\n", "<BR>", w2u($vcard[$k][0]['val'][0])))) . '</body>' . '</html>';
                         if (isset($bodypreference[2]["TruncationSize"]) && strlen($html) > $bodypreference[2]["TruncationSize"]) {
                             $html = utf8_truncate($html, $bodypreference[2]["TruncationSize"]);
                             $message->airsyncbasebody->truncated = 1;
                         }
                         $message->airsyncbasebody->data = $html;
                         $message->airsyncbasebody->estimateddatasize = strlen($html);
                     } else {
                         // Send Plaintext as Fallback or if original body is plaintext
                         debugLog("Plaintext Body");
                         $plain = w2u(str_replace("\n", "\r\n", str_replace("\r", "", $vcard[$k][0]['val'][0])));
                         $message->airsyncbasebody->type = 1;
                         if (isset($bodypreference[1]["TruncationSize"]) && strlen($plain) > $bodypreference[1]["TruncationSize"]) {
                             $plain = utf8_truncate($plain, $bodypreference[1]["TruncationSize"]);
                             $message->airsyncbasebody->truncated = 1;
                         }
                         $message->airsyncbasebody->estimateddatasize = strlen($plain);
                         $message->airsyncbasebody->data = $plain;
                     }
                     // In case we have nothing for the body, send at least a blank...
                     // dw2412 but only in case the body is not rtf!
                     if ($message->airsyncbasebody->type != 3 && (!isset($message->airsyncbasebody->data) || strlen($message->airsyncbasebody->data) == 0)) {
                         $message->airsyncbasebody->data = " ";
                     }
                 }
                 break;
             case 'birthday':
                 if (!empty($vcard[$k][0]['val'][0])) {
                     $tz = date_default_timezone_get();
                     date_default_timezone_set('UTC');
                     $message->{$fieldmapping}[$k] = strtotime($vcard[$k][0]['val'][0]);
                     date_default_timezone_set($tz);
                 }
                 break;
             case 'picture':
                 $message->{$fieldmapping}[$k] = !empty($vcard[$k][0]['val'][0]) ? base64_encode($vcard[$k][0]['val'][0]) : NULL;
                 break;
             default:
                 $message->{$fieldmapping}[$k] = !empty($vcard[$k][0]['val'][0]) ? w2u($vcard[$k][0]['val'][0]) : NULL;
         }
     }
     return $message;
 }
Example #8
0
 function GetMessage($folderid, $id, $truncsize, $bodypreference = false, $optionbodypreference = false, $mimesupport = 0)
 {
     debugLog('GContacts::GetMessage(' . $folderid . ', ' . $this->_items[$id] . ', ..)');
     if ($folderid != "root") {
         return;
     }
     debugLog("GContacts::GetMessage: (fid: '{$folderid}'  id: '{$id}' )");
     // Parse the vcard
     $message = new SyncContact();
     try {
         // perform query and get feed of all results
         $query = new Zend_Gdata_Query(GCONTACTS_URL . '/' . $id);
         $entry = $this->service->getEntry($query);
     } catch (Zend_Gdata_App_Exception $e) {
         debugLog("GContacts::GetMessage - ERROR! (" . $e->getMessage() . ")");
         return false;
     }
     // parse feed and extract contact information
     // into simpler objects
     try {
         $doc = new DOMDocument();
         $doc->formatOutput = true;
         //$obj = new stdClass;
         //$obj->edit = $entry->getEditLink()->href;
         $xmldata = $entry->getXML();
         $doc->loadXML($xmldata);
         //filter out real contact id without other garbage
         preg_match("/[_a-z0-9]+\$/", $entry->id, $matches);
         $contactid = $matches[0];
         $fh = fopen(STATE_DIR . '/xml-get/' . (string) $entry->title . '_' . (string) $contactid . '.xml', 'w');
         fwrite($fh, $doc->saveXML());
         $xml = simplexml_load_string($xmldata);
         fclose($fh);
         //Prefix:
         //givenName:	 ok
         //Middle:
         //familyName:		ok
         //nameSuffix:	ok
         //last
         //first
         //middlename
         //title
         //suffix
         if (!empty($xml->name->fullName)) {
             debugLog('GContacts::GetMessage - fullName: ' . (string) $xml->name->fullName);
             $message->fileas = w2ui($xml->name->fullName);
         }
         //    if (!empty($xml->name->namePrefix)){
         //	debugLog('GContacts::GetMessage - namePrefix: '.(string) $xml->name->namePrefix);
         //	$message->middlename = w2ui($xml->name->namePrefix);
         //    }
         if (!empty($xml->name->givenName)) {
             debugLog('GContacts::GetMessage - givenName: ' . (string) $xml->name->givenName);
             $message->firstname = w2ui($xml->name->givenName);
         }
         //if (!empty($xml->name->????)){
         //	debugLog('GContacts::GetMessage - familyName: '.(string) $xml->name->????);
         //	$message->title = w2ui($xml->name->^^^^);
         //    }
         if (!empty($xml->name->familyName)) {
             debugLog('GContacts::GetMessage - familyName: ' . (string) $xml->name->familyName);
             $message->lastname = w2ui($xml->name->familyName);
         }
         if (!empty($xml->name->nameSuffix)) {
             debugLog('GContacts::GetMessage - nameSuffix: ' . (string) $xml->name->nameSuffix);
             $message->suffix = w2ui($xml->name->nameSuffix);
         }
         if (!empty($xml->organization->orgName)) {
             debugLog('GContacts::GetMessage - orgName: ' . (string) $xml->organization->orgName);
             $message->companyname = w2ui($xml->organization->orgName);
         }
         if (!empty($xml->organization->orgTitle)) {
             debugLog('GContacts::GetMessage - orgName: ' . (string) $xml->organization->orgTitle);
             $message->jobtitle = w2ui($xml->organization->orgTitle);
         }
         if (!empty($xml->nickname)) {
             debugLog('GContacts::GetMessage - Nickname: ' . (string) $xml->nickname);
             $message->nickname = w2ui($xml->nickname);
         }
         foreach ($xml->email as $e) {
             debugLog('GContacts::GetMessage - email: ' . (string) $e['address']);
             if (empty($message->email1address)) {
                 $message->email1address = w2ui($e['address']);
             } elseif (empty($message->email2address)) {
                 $message->email2address = w2ui($e['address']);
             } elseif (empty($message->email3address)) {
                 $message->email3address = w2ui($e['address']);
             } else {
                 debugLog('GContacts::GetMessage - LOST email address: ' . (string) $e['address']);
             }
         }
         foreach ($xml->im as $i) {
             debugLog('GContacts::GetMessage - im: ' . (string) $i['address']);
             if (empty($message->imaddress)) {
                 $message->imaddress = w2ui($i['address']);
             } elseif (empty($message->im2address)) {
                 $message->imaddress2 = w2ui($i['address']);
             } elseif (empty($message->imaddress3)) {
                 $message->imaddress3 = w2ui($i['address']);
             } else {
                 debugLog('GContacts::GetMessage - LOST im address: ' . (string) $i['address']);
             }
         }
         foreach ($xml->structuredPostalAddress as $p) {
             switch ($p['key']) {
                 case 'Children':
                     debugLog($p['key'] . ': ' . (string) $p['value']);
                     $message->children = w2ui($p['value']);
                     break;
                 case 'Spouse':
                     debugLog($p['key'] . ': ' . (string) $p['value']);
                     $message->spouse = w2ui($p['value']);
                     break;
             }
         }
         foreach ($xml->structuredPostalAddress as $p) {
             preg_match("/[_a-z0-9]+\$/", $p['rel'], $matches);
             $rel = $matches[0];
             switch ($rel) {
                 case 'home':
                     $a = 'home';
                     break;
                 case 'work':
                     break;
                 case 'office':
                     $a = 'business';
                     break;
                 case 'other':
                     $a = 'other';
                     break;
                 default:
                     debugLog('GContacts::GetMessage - structuredPostalAddress di tipo ' . $rel . ': non censito');
                     break;
             }
             if (!empty($p->street)) {
                 $b = $a . 'street';
                 debugLog($b . ': ' . (string) $p->street);
                 $message->{$b} = w2ui($p->street);
             }
             if (!empty($p->city)) {
                 $b = $a . 'city';
                 debugLog($b . ': ' . (string) $p->city);
                 $message->{$b} = w2ui($p->city);
             }
             if (!empty($p->postcode)) {
                 $b = $a . 'postalcode';
                 debugLog($b . ': ' . (string) $p->postcode);
                 $message->{$b} = w2ui($p->postcode);
             }
             if (!empty($p->region)) {
                 $b = $a . 'state';
                 debugLog($b . ': ' . (string) $p->region);
                 $message->{$b} = w2ui($p->region);
             }
             if (!empty($p->country)) {
                 $b = $a . 'country';
                 debugLog($b . ': ' . (string) $p->country);
                 $message->{$b} = w2ui($p->country);
             }
         }
         foreach ($xml->phoneNumber as $p) {
             preg_match("/[_a-z0-9]+\$/", $p['rel'], $matches);
             $rel = $matches[0];
             switch ($rel) {
                 case 'home':
                     if (empty($message->homephonenumber)) {
                         debugLog('GContacts::GetMessage - homephonenumber: ' . (string) $p);
                         $message->homephonenumber = w2ui($p);
                     } elseif (empty($message->home2phonenumber)) {
                         debugLog('GContacts::GetMessage - home2phonenumber: ' . (string) $p);
                         $message->home2phonenumber = w2ui($p);
                     } else {
                         debugLog('GContacts::GetMessage - LOST phone number: ' . (string) $p);
                     }
                     break;
                 case 'home_fax':
                     if (empty($message->homefaxnumber)) {
                         debugLog('GContacts::GetMessage - homefaxnumber: ' . (string) $p);
                         $message->homefaxnumber = w2ui($p);
                     } else {
                         debugLog('GContacts::GetMessage - LOST phone number: ' . (string) $p);
                     }
                     break;
                 case 'work_fax':
                     if (empty($message->businessfaxnumber)) {
                         debugLog('GContacts::GetMessage - businessfaxnumber: ' . (string) $p);
                         $message->businessfaxnumber = w2ui($p);
                     } else {
                         debugLog('GContacts::GetMessage - LOST phone number: ' . (string) $p);
                     }
                     break;
                 case 'mobile':
                     if (empty($message->mobilephonenumber)) {
                         debugLog('GContacts::GetMessage - mobilephonenumber: ' . (string) $p);
                         $message->mobilephonenumber = w2ui($p);
                     } elseif (empty($message->home2phonenumber)) {
                         debugLog('GContacts::GetMessage - home2phonenumber: ' . (string) $p);
                         $message->home2phonenumber = w2ui($p);
                     } elseif (empty($message->radiophonenumber)) {
                         debugLog('GContacts::GetMessage - radiophonenumber: ' . (string) $p);
                         $message->radiophonenumber = w2ui($p);
                     } else {
                         debugLog('GContacts::GetMessage - LOST phone number: ' . (string) $p);
                     }
                     break;
                 case 'work':
                     if (empty($message->businessphonenumber)) {
                         debugLog('GContacts::GetMessage - businessphonenumber: ' . (string) $p);
                         $message->businessphonenumber = w2ui($p);
                     } elseif (empty($message->business2phonenumber)) {
                         debugLog('GContacts::GetMessage - business2phonenumber: ' . (string) $p);
                         $message->business2phonenumber = w2ui($p);
                     } else {
                         debugLog('GContacts::GetMessage - LOST phone number: ' . (string) $p);
                     }
                     break;
                 case 'pager':
                     if (empty($message->pagernumber)) {
                         debugLog('GContacts::GetMessage - pagernumber: ' . (string) $p);
                         $message->pagernumber = w2ui($p);
                     } else {
                         debugLog('GContacts::GetMessage - LOST phone number: ' . (string) $p);
                     }
                     break;
                 case 'main':
                 case 'other':
                     if (empty($message->homephonenumber)) {
                         debugLog('GContacts::GetMessage - homephonenumber: ' . (string) $p);
                         $message->homephonenumber = w2ui($p);
                     } elseif (empty($message->home2phonenumber)) {
                         debugLog('GContacts::GetMessage - home2phonenumber: ' . (string) $p);
                         $message->home2phonenumber = w2ui($p);
                     } elseif (empty($message->businessphonenumber)) {
                         debugLog('GContacts::GetMessage - businessphonenumber: ' . (string) $p);
                         $message->businessphonenumber = w2ui($p);
                     } elseif (empty($message->business2phonenumber)) {
                         debugLog('GContacts::GetMessage - business2phonenumber: ' . (string) $p);
                         $message->business2phonenumber = w2ui($p);
                     } elseif (empty($message->carphonenumber)) {
                         debugLog('GContacts::GetMessage - carphonenumber: ' . (string) $p);
                         $message->carphonenumber = w2ui($p);
                     } else {
                         debugLog('GContacts::GetMessage - LOST phone number: ' . (string) $p);
                     }
                     break;
                 default:
                     debugLog('GContacts::GetMessage - LOST phone number: ' . (string) $p . ' phoneNumber di tipo ' . $rel . ': non censito');
                     break;
             }
         }
         if (!empty($xml->birthday['when'])) {
             debugLog('GContacts::GetMessage - birthday: ' . (string) $xml->birthday['when']);
             $tz = date_default_timezone_get();
             date_default_timezone_set('UTC');
             $message->birthday = strtotime($xml->birthday['when']);
             date_default_timezone_set($tz);
         }
         foreach ($xml->website as $w) {
             debugLog('GContacts::GetMessage - webpage: ' . (string) $w['href']);
             $message->webpage = w2ui($w['href']);
         }
         //$e["id"] = (string)$contactid;
         //$e["flags"] = "1";
         //$e["mod"] = strtotime((string)$entry->getUpdated());
         //$results[] = $e;
         //debugLog((string)$entry->getUpdated());
         if (!empty($entry->content)) {
             debugLog('GContacts::GetMessage - Note: ' . (string) $entry->content);
             if ($bodypreference === false) {
                 $message->body = w2ui($entry->content);
                 $message->bodysize = strlen($entry->content);
                 $message->bodytruncated = 0;
             } else {
                 if (isset($bodypreference[1]) && !isset($bodypreference[1]["TruncationSize"])) {
                     $bodypreference[1]["TruncationSize"] = 1024 * 1024;
                 }
                 if (isset($bodypreference[2]) && !isset($bodypreference[2]["TruncationSize"])) {
                     $bodypreference[2]["TruncationSize"] = 1024 * 1024;
                 }
                 if (isset($bodypreference[3]) && !isset($bodypreference[3]["TruncationSize"])) {
                     $bodypreference[3]["TruncationSize"] = 1024 * 1024;
                 }
                 if (isset($bodypreference[4]) && !isset($bodypreference[4]["TruncationSize"])) {
                     $bodypreference[4]["TruncationSize"] = 1024 * 1024;
                 }
                 $message->airsyncbasebody = new SyncAirSyncBaseBody();
                 debugLog("airsyncbasebody!");
                 $body = "";
                 $plain = $entry->content;
                 if (isset($bodypreference[2])) {
                     debugLog("HTML Body");
                     // Send HTML if requested and native type was html
                     $message->airsyncbasebody->type = 2;
                     $html = '<html>' . '<head>' . '<meta name="Generator" content="Z-Push">' . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . '</head>' . '<body>' . str_replace("\n", "<BR>", str_replace("\r", "<BR>", str_replace("\r\n", "<BR>", w2u($plain)))) . '</body>' . '</html>';
                     if (isset($bodypreference[2]["TruncationSize"]) && strlen($html) > $bodypreference[2]["TruncationSize"]) {
                         $html = utf8_truncate($html, $bodypreference[2]["TruncationSize"]);
                         $message->airsyncbasebody->truncated = 1;
                     }
                     $message->airsyncbasebody->data = $html;
                     $message->airsyncbasebody->estimateddatasize = strlen($html);
                 } else {
                     // Send Plaintext as Fallback or if original body is plaintext
                     debugLog("Plaintext Body");
                     $plain = $entry->content;
                     $plain = w2u(str_replace("\n", "\r\n", str_replace("\r", "", $plain)));
                     $message->airsyncbasebody->type = 1;
                     if (isset($bodypreference[1]["TruncationSize"]) && strlen($plain) > $bodypreference[1]["TruncationSize"]) {
                         $plain = utf8_truncate($plain, $bodypreference[1]["TruncationSize"]);
                         $message->airsyncbasebody->truncated = 1;
                     }
                     $message->airsyncbasebody->estimateddatasize = strlen($plain);
                     $message->airsyncbasebody->data = $plain;
                 }
                 // In case we have nothing for the body, send at least a blank...
                 // dw2412 but only in case the body is not rtf!
                 if ($message->airsyncbasebody->type != 3 && (!isset($message->airsyncbasebody->data) || strlen($message->airsyncbasebody->data) == 0)) {
                     $message->airsyncbasebody->data = " ";
                 }
             }
         }
         if (!empty($vcard['categories'][0]['val'])) {
             $message->categories = $vcard['categories'][0]['val'];
         }
         if (!empty($vcard['photo'][0]['val'][0])) {
             $message->picture = base64_encode($vcard['photo'][0]['val'][0]);
         }
     } catch (Exception $e) {
         debugLog('Gcontacts::GetMessageList - Problem retrieving data (' . $e->exception() . ')');
         return false;
     }
     return $message;
     /*
     $types = array ('dom' => 'type', 'intl' => 'type', 'postal' => 'type', 'parcel' => 'type', 'home' => 'type', 'work' => 'type',
         'pref' => 'type', 'voice' => 'type', 'fax' => 'type', 'msg' => 'type', 'cell' => 'type', 'pager' => 'type',
         'bbs' => 'type', 'modem' => 'type', 'car' => 'type', 'isdn' => 'type', 'video' => 'type',
         'aol' => 'type', 'applelink' => 'type', 'attmail' => 'type', 'cis' => 'type', 'eworld' => 'type',
         'internet' => 'type', 'ibmmail' => 'type', 'mcimail' => 'type',
         'powershare' => 'type', 'prodigy' => 'type', 'tlx' => 'type', 'x400' => 'type',
         'gif' => 'type', 'cgm' => 'type', 'wmf' => 'type', 'bmp' => 'type', 'met' => 'type', 'pmb' => 'type', 'dib' => 'type',
         'pict' => 'type', 'tiff' => 'type', 'pdf' => 'type', 'ps' => 'type', 'jpeg' => 'type', 'qtime' => 'type',
         'mpeg' => 'type', 'mpeg2' => 'type', 'avi' => 'type',
         'wave' => 'type', 'aiff' => 'type', 'pcm' => 'type',
         'x509' => 'type', 'pgp' => 'type', 'text' => 'value', 'inline' => 'value', 'url' => 'value', 'cid' => 'value', 'content-id' => 'value',
         '7bit' => 'encoding', '8bit' => 'encoding', 'quoted-printable' => 'encoding', 'base64' => 'encoding',
     );
     
     
     // Parse the vcard
     $message = new SyncContact();
     
     $data = file_get_contents($this->_path . "/" . $this->_items[$id]);
     $data = str_replace("\x00", '', $data);
     $data = str_replace("\r\n", "\n", $data);
     $data = str_replace("\r", "\n", $data);
     $data = preg_replace('/(\n)([ \t])/i', '', $data);
     
     $lines = explode("\n", $data);
     
     $vcard = array();
     foreach($lines as $line) {
         if (trim($line) == '')
     	continue;
         $pos = strpos($line, ':');
         if ($pos === false)
     	continue;
     
         $field = trim(substr($line, 0, $pos));
         $value = trim(substr($line, $pos+1));
     
         $fieldparts = preg_split('/(?<!\\\\)(\;)/i', $field, -1, PREG_SPLIT_NO_EMPTY);
     
         $type = strtolower(array_shift($fieldparts));
     
         $fieldvalue = array();
     
         foreach ($fieldparts as $fieldpart) {
     	if(preg_match('/([^=]+)=(.+)/', $fieldpart, $matches)){
     	    if(!in_array(strtolower($matches[1]),array('value','type','encoding','language')))
     		continue;
     	    if(isset($fieldvalue[strtolower($matches[1])]) && is_array($fieldvalue[strtolower($matches[1])])){
     		$fieldvalue[strtolower($matches[1])] = array_merge($fieldvalue[strtolower($matches[1])], preg_split('/(?<!\\\\)(\,)/i', $matches[2], -1, PREG_SPLIT_NO_EMPTY));
     	    }else{
     		$fieldvalue[strtolower($matches[1])] = preg_split('/(?<!\\\\)(\,)/i', $matches[2], -1, PREG_SPLIT_NO_EMPTY);
     	    }
     	}else{
     	    if(!isset($types[strtolower($fieldpart)]))
     		continue;
     	    $fieldvalue[$types[strtolower($fieldpart)]][] = $fieldpart;
     	}
         }
         //
         switch ($type) {
     	case 'categories':
     	    //case 'nickname':
     	    $val = preg_split('/(?<!\\\\)(\,)/i', $value);
     	    $val = array_map("w2ui", $val);
     	    break;
     	default:
     	    $val = preg_split('/(?<!\\\\)(\;)/i', $value);
     	    break;
         }
         if(isset($fieldvalue['encoding'][0])){
     	switch(strtolower($fieldvalue['encoding'][0])){
     	    case 'q':
     	    case 'quoted-printable':
     		foreach($val as $i => $v){
     		    $val[$i] = quoted_printable_decode($v);
     		}
     		break;
     	    case 'b':
     	    case 'base64':
     		foreach($val as $i => $v){
     		    $val[$i] = base64_decode($v);
     		}
     		break;
     	}
         }else{
     	foreach($val as $i => $v){
     	    $val[$i] = $this->unescape($v);
     	}
         }
         $fieldvalue['val'] = $val;
         $vcard[$type][] = $fieldvalue;
     }
     */
     /*
     	if(isset($vcard['tel'])){
     	    foreach($vcard['tel'] as $tel) {
     		if(!isset($tel['type'])){
     		    $tel['type'] = array();
     		}
     		if(in_array('car', $tel['type'])){
     		    $message->carphonenumber = $tel['val'][0];
     		}elseif(in_array('pager', $tel['type'])){
     		    $message->pagernumber = $tel['val'][0];
     		}elseif(in_array('cell', $tel['type'])){
     		    $message->mobilephonenumber = $tel['val'][0];
     		}elseif(in_array('home', $tel['type'])){
     		    if(in_array('fax', $tel['type'])){
     			$message->homefaxnumber = $tel['val'][0];
     		    }elseif(empty($message->homephonenumber)){
     			$message->homephonenumber = $tel['val'][0];
     		    }else{
     			$message->home2phonenumber = $tel['val'][0];
     		    }
     		}elseif(in_array('work', $tel['type'])){
     		    if(in_array('fax', $tel['type'])){
     			$message->businessfaxnumber = $tel['val'][0];
     		    }elseif(empty($message->businessphonenumber)){
     			$message->businessphonenumber = $tel['val'][0];
     		    }else{
     			$message->business2phonenumber = $tel['val'][0];
     		    }
     		}elseif(empty($message->homephonenumber)){
     		    $message->homephonenumber = $tel['val'][0];
     		}elseif(empty($message->home2phonenumber)){
     		    $message->home2phonenumber = $tel['val'][0];
     		}else{
     		    $message->radiophonenumber = $tel['val'][0];
     		}
     	    }
     	}
     */
     if (!empty($vcard['categories'][0]['val'])) {
         $message->categories = $vcard['categories'][0]['val'];
     }
     if (!empty($vcard['photo'][0]['val'][0])) {
         $message->picture = base64_encode($vcard['photo'][0]['val'][0]);
     }
     return $message;
 }
Example #9
0
 /**
  * Resolves recipient from the GAL and gets his certificates.
  *
  * @param string $to
  * @return SyncResolveRecipient|boolean
  */
 private function resolveRecipientGAL($to)
 {
     $addrbook = $this->getAddressbook();
     $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->resolveRecipient(): could not open addressbook: 0x%X", mapi_last_hresult()), SYNC_RESOLVERECIPSSTATUS_RESPONSE_UNRESOLVEDRECIP);
     if (!$table) {
         ZLog::Write(LOGLEVEL_WARN, sprintf("Unable to open addressbook:0x%X", mapi_last_hresult()));
         return false;
     }
     $restriction = MAPIUtils::GetSearchRestriction(u2w($to));
     mapi_table_restrict($table, $restriction);
     $querycnt = mapi_table_getrowcount($table);
     if ($querycnt > 0) {
         $abentries = mapi_table_queryrows($table, array(PR_DISPLAY_NAME, PR_EMS_AB_TAGGED_X509_CERT), 0, 1);
         $certificates = isset($abentries[0][PR_EMS_AB_TAGGED_X509_CERT]) && is_array($abentries[0][PR_EMS_AB_TAGGED_X509_CERT]) && count($abentries[0][PR_EMS_AB_TAGGED_X509_CERT]) ? $this->getCertificates($abentries[0][PR_EMS_AB_TAGGED_X509_CERT], $querycnt) : false;
         if ($certificates === false) {
             // the recipient does not have a valid certificate, set the appropriate status
             ZLog::Write(LOGLEVEL_INFO, sprintf("No certificates found for '%s'", $to));
             $certificates = $this->getCertificates(false);
         }
         $recipient = $this->createResolveRecipient(SYNC_RESOLVERECIPIENTS_TYPE_GAL, w2u($abentries[0][PR_DISPLAY_NAME]), $to, $certificates);
         return $recipient;
     } else {
         ZLog::Write(LOGLEVEL_WARN, sprintf("No recipient found for: '%s'", $to));
         return SYNC_RESOLVERECIPSSTATUS_RESPONSE_UNRESOLVEDRECIP;
     }
     return false;
 }
 function Convert()
 {
     $message = $this->_mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'rfc_822bodies' => true, 'include_bodies' => true, 'crlf' => "\n", 'charset' => BACKEND_CHARSET));
     $rawmessage = $this->_mobj->decode(array('decode_headers' => false, 'decode_bodies' => true, 'rfc_822bodies' => true, 'include_bodies' => true, 'crlf' => "\n", 'charset' => BACKEND_CHARSET));
     $body = "";
     foreach ($rawmessage->headers as $key => $value) {
         if ($key != "content-type" && $key != "mime-version" && $key != "content-transfer-encoding" && !is_array($value)) {
             $body .= $key . ":";
             // Split -> Explode replace
             $tokens = explode(" ", trim($value));
             $line = "";
             foreach ($tokens as $valu) {
                 if (strlen($line) + strlen($valu) + 2 > 60) {
                     $line .= "\n";
                     $body .= $line;
                     $line = " " . $valu;
                 } else {
                     $line .= " " . $valu;
                 }
             }
             $body .= $line . "\n";
         }
     }
     unset($rawmessage);
     $mimemsg = new Mail_mime(array('head_encoding' => 'quoted-printable', 'text_encoding' => 'quoted-printable', 'html_encoding' => 'base64', 'head_charset' => 'utf-8', 'text_charset' => 'utf-8', 'html_charset' => 'utf-8', 'eol' => "\n", 'delay_file_io' => false));
     $this->getAllAttachmentsRecursive($message, $mimemsg);
     if ($this->_nativebodytype == 1) {
         $this->getBodyRecursive($message, "plain", $plain);
         $this->getBodyRecursive($message, "html", $html);
         if ($html == "") {
             $this->getBodyRecursive($message, "plain", $html);
         }
         if ($html == "" && $plain == "" && strlen($this->_mobj->_body) != "") {
             $body .= "Content-Type:" . $message->headers['content-type'] . "\r\n";
             $body .= "Content-Transfer-Encoding:" . $message->headers['content-transfer-encoding'] . "\r\n";
             $body .= "\n\n" . $this->_mobj->_body;
             return $body;
         }
         $mimemsg->setTXTBody(str_replace("\n", "\r\n", str_replace("\r", "", w2u($plain))));
         $html = '<html>' . '<head>' . '<meta name="Generator" content="Z-Push">' . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . '</head>' . '<body>' . str_replace("\n", "<BR>", str_replace("\r", "", str_replace("\r\n", "<BR>", w2u($html)))) . '</body>' . '</html>';
         $mimemsg->setHTMLBody(str_replace("\n", "\r\n", str_replace("\r", "", $html)));
     }
     if ($this->_nativebodytype == 2) {
         $this->getBodyRecursive($message, "plain", $plain);
         if ($plain == "") {
             $this->getBodyRecursive($message, "html", $plain);
             // remove css-style tags
             $plain = preg_replace("/<style.*?<\\/style>/is", "", $plain);
             // remove all other html
             $plain = preg_replace("/<br.*>/is", "<br>", $plain);
             $plain = preg_replace("/<br >/is", "<br>", $plain);
             $plain = preg_replace("/<br\\/>/is", "<br>", $plain);
             $plain = str_replace("<br>", "\r\n", $plain);
             $plain = strip_tags($plain);
         }
         $mimemsg->setTXTBody(str_replace("\n", "\r\n", str_replace("\r", "", w2u($plain))));
         $this->getBodyRecursive($message, "html", $html);
         $mimemsg->setHTMLBody(str_replace("\n", "\r\n", str_replace("\r", "", w2u($html))));
     }
     if (!isset($output->airsyncbasebody->data)) {
         $body = $body . $mimemsg->txtheaders() . "\n\n" . $mimemsg->get();
     }
     return $body;
 }
Example #11
0
 function getEmailAddress($str)
 {
     if (strrpos($str, " ") && $str[0] != "\"") {
         $str = "\"" . substr($str, 0, strrpos($str, " ")) . "\"" . substr($str, strrpos($str, " "));
     }
     $address = imap_rfc822_parse_adrlist($str, "domain.com");
     if ($address[0]) {
         $email = $address[0]->mailbox . "@" . (isset($address[0]->host) ? $address[0]->host : "localhost");
         $str = $email;
     }
     return w2u($str);
 }
Example #12
0
 function GetFolder($id)
 {
     $folder = new SyncFolder();
     $folder->serverid = $id;
     // get real imap id from cache
     $id = $this->_folders[$id];
     // explode hierarchy
     $fhir = explode(".", $id);
     // compare on lowercase strings
     $lid = strtolower($id);
     if ($lid == "inbox") {
         $folder->parentid = "0";
         // Root
         $folder->displayname = "Inbox";
         $folder->type = SYNC_FOLDER_TYPE_INBOX;
     } else {
         if ($lid == "drafts") {
             $folder->parentid = "0";
             $folder->displayname = "Drafts";
             $folder->type = SYNC_FOLDER_TYPE_DRAFTS;
         } else {
             if ($lid == "trash" || $lid == "deleted items") {
                 $folder->parentid = "0";
                 $folder->displayname = "Trash";
                 $folder->type = SYNC_FOLDER_TYPE_WASTEBASKET;
                 $this->_wasteID = $id;
             } else {
                 if ($lid == "sent" || $lid == "sent items" || $lid == IMAP_SENTFOLDER) {
                     $folder->parentid = "0";
                     $folder->displayname = "Sent";
                     $folder->type = SYNC_FOLDER_TYPE_SENTMAIL;
                     $this->_sentID = $id;
                 } else {
                     if ($lid == "outbox") {
                         $folder->parentid = "0";
                         // Root
                         $folder->displayname = "Outbox";
                         $folder->type = SYNC_FOLDER_TYPE_OUTBOX;
                     } else {
                         if ($lid == "inbox.drafts") {
                             $folder->parentid = $fhir[0];
                             $folder->displayname = "Drafts";
                             $folder->type = SYNC_FOLDER_TYPE_DRAFTS;
                         } else {
                             if ($lid == "inbox.trash") {
                                 $folder->parentid = $fhir[0];
                                 $folder->displayname = "Trash";
                                 $folder->type = SYNC_FOLDER_TYPE_WASTEBASKET;
                                 $this->_wasteID = $id;
                             } else {
                                 if ($lid == "inbox.sent") {
                                     $folder->parentid = $fhir[0];
                                     $folder->displayname = "Sent";
                                     $folder->type = SYNC_FOLDER_TYPE_SENTMAIL;
                                     $this->_sentID = $id;
                                 } else {
                                     if ($lid == "inbox.outbox") {
                                         $folder->parentid = "0";
                                         // Root
                                         $folder->displayname = "Outbox";
                                         $folder->type = SYNC_FOLDER_TYPE_OUTBOX;
                                     } else {
                                         if (count($fhir) > 1) {
                                             $folder->displayname = w2u(imap_utf7_decode(array_pop($fhir)));
                                             if (($folder->parentid = array_search(implode(".", $fhir), $this->_folders)) === false) {
                                                 $folder->parentid = $this->_folderid();
                                                 $this->_folders[$folder->parentid] = implode(".", $fhir);
                                             }
                                         } else {
                                             $folder->displayname = w2u(imap_utf7_decode($id));
                                             $folder->parentid = "0";
                                         }
                                         $folder->type = SYNC_FOLDER_TYPE_USER_MAIL;
                                         // Type Other is not displayed on i.e. Nokia
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     //advanced debugging
     //debugLog("IMAP-GetFolder(id: '$id') -> " . print_r($folder, 1));
     file_put_contents(STATE_DIR . '/imap_folders_' . $this->_user, serialize($this->_folders));
     return $folder;
 }
Example #13
0
 /**
  * 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);
 }
Example #14
0
 function _getFolder($mapifolder)
 {
     $folder = new SyncFolder();
     $folderprops = mapi_getprops($mapifolder, array(PR_DISPLAY_NAME, PR_PARENT_ENTRYID, PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY, PR_ENTRYID));
     $storeprops = mapi_getprops($this->_store, array(PR_IPM_SUBTREE_ENTRYID));
     if (!isset($folderprops[PR_DISPLAY_NAME]) || !isset($folderprops[PR_PARENT_ENTRYID]) || !isset($folderprops[PR_SOURCE_KEY]) || !isset($folderprops[PR_ENTRYID]) || !isset($folderprops[PR_PARENT_SOURCE_KEY]) || !isset($storeprops[PR_IPM_SUBTREE_ENTRYID])) {
         debugLog("Missing properties on folder");
         return false;
     }
     $folder->serverid = bin2hex($folderprops[PR_SOURCE_KEY]);
     if ($folderprops[PR_PARENT_ENTRYID] == $storeprops[PR_IPM_SUBTREE_ENTRYID]) {
         $folder->parentid = "0";
     } else {
         $folder->parentid = bin2hex($folderprops[PR_PARENT_SOURCE_KEY]);
     }
     $folder->displayname = w2u($folderprops[PR_DISPLAY_NAME]);
     $folder->type = $this->_getFolderType($folderprops[PR_ENTRYID]);
     return $folder;
 }
Example #15
0
 function GetMessage($folderid, $id, $truncsize, $bodypreference = false, $optionbodypreference = false, $mimesupport = 0)
 {
     debugLog('iCalDir::GetMessage(' . $folderid . ', ' . $this->_items[$id] . ', ..)');
     if ($folderid != "root") {
         return;
     }
     $types = array('dom' => 'type', 'intl' => 'type', 'postal' => 'type', 'parcel' => 'type', 'home' => 'type', 'work' => 'type', 'pref' => 'type', 'voice' => 'type', 'fax' => 'type', 'msg' => 'type', 'cell' => 'type', 'pager' => 'type', 'bbs' => 'type', 'modem' => 'type', 'car' => 'type', 'isdn' => 'type', 'video' => 'type', 'aol' => 'type', 'applelink' => 'type', 'attmail' => 'type', 'cis' => 'type', 'eworld' => 'type', 'internet' => 'type', 'ibmmail' => 'type', 'mcimail' => 'type', 'powershare' => 'type', 'prodigy' => 'type', 'tlx' => 'type', 'x400' => 'type', 'gif' => 'type', 'cgm' => 'type', 'wmf' => 'type', 'bmp' => 'type', 'met' => 'type', 'pmb' => 'type', 'dib' => 'type', 'pict' => 'type', 'tiff' => 'type', 'pdf' => 'type', 'ps' => 'type', 'jpeg' => 'type', 'qtime' => 'type', 'mpeg' => 'type', 'mpeg2' => 'type', 'avi' => 'type', 'wave' => 'type', 'aiff' => 'type', 'pcm' => 'type', 'x509' => 'type', 'pgp' => 'type', 'text' => 'value', 'inline' => 'value', 'url' => 'value', 'cid' => 'value', 'content-id' => 'value', '7bit' => 'encoding', '8bit' => 'encoding', 'quoted-printable' => 'encoding', 'base64' => 'encoding', 'uid' => 'value');
     // Parse the vcard
     $message = new SyncAppointment();
     $data = file_get_contents($this->_path . "/" . $this->_items[$id]);
     $data = str_replace("", '', $data);
     $data = str_replace("\r\n", "\n", $data);
     $data = str_replace("\r", "\n", $data);
     $data = preg_replace('/(\\n)([ \\t])/i', '', $data);
     $data = utf8_decode($data);
     $lines = explode("\n", $data);
     $vcard = array();
     foreach ($lines as $line) {
         if (trim($line) == '') {
             continue;
         }
         $pos = strpos($line, ':');
         if ($pos === false) {
             continue;
         }
         $field = trim(substr($line, 0, $pos));
         $value = trim(substr($line, $pos + 1));
         $fieldparts = preg_split('/(?<!\\\\)(\\;)/i', $field, -1, PREG_SPLIT_NO_EMPTY);
         $type = strtolower(array_shift($fieldparts));
         $fieldvalue = array();
         foreach ($fieldparts as $fieldpart) {
             if (preg_match('/([^=]+)=(.+)/', $fieldpart, $matches)) {
                 if (!in_array(strtolower($matches[1]), array('value', 'type', 'encoding', 'language'))) {
                     continue;
                 }
                 if (isset($fieldvalue[strtolower($matches[1])]) && is_array($fieldvalue[strtolower($matches[1])])) {
                     $fieldvalue[strtolower($matches[1])] = array_merge($fieldvalue[strtolower($matches[1])], preg_split('/(?<!\\\\)(\\,)/i', $matches[2], -1, PREG_SPLIT_NO_EMPTY));
                 } else {
                     $fieldvalue[strtolower($matches[1])] = preg_split('/(?<!\\\\)(\\,)/i', $matches[2], -1, PREG_SPLIT_NO_EMPTY);
                 }
             } else {
                 if (!isset($types[strtolower($fieldpart)])) {
                     continue;
                 }
                 $fieldvalue[$types[strtolower($fieldpart)]][] = $fieldpart;
             }
         }
         //
         switch ($type) {
             case 'categories':
                 //case 'nickname':
                 $val = preg_split('/(?<!\\\\)(\\,)/i', $value);
                 $val = array_map("w2ui", $val);
                 break;
             default:
                 $val = preg_split('/(?<!\\\\)(\\;)/i', $value);
                 break;
         }
         if (isset($fieldvalue['encoding'][0])) {
             switch (strtolower($fieldvalue['encoding'][0])) {
                 case 'q':
                 case 'quoted-printable':
                     foreach ($val as $i => $v) {
                         $val[$i] = quoted_printable_decode($v);
                     }
                     break;
                 case 'b':
                 case 'base64':
                     foreach ($val as $i => $v) {
                         $val[$i] = base64_decode($v);
                     }
                     break;
             }
         } else {
             foreach ($val as $i => $v) {
                 $val[$i] = $this->unescape($v);
             }
         }
         $fieldvalue['val'] = $val;
         $vcard[$type][] = $fieldvalue;
     }
     // debugLog('iCalDir::LoadedMessage-source:' . print_r($vcard,1));
     //http://www.zachstronaut.com/posts/2009/02/09/careful-with-php-empty.html
     // We pass all times in GMT to device. Calculation to gmt takes place based on timezone definition in config.php
     $message->timezone = base64_encode($this->_getSyncBlobFromTZ(array("bias" => 0, "dstendmonth" => 0, "dstendday" => 0, "dstendweek" => 0, "dstendhour" => 0, "dstendminute" => 0, "dstendsecond" => 0, "dstendmillis" => 0, "stdbias" => 0, "dststartmonth" => 0, "dststartday" => 0, "dststartweek" => 0, "dststarthour" => 0, "dststartminute" => 0, "dststartsecond" => 0, "dststartmillis" => 0, "dstbias" => 0)));
     $fieldmapping = $this->_mapping;
     foreach ($fieldmapping as $k => $v) {
         switch ($v) {
             // these fields should be filled with 0
             case 'busystatus':
             case 'sensitivity':
             case 'meetingstatus':
             case 'alldayevent':
                 $message->{$fieldmapping}[$k] = !empty($vcard[$k][0]['val'][0]) ? w2u($vcard[$k][0]['val'][0]) : "0";
                 break;
             case 'starttime':
             case 'endtime':
             case 'dtstamp':
                 if (empty($vcard[$k][0]['val'][0])) {
                     $message->{$fieldmapping}[$k] = NULL;
                     break;
                 }
                 $time = w2u($vcard[$k][0]['val'][0]);
                 $time = gmmktime(gmdate("H", $time), gmdate("i", $time), gmdate("s", $time), gmdate("n", $time), gmdate("j", $time), gmdate("Y", $time));
                 $message->{$fieldmapping}[$k] = $time;
                 break;
             case 'body':
                 if ($bodypreference == false) {
                     $message->body = w2u(str_replace("\n", "\r\n", str_replace("\r", "", $vcard[$k][0]['val'][0])));
                     $message->bodysize = strlen($message->body);
                     $message->bodytruncated = 0;
                 } else {
                     $message->airsyncbasebody = new SyncAirSyncBaseBody();
                     debugLog("airsyncbasebody!");
                     $message->airsyncbasenativebodytype = 1;
                     if (isset($bodypreference[2])) {
                         debugLog("HTML Body");
                         // Send HTML if requested and native type was html
                         $message->airsyncbasebody->type = 2;
                         $html = '<html>' . '<head>' . '<meta name="Generator" content="Z-Push">' . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . '</head>' . '<body>' . str_replace("\n", "<BR>", str_replace("\r", "<BR>", str_replace("\r\n", "<BR>", w2u($vcard[$k][0]['val'][0])))) . '</body>' . '</html>';
                         if (isset($bodypreference[2]["TruncationSize"]) && strlen($html) > $bodypreference[2]["TruncationSize"]) {
                             $html = utf8_truncate($html, $bodypreference[2]["TruncationSize"]);
                             $message->airsyncbasebody->truncated = 1;
                         }
                         $message->airsyncbasebody->data = $html;
                         $message->airsyncbasebody->estimateddatasize = strlen($html);
                     } else {
                         // Send Plaintext as Fallback or if original body is plaintext
                         debugLog("Plaintext Body");
                         $plain = w2u(str_replace("\n", "\r\n", str_replace("\r", "", $vcard[$k][0]['val'][0])));
                         $message->airsyncbasebody->type = 1;
                         if (isset($bodypreference[1]["TruncationSize"]) && strlen($plain) > $bodypreference[1]["TruncationSize"]) {
                             $plain = utf8_truncate($plain, $bodypreference[1]["TruncationSize"]);
                             $message->airsyncbasebody->truncated = 1;
                         }
                         $message->airsyncbasebody->estimateddatasize = strlen($plain);
                         $message->airsyncbasebody->data = $plain;
                     }
                     // In case we have nothing for the body, send at least a blank...
                     // dw2412 but only in case the body is not rtf!
                     if ($message->airsyncbasebody->type != 3 && (!isset($message->airsyncbasebody->data) || strlen($message->airsyncbasebody->data) == 0)) {
                         $message->airsyncbasebody->data = " ";
                     }
                 }
                 break;
             default:
                 $vs = explode("->", $v);
                 if ($vs[0] == "recurrence" && !empty($vcard[$k][0]['val'][0])) {
                     if (!isset($message->recurrence)) {
                         $message->recurrence = new SyncRecurrence();
                     }
                     $message->recurrence->{$vs}[1] = !empty($vcard[$k][0]['val'][0]) ? w2u($vcard[$k][0]['val'][0]) : NULL;
                 } else {
                     $message->{$fieldmapping}[$k] = !empty($vcard[$k][0]['val'][0]) ? w2u($vcard[$k][0]['val'][0]) : NULL;
                 }
         }
     }
     if (!isset($message->uid) || strlen($message->uid) == 0) {
         $message->uid = $this->_uid();
     }
     if (isset($message->recurrence)) {
         if (!isset($message->recurrence->interval)) {
             debugLog('iCalDir::GetMessage: Error, recurrence object found but no interval is set. Set it to 1 since it needs to be set');
             $message->recurrence->interval = 1;
         }
     }
     // debugLog('iCalDir::LoadedMessage-imported:' . print_r($message,1));
     return $message;
 }
Example #16
0
 /**
  * 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, $contentparameters)
 {
     $truncsize = Utils::GetTruncSize($contentparameters->GetTruncation());
     $mimesupport = $contentparameters->GetMimeSupport();
     $bodypreference = $contentparameters->GetBodyPreference();
     /* fmbiete's contribution r1528, ZP-320 */
     ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessage('%s','%s')", $folderid, $id));
     $folderImapid = $this->getImapIdFromFolderId($folderid);
     // Get flags, etc
     $stat = $this->StatMessage($folderid, $id);
     if ($stat) {
         $this->imap_reopenFolder($folderImapid);
         $mail = @imap_fetchheader($this->mbox, $id, FT_UID) . @imap_body($this->mbox, $id, FT_PEEK | FT_UID);
         $mobj = new Mail_mimeDecode($mail);
         $message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'charset' => 'utf-8'));
         /* BEGIN fmbiete's contribution r1528, ZP-320 */
         $output = new SyncMail();
         //Select body type preference
         $bpReturnType = SYNC_BODYPREFERENCE_PLAIN;
         if ($bodypreference !== false) {
             $bpReturnType = Utils::GetBodyPreferenceBestMatch($bodypreference);
             // changed by mku ZP-330
         }
         ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessage - getBodyPreferenceBestMatch: %d", $bpReturnType));
         //Get body data
         $this->getBodyRecursive($message, "plain", $plainBody);
         $this->getBodyRecursive($message, "html", $htmlBody);
         if ($plainBody == "") {
             $plainBody = Utils::ConvertHtmlToText($htmlBody);
         }
         $htmlBody = str_replace("\n", "\r\n", str_replace("\r", "", $htmlBody));
         $plainBody = str_replace("\n", "\r\n", str_replace("\r", "", $plainBody));
         if (Request::GetProtocolVersion() >= 12.0) {
             $output->asbody = new SyncBaseBody();
             switch ($bpReturnType) {
                 case SYNC_BODYPREFERENCE_PLAIN:
                     $output->asbody->data = $plainBody;
                     break;
                 case SYNC_BODYPREFERENCE_HTML:
                     if ($htmlBody == "") {
                         $output->asbody->data = $plainBody;
                         $bpReturnType = SYNC_BODYPREFERENCE_PLAIN;
                     } else {
                         $output->asbody->data = $htmlBody;
                     }
                     break;
                 case SYNC_BODYPREFERENCE_MIME:
                     //We don't need to create a new MIME mail, we already have one!!
                     $output->asbody->data = $mail;
                     break;
                 case SYNC_BODYPREFERENCE_RTF:
                     ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->GetMessage RTF Format NOT CHECKED");
                     $output->asbody->data = base64_encode($plainBody);
                     break;
             }
             // truncate body, if requested
             if (strlen($output->asbody->data) > $truncsize) {
                 $output->asbody->data = Utils::Utf8_truncate($output->asbody->data, $truncsize);
                 $output->asbody->truncated = 1;
             }
             $output->asbody->type = $bpReturnType;
             $output->nativebodytype = $bpReturnType;
             $output->asbody->estimatedDataSize = strlen($output->asbody->data);
             $bpo = $contentparameters->BodyPreference($output->asbody->type);
             if (Request::GetProtocolVersion() >= 14.0 && $bpo->GetPreview()) {
                 $output->asbody->preview = Utils::Utf8_truncate(Utils::ConvertHtmlToText($plainBody), $bpo->GetPreview());
             } else {
                 $output->asbody->truncated = 0;
             }
         } else {
             // ASV_2.5
             $output->bodytruncated = 0;
             /* BEGIN fmbiete's contribution r1528, ZP-320 */
             if ($bpReturnType == SYNC_BODYPREFERENCE_MIME) {
                 if (strlen($mail) > $truncsize) {
                     $output->mimedata = Utils::Utf8_truncate($mail, $truncsize);
                     $output->mimetruncated = 1;
                 } else {
                     $output->mimetruncated = 0;
                     $output->mimedata = $mail;
                 }
                 $output->mimesize = strlen($output->mimedata);
             } else {
                 // truncate body, if requested
                 if (strlen($plainBody) > $truncsize) {
                     $output->body = Utils::Utf8_truncate($plainBody, $truncsize);
                     $output->bodytruncated = 1;
                 } else {
                     $output->body = $plainBody;
                     $output->bodytruncated = 0;
                 }
                 $output->bodysize = strlen($output->body);
             }
             /* END fmbiete's contribution r1528, ZP-320 */
         }
         $output->datereceived = isset($message->headers["date"]) ? $this->cleanupDate($message->headers["date"]) : null;
         $output->messageclass = "IPM.Note";
         $output->subject = isset($message->headers["subject"]) ? $message->headers["subject"] : "";
         $output->read = $stat["flags"];
         $output->from = isset($message->headers["from"]) ? $message->headers["from"] : null;
         /* BEGIN fmbiete's contribution r1528, ZP-320 */
         if (isset($message->headers["thread-topic"])) {
             $output->threadtopic = $message->headers["thread-topic"];
         }
         // Language Code Page ID: http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx
         $output->internetcpid = INTERNET_CPID_UTF8;
         if (Request::GetProtocolVersion() >= 12.0) {
             $output->contentclass = "urn:content-classes:message";
         }
         /* END fmbiete's contribution r1528, ZP-320 */
         $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"]);
             //MAIL 1 - most important, 3 - normal, 5 - lowest
             //AS 0 - low, 1 - normal, 2 - important
             if ($mimeImportance > 3) {
                 $output->importance = 0;
             }
             if ($mimeImportance == 3) {
                 $output->importance = 1;
             }
             if ($mimeImportance < 3) {
                 $output->importance = 2;
             }
         } else {
             /* fmbiete's contribution r1528, ZP-320 */
             $output->importance = 1;
         }
         // Attachments are not needed for MIME messages
         if ($bpReturnType != SYNC_BODYPREFERENCE_MIME && isset($message->parts)) {
             $mparts = $message->parts;
             for ($i = 0; $i < count($mparts); $i++) {
                 $part = $mparts[$i];
                 //recursively add parts
                 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;
                 }
                 //add part as attachment if it's disposition indicates so or if it is not a text part
                 if (isset($part->disposition) && ($part->disposition == "attachment" || $part->disposition == "inline") || isset($part->ctype_primary) && $part->ctype_primary != "text") {
                     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";
                             }
                         }
                     }
                     /* BEGIN fmbiete's contribution r1528, ZP-320 */
                     if (Request::GetProtocolVersion() >= 12.0) {
                         if (!isset($output->asattachments) || !is_array($output->asattachments)) {
                             $output->asattachments = array();
                         }
                         $attachment = new SyncBaseAttachment();
                         $attachment->estimatedDataSize = isset($part->d_parameters['size']) ? $part->d_parameters['size'] : isset($part->body) ? strlen($part->body) : 0;
                         $attachment->displayname = $attname;
                         $attachment->filereference = $folderid . ":" . $id . ":" . $i;
                         $attachment->method = 1;
                         //Normal attachment
                         $attachment->contentid = isset($part->headers['content-id']) ? str_replace("<", "", str_replace(">", "", $part->headers['content-id'])) : "";
                         if (isset($part->disposition) && $part->disposition == "inline") {
                             $attachment->isinline = 1;
                         } else {
                             $attachment->isinline = 0;
                         }
                         array_push($output->asattachments, $attachment);
                     } else {
                         //ASV_2.5
                         if (!isset($output->attachments) || !is_array($output->attachments)) {
                             $output->attachments = array();
                         }
                         $attachment = new SyncAttachment();
                         $attachment->attsize = isset($part->d_parameters['size']) ? $part->d_parameters['size'] : isset($part->body) ? strlen($part->body) : 0;
                         $attachment->displayname = $attname;
                         $attachment->attname = $folderid . ":" . $id . ":" . $i;
                         $attachment->attmethod = 1;
                         $attachment->attoid = isset($part->headers['content-id']) ? str_replace("<", "", str_replace(">", "", $part->headers['content-id'])) : "";
                         array_push($output->attachments, $attachment);
                     }
                     /* END fmbiete's contribution r1528, ZP-320 */
                 }
             }
         }
         // unset mimedecoder & mail
         unset($mobj);
         unset($mail);
         return $output;
     }
     return false;
 }
Example #17
0
 /**
  * Returns the message body for a required format.
  *
  * @param MAPIMessage       $mapimessage
  * @param int               $bpReturnType
  * @param SyncObject        $message
  *
  * @access private
  * @return boolean
  */
 private function setMessageBodyForType($mapimessage, $bpReturnType, &$message)
 {
     //default value is PR_BODY
     $property = PR_BODY;
     switch ($bpReturnType) {
         case SYNC_BODYPREFERENCE_HTML:
             $property = PR_HTML;
             break;
         case SYNC_BODYPREFERENCE_RTF:
             $property = PR_RTF_COMPRESSED;
             break;
         case SYNC_BODYPREFERENCE_MIME:
             $stat = $this->imtoinet($mapimessage, $message);
             if (isset($message->asbody)) {
                 $message->asbody->type = $bpReturnType;
             }
             return $stat;
     }
     $stream = mapi_openproperty($mapimessage, $property, IID_IStream, 0, 0);
     if ($stream) {
         $stat = mapi_stream_stat($stream);
         $streamsize = $stat['cb'];
     } else {
         $streamsize = 0;
     }
     //set the properties according to supported AS version
     if (Request::GetProtocolVersion() >= 12.0) {
         $message->asbody = new SyncBaseBody();
         $message->asbody->type = $bpReturnType;
         if ($bpReturnType == SYNC_BODYPREFERENCE_RTF) {
             $body = $this->mapiReadStream($stream, $streamsize);
             $message->asbody->data = StringStreamWrapper::Open(base64_encode($body));
         } elseif (isset($message->internetcpid) && $bpReturnType == SYNC_BODYPREFERENCE_HTML) {
             // if PR_HTML is UTF-8 we can stream it directly, else we have to convert to UTF-8 & wrap it
             if (Utils::GetCodepageCharset($message->internetcpid) == "utf-8") {
                 $message->asbody->data = MAPIStreamWrapper::Open($stream);
             } else {
                 $body = $this->mapiReadStream($stream, $streamsize);
                 $message->asbody->data = StringStreamWrapper::Open(Utils::ConvertCodepageStringToUtf8($message->internetcpid, $body));
             }
         } else {
             $message->asbody->data = MAPIStreamWrapper::Open($stream);
         }
         $message->asbody->estimatedDataSize = $streamsize;
     } else {
         $body = $this->mapiReadStream($stream, $streamsize);
         $message->body = str_replace("\n", "\r\n", w2u(str_replace("\r", "", $body)));
         $message->bodysize = $streamsize;
         $message->bodytruncated = 0;
     }
     return true;
 }
Example #18
0
function buildEMLAttachment($attach)
{
    $msgembedded = mapi_attach_openobj($attach);
    $msgprops = mapi_getprops($msgembedded, array(PR_MESSAGE_CLASS, PR_CLIENT_SUBMIT_TIME, PR_DISPLAY_TO, PR_SUBJECT, PR_SENT_REPRESENTING_NAME, PR_SENT_REPRESENTING_EMAIL_ADDRESS));
    $msgembeddedrcpttable = mapi_message_getrecipienttable($msgembedded);
    $msgto = $msgprops[PR_DISPLAY_TO];
    if ($msgembeddedrcpttable) {
        $msgembeddedrecipients = mapi_table_queryrows($msgembeddedrcpttable, array(PR_ADDRTYPE, PR_ENTRYID, PR_DISPLAY_NAME, PR_EMAIL_ADDRESS, PR_SMTP_ADDRESS, PR_RECIPIENT_TYPE, PR_RECIPIENT_FLAGS, PR_PROPOSEDNEWTIME, PR_PROPOSENEWTIME_START, PR_PROPOSENEWTIME_END, PR_RECIPIENT_TRACKSTATUS), 0, 99999999);
        foreach ($msgembeddedrecipients as $rcpt) {
            if ($rcpt[PR_DISPLAY_NAME] == $msgprops[PR_DISPLAY_TO]) {
                $msgto = $rcpt[PR_DISPLAY_NAME];
                if (isset($rcpt[PR_EMAIL_ADDRESS]) && $rcpt[PR_EMAIL_ADDRESS] != $msgprops[PR_DISPLAY_TO]) {
                    $msgto .= " <" . $rcpt[PR_EMAIL_ADDRESS] . ">";
                }
                break;
            }
        }
    }
    $msgsubject = $msgprops[PR_SUBJECT];
    $msgfrom = $msgprops[PR_SENT_REPRESENTING_NAME];
    if (isset($msgprops[PR_SENT_REPRESENTING_EMAIL_ADDRESS]) && $msgprops[PR_SENT_REPRESENTING_EMAIL_ADDRESS] != $msgprops[PR_SENT_REPRESENTING_NAME]) {
        $msgfrom .= " <" . $msgprops[PR_SENT_REPRESENTING_EMAIL_ADDRESS] . ">";
    }
    $msgtime = $msgprops[PR_CLIENT_SUBMIT_TIME];
    $msgembeddedbody = eml_ReadMessage($msgembedded);
    $msgembeddedattachtable = mapi_message_getattachmenttable($msgembedded);
    $msgembeddedattachtablerows = mapi_table_queryallrows($msgembeddedattachtable, array(PR_ATTACH_NUM, PR_ATTACH_METHOD));
    if ($msgembeddedattachtablerows) {
        $boundary = '=_zpush_static';
        $headercontenttype = "multipart/mixed";
        $msgembeddedbody['body'] = "Unfortunately your mobile is not able to handle MIME Messages\n" . "--" . $boundary . "\n" . "Content-Type: " . $msgembeddedbody['content'] . "; charset=utf-8\n" . "Content-Transfer-Encoding: quoted-printable\n\n" . $msgembeddedbody['body'] . "\n";
        foreach ($msgembeddedattachtablerows as $msgembeddedattachtablerow) {
            $msgembeddedattach = mapi_message_openattach($msgembedded, $msgembeddedattachtablerow[PR_ATTACH_NUM]);
            if (!$msgembeddedattach) {
                debugLog("Unable to open attachment number {$attachnum}");
            } else {
                $msgembeddedattachprops = mapi_getprops($msgembeddedattach, array(PR_ATTACH_MIME_TAG, PR_ATTACH_LONG_FILENAME, PR_ATTACH_FILENAME, PR_DISPLAY_NAME));
                if (isset($msgembeddedattachprops[PR_ATTACH_LONG_FILENAME])) {
                    $attachfilename = w2u($msgembeddedattachprops[PR_ATTACH_LONG_FILENAME]);
                } else {
                    if (isset($msgembeddedattachprops[PR_ATTACH_FILENAME])) {
                        $attachfilename = w2u($msgembeddedattachprops[PR_ATTACH_FILENAME]);
                    } else {
                        if (isset($msgembeddedattachprops[PR_DISPLAY_NAME])) {
                            $attachfilename = w2u($msgembeddedattachprops[PR_DISPLAY_NAME]);
                        } else {
                            $attachfilename = w2u("untitled");
                        }
                    }
                }
                if ($msgembeddedattachtablerow[PR_ATTACH_METHOD] == ATTACH_EMBEDDED_MSG) {
                    $attachfilename .= w2u(".eml");
                }
                $msgembeddedbody['body'] .= "--" . $boundary . "\n" . "Content-Type: " . $msgembeddedattachprops[PR_ATTACH_MIME_TAG] . ";\n" . " name=\"" . $attachfilename . "\"\n" . "Content-Transfer-Encoding: base64\n" . "Content-Disposition: attachment;\n" . " filename=\"" . $attachfilename . "\"\n\n";
                $msgembeddedattachstream = mapi_openpropertytostream($msgembeddedattach, PR_ATTACH_DATA_BIN);
                $msgembeddedattachment = "";
                while (1) {
                    $msgembeddedattachdata = mapi_stream_read($msgembeddedattachstream, 4096);
                    if (byte_strlen($msgembeddedattachdata) == 0) {
                        break;
                    }
                    $msgembeddedattachment .= $msgembeddedattachdata;
                }
                $msgembeddedbody['body'] .= chunk_split(base64_encode($msgembeddedattachment)) . "\n";
                unset($msgembeddedattachment);
            }
        }
        $msgembeddedbody['body'] .= "--" . $boundary . "--\n";
    } else {
        $headercontenttype = $msgembeddedbody['content'] . "; charset=utf-8";
        $boundary = '';
    }
    $msgembeddedheader = "Subject: " . $msgsubject . "\n" . "From: " . $msgfrom . "\n" . "To: " . $msgto . "\n" . "Date: " . gmstrftime("%a, %d %b %Y %T +0000", $msgprops[PR_CLIENT_SUBMIT_TIME]) . "\n" . "MIME-Version: 1.0\n" . "Content-Type: " . $headercontenttype . ";\n" . ($boundary ? " boundary=\"" . $boundary . "\"\n" : "") . "\n";
    $stream = mapi_stream_create();
    mapi_stream_setsize($stream, byte_strlen($msgembeddedheader . $msgembeddedbody['body']));
    mapi_stream_write($stream, $msgembeddedheader . $msgembeddedbody['body']);
    mapi_stream_seek($stream, 0, STREAM_SEEK_SET);
    return $stream;
}
Example #19
0
 /**
  * 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, $contentparameters)
 {
     $truncsize = Utils::GetTruncSize($contentparameters->GetTruncation());
     $mimesupport = $contentparameters->GetMimeSupport();
     ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessage('%s','%s')", $folderid, $id));
     $folderImapid = $this->getImapIdFromFolderId($folderid);
     // Get flags, etc
     $stat = $this->StatMessage($folderid, $id);
     if ($stat) {
         $this->imap_reopenFolder($folderImapid);
         $mail = @imap_fetchheader($this->mbox, $id, FT_UID) . @imap_body($this->mbox, $id, FT_PEEK | FT_UID);
         $mobj = new Mail_mimeDecode($mail);
         $message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'charset' => 'utf-8'));
         $output = new SyncMail();
         $body = $this->getBody($message);
         $output->bodysize = strlen($body);
         // truncate body, if requested
         if (strlen($body) > $truncsize) {
             $body = Utils::Utf8_truncate($body, $truncsize);
             $output->bodytruncated = 1;
         } else {
             $body = $body;
             $output->bodytruncated = 0;
         }
         $body = str_replace("\n", "\r\n", str_replace("\r", "", $body));
         $output->body = $body;
         $output->datereceived = isset($message->headers["date"]) ? $this->cleanupDate($message->headers["date"]) : null;
         $output->messageclass = "IPM.Note";
         $output->subject = isset($message->headers["subject"]) ? $message->headers["subject"] : "";
         $output->read = $stat["flags"];
         $output->from = isset($message->headers["from"]) ? $message->headers["from"] : null;
         $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
         if (isset($message->parts)) {
             $mparts = $message->parts;
             for ($i = 0; $i < count($mparts); $i++) {
                 $part = $mparts[$i];
                 //recursively add parts
                 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;
                 }
                 //add part as attachment if it's disposition indicates so or if it is not a text part
                 if (isset($part->disposition) && ($part->disposition == "attachment" || $part->disposition == "inline") || isset($part->ctype_primary) && $part->ctype_primary != "text") {
                     if (!isset($output->attachments) || !is_array($output->attachments)) {
                         $output->attachments = array();
                     }
                     $attachment = new SyncAttachment();
                     if (isset($part->body)) {
                         $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 = $folderid . ":" . $id . ":" . $i;
                     $attachment->attmethod = 1;
                     $attachment->attoid = isset($part->headers['content-id']) ? $part->headers['content-id'] : "";
                     array_push($output->attachments, $attachment);
                 }
             }
         }
         // unset mimedecoder & mail
         unset($mobj);
         unset($mail);
         return $output;
     }
     return false;
 }
Example #20
0
 /**
  * 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));
     $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;
     } 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);
 }
Example #21
0
 function readCertsfromContact($emailaddress)
 {
     $email1address = GetPropIDFromString($this->_defaultstore, "PT_STRING8:{00062004-0000-0000-C000-000000000046}:0x8083");
     $email2address = GetPropIDFromString($this->_defaultstore, "PT_STRING8:{00062004-0000-0000-C000-000000000046}:0x8093");
     $email3address = GetPropIDFromString($this->_defaultstore, "PT_STRING8:{00062004-0000-0000-C000-000000000046}:0x80A3");
     $x509certs = mapi_prop_tag(PT_MV_BINARY, 0x3a70);
     $rows = $this->readResolveRecipientsfromContacts($emailaddress);
     foreach ($rows as $entry) {
         $res['displayname'] = w2u($entry[PR_DISPLAY_NAME]);
         $res['type'] = 2;
         if (isset($entry[$email1address]) && $entry[$email1address] == $emailaddress) {
             $res['emailaddress'] = $entry[$email1address];
         } else {
             if (isset($entry[$email2address]) && $entry[$email2address] == $emailaddress) {
                 $res['emailaddress'] = $entry[$email2address];
             } else {
                 if (isset($entry[$email3address]) && $entry[$email3address] == $emailaddress) {
                     $res['emailaddress'] = $entry[$email3address];
                 }
             }
         }
         $entries = array();
         if (isset($entry[$x509certs]) && USERX509CERTIFICATES == true) {
             $certs = new Userx509Certificates(isset($entry[$x509certs]) ? $entry[$x509certs] : array());
             if ($der_certs = $certs->findCertificatebySubjectValue('emailAddress', $emailaddress)) {
                 foreach ($der_certs as $der_cert) {
                     $entries[] = base64_encode($der_cert);
                 }
             }
         }
         $res['entries'] = $entries;
         if (count($res['entries']) > 0) {
             $result[$emailaddress][] = $res;
         }
     }
     return $result;
 }
 /**
  * Returns the message body for a required format
  *
  * @param MAPIMessage       $mapimessage
  * @param int               $bpReturnType
  * @param SyncObject        $message
  *
  * @access private
  * @return boolean
  */
 private function setMessageBodyForType($mapimessage, $bpReturnType, &$message)
 {
     //default value is PR_BODY
     $property = PR_BODY;
     switch ($bpReturnType) {
         case SYNC_BODYPREFERENCE_HTML:
             $property = PR_HTML;
             break;
         case SYNC_BODYPREFERENCE_RTF:
             $property = PR_RTF_COMPRESSED;
             break;
         case SYNC_BODYPREFERENCE_MIME:
             $stat = $this->imtoinet($mapimessage, $message);
             if (isset($message->asbody)) {
                 $message->asbody->type = $bpReturnType;
             }
             return $stat;
     }
     $body = mapi_message_openproperty($mapimessage, $property);
     //set the properties according to supported AS version
     if (Request::GetProtocolVersion() >= 12.0) {
         $message->asbody = new SyncBaseBody();
         $message->asbody->type = $bpReturnType;
         if ($bpReturnType == SYNC_BODYPREFERENCE_RTF) {
             $message->asbody->data = base64_encode($body);
         } elseif (isset($message->internetcpid) && $bpReturnType == SYNC_BODYPREFERENCE_HTML) {
             $message->asbody->data = Utils::ConvertCodepageStringToUtf8($message->internetcpid, $body);
         } else {
             $message->asbody->data = w2u($body);
         }
         $message->asbody->estimatedDataSize = strlen($message->asbody->data);
     } else {
         $message->body = str_replace("\n", "\r\n", w2u(str_replace("\r", "", $body)));
         $message->bodysize = strlen($message->body);
         $message->bodytruncated = 0;
     }
     return true;
 }
Example #23
0
 function _getFolder($mapifolder)
 {
     $folder = new SyncFolder();
     $folderprops = mapi_getprops($mapifolder, array(PR_DISPLAY_NAME, PR_PARENT_ENTRYID, PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY, PR_ENTRYID, PR_CONTAINER_CLASS));
     $storeprops = mapi_getprops($this->_store, array(PR_IPM_SUBTREE_ENTRYID));
     if (!isset($folderprops[PR_DISPLAY_NAME]) || !isset($folderprops[PR_PARENT_ENTRYID]) || !isset($folderprops[PR_SOURCE_KEY]) || !isset($folderprops[PR_ENTRYID]) || !isset($folderprops[PR_PARENT_SOURCE_KEY]) || !isset($storeprops[PR_IPM_SUBTREE_ENTRYID])) {
         debugLog("Missing properties on folder");
         return false;
     }
     $folder->serverid = bin2hex($folderprops[PR_SOURCE_KEY]);
     if ($folderprops[PR_PARENT_ENTRYID] == $storeprops[PR_IPM_SUBTREE_ENTRYID]) {
         $folder->parentid = "0";
     } else {
         $folder->parentid = bin2hex($folderprops[PR_PARENT_SOURCE_KEY]);
     }
     $folder->displayname = w2u($folderprops[PR_DISPLAY_NAME]);
     $folder->type = $this->_getFolderType($folderprops[PR_ENTRYID]);
     // try to find a correct type if not one of the default folders
     if ($folder->type == SYNC_FOLDER_TYPE_OTHER && isset($folderprops[PR_CONTAINER_CLASS])) {
         if ($folderprops[PR_CONTAINER_CLASS] == "IPF.Note") {
             $folder->type = SYNC_FOLDER_TYPE_USER_MAIL;
         }
         if ($folderprops[PR_CONTAINER_CLASS] == "IPF.Task") {
             $folder->type = SYNC_FOLDER_TYPE_USER_TASK;
         }
         if ($folderprops[PR_CONTAINER_CLASS] == "IPF.Appointment") {
             $folder->type = SYNC_FOLDER_TYPE_USER_APPOINTMENT;
         }
         if ($folderprops[PR_CONTAINER_CLASS] == "IPF.Contact") {
             $folder->type = SYNC_FOLDER_TYPE_USER_CONTACT;
         }
         if ($folderprops[PR_CONTAINER_CLASS] == "IPF.StickyNote") {
             $folder->type = SYNC_FOLDER_TYPE_USER_NOTE;
         }
         if ($folderprops[PR_CONTAINER_CLASS] == "IPF.Journal") {
             $folder->type = SYNC_FOLDER_TYPE_USER_JOURNAL;
         }
     }
     return $folder;
 }