From 2d08c50fd78e8ae74f27a2418f7909b18ae2bf42 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Fri, 05 Mar 2010 04:47:32 -0500
Subject: [PATCH] - Support/Require tls:// prefix in 'smtp_server' option for TLS connections - "Split" config file into sections

---
 program/include/rcube_smtp.php |   39 +++++++++++++++++++++++++++------------
 1 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/program/include/rcube_smtp.php b/program/include/rcube_smtp.php
index 9253468..2bf8cc1 100644
--- a/program/include/rcube_smtp.php
+++ b/program/include/rcube_smtp.php
@@ -82,6 +82,12 @@
     if (isset($smtp_host_url['host']) && isset($smtp_host_url['scheme']))
       $smtp_host = sprintf('%s://%s', $smtp_host_url['scheme'], $smtp_host_url['host']);
 
+    // remove TLS prefix and set flag for use in Net_SMTP::auth()
+    if (preg_match('#^tls://#i', $smtp_host)) {
+      $smtp_host = preg_replace('#^tls://#i', '', $smtp_host);
+      $use_tls = true;
+    }
+
     if (!empty($CONFIG['smtp_helo_host']))
       $helo_host = $CONFIG['smtp_helo_host'];
     else if (!empty($_SERVER['SERVER_NAME']))
@@ -107,11 +113,12 @@
     $smtp_user = str_replace('%u', $_SESSION['username'], $CONFIG['smtp_user']);
     $smtp_pass = str_replace('%p', $RCMAIL->decrypt($_SESSION['password']), $CONFIG['smtp_pass']);
     $smtp_auth_type = empty($CONFIG['smtp_auth_type']) ? NULL : $CONFIG['smtp_auth_type'];
-      
+    
     // attempt to authenticate to the SMTP server
     if ($smtp_user && $smtp_pass)
     {
-      $result = $this->conn->auth($smtp_user, $smtp_pass, $smtp_auth_type);
+      $result = $this->conn->auth($smtp_user, $smtp_pass, $smtp_auth_type, $use_tls);
+
       if (PEAR::isError($result))
       {
         $this->error = array('label' => 'smtpautherror', 'vars' => array('code' => $this->conn->_code));
@@ -141,7 +148,8 @@
    *               Either as an associative array or a finally
    *               formatted string
    *
-   * @param string The full text of the message body, including any Mime parts, etc.
+   * @param mixed  The full text of the message body, including any Mime parts
+   *               or file handle
    *
    * @return bool  Returns true on success, or false on error
    */
@@ -206,17 +214,24 @@
       }
     }
 
-    // Concatenate headers and body so it can be passed by reference to SMTP_CONN->data
-    // so preg_replace in SMTP_CONN->quotedata will store a reference instead of a copy. 
-    // We are still forced to make another copy here for a couple ticks so we don't really 
-    // get to save a copy in the method call.
-    $data = $text_headers . "\r\n" . $body;
+    if (is_resource($body))
+    {
+      // file handle
+      $data = $body;
+      $text_headers = preg_replace('/[\r\n]+$/', '', $text_headers);
+    } else {
+      // Concatenate headers and body so it can be passed by reference to SMTP_CONN->data
+      // so preg_replace in SMTP_CONN->quotedata will store a reference instead of a copy. 
+      // We are still forced to make another copy here for a couple ticks so we don't really 
+      // get to save a copy in the method call.
+      $data = $text_headers . "\r\n" . $body;
 
-    // unset old vars to save data and so we can pass into SMTP_CONN->data by reference.
-    unset($text_headers, $body);
-   
+      // unset old vars to save data and so we can pass into SMTP_CONN->data by reference.
+      unset($text_headers, $body);
+    }
+
     // Send the message's headers and the body as SMTP data.
-    if (PEAR::isError($result = $this->conn->data($data)))
+    if (PEAR::isError($result = $this->conn->data($data, $text_headers)))
     {
       $this->error = array('label' => 'smtperror', 'vars' => array('msg' => $result->getMessage()));
       $this->response[] .= "Failed to send data";

--
Gitblit v1.9.1