Index: index.php
===================================================================
RCS file: /cvs/drupal/drupal/index.php,v
retrieving revision 1.93
diff -u -F^f -r1.93 index.php
--- index.php	6 Apr 2007 13:27:20 -0000	1.93
+++ index.php	17 May 2007 03:48:50 -0000
@@ -11,7 +11,6 @@
 
 require_once './includes/bootstrap.inc';
 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
-
 $return = menu_execute_active_handler();
 
 // Menu status constants are integers; page content is a string.
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.641
diff -u -F^f -r1.641 common.inc
--- includes/common.inc	15 May 2007 20:19:47 -0000	1.641
+++ includes/common.inc	17 May 2007 03:48:50 -0000
@@ -2003,50 +2003,10 @@ function drupal_mail($mailkey, $to, $sub
   // Bundle up the variables into a structured array for altering.
   $message = array('#mail_id' => $mailkey, '#to' => $to, '#subject' => $subject, '#body' => $body, '#from' => $from, '#headers' => $headers);
   drupal_alter('mail', $message);
-  $mailkey = $message['#mail_id'];
-  $to = $message['#to'];
-  $subject = $message['#subject'];
-  $body = $message['#body'];
-  $from = $message['#from'];
-  $headers = $message['#headers'];
 
   // Allow for custom mail backend
-  if (variable_get('smtp_library', '') && file_exists(variable_get('smtp_library', ''))) {
-    include_once './' . variable_get('smtp_library', '');
-    return drupal_mail_wrapper($mailkey, $to, $subject, $body, $from, $headers);
-  }
-  else {
-    /*
-    ** Note: if you are having problems with sending mail, or mails look wrong
-    ** when they are received you may have to modify the str_replace to suit
-    ** your systems.
-    **  - \r\n will work under dos and windows.
-    **  - \n will work for linux, unix and BSDs.
-    **  - \r will work for macs.
-    **
-    ** According to RFC 2646, it's quite rude to not wrap your e-mails:
-    **
-    ** "The Text/Plain media type is the lowest common denominator of
-    ** Internet e-mail, with lines of no more than 997 characters (by
-    ** convention usually no more than 80), and where the CRLF sequence
-    ** represents a line break [MIME-IMT]."
-    **
-    ** CRLF === \r\n
-    **
-    ** http://www.rfc-editor.org/rfc/rfc2646.txt
-    **
-    */
-    $mimeheaders = array();
-    foreach ($headers as $name => $value) {
-      $mimeheaders[] = $name .': '. mime_header_encode($value);
-    }
-    return mail(
-      $to,
-      mime_header_encode($subject),
-      str_replace("\r", '', $body),
-      join("\n", $mimeheaders)
-    );
-  }
+  $engine = variable_get('mail_engine', 'system') .'_mailengine';
+  return $engine('send', $message, $mailkey);
 }
 
 /**
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.477
diff -u -F^f -r1.477 system.module
--- modules/system/system.module	16 May 2007 13:45:16 -0000	1.477
+++ modules/system/system.module	17 May 2007 03:48:51 -0000
@@ -272,6 +272,12 @@ function system_menu() {
     'page callback' => 'drupal_get_form',
     'page arguments' => array('system_image_toolkit_settings'),
   );
+  $items['admin/settings/mail'] = array(
+    'title' => t('Mail'),
+    'description' => t('E-mail settings.'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('system_mail_settings'),
+  );
   $items['admin/content/rss-publishing'] = array(
     'title' => 'RSS publishing',
     'description' => 'Configure the number of items per feed and whether feeds should be titles/teasers/full-text.',
@@ -595,13 +601,6 @@ function system_site_information_setting
     '#description' => t('The name of this website.'),
     '#required' => TRUE
   );
-  $form['site_mail'] = array(
-    '#type' => 'textfield',
-    '#title' => t('E-mail address'),
-    '#default_value' => variable_get('site_mail', ini_get('sendmail_from')),
-    '#description' => t('A valid e-mail address to be used as the "From" address by the auto-mailer during registration, new password requests, notifications, etc.  To lessen the likelihood of e-mail being marked as spam, this e-mail address should use the same domain as the website.'),
-    '#required' => TRUE,
-  );
   $form['site_slogan'] = array(
     '#type' => 'textfield',
     '#title' => t('Slogan'),
@@ -811,6 +810,45 @@ function system_image_toolkit_settings()
   return system_settings_form($form);
 }
 
+function system_mail_settings() {
+  $form['site_mail'] = array(
+    '#type' => 'textfield',
+    '#title' => t('E-mail address'),
+    '#default_value' => variable_get('site_mail', ini_get('sendmail_from')),
+    '#description' => t('A valid e-mail address to be used as the "From" address by the auto-mailer during registration, new password requests, notifications, etc.  To lessen the likelihood of e-mail being marked as spam, this e-mail address should use the same domain as the website.'),
+    '#required' => TRUE,
+  );
+
+  $mail_engines = array();
+  foreach (module_implements('mailengine') as $engine) {
+    $mail_engines[$engine] = array(
+      '#type' => 'radio',
+      '#name' => 'mail_engine',
+      '#return_value' => $engine,
+      '#value' => ($engine == variable_get('mail_engine', 'system')),
+      '#title' => module_invoke($engine, 'mailengine', 'name'),
+      '#description' => module_invoke($engine, 'mailengine', 'description'),
+    );
+  }
+
+  if (count($mail_engines) > 1) {
+    $form['mail_engine'] = array(
+      '#type' => 'radios',
+      '#title' => t('E-mail engine'),
+      '#description' => t('Choose an e-mail engine for sending mails from your site.'),
+      '#default_value' => variable_get('mail_engine', 'system'),
+      $mail_engines,
+    );
+  }
+  else {
+    // Use the system module's default mail engine.
+    $form['mail_engine'] = array('#type' => 'value', '#value' => 'system');
+  }
+
+  $form['mail_settings'] = module_invoke(variable_get('mail_engine', 'system'), 'mailengine', 'settings');
+  return system_settings_form($form);
+}
+
 function system_rss_feeds_settings() {
 
   $form['feed_default_items'] = array(
@@ -2337,6 +2375,56 @@ function system_node_type($op, $info) {
 }
 
 /**
+ * Implementation of hook_mailengine().
+ *
+ * Delivers messages for drupal_mail() using PHP's mail().
+ */
+function system_mailengine($op, $message = NULL, $mailkey = NULL) {
+  switch ($op) {
+    case 'name':
+      return t('Drupal Mail');
+
+    case 'description':
+      return t("Default mailing engine using mail().");
+
+    case 'settings':
+      return FALSE;
+
+    case 'send':
+      /*
+      ** Note: if you are having problems with sending mail, or mails look wrong
+      ** when they are received you may have to modify the str_replace to suit
+      ** your systems.
+      **  - \r\n will work under dos and windows.
+      **  - \n will work for linux, unix and BSDs.
+      **  - \r will work for macs.
+      **
+      ** According to RFC 2646, it's quite rude to not wrap your e-mails:
+      **
+      ** "The Text/Plain media type is the lowest common denominator of
+      ** Internet e-mail, with lines of no more than 997 characters (by
+      ** convention usually no more than 80), and where the CRLF sequence
+      ** represents a line break [MIME-IMT]."
+      **
+      ** CRLF === \r\n
+      **
+      ** http://www.rfc-editor.org/rfc/rfc2646.txt
+      **
+      */
+      $mimeheaders = array();
+      foreach ($message['#headers'] as $name => $value) {
+        $mimeheaders[] = $name .': '. mime_header_encode($value);
+      }
+      return mail(
+        $message['#to'],
+        mime_header_encode($message['#subject']),
+        str_replace("\r", '', $message['#body']),
+        join("\n", $mimeheaders)
+      );
+  }
+}
+
+/**
  * Output a confirmation form
  *
  * This function returns a complete form for confirming an action. A link is
