Additional server debug information MAY be found in the $details
property.
/** * Constructor. * * @param string $extension The extension not supported on the server. * @param string $msg A non-standard error message to use instead * of the default. */ public function __construct($extension, $msg = null) { $this->extension = $extension; if (is_null($msg)) { $msg = sprintf(Horde_Imap_Client_Translation::r("The server does not support the %s extension."), $extension); } parent::__construct($msg, self::NOT_SUPPORTED); }
/** * Constructor. * * @param string $msg Error message. * @param integer $code Error code. * @param integer $status Server error status. * @param string $errtext Server error text. * @param string $errcmd The command that caused the error. */ public function __construct($msg = null, $code = 0, $status = 0, $errtext = null, $errcmd = null) { $this->status = $status; if (!is_null($errtext)) { $this->details = $errtext; } if (!is_null($errcmd)) { $this->command = $errcmd; } parent::__construct($msg, $code); }
/** */ public function __get($name) { switch ($name) { case 'command': return $this->_server instanceof Horde_Imap_Client_Interaction_Server_Tagged ? $this->_pipeline->getCmd($this->_server->tag)->getCommand() : null; case 'resp_data': return $this->_pipeline->data; case 'status': return $this->_server->status; default: return parent::__get($name); } }
/** * Authenticate to the POP3 server. * * @param string $method POP3 login method. * * @throws Horde_Imap_Client_Exception */ protected function _tryLogin($method) { $username = $this->getParam('username'); $password = $this->getParam('password'); switch ($method) { case 'CRAM-MD5': case 'CRAM-SHA1': case 'CRAM-SHA256': // RFC 5034: CRAM-MD5 // CRAM-SHA1 & CRAM-SHA256 supported by Courier SASL library $challenge = $this->_sendLine('AUTH ' . $method); $response = base64_encode($username . ' ' . hash_hmac(Horde_String::lower(substr($method, 5)), base64_decode(substr($challenge['resp'], 2)), $password, true)); $this->_sendLine($response, array('debug' => sprintf('[AUTH Response (username: %s)]', $username))); break; case 'DIGEST-MD5': // RFC 2831; Obsoleted by RFC 6331 $challenge = $this->_sendLine('AUTH DIGEST-MD5'); $response = base64_encode(new Horde_Imap_Client_Auth_DigestMD5($username, $password, base64_decode(substr($challenge['resp'], 2)), $this->getParam('hostspec'), 'pop3')); $sresponse = $this->_sendLine($response, array('debug' => sprintf('[AUTH Response (username: %s)]', $username))); if (stripos(base64_decode(substr($sresponse['resp'], 2)), 'rspauth=') === false) { throw new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::r("Unexpected response from server when authenticating."), Horde_Imap_Client_Exception::SERVER_CONNECT); } /* POP3 doesn't use protocol's third step. */ $this->_sendLine(''); break; case 'LOGIN': // RFC 4616 (AUTH=PLAIN) & 5034 (POP3 SASL) $this->_sendLine('AUTH LOGIN'); $this->_sendLine(base64_encode($username)); $this->_sendLine(base64_encode($password), array('debug' => sprintf('[AUTH Password (username: %s)]', $username))); break; case 'PLAIN': // RFC 5034 $this->_sendLine('AUTH PLAIN ' . base64_encode(implode("", array($username, $username, $password))), array('debug' => sprintf('AUTH PLAIN [Auth Response (username: %s)]', $username))); break; case 'APOP': /* If UTF8 (+ USER) is active, and non-ASCII exists, need to apply * SASLprep to username/password. RFC 6856[2.2]. Reject if * UTF8 (+ USER) is not supported and 8-bit characters exist. */ if (Horde_Mime::is8bit($username) || Horde_Mime::is8bit($password)) { if (empty($this->_temp['utf8']) || !$this->_capability('UTF8', 'USER') || !class_exists('Horde_Stringprep')) { $error = true; } else { Horde_Stringprep::autoload(); $saslprep = new Znerol\Component\Stringprep\Profile\SASLprep(); try { $username = $saslprep->apply($username, 'UTF-8', Znerol\Compnonent\Stringprep\Profile::MODE_QUERY); $password = $saslprep->apply($password, 'UTF-8', Znerol\Compnonent\Stringprep\Profile::MODE_STORE); $error = false; } catch (Znerol\Component\Stringprep\ProfileException $e) { $error = true; } } if ($error) { throw new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::r("Authentication failed."), Horde_Imap_Client_Exception::LOGIN_AUTHENTICATIONFAILED); } } // RFC 1939 [7] $this->_sendLine('APOP ' . $username . ' ' . hash('md5', $this->_temp['pop3timestamp'] . $password)); break; case 'USER': /* POP3 servers without UTF8 (+ USER) does not accept non-ASCII * in USER/PASS. RFC 6856[2.2] */ if ((empty($this->_temp['utf8']) || !$this->_capability('UTF8', 'USER')) && (Horde_Mime::is8bit($username) || Horde_Mime::is8bit($password))) { throw new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::r("Authentication failed."), Horde_Imap_Client_Exception::LOGIN_AUTHENTICATIONFAILED); } // RFC 1939 [7] $this->_sendLine('USER ' . $username); $this->_sendLine('PASS ' . $password, array('debug' => 'PASS [Password]')); break; case 'SCRAM-SHA-1': $scram = new Horde_Imap_Client_Auth_Scram($username, $password, 'SHA1'); $c1 = $this->_sendLine('AUTH ' . $method . ' ' . base64_encode($scram->getClientFirstMessage())); $sr1 = base64_decode(substr($c1['resp'], 2)); if (!$scram->parseServerFirstMessage($sr1)) { throw new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::r("Authentication failed."), Horde_Imap_Client_Exception::LOGIN_AUTHENTICATIONFAILED); } $c2 = $this->_sendLine(base64_encode($scram->getClientFinalMessage())); $sr2 = base64_decode(substr($c2['resp'], 2)); if (!$scram->parseServerFirstMessage($sr)) { throw new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::r("Authentication failed."), Horde_Imap_Client_Exception::LOGIN_AUTHENTICATIONFAILED); /* This means authentication passed, according to the server, * but the server signature is incorrect. This indicates that * server verification has failed. Immediately disconnect from * the server, since this is a possible security issue. */ $this->logout(); throw new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::r("Server failed verification check."), Horde_Imap_Client_Exception::LOGIN_SERVER_VERIFICATION_FAILED); } $this->_sendLine(''); break; default: $e = new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::r("Unknown authentication method: %s"), Horde_Imap_Client_Exception::SERVER_CONNECT); $e->messagePrintf(array($method)); throw $e; } }
/** * Connects to the IMAP server. * * @throws Horde_Imap_Client_Exception */ protected function _connect() { if (!is_null($this->_stream)) { return; } if (!empty($this->_params['secure']) && !extension_loaded('openssl')) { throw new InvalidArgumentException('Secure connections require the PHP openssl extension.'); } switch ($this->_params['secure']) { case 'ssl': case 'sslv2': case 'sslv3': $conn = $this->_params['secure'] . '://'; $this->_isSecure = true; break; case 'tls': default: $conn = 'tcp://'; break; } $this->_stream = @stream_socket_client($conn . $this->_params['hostspec'] . ':' . $this->_params['port'], $error_number, $error_string, $this->_params['timeout']); if ($this->_stream === false) { $this->_stream = null; $this->_isSecure = false; $e = new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::t("Error connecting to mail server."), Horde_Imap_Client_Exception::SERVER_CONNECT); $e->details = sprintf("[%u] %s", $error_number, $error_string); throw $e; } stream_set_timeout($this->_stream, $this->_params['timeout']); // If we already have capability information, don't re-set with // (possibly) limited information sent in the inital banner. if (isset($this->_init['capability'])) { $this->_temp['no_cap'] = true; } /* Get greeting information. This is untagged so we need to specially * deal with it here. */ try { $this->_getLine(); } catch (Horde_Imap_Client_Exception_ServerResponse $e) { if ($e->status == Horde_Imap_Client_Interaction_Server::BYE) { /* Server is explicitly rejecting our connection (RFC 3501 * [7.1.5]). */ $e->setMessage(Horde_Imap_Client_Translation::t("Server rejected connection.")); $e->setCode(Horde_Imap_Client_Exception::SERVER_CONNECT); } throw $e; } // Check for IMAP4rev1 support if (!$this->queryCapability('IMAP4REV1')) { throw new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::t("The mail server does not support IMAP4rev1 (RFC 3501)."), Horde_Imap_Client_Exception::SERVER_CONNECT); } // Set language if NOT using imapproxy if (empty($this->_init['imapproxy'])) { if ($this->queryCapability('XIMAPPROXY')) { $this->_setInit('imapproxy', true); } else { $this->setLanguage(); } } // If pre-authenticated, we need to do all login tasks now. if (!empty($this->_temp['preauth'])) { $this->login(); } }
/** * Constructor. * * @param string $feature The feature not supported in POP3. */ public function __construct($feature) { parent::__construct(sprintf(Horde_Imap_Client_Translation::r("%s not supported on POP3 servers."), $feature), self::NOT_SUPPORTED); }
/** * Parse an ANNOTATION response (ANNOTATEMORE/ANNOTATEMORE2). * * @param Horde_Imap_Client_Interaction_Pipeline $pipeline Pipeline * object. * @param Horde_Imap_Client_Tokenize $data The server response. * * @throws Horde_Imap_Client_Exception */ protected function _parseAnnotation(Horde_Imap_Client_Interaction_Pipeline $pipeline, Horde_Imap_Client_Tokenize $data) { // Mailbox name is in UTF7-IMAP. $mbox = Horde_Imap_Client_Mailbox::get($data->next(), true); $entry = $data->next(); // Ignore unsolicited responses. if ($data->next() !== true) { return; } while (($type = $data->next()) !== false) { switch ($type) { case 'value.priv': $pipeline->data['metadata'][strval($mbox)]['/private' . $entry] = $data->next(); break; case 'value.shared': $pipeline->data['metadata'][strval($mbox)]['/shared' . $entry] = $data->next(); break; default: $e = new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::r("Invalid METADATA value type \"%s\"."), Horde_Imap_Client_Exception::METADATA_INVALID); $e->messagePrintf(array($type)); throw $e; } } }
/** * Constructor. * * @param string $feature The feature not supported in POP3. */ public function __construct($feature) { parent::__construct(Horde_Imap_Client_Translation::r("%s not supported on POP3 servers."), self::NOT_SUPPORTED); $this->messagePrintf(array($feature)); }
/** * Authenticate to the POP3 server. * * @param string $method POP3 login method. * * @throws Horde_Imap_Client_Exception */ protected function _tryLogin($method) { $username = $this->getParam('username'); $password = $this->getParam('password'); switch ($method) { case 'CRAM-MD5': case 'CRAM-SHA1': case 'CRAM-SHA256': // RFC 5034: CRAM-MD5 // CRAM-SHA1 & CRAM-SHA256 supported by Courier SASL library $challenge = $this->_sendLine('AUTH ' . $method); $response = base64_encode($username . ' ' . hash_hmac(strtolower(substr($method, 5)), base64_decode(substr($challenge['resp'], 2)), $password, true)); $this->_sendLine($response, array('debug' => sprintf('[AUTH Response (username: %s)]', $username))); break; case 'DIGEST-MD5': // RFC 2831; Obsoleted by RFC 6331 $challenge = $this->_sendLine('AUTH DIGEST-MD5'); $response = base64_encode(new Horde_Imap_Client_Auth_DigestMD5($username, $password, base64_decode(substr($challenge['resp'], 2)), $this->getParam('hostspec'), 'pop3')); $sresponse = $this->_sendLine($response, array('debug' => sprintf('[AUTH Response (username: %s)]', $username))); if (stripos(base64_decode(substr($sresponse['resp'], 2)), 'rspauth=') === false) { throw new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::r("Unexpected response from server when authenticating."), Horde_Imap_Client_Exception::SERVER_CONNECT); } /* POP3 doesn't use protocol's third step. */ $this->_sendLine(''); break; case 'LOGIN': // RFC 4616 (AUTH=PLAIN) & 5034 (POP3 SASL) $this->_sendLine('AUTH LOGIN'); $this->_sendLine(base64_encode($username)); $this->_sendLine(base64_encode($password), array('debug' => sprintf('[AUTH Password (username: %s)]', $username))); break; case 'PLAIN': // RFC 5034 $this->_sendLine('AUTH PLAIN ' . base64_encode(implode("", array($username, $username, $password))), array('debug' => sprintf('AUTH PLAIN [Auth Response (username: %s)]', $username))); break; case 'APOP': // RFC 1939 [7] $this->_sendLine('APOP ' . $username . ' ' . hash('md5', $this->_temp['pop3timestamp'] . $password)); break; case 'USER': // RFC 1939 [7] $this->_sendLine('USER ' . $username); $this->_sendLine('PASS ' . $password, array('debug' => 'PASS [Password]')); break; default: $e = new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::r("Unknown authentication method: %s"), Horde_Imap_Client_Exception::SERVER_CONNECT); $e->messagePrintf(array($method)); throw $e; } }
/** * Constructor. * * @param string $charset The charset that was attempted to be converted * to. */ public function __construct($charset) { $this->charset = $charset; parent::__construct(Horde_Imap_Client_Translation::t("Cannot convert search query text to new charset"), self::BADCHARSET); }