ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
Mail Class Reference
+ Inheritance diagram for Mail:
+ Collaboration diagram for Mail:

Public Member Functions

factory ($driver, $params=array())
 Provides an interface for generating Mail:: objects of various types.
 send ($recipients, $headers, $body)
 Implements Mail::send() function using php's built-in mail() command.
 _sanitizeHeaders (&$headers)
 Sanitize an array of mail headers by removing any additional header strings present in a legitimate header's value.
 prepareHeaders ($headers)
 Take an array of mail headers and return a string containing text usable in sending a message.
 parseRecipients ($recipients)
 Take a set of recipients and parse them, returning an array of bare addresses (forward paths) that can be passed to sendmail or an smtp server with the rcpt to: command.

Data Fields

 $sep = "\r\n"

Detailed Description

Definition at line 57 of file Mail.php.

Member Function Documentation

Mail::_sanitizeHeaders ( $headers)

Sanitize an array of mail headers by removing any additional header strings present in a legitimate header's value.

The goal of this filter is to prevent mail injection attacks.

Parameters
array$headersThe associative array of headers to sanitize.

private

Definition at line 153 of file Mail.php.

Referenced by Mail_sendmail\send(), send(), Mail_mail\send(), Mail_smtp\send(), and Mail_smtpmx\send().

{
foreach ($headers as $key => $value) {
$headers[$key] =
preg_replace('=((<CR>|<LF>|0x0A/%0A|0x0D/%0D|\\n|\\r)\S).*=i',
null, $value);
}
}

+ Here is the caller graph for this function:

& Mail::factory (   $driver,
  $params = array() 
)

Provides an interface for generating Mail:: objects of various types.

Parameters
string$driverThe kind of Mail:: object to instantiate.
array$paramsThe parameters to pass to the Mail:: object.
Returns
object Mail a instance of the driver class or if fails a PEAR Error public

Definition at line 74 of file Mail.php.

References PEAR\raiseError().

{
$driver = strtolower($driver);
@include_once 'Mail/' . $driver . '.php';
$class = 'Mail_' . $driver;
if (class_exists($class)) {
$mailer = new $class($params);
return $mailer;
} else {
return PEAR::raiseError('Unable to find class for driver ' . $driver);
}
}

+ Here is the call graph for this function:

Mail::parseRecipients (   $recipients)

Take a set of recipients and parse them, returning an array of bare addresses (forward paths) that can be passed to sendmail or an smtp server with the rcpt to: command.

Parameters
mixedEither a comma-seperated list of recipients (RFC822 compliant), or an array of recipients, each RFC822 valid.
Returns
mixed An array of forward paths (bare addresses) or a PEAR_Error object if the address list could not be parsed. private

Definition at line 240 of file Mail.php.

References Mail_RFC822\parseAddressList().

Referenced by Mail_sendmail\send(), Mail_smtp\send(), and Mail_smtpmx\send().

{
include_once 'Mail/RFC822.php';
// if we're passed an array, assume addresses are valid and
// implode them before parsing.
if (is_array($recipients)) {
$recipients = implode(', ', $recipients);
}
// Parse recipients, leaving out all personal info. This is
// for smtp recipients, etc. All relevant personal information
// should already be in the headers.
$addresses = Mail_RFC822::parseAddressList($recipients, 'localhost', false);
// If parseAddressList() returned a PEAR_Error object, just return it.
if (is_a($addresses, 'PEAR_Error')) {
return $addresses;
}
$recipients = array();
if (is_array($addresses)) {
foreach ($addresses as $ob) {
$recipients[] = $ob->mailbox . '@' . $ob->host;
}
}
return $recipients;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Mail::prepareHeaders (   $headers)

Take an array of mail headers and return a string containing text usable in sending a message.

Parameters
array$headersThe array of headers to prepare, in an associative array, where the array key is the header name (ie, 'Subject'), and the array value is the header value (ie, 'test'). The header produced from those values would be 'Subject: test'.
Returns
mixed Returns false if it encounters a bad address, otherwise returns an array containing two elements: Any From: address found in the headers, and the plain text version of the headers. private

Definition at line 178 of file Mail.php.

Referenced by Mail_sendmail\send(), send(), Mail_mail\send(), Mail_smtp\send(), and Mail_smtpmx\send().

{
$lines = array();
$from = null;
foreach ($headers as $key => $value) {
if (strcasecmp($key, 'From') === 0) {
include_once 'Mail/RFC822.php';
$parser = new Mail_RFC822();
$addresses = $parser->parseAddressList($value, 'localhost', false);
if (is_a($addresses, 'PEAR_Error')) {
return $addresses;
}
$from = $addresses[0]->mailbox . '@' . $addresses[0]->host;
// Reject envelope From: addresses with spaces.
if (strstr($from, ' ')) {
return false;
}
$lines[] = $key . ': ' . $value;
} elseif (strcasecmp($key, 'Received') === 0) {
$received = array();
if (is_array($value)) {
foreach ($value as $line) {
$received[] = $key . ': ' . $line;
}
}
else {
$received[] = $key . ': ' . $value;
}
// Put Received: headers at the top. Spam detectors often
// flag messages with Received: headers after the Subject:
// as spam.
$lines = array_merge($received, $lines);
} else {
// If $value is an array (i.e., a list of addresses), convert
// it to a comma-delimited string of its elements (addresses).
if (is_array($value)) {
$value = implode(', ', $value);
}
$lines[] = $key . ': ' . $value;
}
}
return array($from, join($this->sep, $lines));
}

+ Here is the caller graph for this function:

Mail::send (   $recipients,
  $headers,
  $body 
)

Implements Mail::send() function using php's built-in mail() command.

Parameters
mixed$recipientsEither a comma-seperated list of recipients (RFC822 compliant), or an array of recipients, each RFC822 valid. This may contain recipients not specified in the headers, for Bcc:, resending messages, etc.
array$headersThe array of headers to send with the mail, in an associative array, where the array key is the header name (ie, 'Subject'), and the array value is the header value (ie, 'test'). The header produced from those values would be 'Subject: test'.
string$bodyThe full text of the message body, including any Mime parts, etc.
Returns
mixed Returns true on success, or a PEAR_Error containing a descriptive error message on failure.

public

Deprecated:
use Mail_mail::send instead

Reimplemented in Mail_smtpmx, Mail_smtp, Mail_mock, Mail_mail, Mail_sendmail, and Mail_null.

Definition at line 114 of file Mail.php.

References $result, _sanitizeHeaders(), prepareHeaders(), and PEAR\raiseError().

{
if (!is_array($headers)) {
return PEAR::raiseError('$headers must be an array');
}
$result = $this->_sanitizeHeaders($headers);
if (is_a($result, 'PEAR_Error')) {
return $result;
}
// if we're passed an array of recipients, implode it.
if (is_array($recipients)) {
$recipients = implode(', ', $recipients);
}
// get the Subject out of the headers array so that we can
// pass it as a seperate argument to mail().
$subject = '';
if (isset($headers['Subject'])) {
$subject = $headers['Subject'];
unset($headers['Subject']);
}
// flatten the headers out.
list(, $text_headers) = Mail::prepareHeaders($headers);
return mail($recipients, $subject, $body, $text_headers);
}

+ Here is the call graph for this function:

Field Documentation

Mail::$sep = "\r\n"

Definition at line 63 of file Mail.php.


The documentation for this class was generated from the following file: