From f22ea7ba1875863890b486db3e5f448f99c1debc Mon Sep 17 00:00:00 2001 From: alecpl Date: Thu, 7 Oct 2010 08:52:05 +0000 Subject: - Support SMTP Delivery Status Notifications - RFC3461 (#1486142) --- program/include/rcube_smtp.php | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'program/include/rcube_smtp.php') diff --git a/program/include/rcube_smtp.php b/program/include/rcube_smtp.php index 61eebf3fa..5acc156c6 100644 --- a/program/include/rcube_smtp.php +++ b/program/include/rcube_smtp.php @@ -153,17 +153,16 @@ class rcube_smtp * each RFC822 valid. This may contain recipients not * specified in the headers, for Bcc:, resending * messages, etc. - * * @param mixed The message headers to send with the mail * Either as an associative array or a finally * formatted string - * * @param mixed The full text of the message body, including any Mime parts * or file handle + * @param array Delivery options (e.g. DSN request) * * @return bool Returns true on success, or false on error */ - public function send_mail($from, $recipients, &$headers, &$body) + public function send_mail($from, $recipients, &$headers, &$body, $opts=null) { if (!is_object($this->conn)) return false; @@ -183,7 +182,7 @@ class rcube_smtp else { $this->reset(); - $this->response[] .= "Invalid message headers"; + $this->response[] = "Invalid message headers"; return false; } @@ -191,10 +190,24 @@ class rcube_smtp if (!isset($from)) { $this->reset(); - $this->response[] .= "No From address has been provided"; + $this->response[] = "No From address has been provided"; return false; } + // RFC3461: Delivery Status Notification + if ($opts['dsn']) { + $exts = $this->conn->getServiceExtensions(); + + if (!isset($exts['DSN'])) { + $this->error = array('label' => 'smtpdsnerror'); + $this->response[] = "DSN not supported"; + return false; + } + + $from_params = 'RET=HDRS'; + $recipient_params = 'NOTIFY=SUCCESS,FAILURE'; + } + // RFC2298.3: remove envelope sender address if (preg_match('/Content-Type: multipart\/report/', $text_headers) && preg_match('/report-type=disposition-notification/', $text_headers) @@ -203,12 +216,12 @@ class rcube_smtp } // set From: address - if (PEAR::isError($this->conn->mailFrom($from))) + if (PEAR::isError($this->conn->mailFrom($from, $from_params))) { $err = $this->conn->getResponse(); $this->error = array('label' => 'smtpfromerror', 'vars' => array( 'from' => $from, 'code' => $this->conn->_code, 'msg' => $err[1])); - $this->response[] .= "Failed to set sender '$from'"; + $this->response[] = "Failed to set sender '$from'"; $this->reset(); return false; } @@ -225,11 +238,11 @@ class rcube_smtp // set mail recipients foreach ($recipients as $recipient) { - if (PEAR::isError($this->conn->rcptTo($recipient))) { + if (PEAR::isError($this->conn->rcptTo($recipient, $recipient_params))) { $err = $this->conn->getResponse(); $this->error = array('label' => 'smtptoerror', 'vars' => array( 'to' => $recipient, 'code' => $this->conn->_code, 'msg' => $err[1])); - $this->response[] .= "Failed to add recipient '$recipient'"; + $this->response[] = "Failed to add recipient '$recipient'"; $this->reset(); return false; } @@ -261,7 +274,7 @@ class rcube_smtp $msg = $result->getMessage(); $this->error = array('label' => 'smtperror', 'vars' => array('msg' => $msg)); - $this->response[] .= "Failed to send data"; + $this->response[] = "Failed to send data"; $this->reset(); return false; } -- cgit v1.2.3