function u2wi($string) { return utf8_to_windows1252($string, "//TRANSLIT"); }
function GetMessage($folderid, $id, $truncsize) { debugLog("IMAP-GetMessage: (fid: '{$folderid}' id: '{$id}' truncsize: {$truncsize})"); // Get flags, etc $stat = $this->StatMessage($folderid, $id); if ($stat) { $this->imap_reopenFolder($folderid); $mail = @imap_fetchheader($this->_mbox, $id, FT_PREFETCHTEXT | 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, 'input' => $mail, 'crlf' => "\n", 'charset' => 'utf-8')); $output = new SyncMail(); // decode body to truncate it $body = utf8_to_windows1252($this->getBody($message)); if (strlen($body) > $truncsize) { $body = substr($body, 0, $truncsize); $output->bodytruncated = 1; } else { $body = $body; $output->bodytruncated = 0; } $body = str_replace("\n", "\r\n", windows1252_to_utf8(str_replace("\r", "", $body))); $output->bodysize = strlen($body); $output->body = $body; $output->datereceived = isset($message->headers["date"]) ? strtotime($message->headers["date"]) : null; $output->displayto = isset($message->headers["to"]) ? $message->headers["to"] : null; $output->importance = isset($message->headers["x-priority"]) ? preg_replace("/\\D+/", "", $message->headers["x-priority"]) : null; $output->messageclass = "IPM.Note"; $output->subject = isset($message->headers["subject"]) ? $message->headers["subject"] : ""; $output->read = $stat["flags"]; $output->to = isset($message->headers["to"]) ? $message->headers["to"] : null; $output->cc = isset($message->headers["cc"]) ? $message->headers["cc"] : null; $output->from = isset($message->headers["from"]) ? $message->headers["from"] : null; $output->reply_to = isset($message->headers["reply-to"]) ? $message->headers["reply-to"] : null; // Attachments are only searched in the top-level part $n = 0; if (isset($message->parts)) { foreach ($message->parts as $part) { if (isset($part->disposition) && ($part->disposition == "attachment" || $part->disposition == "inline")) { $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 . ":" . $n; $attachment->attmethod = 1; $attachment->attoid = isset($part->headers['content-id']) ? $part->headers['content-id'] : ""; array_push($output->attachments, $attachment); } $n++; } } // unset mimedecoder & mail unset($mobj); unset($mail); return $output; } return false; }
function u2w($string) { return utf8_to_windows1252($string); }
function GetMessage($folderid, $id, $truncsize) { debugLog("KOLAB-GetMessage: (fid: '{$folderid}' id: '{$id}' truncsize: {$truncsize})"); // Get flags, etc $stat = $this->StatMessage($folderid, $id); if ($stat) { if ($this->kolabFolderType($folderid)) { //get the imap_id $imap_id = array_pop(explode("/", $stat['mod'])); //$imap_id=$stat['mod']; if (substr($folderid, 0, 7) == "VIRTUAL") { $folderid = $this->CacheIndexUid2FolderUid($id); debugLog("GetMessage Flmode: {$id} - > {$folderid}"); $this->Log("NOTICE GetMessage Flmode: {$id} - > {$folderid}"); } } else { $imap_id = $id; } $this->imap_reopenFolder($folderid); $mail = @imap_fetchheader($this->_mbox, $imap_id, FT_PREFETCHTEXT | FT_UID) . @imap_body($this->_mbox, $imap_id, FT_PEEK | FT_UID); $mobj = new Mail_mimeDecode($mail); $message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'input' => $mail, 'crlf' => "\n", 'charset' => 'utf-8')); if ($this->kolabFolderType($folderid) == 1) { $output = $this->KolabReadContact($message, 0); $this->Log("Changed on Server C: {$folderid} /" . $id . "imap id : " . $imap_id); $this->Log(" : " . u2w($output->fileas)); $this->CacheCreateIndex($folderid, $id, $imap_id); return $output; } elseif ($this->kolabFolderType($folderid) == 2) { //bug #9 we must test if we want alarms or not // for the moment disable it if namespace <> INBOX $fa = $this->CacheReadFolderParam($folderid); $fa->setFolder($folderid); if ($fa->showAlarm($this->_devid)) { $output = $this->KolabReadEvent($message, $id, false); //alarm must be shown } else { $output = $this->KolabReadEvent($message, $id, true); } $this->Log("Changed on Server A: {$folderid}/" . $id); $this->Log(" : " . u2w($output->subject)); $this->CacheCreateIndex($folderid, $id, $imap_id); $this->CacheWriteSensitivity($id, $output->sensitivity); return $output; } elseif ($this->kolabFolderType($folderid) == 3) { $output = $this->KolabReadTask($message, $id); $this->Log("Changed on Server T: {$folderid} /" . $id); $this->Log(" : " . u2w($output->subject)); $this->CacheCreateIndex($folderid, $id, $imap_id); //rewrite completion $this->CacheWriteTaskCompleted($id, $output->completed); $this->CacheWriteSensitivity($id, $output->sensitivity); return $output; } else { $output = new SyncMail(); // decode body to truncate it $body = utf8_to_windows1252($this->getBody($message)); $truncsize = 2048; if (strlen($body) > $truncsize) { $body = substr($body, 0, $truncsize); $output->bodytruncated = 1; } else { $body = $body; $output->bodytruncated = 0; } $body = str_replace("\n", "\r\n", windows1252_to_utf8(str_replace("\r", "", $body))); $output->bodysize = strlen($body); $output->body = $body; $output->datereceived = isset($message->headers["date"]) ? strtotime($message->headers["date"]) : null; $output->displayto = isset($message->headers["to"]) ? $message->headers["to"] : null; $output->importance = isset($message->headers["x-priority"]) ? preg_replace("/\\D+/", "", $message->headers["x-priority"]) : null; $output->messageclass = "IPM.Note"; $output->subject = isset($message->headers["subject"]) ? $message->headers["subject"] : ""; $output->read = $stat["flags"]; $output->to = isset($message->headers["to"]) ? $message->headers["to"] : null; $output->cc = isset($message->headers["cc"]) ? $message->headers["cc"] : null; $output->from = isset($message->headers["from"]) ? $message->headers["from"] : null; $output->reply_to = isset($message->headers["reply-to"]) ? $message->headers["reply-to"] : null; // Attachments are only searched in the top-level part $n = 0; if (isset($message->parts)) { foreach ($message->parts as $part) { if (isset($part->disposition) && ($part->disposition == "attachment" || $part->disposition == "inline")) { $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 . ":" . $n; $attachment->attmethod = 1; $attachment->attoid = isset($part->headers['content-id']) ? $part->headers['content-id'] : ""; array_push($output->attachments, $attachment); } $n++; } } // unset mimedecoder & mail unset($mobj); unset($mail); return $output; } } return false; }
function setSettings($request, $devid) { if (isset($request["oof"])) { if ($request["oof"]["oofstate"] == 1) { foreach ($request["oof"]["oofmsgs"] as $oofmsg) { switch ($oofmsg["appliesto"]) { case SYNC_SETTINGS_APPLIESTOINTERNAL: $result = mapi_setprops($this->_defaultstore, array(PR_EC_OUTOFOFFICE_MSG => utf8_to_windows1252(isset($oofmsg["replymessage"]) ? $oofmsg["replymessage"] : ""), PR_EC_OUTOFOFFICE_SUBJECT => utf8_to_windows1252(_("Out of office notification")))); break; } } $response["oof"]["status"] = mapi_setprops($this->_defaultstore, array(PR_EC_OUTOFOFFICE => $request["oof"]["oofstate"] == 1 ? true : false)); } else { $response["oof"]["status"] = mapi_setprops($this->_defaultstore, array(PR_EC_OUTOFOFFICE => $request["oof"]["oofstate"] == 1 ? true : false)); } } if (isset($request["deviceinformation"])) { if ($this->_defaultstore !== false) { //get devices settings from store $props = array(); $props[SYNC_SETTINGS_MODEL] = mapi_prop_tag(PT_MV_STRING8, 0x6890); $props[SYNC_SETTINGS_IMEI] = mapi_prop_tag(PT_MV_STRING8, 0x6891); $props[SYNC_SETTINGS_FRIENDLYNAME] = mapi_prop_tag(PT_MV_STRING8, 0x6892); $props[SYNC_SETTINGS_OS] = mapi_prop_tag(PT_MV_STRING8, 0x6893); $props[SYNC_SETTINGS_OSLANGUAGE] = mapi_prop_tag(PT_MV_STRING8, 0x6894); $props[SYNC_SETTINGS_PHONENUMBER] = mapi_prop_tag(PT_MV_STRING8, 0x6895); $props[SYNC_SETTINGS_USERAGENT] = mapi_prop_tag(PT_MV_STRING8, 0x6896); $props[SYNC_SETTINGS_ENABLEOUTBOUNDSMS] = mapi_prop_tag(PT_MV_STRING8, 0x6897); $props[SYNC_SETTINGS_MOBILEOPERATOR] = mapi_prop_tag(PT_MV_STRING8, 0x6898); $sprops = mapi_getprops($this->_defaultstore, array(0x6881101e, $props[SYNC_SETTINGS_MODEL], $props[SYNC_SETTINGS_IMEI], $props[SYNC_SETTINGS_FRIENDLYNAME], $props[SYNC_SETTINGS_OS], $props[SYNC_SETTINGS_OSLANGUAGE], $props[SYNC_SETTINGS_PHONENUMBER], $props[SYNC_SETTINGS_USERAGENT], $props[SYNC_SETTINGS_ENABLEOUTBOUNDSMS], $props[SYNC_SETTINGS_MOBILEOPERATOR])); //try to find index of current device $ak = array_search($devid, $sprops[0x6881101e]); // Set undefined properties to the amount of known device ids foreach ($props as $key => $value) { if (!isset($sprops[$value])) { for ($i = 0; $i < sizeof($sprops[0x6881101e]); $i++) { $sprops[$value][] = "undefined"; } } } if ($ak !== false) { //update settings (huh this could really occur?!?! - maybe in case of OS update) foreach ($request["deviceinformation"] as $key => $value) { if (trim($value) != "") { $sprops[$props[$key]][$ak] = $value; } else { $sprops[$props[$key]][$ak] = "undefined"; } } } else { //new device settings for the db $devicesprops[0x6881101e][] = $devid; foreach ($props as $key => $value) { if (isset($request["deviceinformation"][$key]) && trim($request["deviceinformation"][$key]) != "") { $sprops[$value][] = $request["deviceinformation"][$key]; } else { $sprops[$value][] = "undefined"; } } } // save them $response["deviceinformation"]["status"] = mapi_setprops($this->_defaultstore, $sprops); } } if (isset($request["devicepassword"])) { if ($this->_defaultstore !== false) { //get devices settings from store $props = array(); $props[SYNC_SETTINGS_PASSWORD] = mapi_prop_tag(PT_MV_STRING8, 0x689f); $pprops = mapi_getprops($this->_defaultstore, array(0x6881101e, $props[SYNC_SETTINGS_PASSWORD])); //try to find index of current device $ak = array_search($devid, $pprops[0x6881101e]); // Set undefined properties to the amount of known device ids foreach ($props as $key => $value) { if (!isset($pprops[$value])) { for ($i = 0; $i < sizeof($pprops[0x6881101e]); $i++) { $pprops[$value][] = "undefined"; } } } if ($ak !== false) { //update password if (trim($value) != "") { $pprops[$props[$key]][$ak] = $request["devicepassword"]; } else { $pprops[$props[$key]][$ak] = "undefined"; } } else { //new device password for the db $devicesprops[0x6881101e][] = $devid; foreach ($props as $key => $value) { if (isset($request["devicepassword"]) && trim($request["devicepassword"]) != "") { $pprops[$value][] = $request["devicepassword"]; } else { $pprops[$value][] = "undefined"; } } } // save them $response["devicepassword"]["status"] = mapi_setprops($this->_defaultstore, $pprops); } } return $response; }