]> git.donarmstrong.com Git - roundcube.git/blob - plugins/new_user_identity/new_user_identity.php
45750facd46d9ddf5d0a14efbc0df700c6cfa323
[roundcube.git] / plugins / new_user_identity / new_user_identity.php
1 <?php
2 /**
3  * New user identity
4  *
5  * Populates a new user's default identity from LDAP on their first visit.
6  *
7  * This plugin requires that a working public_ldap directory be configured.
8  *
9  * @version 1.0
10  * @author Kris Steinhoff
11  *
12  * Example configuration:
13  *
14  *  // The id of the address book to use to automatically set a new
15  *  // user's full name in their new identity. (This should be an
16  *  // string, which refers to the $rcmail_config['ldap_public'] array.)
17  *  $rcmail_config['new_user_identity_addressbook'] = 'People';
18  *  
19  *  // When automatically setting a new users's full name in their
20  *  // new identity, match the user's login name against this field.
21  *  $rcmail_config['new_user_identity_match'] = 'uid';
22  */
23 class new_user_identity extends rcube_plugin
24 {
25     public $task = 'login';
26
27     function init()
28     {
29         $this->add_hook('user_create', array($this, 'lookup_user_name'));
30     }
31
32     function lookup_user_name($args)
33     {
34         $rcmail = rcmail::get_instance();
35         if ($addressbook = $rcmail->config->get('new_user_identity_addressbook')) {
36             $match = $rcmail->config->get('new_user_identity_match');
37             $ldap = $rcmail->get_address_book($addressbook);
38             $ldap->prop['search_fields'] = array($match);
39             $results = $ldap->search($match, $args['user'], TRUE);
40             if (count($results->records) == 1) {
41                 $args['user_name'] = $results->records[0]['name'];
42                 if (!$args['user_email'] && strpos($results->records[0]['email'], '@')) {
43                     $args['user_email'] = rcube_idn_to_ascii($results->records[0]['email']);
44                 }
45             }
46         }
47         return $args;
48     }
49 }
50 ?>