From bb5d7282855dd83ccdd211cb77d0776dce71468e Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 12 Dec 2012 02:54:33 -0500
Subject: [PATCH] Use also Envelope-To for identity selection (#1488553)

---
 program/lib/Roundcube/rcube_user.php |   22 +++++++++++++++++++---
 1 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/program/lib/Roundcube/rcube_user.php b/program/lib/Roundcube/rcube_user.php
index 7bd73e0..f6b77f5 100644
--- a/program/lib/Roundcube/rcube_user.php
+++ b/program/lib/Roundcube/rcube_user.php
@@ -86,12 +86,17 @@
     /**
      * Build a user name string (as e-mail address)
      *
-     * @param  string $part Username part (empty or 'local' or 'domain')
+     * @param  string $part Username part (empty or 'local' or 'domain', 'mail')
      * @return string Full user name or its part
      */
     function get_username($part = null)
     {
         if ($this->data['username']) {
+            // return real name
+            if (!$part) {
+                return $this->data['username'];
+            }
+
             list($local, $domain) = explode('@', $this->data['username']);
 
             // at least we should always have the local part
@@ -235,10 +240,12 @@
     /**
      * Return a list of all identities linked with this user
      *
-     * @param string $sql_add Optional WHERE clauses
+     * @param string $sql_add   Optional WHERE clauses
+     * @param bool   $formatted Format identity email and name
+     *
      * @return array List of identities
      */
-    function list_identities($sql_add = '')
+    function list_identities($sql_add = '', $formatted = false)
     {
         $result = array();
 
@@ -250,6 +257,15 @@
             $this->ID);
 
         while ($sql_arr = $this->db->fetch_assoc($sql_result)) {
+            if ($formatted) {
+                $ascii_email = format_email($sql_arr['email']);
+                $utf8_email  = format_email(rcube_utils::idn_to_utf8($ascii_email));
+
+                $sql_arr['email_ascii'] = $ascii_email;
+                $sql_arr['email']       = $utf8_email;
+                $sql_arr['ident']       = format_email_recipient($ascii_email, $sql_arr['name']);
+            }
+
             $result[] = $sql_arr;
         }
 

--
Gitblit v1.9.1