Happy New Year
[squirrelmail.git] / class / deliver / Deliver_SMTP.class.php
index 90c90c0052cae54cbd8d8dba44266223369570de..da7fdcdc8ada62756a913a79b12d1d95674e582b 100644 (file)
@@ -5,7 +5,7 @@
  *
  * SMTP delivery backend for the Deliver class.
  *
- * @copyright 1999-2015 The SquirrelMail Project Team
+ * @copyright 1999-2024 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
@@ -57,7 +57,7 @@ class Deliver_SMTP extends Deliver {
 
     function preWriteToStream(&$s) {
         if ($s) {
-            if ($s{0} == '.')   $s = '.' . $s;
+            if ($s[0] == '.')   $s = '.' . $s;
             $s = str_replace("\n.","\n..",$s);
         }
     }
@@ -66,7 +66,7 @@ class Deliver_SMTP extends Deliver {
         global $use_smtp_tls,$smtp_auth_mech;
 
         if ($authpop) {
-            $this->authPop($pop_host, '', $user, $pass);
+            $this->authPop($user, $pass, $pop_host, '');
         }
 
         $rfc822_header = $message->rfc822_header;
@@ -163,7 +163,7 @@ class Deliver_SMTP extends Deliver {
         $tmp = $this->parse_ehlo_response($stream);
         if ($this->errorCheck($tmp,$stream)) {
             // fall back to HELO if EHLO is not supported (error 5xx)
-            if ($this->dlv_ret_nr{0} == '5') {
+            if ($this->dlv_ret_nr[0] == '5') {
                 fputs($stream, "HELO $helohost\r\n");
                 $tmp = fgets($stream,1024);
                 if ($this->errorCheck($tmp,$stream)) {
@@ -346,7 +346,18 @@ class Deliver_SMTP extends Deliver {
         for ($i = 0, $cnt = count($to); $i < $cnt; $i++) {
             if (!$to[$i]->host) $to[$i]->host = $domain;
             if (strlen($to[$i]->mailbox)) {
-                fputs($stream, 'RCPT TO:<'.$to[$i]->mailbox.'@'.$to[$i]->host.">\r\n");
+                // Ask for DSN if user has requested such and remote server supports it
+                if (isset($rfc822_header->dsn) && $rfc822_header->dsn
+                 && array_key_exists('DSN',$this->ehlo)) {
+                    // TODO: Make the DSN parameters configurable by admin? user?
+                    fputs($stream, 'RCPT TO:<'.$to[$i]->mailbox.'@'.$to[$i]->host."> NOTIFY=SUCCESS,DELAY,FAILURE\r\n");
+                    // Retry without DSN fields for cranky MTAs
+                    if ($this->errorCheck($tmp, $stream)) {
+                        fputs($stream, 'RCPT TO:<'.$to[$i]->mailbox.'@'.$to[$i]->host.">\r\n");
+                    }
+                }
+                else
+                    fputs($stream, 'RCPT TO:<'.$to[$i]->mailbox.'@'.$to[$i]->host.">\r\n");
                 $tmp = fgets($stream, 1024);
                 if ($this->errorCheck($tmp, $stream)) {
                     return(0);
@@ -357,7 +368,18 @@ class Deliver_SMTP extends Deliver {
         for ($i = 0, $cnt = count($cc); $i < $cnt; $i++) {
             if (!$cc[$i]->host) $cc[$i]->host = $domain;
             if (strlen($cc[$i]->mailbox)) {
-                fputs($stream, 'RCPT TO:<'.$cc[$i]->mailbox.'@'.$cc[$i]->host.">\r\n");
+                // Ask for DSN if user has requested such and remote server supports it
+                if (isset($rfc822_header->dsn) && $rfc822_header->dsn
+                 && array_key_exists('DSN',$this->ehlo)) {
+                    // TODO: Make the DSN parameters configurable by admin? user?
+                    fputs($stream, 'RCPT TO:<'.$cc[$i]->mailbox.'@'.$cc[$i]->host."> NOTIFY=SUCCESS,DELAY,FAILURE\r\n");
+                    // Retry without DSN fields for cranky MTAs
+                    if ($this->errorCheck($tmp, $stream)) {
+                        fputs($stream, 'RCPT TO:<'.$cc[$i]->mailbox.'@'.$cc[$i]->host.">\r\n");
+                    }
+                }
+                else
+                    fputs($stream, 'RCPT TO:<'.$cc[$i]->mailbox.'@'.$cc[$i]->host.">\r\n");
                 $tmp = fgets($stream, 1024);
                 if ($this->errorCheck($tmp, $stream)) {
                     return(0);
@@ -368,7 +390,18 @@ class Deliver_SMTP extends Deliver {
         for ($i = 0, $cnt = count($bcc); $i < $cnt; $i++) {
             if (!$bcc[$i]->host) $bcc[$i]->host = $domain;
             if (strlen($bcc[$i]->mailbox)) {
-                fputs($stream, 'RCPT TO:<'.$bcc[$i]->mailbox.'@'.$bcc[$i]->host.">\r\n");
+                // Ask for DSN if user has requested such and remote server supports it
+                if (isset($rfc822_header->dsn) && $rfc822_header->dsn
+                 && array_key_exists('DSN',$this->ehlo)) {
+                    // TODO: Make the DSN parameters configurable by admin? user?
+                    fputs($stream, 'RCPT TO:<'.$bcc[$i]->mailbox.'@'.$bcc[$i]->host."> NOTIFY=SUCCESS,DELAY,FAILURE\r\n");
+                    // Retry without DSN fields for cranky MTAs
+                    if ($this->errorCheck($tmp, $stream)) {
+                        fputs($stream, 'RCPT TO:<'.$bcc[$i]->mailbox.'@'.$bcc[$i]->host.">\r\n");
+                    }
+                }
+                else
+                    fputs($stream, 'RCPT TO:<'.$bcc[$i]->mailbox.'@'.$bcc[$i]->host.">\r\n");
                 $tmp = fgets($stream, 1024);
                 if ($this->errorCheck($tmp, $stream)) {
                     return(0);
@@ -408,7 +441,7 @@ class Deliver_SMTP extends Deliver {
             $server_msg .= substr($line, 4);
         }
 
-        if ( ((int) $err_num{0}) < 4) {
+        if ( ((int) $err_num[0]) < 4) {
             return false;
         }
 
@@ -463,7 +496,7 @@ class Deliver_SMTP extends Deliver {
         return true;
     }
 
-    function authPop($pop_server='', $pop_port='', $user, $pass) {
+    function authPop($user, $pass, $pop_server='', $pop_port='') {
         if (!$pop_port) {
             $pop_port = 110;
         }