Author Topic: Force to choose identity on composing mail  (Read 2566 times)

Offline Chembin

  • Newbie
  • *
  • Posts: 2
Force to choose identity on composing mail
« on: August 19, 2011, 12:00:53 PM »
(Not sure if this is the right forum, but I hope so)

I intend to use roundcube on a dovecot/ldap backend using public namespaces. To ensure mail is sent using the correct email address/identity I would like to force the user to take some action to choose a from address (so no default identity selected, or something like that). I've been looking in the RC-src to find where I could implement this, but I have been unsuccessful so far.
Any help would be appreciated.

Kind regards.

Offline Chembin

  • Newbie
  • *
  • Posts: 2
Force to choose identity on composing mail
« Reply #1 on: August 30, 2011, 08:49:21 AM »
I've finally found the solution myself, but it's not elegant: the plugin hook is not there and i ended up modifying list_identities in program/includes/rcube_user.php with some ldap lookup code that outputs a 'fake' sql result array. The hook that would be needed here should give the chance to modify the behavior of list_identities().
The modification I made looks up the groups of which a user is a member of, and creates identities according to that, prepended  with an empty identity string.
Here's the code:


    function list_identities($sql_add = '')
    {
         $result = $this->_cb_make_fakequery($this->data['username']);

         return $result;
    }


function _cb_findcn($_cb_ldap_server, $ou, $cb_id)
{
        $con = ldap_connect($_cb_ldap_server);
        $search = ldap_search($con, "ou=".$ou.",dc=example,dc=com","(|(uid=".$cb_id."))",array("cn"));
        $search_result = ldap_get_entries($con, $search);
        $cnresult = $search_result[0]['cn'][0];
        return $cnresult;
}

function _cb_findgroups($_cb_ldap_server, $ou, $cb_id)
{
$con = ldap_connect($_cb_ldap_server);
$search_result = ldap_search($con,"ou=".$ou.",dc=example,dc=com","(|(uid=".$cb_id.")(memberUid=".$cb_id."))",array("cn"));
$ldap_result = ldap_get_entries($con,$search_result);

for($i = 0; $i <= $ldap_result['count']-1; $i++)
{
        $ids[] = $ldap_result[$i]['cn'][0];
}
return $ids;
}

function _cb_make_fakequery($uid)
{
$fakequery = array(array('name' => '', 'standard' => 1, 'del' => 0, 'email' => '', 'identity_id' => '', 'signature' => '', 'html_signature' => 0));

foreach($this->_cb_findgroups("localhost", "Group",$uid) as $gid)
{
        $domain = "example.com";
        if($gid == $uid)
        {
                $fullname = $this->_cb_findcn("localhost", "People", $gid);
                $fakequery[] = array('name' => $fullname, 'standard' => 0, 'del' => 0, 'email' => $gid.'@'.$domain, 'identity_id' => $gid, 'signature' => '', 'html_signature' => 0);
        }

        else
        {
                $fullname = $this->_cb_findcn("localhost", "Groups", $gid);
                $fakequery[] = array('name' => $fullname, 'standard' => 0, 'del' => 0, 'email' => $gid.'@'.$domain, 'identity_id' => $gid, 'signature' => '', 'html_signature' => 0);
        }
}
return $fakequery;
}