     public function prefs_init($pref, $value, $username, $scope_ob)
     \{
        if (is_null($username)) \{    // not logged in
            return $value;
        \}
        # get the virtualhost
        $vdomain = getenv('HTTP_HOST');
	# if it is an ip, let's use the Primary domain
        if (filter_var($vdomain, FILTER_VALIDATE_IP)) \{
            $vdomain = "{$DomainName}";
        \} else\{ # else filter the virtual domain to remove unwanted parts
{
 my @filtered = split /[;,: ]/, $horde{SubdomainFilter} || "www,mail,webmail";
 $OUT .= "            \$patterns = array();\n";
 foreach my $filter (sort @filtered)
         {
            $OUT .= "            array_push(\$patterns,'|^$filter\\.|i');\n";
         }
}
            $vdomain = preg_replace($patterns, '', $vdomain);
        \}
        $vdomain = Horde_String::lower($vdomain);
{        # override to Primary Domain
 my $UsePrimary = $horde{ForcePrimaryDomain} || "disabled"; 
 $OUT .= ($UsePrimary eq "enabled") ? "        \$vdomain = '$DomainName';\n" : "        # ForcePrimaryDomain disabled\n        # \$vdomain = '$DomainName';\n" ;
 
 my $basedn = esmith::util::ldapBase ($DomainName);
 $OUT .= "        \$ldapServer = 'localhost';
        \$ldapPort = '389';
        \$searchBase = 'ou=Users,$basedn';
        \$ds = \@ldap_connect(\$ldapServer, \$ldapPort);
        if (\@ldap_bind(\$ds )) {
            \$searchResult = \@ldap_search(\$ds, \$searchBase, 'uid=' . \$username);
        }
	\$information = \@ldap_get_entries(\$ds, \$searchResult);";

}

        switch ($pref) \{

                case 'default_share' :
                        if (is_null($username)) \{
                                return $value;
                        \}
                        return $username;

                case 'from_addr':
                        if($value == '') \{
                                $value = "$username@$vdomain";
                        \}
                        return $value;
                case 'fullname':
                        if($value == '') \{
                                $value = "$username";
                        \}
			if (($information['count'] > 0) && ($information[0]['displayname'][0] != '') ) \{
				$value = $information[0]['displayname'][0];
			\} else \{
				$value = "$username";
			\}
                        return $value;
        \}

     \}

