ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
CAS_ProxiedService_Imap Class Reference

Provides access to a proxy-authenticated IMAP stream. More...

+ Inheritance diagram for CAS_ProxiedService_Imap:
+ Collaboration diagram for CAS_ProxiedService_Imap:

Public Member Functions

 __construct ($username)
 Constructor. More...
 
 getServiceUrl ()
 Answer a service identifier (URL) for whom we should fetch a proxy ticket. More...
 
 setServiceUrl ($url)
 Set the URL of the service to pass to CAS for proxy-ticket retrieval. More...
 
 setMailbox ($mailbox)
 Set the mailbox to open. More...
 
 setOptions ($options)
 Set the options for opening the stream. More...
 
 open ()
 Open the IMAP stream (similar to imap_open()). More...
 
 getStream ()
 Answer the IMAP stream. More...
 
 getImapProxyTicket ()
 CAS_Client::serviceMail() needs to return the proxy ticket for some reason, so this method provides access to it. More...
 
- Public Member Functions inherited from CAS_ProxiedService_Abstract
 setProxyTicket ($proxyTicket)
 Register a proxy ticket with the Proxy that it can use when making requests. More...
 
 setCasClient (CAS_Client $casClient)
 Use a particular CAS_Client->initializeProxiedService() rather than the static phpCAS::initializeProxiedService(). More...
 
 getServiceUrl ()
 Answer a service identifier (URL) for whom we should fetch a proxy ticket. More...
 
 setProxyTicket ($proxyTicket)
 Register a proxy ticket with the ProxiedService that it can use when making requests. More...
 
 setCasClient (CAS_Client $casClient)
 Use a particular CAS_Client->initializeProxiedService() rather than the static phpCAS::initializeProxiedService(). More...
 

Protected Member Functions

 hasBeenOpened ()
 Answer true if our request has been sent yet. More...
 
- Protected Member Functions inherited from CAS_ProxiedService_Abstract
 getProxyTicket ()
 Answer the proxy ticket to be used when making requests. More...
 
 initializeProxyTicket ()
 Fetch our proxy ticket. More...
 

Private Attributes

 $_username
 The username to send via imap_open. More...
 
 $_url
 The target service url. More...
 
 $_mailbox
 The mailbox to open. More...
 
 $_options = null
 A bit mask of options to pass to imap_open() as the $options parameter. More...
 
 $_stream
 The IMAP stream. More...
 

Detailed Description

Provides access to a proxy-authenticated IMAP stream.

Definition at line 40 of file Imap.php.

Constructor & Destructor Documentation

◆ __construct()

CAS_ProxiedService_Imap::__construct (   $username)

Constructor.

Parameters
string$usernameUsername
Returns
void

Definition at line 57 of file Imap.php.

58 {
59 if (!is_string($username) || !strlen($username)) {
60 throw new CAS_InvalidArgumentException('Invalid username.');
61 }
62
63 $this->_username = $username;
64 }
Exception that denotes invalid arguments were passed.

Member Function Documentation

◆ getImapProxyTicket()

CAS_ProxiedService_Imap::getImapProxyTicket ( )

CAS_Client::serviceMail() needs to return the proxy ticket for some reason, so this method provides access to it.

Returns
string
Exceptions
CAS_OutOfSequenceExceptionIf called before the stream has been opened.

Definition at line 271 of file Imap.php.

272 {
273 if (!$this->hasBeenOpened()) {
275 'Cannot access errors, stream not opened yet.'
276 );
277 }
278 return $this->getProxyTicket();
279 }
This class defines Exceptions that should be thrown when the sequence of operations is invalid.
getProxyTicket()
Answer the proxy ticket to be used when making requests.
Definition: Abstract.php:82
hasBeenOpened()
Answer true if our request has been sent yet.
Definition: Imap.php:233

◆ getServiceUrl()

CAS_ProxiedService_Imap::getServiceUrl ( )

Answer a service identifier (URL) for whom we should fetch a proxy ticket.

Returns
string
Exceptions
ExceptionIf no service url is available.

Reimplemented from CAS_ProxiedService.

Definition at line 78 of file Imap.php.

79 {
80 if (empty($this->_url)) {
82 'No URL set via ' . get_class($this) . '->getServiceUrl($url).'
83 );
84 }
85
86 return $this->_url;
87 }
An Exception for problems communicating with a proxied service.
Definition: Exception.php:41
$_url
The target service url.
Definition: Imap.php:70

References $_url.

◆ getStream()

CAS_ProxiedService_Imap::getStream ( )

Answer the IMAP stream.

Returns
resource

Definition at line 253 of file Imap.php.

254 {
255 if (!$this->hasBeenOpened()) {
257 'Cannot access stream, not opened yet.'
258 );
259 }
260 return $this->_stream;
261 }
$_stream
The IMAP stream.
Definition: Imap.php:246

◆ hasBeenOpened()

CAS_ProxiedService_Imap::hasBeenOpened ( )
protected

Answer true if our request has been sent yet.

Returns
bool

Definition at line 233 of file Imap.php.

234 {
235 return !empty($this->_stream);
236 }

Referenced by open(), setMailbox(), setOptions(), and setServiceUrl().

+ Here is the caller graph for this function:

◆ open()

CAS_ProxiedService_Imap::open ( )

Open the IMAP stream (similar to imap_open()).

Returns
resource Returns an IMAP stream on success
Exceptions
CAS_OutOfSequenceExceptionIf called multiple times.
CAS_ProxyTicketExceptionIf there is a proxy-ticket failure. The code of the Exception will be one of: PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE PHPCAS_SERVICE_PT_FAILURE
CAS_ProxiedService_ExceptionIf there is a failure sending the request to the target service.

Definition at line 191 of file Imap.php.

192 {
193 if ($this->hasBeenOpened()) {
194 throw new CAS_OutOfSequenceException('Stream already opened.');
195 }
196 if (empty($this->_mailbox)) {
198 'You must specify a mailbox via ' . get_class($this)
199 . '->setMailbox($mailbox)'
200 );
201 }
202
204
205 // Get our proxy ticket and append it to our URL.
206 $this->initializeProxyTicket();
207 phpCAS::trace('opening IMAP mailbox `' . $this->_mailbox . '\'...');
208 $this->_stream = @imap_open(
209 $this->_mailbox,
210 $this->_username,
211 $this->getProxyTicket(),
212 $this->_options
213 );
214 if ($this->_stream) {
215 phpCAS::trace('ok');
216 } else {
217 phpCAS::trace('could not open mailbox');
218 // @todo add localization integration.
219 $message = 'IMAP Error: ' . $this->_url . ' ' . var_export(imap_errors(), true);
220 phpCAS::trace($message);
221 throw new CAS_ProxiedService_Exception($message);
222 }
223
224 phpCAS::traceEnd();
225 return $this->_stream;
226 }
initializeProxyTicket()
Fetch our proxy ticket.
Definition: Abstract.php:132
open()
Open the IMAP stream (similar to imap_open()).
Definition: Imap.php:191
static trace($str)
This method is used to log something in debug mode.
Definition: CAS.php:599
static traceBegin()
This method is used to indicate the start of the execution of a function in debug mode.
Definition: CAS.php:611

References hasBeenOpened(), CAS_ProxiedService_Abstract\initializeProxyTicket(), open(), phpCAS\trace(), and phpCAS\traceBegin().

Referenced by open().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setMailbox()

CAS_ProxiedService_Imap::setMailbox (   $mailbox)

Set the mailbox to open.

See the $mailbox parameter of imap_open().

Parameters
string$mailboxMailbox to set
Returns
void
Exceptions
CAS_OutOfSequenceExceptionIf called after the stream has been opened.

Definition at line 130 of file Imap.php.

131 {
132 if ($this->hasBeenOpened()) {
134 'Cannot set the mailbox, stream already opened.'
135 );
136 }
137 if (!is_string($mailbox) || !strlen($mailbox)) {
138 throw new CAS_InvalidArgumentException('Invalid mailbox.');
139 }
140
141 $this->_mailbox = $mailbox;
142 }

References hasBeenOpened().

+ Here is the call graph for this function:

◆ setOptions()

CAS_ProxiedService_Imap::setOptions (   $options)

Set the options for opening the stream.

See the $options parameter of imap_open().

Parameters
int$optionsOptions for the stream
Returns
void
Exceptions
CAS_OutOfSequenceExceptionIf called after the stream has been opened.

Definition at line 160 of file Imap.php.

161 {
162 if ($this->hasBeenOpened()) {
164 'Cannot set options, stream already opened.'
165 );
166 }
167 if (!is_int($options)) {
168 throw new CAS_InvalidArgumentException('Invalid options.');
169 }
170
171 $this->_options = $options;
172 }

References hasBeenOpened().

+ Here is the call graph for this function:

◆ setServiceUrl()

CAS_ProxiedService_Imap::setServiceUrl (   $url)

Set the URL of the service to pass to CAS for proxy-ticket retrieval.

Parameters
string$urlUrl to set
Returns
void
Exceptions
CAS_OutOfSequenceExceptionIf called after the stream has been opened.

Definition at line 101 of file Imap.php.

102 {
103 if ($this->hasBeenOpened()) {
105 'Cannot set the URL, stream already opened.'
106 );
107 }
108 if (!is_string($url) || !strlen($url)) {
109 throw new CAS_InvalidArgumentException('Invalid url.');
110 }
111
112 $this->_url = $url;
113 }
$url

References $url, and hasBeenOpened().

+ Here is the call graph for this function:

Field Documentation

◆ $_mailbox

string CAS_ProxiedService_Imap::$_mailbox
private

The mailbox to open.

See the $mailbox parameter of imap_open().

Definition at line 120 of file Imap.php.

◆ $_options

int CAS_ProxiedService_Imap::$_options = null
private

A bit mask of options to pass to imap_open() as the $options parameter.

Definition at line 149 of file Imap.php.

◆ $_stream

resource CAS_ProxiedService_Imap::$_stream
private

The IMAP stream.

Definition at line 246 of file Imap.php.

◆ $_url

string CAS_ProxiedService_Imap::$_url
private

The target service url.

Definition at line 70 of file Imap.php.

Referenced by getServiceUrl().

◆ $_username

string CAS_ProxiedService_Imap::$_username
private

The username to send via imap_open.

Definition at line 48 of file Imap.php.


The documentation for this class was generated from the following file: