Fix: Lors d'envoi de mails html avec certains maileurs

This commit is contained in:
Laurent Destailleur 2006-10-31 23:10:46 +00:00
parent 0675975f36
commit cff38c88a4
2 changed files with 36 additions and 30 deletions

1
htdocs/lib/.cvsignore Normal file
View File

@ -0,0 +1 @@
htmlMimeMail

View File

@ -51,11 +51,7 @@ class CMailFile
var $addr_to; var $addr_to;
var $addr_cc; var $addr_cc;
var $addr_bcc; var $addr_bcc;
var $text_body;
var $text_encoded;
var $mime_headers;
var $mime_boundary; var $mime_boundary;
var $smtp_headers;
var $deliveryreceipt; var $deliveryreceipt;
var $eol; var $eol;
@ -90,39 +86,50 @@ class CMailFile
dolibarr_syslog("CMailFile::CMailfile: filename_list[$i]=".$filename_list[$i].", mimetype_list[$i]=".$mimetype_list[$i]." mimefilename_list[$i]=".$mimefilename_list[$i]); dolibarr_syslog("CMailFile::CMailfile: filename_list[$i]=".$filename_list[$i].", mimetype_list[$i]=".$mimetype_list[$i]." mimefilename_list[$i]=".$mimefilename_list[$i]);
} }
} }
$this->mime_boundary = md5( uniqid("dolibarr") );
// On defini mime_boundary
$this->mime_boundary = md5(uniqid("dolibarr"));
// 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";
if (eregi('^mac',PHP_OS)) $this->eol="\r"; if (eregi('^mac',PHP_OS)) $this->eol="\r";
// On defini si message HTML
$this->msgishtml = $msgishtml; $this->msgishtml = $msgishtml;
// Genere en-tete dans $this->smtp_headers $smtp_headers = "";
$mime_headers = "";
$text_body = "";
$text_encoded = "";
// En-tete dans $smtp_headers
$this->subject = $subject; $this->subject = $subject;
$this->addr_from = $from; $this->addr_from = $from;
$this->addr_to = $to; $this->addr_to = $to;
$this->addr_cc = $addr_cc; $this->addr_cc = $addr_cc;
$this->addr_bcc = $addr_bcc; $this->addr_bcc = $addr_bcc;
$this->deliveryreceipt = $deliveryreceipt; $this->deliveryreceipt = $deliveryreceipt;
$this->smtp_headers = $this->write_smtpheaders(); $smtp_headers = $this->write_smtpheaders();
// Genere en-tete suite dans $this->mime_headers // En-tete suite dans $mime_headers
if ($this->atleastonefile) if ($this->atleastonefile)
{ {
$this->mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list); $mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list);
} }
// Genere corps message dans $this->text_body // Corps message dans $text_body
$this->text_body = $this->write_body($msg, $filename_list); $text_body = $this->write_body($msg, $filename_list);
// Genere corps message suite (fichiers attachés) dans $this->text_encoded // Corps message suite (fichiers attachés) dans $text_encoded
if ($this->atleastonefile) if ($this->atleastonefile)
{ {
$this->text_encoded = $this->write_files($filename_list,$mimetype_list,$mimefilename_list); $text_encoded = $this->write_files($filename_list,$mimetype_list,$mimefilename_list);
} }
// On defini $this->headers et $this->message
$this->headers = $smtp_headers . $mime_headers . $this->eol;
$this->message = $text_body . $text_encoded . $this->eol;
} }
@ -158,11 +165,8 @@ class CMailFile
{ {
global $conf,$langs; global $conf,$langs;
$headers = $this->smtp_headers . $this->mime_headers;
$message = $this->text_body . $this->text_encoded;
dolibarr_syslog("CMailFile::sendfile addr_to=".$this->addr_to.", subject=".$this->subject); dolibarr_syslog("CMailFile::sendfile addr_to=".$this->addr_to.", subject=".$this->subject);
dolibarr_syslog("CMailFile::sendfile header=\n".$headers); dolibarr_syslog("CMailFile::sendfile header=\n".$this->headers);
//dolibarr_syslog("CMailFile::sendfile message=\n".$message); //dolibarr_syslog("CMailFile::sendfile message=\n".$message);
//$this->send_to_file(); //$this->send_to_file();
@ -177,12 +181,12 @@ class CMailFile
if ($this->errors_to) if ($this->errors_to)
{ {
dolibarr_syslog("CMailFile::sendfile: mail start SMTP=".ini_get('SMTP').", PORT=".ini_get('smtp_port').", with errorsto : ".getValidAddress($this->errors_to,1)); dolibarr_syslog("CMailFile::sendfile: mail start SMTP=".ini_get('SMTP').", PORT=".ini_get('smtp_port').", with errorsto : ".getValidAddress($this->errors_to,1));
$res = mail(getValidAddress($this->addr_to,2),$this->subject,stripslashes($message),$headers,"-f".getValidAddress($this->errors_to,2)); $res = mail(getValidAddress($this->addr_to,2),$this->subject,stripslashes($this->message),$this->headers,"-f".getValidAddress($this->errors_to,2));
} }
else else
{ {
dolibarr_syslog("CMailFile::sendfile: mail start SMTP=".ini_get('SMTP').", PORT=".ini_get('smtp_port')); dolibarr_syslog("CMailFile::sendfile: mail start SMTP=".ini_get('SMTP').", PORT=".ini_get('smtp_port'));
$res = mail(getValidAddress($this->addr_to,2),$this->subject,stripslashes($message),$headers); $res = mail(getValidAddress($this->addr_to,2),$this->subject,stripslashes($this->message),$this->headers);
} }
if (! $res) if (! $res)
{ {
@ -214,12 +218,9 @@ class CMailFile
*/ */
function send_to_file() function send_to_file()
{ {
$headers = $this->smtp_headers . $this->mime_headers;
$message = $this->text_body . $this->text_encoded;
$fp = fopen("/tmp/dolibarr_mail","w"); $fp = fopen("/tmp/dolibarr_mail","w");
fputs($fp, $headers); fputs($fp, $this->headers);
fputs($fp, $message); fputs($fp, $this->message);
fclose($fp); fclose($fp);
} }
@ -247,11 +248,12 @@ class CMailFile
if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $out .= "Disposition-Notification-To: ".getValidAddress($this->addr_from,1).$this->eol; if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $out .= "Disposition-Notification-To: ".getValidAddress($this->addr_from,1).$this->eol;
$out .= "X-Mailer: Dolibarr version " . DOL_VERSION .$this->eol; $out .= "X-Mailer: Dolibarr version " . DOL_VERSION .$this->eol;
$out .= "MIME-Version: 1.0".$this->eol;
//$out .= "X-Priority: 3\n"; //$out .= "X-Priority: 3\n";
if ($this->msgishtml) if ($this->msgishtml)
{ {
$out.= "Content-Type: text/html; charset=\"iso-8859-1\"".$this->eol; $out.= "Content-Type: text/html; charset=iso-8859-1".$this->eol;
$out.= "Content-Transfer-Encoding: 8bit".$this->eol; $out.= "Content-Transfer-Encoding: 8bit".$this->eol;
} }
else else
@ -273,14 +275,13 @@ class CMailFile
function write_mimeheaders($filename_list, $mimefilename_list) function write_mimeheaders($filename_list, $mimefilename_list)
{ {
$mimedone=0; $mimedone=0;
$out = "";
for ($i = 0; $i < count($filename_list); $i++) for ($i = 0; $i < count($filename_list); $i++)
{ {
if ($filename_list[$i]) if ($filename_list[$i])
{ {
if (! $mimedone) if (! $mimedone)
{ {
$out = "";
$out.= "MIME-Version: 1.0".$this->eol;
$out.= "Content-Type: multipart/mixed; boundary=\"".$this->mime_boundary."\"".$this->eol; $out.= "Content-Type: multipart/mixed; boundary=\"".$this->mime_boundary."\"".$this->eol;
$mimedone=1; $mimedone=1;
} }
@ -301,12 +302,13 @@ class CMailFile
function write_body($msgtext, $filename_list) function write_body($msgtext, $filename_list)
{ {
$out=''; $out='';
if ($this->atleastonefile) if ($this->atleastonefile)
{ {
$out.= "--" . $this->mime_boundary . $this->eol; $out.= "--" . $this->mime_boundary . $this->eol;
if ($this->msgishtml) if ($this->msgishtml)
{ {
$out.= "Content-Type: text/html; charset=\"iso-8859-1\"".$this->eol; $out.= "Content-Type: text/html; charset=iso-8859-1".$this->eol;
} }
$out.= $this->eol; $out.= $this->eol;
} }
@ -325,6 +327,7 @@ class CMailFile
$out.= $msgtext; $out.= $msgtext;
} }
$out.= $this->eol; $out.= $this->eol;
// $out.= $this->eol;
return $out; return $out;
} }
@ -338,7 +341,7 @@ class CMailFile
*/ */
function write_files($filename_list,$mimetype_list,$mimefilename_list) function write_files($filename_list,$mimetype_list,$mimefilename_list)
{ {
$out = ""; $out = '';
for ($i = 0; $i < count($filename_list); $i++) for ($i = 0; $i < count($filename_list); $i++)
{ {
@ -358,6 +361,7 @@ class CMailFile
$out.= $this->eol; $out.= $this->eol;
$out.= $encoded; $out.= $encoded;
$out.= $this->eol; $out.= $this->eol;
// $out.= $this->eol;
} }
else else
{ {
@ -368,6 +372,7 @@ class CMailFile
// Fin de tous les attachements // Fin de tous les attachements
$out = $out . "--" . $this->mime_boundary . "--" . $this->eol; $out = $out . "--" . $this->mime_boundary . "--" . $this->eol;
// $out.= $this->eol;
return $out; return $out;
} }