ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 58 of file Imap.php.

59 {
60 if (!is_string($username) || !strlen($username)) {
61 throw new CAS_InvalidArgumentException('Invalid username.');
62 }
63
64 $this->_username = $username;
65 }
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 270 of file Imap.php.

271 {
272 if (!$this->hasBeenOpened()) {
274 'Cannot access errors, stream not opened yet.'
275 );
276 }
277 return $this->getProxyTicket();
278 }
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:83
hasBeenOpened()
Answer true if our request has been sent yet.
Definition: Imap.php:232

◆ 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 79 of file Imap.php.

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

References $_url.

◆ getStream()

CAS_ProxiedService_Imap::getStream ( )

Answer the IMAP stream.

Returns
resource

Definition at line 252 of file Imap.php.

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

◆ hasBeenOpened()

CAS_ProxiedService_Imap::hasBeenOpened ( )
protected

Answer true if our request has been sent yet.

Returns
bool

Definition at line 232 of file Imap.php.

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

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 192 of file Imap.php.

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

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 131 of file Imap.php.

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

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 161 of file Imap.php.

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

References $options, and 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 102 of file Imap.php.

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

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 121 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 150 of file Imap.php.

◆ $_stream

resource CAS_ProxiedService_Imap::$_stream
private

The IMAP stream.

Definition at line 245 of file Imap.php.

◆ $_url

string CAS_ProxiedService_Imap::$_url
private

The target service url.

Definition at line 71 of file Imap.php.

Referenced by getServiceUrl().

◆ $_username

string CAS_ProxiedService_Imap::$_username
private

The username to send via imap_open.

Definition at line 49 of file Imap.php.


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