]> git.donarmstrong.com Git - roundcube.git/blobdiff - program/include/rcube_smtp.php
Imported Upstream version 0.7
[roundcube.git] / program / include / rcube_smtp.php
index b3db9d22955d275d4c39df9b034ba4b47c80342e..8c668c0a4b03fb46f1a08d57051ba7783f262f96 100644 (file)
@@ -5,7 +5,7 @@
  | program/include/rcube_smtp.php                                        |
  |                                                                       |
  | This file is part of the Roundcube Webmail client                     |
- | Copyright (C) 2005-2010, Roundcube Dev. - Switzerland                 |
+ | Copyright (C) 2005-2010, The Roundcube Dev Team                       |
  | Licensed under the GNU GPL                                            |
  |                                                                       |
  | PURPOSE:                                                              |
@@ -15,7 +15,7 @@
  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
  +-----------------------------------------------------------------------+
 
- $Id: rcube_smtp.php 4123 2010-10-22 19:16:45Z alec $
+ $Id: rcube_smtp.php 5499 2011-11-28 09:03:27Z alec $
 
 */
 
@@ -101,11 +101,11 @@ class rcube_smtp
       $helo_host = 'localhost';
 
     // IDNA Support
-    $smtp_host = idn_to_ascii($smtp_host);
+    $smtp_host = rcube_idn_to_ascii($smtp_host);
 
     $this->conn = new Net_SMTP($smtp_host, $smtp_port, $helo_host);
 
-    if($RCMAIL->config->get('smtp_debug'))
+    if ($RCMAIL->config->get('smtp_debug'))
       $this->conn->setDebug(true, array($this, 'debug_handler'));
 
     // try to connect to server and exit on failure
@@ -118,6 +118,13 @@ class rcube_smtp
       return false;
     }
 
+    // workaround for timeout bug in Net_SMTP 1.5.[0-1] (#1487843)
+    if (method_exists($this->conn, 'setTimeout')
+      && ($timeout = ini_get('default_socket_timeout'))
+    ) {
+      $this->conn->setTimeout($timeout);
+    }
+
     $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'];
@@ -132,8 +139,9 @@ class rcube_smtp
     if ($smtp_user && $smtp_pass)
     {
       // IDNA Support
-      if (strpos($smtp_user, '@'))
-        $smtp_user = idn_to_ascii($smtp_user);
+      if (strpos($smtp_user, '@')) {
+        $smtp_user = rcube_idn_to_ascii($smtp_user);
+      }
 
       $result = $this->conn->auth($smtp_user, $smtp_pass, $smtp_auth_type, $use_tls, $smtp_authz);
 
@@ -206,14 +214,10 @@ class rcube_smtp
     if ($opts['dsn']) {
       $exts = $this->conn->getServiceExtensions();
 
-      if (!isset($exts['DSN'])) {
-        $this->error = array('label' => 'smtpdsnerror');
-        $this->response[] = "DSN not supported";
-        return false;
+      if (isset($exts['DSN'])) {
+        $from_params      = 'RET=HDRS';
+        $recipient_params = 'NOTIFY=SUCCESS,FAILURE';
       }
-
-      $from_params      = 'RET=HDRS';
-      $recipient_params = 'NOTIFY=SUCCESS,FAILURE';
     }
 
     // RFC2298.3: remove envelope sender address
@@ -377,7 +381,7 @@ class rcube_smtp
           $from = $addresses[0];
 
         // Reject envelope From: addresses with spaces.
-        if (strstr($from, ' '))
+        if (strpos($from, ' ') !== false)
           return false;
 
         $lines[] = $key . ': ' . $value;
@@ -431,14 +435,14 @@ class rcube_smtp
     // if we're passed an array, assume addresses are valid and implode them before parsing.
     if (is_array($recipients))
       $recipients = implode(', ', $recipients);
-    
+
     $addresses = array();
     $recipients = rcube_explode_quoted_string(',', $recipients);
 
     reset($recipients);
     while (list($k, $recipient) = each($recipients))
     {
-      $a = explode(" ", $recipient);
+      $a = rcube_explode_quoted_string(' ', $recipient);
       while (list($k2, $word) = each($a))
       {
         if (strpos($word, "@") > 0 && $word[strlen($word)-1] != '"')
@@ -449,6 +453,7 @@ class rcube_smtp
         }
       }
     }
+
     return $addresses;
   }