From 75667833feb0618541b889f63a98f2f4977ebd84 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 14 Nov 2019 10:01:05 +0100 Subject: [PATCH] Fix missing ->msgid --- htdocs/core/class/CMailFile.class.php | 20 ++++++++++++++------ htdocs/core/class/smtps.class.php | 7 ------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index 22ba7b66ec8..335c1b50111 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -78,6 +78,7 @@ class CMailFile //! Defined background directly in body tag public $bodyCSS; + public $msgid; public $headers; public $message; /** @@ -263,7 +264,8 @@ class CMailFile // Add autocopy to (Note: Adding bcc for specific modules are also done from pages) if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) $addr_bcc .= ($addr_bcc ? ', ' : '').$conf->global->MAIN_MAIL_AUTOCOPY_TO; - // Action according to choosed sending method + // We set all data according to choosed sending method. + // We also set a value for ->msgid if ($this->sendmode == 'mail') { // Use mail php function (default PHP method) @@ -274,7 +276,7 @@ class CMailFile $text_body = ""; $files_encoded = ""; - // Define smtp_headers + // Define smtp_headers (this also set ->msgid) $smtp_headers = $this->write_smtpheaders(); if (!empty($moreinheader)) $smtp_headers .= $moreinheader; // $moreinheader contains the \r\n @@ -365,6 +367,9 @@ class CMailFile $smtps->setErrorsTo($errors_to); $smtps->setDeliveryReceipt($deliveryreceipt); + $host=dol_getprefix('email'); + $this->msgid = time() . '.SMTPs-dolibarr-'.$trackid.'@' . $host; + $this->smtps = $smtps; } elseif ($this->sendmode == 'swiftmailer') @@ -386,7 +391,8 @@ class CMailFile // Adding a trackid header to a message $headers = $this->message->getHeaders(); $headers->addTextHeader('X-Dolibarr-TRACKID', $trackid.'@'.$host); - $headerID = time().'.swiftmailer-dolibarr-'.$trackid.'@'.$host; + $this->msgid = time().'.swiftmailer-dolibarr-'.$trackid.'@'.$host; + $headerID = $this->msgid; $msgid = $headers->get('Message-ID'); $msgid->setId($headerID); $headers->addIdHeader('References', $headerID); @@ -1038,13 +1044,15 @@ class CMailFile if ($trackid) { // References is kept in response and Message-ID is returned into In-Reply-To: - $out .= 'Message-ID: <'.time().'.phpmail-dolibarr-'.$trackid.'@'.$host.">".$this->eol2; // Uppercase seems replaced by phpmail - $out .= 'References: <'.time().'.phpmail-dolibarr-'.$trackid.'@'.$host.">".$this->eol2; + $this->msgid = time().'.phpmail-dolibarr-'.$trackid.'@'.$host; + $out .= 'Message-ID: <'.$this->msgid.">".$this->eol2; // Uppercase seems replaced by phpmail + $out .= 'References: <'.$this->msgid.">".$this->eol2; $out .= 'X-Dolibarr-TRACKID: '.$trackid.'@'.$host.$this->eol2; } else { - $out .= 'Message-ID: <'.time().'.phpmail@'.$host.">".$this->eol2; + $this->msgid = time().'.phpmail@'.$host; + $out .= 'Message-ID: <'.$this->msgid.">".$this->eol2; } if (!empty($_SERVER['REMOTE_ADDR'])) $out .= "X-RemoteAddr: ".$_SERVER['REMOTE_ADDR'].$this->eol2; diff --git a/htdocs/core/class/smtps.class.php b/htdocs/core/class/smtps.class.php index 5c5975b9284..9eebf9091b2 100644 --- a/htdocs/core/class/smtps.class.php +++ b/htdocs/core/class/smtps.class.php @@ -1304,13 +1304,6 @@ class SMTPs $_header .= 'Bcc: ' . $this->getBCC() . "\r\n"; */ - $host=$this->getHost(); - $usetls = preg_match('@tls://@i', $host); - - $host=preg_replace('@tcp://@i', '', $host); // Remove prefix - $host=preg_replace('@ssl://@i', '', $host); // Remove prefix - $host=preg_replace('@tls://@i', '', $host); // Remove prefix - $host=dol_getprefix('email'); //NOTE: Message-ID should probably contain the username of the user who sent the msg