eZ Publish  [trunk]
ezmailnotificationtransport.php
Go to the documentation of this file.
00001 <?php
00002 /**
00003  * File containing the eZMailNotificationTransport class.
00004  *
00005  * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
00006  * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
00007  * @version //autogentag//
00008  * @package kernel
00009  */
00010 
00011 /*!
00012   \class eZMailNotificationTransport ezmailnotificationtransport.php
00013   \brief The class eZMailNotificationTransport does
00014 
00015 */
00016 
00017 class eZMailNotificationTransport extends eZNotificationTransport
00018 {
00019     /*!
00020      Constructor
00021     */
00022     function eZMailNotificationTransport()
00023     {
00024         $this->eZNotificationTransport();
00025     }
00026 
00027     function send( $addressList = array(), $subject, $body, $transportData = null, $parameters = array() )
00028     {
00029         $ini = eZINI::instance();
00030         $mail = new eZMail();
00031         $addressList = $this->prepareAddressString( $addressList, $mail );
00032 
00033         if ( $addressList == false )
00034         {
00035             eZDebug::writeError( 'Error with receiver', __METHOD__ );
00036             return false;
00037         }
00038 
00039         $notificationINI = eZINI::instance( 'notification.ini' );
00040         $emailSender = $notificationINI->variable( 'MailSettings', 'EmailSender' );
00041         if ( !$emailSender )
00042             $emailSender = $ini->variable( 'MailSettings', 'EmailSender' );
00043         if ( !$emailSender )
00044             $emailSender = $ini->variable( "MailSettings", "AdminEmail" );
00045 
00046         foreach ( $addressList as $addressItem )
00047         {
00048             $mail->extractEmail( $addressItem, $email, $name );
00049             $mail->addBcc( $email, $name );
00050         }
00051         $mail->setSender( $emailSender );
00052         $mail->setSubject( $subject );
00053         $mail->setBody( $body );
00054         if ( isset( $parameters['message_id'] ) )
00055             $mail->addExtraHeader( 'Message-ID', $parameters['message_id'] );
00056         if ( isset( $parameters['references'] ) )
00057             $mail->addExtraHeader( 'References', $parameters['references'] );
00058         if ( isset( $parameters['reply_to'] ) )
00059             $mail->addExtraHeader( 'In-Reply-To', $parameters['reply_to'] );
00060         if ( isset( $parameters['from'] ) )
00061             $mail->setSenderText( $parameters['from'] );
00062         if ( isset( $parameters['content_type'] ) )
00063             $mail->setContentType( $parameters['content_type'] );
00064         $mailResult = eZMailTransport::send( $mail );
00065         return $mailResult;
00066     }
00067 
00068 
00069     function prepareAddressString( $addressList, $mail )
00070     {
00071         if ( is_array( $addressList ) )
00072         {
00073             $validatedAddressList = array();
00074             foreach ( $addressList as $address )
00075             {
00076                 if ( $mail->validate( $address ) )
00077                 {
00078                     $validatedAddressList[] = $address;
00079                 }
00080             }
00081 //             $addressString = '';
00082 //             if ( count( $validatedAddressList ) > 0 )
00083 //             {
00084 //                 $addressString = implode( ',', $validatedAddressList );
00085 //                 return $addressString;
00086 //             }
00087             return $validatedAddressList;
00088         }
00089         else if ( strlen( $addressList ) > 0 )
00090         {
00091             if ( $mail->validate( $addressList ) )
00092             {
00093                 return $addressList;
00094             }
00095         }
00096         return false;
00097     }
00098 }
00099 
00100 ?>