Changeset View
Changeset View
Standalone View
Standalone View
lib/Kolab/FreeBusy/SourceIMAP.php
Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | public function getFreeBusyData($user, $extended) | ||||
$config = $this->getUserConfig($user); | $config = $this->getUserConfig($user); | ||||
parse_str(strval($config['query']), $param); | parse_str(strval($config['query']), $param); | ||||
$config += $param; | $config += $param; | ||||
// log this... | // log this... | ||||
$log->addInfo("Fetching data for ", $config); | $log->addInfo("Fetching data for ", $config); | ||||
// caching is enabled | |||||
if (!empty($config['cacheto'])) { | |||||
// check for cached data | |||||
if ($cached = $this->getCached($config)) { | |||||
$log->addInfo("Deliver cached data from " . $config['cacheto']); | |||||
return $cached; | |||||
} | |||||
// touch cache file to avoid multiple requests generating the same data | |||||
if (file_exists($config['cacheto'])) { | |||||
touch($config['cacheto']); | |||||
} | |||||
else { | |||||
file_put_contents($config['cacheto'], Utils::dummyVFreebusy($user['mail'])); | |||||
$tempfile = $config['cacheto']; | |||||
} | |||||
} | |||||
// compose a list of user email addresses | // compose a list of user email addresses | ||||
$user_email = array(); | $user_email = array(); | ||||
foreach (Config::convert($this->config['mail_attributes'], Config::ARR) as $key) { | foreach (Config::convert($this->config['mail_attributes'], Config::ARR) as $key) { | ||||
if (!empty($user[$key])) { | if (!empty($user[$key])) { | ||||
$user_email = array_merge($user_email, (array)$user[$key]); | $user_email = array_merge($user_email, (array)$user[$key]); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | if ($imap = $this->imap_login($config)) { | ||||
$freebusy->PRODID = Utils::PRODID; | $freebusy->PRODID = Utils::PRODID; | ||||
$freebusy->METHOD = 'PUBLISH'; | $freebusy->METHOD = 'PUBLISH'; | ||||
$freebusy->VFREEBUSY->UID = date('YmdHi') . '-' . substr(md5($user_email[0]), 0, 16); | $freebusy->VFREEBUSY->UID = date('YmdHi') . '-' . substr(md5($user_email[0]), 0, 16); | ||||
$freebusy->VFREEBUSY->ORGANIZER = 'mailto:' . $user_email[0]; | $freebusy->VFREEBUSY->ORGANIZER = 'mailto:' . $user_email[0]; | ||||
// serialize to VCALENDAR format | // serialize to VCALENDAR format | ||||
return $freebusy->serialize(); | return $freebusy->serialize(); | ||||
} | } | ||||
// remove (temporary) cache file again | |||||
else if ($tempfile) { | |||||
unlink($tempfile); | |||||
} | |||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* Helper method to establish connection to the configured IMAP backend | * Helper method to establish connection to the configured IMAP backend | ||||
*/ | */ | ||||
private function imap_login($config) | private function imap_login($config) | ||||
▲ Show 20 Lines • Show All 106 Lines • Show Last 20 Lines |