Path

ez.no / developer / contribs / hacks / ezmail debug


eZMail Debug

Author Version Downloads Compatible with
Kristof Coomans 1.1 1368 3.6.4, 3.7.2
The changes in this patch allow you to debug e-mail messages. All e-mail will be send to a specified address. Custom headers with the original receivers are added to each e-mail.

Description

Due to overdone censoring by eZ Systems, I decided not to host my project here or on eZ Projects any longer. A link to a new home for the project will be available soon.

Changelog

* v1.1 2006-01-10
- repackaged with patches for eZ publish 3.6.4 & 3.7.2

* v1.0:
- Initial public release

Comments

patch - 4.0.2

think this should be the correct updated version.




Index: ezmail.php


===================================================================


--- ezmail.php  (revision 22999)


+++ ezmail.php  (working copy)


@@ -8,7 +8,8 @@


 //


 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##


 // SOFTWARE NAME: eZ Publish


-// SOFTWARE RELEASE: 4.0.x


+// SOFTWARE RELEASE: 4.0.2


+// SHOULD WORK WITH 4.0.0 AND UP


 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS


 // SOFTWARE LICENSE: GNU General Public License v2.0


 // NOTICE: >


@@ -26,9 +27,22 @@


 //  Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,


 //  MA 02110-1301, USA.


 //


+// eZMail changes to support mail debugging


+// Copyright (C) 2005 SCK-CEN (Belgian Nuclear Research Centre)


+// Written by Kristof Coomans


+// Applied to eZ Publish 4.0.0 by Bruce Morrison <bruce@stuffandcontent.com> 29 Jan 2008


+// Merged with updates to eZ Publish 4.0.2 by Michiel N. <michieln@gmail.com> 17 Feb 2009


+//  

+// 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.


 //


-// ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##


-//


 

 /*! \defgroup eZUtils Utility classes */


 

@@ -83,6 +97,21 @@


 

        if ( $ini->hasVariable( 'MailSettings', 'ContentType' ) )


            $this->setContentType( $ini->variable( 'MailSettings', 'ContentType' ) );


+       $maildebugIni = eZINI::instance( 'site.ini' );


+


+       if ( $maildebugIni->hasVariable( 'MailSettings', 'Debug' ) and $maildebugIni->variable( 'MailSettings', 'Debug' ) == 'enabled' )


+       {


+           $this->Debug = true;


+       }


+       else


+       {


+           $this->Debug = false;


+       }


+        

+       if ( $this->Debug )


+       {


+           $this->ReceiverElements[] = array( 'name' => 'mail-debugger', 'email' => $maildebugIni->variable( 'MailSettings', 'DebugReceiverAddress' ) );


+       }


    }


 

    /*!


@@ -285,7 +314,14 @@


    */


    function setReceiverElements( $toElements )


    {


-       $this->ReceiverElements = $toElements;


+       if ( $this->Debug )


+       {


+           $this->addExtraHeader( 'x-debug-to', $this->composeEmailItems( $toElements, true, false, true ) );


+       }


+       else


+       {


+           $this->ReceiverElements = $toElements;


+       }


    }


 

    /*!


@@ -295,8 +331,16 @@


    */


    function setReceiver( $email, $name = false )


    {


-       $this->ReceiverElements = array( array( 'name' => $name,


-                                               'email' => $email ) );


+       if ( $this->Debug )


+       {


+           $to = array( array( 'name' => $name, 'email' => $email ) );


+           $this->addExtraHeader( 'x-debug-to', $this->composeEmailItems( $to, true, false, true ) );


+       }


+       else


+       {


+           $this->ReceiverElements = array( array( 'name' => $name,


+                                                   'email' => $email ) );


+       }


    }


 

    /*!


@@ -307,8 +351,16 @@


    function setReceiverText( $text )


    {


        $this->extractEmail( $text, $email, $name );


-       $this->ReceiverElements = array( array( 'name' => $name,


-                                               'email' => $email ) );


+       if ( $this->Debug )


+       {


+           $to = array( array( 'name' => $name, 'email' => $email ) );


+           $this->addExtraHeader( 'x-debug-to', $this->composeEmailItems( $to, true, false, true ) );


+       }


+       else


+       {


+           $this->ReceiverElements = array( array( 'name' => $name,


+                                                   'email' => $email ) );


+       }


    }


 

    /*!


@@ -316,8 +368,16 @@


    */


    function addReceiver( $email, $name = false )


    {


-       $this->ReceiverElements[] = array( 'name' => $name,


-                                          'email' => $email );


+       if ( $this->Debug )


+       {


+           $to = array( array( 'name' => $name, 'email' => $email ) );


+           $this->addExtraHeader( 'x-debug-to', $this->composeEmailItems( $to, true, false, true ) );


+       }


+       else


+       {


+           $this->ReceiverElements[] = array( 'name' => $name,


+                                              'email' => $email );


+       }


    }


 

 

@@ -354,7 +414,14 @@


     */


    function setCcElements( $newCc )


    {


-       $this->CcElements = $newCc;


+       if ( $this->Debug )


+       {


+           $this->addExtraHeader( 'x-debug-cc', $this->composeEmailItems( $newCc, true, false, true ) );


+       }


+       else


+       {


+           $this->CcElements = $newCc;


+       }


    }


 

    /*!


@@ -362,8 +429,16 @@


    */


    function addCc( $email, $name = false )


    {


-       $this->CcElements[] = array( 'name' => $name,


-                                    'email' => $email );


+       if ( $this->Debug )


+       {


+           $cc = array( array( 'name' => $name, 'email' => $email ) );


+           $this->addExtraHeader( 'x-debug-cc', $this->composeEmailItems( $cc, true, false, true ) );


+       }


+       else


+       {


+           $this->CcElements[] = array( 'name' => $name,


+                                        'email' => $email );


+       }


    }


 

    /*!


@@ -371,7 +446,14 @@


     */


    function setBccElements( $newBcc )


    {


-       $this->BccElements = $newBcc;


+       if ( $this->Debug )


+       {


+           $this->addExtraHeader( 'x-debug-bcc', $this->composeEmailItems( $newBcc, true, false, true ) );


+       }


+       else


+       {


+           $this->BccElements = $newBcc;


+       }


    }


 

    /*!


@@ -379,8 +461,16 @@


    */


    function addBcc( $email, $name = false )


    {


-       $this->BccElements[] = array( 'name' => $name,


-                                     'email' => $email );


+       if ( $this->Debug )


+       {


+           $bcc = array( array( 'name' => $name, 'email' => $email ) );


+           $this->addExtraHeader( 'x-debug-bcc', $this->composeEmailItems( $bcc, true, false, true ) );


+       }


+       else


+       {


+           $this->BccElements[] = array( 'name' => $name,


+                                         'email' => $email );


+       }


    }


 

    /*!


@@ -515,7 +605,8 @@


    */


    static function validate( $address )


    {


-       return preg_match( '/^' . eZMail::REGEXP . '$/', $address );


+       $pos = ( ereg( '^' . eZMail::REGEXP . '$', $address) );


+       return $pos;


    }


 

    static function extractEmail( $text, &$email, &$name )


@@ -523,7 +614,7 @@


        if ( preg_match( "/([^<]+)<" . eZMail::REGEXP . ">/", $text, $matches ) )


        {


            $email = $matches[2];


-           $name = trim( $matches[1], '" ' );


+           $name = $matches[1];


        }


        else


        {


@@ -540,8 +631,7 @@


    */


    static function stripEmail( $address )


    {


-       $res = preg_match( "/" . eZMail::REGEXP . "/", $address, $email );


-


+       $res = ereg( eZMail::REGEXP, $address, $email );


        if ( $res )


            return $email[0];


        else


@@ -637,7 +727,7 @@


        {


            $toHeaderContent = count( $this->ReceiverElements ) > 0 ? $this->composeEmailItems( $this->ReceiverElements ) : 'undisclosed-recipients:;';


            $headers[] = array( 'name' => 'To',


-                               'content' => $toHeaderContent );


+                               'content' => $this->composeEmailItems( $this->ReceiverElements ) );


            $headerNames[] = 'to';


        }


        if ( !in_array( 'date', $excludeHeaders ) )


@@ -944,6 +1034,7 @@


    public $ExtraHeaders;


    public $TextCodec;


    public $MessageID;


+   public $Debug;


 }


 

 ?>


Multiple addresses overwritten

If you have a message that is sent to multiple addresses, say multiple CC addresses that you will only see one x-debug-cc: header. The code overwrites all but the last version.

log in or create a user account to comment.

Contribution info (stable)

Download