ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules 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. More...
 
 send ($recipients, $headers, $body)
 Implements Mail::send() function using php's built-in mail() command. More...
 
 _sanitizeHeaders (&$headers)
 Sanitize an array of mail headers by removing any additional header strings present in a legitimate header's value. More...
 
 prepareHeaders ($headers)
 Take an array of mail headers and return a string containing text usable in sending a message. More...
 
 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. More...
 

Data Fields

 $sep = "\r\n"
 

Detailed Description

Definition at line 57 of file Mail.php.

Member Function Documentation

◆ _sanitizeHeaders()

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().

154  {
155  foreach ($headers as $key => $value) {
156  $headers[$key] =
157  preg_replace('=((<CR>|<LF>|0x0A/%0A|0x0D/%0D|\\n|\\r)\S).*=i',
158  null, $value);
159  }
160  }
+ Here is the caller graph for this function:

◆ factory()

& 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().

Referenced by Log_mail\close().

75  {
76  $driver = strtolower($driver);
77  @include_once 'Mail/' . $driver . '.php';
78  $class = 'Mail_' . $driver;
79  if (class_exists($class)) {
80  $mailer = new $class($params);
81  return $mailer;
82  } else {
83  return PEAR::raiseError('Unable to find class for driver ' . $driver);
84  }
85  }
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object&#39;s de...
Definition: PEAR.php:524
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseRecipients()

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().

241  {
242  include_once 'Mail/RFC822.php';
243 
244  // if we're passed an array, assume addresses are valid and
245  // implode them before parsing.
246  if (is_array($recipients)) {
247  $recipients = implode(', ', $recipients);
248  }
249 
250  // Parse recipients, leaving out all personal info. This is
251  // for smtp recipients, etc. All relevant personal information
252  // should already be in the headers.
253  $addresses = Mail_RFC822::parseAddressList($recipients, 'localhost', false);
254 
255  // If parseAddressList() returned a PEAR_Error object, just return it.
256  if (is_a($addresses, 'PEAR_Error')) {
257  return $addresses;
258  }
259 
260  $recipients = array();
261  if (is_array($addresses)) {
262  foreach ($addresses as $ob) {
263  $recipients[] = $ob->mailbox . '@' . $ob->host;
264  }
265  }
266 
267  return $recipients;
268  }
parseAddressList($address=null, $default_domain=null, $nest_groups=null, $validate=null, $limit=null)
Starts the whole process.
Definition: RFC822.php:173
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ prepareHeaders()

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().

179  {
180  $lines = array();
181  $from = null;
182 
183  foreach ($headers as $key => $value) {
184  if (strcasecmp($key, 'From') === 0) {
185  include_once 'Mail/RFC822.php';
186  $parser = new Mail_RFC822();
187  $addresses = $parser->parseAddressList($value, 'localhost', false);
188  if (is_a($addresses, 'PEAR_Error')) {
189  return $addresses;
190  }
191 
192  $from = $addresses[0]->mailbox . '@' . $addresses[0]->host;
193 
194  // Reject envelope From: addresses with spaces.
195  if (strstr($from, ' ')) {
196  return false;
197  }
198 
199  $lines[] = $key . ': ' . $value;
200  } elseif (strcasecmp($key, 'Received') === 0) {
201  $received = array();
202  if (is_array($value)) {
203  foreach ($value as $line) {
204  $received[] = $key . ': ' . $line;
205  }
206  }
207  else {
208  $received[] = $key . ': ' . $value;
209  }
210  // Put Received: headers at the top. Spam detectors often
211  // flag messages with Received: headers after the Subject:
212  // as spam.
213  $lines = array_merge($received, $lines);
214  } else {
215  // If $value is an array (i.e., a list of addresses), convert
216  // it to a comma-delimited string of its elements (addresses).
217  if (is_array($value)) {
218  $value = implode(', ', $value);
219  }
220  $lines[] = $key . ': ' . $value;
221  }
222  }
223 
224  return array($from, join($this->sep, $lines));
225  }
+ Here is the caller graph for this function:

◆ send()

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

Definition at line 114 of file Mail.php.

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

115  {
116  if (!is_array($headers)) {
117  return PEAR::raiseError('$headers must be an array');
118  }
119 
120  $result = $this->_sanitizeHeaders($headers);
121  if (is_a($result, 'PEAR_Error')) {
122  return $result;
123  }
124 
125  // if we're passed an array of recipients, implode it.
126  if (is_array($recipients)) {
127  $recipients = implode(', ', $recipients);
128  }
129 
130  // get the Subject out of the headers array so that we can
131  // pass it as a seperate argument to mail().
132  $subject = '';
133  if (isset($headers['Subject'])) {
134  $subject = $headers['Subject'];
135  unset($headers['Subject']);
136  }
137 
138  // flatten the headers out.
139  list(, $text_headers) = Mail::prepareHeaders($headers);
140 
141  return mail($recipients, $subject, $body, $text_headers);
142  }
$result
_sanitizeHeaders(&$headers)
Sanitize an array of mail headers by removing any additional header strings present in a legitimate h...
Definition: Mail.php:153
prepareHeaders($headers)
Take an array of mail headers and return a string containing text usable in sending a message...
Definition: Mail.php:178
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object&#39;s de...
Definition: PEAR.php:524
+ Here is the call graph for this function:

Field Documentation

◆ $sep

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

Definition at line 63 of file Mail.php.


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