Author: as
Date: Fri Jul 27 10:08:53 2007
New Revision: 5742

Log:
- Fixed issue #11175: ezcMailTools::composeEmailAddress quotes the name part
  if it contains special characters ( , @ < > : ; ' " ).

Modified:
    stable/Mail/1.3/ChangeLog
    stable/Mail/1.3/src/tools.php
    stable/Mail/1.3/tests/tools_test.php

Modified: stable/Mail/1.3/ChangeLog
==============================================================================
--- stable/Mail/1.3/ChangeLog [iso-8859-1] (original)
+++ stable/Mail/1.3/ChangeLog [iso-8859-1] Fri Jul 27 10:08:53 2007
@@ -1,3 +1,10 @@
+1.3.1 - [RELEASEDATE]
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Fixed issue #11175: ezcMailTools::composeEmailAddress quotes the name part
+  if it contains special characters ( , @ < > : ; ' " ).
+
+
 1.3 - Monday 02 July 2007
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 

Modified: stable/Mail/1.3/src/tools.php
==============================================================================
--- stable/Mail/1.3/src/tools.php [iso-8859-1] (original)
+++ stable/Mail/1.3/src/tools.php [iso-8859-1] Fri Jul 27 10:08:53 2007
@@ -57,17 +57,35 @@
      * John Doe <[EMAIL PROTECTED]>
      * </pre>
      *
+     * The name part of $item will be surrounded by quotes if it contains any 
of
+     * these characters: , @ < > : ; ' "
+     *
      * @param ezcMailAddress $item
      * @return string
      */
     public static function composeEmailAddress( ezcMailAddress $item )
     {
-        if ( $item->name !== '' )
-        {
+        $name = trim( $item->name );
+        if ( $name !== '' )
+        {
+            // remove the quotes around the name part if they are already there
+            if ( $name{0} === '"' && $name{strlen( $name ) - 1} === '"' )
+            {
+                $name = substr( $name, 1, -1 );
+            }
+
+            // add slashes to " and \ and surround the name part with quotes
+            if ( strpbrk( $name, ",@<>:;'\"" ) !== false )
+            {
+                $name = str_replace( '\\', '\\\\', $name );
+                $name = str_replace( '"', '\"', $name );
+                $name = "\"{$name}\"";
+            }
+
             switch ( strtolower( $item->charset ) )
             {
                 case 'us-ascii':
-                    $text = $item->name . ' <' . $item->email . '>';
+                    $text = $name . ' <' . $item->email . '>';
                     break;
 
                 case 'iso-8859-1': case 'iso-8859-2': case 'iso-8859-3': case 
'iso-8859-4':
@@ -76,9 +94,9 @@
                 case 'iso-8859-13': case 'iso-8859-14': case 'iso-8859-15' 
:case 'iso-8859-16':
                 case 'windows-1250': case 'windows-1251': case 'windows-1252':
                 case 'utf-8':
-                    if ( strpbrk( $item->name, 
"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"
 ) === false )
+                    if ( strpbrk( $name, 
"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"
 ) === false )
                     {
-                        $text = $item->name . ' <' . $item->email . '>';
+                        $text = $name . ' <' . $item->email . '>';
                         break;
                     }
                     // break intentionally missing
@@ -90,7 +108,7 @@
                         'scheme' => 'Q',
                         'line-break-chars' => ezcMailTools::lineBreak()
                     );
-                    $name = iconv_mime_encode( 'dummy', $item->name, 
$preferences );
+                    $name = iconv_mime_encode( 'dummy', $name, $preferences );
                     $name = substr( $name, 7 ); // "dummy: " + 1
                     $text = $name . ' <' . $item->email . '>';
                     break;

Modified: stable/Mail/1.3/tests/tools_test.php
==============================================================================
--- stable/Mail/1.3/tests/tools_test.php [iso-8859-1] (original)
+++ stable/Mail/1.3/tests/tools_test.php [iso-8859-1] Fri Jul 27 10:08:53 2007
@@ -120,6 +120,57 @@
                             new ezcMailAddress( '[EMAIL PROTECTED]' ) );
         $result = ezcMailTools::composeEmailAddresses( $addresses, 76 );
         $this->assertEquals( $reference, $result );
+    }
+
+    public function testComposeEmailAddressNameNotQuoted()
+    {
+        $addressesNotQuoted = array(
+            array( "Doe John <[EMAIL PROTECTED]>", new ezcMailAddress( '[EMAIL 
PROTECTED]', 'Doe John' ) ),
+            array( "\"Doe, John\" <[EMAIL PROTECTED]>", new ezcMailAddress( 
'[EMAIL PROTECTED]', '"Doe, John"' ) ), // already quoted
+            array( "\"<Doe John>\" <[EMAIL PROTECTED]>", new ezcMailAddress( 
'[EMAIL PROTECTED]', '"<Doe John>"' ) ), // already quoted
+            array( "\"[EMAIL PROTECTED]" <[EMAIL PROTECTED]>", new 
ezcMailAddress( '[EMAIL PROTECTED]', '"[EMAIL PROTECTED]"' ) ), // already 
quoted
+            array( "\"John, [EMAIL PROTECTED]" <[EMAIL PROTECTED]>", new 
ezcMailAddress( '[EMAIL PROTECTED]', '"John, [EMAIL PROTECTED]"' ) ), // 
already quoted
+            array( "\":sysmail\" <[EMAIL PROTECTED]>", new ezcMailAddress( 
'[EMAIL PROTECTED]', '":sysmail"' ) ), // already quoted
+            array( "\";sysmail\" <[EMAIL PROTECTED]>", new ezcMailAddress( 
'[EMAIL PROTECTED]', '";sysmail"' ) ), // already quoted
+            array( "sysmail <[EMAIL PROTECTED]>", new ezcMailAddress( '[EMAIL 
PROTECTED]', 'sysmail' ) ),
+            array( "\"John 'Doe'\" <[EMAIL PROTECTED]>", new ezcMailAddress( 
'[EMAIL PROTECTED]', 'John \'Doe\'' ) ),
+            );
+
+        foreach ( $addressesNotQuoted as $address )
+        {
+            $reference = $address[0];
+            $result = ezcMailTools::composeEmailAddress( $address[1] );
+
+            $this->assertEquals( $reference, $result );
+        }
+    }
+        
+    public function testComposeEmailAddressNameQuoted()
+    {
+        $addressesQuoted = array(
+            array( "\"Doe, John\" <[EMAIL PROTECTED]>", new ezcMailAddress( 
'[EMAIL PROTECTED]', 'Doe, John' ) ),
+            array( "\"<Doe John>\" <[EMAIL PROTECTED]>", new ezcMailAddress( 
'[EMAIL PROTECTED]', '<Doe John>' ) ), // double bad character < and >
+            array( "\"[EMAIL PROTECTED]" <[EMAIL PROTECTED]>", new 
ezcMailAddress( '[EMAIL PROTECTED]', '[EMAIL PROTECTED]' ) ),
+            array( "\"John, [EMAIL PROTECTED]" <[EMAIL PROTECTED]>", new 
ezcMailAddress( '[EMAIL PROTECTED]', 'John, [EMAIL PROTECTED]' ) ), // double 
bad character , and @
+            array( "\"John \\\"Doe\\\"\" <[EMAIL PROTECTED]>", new 
ezcMailAddress( '[EMAIL PROTECTED]', 'John "Doe"' ) ),
+            array( "\":sysmail\" <[EMAIL PROTECTED]>", new ezcMailAddress( 
'[EMAIL PROTECTED]', ':sysmail' ) ),
+            array( "\";sysmail\" <[EMAIL PROTECTED]>", new ezcMailAddress( 
'[EMAIL PROTECTED]', ';sysmail' ) ),
+            array( "\"John \\\"Doe\" <[EMAIL PROTECTED]>", new ezcMailAddress( 
'[EMAIL PROTECTED]', 'John "Doe' ) ),
+            array( "\"John 'Doe\" <[EMAIL PROTECTED]>", new ezcMailAddress( 
'[EMAIL PROTECTED]', 'John \'Doe' ) ),
+            array( "\"John \\\\\\\"Doe\" <[EMAIL PROTECTED]>", new 
ezcMailAddress( '[EMAIL PROTECTED]', 'John \"Doe' ) ), // already escaped quotes
+            array( "\"John \\\"Doe\" <[EMAIL PROTECTED]>", new ezcMailAddress( 
'[EMAIL PROTECTED]', '"John "Doe"' ) ),
+            array( "\"\\\"Doe\\\" \\\"John\" <[EMAIL PROTECTED]>", new 
ezcMailAddress( '[EMAIL PROTECTED]', '"Doe" "John' ) ),
+            array( "\"Doe\\\" John\" <[EMAIL PROTECTED]>", new ezcMailAddress( 
'[EMAIL PROTECTED]', '"Doe" John"' ) ),
+            array( "\"'Doe' 'John\" <[EMAIL PROTECTED]>", new ezcMailAddress( 
'[EMAIL PROTECTED]', "'Doe' 'John" ) ),
+            );
+
+        foreach ( $addressesQuoted as $key => $address )
+        {
+            $reference = $address[0];
+            $result = ezcMailTools::composeEmailAddress( $address[1] );
+
+            $this->assertEquals( $reference, $result );
+        }
     }
 
     public function testParseEmailAddressMimeGood()


-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to