? LICENSE.txt
Index: INSTALL.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/smtp/INSTALL.txt,v
retrieving revision 1.5
diff -u -r1.5 INSTALL.txt
--- INSTALL.txt	31 Dec 2006 15:53:00 -0000	1.5
+++ INSTALL.txt	15 Mar 2008 17:19:15 -0000
@@ -1,4 +1,4 @@
-// $Id: INSTALL.txt,v 1.5 2006/12/31 15:53:00 lukelast Exp $
+// $Id: INSTALL.txt,v 1.5.2.2 2007/12/03 16:39:03 oadaeh Exp $
 
 INSTALL INSTRUCTIONS FOR SMTP.MODULE
 ----
@@ -10,4 +10,4 @@
 5. Enjoy.
 
 Notes:
-This version of the module is designed for DRUPAL 5.0 only.
\ No newline at end of file
+This version of the module is designed for DRUPAL 6.0 only.
Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/smtp/README.txt,v
retrieving revision 1.9
diff -u -r1.9 README.txt
--- README.txt	15 Feb 2007 19:37:30 -0000	1.9
+++ README.txt	15 Mar 2008 17:18:57 -0000
@@ -1,6 +1,6 @@
-// $Id: README.txt,v 1.9 2007/02/15 19:37:30 lukelast Exp $
+// $Id: README.txt,v 1.9.2.2 2007/12/03 16:39:03 oadaeh Exp $
 
-SMTP MODULE for DRUPAL 5.0
+SMTP MODULE for DRUPAL 6.0
 This module adds SMTP functionality to Drupal.
 
 INSTALL INSTRUCTIONS
Index: smtp.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/smtp/smtp.info,v
retrieving revision 1.2
diff -u -r1.2 smtp.info
--- smtp.info	15 Feb 2007 19:37:03 -0000	1.2
+++ smtp.info	15 Mar 2008 16:49:53 -0000
@@ -1,4 +1,10 @@
-; $Id: smtp.info,v 1.2 2007/02/15 19:37:03 lukelast Exp $
+; $Id: smtp.info,v 1.2.2.2 2007/12/03 16:39:03 oadaeh Exp $
 name = SMTP
 description = Allows the sending of site email to an SMTP server.
-package = "Mail"
\ No newline at end of file
+package = "Mail"
+
+; Information added by drupal.org packaging script on 2008-03-08
+core = 6.x
+version = "6.x-1.x-dev"
+project = "smtp"
+datestamp = "1204935042"
\ No newline at end of file
Index: smtp.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/smtp/smtp.module,v
retrieving revision 1.15
diff -u -r1.15 smtp.module
--- smtp.module	28 May 2007 20:02:41 -0000	1.15
+++ smtp.module	15 Mar 2008 17:06:55 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: smtp.module,v 1.15 2007/05/28 20:02:41 lukelast Exp $
+// $Id $
 
 /**
  * @file
@@ -18,18 +18,15 @@
 /**
  * Implementation of hook_menu().
  */
-function smtp_menu($may_cache) {
-  $items = array();
-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'admin/settings/smtp',
-      'title' => t('SMTP support'),
-      'description' => t('Allows the sending of site email to an SMTP server of your choice.'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => 'smtp_admin_settings',
-      'type' => MENU_NORMAL_ITEM,
-    );
-  }
+function smtp_menu() {
+  $items['admin/settings/smtp'] = array(
+    'title' => 'SMTP support',
+    'description' => 'Allows the sending of site email to an SMTP server of your choice.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('smtp_admin_settings'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+
   return $items;
 }
 
@@ -83,10 +80,10 @@
   $form['server']['smtp_port'] = array(
     '#type' => 'textfield',
     '#title' => t('SMTP port'),
-    '#size' => 4,
-    '#maxlength' => 4,
+    '#size' => 6,
+    '#maxlength' => 6,
     '#default_value' => variable_get('smtp_port', '25'),
-    '#description' => t('The default SMTP port is 25, if that is being blocked try 80. Gmail uses 465.'));
+    '#description' => t('The default SMTP port is 25, if that is being blocked try 80. Gmail uses 465. See !url for more information on configuring for use with Gmail.', array('!url' => l(t('this page'), 'http://gmail.google.com/support/bin/answer.py?answer=13287'))));
   if (function_exists('openssl_open')){ //Only display the option if openssl is installed.
     $form['server']['smtp_protocol'] = array(
       '#type' => 'select',
@@ -97,6 +94,7 @@
   }
   else{ //If openssl is not installed use normal protocol.
     variable_set('smtp_protocol', 'standard');
+    $form['server']['smtp_protocol'] = array('#value' => t('Your PHP installation does not have SSL enabled. See the !url page on php.net for more information.', array('' => l(t('OpenSSL Functions'), 'http://php.net/openssl'))));
   }
   
   $form['auth'] = array('#type' => 'fieldset', '#title' => t('SMTP Authentication'), '#description' => t('Leave blank if your SMTP server does not require authentication.'));
@@ -112,6 +110,11 @@
     '#description' => t('SMTP password.'));
     
   $form['email_options'] = array('#type' => 'fieldset', '#title' => t('E-mail options'));
+  $form['email_options']['smtp_from'] = array(
+    '#type' => 'textfield',
+    '#title' => t('E-mail from'),
+    '#default_value' => variable_get('smtp_from', ''),
+    '#description' => t('The E-mail-address that all emails will be from.'));
   $form['email_options']['smtp_fromname'] = array(
     '#type' => 'textfield',
     '#title' => t('E-mail from Name'),
@@ -122,8 +125,8 @@
   $test_address = variable_get('smtp_test_address', '');
   if ($test_address != ''){
     variable_del('smtp_test_address'); //Clear the variable so only one message is sent.
-    drupal_mail('smtp-test', $test_address, t('Drupal test email'), t('If you receive this message it means your site is capable of sending email.'), variable_get('site_mail', ini_get('sendmail_from')));
-    drupal_set_message(t('A test E-mail has been sent to @email. You may want to !check for any error messages.', array('@email' => $test_address, '!check' => l(t('check the logs'), 'admin/logs/watchdog'))));
+    drupal_mail('smtp', 'test', $test_address, user_preferred_language($account));
+    drupal_set_message(t('A test E-mail has been sent to @email. You may want to !check for any error messages.', array('@email' => $test_address, '!check' => l(t('check the logs'), 'admin/reports/dblog'))));
   }
 
   $form['email_test'] = array('#type' => 'fieldset', '#title' => t('Send test E-mail'));
@@ -137,99 +140,172 @@
 }
 
 /**
+ * Implementation of hook_mail
+ */
+function smtp_mail($key, &$message, $params) {
+  $language = $message['language'];
+
+  switch($key) {
+    case 'test':
+      $message['subject'] = t('Drupal test email', array(), $language->language);
+      $message['body'] = t('If you receive this message it means your site is capable of sending email.', array(), $language->language);
+    break;
+  }
+}
+
+/**
  * Sends out the email.
  *
- * @param $mailkey
- *   A key to identify the mail sent, for altering.
- * @param $to
- *   string email address to send to.
- * @param $subject
- *   string subject of email.
- * @param $body
- *   string body of message.
- * @param $header
- *   string of header lines seperated by "\n".
+ * @param $message = array()
+ *   keys:
+ *     'id' - A unique identifier of the e-mail type.
+ *     'to' - The mail address or addresses where the message will be sent to.
+ *     'subject' - Subject of the e-mail to be sent.
+ *     'body' - Message to be sent.
+ *     'headers' - Associative array containing all mail headers.
  */
-function drupal_mail_wrapper($mailkey, $to, $subject, $body, $from, $header) {
-	$mail = new phpmailer(); //Create a new phpmailer object.
-	$username = variable_get('smtp_username', '');
-	$password = variable_get('smtp_password', '');
-	
-	//Set the default name emails should be from. If value is not defined in settings use site_name.
-	if (variable_get('smtp_fromname', '') != ''){
-    $from_name = variable_get('smtp_fromname', '');
-	}
-	else{
-	  $from_name = variable_get('site_name', '');
-	}
-
-	//Decide whether to use SMTP Authorization. Do so if username and password are given.
-	if ($username != '' and $password != '') {
-	  $auth = TRUE;
-	} else {
-	  $auth = FALSE;
-	}
-	
-	
-	//Take care of the email headers.
-  foreach ($header as $key => $value) {
-    //watchdog('error', 'Key: ' . $key . ' Value: ' . $value);
-    if (strtolower($key) == 'from') {
-      if ($from == NULL or $from == '') {
-        $from = $value; //If a from value was already given then set based on header.
-      }
+function drupal_mail_wrapper($message) {
+  $mail = new phpmailer(); //Create a new phpmailer object.
+  $username = variable_get('smtp_username', '');
+  $password = variable_get('smtp_password', '');
+  
+  //Set the default name emails should be from. If value is not defined in settings use site_name.
+  if (variable_get('smtp_fromname', '') != '') {
+      $from_name = variable_get('smtp_fromname', '');
+  }
+  else{
+    $from_name = variable_get('site_name', '');
+  }
+
+  //If from email address is blank use smtp_from config option
+  if(array_key_exists('from', $message['headers'])) {
+    if($message['headers']['from'] != '') {
+      $from = $message['headers']['from'];
     }
-    else if (strtolower($key) == 'content-type' and strtolower($value) == 'text/html') {
+    else {
+      $from = variable_get('smtp_from', '');
+    }
+  }
+  else {
+     $from = variable_get('smtp_from', '');
+   }
+    $from = variable_get('smtp_from', '');
+  }
+
+  //Decide whether to use SMTP Authorization. Do so if username and password are given.
+  if ($username != '' and $password != '') {
+    $auth = TRUE;
+  } else {
+    $auth = FALSE;
+  }
+  
+  //Take care of the email headers.
+  foreach ($message['headers'] as $name => $value) {
+    //watchdog('error', 'Key: ' . $name . ' Value: ' . $value);
+    if (strtolower($name) == 'content-type' && strpos(strtolower($value),'text/html') !== FALSE) {
+       $mail->IsHTML(TRUE);
+     }
+
       $mail->IsHTML(TRUE);
     }
+    else if (strtolower($name) == 'content-type' && strpos(strtolower($value), 'multipart/mixed') !== FALSE) {
+      //$body passed to smtp should already be formatted. add multipart header and tell phpmailer to leave it alone
+      $mail->AddCustomHeader($name . ": " . $value);
+      $mail->message_type = "pre";
+    }
+    else if (strtolower($name) == 'reply-to') {
+      // Only add a "reply-to" if it's not the same as "return-path".
+      if ($value != $header['Return-Path']) {
+        $mail->AddReplyTo($value);
+      }
+    }
+    else if (strtolower($name) == 'return-path') {
+      if (trim($value) !=  '') {
+        $mail->Sender = $value;
+      }
+    }
+    else if (strtolower($name) == 'content-transfer-encoding') {
+      $mail->Encoding = $value;
+    }
+    else if (strtolower($name) == 'mime-version') {
+      // just ommit MIME-Version it since it will be set by PHP-Mailer
+    }
+    else if (strtolower($name) == 'bcc') {
+      $bccrecipients = split(",", $value);
+      foreach ($bccrecipients as $bccrecipient) {
+        if ( strpos($bccrecipient, '<') !== false ) {
+          $bccparts = explode(" <", $bccrecipient);
+          $bccname = $bccparts[0];
+          $bccaddr = rtrim($bccparts[1], ">");
+        }
+        else {
+          $bccname = "";
+          $bccaddr = $bccrecipient;
+        }
+        $mail->AddBCC($bccaddr, $bccname);
+      }
+    }
     else { //Else the header key is not special, just add it.
-      $mail->AddCustomHeader($key . ": " . $value); //Add header line.
+      $mail->AddCustomHeader($name . ": " . $value); //Add header line.
     }
   }
 
-	//If no from address has been set than use a default.
-	if ($from == '' or $from == NULL){
+  //If no from address has been set than use a default.
+  if ($from == '' or $from == NULL){
     $from = variable_get('site_mail', 'test@example.com'); //If no from can be found use site_mail variable.
-	}
+  }
+  
+  //Set the correct protocol prefix to append to the smtp host.
+  switch(variable_get('smtp_protocol', 'standard')) {
+    case "ssl":
+      $mail->Protocol = 'ssl://';
+      break;
+    case "tls":
+      $mail->Protocol = 'tls://';
+      break;
+    case "standard":
+      $mail->Protocol = '';
+  }
+  
+  $mail->Host = variable_get('smtp_host', '') . ';' . variable_get('smtp_hostbackup', '');
+  $mail->Port = variable_get('smtp_port', '25');
+  $mail->Mailer = "smtp";
+  $mail->SMTPAuth = $auth;
+  $mail->Username = $username;
+  $mail->Password = $password;
+  $mail->CharSet = 'utf-8';
+  
+  $mail->From = $from;
+  $mail->FromName = $from_name;
+  
+  $torecipients = split(",", $message['to']);
+  foreach ($torecipients as $torecipient) {
+    if (strpos($torecipient, '<') !== false) {
+      $toparts = explode(" <", $torecipient);
+      $toname = $toparts[0];
+      $toaddr = rtrim($toparts[1], ">");
+    }
+    else {
+      $toname = "";
+      $toaddr = $torecipient;
+    }
+    $mail->AddAddress($toaddr, $toname);
+  }
 
-	//Set the correct protocol prefix to append to the smtp host.
-	switch(variable_get('smtp_protocol', 'standard')){
-	  case "ssl":
-	    $mail->Protocol = 'ssl://';
-	    break;
-	  case "tls":
-	    $mail->Protocol = 'tls://';
-	    break;
-	  case "standard":
-	    $mail->Protocol = '';
-	}
-	
-	$mail->Host = variable_get('smtp_host', '') . ';' . variable_get('smtp_hostbackup', '');
-	$mail->Port = variable_get('smtp_port', '25');
-	$mail->Mailer = "smtp";
-	$mail->SMTPAuth = $auth;
-	$mail->Username = $username;
-	$mail->Password = $password;
-	$mail->CharSet = 'utf-8';
-	
-	$mail->From = $from;
-	$mail->FromName = $from_name;
-	$mail->AddAddress($to);
-	$mail->Subject = $subject;
-	$mail->Body = $body;
-	
-	watchdog("error", "About to send email to: " . $to);
-
-	//Try to send email, if it fails set watchdog entry.
-	if(!$mail->Send()) {
-		watchdog("error", "Error sending email: \"" . $mail->ErrorInfo . "\" From: \"$from\" To: \"$to\"");
-		return false;
-	}
-	
-	$mail->SmtpClose();
-	return true;
-}
+  $mail->Subject = $message['subject'];
+  $mail->Body = $message['body'];
+  
+  watchdog('smtp', t('Sending mail to: !to', array('!to' => $message['to'])));
 
+  //Try to send email, if it fails set watchdog entry.
+  if(!$mail->Send()) {
+    watchdog("smtp", t('Error sending e-mail from !from to !to: ', array('!from' => $from, '!to' => $message['to'])) . $mail->ErrorInfo, NULL, WATCHDOG_ERROR);
+    return false;
+  }
+  
+  $mail->SmtpClose();
+  return true;
+}
 
 /**
  * PHPMailer language settings.  
@@ -265,6 +341,7 @@
  * Added "var $protocol = '';" to the smtp class variables.
  * After line "if($this->smtp == NULL) { $this->smtp = new SMTP(); }" Added "$this->smtp->protocol = $this->Protocol;"
  * Added "var $Protocol = '';" to the PHPMailer class variables.
+ * Added "pre" message_type to allow pass-through of pre-formated $body
  **************************************************************************************************/
 
 
@@ -465,6 +542,10 @@
 
     /**
      *  Sets SMTP class debugging on or off.
+     *
+     *  Set this to 'true' to get additional information for debugging
+     *  problems.
+     *
      *  @var bool
      */
     var $SMTPDebug    = false;
@@ -914,8 +995,19 @@
             $formatted = $addr[0];
         else
         {
-            $formatted = $this->EncodeHeader($addr[1], 'phrase') . " <" . 
-                         $addr[0] . ">";
+            // If the from address already contains a name and address, as indicated
+            // by the angle brackets, then ignore the FromName and simply use
+            // the From field as it was provided.  This allows per-call override
+            // of the From field when using the smtp module, important to modules
+            // such as OG
+            if(strpos($addr[0], "<") !== false && strpos($addr[0], ">") !== false)
+            {
+                $formatted = $addr[0];
+            }
+            else
+            {
+                $formatted = $this->EncodeHeader($addr[1], 'phrase') . " <" . $addr[0] . ">";
+            }
         }
 
         return $formatted;
@@ -1017,6 +1109,8 @@
            case "alt_attachments":
               $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
               break;
+           case "pre":
+              break;
            default:
               $this->Body = $this->WrapText($this->Body, $this->WordWrap);
               break;
@@ -1082,8 +1176,8 @@
         // Add custom headers
         for($index = 0; $index < count($this->CustomHeader); $index++)
         {
-            $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), 
-                       $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
+            $result .= ($this->CustomHeader[$index][0]) ? $this->HeaderLine(trim($this->CustomHeader[$index][0]),
+                       $this->EncodeHeader(trim($this->CustomHeader[$index][1]))) : '';
         }
         $result .= $this->HeaderLine("MIME-Version", "1.0");
 
@@ -1113,6 +1207,9 @@
                 $result .= $this->HeaderLine("Content-Type", "multipart/alternative;");
                 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
                 break;
+            case "pre":
+                // Content-Type header already added before passing to phpmailer(), leave it alone
+                break;
         }
 
         if($this->Mailer != "mail")
@@ -1181,6 +1278,8 @@
                 
                 $result .= $this->AttachAll();
                 break;
+            case "pre":
+                $result .= $this->Body;
         }
         if($this->IsError())
             $result = "";
@@ -1222,8 +1321,12 @@
      * @return void
      */
     function SetMessageType() {
-        if(count($this->attachment) < 1 && strlen($this->AltBody) < 1)
+        if ($this->message_type == "pre") {
+            return;
+        }
+        if (count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
             $this->message_type = "plain";
+        }
         else
         {
             if(count($this->attachment) > 0)
