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,31 +135,37 @@ class simplemail {
function writeattachement(&$attachement,$B) { function writeattachement(&$attachement,$B) {
$message = ''; $message = '';
$inline = array();
if ( !empty($attachement) ) { if ( !empty($attachement) ) {
foreach($attachement as $AttmFile){ foreach($attachement as $AttmFile){
$patharray = explode ("/", $AttmFile['filename']); $patharray = explode ("/", $AttmFile['filename']);
$FileName = $patharray[count($patharray)-1]; $FileName = $patharray[count($patharray)-1];
$message .= "\n--".$B."\n"; // If duplicate images are embedded, they may show up as attachments, so remove them.
if (!in_array($AttmFile['filename'],$inline))
if (!empty($AttmFile['cid'])) { {
$message .= "Content-Type: {$AttmFile['contenttype']};\n name=\"".$FileName."\"\n"; $message .= "\n--".$B."\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-ID: <{$AttmFile['cid']}>\n"; if (!empty($AttmFile['cid'])) {
$message .= "Content-Disposition: inline;\n filename=\"".$FileName."\"\n\n"; $inline[] = $AttmFile['filename'];
} else { $message .= "Content-Type: {$AttmFile['contenttype']};\n name=\"".$FileName."\"\n";
$message .= "Content-Type: application/octetstream;\n name=\"".$FileName."\"\n"; $message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-Transfer-Encoding: base64\n"; $message .= "Content-ID: <{$AttmFile['cid']}>\n";
$message .= "Content-Disposition: attachment;\n filename=\"".$FileName."\"\n\n"; $message .= "Content-Disposition: inline;\n filename=\"".$FileName."\"\n\n";
} else {
$message .= "Content-Type: application/octetstream;\n name=\"".$FileName."\"\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-Disposition: attachment;\n filename=\"".$FileName."\"\n\n";
}
$fd=fopen ($AttmFile['filename'], "rb");
$FileContent=fread($fd,filesize($AttmFile['filename']));
fclose ($fd);
$FileContent = chunk_split(base64_encode($FileContent));
$message .= $FileContent;
$message .= "\n\n";
} }
$fd=fopen ($AttmFile['filename'], "rb");
$FileContent=fread($fd,filesize($AttmFile['filename']));
fclose ($fd);
$FileContent = chunk_split(base64_encode($FileContent));
$message .= $FileContent;
$message .= "\n\n";
} }
$message .= "\n--".$B."--\n"; $message .= "\n--".$B."--\n";
} }

View File

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