/[drupal]/drupal/modules/system/mail.sending.inc
ViewVC logotype

Contents of /drupal/modules/system/mail.sending.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Mon Nov 2 04:10:51 2009 UTC (3 weeks, 3 days ago) by webchick
Branch: MAIN
CVS Tags: DRUPAL-7-0-UNSTABLE-10, HEAD
Changes since 1.3: +4 -2 lines
File MIME type: text/x-php
#239825 follow-up: Adjusting comments.
1 <?php
2 // $Id: mail.sending.inc,v 1.3 2009/11/02 02:37:36 webchick Exp $
3
4 /**
5 * @file
6 * Drupal core implementations of MailSystemInterface.
7 */
8
9 /**
10 * The default Drupal mail backend using PHP's mail function.
11 */
12 class DefaultMailSystem implements MailSystemInterface {
13 /**
14 * Concatenate and wrap the e-mail body for plain-text mails.
15 *
16 * @param $message
17 * A message array, as described in hook_mail_alter().
18 *
19 * @return
20 * The formatted $message.
21 */
22 public function format(array $message) {
23 // Join the body array into one string.
24 $message['body'] = implode("\n\n", $message['body']);
25 // Convert any HTML to plain-text.
26 $message['body'] = drupal_html_to_text($message['body']);
27 // Wrap the mail body for sending.
28 $message['body'] = drupal_wrap_mail($message['body']);
29 return $message;
30 }
31
32 /**
33 * Send an e-mail message, using Drupal variables and default settings.
34 *
35 * @see http://php.net/manual/en/function.mail.php
36 * @see drupal_mail()
37 *
38 * @param $message
39 * A message array, as described in hook_mail_alter().
40 * @return
41 * TRUE if the mail was successfully accepted, otherwise FALSE.
42 */
43 public function mail(array $message) {
44 $mimeheaders = array();
45 foreach ($message['headers'] as $name => $value) {
46 $mimeheaders[] = $name . ': ' . mime_header_encode($value);
47 }
48 $line_endings = variable_get('mail_line_endings', MAIL_LINE_ENDINGS);
49 return mail(
50 $message['to'],
51 mime_header_encode($message['subject']),
52 // Note: e-mail uses CRLF for line-endings. PHP's API requires LF
53 // on Unix and CRLF on Windows. Drupal automatically guesses the
54 // line-ending format appropriate for your system. If you need to
55 // override this, adjust $conf['mail_line_endings'] in settings.php.
56 preg_replace('@\r?\n@', $line_endings, $message['body']),
57 // For headers, PHP's API suggests that we use CRLF normally,
58 // but some MTAs incorrectly replace LF with CRLF. See #234403.
59 join("\n", $mimeheaders)
60 );
61 }
62 }
63
64 /**
65 * A mail sending implementation that captures sent messages to a variable.
66 *
67 * This class is for running tests or for development.
68 */
69 class TestingMailSystem extends DefaultMailSystem implements MailSystemInterface {
70 /**
71 * Accept an e-mail message and store it in a variable.
72 *
73 * @param $message
74 * An e-mail message.
75 */
76 public function mail(array $message) {
77 $captured_emails = variable_get('drupal_test_email_collector', array());
78 $captured_emails[] = $message;
79 variable_set('drupal_test_email_collector', $captured_emails);
80 return TRUE;
81 }
82 }
83

  ViewVC Help
Powered by ViewVC 1.1.2