CAS_Client::serviceMail PHP Метод

serviceMail() публичный Метод

This method is used to access an IMAP/POP3/NNTP service.
public serviceMail ( string $url, string $serviceUrl, string $flags, &$err_code, &$err_msg, &$pt ) : object
$url string a string giving the URL of the service, including the mailing box for IMAP URLs, as accepted by imap_open().
$serviceUrl string a string giving for CAS retrieve Proxy ticket
$flags string options given to imap_open().
Результат object an IMAP stream on success, false otherwise (in this later case, $err_code gives the reason why it failed and $err_msg contains an error message).
    public function serviceMail($url, $serviceUrl, $flags, &$err_code, &$err_msg, &$pt)
    {
        // Sequence validation
        $this->ensureIsProxy();
        $this->ensureAuthenticationCallSuccessful();
        // Argument validation
        if (gettype($url) != 'string') {
            throw new CAS_TypeMismatchException($url, '$url', 'string');
        }
        if (gettype($serviceUrl) != 'string') {
            throw new CAS_TypeMismatchException($serviceUrl, '$serviceUrl', 'string');
        }
        if (gettype($flags) != 'integer') {
            throw new CAS_TypeMismatchException($flags, '$flags', 'string');
        }
        try {
            $service = $this->getProxiedService(PHPCAS_PROXIED_SERVICE_IMAP);
            $service->setServiceUrl($serviceUrl);
            $service->setMailbox($url);
            $service->setOptions($flags);
            $stream = $service->open();
            $err_code = PHPCAS_SERVICE_OK;
            $pt = $service->getImapProxyTicket();
            return $stream;
        } catch (CAS_ProxyTicketException $e) {
            $err_msg = $e->getMessage();
            $err_code = $e->getCode();
            $pt = false;
            return false;
        } catch (CAS_ProxiedService_Exception $e) {
            $lang = $this->getLangObj();
            $err_msg = sprintf($lang->getServiceUnavailable(), $url, $e->getMessage());
            $err_code = PHPCAS_SERVICE_NOT_AVAILABLE;
            $pt = false;
            return false;
        }
    }

Usage Example

Пример #1
0
 /**
  * Verify that proxy-ticket Exceptions are caught and converted to error
  * codes in serviceMail().
  *
  * @return void
  */
 public function testServiceMailPtError()
 {
     $stream = $this->object->serviceMail('mailbox_name', 'imap://mail.example.edu/path/that/doesnt/exist', OP_READONLY, $err_code, $err_msg, $pt);
     $this->assertFalse($stream, "serviceMail() should have returned false on a PT error.");
     $this->assertEquals(PHPCAS_SERVICE_PT_FAILURE, $err_code);
     $this->assertStringStartsWith("PT retrieving failed", $err_msg);
     $this->assertFalse($pt, '$pt should be false.');
 }
All Usage Examples Of CAS_Client::serviceMail
CAS_Client