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:
@@ -144,12 +144,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";
|
||||||
if (eregi('^win',PHP_OS)) $this->eol="\r\n";
|
if (eregi('^win',PHP_OS)) $this->eol="\r\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;
|
||||||
@@ -463,15 +457,19 @@ class CMailFile
|
|||||||
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -709,11 +708,11 @@ 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.
|
// 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"]))
|
||||||
{
|
{
|
||||||
@@ -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,7 +771,7 @@ 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
|
||||||
|
|||||||
Reference in New Issue
Block a user