forked from Wavyzz/dolibarr
Fix: Mauvais respet RFC lors envoi mail si serveur Windows.
This commit is contained in:
@@ -71,6 +71,8 @@ class CMailFile
|
|||||||
*/
|
*/
|
||||||
function CMailFile($subject,$to,$from,$msg,$filename_list,$mimetype_list,$mimefilename_list,$addr_cc="",$addr_bcc="")
|
function CMailFile($subject,$to,$from,$msg,$filename_list,$mimetype_list,$mimefilename_list,$addr_cc="",$addr_bcc="")
|
||||||
{
|
{
|
||||||
|
dolibarr_syslog("CMailFile::CMailfile: filename_list[0]=$filename_list[0], mimetype_list[0]=$mimetype_list[0] mimefilename_list[0]=$mimefilename_list[0]");
|
||||||
|
|
||||||
$this->mime_boundary = md5( uniqid("dolibarr") );
|
$this->mime_boundary = md5( uniqid("dolibarr") );
|
||||||
|
|
||||||
$this->subject = $subject;
|
$this->subject = $subject;
|
||||||
@@ -98,7 +100,10 @@ class CMailFile
|
|||||||
{
|
{
|
||||||
for ($i = 0; $i < count($filename_list); $i++)
|
for ($i = 0; $i < count($filename_list); $i++)
|
||||||
{
|
{
|
||||||
|
dolibarr_syslog("CMailFile::attach_file: i=$i");
|
||||||
$encoded = $this->encode_file($filename_list[$i]);
|
$encoded = $this->encode_file($filename_list[$i]);
|
||||||
|
if ($encoded != -1)
|
||||||
|
{
|
||||||
if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i];
|
if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i];
|
||||||
$out = $out . "--" . $this->mime_boundary . "\n";
|
$out = $out . "--" . $this->mime_boundary . "\n";
|
||||||
if (! $mimetype_list[$i]) { $mimetype_list[$i] = "application/octet-stream"; }
|
if (! $mimetype_list[$i]) { $mimetype_list[$i] = "application/octet-stream"; }
|
||||||
@@ -107,6 +112,7 @@ class CMailFile
|
|||||||
$out .= "Content-disposition: attachment; filename=\"$filename_list[$i]\"\n\n";
|
$out .= "Content-disposition: attachment; filename=\"$filename_list[$i]\"\n\n";
|
||||||
$out .= $encoded . "\n";
|
$out .= $encoded . "\n";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$out = $out . "--" . $this->mime_boundary . "--" . "\n";
|
$out = $out . "--" . $this->mime_boundary . "--" . "\n";
|
||||||
return $out;
|
return $out;
|
||||||
// added -- to notify email client attachment is done
|
// added -- to notify email client attachment is done
|
||||||
@@ -116,7 +122,7 @@ class CMailFile
|
|||||||
/**
|
/**
|
||||||
\brief Permet d'encoder un fichier
|
\brief Permet d'encoder un fichier
|
||||||
\param sourcefile
|
\param sourcefile
|
||||||
\return < 0 si erreur, fichier encod<6F> si ok
|
\return <0 si erreur, fichier encod<6F> si ok
|
||||||
*/
|
*/
|
||||||
function encode_file($sourcefile)
|
function encode_file($sourcefile)
|
||||||
{
|
{
|
||||||
@@ -127,12 +133,13 @@ class CMailFile
|
|||||||
$encoded = chunk_split(base64_encode($contents));
|
$encoded = chunk_split(base64_encode($contents));
|
||||||
//$encoded = my_chunk_split(base64_encode($contents));
|
//$encoded = my_chunk_split(base64_encode($contents));
|
||||||
fclose($fd);
|
fclose($fd);
|
||||||
|
return $encoded;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dolibarr_syslog("CMailFile::encode_file: Can't read file $sourcefile");
|
dolibarr_syslog("CMailFile::encode_file: Can't read file '$sourcefile'");
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
return $encoded;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,10 +149,22 @@ class CMailFile
|
|||||||
function sendfile()
|
function sendfile()
|
||||||
{
|
{
|
||||||
$headers = $this->smtp_headers . $this->mime_headers;
|
$headers = $this->smtp_headers . $this->mime_headers;
|
||||||
$message = $this->text_body . $this->text_encoded;
|
$message=$this->text_body . $this->text_encoded;
|
||||||
|
|
||||||
|
// Fix si windows, la fonction mail ne traduit pas les \n, il faut donc y mettre
|
||||||
|
// des champs \r\n (impos<6F>s par SMTP).
|
||||||
|
if (eregi('^win',PHP_OS))
|
||||||
|
{
|
||||||
|
$message = eregi_replace("\r","", $this->text_body . $this->text_encoded);
|
||||||
|
$message = eregi_replace("\n","\r\n", $message);
|
||||||
|
}
|
||||||
|
|
||||||
|
dolibarr_syslog("CMailFile::sendfile addr_to=".$this->addr_to.", subject=".$this->subject);
|
||||||
|
//dolibarr_syslog("CMailFile::sendfile message=\n".$message);
|
||||||
|
//dolibarr_syslog("CMailFile::sendfile header=\n".$headers);
|
||||||
|
|
||||||
$errorlevel=error_reporting();
|
$errorlevel=error_reporting();
|
||||||
error_reporting($errorlevel ^ E_WARNING); // D<>sactive warnings
|
//error_reporting($errorlevel ^ E_WARNING); // D<>sactive warnings
|
||||||
if ($this->errors_to)
|
if ($this->errors_to)
|
||||||
{
|
{
|
||||||
dolibarr_syslog("CMailFile::sendfile with errorsto : ".$this->errors_to);
|
dolibarr_syslog("CMailFile::sendfile with errorsto : ".$this->errors_to);
|
||||||
@@ -156,6 +175,7 @@ class CMailFile
|
|||||||
dolibarr_syslog("CMailFile::sendfile");
|
dolibarr_syslog("CMailFile::sendfile");
|
||||||
$res = mail($this->addr_to,$this->subject,stripslashes($message),$headers);
|
$res = mail($this->addr_to,$this->subject,stripslashes($message),$headers);
|
||||||
}
|
}
|
||||||
|
//if (! $res) $this->error=
|
||||||
error_reporting($errorlevel); // R<>active niveau erreur origine
|
error_reporting($errorlevel); // R<>active niveau erreur origine
|
||||||
|
|
||||||
//$this->write_to_file();
|
//$this->write_to_file();
|
||||||
|
|||||||
Reference in New Issue
Block a user