/**
* Inject IMAP authentication credentials
*
* @param array $args arguments from rcmail
* @return array modified arguments
*/
function imap_connect($args) {
// retrieve configurations
$cfg = rcmail::get_instance()->config->all();
// RoundCube is acting as CAS proxy
if ($cfg['cas_proxy']) {
// a proxy ticket has been retrieved, the IMAP server caches proxy tickets, and this is the first connection attempt
if ($_SESSION['cas_pt'][php_uname('n')] && $cfg['cas_imap_caching'] && $args['attempt'] == 1) {
// use existing proxy ticket in session
$args['pass'] = $_SESSION['cas_pt'][php_uname('n')];
}
// no proxy tickets have been retrieved, the IMAP server doesn't cache proxy tickets, or the first connection attempt has failed
else {
// initialize CAS client
$this->cas_init();
// retrieve a new proxy ticket and store it in session
if (phpCAS::forceAuthentication()) {
$_SESSION['cas_pt'][php_uname('n')] = phpCAS::retrievePT($cfg['cas_imap_name'], $err_code, $output);
$args['pass'] = $_SESSION['cas_pt'][php_uname('n')];
}
}
// enable retry on the first connection attempt only
if ($args['attempt'] <= 1) {
$args['retry'] = true;
}
}
$args['valid'] = true;
return $args;
}