ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
IMAP.php
Go to the documentation of this file.
1<?php
2/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
3
29require_once "Auth/Container.php";
30
34require_once "PEAR.php";
35
85{
86
87 // {{{ properties
88
93 var $options = array();
94
95 // }}}
96 // {{{ Auth_Container_IMAP() [constructor]
97
107 {
108 if (!extension_loaded('imap')) {
109 return PEAR::raiseError('Cannot use IMAP authentication, '
110 .'IMAP extension not loaded!', 41, PEAR_ERROR_DIE);
111 }
112 $this->_setDefaults();
113
114 // set parameters (if any)
115 if (is_array($params)) {
116 $this->_parseOptions($params);
117 }
118
119 if ($this->options['checkServer']) {
120 $this->_checkServer($this->options['timeout']);
121 }
122 return true;
123 }
124
125 // }}}
126 // {{{ _setDefaults()
127
133 function _setDefaults()
134 {
135 $this->options['host'] = 'localhost';
136 $this->options['port'] = 143;
137 $this->options['baseDSN'] = '';
138 $this->options['checkServer'] = true;
139 $this->options['timeout'] = 20;
140 }
141
142 // }}}
143 // {{{ _checkServer()
144
150 function _checkServer() {
151 $this->log('Auth_Container_IMAP::_checkServer() called.', AUTH_LOG_DEBUG);
152 $fp = @fsockopen ($this->options['host'], $this->options['port'],
153 $errno, $errstr, $this->options['timeout']);
154 if (is_resource($fp)) {
155 @fclose($fp);
156 } else {
157 $message = "Error connecting to IMAP server "
158 . $this->options['host']
159 . ":" . $this->options['port'];
160 return PEAR::raiseError($message, 41);
161 }
162 }
163
164 // }}}
165 // {{{ _parseOptions()
166
173 function _parseOptions($array)
174 {
175 foreach ($array as $key => $value) {
176 $this->options[$key] = $value;
177 }
178 }
179
180 // }}}
181 // {{{ fetchData()
182
190 function fetchData($username, $password)
191 {
192 $this->log('Auth_Container_IMAP::fetchData() called.', AUTH_LOG_DEBUG);
193 $dsn = '{'.$this->options['host'].':'.$this->options['port'].$this->options['baseDSN'].'}';
194 $conn = @imap_open ($dsn, $username, $password, OP_HALFOPEN);
195 if (is_resource($conn)) {
196 $this->log('Successfully connected to IMAP server.', AUTH_LOG_DEBUG);
197 $this->activeUser = $username;
198 @imap_close($conn);
199 return true;
200 } else {
201 $this->log('Connection to IMAP server failed.', AUTH_LOG_DEBUG);
202 $this->activeUser = '';
203 return false;
204 }
205 }
206
207 // }}}
208
209}
210?>
const AUTH_LOG_DEBUG
Auth Log level - DEBUG.
Definition: Auth.php:59
const PEAR_ERROR_DIE
Definition: PEAR.php:34
fetchData($username, $password)
Try to open a IMAP stream using $username / $password.
Definition: IMAP.php:190
_parseOptions($array)
Parse options passed to the container class.
Definition: IMAP.php:173
_checkServer()
Check if the given server and port are reachable.
Definition: IMAP.php:150
Auth_Container_IMAP($params)
Constructor of the container class.
Definition: IMAP.php:106
_setDefaults()
Set some default options.
Definition: IMAP.php:133
log($message, $level=AUTH_LOG_DEBUG)
Log a message to the Auth log.
Definition: Container.php:246
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object's de...
Definition: PEAR.php:524
$params
Definition: example_049.php:96