예제 #1
0
파일: Resource.php 프로젝트: Gomez/horde
 function _imapConnect($id)
 {
     global $conf;
     // Handle virtual domains
     list($user, $domain) = explode('@', $id);
     if (empty($domain)) {
         $domain = $conf['kolab']['filter']['email_domain'];
     }
     $calendar_user = $conf['kolab']['filter']['calendar_id'] . '@' . $domain;
     /* Load the authentication libraries */
     $auth = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Auth')->create(isset($conf['auth']['driver']) ? null : 'kolab');
     $authenticated = $auth->authenticate($calendar_user, array('password' => $conf['kolab']['filter']['calendar_pass']), false);
     if (is_a($authenticated, 'PEAR_Error')) {
         $authenticated->code = OUT_LOG | EX_UNAVAILABLE;
         return $authenticated;
     }
     if (!$authenticated) {
         return PEAR::raiseError(sprintf('Failed to authenticate as calendar user: %s', $auth->getLogoutReasonString()), OUT_LOG | EX_UNAVAILABLE);
     }
     @session_start();
     $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
     $_SESSION['__auth'] = array('authenticated' => true, 'userId' => $calendar_user, 'timestamp' => time(), 'credentials' => $secret->write($secret->getKey(), serialize(array('password' => $conf['kolab']['filter']['calendar_pass']))), 'remote_addr' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null);
     /* Kolab IMAP handling */
     require_once 'Horde/Kolab/Storage/List.php';
     $list =& Kolab_List::singleton();
     $default = $list->getForeignDefault($id, 'event');
     if (!$default || is_a($default, 'PEAR_Error')) {
         $default = new Kolab_Folder();
         $default->setList($list);
         $default->setName($conf['kolab']['filter']['calendar_store']);
         //FIXME: The calendar user needs access here
         $attributes = array('default' => true, 'type' => 'event', 'owner' => $id);
         $result = $default->save($attributes);
         if (is_a($result, 'PEAR_Error')) {
             $result->code = OUT_LOG | EX_UNAVAILABLE;
             return $result;
         }
     }
     return $default;
 }