get_email_addresses_hook
Mon Mar 02, 2009 · 139 words

SmartSieve is something one can use to set up server-based mail filtering, including vacation messages. It has a nice feature which enables it to fetch any list of email addresses for a user account. The default hook for this uses LDAP, but unfortunately does not work with OS X server. Here's a modified get_email_addrsesses_hook that works on both 10.4 and 10.5:

function getEmailAddresses()
{
  $server = 'localhost';
  $baseDn = 'cn=users,dc=pretendco,dc=com';
  $addresses = array();

  if (extension_loaded('ldap')) {
      $ds = ldap_connect($server);
      // To avoid protocol error
      ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
      if ($ds) {
        // Anonymous bind.
        $r = ldap_bind($ds);
        $sr = ldap_search($ds, $baseDn,
          "uid=".$_SESSION['smartsieve']['authz'], array('mail'));
        $entries = ldap_get_entries($ds, $sr);
        // Strip count
        array_shift($entries[0]['mail']);
        $addresses = $entries[0]['mail'];
        ldap_close($ds);
      }
  }

  return $addresses;

}

And just to clarify, the list of addresses comes from what's defined under WGM > User > Info > Email.


back · essays · credits ·