2
0
forked from Wavyzz/dolibarr

Fix: If duplicate images are embedded, they may show up as attachments, so remove them.

This commit is contained in:
Regis Houssin
2009-05-18 07:30:53 +00:00
parent 364c247405
commit ef5c7f1caa
2 changed files with 45 additions and 33 deletions

View File

@@ -135,14 +135,19 @@ class simplemail {
function writeattachement(&$attachement,$B) {
$message = '';
$inline = array();
if ( !empty($attachement) ) {
foreach($attachement as $AttmFile){
$patharray = explode ("/", $AttmFile['filename']);
$FileName = $patharray[count($patharray)-1];
// If duplicate images are embedded, they may show up as attachments, so remove them.
if (!in_array($AttmFile['filename'],$inline))
{
$message .= "\n--".$B."\n";
if (!empty($AttmFile['cid'])) {
$inline[] = $AttmFile['filename'];
$message .= "Content-Type: {$AttmFile['contenttype']};\n name=\"".$FileName."\"\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-ID: <{$AttmFile['cid']}>\n";
@@ -161,6 +166,7 @@ class simplemail {
$message .= $FileContent;
$message .= "\n\n";
}
}
$message .= "\n--".$B."--\n";
}
return $message;

View File

@@ -895,15 +895,19 @@ class CMailFile
if (!empty($this->html_images))
{
// If duplicate images are embedded, they may show up as attachments, so remove them.
//$html_images = array_unique($this->html_images);
//sort($html_images);
$inline = array();
$i=0;
foreach ($this->html_images as $img)
{
// Read imahe file
if ($image = file_get_contents($images_dir.'/'.$img["name"]))
$fullpath = $images_dir.'/'.$img["name"];
// If duplicate images are embedded, they may show up as attachments, so remove them.
if (!in_array($fullpath,$inline))
{
// Read image file
if ($image = file_get_contents($fullpath))
{
// On garde que le nom de l'image
eregi('([A-Za-z0-9_-]+[.]?[A-Za-z0-9]+)?$',$img["name"],$regs);
@@ -914,6 +918,8 @@ class CMailFile
$this->images_encoded[$i]['cid'] = $img["cid"];
// Encodage de l'image
$this->images_encoded[$i]["image_encoded"] = chunk_split(base64_encode($image), 68, $this->eol);
$inline[] = $fullpath;
}
}
$i++;
}