summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-10-16 03:01:55 +0000
committerDries Buytaert <dries@buytaert.net>2009-10-16 03:01:55 +0000
commit13d3072f418835569f37f65b5055e5b3180fad2e (patch)
tree6964b91e90d3bddbc3d5ce302897c35a248ddf6b /modules
parentb965f7478f34c78b747ad6667738828599e86df7 (diff)
downloadbrdo-13d3072f418835569f37f65b5055e5b3180fad2e.tar.gz
brdo-13d3072f418835569f37f65b5055e5b3180fad2e.tar.bz2
- Patch #356074 by chx, Damien Tournoud: provide a sequences API.
Diffstat (limited to 'modules')
-rw-r--r--modules/contact/contact.test4
-rw-r--r--modules/simpletest/drupal_web_test_case.php2
-rw-r--r--modules/simpletest/simpletest.test6
-rw-r--r--modules/simpletest/tests/mail.test17
-rw-r--r--modules/system/mail.sending.inc34
-rw-r--r--modules/system/system.api.php34
-rw-r--r--modules/system/system.module15
-rw-r--r--modules/user/user.module3
8 files changed, 96 insertions, 19 deletions
diff --git a/modules/contact/contact.test b/modules/contact/contact.test
index 8b15df4cd..6bbf4d996 100644
--- a/modules/contact/contact.test
+++ b/modules/contact/contact.test
@@ -174,7 +174,7 @@ class ContactSitewideTestCase extends DrupalWebTestCase {
// We are testing the auto-reply, so there should be one e-mail going to the sender.
$captured_emails = $this->drupalGetMails(array('id' => 'contact_page_autoreply', 'to' => $email, 'from' => 'foo@example.com'));
$this->assertEqual(count($captured_emails), 1, t('Auto-reply e-mail was sent to the sender for category "foo".'), t('Contact'));
- $this->assertEqual($captured_emails[0]['body'], $foo_autoreply, t('Auto-reply e-mail body is correct for category "foo".'), t('Contact'));
+ $this->assertEqual($captured_emails[0]['body'], drupal_html_to_text($foo_autoreply), t('Auto-reply e-mail body is correct for category "foo".'), t('Contact'));
// Test the auto-reply for category 'bar'.
$email = $this->randomName(32) . '@example.com';
@@ -183,7 +183,7 @@ class ContactSitewideTestCase extends DrupalWebTestCase {
// Auto-reply for category 'bar' should result in one auto-reply e-mail to the sender.
$captured_emails = $this->drupalGetMails(array('id' => 'contact_page_autoreply', 'to' => $email, 'from' => 'bar@example.com'));
$this->assertEqual(count($captured_emails), 1, t('Auto-reply e-mail was sent to the sender for category "bar".'), t('Contact'));
- $this->assertEqual($captured_emails[0]['body'], $bar_autoreply, t('Auto-reply e-mail body is correct for category "bar".'), t('Contact'));
+ $this->assertEqual($captured_emails[0]['body'], drupal_html_to_text($bar_autoreply), t('Auto-reply e-mail body is correct for category "bar".'), t('Contact'));
// Verify that no auto-reply is sent when the auto-reply field is left blank.
$email = $this->randomName(32) . '@example.com';
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 88850e472..e2cb53e0e 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -1107,7 +1107,7 @@ class DrupalWebTestCase extends DrupalTestCase {
$language = language_default();
// Use the test mail class instead of the default mail handler class.
- variable_set('mail_sending_system', array('default-system' => 'TestingMailSystem'));
+ variable_set('mail_system', array('default-system' => 'TestingMailSystem'));
// Use temporary files directory with the same prefix as the database.
$public_files_directory = $this->originalFileDirectory . '/' . $db_prefix;
diff --git a/modules/simpletest/simpletest.test b/modules/simpletest/simpletest.test
index a26216a6e..3f157d4d1 100644
--- a/modules/simpletest/simpletest.test
+++ b/modules/simpletest/simpletest.test
@@ -339,7 +339,7 @@ class SimpleTestMailCaptureTestCase extends DrupalWebTestCase {
$this->assertEqual(count($captured_emails), 0, t('The captured e-mails queue is empty.'), t('E-mail'));
// Send the e-mail.
- $response = drupal_mail_sending_system('simpletest', 'drupal_mail_test')->mail($message);
+ $response = drupal_mail_system('simpletest', 'drupal_mail_test')->mail($message);
// Ensure that there is one e-mail in the captured e-mails array.
$captured_emails = $this->drupalGetMails();
@@ -360,7 +360,7 @@ class SimpleTestMailCaptureTestCase extends DrupalWebTestCase {
'to' => $this->randomName(32) . '@example.com',
'body' => $this->randomString(512),
);
- drupal_mail_sending_system('drupal_mail_test', $index)->mail($message);
+ drupal_mail_system('drupal_mail_test', $index)->mail($message);
}
// There should now be 6 e-mails captured.
@@ -377,7 +377,7 @@ class SimpleTestMailCaptureTestCase extends DrupalWebTestCase {
// Send the last e-mail again, so we can confirm that the drupalGetMails-filter
// correctly returns all e-mails with a given property/value.
- drupal_mail_sending_system('drupal_mail_test', $index)->mail($message);
+ drupal_mail_system('drupal_mail_test', $index)->mail($message);
$captured_emails = $this->drupalGetMails(array('id' => 'drupal_mail_test_4'));
$this->assertEqual(count($captured_emails), 2, t('All e-mails with the same id are returned when filtering by id.'), t('E-mail'));
}
diff --git a/modules/simpletest/tests/mail.test b/modules/simpletest/tests/mail.test
index 641d606ff..5db3abb7e 100644
--- a/modules/simpletest/tests/mail.test
+++ b/modules/simpletest/tests/mail.test
@@ -25,7 +25,7 @@ class MailTestCase extends DrupalWebTestCase implements MailSystemInterface {
parent::setUp();
// Set MailTestCase (i.e. this class) as the SMTP library
- variable_set('mail_sending_system', array('default-system' => 'MailTestCase'));
+ variable_set('mail_system', array('default-system' => 'MailTestCase'));
}
/**
@@ -42,6 +42,21 @@ class MailTestCase extends DrupalWebTestCase implements MailSystemInterface {
}
/**
+ * Concatenate and wrap the e-mail body for plain-text mails.
+ *
+ * @see DefaultMailSystem
+ */
+ public function format(array $message) {
+ // Join the body array into one string.
+ $message['body'] = implode("\n\n", $message['body']);
+ // Convert any HTML to plain-text.
+ $message['body'] = drupal_html_to_text($message['body']);
+ // Wrap the mail body for sending.
+ $message['body'] = drupal_wrap_mail($message['body']);
+ return $message;
+ }
+
+ /**
* Send function that is called through the mail system.
*/
public function mail(array $message) {
diff --git a/modules/system/mail.sending.inc b/modules/system/mail.sending.inc
index 6533de07d..96db60bb6 100644
--- a/modules/system/mail.sending.inc
+++ b/modules/system/mail.sending.inc
@@ -3,21 +3,40 @@
/**
* @file
- * Drupal core implementations of the DrupalMailSendingInterface.
+ * Drupal core implementations of MailSystemInterface.
*/
/**
- * The default Drupal mail sending library using PHP's mail function.
+ * The default Drupal mail backend using PHP's mail function.
*/
class DefaultMailSystem implements MailSystemInterface {
/**
+ * Concatenate and wrap the e-mail body for plain-text mails.
+ *
+ * @param $message
+ * A message array, as described in hook_mail_alter().
+ *
+ * @return
+ * The formatted $message.
+ */
+ public function format(array $message) {
+ // Join the body array into one string.
+ $message['body'] = implode("\n\n", $message['body']);
+ // Convert any HTML to plain-text.
+ $message['body'] = drupal_html_to_text($message['body']);
+ // Wrap the mail body for sending.
+ $message['body'] = drupal_wrap_mail($message['body']);
+ return $message;
+ }
+
+ /**
* Send an e-mail message, using Drupal variables and default settings.
- * @see http://php.net/manual/en/function.mail.php the PHP function reference
- * for mail().
- * @see drupal_mail() for information on how $message is composed.
+ *
+ * @see http://php.net/manual/en/function.mail.php
+ * @see drupal_mail()
*
* @param $message
- * Message array as described by DrupalMailSendingInterface.
+ * A message array, as described in hook_mail_alter().
* @return
* TRUE if the mail was successfully accepted, otherwise FALSE.
*/
@@ -44,8 +63,7 @@ class DefaultMailSystem implements MailSystemInterface {
*
* This class is for running tests or for development.
*/
-class TestingMailSystem implements MailSystemInterface {
-
+class TestingMailSystem extends DefaultMailSystem implements MailSystemInterface {
/**
* Accept an e-mail message and store it in a variable.
*
diff --git a/modules/system/system.api.php b/modules/system/system.api.php
index 1f4d1d394..d29a16035 100644
--- a/modules/system/system.api.php
+++ b/modules/system/system.api.php
@@ -12,6 +12,38 @@
*/
/**
+ * Defines one or more hooks that are exposed by a module.
+ *
+ * Normally hooks do not need to be explicitly defined. However, by declaring a
+ * hook explicitly, a module may define a "group" for it. Modules that implement
+ * a hook may then place their implementation in either $module.module or in
+ * $module.$group.inc. If the hook is located in $module.$group.inc, then that
+ * file will be automatically loaded when needed.
+ * In general, hooks that are rarely invoked and/or are very large should be
+ * placed in a separate include file, while hooks that are very short or very
+ * frequently called should be left in the main module file so that they are
+ * always available.
+ *
+ * @return
+ * An associative array whose keys are hook names and whose values are an
+ * associative array containing:
+ * - group: A string defining the group to which the hook belongs. The module
+ * system will determine whether a file with the name $module.$group.inc
+ * exists, and automatically load it when required.
+ *
+ * See system_hook_info() for all hook groups defined by Drupal core.
+ */
+function hook_hook_info() {
+ $hooks['token_info'] = array(
+ 'group' => 'tokens',
+ );
+ $hooks['tokens'] = array(
+ 'group' => 'tokens',
+ );
+ return $hooks;
+}
+
+/**
* Inform the base system and the Field API about one or more entity types.
*
* Inform the system about one or more entity types (i.e., object types that
@@ -700,7 +732,7 @@ function hook_image_toolkits() {
*
* Email messages sent using functions other than drupal_mail() will not
* invoke hook_mail_alter(). For example, a contributed module directly
- * calling the drupal_mail_sending_system()->mail() or PHP mail() function
+ * calling the drupal_mail_system()->mail() or PHP mail() function
* will not invoke this hook. All core modules use drupal_mail() for
* messaging, it is best practice but not manditory in contributed modules.
*
diff --git a/modules/system/system.module b/modules/system/system.module
index cb63659ec..cd35aa8ac 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -278,6 +278,19 @@ function system_rdf_namespaces() {
}
/**
+ * Implement hook_hook_info().
+ */
+function system_hook_info() {
+ $hooks['token_info'] = array(
+ 'group' => 'tokens',
+ );
+ $hooks['tokens'] = array(
+ 'group' => 'tokens',
+ );
+ return $hooks;
+}
+
+/**
* Implement hook_entity_info().
*/
function system_entity_info() {
@@ -2762,7 +2775,7 @@ function system_mail($key, &$message, $params) {
$body = token_replace($context['message'], $context);
$message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
- $message['body'][] = drupal_html_to_text($body);
+ $message['body'][] = $body;
}
function system_message_action_form($context) {
diff --git a/modules/user/user.module b/modules/user/user.module
index 2d400f54c..8e23ba165 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -2910,8 +2910,7 @@ function user_preferred_language($account, $default = NULL) {
* @param $language
* Optional language to use for the notification, overriding account language.
* @return
- * The return value from drupal_mail_sending_system()->mail(), if ends up
- * being called.
+ * The return value from drupal_mail_system()->mail(), if ends up being called.
*/
function _user_mail_notify($op, $account, $language = NULL) {
// By default, we always notify except for canceled and blocked.