<?php
-class IPF_Exception extends Exception{}
+class IPF_Exception extends Exception
+{
+}
+
IPF_Mime::MULTIPART_RELATED,
);
if (!in_array($type, $allowed)) {
- throw new IPF_Exception_Mail('Invalid content type "' . $type . '"');
+ throw new IPF_Mail_Exception('Invalid content type "' . $type . '"');
}
$this->_type = $type;
$this->_from = $email;
$this->_storeHeader('From', $this->_encodeHeader('"'.$name.'"').' <'.$email.'>', true);
} else {
- throw new IPF_Exception_Mail('From Header set twice');
+ throw new IPF_Mail_Exception('From Header set twice');
}
return $this;
}
$this->_returnPath = $email;
$this->_storeHeader('Return-Path', $email, false);
} else {
- throw new IPF_Exception_Mail('Return-Path Header set twice');
+ throw new IPF_Mail_Exception('Return-Path Header set twice');
}
return $this;
}
$this->_subject = IPF_Mime::encodeQ($subject);
$this->_storeHeader('Subject', $this->_subject);
} else {
- throw new IPF_Exception_Mail('Subject set twice');
+ throw new IPF_Mail_Exception('Subject set twice');
}
return $this;
}
} else if (is_string($date)) {
$date = strtotime($date);
if ($date === false || $date < 0) {
- throw new IPF_Exception_Mail('String representations of Date Header must be ' .
+ throw new IPF_Mail_Exception('String representations of Date Header must be ' .
'strtotime()-compatible');
}
$date = date('r', $date);
} else {
- throw new IPF_Exception_Mail(__METHOD__ . ' only accepts UNIX timestamps and strtotime()-compatible strings');
+ throw new IPF_Mail_Exception(__METHOD__ . ' only accepts UNIX timestamps and strtotime()-compatible strings');
}
$this->_date = $date;
$this->_storeHeader('Date', $date);
} else {
- throw new IPF_Exception_Mail('Date Header set twice');
+ throw new IPF_Mail_Exception('Date Header set twice');
}
return $this;
}
public function addHeader($name, $value, $append = false)
{
if (in_array(strtolower($name), array('to', 'cc', 'bcc', 'from', 'subject', 'return-path', 'date'))) {
- throw new IPF_Exception_Mail('Cannot set standard header from addHeader()');
+ throw new IPF_Mail_Exception('Cannot set standard header from addHeader()');
}
$value = strtr($value,"\r\n\t",'???');
--- /dev/null
+<?php
+
+class IPF_Mail_Exception extends Exception
+{
+}
+
if (!is_resource($params['file'])) {
$params['raw'] = @file_get_contents($params['file']);
if ($params['raw'] === false) {
- throw new IPF_Exception_Mail('could not open file');
+ throw new IPF_Mail_Exception('could not open file');
}
} else {
$params['raw'] = stream_get_contents($params['file']);
{
if (isset($params['handler'])) {
if (!$params['handler'] instanceof IPF_Mail_Storage_Abstract) {
- throw new IPF_Exception_Mail('handler is not a valid mail handler');
+ throw new IPF_Mail_Exception('handler is not a valid mail handler');
}
if (!isset($params['id'])) {
- throw new IPF_Exception_Mail('need a message id with a handler');
+ throw new IPF_Mail_Exception('need a message id with a handler');
}
$this->_mail = $params['handler'];
{
try {
return stripos($this->contentType, 'multipart/') === 0;
- } catch(IPF_Exception_Mail $e) {
+ } catch(IPF_Mail_Exception $e) {
return false;
}
}
if ($this->_mail) {
return $this->_mail->getRawContent($this->_messageNum);
} else {
- throw new IPF_Exception_Mail('no content');
+ throw new IPF_Mail_Exception('no content');
}
}
// split content in parts
$boundary = $this->getHeaderField('content-type', 'boundary');
if (!$boundary) {
- throw new IPF_Exception_Mail('no boundary found in content type to split message');
+ throw new IPF_Mail_Exception('no boundary found in content type to split message');
}
$parts = IPF_Mime_Decode::splitMessageStruct($this->_content, $boundary);
$counter = 1;
}
if (!$this->_mail && $this->_content === null) {
- throw new IPF_Exception_Mail('part not found');
+ throw new IPF_Mail_Exception('part not found');
}
if ($this->_mail && $this->_mail->hasFetchPart) {
$this->_cacheContent();
if (!isset($this->_parts[$num])) {
- throw new IPF_Exception_Mail('part not found');
+ throw new IPF_Mail_Exception('part not found');
}
return $this->_parts[$num];
if (!isset($this->_headers[$lowerName])) {
$lowerName = strtolower(preg_replace('%([a-z])([A-Z])%', '\1-\2', $name));
if (!isset($this->_headers[$lowerName])) {
- throw new IPF_Exception_Mail("no Header with Name $name found");
+ throw new IPF_Mail_Exception("no Header with Name $name found");
}
}
$name = $lowerName;
if ($errorNum == 0) {
$errorStr = 'Could not open socket';
}
- throw new IPF_Exception_Mail($errorStr);
+ throw new IPF_Mail_Exception($errorStr);
}
if (($result = stream_set_timeout($this->_socket, self::TIMEOUT_CONNECTION)) === false) {
- throw new IPF_Exception_Mail('Could not set stream timeout');
+ throw new IPF_Mail_Exception('Could not set stream timeout');
}
return $result;
protected function _send($request)
{
if (!is_resource($this->_socket)) {
- throw new IPF_Exception_Mail('No connection has been established to ' . $this->_host);
+ throw new IPF_Mail_Exception('No connection has been established to ' . $this->_host);
}
$this->_request = $request;
$this->_log .= $request . self::EOL;
if ($result === false) {
- throw new IPF_Exception_Mail('Could not send request to ' . $this->_host);
+ throw new IPF_Mail_Exception('Could not send request to ' . $this->_host);
}
return $result;
protected function _receive($timeout = null)
{
if (!is_resource($this->_socket)) {
- throw new IPF_Exception_Mail('No connection has been established to ' . $this->_host);
+ throw new IPF_Mail_Exception('No connection has been established to ' . $this->_host);
}
// Adapters may wish to supply per-commend timeouts according to appropriate RFC
$info = stream_get_meta_data($this->_socket);
if (!empty($info['timed_out'])) {
- throw new IPF_Exception_Mail($this->_host . ' has timed out');
+ throw new IPF_Mail_Exception($this->_host . ' has timed out');
}
if ($reponse === false) {
- throw new IPF_Exception_Mail('Could not read from ' . $this->_host);
+ throw new IPF_Mail_Exception('Could not read from ' . $this->_host);
}
return $reponse;
sscanf($result, $this->_template, $cmd, $msg);
if ($cmd === null || !in_array($cmd, $code)) {
- throw new IPF_Exception_Mail($result);
+ throw new IPF_Mail_Exception($result);
}
} while (strpos($msg, '-') === 0); // The '-' message prefix indicates an information string instead of a response string.
$this->_socket = @fsockopen($host, $port);
if (!$this->_socket) {
- throw new IPF_Exception_Mail('cannot connect to host');
+ throw new IPF_Mail_Exception('cannot connect to host');
}
if (!$this->_assumedNextLine('* OK')) {
- throw new IPF_Exception_Mail('host doesn\'t allow connection');
+ throw new IPF_Mail_Exception('host doesn\'t allow connection');
}
if ($ssl === 'TLS') {
$result = $this->requestAndResponse('STARTTLS');
$result = $result && stream_socket_enable_crypto($this->_socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
if (!$result) {
- throw new IPF_Exception_Mail('cannot enable TLS');
+ throw new IPF_Mail_Exception('cannot enable TLS');
}
}
}
{
$line = @fgets($this->_socket);
if ($line === false) {
- throw new IPF_Exception_Mail('cannot read - connection closed?');
+ throw new IPF_Mail_Exception('cannot read - connection closed?');
}
return $line;
foreach ($tokens as $token) {
if (is_array($token)) {
if (@fputs($this->_socket, $line . ' ' . $token[0] . "\r\n") === false) {
- throw new IPF_Exception_Mail('cannot write - connection closed?');
+ throw new IPF_Mail_Exception('cannot write - connection closed?');
}
if (!$this->_assumedNextLine('+ ')) {
- throw new IPF_Exception_Mail('cannot send literal string');
+ throw new IPF_Mail_Exception('cannot send literal string');
}
$line = $token[1];
} else {
}
if (@fputs($this->_socket, $line . "\r\n") === false) {
- throw new IPF_Exception_Mail('cannot write - connection closed?');
+ throw new IPF_Mail_Exception('cannot write - connection closed?');
}
}
if ($this->_socket) {
try {
$result = $this->requestAndResponse('LOGOUT', array(), true);
- } catch (IPF_Exception_Mail $e) {
+ } catch (IPF_Mail_Exception $e) {
// ignoring exception
}
fclose($this->_socket);
}
if ($to === null && !is_array($from)) {
- throw new IPF_Exception_Mail('the single id was not found in response');
+ throw new IPF_Mail_Exception('the single id was not found in response');
}
return $result;
$this->_socket = @fsockopen($host, $port);
if (!$this->_socket) {
- throw new IPF_Exception_Mail('cannot connect to host');
+ throw new IPF_Mail_Exception('cannot connect to host');
}
$welcome = $this->readResponse();
$this->request('STLS');
$result = stream_socket_enable_crypto($this->_socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
if (!$result) {
- throw new IPF_Exception_Mail('cannot enable TLS');
+ throw new IPF_Mail_Exception('cannot enable TLS');
}
}
{
$result = @fputs($this->_socket, $request . "\r\n");
if (!$result) {
- throw new IPF_Exception_Mail('send failed - connection closed?');
+ throw new IPF_Mail_Exception('send failed - connection closed?');
}
}
{
$result = @fgets($this->_socket);
if (!is_string($result)) {
- throw new IPF_Exception_Mail('read failed - connection closed?');
+ throw new IPF_Mail_Exception('read failed - connection closed?');
}
$result = trim($result);
}
if ($status != '+OK') {
- throw new IPF_Exception_Mail('last request failed');
+ throw new IPF_Mail_Exception('last request failed');
}
if ($multiline) {
try {
$this->request('QUIT');
- } catch (IPF_Exception_Mail $e) {
+ } catch (IPF_Mail_Exception $e) {
// ignore error - we're closing the socket anyway
}
try {
$this->request("APOP $user " . md5($this->_timestamp . $password));
return;
- } catch (IPF_Exception_Mail $e) {
+ } catch (IPF_Mail_Exception $e) {
// ignore
}
}
if ($fallback) {
return $this->retrieve($msgno);
} else {
- throw new IPF_Exception_Mail('top not supported and no fallback wanted');
+ throw new IPF_Mail_Exception('top not supported and no fallback wanted');
}
}
$this->hasTop = true;
try {
$result = $this->request("TOP $msgno $lines", true);
- } catch (IPF_Exception_Mail $e) {
+ } catch (IPF_Mail_Exception $e) {
$this->hasTop = false;
if ($fallback) {
$result = $this->retrieve($msgno);
break;
default:
- throw new IPF_Exception_Mail($config['ssl'] . ' is unsupported SSL type');
+ throw new IPF_Mail_Exception($config['ssl'] . ' is unsupported SSL type');
break;
}
}
{
// Respect RFC 2821 and disallow HELO attempts if session is already initiated.
if ($this->_sess === true) {
- throw new IPF_Exception_Mail('Cannot issue HELO to existing session');
+ throw new IPF_Mail_Exception('Cannot issue HELO to existing session');
}
// Validate client hostname
if (!$this->_validHost->isValid($host)) {
- throw new IPF_Exception_Mail(join(', ', $this->_validHost->getMessage()));
+ throw new IPF_Mail_Exception(join(', ', $this->_validHost->getMessage()));
}
// Initiate helo sequence
$this->_send('STARTTLS');
$this->_expect(220, 180);
if (!stream_socket_enable_crypto($this->_socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
- throw new IPF_Exception_Mail('Unable to connect via TLS');
+ throw new IPF_Mail_Exception('Unable to connect via TLS');
}
$this->_ehlo($host);
}
try {
$this->_send('EHLO ' . $host);
$this->_expect(250, 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
- } catch (IPF_Exception_Mail $e) {
+ } catch (IPF_Mail_Exception $e) {
$this->_send('HELO ' . $host);
$this->_expect(250, 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
- } catch (IPF_Exception_Mail $e) {
+ } catch (IPF_Mail_Exception $e) {
throw $e;
}
}
public function mail($from)
{
if ($this->_sess !== true) {
- throw new IPF_Exception_Mail('A valid session has not been started');
+ throw new IPF_Mail_Exception('A valid session has not been started');
}
$this->_send('MAIL FROM:<' . $from . '>');
public function rcpt($to)
{
if ($this->_mail !== true) {
- throw new IPF_Exception_Mail('No sender reverse path has been supplied');
+ throw new IPF_Mail_Exception('No sender reverse path has been supplied');
}
// Set rcpt to true, as per 4.1.1.3 of RFC 2821
{
// Ensure recipients have been set
if ($this->_rcpt !== true) {
- throw new IPF_Exception_Mail('No recipient forward path has been supplied');
+ throw new IPF_Mail_Exception('No recipient forward path has been supplied');
}
$this->_send('DATA');
public function auth()
{
if ($this->_auth === true) {
- throw new IPF_Exception_Mail('Already authenticated for this session');
+ throw new IPF_Mail_Exception('Already authenticated for this session');
}
}
protected function _prepareHeaders($headers)
{
if (!$this->_mail) {
- throw new IPF_Exception_Mail('Missing IPF_Mail object in _mail property');
+ throw new IPF_Mail_Exception('Missing IPF_Mail object in _mail property');
}
$this->header = '';
}
}
if (!$sane) {
- throw new IPF_Exception_Mail('At least one mail header line is too long');
+ throw new IPF_Mail_Exception('At least one mail header line is too long');
}
}
}
if (!$body) {
- throw new IPF_Exception_Mail('No body specified');
+ throw new IPF_Mail_Exception('No body specified');
}
// Get headers
$count = count($this->_parts);
$boundary = null;
if ($count < 1) {
- throw new IPF_Exception_Mail('Empty mail cannot be sent');
+ throw new IPF_Mail_Exception('Empty mail cannot be sent');
}
if ($count > 1) {
$this->parameters);
}
if (!$result) {
- throw new IPF_Exception_Mail('Unable to send mail');
+ throw new IPF_Mail_Exception('Unable to send mail');
}
}
protected function _prepareHeaders($headers)
{
if (!$this->_mail) {
- throw new IPF_Exception_Mail('_prepareHeaders requires a registered IPF_Mail object');
+ throw new IPF_Mail_Exception('_prepareHeaders requires a registered IPF_Mail object');
}
// mail() uses its $to parameter to set the To: header, and the $subject
if (0 === strpos(PHP_OS, 'WIN')) {
// If the current recipients list is empty, throw an error
if (empty($this->recipients)) {
- throw new IPF_Exception_Mail('Missing To addresses');
+ throw new IPF_Mail_Exception('Missing To addresses');
}
} else {
// All others, simply grab the recipients and unset the To: header
if (!isset($headers['To'])) {
- throw new IPF_Exception_Mail('Missing To header');
+ throw new IPF_Mail_Exception('Missing To header');
}
unset($headers['To']['append']);
if ($this->_connection instanceof IPF_Mail_Protocol_Smtp) {
try {
$this->_connection->quit();
- } catch (IPF_Exception_Mail $e) {
+ } catch (IPF_Mail_Exception $e) {
// ignore
}
$this->_connection->disconnect();
protected function _prepareHeaders($headers)
{
if (!$this->_mail) {
- throw new IPF_Exception_Mail('_prepareHeaders requires a registered IPF_Mail object');
+ throw new IPF_Mail_Exception('_prepareHeaders requires a registered IPF_Mail object');
}
unset($headers['Bcc']);
// no more parts, find end boundary
$p = strpos($body, '--' . $boundary . '--', $start);
if ($p===false) {
- throw new IPF_Exception('Not a valid Mime Message: End Missing');
+ throw new IPF_Mime_Exception('Not a valid Mime Message: End Missing');
}
// the remaining part also needs to be parsed:
$field = $firstName . '=' . $field;
if (!preg_match_all('%([^=\s]+)\s*=("[^"]+"|[^;]+)(;\s*|$)%', $field, $matches)) {
- throw new IPF_Exception('not a valid header field');
+ throw new IPF_Mime_Exception('not a valid header field');
}
if ($wantedPart) {
--- /dev/null
+<?php
+
+class IPF_Mime_Exception extends Exception
+{
+}
+
// no more parts, find end boundary
$p = strpos($body, '--' . $boundary . '--', $start);
if ($p===false) {
- throw new IPF_Exception('Not a valid Mime Message: End Missing');
+ throw new IPF_Mime_Exception('Not a valid Mime Message: End Missing');
}
// the remaining part also needs to be parsed:
$newPart->description = $value;
break;
default:
- throw new IPF_Exception('Unknown header ignored for MimePart:' . $key);
+ throw new IPF_Mime_Exception('Unknown header ignored for MimePart:' . $key);
}
}
$res->addPart($newPart);
public function getEncodedStream()
{
if (!$this->_isStream) {
- throw new IPF_Exception('Attempt to get a stream from a string part');
+ throw new IPF_Mime_Exception('Attempt to get a stream from a string part');
}
//stream_filter_remove(); // ??? is that right?
)
);
if (!is_resource($filter)) {
- throw new IPF_Exception('Failed to append quoted-printable filter');
+ throw new IPF_Mime_Exception('Failed to append quoted-printable filter');
}
break;
case IPF_Mime::ENCODING_BASE64:
)
);
if (!is_resource($filter)) {
- throw new IPF_Exception('Failed to append base64 filter');
+ throw new IPF_Mime_Exception('Failed to append base64 filter');
}
break;
default: