Allow the passing of connection parameters to imap_open()

Since version 5.3.2 of PHP, imap_open() has an optional 6th
parameter which allows you to set certain connection parameters.

Currently the only key is:

- DISABLE_AUTHENTICATOR - Disable authentication properties

see https://bugs.php.net/bug.php?id=33500

Example of use:

  $server = new Server('imap.example.com', 993);
  $server->setParam('DISABLE_AUTHENTICATOR', 'GSSAPI');

This gets rid of the following errors:
<br />
<b>Notice</b>:  Unknown: Unknown GSSAPI failure: An invalid name was
supplied (errflg=1) in <b>Unknown</b> on line <b>0</b><br />
<br />
<b>Notice</b>:  Unknown: GSSAPI mechanism status: Hostname cannot be
canonicalized (errflg=1) in <b>Unknown</b> on line <b>0</b><br />
This commit is contained in:
David Rainsford 2014-04-03 10:59:19 +11:00
parent 8650586610
commit b0d22fb76c

View File

@ -93,6 +93,13 @@ class Server
*/ */
protected $options = 0; protected $options = 0;
/**
* This is the set of connection parameters
*
* @var array
*/
protected $params = array();
/** /**
* This is the resource connection to the server. It is required by a number of imap based functions to specify how * This is the resource connection to the server. It is required by a number of imap based functions to specify how
* to connect. * to connect.
@ -224,6 +231,16 @@ class Server
$this->options = $bitmask; $this->options = $bitmask;
} }
/**
* This function is used to set connection parameters
*
* @param string $key
* @param string $value
*/
public function setParam($key, $value) {
$this->params[$key] = $value;
}
/** /**
* This function gets the current saved imap resource and returns it. * This function gets the current saved imap resource and returns it.
* *
@ -287,7 +304,7 @@ class Server
if (!imap_reopen($this->imapStream, $this->getServerString(), $this->options, 1)) if (!imap_reopen($this->imapStream, $this->getServerString(), $this->options, 1))
throw new \RuntimeException(imap_last_error()); throw new \RuntimeException(imap_last_error());
} else { } else {
$imapStream = imap_open($this->getServerString(), $this->username, $this->password, $this->options, 1); $imapStream = imap_open($this->getServerString(), $this->username, $this->password, $this->options, 1, $this->params);
if ($imapStream === false) if ($imapStream === false)
throw new \RuntimeException(imap_last_error()); throw new \RuntimeException(imap_last_error());