Happy New Year
[squirrelmail.git] / class / deliver / Deliver_SMTP.class.php
index 2d15e500db0801d269e0d89b769c61423bf9c6c1..da7fdcdc8ada62756a913a79b12d1d95674e582b 100644 (file)
@@ -5,7 +5,7 @@
  *
  * SMTP delivery backend for the Deliver class.
  *
- * @copyright 1999-2021 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
@@ -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);