From 1a2f8375ded7563964ea24c44c7874a92e6f7b77 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Thu, 12 Aug 2010 03:11:28 -0400
Subject: [PATCH] - add message_part_structure hook also for text parts of mixed messages

---
 program/include/rcube_user.php |   45 +++++++++++++++++++++++++++++++--------------
 1 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/program/include/rcube_user.php b/program/include/rcube_user.php
index ec10728..1e05d99 100644
--- a/program/include/rcube_user.php
+++ b/program/include/rcube_user.php
@@ -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,32 @@
     /**
      * 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...
+            if (empty($domain)) {
+                $rcmail = rcmail::get_instance();
+                $domain = $rcmail->config->mail_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 +103,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
      *
@@ -370,7 +387,7 @@
             $user_email = is_array($email_list[0]) ? $email_list[0]['email'] : $email_list[0];
         }
 
-        $data = $rcmail->plugins->exec_hook('create_user',
+        $data = $rcmail->plugins->exec_hook('user_create',
 	        array('user'=>$user, 'user_name'=>$user_name, 'user_email'=>$user_email));
 
         // plugin aborted this operation
@@ -389,7 +406,7 @@
             strip_newlines($user),
             strip_newlines($host),
             strip_newlines($data['alias'] ? $data['alias'] : $user_email),
-            $_SESSION['language']);
+            strip_newlines($data['language'] ? $data['language'] : $_SESSION['language']));
 
         if ($user_id = $dbh->insert_id('users')) {
             // create rcube_user instance to make plugin hooks work
@@ -429,7 +446,7 @@
                 $record['user_id'] = $user_id;
                 $record['standard'] = $standard;
 
-                $plugin = $rcmail->plugins->exec_hook('create_identity',
+                $plugin = $rcmail->plugins->exec_hook('identity_create',
 	                array('login' => true, 'record' => $record));
           
                 if (!$plugin['abort'] && $plugin['record']['email']) {
@@ -484,5 +501,5 @@
 
         return empty($plugin['email']) ? NULL : $plugin['email'];
     }
-  
+
 }

--
Gitblit v1.9.1