Add proper RFC 3461 DSN functionality (previously we relied only on the Return-Receip...
authorpdontthink <pdontthink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Wed, 13 Apr 2022 22:41:54 +0000 (22:41 +0000)
committerpdontthink <pdontthink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Wed, 13 Apr 2022 22:41:54 +0000 (22:41 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@14947 7612ce4b-ef26-0410-bec9-ea0150e637f0

class/deliver/Deliver_SMTP.class.php

index 7016a58cbab8eabe928e0a2b97c6637a52989683..90075ccbc8061b26f4dace7b0f547b9ebd2507f1 100644 (file)
@@ -346,7 +346,17 @@ 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 ($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 +367,17 @@ 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 ($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 +388,17 @@ 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 ($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);