6.0.0-beta1
7/5/25

[#14110] [ActiveSync] Custom hook breaks send mail functionality
Summary [ActiveSync] Custom hook breaks send mail functionality
Queue Synchronization
Queue Version FRAMEWORK_5_2
Type Bug
State Not A Bug
Priority 1. Low
Owners mrubinsk (at) horde (dot) org
Requester hn (at) axxedia-it (dot) de
Created 09/14/2015 (3582 days ago)
Due
Updated 09/16/2015 (3580 days ago)
Assigned 09/16/2015 (3580 days ago)
Resolved 09/16/2015 (3580 days ago)
Github Issue Link
Github Pull Request
Milestone
Patch No

History
09/16/2015 09:15:46 PM Michael Rubinsky Comment #5
State ⇒ Not A Bug
Reply to this comment
This is a support question, not a bug report.

Please use the mailing lists to ask for support.

http://www.horde.org/mail/ contains a list of all available mailing lists.
09/16/2015 09:10:18 PM hn (at) axxedia-it (dot) de Comment #4 Reply to this comment
OK it is related to my other hooks. Tested it a few minutes ago, and 
if I comment them all, I can use my ActiveSync hook. So what is the 
problem here? I'd like to get the default identity pre populated when 
a new user is added to the system and does his first login. Saves me 
and the users some trouble.

Did I use the wrong mechanism here?
09/16/2015 08:51:00 PM hn (at) axxedia-it (dot) de Comment #3 Reply to this comment
I think you mean this piece of code:

/**
      * Return the current user's From/Reply_To address.
      *
      * @return string  A RFC822 valid email string.
      */
     protected function _getIdentityFromAddress()
     {
         global $prefs;

         $ident = $GLOBALS['injector']
             ->getInstance('Horde_Core_Factory_Identity')
             ->create($this->_user);

         $as_ident = $prefs->getValue('activesync_identity');
         $name = $ident->getValue('fullname', $as_ident == 'horde' ? 
$prefs->getValue('default_identity') : 
$prefs->getValue('activesync_identity'));
         $from_addr = $ident->getValue('from_addr', $as_ident == 
'horde' ? $prefs->getValue('default_identity') : 
$prefs->getValue('activesync_identity'));
         $rfc822 = new Horde_Mail_Rfc822_Address($from_addr);
         $rfc822->personal = $name;

         return $rfc822->encoded;
     }

From what I understand here is, that this function does a lookup for 
the full username and the corresponding mail address of the default 
ActiveSync user identity. I checked the user and the ActiveSync 
identity is set to default. Changing it from default does not give a 
different result. I also checked the default user identity on the 
horde web interface, and it shows up populated with the correct values 
for the full user name and the mail address.
Maybe this is not ActiveSync related at all, but I do use custom hooks 
to populate the user identity.

Here are my custom hooks for the default identity:

public function prefs_init($pref, $value, $username, $scope_ob)
     {
        switch ($pref) {

        case 'id':
                 if (is_null($uid)) {
                         $uid = $GLOBALS['registry']->getAuth('bare');
                 }
         return $uid;

         case 'from_addr':
         if (is_null($username)) {
                 return ;
         }

         $cmd = 'ldapsearch -H ldaps://my-dc.mylocal.net:636 -x -D 
cn=horde,cn=Users,dc=mylocal,dc=net -w somepassword -b 
dc=mylocal,dc=net samaccountname=' . $username . ' | /bin/grep mail: | 
  /usr/bin/awk \'{print $2}\'';;
         $mails = `$cmd`;
         $mail_array = explode("\n", $mails);
         $mail = $mail_array['0'];
         return empty($mail)
         ? ''
         : $mail;


        case 'fullname':
             // Set the fullname.

             // Set the fullname from the GECOS information in
             // the passwd file.
             if (is_null($username)) {
                 return $value;
             }

             $user = $GLOBALS['registry']->getAuth('bare');

             $array = posix_getpwnam($user);
             $gecos_array = explode(',', $array['gecos']);
             return empty($gecos_array)
                 ? $user
                 : $gecos_array[0];
         }
    }

I could also use ldap to read the fullname from my Active Directory, 
but I was lazy and winbind gives GECOS all the information I need 
here, so I just copied that one from the examples.

So could it be a problem caused by the custom hooks? I think they are 
executed every time a user does a log in, and so the default user 
identity always gets these values set anew.

09/16/2015 12:24:33 PM Michael Rubinsky Version ⇒ FRAMEWORK_5_2
Queue ⇒ Synchronization
 
09/16/2015 12:24:10 PM Michael Rubinsky Comment #2
State ⇒ Feedback
Assigned to Michael Rubinsky
Reply to this comment
This hook is only used to set the username during authentication and 
to determine the username to send in Autodiscovery responses if all 
that is available is the user email address. It has nothing to do with 
setting the From: header of an outgoing email.

Are you sure the user "maxmus" has a proper From address set in the 
Identity used for ActiveSync? The From: header is determined in 
Horde_Core_ActiveSync_Mail::_getIdentityFromAddress() if you want to 
see the code that determines this for yourself.
09/14/2015 01:34:33 PM hn (at) axxedia-it (dot) de Comment #1
Priority ⇒ 1. Low
Type ⇒ Bug
Summary ⇒ [ActiveSync] Custom hook breaks send mail functionality
Queue ⇒ Horde Groupware Webmail Edition
Milestone ⇒
Patch ⇒ No
State ⇒ Unconfirmed
Reply to this comment
I was trying to implement a custom hook that detects the correct 
username for ActiveSync login from a given mail address. This is the 
hook I'm using (server and login information changed for privacy 
reasons, but you get the idea):

public function activesync_get_autodiscover_username($email)
     {
         $cmd = 'ldapsearch -H ldaps://my-dc.mylocal.net:636 -x -D 
cn=horde,cn=Users,dc=mylocal,dc=net -w somepassword -b 
dc=mylocal,dc=net mail=' . $email . ' | /bin/grep sAMAccountName: | 
/usr/bin/awk \'{print $2}\'';;
         $username  = `$cmd`;

         return $username;
     }

This works quite well, I can use my e-mail address and the hook 
provides the correct username and the ActiveSync login is ok.

If the e-mail address is: max.mustermann@mylocal.net it returns the 
corresponding username: maxmus

  The downside of this approach is, that I cannot send mails from 
ActiveSync devices anymore. The ActiveSync.log gives me:

ERR: Address is missing domain.

It seems that ActiveSync is using the username maxmus without a domain 
as from address which cannot work, thus the error message is correct. 
This shouldn't be happening as I understand that the hook only 
provides a login username and nothing more. The example shows exactly 
that:

/**
      * ActiveSync hook for determing a Horde username from an email address.
      *
      * @param string $email  The email address
      *
      * @return string  The username to use to authenticate to Horde with.
      */
//    public function activesync_get_autodiscover_username($email)
//    {
//        return substr($email, 0, strpos($email, '@'));
//    }

Only the username (part of the mail address in that case) is returned.
I assume there must be some kind of bug in Driver.php but I'm no php 
specialist, so I have no idea where to look at right now.

When I disable the custom hook in the ActiveSync configuration, all 
works as expected, but I have to enter the username manually (not a 
big deal, but the end user has to know the username for this to work).

If you need further Information, please ask.

Best regards,
Hendrik



Saved Queries