[Svn] r3774 - trunk/roundcubemail/program/include

trac at roundcube.net trac at roundcube.net
Sun Jun 20 12:36:31 CEST 2010


Author: alec
Date: 2010-06-20 05:36:31 -0500 (Sun, 20 Jun 2010)
New Revision: 3774

Modified:
   trunk/roundcubemail/program/include/rcube_user.php
Log:
- Extended rcube_user::get_username (#1486707)


Modified: trunk/roundcubemail/program/include/rcube_user.php
===================================================================
--- trunk/roundcubemail/program/include/rcube_user.php	2010-06-20 09:27:32 UTC (rev 3773)
+++ trunk/roundcubemail/program/include/rcube_user.php	2010-06-20 10:36:31 UTC (rev 3774)
@@ -5,7 +5,7 @@
  | program/include/rcube_user.inc                                        |
  |                                                                       |
  | This file is part of the RoundCube Webmail client                     |
- | Copyright (C) 2005-2009, RoundCube Dev. - Switzerland                 |
+ | Copyright (C) 2005-2010, RoundCube Dev. - Switzerland                 |
  | Licensed under the GNU GPL                                            |
  |                                                                       |
  | PURPOSE:                                                              |
@@ -62,15 +62,30 @@
     /**
      * Build a user name string (as e-mail address)
      *
-     * @return string Full user name
+     * @param string Username part (empty or 'local' or 'domain')
+     * @return string Full user name or its part
      */
-    function get_username()
+    function get_username($part = null)
     {
         if ($this->data['username']) {
-            if (!strpos($this->data['username'], '@'))
-                return $this->data['username'] . '@' . $this->data['mail_host'];
+            list($local, $domain) = explode('@', $this->data['username']);
+
+            // at least we should always have the local part
+            if ($part == 'local') {
+                return $local;
+            }
+            // if no domain was provided use the default if available
+            if (empty($domain))
+                $domain = $this->data['mail_host'];
+
+            if ($part == 'domain') {
+                return $domain;
+            }
+
+            if (!empty($domain))
+                return $local . '@' . $domain;
             else
-                return $this->data['username'];
+                return $local;
         }
 
         return false;
@@ -86,14 +101,14 @@
     {
         if (!empty($this->language))
             $prefs = array('language' => $this->language);
-    
+
         if ($this->ID && $this->data['preferences'])
             $prefs += (array)unserialize($this->data['preferences']);
-    
+
         return $prefs;
     }
-  
-  
+
+
     /**
      * Write the given user prefs to the user's record
      *
@@ -484,5 +499,5 @@
 
         return empty($plugin['email']) ? NULL : $plugin['email'];
     }
-  
+
 }

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list