2
0
forked from Wavyzz/dolibarr

Add: possibilit d'uploader une image et de l'envoyer dans un mailing (finalis et fonctionnel)

This commit is contained in:
Regis Houssin
2009-05-10 15:49:44 +00:00
parent a8abdefd71
commit 089c327923

View File

@@ -143,12 +143,6 @@ class CMailFile
// On defini mime_boundary // On defini mime_boundary
$this->mime_boundary = md5(uniqid("dolibarr")); $this->mime_boundary = md5(uniqid("dolibarr"));
// On defini image_boundary
$this->image_boundary = md5(uniqid(time()));
// On defini alternative_boundary
$this->alternative_boundary = md5(uniqid(time()));
// On definit fin de ligne // On definit fin de ligne
$this->eol="\n"; $this->eol="\n";
@@ -161,7 +155,7 @@ class CMailFile
$text_encoded = ""; $text_encoded = "";
// En-tete dans $smtp_headers // En-tete dans $smtp_headers
$this->subject = $subject; $this->subject = utf8_decode($subject);
$this->addr_from = $from; $this->addr_from = $from;
$this->errors_to = $errors_to; $this->errors_to = $errors_to;
$this->addr_to = $to; $this->addr_to = $to;
@@ -460,18 +454,22 @@ class CMailFile
if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $out .= "Disposition-Notification-To: ".getValidAddress($this->addr_from,2).$this->eol; if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $out .= "Disposition-Notification-To: ".getValidAddress($this->addr_from,2).$this->eol;
//$out .= "X-Priority: 3".$this->eol; //$out .= "X-Priority: 3".$this->eol;
$out .= "X-Mailer: Dolibarr version " . DOL_VERSION ." (using php mail)".$this->eol; $out.= "X-Mailer: Dolibarr version " . DOL_VERSION ." (using php mail)".$this->eol;
$out .= "MIME-Version: 1.0".$this->eol; $out.= "MIME-Version: 1.0".$this->eol;
if ($this->msgishtml) if ($this->atleastoneimage)
{ {
$out.= "Content-Type: multipart/alternative; boundary=\"".$this->alternative_boundary."\"".$this->eol; if (! $this->atleastonefile) $out.= "Content-Type: multipart/related; boundary=\"".$this->mime_boundary."\"".$this->eol;
if (! $this->atleastonefile) $out.= "Content-Type: text/html; charset=".$conf->file->character_set_client.$this->eol; $out.= "Content-Transfer-Encoding: 8bit".$this->eol;
}
else if ($this->msgishtml)
{
if (! $this->atleastonefile) $out.= "Content-Type: text/html; boundary=\"".$this->mime_boundary."\"".$this->eol;
$out.= "Content-Transfer-Encoding: 8bit".$this->eol; $out.= "Content-Transfer-Encoding: 8bit".$this->eol;
} }
else else
{ {
if (! $this->atleastonefile) $out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol; if (! $this->atleastonefile) $out.= "Content-Type: text/plain; boundary=\"".$this->mime_boundary."\"".$this->eol;
$out.= "Content-Transfer-Encoding: 8bit".$this->eol; $out.= "Content-Transfer-Encoding: 8bit".$this->eol;
} }
@@ -507,11 +505,6 @@ class CMailFile
} }
} }
if ($this->atleastoneimage)
{
$out.= "Content-Type: multipart/related; boundary=\"".$this->image_boundary."\"".$this->eol;
}
//$out.= $this->eol; //$out.= $this->eol;
dol_syslog("CMailFile::write_mimeheaders mime_header=\n".$out, LOG_DEBUG); dol_syslog("CMailFile::write_mimeheaders mime_header=\n".$out, LOG_DEBUG);
return $out; return $out;
@@ -532,7 +525,7 @@ class CMailFile
{ {
if ($this->msgishtml) if ($this->msgishtml)
{ {
$out.= "--" . $this->alternative_boundary . $this->eol; $out.= "--" . $this->mime_boundary . $this->eol;
$out.= "Content-Type: text/html; charset=".$conf->file->character_set_client.$this->eol; $out.= "Content-Type: text/html; charset=".$conf->file->character_set_client.$this->eol;
} }
else else
@@ -551,12 +544,17 @@ class CMailFile
if (! $htmlalreadyinmsg) $out .= "<html><head><title></title></head><body>"; if (! $htmlalreadyinmsg) $out .= "<html><head><title></title></head><body>";
$out.= $msgtext; $out.= $msgtext;
if (! $htmlalreadyinmsg) $out .= "</body></html>"; if (! $htmlalreadyinmsg) $out .= "</body></html>";
//$out.= "--" . $this->alternative_boundary . "--" . $this->eol; if ($this->atleastonefile || $this->atleastoneimage)
{
$out.= $this->eol . "--" . $this->mime_boundary . $this->eol;
}
} }
else else
{ {
$out.= $msgtext; $out.= $msgtext;
$out.= $this->eol . "--" . $this->mime_boundary . $this->eol;
} }
return $out; return $out;
} }
@@ -589,7 +587,7 @@ class CMailFile
$out.= $this->eol; $out.= $this->eol;
$out.= $encoded; $out.= $encoded;
$out.= $this->eol; $out.= $this->eol;
// $out.= $this->eol; //$out.= $this->eol;
} }
else else
{ {
@@ -600,6 +598,7 @@ class CMailFile
// Fin de tous les attachements // Fin de tous les attachements
$out.= "--" . $this->mime_boundary . "--" . $this->eol; $out.= "--" . $this->mime_boundary . "--" . $this->eol;
return $out; return $out;
} }
@@ -705,16 +704,16 @@ class CMailFile
} }
$i++; $i++;
} }
if (!empty($this->html_images)) if (!empty($this->html_images))
{ {
// If duplicate images are embedded, they may show up as attachments, so remove them. // If duplicate images are embedded, they may show up as attachments, so remove them.
$html_images = array_unique($this->html_images); //$html_images = array_unique($this->html_images);
sort($html_images); //sort($html_images);
$i=0; $i=0;
foreach ($html_images as $img) foreach ($this->html_images as $img)
{ {
if ($image = file_get_contents($images_dir.'/'.$img["name"])) if ($image = file_get_contents($images_dir.'/'.$img["name"]))
{ {
$this->images_encoded[$i]['name'] = $img["name"]; $this->images_encoded[$i]['name'] = $img["name"];
@@ -724,6 +723,7 @@ class CMailFile
// Encodage de l'image // Encodage de l'image
$this->images_encoded[$i]["image_encoded"] = chunk_split(base64_encode($image), 68, $this->eol); $this->images_encoded[$i]["image_encoded"] = chunk_split(base64_encode($image), 68, $this->eol);
} }
$i++;
} }
} }
else else
@@ -755,9 +755,10 @@ class CMailFile
{ {
dol_syslog("CMailFile::write_images: i=$i"); dol_syslog("CMailFile::write_images: i=$i");
$out.= "--" . $this->image_boundary . $this->eol; $out.= "--" . $this->mime_boundary . $this->eol;
$out.= "Content-Type: " . $img["content_type"] . "; name=\"".$img["name"]."\"".$this->eol; $out.= "Content-Type: " . $img["content_type"] . "; name=\"".$img["name"]."\"".$this->eol;
$out.= "Content-Transfer-Encoding: base64".$this->eol; $out.= "Content-Transfer-Encoding: base64".$this->eol;
$out.= "Content-Disposition: inline; filename=\"".$img["name"]."\"".$this->eol;
$out.= "Content-ID: <".$img["cid"].">".$this->eol; $out.= "Content-ID: <".$img["cid"].">".$this->eol;
$out.= $this->eol; $out.= $this->eol;
$out.= $img["image_encoded"]; $out.= $img["image_encoded"];
@@ -770,8 +771,8 @@ class CMailFile
} }
// Fin de tous les attachements // Fin de tous les attachements
$out.= "--" . $this->image_boundary . "--" . $this->eol; $out.= "--" . $this->mime_boundary . "--" . $this->eol;
return $out; return $out;
} }
@@ -798,7 +799,7 @@ function getValidAddress($adresses,$format)
{ {
if (eregi('^(.*)<(.*)>$',trim($val),$regs)) if (eregi('^(.*)<(.*)>$',trim($val),$regs))
{ {
$name = trim($regs[1]); $name = trim(utf8_decode($regs[1]));
$email = trim($regs[2]); $email = trim($regs[2]);
} }
else else