diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index fdf52d67ba6..28350f84d96 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -589,7 +589,7 @@ class CMailFile // Sender //$out .= "Sender: ".getValidAddress($this->addr_from,2).$this->eol; - $out .= "From: ".$this->getValidAddress($this->addr_from,0,1).$this->eol; + $out .= "From: ".$this->getValidAddress($this->addr_from,3,1).$this->eol; //$out .= "Return-Path: ".$this->getValidAddress($this->addr_from,0,1).$this->eol; if (isset($this->reply_to) && $this->reply_to) $out .= "Reply-To: ".$this->getValidAddress($this->reply_to,2).$this->eol; if (isset($this->errors_to) && $this->errors_to) $out .= "Errors-To: ".$this->getValidAddress($this->errors_to,2).$this->eol; @@ -952,10 +952,12 @@ class CMailFile * Return an address for SMTP protocol * * @param string $adresses Example: 'John Doe ' or 'john@doe.com' - * @param int $format 0=Auto, 1=emails with <>, 2=emails without <> + * @param int $format 0=auto, 1=emails with <>, 2=emails without <>, 3=auto + label between " * @param int $encode 1=Encode name to RFC2822 - * @return string If format 1: '' or 'John Doe ' + * @return string If format 0: '' or 'John Doe ' or '=?UTF-8?B?Sm9obiBEb2U=?= ' + * If format 1: '' * If format 2: 'john@doe.com' + * If format 3: '' or '"John Doe" ' or '"=?UTF-8?B?Sm9obiBEb2U=?=" ' */ function getValidAddress($adresses,$format,$encode='') { @@ -986,15 +988,15 @@ class CMailFile { $newemail=$email; } - if ($format == 1) + if ($format == 1 || $format == 3) { $newemail='<'.$email.'>'; } - if ($format == 0) + if ($format == 0 || $format == 3) { if ($conf->global->MAIN_MAIL_NO_FULL_EMAIL) $newemail='<'.$email.'>'; elseif (! $name) $newemail='<'.$email.'>'; - else $newemail=($encode?$this->encodetorfc2822($name):$name).' <'.$email.'>'; + else $newemail=($format==3?'"':'').($encode?$this->encodetorfc2822($name):$name).($format==3?'"':'').' <'.$email.'>'; } $ret=($ret ? $ret.',' : '').$newemail; diff --git a/test/phpunit/CMailFileTest.php b/test/phpunit/CMailFileTest.php index ea26e4f528a..fccf9e2a3cb 100755 --- a/test/phpunit/CMailFileTest.php +++ b/test/phpunit/CMailFileTest.php @@ -139,6 +139,11 @@ class CMailFileTest extends PHPUnit_Framework_TestCase $localobject=new CMailFile('','','',''); + $src='John Doe '; + $result=$localobject->getValidAddress($src,0); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result,'John Doe '); + $src='John Doe '; $result=$localobject->getValidAddress($src,1); print __METHOD__." result=".$result."\n"; @@ -149,6 +154,16 @@ class CMailFileTest extends PHPUnit_Framework_TestCase print __METHOD__." result=".$result."\n"; $this->assertEquals($result,'john@doe.com'); + $src='John Doe '; + $result=$localobject->getValidAddress($src,3,0); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result,'"John Doe" '); + + $src='John Doe '; + $result=$localobject->getValidAddress($src,3,1); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result,'"=?UTF-8?B?Sm9obiBEb2U=?=" '); + return $result; }