This commit is contained in:
Laurent Destailleur
2008-11-15 00:52:42 +00:00
parent f6dc853d70
commit 2f6f53b8e3

View File

@@ -22,70 +22,70 @@
*/ */
/** /**
* \file htdocs/lib/CMailFile.class.php * \file htdocs/lib/CMailFile.class.php
* \brief Fichier de la classe permettant d'envoyer des mail avec attachements * \brief Fichier de la classe permettant d'envoyer des mail avec attachements
* \version $Id$ * \version $Id$
* \author Dan Potter. * \author Dan Potter.
* \author Eric Seigne * \author Eric Seigne
* \author Laurent Destailleur. * \author Laurent Destailleur.
*/ */
/** /**
* \class CMailFile * \class CMailFile
* \brief Classe d'envoi de mails et pieces jointes. Encapsule mail() avec d'eventuels attachements. * \brief Classe d'envoi de mails et pieces jointes. Encapsule mail() avec d'eventuels attachements.
* \remarks Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to); * \remarks Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to);
* \remarks $mailfile->sendfile(); * \remarks $mailfile->sendfile();
*/ */
class CMailFile class CMailFile
{ {
var $subject; var $subject;
var $addr_from; var $addr_from;
var $errors_to; var $errors_to;
var $addr_to; var $addr_to;
var $addr_cc; var $addr_cc;
var $addr_bcc; var $addr_bcc;
var $mime_boundary;
var $deliveryreceipt;
var $eol;
var $atleastonefile=0;
var $error='';
/** var $mime_boundary;
\brief CMailFile var $deliveryreceipt;
\param subject sujet
\param to email destinataire (RFC 2822: "Nom prenom <email>[, ...]" ou "email[, ...]" ou "<email>[, ...]")
\param from email emetteur (RFC 2822: "Nom prenom <email>[, ...]" ou "email[, ...]" ou "<email>[, ...]")
\param msg message
\param filename_list tableau de fichiers attaches
\param mimetype_list tableau des types des fichiers attaches
\param mimefilename_list tableau des noms des fichiers attaches
\param addr_cc email cc
\param addr_bcc email bcc
\param deliveryreceipt demande accuse reception
\param msgishtml 1=String IS already html, 0=String IS NOT html, -1=Unknown need autodetection
*/
function CMailFile($subject,$to,$from,$msg,
$filename_list=array(),$mimetype_list=array(),$mimefilename_list=array(),
$addr_cc="",$addr_bcc="",$deliveryreceipt=0,$msgishtml=0,$errors_to='')
{
dolibarr_syslog("CMailFile::CMailfile: from=$from, to=$to, addr_cc=$addr_cc, addr_bcc=$addr_bcc, errors_to=$errors_to");
dolibarr_syslog("CMailFile::CMailfile: subject=$subject, deliveryreceipt=$deliveryreceipt, msgishtml=$msgishtml");
// Define if there is at least one file var $eol;
foreach ($filename_list as $i => $val) var $atleastonefile=0;
{ var $error='';
if ($filename_list[$i])
{
$this->atleastonefile=1; /**
dolibarr_syslog("CMailFile::CMailfile: filename_list[$i]=".$filename_list[$i].", mimetype_list[$i]=".$mimetype_list[$i]." mimefilename_list[$i]=".$mimefilename_list[$i]); \brief CMailFile
\param subject sujet
\param to email destinataire (RFC 2822: "Nom prenom <email>[, ...]" ou "email[, ...]" ou "<email>[, ...]")
\param from email emetteur (RFC 2822: "Nom prenom <email>[, ...]" ou "email[, ...]" ou "<email>[, ...]")
\param msg message
\param filename_list tableau de fichiers attaches
\param mimetype_list tableau des types des fichiers attaches
\param mimefilename_list tableau des noms des fichiers attaches
\param addr_cc email cc
\param addr_bcc email bcc
\param deliveryreceipt demande accuse reception
\param msgishtml 1=String IS already html, 0=String IS NOT html, -1=Unknown need autodetection
*/
function CMailFile($subject,$to,$from,$msg,
$filename_list=array(),$mimetype_list=array(),$mimefilename_list=array(),
$addr_cc="",$addr_bcc="",$deliveryreceipt=0,$msgishtml=0,$errors_to='')
{
dolibarr_syslog("CMailFile::CMailfile: from=$from, to=$to, addr_cc=$addr_cc, addr_bcc=$addr_bcc, errors_to=$errors_to");
dolibarr_syslog("CMailFile::CMailfile: subject=$subject, deliveryreceipt=$deliveryreceipt, msgishtml=$msgishtml");
// Define if there is at least one file
foreach ($filename_list as $i => $val)
{
if ($filename_list[$i])
{
$this->atleastonefile=1;
dolibarr_syslog("CMailFile::CMailfile: filename_list[$i]=".$filename_list[$i].", mimetype_list[$i]=".$mimetype_list[$i]." mimefilename_list[$i]=".$mimefilename_list[$i]);
} }
} }
// On defini mime_boundary // On defini mime_boundary
$this->mime_boundary = md5(uniqid("dolibarr")); $this->mime_boundary = md5(uniqid("dolibarr"));
// On definit fin de ligne // On definit fin de ligne
$this->eol="\n"; $this->eol="\n";
@@ -96,7 +96,7 @@ class CMailFile
if ($msgishtml == -1) if ($msgishtml == -1)
{ {
$this->msgishtml = 0; $this->msgishtml = 0;
if (dol_textishtml($msg,1)) $this->msgishtml = 1; if (dol_textishtml($msg,1)) $this->msgishtml = 1;
} }
else else
{ {
@@ -107,74 +107,74 @@ class CMailFile
$mime_headers = ""; $mime_headers = "";
$text_body = ""; $text_body = "";
$text_encoded = ""; $text_encoded = "";
// En-tete dans $smtp_headers // En-tete dans $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;
$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;
$smtp_headers = $this->write_smtpheaders(); $smtp_headers = $this->write_smtpheaders();
// En-tete suite dans $mime_headers // En-tete suite dans $mime_headers
if ($this->atleastonefile) if ($this->atleastonefile)
{ {
$mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list); $mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list);
} }
// Corps message dans $text_body // Corps message dans $text_body
$text_body = $this->write_body($msg, $filename_list); $text_body = $this->write_body($msg, $filename_list);
// Corps message suite (fichiers attaches) dans $text_encoded // Corps message suite (fichiers attaches) dans $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 // On defini $this->headers et $this->message
$this->headers = $smtp_headers . $mime_headers; $this->headers = $smtp_headers . $mime_headers;
$this->message = $text_body . $text_encoded; $this->message = $text_body . $text_encoded;
// On nettoie le header pour qu'il ne se termine pas par un retour chariot. // On nettoie le header pour qu'il ne se termine pas par un retour chariot.
// Ceci evite aussi les lignes vides en fin qui peuvent etre interpretees // Ceci evite aussi les lignes vides en fin qui peuvent etre interpretees
// comme des injections mail par les serveurs de messagerie. // comme des injections mail par les serveurs de messagerie.
$this->headers = eregi_replace("[\r\n]+$","",$this->headers); $this->headers = eregi_replace("[\r\n]+$","",$this->headers);
} }
/** /**
\brief Permet d'encoder un fichier \brief Permet d'encoder un fichier
\param sourcefile \param sourcefile
\return <0 si erreur, fichier encode si ok \return <0 si erreur, fichier encode si ok
*/ */
function _encode_file($sourcefile) function _encode_file($sourcefile)
{ {
if (is_readable($sourcefile)) if (is_readable($sourcefile))
{ {
$fd = fopen($sourcefile, "r"); $fd = fopen($sourcefile, "r");
$contents = fread($fd, filesize($sourcefile)); $contents = fread($fd, filesize($sourcefile));
$encoded = chunk_split(base64_encode($contents), 68, $this->eol); $encoded = chunk_split(base64_encode($contents), 68, $this->eol);
fclose($fd); fclose($fd);
return $encoded; return $encoded;
} }
else else
{ {
$this->error="Error: Can't read file '$sourcefile'"; $this->error="Error: Can't read file '$sourcefile'";
dolibarr_syslog("CMailFile::encode_file: ".$this->error); dolibarr_syslog("CMailFile::encode_file: ".$this->error);
return -1; return -1;
} }
} }
/** /**
\brief Envoi le mail \brief Envoi le mail
\return boolean true si mail envoye, false sinon \return boolean true si mail envoye, false sinon
*/ */
function sendfile() function sendfile()
{ {
global $conf; global $conf;
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".$this->headers); dolibarr_syslog("CMailFile::sendfile header=\n".$this->headers);
//dolibarr_syslog("CMailFile::sendfile message=\n".$message); //dolibarr_syslog("CMailFile::sendfile message=\n".$message);
@@ -184,7 +184,7 @@ class CMailFile
error_reporting($errorlevel ^ E_WARNING); // Desactive warnings error_reporting($errorlevel ^ E_WARNING); // Desactive warnings
$res=false; $res=false;
if (! $conf->global->MAIN_DISABLE_ALL_MAILS) if (! $conf->global->MAIN_DISABLE_ALL_MAILS)
{ {
// Si Windows, addr_from doit obligatoirement etre defini // Si Windows, addr_from doit obligatoirement etre defini
@@ -197,7 +197,7 @@ class CMailFile
// 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);
$dest=getValidAddress($this->addr_to,2); $dest=getValidAddress($this->addr_to,2);
if (! $dest) if (! $dest)
{ {
@@ -217,10 +217,10 @@ class CMailFile
// La variable definie pose des pb avec certains sendmail securisee (option -f refusee car dangereuse) // La variable definie pose des pb avec certains sendmail securisee (option -f refusee car dangereuse)
$bounce = $this->addr_from != '' ? "-f {$this->addr_from}" : ""; $bounce = $this->addr_from != '' ? "-f {$this->addr_from}" : "";
} }
$res = mail($dest,$this->subject,stripslashes($this->message),$this->headers, $bounce); $res = mail($dest,$this->subject,stripslashes($this->message),$this->headers, $bounce);
if (! $res) if (! $res)
{ {
$this->error="Failed to send mail to SMTP=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Check your server logs and your firewalls setup"; $this->error="Failed to send mail to SMTP=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Check your server logs and your firewalls setup";
dolibarr_syslog("CMailFile::sendfile: mail end error=".$this->error); dolibarr_syslog("CMailFile::sendfile: mail end error=".$this->error);
@@ -230,7 +230,7 @@ class CMailFile
dolibarr_syslog("CMailFile::sendfile: mail end success"); dolibarr_syslog("CMailFile::sendfile: mail end success");
} }
} }
if (isset($_SERVER["WINDIR"])) if (isset($_SERVER["WINDIR"]))
{ {
@ini_restore('sendmail_from'); @ini_restore('sendmail_from');
@@ -252,181 +252,181 @@ class CMailFile
} }
/** /**
* \brief Ecrit le mail dans un fichier. Utilisation pour le debuggage. * \brief Ecrit le mail dans un fichier. Utilisation pour le debuggage.
*/ */
function dump_mail() function dump_mail()
{ {
global $dolibarr_main_data_root; global $dolibarr_main_data_root;
if (@is_writeable($dolibarr_main_data_root)) // Avoid fatal error on fopen with open_basedir if (@is_writeable($dolibarr_main_data_root)) // Avoid fatal error on fopen with open_basedir
{ {
$fp = fopen($dolibarr_main_data_root."/dolibarr_mail","w"); $fp = fopen($dolibarr_main_data_root."/dolibarr_mail","w");
fputs($fp, $this->headers); fputs($fp, $this->headers);
fputs($fp, $this->eol); // This eol is added by the mail function, so we add it in log fputs($fp, $this->eol); // This eol is added by the mail function, so we add it in log
fputs($fp, $this->message); fputs($fp, $this->message);
fclose($fp); fclose($fp);
if (! empty($conf->global->MAIN_UMASK)) if (! empty($conf->global->MAIN_UMASK))
@chmod($outputfile, octdec($conf->global->MAIN_UMASK)); @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
} }
} }
/** /**
\brief Creation des headers smtp \brief Creation des headers smtp
*/ */
function write_smtpheaders() function write_smtpheaders()
{ {
global $conf; global $conf;
$out = ""; $out = "";
// 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: ".getValidAddress($this->addr_from,0).$this->eol;
$out .= "Return-Path: ".getValidAddress($this->addr_from,0).$this->eol; $out .= "Return-Path: ".getValidAddress($this->addr_from,0).$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: ".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: ".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: ".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: ".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: ".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 .$this->eol; $out .= "X-Mailer: Dolibarr version " . DOL_VERSION .$this->eol;
$out .= "MIME-Version: 1.0".$this->eol; $out .= "MIME-Version: 1.0".$this->eol;
if ($this->msgishtml) if ($this->msgishtml)
{ {
if (! $this->atleastonefile) $out.= "Content-Type: text/html; charset=".$conf->character_set_client.$this->eol; if (! $this->atleastonefile) $out.= "Content-Type: text/html; charset=".$conf->character_set_client.$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->character_set_client.$this->eol; if (! $this->atleastonefile) $out.= "Content-Type: text/plain; charset=".$conf->character_set_client.$this->eol;
$out.= "Content-Transfer-Encoding: 8bit".$this->eol; $out.= "Content-Transfer-Encoding: 8bit".$this->eol;
} }
dolibarr_syslog("CMailFile::write_smtpheaders smtp_header=\n".$out); dolibarr_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)
{ {
$mimedone=0; $mimedone=0;
$out = ""; $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.= "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;
} }
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;
} }
} }
//$out.= $this->eol; //$out.= $this->eol;
dolibarr_syslog("CMailFile::write_mimeheaders mime_header=\n".$out); dolibarr_syslog("CMailFile::write_mimeheaders mime_header=\n".$out);
return $out; return $out;
} }
/** /**
\brief Permet d'ecrire le corps du message \brief Permet d'ecrire le corps du message
\param msgtext \param msgtext
\param filename_list \param filename_list
*/ */
function write_body($msgtext, $filename_list) function write_body($msgtext, $filename_list)
{ {
global $conf; global $conf;
$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=".$conf->character_set_client.$this->eol; $out.= "Content-Type: text/html; charset=".$conf->character_set_client.$this->eol;
} }
else else
{ {
$out.= "Content-Type: text/plain; charset=".$conf->character_set_client.$this->eol; $out.= "Content-Type: text/plain; charset=".$conf->character_set_client.$this->eol;
} }
$out.= $this->eol; $out.= $this->eol;
} }
if ($this->msgishtml) if ($this->msgishtml)
{ {
// Check if html header already in message // Check if html header already in message
$htmlalreadyinmsg=0; $htmlalreadyinmsg=0;
if (eregi('^[ \t]*<html',$msgtext)) $htmlalreadyinmsg=1; if (eregi('^[ \t]*<html',$msgtext)) $htmlalreadyinmsg=1;
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>";
} }
else else
{ {
$out.= $msgtext; $out.= $msgtext;
} }
$out.= $this->eol; $out.= $this->eol;
return $out; return $out;
} }
/** /**
\brief Permet d'attacher un fichier \brief Permet d'attacher un fichier
\param filename_list Tableau \param filename_list Tableau
\param mimetype_list Tableau \param mimetype_list Tableau
\param mimefilename_list Tableau \param mimefilename_list Tableau
\return out Chaine fichiers encodes \return out Chaine fichiers encodes
*/ */
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++)
{
if ($filename_list[$i])
{
dolibarr_syslog("CMailFile::write_files: i=$i");
$encoded = $this->_encode_file($filename_list[$i]);
if ($encoded >= 0)
{
if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i];
if (! $mimetype_list[$i]) { $mimetype_list[$i] = "application/octet-stream"; }
$out = $out . "--" . $this->mime_boundary . $this->eol; for ($i = 0; $i < count($filename_list); $i++)
$out.= "Content-Type: " . $mimetype_list[$i] . "; name=\"".$filename_list[$i]."\"".$this->eol; {
$out.= "Content-Transfer-Encoding: base64".$this->eol; if ($filename_list[$i])
$out.= "Content-Disposition: attachment; filename=\"".$filename_list[$i]."\"".$this->eol; {
$out.= $this->eol; dolibarr_syslog("CMailFile::write_files: i=$i");
$out.= $encoded; $encoded = $this->_encode_file($filename_list[$i]);
$out.= $this->eol; if ($encoded >= 0)
// $out.= $this->eol; {
} if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i];
else if (! $mimetype_list[$i]) { $mimetype_list[$i] = "application/octet-stream"; }
{
return $encoded; $out = $out . "--" . $this->mime_boundary . $this->eol;
} $out.= "Content-Type: " . $mimetype_list[$i] . "; name=\"".$filename_list[$i]."\"".$this->eol;
$out.= "Content-Transfer-Encoding: base64".$this->eol;
$out.= "Content-Disposition: attachment; filename=\"".$filename_list[$i]."\"".$this->eol;
$out.= $this->eol;
$out.= $encoded;
$out.= $this->eol;
// $out.= $this->eol;
}
else
{
return $encoded;
}
} }
} }
// Fin de tous les attachements // Fin de tous les attachements
$out = $out . "--" . $this->mime_boundary . "--" . $this->eol; $out = $out . "--" . $this->mime_boundary . "--" . $this->eol;
return $out; return $out;
} }
function check_server_port($host,$port) function check_server_port($host,$port)
{ {
$_retVal=0; $_retVal=0;
@@ -434,19 +434,19 @@ class CMailFile
if (function_exists('fsockopen')) if (function_exists('fsockopen'))
{ {
//See if we can connect to the SMTP server //See if we can connect to the SMTP server
if ( $socket = @fsockopen($host, // Host to 'hit', IP or domain if ( $socket = @fsockopen($host, // Host to 'hit', IP or domain
$port, // which Port number to use $port, // which Port number to use
$errno, // actual system level error $errno, // actual system level error
$errstr, // and any text that goes with the error $errstr, // and any text that goes with the error
5) ) // timeout for reading/writing data over the socket 5) ) // timeout for reading/writing data over the socket
{ {
// Windows still does not have support for this timeout function // Windows still does not have support for this timeout function
if (function_exists('socket_set_timeout')) if (function_exists('socket_set_timeout'))
socket_set_timeout($socket, 5, 0); socket_set_timeout($socket, 5, 0);
// Check response from Server // Check response from Server
if ( $_retVal = $this->server_parse($socket, "220") ) if ( $_retVal = $this->server_parse($socket, "220") )
$_retVal = $socket; $_retVal = $socket;
} }
else else
{ {
@@ -462,16 +462,16 @@ class CMailFile
// //
function server_parse($socket, $response) function server_parse($socket, $response)
{ {
/** /**
* Default return value * Default return value
* *
* Returns constructed SELECT Object string or boolean upon failure * Returns constructed SELECT Object string or boolean upon failure
* Default value is set at TRUE * Default value is set at TRUE
* *
* @var mixed $_retVal Indicates if Object was created or not * @var mixed $_retVal Indicates if Object was created or not
* @access private * @access private
* @static * @static
*/ */
$_retVal = true; $_retVal = true;
$server_response = ''; $server_response = '';
@@ -491,39 +491,39 @@ class CMailFile
} }
return $_retVal; return $_retVal;
} }
} }
/** /**
\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)
{ {
global $conf; global $conf;
$ret=''; $ret='';
$arrayaddress=split(',',$adresses); $arrayaddress=split(',',$adresses);
// Boucle sur chaque composant de l'adresse // Boucle sur chaque composant de l'adresse
foreach($arrayaddress as $val) foreach($arrayaddress as $val)
{ {
if (eregi('^(.*)<(.*)>$',trim($val),$regs)) if (eregi('^(.*)<(.*)>$',trim($val),$regs))
{ {
$name = trim($regs[1]); $name = trim($regs[1]);
$email = trim($regs[2]); $email = trim($regs[2]);
} }
else else
{ {
$name = ''; $name = '';
$email = trim($val); $email = trim($val);
} }
if ($email) if ($email)
{ {
$newemail=''; $newemail='';
@@ -545,7 +545,7 @@ function getValidAddress($adresses,$format)
$ret=($ret ? $ret.',' : '').$newemail; $ret=($ret ? $ret.',' : '').$newemail;
} }
} }
return $ret; return $ret;
} }
?> ?>