Fix #17475 : Add of List-Unsubscribe in mass emailing

This commit is contained in:
lmarcouiller 2021-05-04 15:11:30 +02:00
parent 526235d020
commit 457a96bc34
2 changed files with 9 additions and 4 deletions

View File

@ -265,9 +265,10 @@ if (empty($reshook)) {
}
//$substitutionisok=true;
$moreinheader = '';
complete_substitutions_array($substitutionarray, $langs);
$newsubject = make_substitutions($subject, $substitutionarray);
$newmessage = make_substitutions($message, $substitutionarray);
$newmessage = make_substitutions($message, $substitutionarray, null, 0, $moreinheader);
$arr_file = array();
$arr_mime = array();
@ -285,7 +286,7 @@ if (empty($reshook)) {
// Mail making
$trackid = 'emailing-'.$obj->fk_mailing.'-'.$obj->rowid;
$mail = new CMailFile($newsubject, $sendto, $from, $newmessage, $arr_file, $arr_mime, $arr_name, '', '', 0, $msgishtml, $errorsto, $arr_css, $trackid, '', 'emailing');
$mail = new CMailFile($newsubject, $sendto, $from, $newmessage, $arr_file, $arr_mime, $arr_name, '', '', 0, $msgishtml, $errorsto, $arr_css, $trackid, $moreinheader, 'emailing');
if ($mail->error) {
$res = 0;

View File

@ -7206,10 +7206,11 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null,
* @param Translate $outputlangs Output language
* @param int $converttextinhtmlifnecessary 0=Convert only value into HTML if text is already in HTML
* 1=Will also convert initial $text into HTML if we try to insert one value that is HTML
* @param string $moreinheader Header for CMailer module
* @return string Output string after substitutions
* @see complete_substitutions_array(), getCommonSubstitutionArray()
*/
function make_substitutions($text, $substitutionarray, $outputlangs = null, $converttextinhtmlifnecessary = 0)
function make_substitutions($text, $substitutionarray, $outputlangs = null, $converttextinhtmlifnecessary = 0, &$moreinheader = null)
{
global $conf, $langs;
@ -7312,9 +7313,12 @@ function make_substitutions($text, $substitutionarray, $outputlangs = null, $con
} else {
$value = dol_nl2br("$value");
}
$text = str_replace("$key", "$value", $text); // We must keep the " to work when value is 123.5 for example
}
if ($key == '__UNSUBSCRIBE__' && (isset($moreinheader))) {
$tmptext = explode('"', $text);
$moreinheader = "List-Unsubscribe: <".$tmptext[1].">\n";
}
}
return $text;