[Svn] r4009 - in trunk/roundcubemail: . installer program/include program/js program/lib/Net program/lib/Net/IDNA2 program/lib/Net/IDNA2/Exception program/steps/mail program/steps/settings

trac at roundcube.net trac at roundcube.net
Wed Sep 29 14:36:28 CEST 2010


Author: alec
Date: 2010-09-29 07:36:28 -0500 (Wed, 29 Sep 2010)
New Revision: 4009

Added:
   trunk/roundcubemail/program/lib/Net/IDNA2.php
   trunk/roundcubemail/program/lib/Net/IDNA2/
   trunk/roundcubemail/program/lib/Net/IDNA2/Exception.php
   trunk/roundcubemail/program/lib/Net/IDNA2/Exception/
   trunk/roundcubemail/program/lib/Net/IDNA2/Exception/Nameprep.php
Modified:
   trunk/roundcubemail/CHANGELOG
   trunk/roundcubemail/installer/check.php
   trunk/roundcubemail/installer/test.php
   trunk/roundcubemail/program/include/main.inc
   trunk/roundcubemail/program/include/rcmail.php
   trunk/roundcubemail/program/include/rcube_config.php
   trunk/roundcubemail/program/include/rcube_imap.php
   trunk/roundcubemail/program/include/rcube_ldap.php
   trunk/roundcubemail/program/include/rcube_shared.inc
   trunk/roundcubemail/program/include/rcube_smtp.php
   trunk/roundcubemail/program/include/rcube_template.php
   trunk/roundcubemail/program/include/rcube_user.php
   trunk/roundcubemail/program/js/common.js
   trunk/roundcubemail/program/steps/mail/addcontact.inc
   trunk/roundcubemail/program/steps/mail/compose.inc
   trunk/roundcubemail/program/steps/mail/func.inc
   trunk/roundcubemail/program/steps/mail/sendmail.inc
   trunk/roundcubemail/program/steps/settings/edit_identity.inc
   trunk/roundcubemail/program/steps/settings/func.inc
   trunk/roundcubemail/program/steps/settings/save_identity.inc
Log:
- Add Internationalized Domain Name (IDNA) support (#1483894)


Modified: trunk/roundcubemail/CHANGELOG
===================================================================
--- trunk/roundcubemail/CHANGELOG	2010-09-29 12:24:01 UTC (rev 4008)
+++ trunk/roundcubemail/CHANGELOG	2010-09-29 12:36:28 UTC (rev 4009)
@@ -3,6 +3,7 @@
 
 - Messages caching: performance improvements, fixed syncing, fixes related with #1486748
 - Add link to identities in compose window (#1486729)
+- Add Internationalized Domain Name (IDNA) support (#1483894)
 
 RELEASE 0.4.1
 -------------

Modified: trunk/roundcubemail/installer/check.php
===================================================================
--- trunk/roundcubemail/installer/check.php	2010-09-29 12:24:01 UTC (rev 4008)
+++ trunk/roundcubemail/installer/check.php	2010-09-29 12:36:28 UTC (rev 4009)
@@ -15,6 +15,7 @@
     'Multibyte' => 'mbstring',
     'OpenSSL'   => 'openssl',
     'Mcrypt'    => 'mcrypt',
+    'Intl'      => 'intl',
 );
 
 $required_libs = array(
@@ -44,19 +45,20 @@
 );
 
 $source_urls = array(
-    'Sockets' => 'http://www.php.net/manual/en/book.sockets.php',
-    'Session' => 'http://www.php.net/manual/en/book.session.php',
-    'PCRE' => 'http://www.php.net/manual/en/book.pcre.php',
-    'FileInfo' => 'http://www.php.net/manual/en/book.fileinfo.php',
-    'Libiconv' => 'http://www.php.net/manual/en/book.iconv.php',
+    'Sockets'   => 'http://www.php.net/manual/en/book.sockets.php',
+    'Session'   => 'http://www.php.net/manual/en/book.session.php',
+    'PCRE'      => 'http://www.php.net/manual/en/book.pcre.php',
+    'FileInfo'  => 'http://www.php.net/manual/en/book.fileinfo.php',
+    'Libiconv'  => 'http://www.php.net/manual/en/book.iconv.php',
     'Multibyte' => 'http://www.php.net/manual/en/book.mbstring.php',
-    'Mcrypt' => 'http://www.php.net/manual/en/book.mcrypt.php',
-    'OpenSSL' => 'http://www.php.net/manual/en/book.openssl.php',
-    'JSON' => 'http://www.php.net/manual/en/book.json.php',
-    'DOM' => 'http://www.php.net/manual/en/book.dom.php',
-    'PEAR' => 'http://pear.php.net',
-    'MDB2' => 'http://pear.php.net/package/MDB2',
-    'Net_SMTP' => 'http://pear.php.net/package/Net_SMTP',
+    'Mcrypt'    => 'http://www.php.net/manual/en/book.mcrypt.php',
+    'OpenSSL'   => 'http://www.php.net/manual/en/book.openssl.php',
+    'JSON'      => 'http://www.php.net/manual/en/book.json.php',
+    'DOM'       => 'http://www.php.net/manual/en/book.dom.php',
+    'Intl'      => 'http://www.php.net/manual/en/book.intl.php',
+    'PEAR'      => 'http://pear.php.net',
+    'MDB2'      => 'http://pear.php.net/package/MDB2',
+    'Net_SMTP'  => 'http://pear.php.net/package/Net_SMTP',
     'Mail_mime' => 'http://pear.php.net/package/Mail_mime',
 );
 

Modified: trunk/roundcubemail/installer/test.php
===================================================================
--- trunk/roundcubemail/installer/test.php	2010-09-29 12:24:01 UTC (rev 4008)
+++ trunk/roundcubemail/installer/test.php	2010-09-29 12:36:28 UTC (rev 4009)
@@ -249,18 +249,21 @@
 
   echo '<p>Trying to send email...<br />';
 
-  if (preg_match('/^' . $RCI->email_pattern . '$/i', trim($_POST['_from'])) &&
-      preg_match('/^' . $RCI->email_pattern . '$/i', trim($_POST['_to']))) {
+  $from = idn_to_ascii(trim($_POST['_from']));
+  $to   = idn_to_ascii(trim($_POST['_to']));
 
+  if (preg_match('/^' . $RCI->email_pattern . '$/i', $from) &&
+      preg_match('/^' . $RCI->email_pattern . '$/i', $to)
+  ) {
     $headers = array(
-      'From'    => trim($_POST['_from']),
-      'To'      => trim($_POST['_to']),
+      'From'    => $from,
+      'To'      => $to,
       'Subject' => 'Test message from Roundcube',
     );
 
     $body = 'This is a test to confirm that Roundcube can send email.';
     $smtp_response = array();
-    
+
     // send mail using configured SMTP server
     if ($RCI->getprop('smtp_server')) {
       $CONFIG = $RCI->config;
@@ -383,9 +386,12 @@
     $imap_host = trim($_POST['_host']);
     $imap_port = $RCI->getprop('default_port');
   }
-  
+
+  $imap_host = idn_to_ascii($imap_host);
+  $imap_user = idn_to_ascii($_POST['_user']);
+
   $imap = new rcube_imap(null);
-  if ($imap->connect($imap_host, $_POST['_user'], $_POST['_pass'], $imap_port, $imap_ssl)) {
+  if ($imap->connect($imap_host, $imap_user, $_POST['_pass'], $imap_port, $imap_ssl)) {
     $RCI->pass('IMAP connect', 'SORT capability: ' . ($imap->get_capability('SORT') ? 'yes' : 'no'));
     $imap->close();
   }

Modified: trunk/roundcubemail/program/include/main.inc
===================================================================
--- trunk/roundcubemail/program/include/main.inc	2010-09-29 12:24:01 UTC (rev 4008)
+++ trunk/roundcubemail/program/include/main.inc	2010-09-29 12:36:28 UTC (rev 4009)
@@ -1764,4 +1764,3 @@
         flush();
     }
 }
-

Modified: trunk/roundcubemail/program/include/rcmail.php
===================================================================
--- trunk/roundcubemail/program/include/rcmail.php	2010-09-29 12:24:01 UTC (rev 4008)
+++ trunk/roundcubemail/program/include/rcmail.php	2010-09-29 12:36:28 UTC (rev 4009)
@@ -587,7 +587,7 @@
     if ($a_host['host']) {
       $host = $a_host['host'];
       $imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? $a_host['scheme'] : null;
-      if(!empty($a_host['port']))
+      if (!empty($a_host['port']))
         $imap_port = $a_host['port'];
       else if ($imap_ssl && $imap_ssl != 'tls' && (!$config['default_port'] || $config['default_port'] == 143))
         $imap_port = 993;
@@ -618,6 +618,12 @@
     if (!$this->imap)
       $this->imap_init();
 
+    // Here we need IDNA ASCII
+    // Only rcube_contacts class is using domain names in Unicode
+    $host = idn_to_ascii($host);
+    if (strpos($username, '@'))
+      $username = idn_to_ascii($username);
+
     // try IMAP login
     if (!($imap_login = $this->imap->connect($host, $username, $pass, $imap_port, $imap_ssl))) {
       // lowercase username if it's an e-mail address (#1484473)

Modified: trunk/roundcubemail/program/include/rcube_config.php
===================================================================
--- trunk/roundcubemail/program/include/rcube_config.php	2010-09-29 12:24:01 UTC (rev 4008)
+++ trunk/roundcubemail/program/include/rcube_config.php	2010-09-29 12:36:28 UTC (rev 4009)
@@ -274,10 +274,11 @@
     /**
      * Return the mail domain configured for the given host
      *
-     * @param string IMAP host
+     * @param string  IMAP host
+     * @param boolean If true, domain name will be converted to IDN ASCII
      * @return string Resolved SMTP host
      */
-    public function mail_domain($host)
+    public function mail_domain($host, $encode=true)
     {
         $domain = $host;
 
@@ -288,6 +289,9 @@
         else if (!empty($this->prop['mail_domain']))
             $domain = rcube_parse_host($this->prop['mail_domain']);
 
+        if ($encode)
+            $domain = idn_to_ascii($domain);
+
         return $domain;
     }
 

Modified: trunk/roundcubemail/program/include/rcube_imap.php
===================================================================
--- trunk/roundcubemail/program/include/rcube_imap.php	2010-09-29 12:24:01 UTC (rev 4008)
+++ trunk/roundcubemail/program/include/rcube_imap.php	2010-09-29 12:36:28 UTC (rev 4009)
@@ -3505,7 +3505,7 @@
             $address = trim($val['address']);
             $name = trim($val['name']);
 
-            if (preg_match('/^[\'"]/', $name) && preg_match('/[\'"]$/', $name))
+            if ($name && preg_match('/^[\'"]/', $name) && preg_match('/[\'"]$/', $name))
                 $name = trim($name, '\'"');
 
             if ($name && $address && $name != $address)
@@ -3515,7 +3515,8 @@
             else if ($name)
                 $string = $name;
 
-            $out[$j] = array('name' => $name,
+            $out[$j] = array(
+                'name'   => $name,
                 'mailto' => $address,
                 'string' => $string
             );
@@ -3912,9 +3913,9 @@
                     $result[$key]['name'] .= (empty($result[$key]['name'])?'':' ').str_replace("\"",'',stripslashes($v));
             }
 
-            if (empty($result[$key]['name']))
-                $result[$key]['name'] = $result[$key]['address'];
-            elseif (empty($result[$key]['address']))
+//          if (empty($result[$key]['name']))
+//              $result[$key]['name'] = $result[$key]['address'];
+            if (empty($result[$key]['address']))
                 $result[$key]['address'] = $result[$key]['name'];
         }
 

Modified: trunk/roundcubemail/program/include/rcube_ldap.php
===================================================================
--- trunk/roundcubemail/program/include/rcube_ldap.php	2010-09-29 12:24:01 UTC (rev 4008)
+++ trunk/roundcubemail/program/include/rcube_ldap.php	2010-09-29 12:36:28 UTC (rev 4009)
@@ -99,7 +99,7 @@
 
     foreach ($this->prop['hosts'] as $host)
     {
-      $host = rcube_parse_host($host);
+      $host = idn_to_ascii(rcube_parse_host($host));
       $this->_debug("C: Connect [$host".($this->prop['port'] ? ':'.$this->prop['port'] : '')."]");
 
       if ($lc = @ldap_connect($host, $this->prop['port']))

Modified: trunk/roundcubemail/program/include/rcube_shared.inc
===================================================================
--- trunk/roundcubemail/program/include/rcube_shared.inc	2010-09-29 12:24:01 UTC (rev 4008)
+++ trunk/roundcubemail/program/include/rcube_shared.inc	2010-09-29 12:36:28 UTC (rev 4009)
@@ -680,3 +680,51 @@
     }
 }
 
+/**
+ * intl replacement functions
+ */
+
+if (!function_exists('idn_to_utf8'))
+{
+    function idn_to_utf8($domain, $flags=null)
+    {
+        static $idn, $loaded;
+
+        if (!$loaded) {
+            $idn = new Net_IDNA2();
+            $loaded = true;
+        }
+
+        if ($idn && $domain && preg_match('/(^|@|\.)xn--/i', $domain)) {
+            try {
+                $domain = $idn->decode($domain);
+            }
+            catch (Exception $e) {
+            }
+        }
+        return $domain;
+    }
+}
+
+if (!function_exists('idn_to_ascii'))
+{
+    function idn_to_ascii($domain, $flags=null)
+    {
+        static $idn, $loaded;
+
+        if (!$loaded) {
+            $idn = new Net_IDNA2();
+            $loaded = true;
+        }
+
+        if ($idn && $domain && preg_match('/[^\x20-\x7E]/', $domain)) {
+            try {
+                $domain = $idn->encode($domain);
+            }
+            catch (Exception $e) {
+            }
+        }
+        return $domain;
+    }
+}
+

Modified: trunk/roundcubemail/program/include/rcube_smtp.php
===================================================================
--- trunk/roundcubemail/program/include/rcube_smtp.php	2010-09-29 12:24:01 UTC (rev 4008)
+++ trunk/roundcubemail/program/include/rcube_smtp.php	2010-09-29 12:36:28 UTC (rev 4009)
@@ -98,6 +98,9 @@
     else
       $helo_host = 'localhost';
 
+    // IDNA Support
+    $smtp_host = idn_to_ascii($smtp_host);
+
     $this->con