From 5c000159c1ffb8cf1452840ad99aefef63046061 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 9 Feb 2020 15:51:43 +0100 Subject: [PATCH] FIX Mail smtps truncated if content has a line with single . --- htdocs/core/class/CMailFile.class.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index 2318cb90e19..f794c76bcac 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -205,7 +205,7 @@ class CMailFile if (empty($msg)) { dol_syslog("CMailFile::CMailfile: Try to send an email with empty body"); - $msg = '.'; // Avoid empty message (with empty message conten show a multipart structure) + $msg = '.'; // Avoid empty message (with empty message content, you will see a multipart structure) } // Detect if message is HTML (use fast method) @@ -227,7 +227,7 @@ class CMailFile //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current // Replace relative /viewimage to absolute path - $msg = preg_replace('/src="'.preg_quote(DOL_URL_ROOT, '/').'\/viewimage\.php/ims', 'src="'.$urlwithroot.'/viewimage.php', $msg, -1, $nbrep); + $msg = preg_replace('/src="'.preg_quote(DOL_URL_ROOT, '/').'\/viewimage\.php/ims', 'src="'.$urlwithroot.'/viewimage.php', $msg, -1); if (!empty($conf->global->MAIN_MAIL_FORCE_CONTENT_TYPE_TO_HTML)) $this->msgishtml = 1; // To force to send everything with content type html. @@ -349,6 +349,9 @@ class CMailFile $msg = $this->checkIfHTML($msg); } + // Replace . alone on a new line with .. to avoid to have SMTP interpret this as end of message + $msg = preg_replace('/(\r|\n)\.(\r|\n)/ims', '\1..\2', $msg); + if ($this->msgishtml) $smtps->setBodyContent($msg, 'html'); else $smtps->setBodyContent($msg, 'plain');