diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index 5ae6b7c9e58..443444859eb 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -203,9 +203,9 @@ if (empty($reshook)) { $thirdpartystatic = new Societe($db); // Loop on each email and send it - $i = 0; + $iforemailloop = 0; - while ($i < $num && $i < $conf->global->MAILING_LIMIT_SENDBYWEB) { + while ($iforemailloop < $num && $iforemailloop < $conf->global->MAILING_LIMIT_SENDBYWEB) { // Here code is common with same loop ino mailing-send.php $res = 1; $now = dol_now(); @@ -367,7 +367,7 @@ if (empty($reshook)) { // Mail successful $nbok++; - dol_syslog("comm/mailing/card.php: ok for #".$i.($mail->error ? ' - '.$mail->error : ''), LOG_DEBUG); + dol_syslog("comm/mailing/card.php: ok for #".$iforemailloop.($mail->error ? ' - '.$mail->error : ''), LOG_DEBUG); $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles"; $sql .= " SET statut=1, date_envoi = '".$db->idate($now)."' WHERE rowid=".((int) $obj->rowid); @@ -406,7 +406,7 @@ if (empty($reshook)) { // Mail failed $nbko++; - dol_syslog("comm/mailing/card.php: error for #".$i.($mail->error ? ' - '.$mail->error : ''), LOG_WARNING); + dol_syslog("comm/mailing/card.php: error for #".$iforemailloop.($mail->error ? ' - '.$mail->error : ''), LOG_WARNING); $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles"; $sql .= " SET statut=-1, error_text='".$db->escape($mail->error)."', date_envoi='".$db->idate($now)."' WHERE rowid=".((int) $obj->rowid); @@ -416,7 +416,7 @@ if (empty($reshook)) { } } - $i++; + $iforemailloop++; } } else { setEventMessages($langs->transnoentitiesnoconv("NoMoreRecipientToSendTo"), null, 'mesgs'); diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index 4b147de05ba..216059a62c2 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -256,12 +256,14 @@ class CMailFile $this->html = $msg; $findimg = 0; - if (!empty($conf->global->MAIN_MAIL_ADD_INLINE_IMAGES_IF_IN_MEDIAS)) { + if (!empty($conf->global->MAIN_MAIL_ADD_INLINE_IMAGES_IF_IN_MEDIAS)) { // Off by default // Search into the body for image_types[$ext]; } // cid - $this->html_images[$i]["cid"] = dol_hash(uniqid(time()), 3); // Force md5 hash (does not contains special chars) + $this->html_images[$i]["cid"] = dol_hash($this->html_images[$i]["fullpath"], 'md5'); // Force md5 hash (does not contains special chars) // type $this->html_images[$i]["type"] = 'cidfromurl'; @@ -1805,17 +1807,22 @@ class CMailFile foreach ($matches[1] as $key => $ext) { // We save the image to send in disk $filecontent = $matches[2][$key]; - $cid = 'cid000'.dol_hash($this->html, 'md5'); // The id must not change if image is same + + $cid = 'cid000'.dol_hash($filecontent, 'md5'); // The id must not change if image is same + $destfiletmp = $images_dir.'/'.$cid.'.'.$ext; - $fhandle = @fopen($destfiletmp, 'w'); - if ($fhandle) { - $nbofbyteswrote = fwrite($fhandle, base64_decode($filecontent)); - fclose($fhandle); - dolChmod($destfiletmp); - } else { - $this->errors[] = "Failed to open file '".$destfiletmp."' for write"; - return -1; + if (!dol_is_file($destfiletmp)) { // If file does not exist yet (this is the case for the first email sent with a data:image inside) + dol_syslog("write the cid file ".$destfiletmp); + $fhandle = @fopen($destfiletmp, 'w'); + if ($fhandle) { + $nbofbyteswrote = fwrite($fhandle, base64_decode($filecontent)); + fclose($fhandle); + dolChmod($destfiletmp); + } else { + $this->errors[] = "Failed to open file '".$destfiletmp."' for write"; + return -1; + } } if (file_exists($destfiletmp)) { diff --git a/htdocs/langs/en_US/mails.lang b/htdocs/langs/en_US/mails.lang index 4d98f0e7f49..0414854a3f4 100644 --- a/htdocs/langs/en_US/mails.lang +++ b/htdocs/langs/en_US/mails.lang @@ -179,3 +179,4 @@ RecordCreatedByEmailCollector=Record created by the Email Collector %s from emai DefaultBlacklistMailingStatus=Default value for field '%s' when creating a new contact DefaultStatusEmptyMandatory=Empty but mandatory WarningLimitSendByDay=WARNING: The setup or contract of your instance limits your number of emails per day to %s. Trying to send more may result in having your instance slow down or suspended. Please contact your support if you need a higher quota. +NoMoreRecipientToSendTo=No more recipient to send the email to \ No newline at end of file