Skip to content

Commit

Permalink
Fixed #019032: Mail Headers are not encoded when using SMTP
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérôme Vieilledent committed Jan 3, 2012
1 parent 12e416f commit a7f14ad
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 15 deletions.
1 change: 1 addition & 0 deletions autoload/ezp_kernel.php
Expand Up @@ -603,6 +603,7 @@
'ezpLanguageSwitcherFunctionCollection' => 'kernel/private/modules/switchlanguage/ezpLanguageSwitcherFunctionCollection.php',
'ezpLanguageSwitcherOperator' => 'kernel/private/eztemplate/ezplanguageswitcheroperator.php',
'ezpLocation' => 'kernel/private/api/location.php',
'ezpMail' => 'kernel/private/classes/ezpmail.php',
'ezpMobileDeviceDetect' => 'kernel/private/classes/ezpmobiledevicedetect.php',
'ezpMobileDeviceDetectFilter' => 'kernel/private/classes/ezpmobiledevicedetectfilter.php',
'ezpMobileDeviceDetectFilterInterface' => 'kernel/private/classes/ezpmobiledevicedetectfilterinterface.php',
Expand Down
35 changes: 35 additions & 0 deletions kernel/private/classes/ezpmail.php
@@ -0,0 +1,35 @@
<?php
/**
* File containing the ezpMail class.
*
* @copyright Copyright (C) 1999-2011 eZ Systems AS. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
* @version //autogentag//
*/

/**
* ezpMail extends ezcMail in order to override default values and limitations.
*/
class ezpMail extends ezcMail
{
/**
* Override of original {@link ezcMail::generateHeaders()}.
* Allows headers customization
*
* @return string The mail headers
*/
public function generateHeaders()
{
// Workaround for encoded email addresses.
// When encoded, email addresses (at least the name param) have more characters
// By default, line length is set to 76 characters, after what a new line is created with $lineBreak.
// This operation is done during encoding via iconv (see ezcMailTools::composeEmailAddress()).
// Problem is that this operation is done a 2nd time in ezcMailPart::generateHeaders().
// Following code ensures that there is no double $lineBreak introduced
// by this process because it potentially breaks headers
$lineBreak = ezcMailTools::lineBreak();
$headers = str_replace( "$lineBreak$lineBreak", $lineBreak, parent::generateHeaders() );
return $headers;
}
}
?>
30 changes: 15 additions & 15 deletions lib/ezutils/classes/ezmail.php
Expand Up @@ -47,9 +47,9 @@
Instead of the code above, ezcMail will be used together with the SMTP
transport from eZ Components (MTA transport will work as well):
$mail = new ezcMail();
$mail->from = new ezcMailAddress( $fromEmail, $yourName );
$mail->addTo( new ezcMailAddress( $receiversEmail, $receiversName ) );
$mail = new ezpMail();
$mail->from = new ezcMailAddress( $fromEmail, $yourName, $charset );
$mail->addTo( new ezcMailAddress( $receiversEmail, $receiversName, $charset ) );
$mail->subject = $subject;
$smtp = new ezcMailSmtpTransport( $host, $username, $password, $port );
Expand All @@ -65,7 +65,7 @@ class eZMail
*/
function eZMail()
{
$this->Mail = new ezcMail();
$this->Mail = new ezpMail();

$this->ReceiverElements = array();
$this->From = false;
Expand Down Expand Up @@ -423,7 +423,7 @@ function setReceiverElements( $toElements )
foreach ( $toElements as $address )
{
$name = isset( $address['name'] ) ? $address['name'] : false;
$this->Mail->addTo( new ezcMailAddress( $address['email'], $name ) );
$this->Mail->addTo( new ezcMailAddress( $address['email'], $name, $this->usedCharset() ) );
}
$this->ReceiverElements = $toElements;
}
Expand All @@ -437,7 +437,7 @@ function setReceiverElements( $toElements )
*/
function setReceiver( $email, $name = false )
{
$this->Mail->to = array( new ezcMailAddress( $email, $name ) );
$this->Mail->to = array( new ezcMailAddress( $email, $name, $this->usedCharset() ) );
$this->ReceiverElements = array( array( 'name' => $name,
'email' => $email ) );
}
Expand All @@ -452,7 +452,7 @@ function setReceiver( $email, $name = false )
function setReceiverText( $text )
{
$this->extractEmail( $text, $email, $name );
$this->Mail->to = array( new ezcMailAddress( $email, $name ) );
$this->Mail->to = array( new ezcMailAddress( $email, $name, $this->usedCharset() ) );
$this->ReceiverElements = array( array( 'name' => $name,
'email' => $email ) );
}
Expand All @@ -464,7 +464,7 @@ function setReceiverText( $text )
*/
function addReceiver( $email, $name = false )
{
$this->Mail->addTo( new ezcMailAddress( $email, $name ) );
$this->Mail->addTo( new ezcMailAddress( $email, $name, $this->usedCharset() ) );
$this->ReceiverElements[] = array( 'name' => $name,
'email' => $email );
}
Expand All @@ -476,7 +476,7 @@ function addReceiver( $email, $name = false )
*/
function setReplyTo( $email, $name = false )
{
$this->Mail->setHeader( 'Reply-To', new ezcMailAddress( $email, $name ) );
$this->Mail->setHeader( 'Reply-To', new ezcMailAddress( $email, $name, $this->usedCharset() ) );
$this->ReplyTo = array( 'name' => $name,
'email' => $email );
}
Expand All @@ -488,7 +488,7 @@ function setReplyTo( $email, $name = false )
*/
function setSender( $email, $name = false )
{
$this->Mail->from = new ezcMailAddress( $email, $name );
$this->Mail->from = new ezcMailAddress( $email, $name, $this->usedCharset() );
$this->From = array( 'name' => $name,
'email' => $email );
}
Expand All @@ -501,7 +501,7 @@ function setSender( $email, $name = false )
function setSenderText( $text )
{
$this->extractEmail( $text, $email, $name );
$this->Mail->from = new ezcMailAddress( $email, $name );
$this->Mail->from = new ezcMailAddress( $email, $name, $this->usedCharset() );
$this->From = array( 'name' => $name,
'email' => $email );
}
Expand All @@ -517,7 +517,7 @@ function setCcElements( $newCc )
foreach ( $newCc as $address )
{
$name = isset( $address['name'] ) ? $address['name'] : false;
$this->Mail->addCc( new ezcMailAddress( $address['email'], $name ) );
$this->Mail->addCc( new ezcMailAddress( $address['email'], $name, $this->usedCharset() ) );
}
$this->CcElements = $newCc;
}
Expand All @@ -529,7 +529,7 @@ function setCcElements( $newCc )
*/
function addCc( $email, $name = false )
{
$this->Mail->addCc( new ezcMailAddress( $email, $name ) );
$this->Mail->addCc( new ezcMailAddress( $email, $name, $this->usedCharset() ) );
$this->CcElements[] = array( 'name' => $name,
'email' => $email );
}
Expand All @@ -545,7 +545,7 @@ function setBccElements( $newBcc )
foreach ( $newBcc as $address )
{
$name = isset( $address['name'] ) ? $address['name'] : false;
$this->Mail->addBcc( new ezcMailAddress( $address['email'], $name ) );
$this->Mail->addBcc( new ezcMailAddress( $address['email'], $name, $this->usedCharset() ) );
}
$this->BccElements = $newBcc;
}
Expand All @@ -557,7 +557,7 @@ function setBccElements( $newBcc )
*/
function addBcc( $email, $name = false )
{
$this->Mail->addBcc( new ezcMailAddress( $email, $name ) );
$this->Mail->addBcc( new ezcMailAddress( $email, $name, $this->usedCharset() ) );
$this->BccElements[] = array( 'name' => $name,
'email' => $email );
}
Expand Down

0 comments on commit a7f14ad

Please sign in to comment.