2002-04-30 12:44:42 +02:00
< ? php
2005-06-25 15:02:39 +02:00
/* Copyright ( C ) 2000 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2003 Jean - Louis Bergamo < jlb @ j1b . org >
2006-04-01 03:10:38 +02:00
* Copyright ( C ) 2004 - 2006 Laurent Destailleur < eldy @ users . sourceforge . net >
2005-06-25 15:02:39 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
* or see http :// www . gnu . org /
*
* $Id $
* $Source $
*
* Lots of code inspired from Dan Potter ' s CMailFile class
*
* If chunk_split does not works on your system , change the call to chunk_split
2006-08-06 20:34:37 +02:00
* to _chunk_split
2005-06-25 15:02:39 +02:00
*/
/**
\file htdocs / lib / CMailFile . class . php
\brief Classe permettant d ' envoyer des mail avec attachements
\author Dan Potter .
\author Eric Seigne
\author Laurent Destailleur .
\version $Revision $
2004-07-16 00:17:39 +02:00
*/
2005-06-25 15:02:39 +02:00
/**
\class CMailFile
\brief Classe d 'envoi de mails et pi<70> ces jointes. Encapsule mail() avec d' <EFBFBD> ventuel attachements .
2004-12-28 19:34:56 +01:00
\remarks Usage :
2005-09-10 18:07:40 +02:00
\remarks $mailfile = new CMailFile ( $subject , $sendto , $replyto , $message , $filepath , $mimetype , $filename , $cc , $ccc );
2004-12-28 19:34:56 +01:00
\remarks $mailfile -> sendfile ();
2004-01-08 12:43:33 +01:00
*/
2004-07-16 00:17:39 +02:00
class CMailFile
2003-07-07 12:04:20 +02:00
{
2005-06-25 15:02:39 +02:00
var $subject ;
2006-08-06 20:34:37 +02:00
var $addr_from ;
2007-07-30 16:44:47 +02:00
var $errors_to ;
var $addr_to ;
2005-06-25 15:02:39 +02:00
var $addr_cc ;
var $addr_bcc ;
2007-07-30 16:44:47 +02:00
2005-06-25 15:02:39 +02:00
var $mime_boundary ;
2006-06-26 17:15:51 +02:00
var $deliveryreceipt ;
2006-08-06 20:34:37 +02:00
var $eol ;
var $atleastonefile = 0 ;
var $error = '' ;
2004-07-16 00:17:39 +02:00
2004-12-28 19:24:19 +01:00
/**
2006-08-06 20:34:37 +02:00
\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 attach<EFBFBD> s
\param mimetype_list tableau des types des fichiers attach<EFBFBD> s
\param mimefilename_list tableau des noms des fichiers attach<EFBFBD> s
\param addr_cc email cc
\param addr_bcc email bcc
2007-02-09 02:32:25 +01:00
\param deliveryreceipt demande accus<EFBFBD> r<EFBFBD> ception
2007-10-04 21:59:21 +02:00
\param msgishtml 1 = message is a html message , 0 = message is not html , 2 = auto detect
2004-12-28 19:24:19 +01:00
*/
2005-09-10 18:07:40 +02:00
function CMailFile ( $subject , $to , $from , $msg ,
$filename_list = array (), $mimetype_list = array (), $mimefilename_list = array (),
2007-07-30 16:44:47 +02:00
$addr_cc = " " , $addr_bcc = " " , $deliveryreceipt = 0 , $msgishtml = 0 , $errors_to = '' )
2003-07-07 12:04:20 +02:00
{
2007-07-30 16:44:47 +02:00
dolibarr_syslog ( " CMailFile::CMailfile: from= $from , to= $to , addr_cc= $addr_cc , addr_bcc= $addr_bcc , errors_to= $errors_to " );
2006-08-06 20:34:37 +02:00
dolibarr_syslog ( " CMailFile::CMailfile: subject= $subject , deliveryreceipt= $deliveryreceipt , msgishtml= $msgishtml " );
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 ]);
}
}
2006-11-01 00:10:46 +01:00
// On defini mime_boundary
$this -> mime_boundary = md5 ( uniqid ( " dolibarr " ));
2005-06-25 15:02:39 +02:00
2006-08-06 20:34:37 +02:00
// On definit fin de ligne
$this -> eol = " \n " ;
if ( eregi ( '^win' , PHP_OS )) $this -> eol = " \r \n " ;
if ( eregi ( '^mac' , PHP_OS )) $this -> eol = " \r " ;
2006-11-01 00:10:46 +01:00
// On defini si message HTML
2007-10-04 21:59:21 +02:00
if ( $msgishtml == 2 )
{
$this -> msgishtml = 0 ;
if ( eregi ( '<html' , $msg )) $this -> msgishtml = 1 ;
elseif ( eregi ( '<body' , $msg )) $this -> msgishtml = 1 ;
elseif ( eregi ( '<br' , $msg )) $this -> msgishtml = 1 ;
}
else
{
$this -> msgishtml = $msgishtml ;
}
2006-08-06 20:34:37 +02:00
2006-11-01 00:10:46 +01:00
$smtp_headers = " " ;
$mime_headers = " " ;
$text_body = " " ;
$text_encoded = " " ;
// En-tete dans $smtp_headers
2005-06-25 15:02:39 +02:00
$this -> subject = $subject ;
2006-08-06 20:34:37 +02:00
$this -> addr_from = $from ;
2007-07-30 16:44:47 +02:00
$this -> errors_to = $errors_to ;
2005-06-25 15:02:39 +02:00
$this -> addr_to = $to ;
$this -> addr_cc = $addr_cc ;
$this -> addr_bcc = $addr_bcc ;
2006-06-26 17:15:51 +02:00
$this -> deliveryreceipt = $deliveryreceipt ;
2006-11-01 00:10:46 +01:00
$smtp_headers = $this -> write_smtpheaders ();
2006-08-06 20:34:37 +02:00
2006-11-01 00:10:46 +01:00
// En-tete suite dans $mime_headers
2006-08-06 20:34:37 +02:00
if ( $this -> atleastonefile )
2005-06-25 15:02:39 +02:00
{
2006-11-01 00:10:46 +01:00
$mime_headers = $this -> write_mimeheaders ( $filename_list , $mimefilename_list );
2006-08-06 20:34:37 +02:00
}
2004-07-16 08:41:58 +02:00
2006-11-01 00:10:46 +01:00
// Corps message dans $text_body
$text_body = $this -> write_body ( $msg , $filename_list );
2006-08-06 20:34:37 +02:00
2006-11-01 00:10:46 +01:00
// Corps message suite (fichiers attach<63> s) dans $text_encoded
2006-08-06 20:34:37 +02:00
if ( $this -> atleastonefile )
2005-06-25 15:02:39 +02:00
{
2006-11-01 00:10:46 +01:00
$text_encoded = $this -> write_files ( $filename_list , $mimetype_list , $mimefilename_list );
2005-06-25 15:02:39 +02:00
}
2006-11-01 00:10:46 +01:00
// On defini $this->headers et $this->message
2007-07-08 19:50:52 +02:00
//$this->headers = $smtp_headers . $mime_headers . $this->eol;
//$this->message = $text_body . $text_encoded . $this->eol;
$this -> headers = $smtp_headers . $mime_headers ;
$this -> message = $text_body . $text_encoded ;
// On nettoie le header pour qu'il ne se termine pas un retour chariot.
// Ceci evite aussi les lignes vides en fin qui peuvent etre interpr<70> t<EFBFBD> es
// comme des injections mail par les serveurs de messagerie.
$this -> headers = eregi_replace ( " [ \r \n ]+ $ " , " " , $this -> headers );
2003-07-07 12:04:20 +02:00
}
2002-04-30 12:44:42 +02:00
2004-07-16 08:41:58 +02:00
2004-12-28 19:34:56 +01:00
/**
2005-06-25 15:02:39 +02:00
\brief Permet d ' encoder un fichier
\param sourcefile
2005-07-11 22:12:45 +02:00
\return < 0 si erreur , fichier encod<EFBFBD> si ok
2004-12-28 19:34:56 +01:00
*/
2006-08-06 20:34:37 +02:00
function _encode_file ( $sourcefile )
2003-07-07 12:04:20 +02:00
{
2005-06-25 15:02:39 +02:00
if ( is_readable ( $sourcefile ))
{
$fd = fopen ( $sourcefile , " r " );
$contents = fread ( $fd , filesize ( $sourcefile ));
2006-08-06 20:34:37 +02:00
$encoded = chunk_split ( base64_encode ( $contents ), 68 , $this -> eol );
//$encoded = _chunk_split(base64_encode($contents));
2005-06-25 15:02:39 +02:00
fclose ( $fd );
2005-07-11 22:12:45 +02:00
return $encoded ;
2005-06-25 15:02:39 +02:00
}
else
{
2006-08-06 20:34:37 +02:00
$this -> error = " Error: Can't read file ' $sourcefile ' " ;
dolibarr_syslog ( " CMailFile::encode_file: " . $this -> error );
2005-07-11 22:12:45 +02:00
return - 1 ;
2005-06-25 15:02:39 +02:00
}
}
2004-07-16 08:41:58 +02:00
2004-12-28 19:34:56 +01:00
/**
2005-06-25 15:02:39 +02:00
\brief Envoi le mail
2006-08-06 20:34:37 +02:00
\return boolean true si mail envoy<EFBFBD> , false sinon
2004-12-28 19:34:56 +01:00
*/
2007-06-07 23:24:01 +02:00
function sendfile ()
{
global $conf ;
2007-07-30 16:44:47 +02:00
dolibarr_syslog ( " CMailFile::sendfile addr_to= " . $this -> addr_to . " , subject= " . $this -> subject );
2007-06-07 23:24:01 +02:00
dolibarr_syslog ( " CMailFile::sendfile header= \n " . $this -> headers );
//dolibarr_syslog("CMailFile::sendfile message=\n".$message);
//$this->send_to_file();
2005-06-25 15:02:39 +02:00
2007-06-07 23:24:01 +02:00
$errorlevel = error_reporting ();
error_reporting ( $errorlevel ^ E_WARNING ); // D<> sactive warnings
2006-08-06 20:34:37 +02:00
2007-06-07 23:24:01 +02:00
$res = false ;
2007-04-01 04:56:53 +02:00
2007-06-07 23:24:01 +02:00
if ( ! $conf -> global -> MAIN_DISABLE_ALL_MAILS )
{
// Si Windows, addr_from doit obligatoirement etre d<> fini
if ( isset ( $_SERVER [ " WINDIR " ]))
{
if ( ! $this -> addr_from ) $this -> addr_from = 'robot@mydomain.com' ;
if ( $this -> addr_from ) @ ini_set ( 'sendmail_from' , getValidAddress ( $this -> addr_from , 2 ));
// Forcage parametres
// \TODO A mettre pout tout OS ?
if ( $conf -> global -> MAIN_MAIL_SMTP_SERVER ) ini_set ( 'SMTP' , $conf -> global -> MAIN_MAIL_SMTP_SERVER );
if ( $conf -> global -> MAIN_MAIL_SMTP_PORT ) ini_set ( 'smtp_port' , $conf -> global -> MAIN_MAIL_SMTP_PORT );
}
$dest = getValidAddress ( $this -> addr_to , 2 );
2007-04-01 04:56:53 +02:00
if ( ! $dest )
{
$this -> error = " Failed to send mail to SMTP= " . ini_get ( 'SMTP' ) . " , PORT= " . ini_get ( 'smtp_port' ) . " <br>Recipient address ' $dest ' invalid " ;
dolibarr_syslog ( " CMailFile::sendfile: mail end error= " . $this -> error );
}
else
{
2007-07-30 16:44:47 +02:00
/* Le errors_to doit se gerer dans en - tete http et non par option - f
2007-04-01 04:56:53 +02:00
if ( $this -> errors_to )
2007-06-06 16:53:31 +02:00
{
2007-04-01 04:56:53 +02:00
// \TODO Tester que le safe_mode est inactif car fonction mail avec ces param non dispo en safe_mode
2007-06-07 23:24:01 +02:00
dolibarr_syslog ( " CMailFile::sendfile: mail start SMTP= " . ini_get ( 'SMTP' ) . " , PORT= " . ini_get ( 'smtp_port' ) . " , with errorsto : " . getValidAddress ( $this -> errors_to , 1 ));
2007-04-01 04:56:53 +02:00
$res = mail ( $dest , $this -> subject , stripslashes ( $this -> message ), $this -> headers , " -f " . getValidAddress ( $this -> errors_to , 2 ));
2007-06-07 23:24:01 +02:00
}
else
2007-07-30 16:44:47 +02:00
{ */
2007-06-07 23:24:01 +02:00
dolibarr_syslog ( " CMailFile::sendfile: mail start SMTP= " . ini_get ( 'SMTP' ) . " , PORT= " . ini_get ( 'smtp_port' ));
//dolibarr_syslog("to=".getValidAddress($this->addr_to,2).", subject=".$this->subject.", message=".stripslashes($this->message).", header=".$this->headers);
2007-04-01 04:56:53 +02:00
$res = mail ( $dest , $this -> subject , stripslashes ( $this -> message ), $this -> headers );
2007-07-30 16:44:47 +02:00
/* } */
2007-06-07 23:24:01 +02:00
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 " ;
dolibarr_syslog ( " CMailFile::sendfile: mail end error= " . $this -> error );
}
else
{
dolibarr_syslog ( " CMailFile::sendfile: mail end success " );
}
2007-04-01 04:56:53 +02:00
}
2007-06-07 23:24:01 +02:00
2007-06-06 17:38:33 +02:00
if ( isset ( $_SERVER [ " WINDIR " ]))
{
2007-06-07 23:24:01 +02:00
@ ini_restore ( 'sendmail_from' );
// Forcage parametres
// \TODO A mettre pout tout OS ?
2007-06-06 17:38:33 +02:00
if ( $conf -> global -> MAIN_MAIL_SMTP_SERVER ) ini_restore ( 'SMTP' );
2007-06-07 23:24:01 +02:00
if ( $conf -> global -> MAIN_MAIL_SMTP_PORT ) ini_restore ( 'smtp_port' );
2007-06-06 17:38:33 +02:00
}
2006-08-06 20:34:37 +02:00
}
else
{
2007-06-07 23:24:01 +02:00
$this -> error = 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS' ;
2007-05-26 17:05:49 +02:00
dolibarr_syslog ( " CMailFile::sendfile: " . $this -> error );
2006-04-01 03:10:38 +02:00
}
2005-06-25 15:02:39 +02:00
2007-06-07 23:24:01 +02:00
error_reporting ( $errorlevel ); // R<> active niveau erreur origine
2005-06-25 15:02:39 +02:00
2007-06-07 23:24:01 +02:00
return $res ;
}
2005-06-25 15:02:39 +02:00
2006-08-06 20:34:37 +02:00
2005-06-25 15:02:39 +02:00
/**
* \brief Ecrit le mail dans un fichier .
* Utilisation pour le debuggage
*/
2006-08-06 20:34:37 +02:00
function send_to_file ()
2005-06-25 15:02:39 +02:00
{
2006-08-06 20:34:37 +02:00
$fp = fopen ( " /tmp/dolibarr_mail " , " w " );
2006-11-01 00:10:46 +01:00
fputs ( $fp , $this -> headers );
fputs ( $fp , $this -> message );
2005-06-25 15:02:39 +02:00
fclose ( $fp );
2003-07-07 12:04:20 +02:00
}
2004-07-16 08:41:58 +02:00
2006-08-06 20:34:37 +02:00
2004-12-28 19:34:56 +01:00
/**
2006-08-06 20:34:37 +02:00
\brief Cr<EFBFBD> ation des headers smtp
2004-12-28 19:34:56 +01:00
*/
2006-08-06 20:34:37 +02:00
function write_smtpheaders ()
2003-07-07 12:04:20 +02:00
{
2007-05-25 22:02:23 +02:00
global $conf ;
$out = " " ;
2006-08-06 20:34:37 +02:00
// Sender
//$out .= "X-Sender: ".getValidAddress($this->addr_from,2).$this->eol;
$out .= " From: " . 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 -> errors_to ) && $this -> errors_to ) $out .= " Errors-To: " . getValidAddress ( $this -> errors_to , 2 ) . $this -> eol ;
// Receiver
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 ;
// Accus<75> r<> ception
2007-06-01 15:04:29 +02:00
if ( isset ( $this -> deliveryreceipt ) && $this -> deliveryreceipt == 1 ) $out .= " Disposition-Notification-To: " . getValidAddress ( $this -> addr_from , 2 ) . $this -> eol ;
2006-08-06 20:34:37 +02:00
2007-07-08 19:50:52 +02:00
//$out .= "X-Priority: 3".$this->eol;
2006-08-06 20:34:37 +02:00
$out .= " X-Mailer: Dolibarr version " . DOL_VERSION . $this -> eol ;
2006-11-01 00:10:46 +01:00
$out .= " MIME-Version: 1.0 " . $this -> eol ;
2006-08-06 20:34:37 +02:00
if ( $this -> msgishtml )
2006-07-22 17:09:22 +02:00
{
2007-05-26 17:05:49 +02:00
$out .= " Content-Type: text/html; charset= " . $conf -> character_set_client . $this -> eol ;
2006-08-06 20:34:37 +02:00
$out .= " Content-Transfer-Encoding: 8bit " . $this -> eol ;
2006-07-22 17:09:22 +02:00
}
else
{
2006-08-06 20:34:37 +02:00
$out .= " Content-Transfer-Encoding: 7bit " . $this -> eol ;
}
2007-07-08 19:50:52 +02:00
dolibarr_syslog ( " CMailFile::write_smtpheaders smtp_header= \n " . $out );
2006-08-06 20:34:37 +02:00
return $out ;
}
/**
\brief Cr<EFBFBD> ation header MIME
\param filename_list
\param mimefilename_list
*/
function write_mimeheaders ( $filename_list , $mimefilename_list )
{
$mimedone = 0 ;
2006-11-01 00:10:46 +01:00
$out = " " ;
2006-08-06 20:34:37 +02:00
for ( $i = 0 ; $i < count ( $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 ];
$out .= " X-attachments: $filename_list[$i] " . $this -> eol ;
}
2006-07-22 17:09:22 +02:00
}
2007-07-08 19:50:52 +02:00
//$out.= $this->eol;
dolibarr_syslog ( " CMailFile::write_mimeheaders mime_header= \n " . $out );
2005-06-25 15:02:39 +02:00
return $out ;
2003-07-07 12:04:20 +02:00
}
2004-07-16 08:41:58 +02:00
2004-12-28 19:34:56 +01:00
/**
2006-08-06 20:34:37 +02:00
\brief Permet d ' ecrire le corps du message
\param msgtext
\param filename_list
2004-12-28 19:34:56 +01:00
*/
2006-08-06 20:34:37 +02:00
function write_body ( $msgtext , $filename_list )
{
$out = '' ;
2006-11-01 00:10:46 +01:00
2006-08-06 20:34:37 +02:00
if ( $this -> atleastonefile )
{
$out .= " -- " . $this -> mime_boundary . $this -> eol ;
if ( $this -> msgishtml )
{
2007-05-26 01:24:21 +02:00
$out .= " Content-Type: text/html; charset= " . $conf -> charset_output . $this -> eol ;
2006-08-06 20:34:37 +02:00
}
2007-08-26 18:40:54 +02:00
else
{
$out .= " Content-Type: text/plain; charset= " . $conf -> charset_output . $this -> eol ;
}
2006-08-06 20:34:37 +02:00
$out .= $this -> eol ;
}
if ( $this -> msgishtml )
{
// Check if html header already in message
$htmlalreadyinmsg = 0 ;
if ( eregi ( '^[ \t]*<html>' , $msgtext )) $htmlalreadyinmsg = 1 ;
if ( ! $htmlalreadyinmsg ) $out .= " <html><head><title></title></head><body> " ;
$out .= $msgtext ;
if ( ! $htmlalreadyinmsg ) $out .= " </body></html> " ;
}
else
{
$out .= $msgtext ;
2005-06-25 15:02:39 +02:00
}
2006-08-06 20:34:37 +02:00
$out .= $this -> eol ;
2005-06-25 15:02:39 +02:00
return $out ;
2004-01-08 12:43:33 +01:00
}
2004-07-16 08:41:58 +02:00
2004-12-28 19:34:56 +01:00
/**
2006-08-06 20:34:37 +02:00
\brief Permet d ' attacher un fichier
\param filename_list Tableau
\param mimetype_list Tableau
\param mimefilename_list Tableau
\return out Chaine fichiers encod<EFBFBD> s
2004-12-28 19:34:56 +01:00
*/
2006-08-06 20:34:37 +02:00
function write_files ( $filename_list , $mimetype_list , $mimefilename_list )
2003-07-07 12:04:20 +02:00
{
2006-11-01 00:10:46 +01:00
$out = '' ;
2006-06-26 17:15:51 +02:00
2006-08-06 20:34:37 +02:00
for ( $i = 0 ; $i < count ( $filename_list ); $i ++ )
2006-07-22 17:09:22 +02:00
{
2006-08-06 20:34:37 +02:00
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 ;
$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 ;
2006-11-01 00:10:46 +01:00
// $out.= $this->eol;
2006-08-06 20:34:37 +02:00
}
else
{
return $encoded ;
}
}
2006-07-22 17:09:22 +02:00
}
2005-06-25 15:02:39 +02:00
2006-08-06 20:34:37 +02:00
// Fin de tous les attachements
$out = $out . " -- " . $this -> mime_boundary . " -- " . $this -> eol ;
2005-06-25 15:02:39 +02:00
return $out ;
2003-07-07 12:04:20 +02:00
}
2006-08-06 20:34:37 +02:00
}
/**
\brief Renvoie une adresse accept<EFBFBD> e par le serveur SMTP
2007-04-01 04:56:53 +02:00
\param adresses Exemple : 'John Doe <john@doe.com>' ou 'john@doe.com'
2006-08-06 20:34:37 +02:00
\param format 0 = Auto , 1 = emails avec <> , 2 = emails sans <>
2007-04-01 04:56:53 +02:00
\return string Renvoi : Si format 1 : '<john@doe.com>' ou 'John Doe <john@doe.com>'
Si format 2 : 'john@doe.com'
2006-08-06 20:34:37 +02:00
*/
function getValidAddress ( $adresses , $format )
{
global $conf ;
$ret = " " ;
$arrayaddress = split ( ',' , $adresses );
2004-12-28 19:34:56 +01:00
2006-08-06 20:34:37 +02:00
// Boucle sur chaque composant de l'adresse
foreach ( $arrayaddress as $val )
{
2007-04-01 04:56:53 +02:00
if ( eregi ( '^(.*)<(.*)>$' , trim ( $val ), $regs ))
2006-08-06 20:34:37 +02:00
{
$name = trim ( $regs [ 1 ]);
$email = trim ( $regs [ 2 ]);
}
else
{
$name = '' ;
$email = trim ( $val );
}
2007-04-01 04:56:53 +02:00
if ( $email )
2006-08-06 20:34:37 +02:00
{
2007-04-01 04:56:53 +02:00
$newemail = '' ;
if ( $format == 2 )
{
$newemail = $email ;
}
if ( $format == 1 )
{
$neweamil = '<' . $email . '>' ;
}
if ( $format == 0 )
{
if ( $conf -> global -> MAIN_MAIL_NO_FULL_EMAIL ) $newemail = '<' . $email . '>' ;
elseif ( ! $name ) $newemail = '<' . $email . '>' ;
else $newemail = $name . ' <' . $email . '>' ;
}
$ret = ( $ret ? $ret . ',' : '' ) . $newemail ;
2006-08-06 20:34:37 +02:00
}
}
return $ret ;
2002-04-30 12:44:42 +02:00
}
2004-12-28 19:34:56 +01:00
2004-12-28 19:24:19 +01:00
/**
2005-06-25 15:02:39 +02:00
\brief Permet de diviser une chaine ( RFC2045 )
\param str
\remarks function chunk_split qui remplace celle de php si n<EFBFBD> c<EFBFBD> ssaire
2006-08-06 20:34:37 +02:00
\remarks 76 caract<EFBFBD> res par ligne , termin<EFBFBD> par " \n "
2004-07-16 08:41:58 +02:00
*/
2006-08-06 20:34:37 +02:00
function _chunk_split ( $str )
2002-04-30 12:44:42 +02:00
{
2005-06-25 15:02:39 +02:00
$stmp = $str ;
$len = strlen ( $stmp );
$out = " " ;
while ( $len > 0 ) {
if ( $len >= 76 ) {
2006-08-06 20:34:37 +02:00
$out = $out . substr ( $stmp , 0 , 76 ) . " \n " ;
2005-06-25 15:02:39 +02:00
$stmp = substr ( $stmp , 76 );
$len = $len - 76 ;
}
else {
2006-08-06 20:34:37 +02:00
$out = $out . $stmp . " \n " ;
2005-06-25 15:02:39 +02:00
$stmp = " " ; $len = 0 ;
}
2003-07-08 21:50:04 +02:00
}
2005-06-25 15:02:39 +02:00
return $out ;
2002-04-30 12:44:42 +02:00
}
2004-12-28 19:34:56 +01:00
2002-04-30 12:44:42 +02:00
?>