Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.646
diff -u -F^f -r1.646 common.inc
--- includes/common.inc	27 May 2007 20:31:13 -0000	1.646
+++ includes/common.inc	29 May 2007 04:15:58 -0000
@@ -2011,50 +2011,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.484
diff -u -F^f -r1.484 system.module
--- modules/system/system.module	28 May 2007 06:08:44 -0000	1.484
+++ modules/system/system.module	29 May 2007 04:15:59 -0000
@@ -275,6 +275,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.',
@@ -549,13 +555,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'),
@@ -778,6 +777,27 @@ 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,
+  );
+
+  // modules which implement a mailengine are expected to use hook_form_alter to inject themselves into this form element.
+  $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'),
+    '#options' => array('system' => t('Standard mailing engine using mail(). Sends e-mail immediately.'))
+  );
+
+  return system_settings_form($form);
+}
+
 function system_rss_feeds_settings() {
 
   $form['feed_default_items'] = array(
@@ -2359,6 +2379,47 @@ 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 '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
