Skip to content
Snippets Groups Projects
Commit c79a093c authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Fix: Try to fix bad encoding when from user contains special caracters.

parent fdcd7db6
Branches
Tags
No related merge requests found
...@@ -172,7 +172,7 @@ class CMailFile ...@@ -172,7 +172,7 @@ class CMailFile
$text_body = ""; $text_body = "";
$text_encoded = ""; $text_encoded = "";
// En-tete dans $smtp_headers // Define smtp_headers
$this->subject = $subject; $this->subject = $subject;
$this->addr_from = $from; $this->addr_from = $from;
$this->errors_to = $errors_to; $this->errors_to = $errors_to;
...@@ -182,31 +182,27 @@ class CMailFile ...@@ -182,31 +182,27 @@ class CMailFile
$this->deliveryreceipt = $deliveryreceipt; $this->deliveryreceipt = $deliveryreceipt;
$smtp_headers = $this->write_smtpheaders(); $smtp_headers = $this->write_smtpheaders();
// En-tete suite dans $mime_headers // Define mime_headers
// if ($this->atleastonefile || $this->atleastoneimage)
// {
$mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list); $mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list);
// }
if (! empty($this->html)) $msg = $this->html; if (! empty($this->html)) $msg = $this->html;
// Corps message dans $text_body // Define body in text_body
$text_body = $this->write_body($msg); $text_body = $this->write_body($msg);
// On encode les images // Encode images
if ($this->atleastoneimage) if ($this->atleastoneimage)
{ {
$images_encoded = $this->write_images($this->images_encoded); $images_encoded = $this->write_images($this->images_encoded);
//print 'xx'.sizeof($this->images_encoded['encoded']);
} }
// Corps message suite (fichiers attaches) dans $text_encoded // Add attachments to text_encoded
if ($this->atleastonefile) if ($this->atleastonefile)
{ {
$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 // We now define $this->headers et $this->message
$this->headers = $smtp_headers . $mime_headers; $this->headers = $smtp_headers . $mime_headers;
$this->message = $text_body . $images_encoded . $text_encoded; $this->message = $text_body . $images_encoded . $text_encoded;
...@@ -323,7 +319,7 @@ class CMailFile ...@@ -323,7 +319,7 @@ class CMailFile
$smtps->setCharSet($conf->file->character_set_client); $smtps->setCharSet($conf->file->character_set_client);
$smtps->setSubject($this->encodetorfc2822($subject)); $smtps->setSubject($this->encodetorfc2822($subject));
$smtps->setTO(getValidAddress($to,2)); $smtps->setTO($this->getValidAddress($to,2));
$smtps->setFrom($from); $smtps->setFrom($from);
//if ($this->atleastoneimage) $msg = $this->html; //if ($this->atleastoneimage) $msg = $this->html;
...@@ -396,19 +392,18 @@ class CMailFile ...@@ -396,19 +392,18 @@ class CMailFile
dol_syslog("CMailFile::sendfile header=\n".$this->headers, LOG_DEBUG); dol_syslog("CMailFile::sendfile header=\n".$this->headers, LOG_DEBUG);
//dol_syslog("CMailFile::sendfile message=\n".$message); //dol_syslog("CMailFile::sendfile message=\n".$message);
// If Windows, sendmail_from must be defined
// Si Windows, addr_from doit obligatoirement etre defini
if (isset($_SERVER["WINDIR"])) if (isset($_SERVER["WINDIR"]))
{ {
if (empty($this->addr_from)) $this->addr_from = 'robot@mydomain.com'; if (empty($this->addr_from)) $this->addr_from = 'robot@mydomain.com';
@ini_set('sendmail_from',getValidAddress($this->addr_from,2)); @ini_set('sendmail_from',$this->getValidAddress($this->addr_from,2));
} }
// Forcage parametres // Forcage parametres
if (! empty($conf->global->MAIN_MAIL_SMTP_SERVER)) ini_set('SMTP',$conf->global->MAIN_MAIL_SMTP_SERVER); if (! empty($conf->global->MAIN_MAIL_SMTP_SERVER)) ini_set('SMTP',$conf->global->MAIN_MAIL_SMTP_SERVER);
if (! empty($conf->global->MAIN_MAIL_SMTP_PORT)) ini_set('smtp_port',$conf->global->MAIN_MAIL_SMTP_PORT); if (! empty($conf->global->MAIN_MAIL_SMTP_PORT)) ini_set('smtp_port',$conf->global->MAIN_MAIL_SMTP_PORT);
if ($conf->global->MAIN_MAIL_SENDMODE == 'mail') $dest=getValidAddress($this->addr_to,2); if ($conf->global->MAIN_MAIL_SENDMODE == 'mail') $dest=$this->getValidAddress($this->addr_to,2);
if (! $dest && $conf->global->MAIN_MAIL_SENDMODE == 'mail') if (! $dest && $conf->global->MAIN_MAIL_SENDMODE == 'mail')
{ {
$this->error="Failed to send mail to SMTP=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Recipient address '$dest' invalid"; $this->error="Failed to send mail to SMTP=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Recipient address '$dest' invalid";
...@@ -417,7 +412,6 @@ class CMailFile ...@@ -417,7 +412,6 @@ class CMailFile
else else
{ {
dol_syslog("CMailFile::sendfile: mail start SMTP=".ini_get('SMTP').", PORT=".ini_get('smtp_port'), LOG_DEBUG); dol_syslog("CMailFile::sendfile: mail start SMTP=".ini_get('SMTP').", PORT=".ini_get('smtp_port'), LOG_DEBUG);
//dol_syslog("to=".getValidAddress($this->addr_to,2).", subject=".$this->subject.", message=".stripslashes($this->message).", header=".$this->headers);
$bounce = ''; $bounce = '';
if ($conf->global->MAIN_MAIL_ALLOW_SENDMAIL_F) if ($conf->global->MAIN_MAIL_ALLOW_SENDMAIL_F)
...@@ -582,7 +576,7 @@ class CMailFile ...@@ -582,7 +576,7 @@ class CMailFile
} }
/** /**
\brief Creation des headers smtp * \brief Create SMTP headers
*/ */
function write_smtpheaders() function write_smtpheaders()
{ {
...@@ -591,50 +585,35 @@ class CMailFile ...@@ -591,50 +585,35 @@ class CMailFile
// Sender // Sender
//$out .= "X-Sender: ".getValidAddress($this->addr_from,2).$this->eol; //$out .= "X-Sender: ".getValidAddress($this->addr_from,2).$this->eol;
$out .= "From: ".getValidAddress($this->addr_from,0).$this->eol; $out .= "From: ".$this->getValidAddress($this->addr_from,0,1).$this->eol;
$out .= "Return-Path: ".getValidAddress($this->addr_from,0).$this->eol; $out .= "Return-Path: ".$this->getValidAddress($this->addr_from,0,1).$this->eol;
if (isset($this->reply_to) && $this->reply_to) $out .= "Reply-To: ".getValidAddress($this->reply_to,2).$this->eol; if (isset($this->reply_to) && $this->reply_to) $out .= "Reply-To: ".$this->getValidAddress($this->reply_to,2).$this->eol;
if (isset($this->errors_to) && $this->errors_to) $out .= "Errors-To: ".getValidAddress($this->errors_to,2).$this->eol; if (isset($this->errors_to) && $this->errors_to) $out .= "Errors-To: ".$this->getValidAddress($this->errors_to,2).$this->eol;
// Receiver // Receiver
if (isset($this->addr_cc) && $this->addr_cc) $out .= "Cc: ".getValidAddress($this->addr_cc,2).$this->eol; if (isset($this->addr_cc) && $this->addr_cc) $out .= "Cc: ".$this->getValidAddress($this->addr_cc,2).$this->eol;
if (isset($this->addr_bcc) && $this->addr_bcc) $out .= "Bcc: ".getValidAddress($this->addr_bcc,2).$this->eol; if (isset($this->addr_bcc) && $this->addr_bcc) $out .= "Bcc: ".$this->getValidAddress($this->addr_bcc,2).$this->eol;
// Accuse reception // Accuse reception
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: ".$this->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->atleastoneimage)
// {
//if (! $this->atleastonefile)
$out.= "Content-Type: multipart/related; boundary=\"".$this->mime_boundary."\"".$this->eol; $out.= "Content-Type: multipart/related; boundary=\"".$this->mime_boundary."\"".$this->eol;
$out.= "Content-Transfer-Encoding: 8bit".$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;
}
else
{
if (! $this->atleastonefile) $out.= "Content-Type: text/plain; boundary=\"".$this->mime_boundary."\"".$this->eol;
$out.= "Content-Transfer-Encoding: 8bit".$this->eol;
}
*/
$out.=$this->eol; $out.=$this->eol;
dol_syslog("CMailFile::write_smtpheaders smtp_header=\n".$out, LOG_DEBUG); dol_syslog("CMailFile::write_smtpheaders smtp_header=\n".$out);
return $out; return $out;
} }
/** /**
\brief Creation header MIME * \brief Creation header MIME
\param filename_list * \param filename_list
\param mimefilename_list * \param mimefilename_list
*/ */
function write_mimeheaders($filename_list, $mimefilename_list) function write_mimeheaders($filename_list, $mimefilename_list)
{ {
...@@ -647,25 +626,12 @@ class CMailFile ...@@ -647,25 +626,12 @@ class CMailFile
{ {
if ($filename_list[$i]) if ($filename_list[$i])
{ {
//if (! $mimedone)
//{
// $out.= "Content-Type: multipart/mixed; boundary=\"".$this->mime_boundary."\"".$this->eol;
// $mimedone=1;
//}
if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i]; if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i];
$out.= "X-attachments: $filename_list[$i]".$this->eol; $out.= "X-attachments: $filename_list[$i]".$this->eol;
//if ($mimedone!=2 && $this->atleastoneimage)
//{
// $out.= "--" . $this->mime_boundary . $this->eol;
// $out.= "Content-Type: multipart/related; boundary=\"".$this->related_boundary."\"".$this->eol;
// $mimedone=2;
// }
} }
} }
} }
//$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;
} }
...@@ -987,17 +953,15 @@ class CMailFile ...@@ -987,17 +953,15 @@ class CMailFile
} }
} }
}
/** /**
\brief Renvoie une adresse acceptee par le serveur SMTP * \brief Renvoie une adresse acceptee par le serveur SMTP
\param adresses Exemple: 'John Doe <john@doe.com>' ou 'john@doe.com' * \param adresses Exemple: 'John Doe <john@doe.com>' ou 'john@doe.com'
\param format 0=Auto, 1=emails avec <>, 2=emails sans <> * \param format 0=Auto, 1=emails avec <>, 2=emails sans <>
\return string Renvoi: Si format 1: '<john@doe.com>' ou 'John Doe <john@doe.com>' * \return string Renvoi: Si format 1: '<john@doe.com>' ou 'John Doe <john@doe.com>'
Si format 2: 'john@doe.com' * Si format 2: 'john@doe.com'
*/ */
function getValidAddress($adresses,$format) function getValidAddress($adresses,$format,$encode='')
{ {
global $conf; global $conf;
...@@ -1010,7 +974,7 @@ function getValidAddress($adresses,$format) ...@@ -1010,7 +974,7 @@ function getValidAddress($adresses,$format)
{ {
if (eregi('^(.*)<(.*)>$',trim($val),$regs)) if (eregi('^(.*)<(.*)>$',trim($val),$regs))
{ {
$name = trim(utf8_decode($regs[1])); $name = trim($regs[1]);
$email = trim($regs[2]); $email = trim($regs[2]);
} }
else else
...@@ -1034,7 +998,7 @@ function getValidAddress($adresses,$format) ...@@ -1034,7 +998,7 @@ function getValidAddress($adresses,$format)
{ {
if ($conf->global->MAIN_MAIL_NO_FULL_EMAIL) $newemail='<'.$email.'>'; if ($conf->global->MAIN_MAIL_NO_FULL_EMAIL) $newemail='<'.$email.'>';
elseif (! $name) $newemail='<'.$email.'>'; elseif (! $name) $newemail='<'.$email.'>';
else $newemail=$name.' <'.$email.'>'; else $newemail=($encode?$this->encodetorfc2822($name):$name).' <'.$email.'>';
} }
$ret=($ret ? $ret.',' : '').$newemail; $ret=($ret ? $ret.',' : '').$newemail;
...@@ -1043,5 +1007,6 @@ function getValidAddress($adresses,$format) ...@@ -1043,5 +1007,6 @@ function getValidAddress($adresses,$format)
return $ret; return $ret;
} }
}
?> ?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment